@@ -2394,34 +2394,32 @@ Now you'll get the expected results when generating URLs in your commands::
23942394 use Symfony\Component\Console\Input\InputInterface;
23952395 use Symfony\Component\Console\Output\OutputInterface;
23962396 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2397- use Symfony\Component\Routing\RouterInterface;
23982397 // ...
23992398
24002399 class SomeCommand extends Command
24012400 {
2402- public function __construct(
2403- private RouterInterface $router,
2404- ) {
2401+ public function __construct(private UrlGeneratorInterface $urlGenerator)
2402+ {
24052403 parent::__construct();
24062404 }
24072405
24082406 protected function execute(InputInterface $input, OutputInterface $output): int
24092407 {
24102408 // generate a URL with no route arguments
2411- $signUpPage = $this->router ->generate('sign_up');
2409+ $signUpPage = $this->urlGenerator ->generate('sign_up');
24122410
24132411 // generate a URL with route arguments
2414- $userProfilePage = $this->router ->generate('user_profile', [
2412+ $userProfilePage = $this->urlGenerator ->generate('user_profile', [
24152413 'username' => $user->getUserIdentifier(),
24162414 ]);
24172415
2418- // generated URLs are "absolute paths" by default . Pass a third optional
2419- // argument to generate different URLs (e.g. an "absolute URL")
2420- $signUpPage = $this->router ->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
2416+ // by default, generated URLs are "absolute paths". Pass a third optional
2417+ // argument to generate different URIs (e.g. an "absolute URL")
2418+ $signUpPage = $this->urlGenerator ->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
24212419
24222420 // when a route is localized, Symfony uses by default the current request locale
24232421 // pass a different '_locale' value if you want to set the locale explicitly
2424- $signUpPageInDutch = $this->router ->generate('sign_up', ['_locale' => 'nl']);
2422+ $signUpPageInDutch = $this->urlGenerator ->generate('sign_up', ['_locale' => 'nl']);
24252423
24262424 // ...
24272425 }
0 commit comments