@@ -2772,37 +2772,32 @@ Now you'll get the expected results when generating URLs in your commands::
27722772 use Symfony\Component\Console\Input\InputInterface;
27732773 use Symfony\Component\Console\Output\OutputInterface;
27742774 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2775- use Symfony\Component\Routing\RouterInterface;
27762775 // ...
27772776
27782777 class SomeCommand extends Command
27792778 {
2780- private $router;
2781-
2782- public function __construct(RouterInterface $router)
2779+ public function __construct(private UrlGeneratorInterface $urlGenerator)
27832780 {
27842781 parent::__construct();
2785-
2786- $this->router = $router;
27872782 }
27882783
27892784 protected function execute(InputInterface $input, OutputInterface $output): int
27902785 {
27912786 // generate a URL with no route arguments
2792- $signUpPage = $this->router ->generate('sign_up');
2787+ $signUpPage = $this->urlGenerator ->generate('sign_up');
27932788
27942789 // generate a URL with route arguments
2795- $userProfilePage = $this->router ->generate('user_profile', [
2790+ $userProfilePage = $this->urlGenerator ->generate('user_profile', [
27962791 'username' => $user->getUserIdentifier(),
27972792 ]);
27982793
2799- // generated URLs are "absolute paths" by default . Pass a third optional
2800- // argument to generate different URLs (e.g. an "absolute URL")
2801- $signUpPage = $this->router ->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
2794+ // by default, generated URLs are "absolute paths". Pass a third optional
2795+ // argument to generate different URIs (e.g. an "absolute URL")
2796+ $signUpPage = $this->urlGenerator ->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
28022797
28032798 // when a route is localized, Symfony uses by default the current request locale
28042799 // pass a different '_locale' value if you want to set the locale explicitly
2805- $signUpPageInDutch = $this->router ->generate('sign_up', ['_locale' => 'nl']);
2800+ $signUpPageInDutch = $this->urlGenerator ->generate('sign_up', ['_locale' => 'nl']);
28062801
28072802 // ...
28082803 }
0 commit comments