Skip to content

Commit

Permalink
minor symfony#20417 [Routing] Rename variable to stay consistent (Osk…
Browse files Browse the repository at this point in the history
…arStark)

This PR was merged into the 5.4 branch.

Discussion
----------

[Routing] Rename variable to stay consistent

Here we are using `$urlGenerator`

* https://symfony.com/doc/6.4/routing.html#generating-urls-in-commands
* https://symfony.com/doc/6.4/security.html#customizing-logout
* https://symfony.com/doc/6.4/security.html#customizing-logout

cc `@mvhirsch`

Commits
-------

0b5820f Rename variable to stay consistent
  • Loading branch information
OskarStark committed Nov 27, 2024
2 parents efb4ecb + 0b5820f commit e134083
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2671,32 +2671,32 @@ the :class:`Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface` class

class SomeService
{
private $router;
private $urlGenerator;

public function __construct(UrlGeneratorInterface $router)
public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->router = $router;
$this->urlGenerator = $urlGenerator;
}

public function someMethod()
{
// ...

// generate a URL with no route arguments
$signUpPage = $this->router->generate('sign_up');
$signUpPage = $this->urlGenerator->generate('sign_up');

// generate a URL with route arguments
$userProfilePage = $this->router->generate('user_profile', [
$userProfilePage = $this->urlGenerator->generate('user_profile', [
'username' => $user->getUserIdentifier(),
]);

// generated URLs are "absolute paths" by default. Pass a third optional
// argument to generate different URLs (e.g. an "absolute URL")
$signUpPage = $this->router->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
$signUpPage = $this->urlGenerator->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);

// when a route is localized, Symfony uses by default the current request locale
// pass a different '_locale' value if you want to set the locale explicitly
$signUpPageInDutch = $this->router->generate('sign_up', ['_locale' => 'nl']);
$signUpPageInDutch = $this->urlGenerator->generate('sign_up', ['_locale' => 'nl']);
}
}

Expand Down

0 comments on commit e134083

Please sign in to comment.