@@ -2394,34 +2394,32 @@ Now you'll get the expected results when generating URLs in your commands::
2394
2394
use Symfony\Component\Console\Input\InputInterface;
2395
2395
use Symfony\Component\Console\Output\OutputInterface;
2396
2396
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2397
- use Symfony\Component\Routing\RouterInterface;
2398
2397
// ...
2399
2398
2400
2399
class SomeCommand extends Command
2401
2400
{
2402
- public function __construct(
2403
- private RouterInterface $router,
2404
- ) {
2401
+ public function __construct(private UrlGeneratorInterface $urlGenerator)
2402
+ {
2405
2403
parent::__construct();
2406
2404
}
2407
2405
2408
2406
protected function execute(InputInterface $input, OutputInterface $output): int
2409
2407
{
2410
2408
// generate a URL with no route arguments
2411
- $signUpPage = $this->router ->generate('sign_up');
2409
+ $signUpPage = $this->urlGenerator ->generate('sign_up');
2412
2410
2413
2411
// generate a URL with route arguments
2414
- $userProfilePage = $this->router ->generate('user_profile', [
2412
+ $userProfilePage = $this->urlGenerator ->generate('user_profile', [
2415
2413
'username' => $user->getUserIdentifier(),
2416
2414
]);
2417
2415
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);
2421
2419
2422
2420
// when a route is localized, Symfony uses by default the current request locale
2423
2421
// 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']);
2425
2423
2426
2424
// ...
2427
2425
}
0 commit comments