Skip to content

Commit

Permalink
Use UrlGeneratorInterface constants for UrlGenerator::generate
Browse files Browse the repository at this point in the history
For relative path (with absolute url) use Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH
  • Loading branch information
Paweł Mikołajczuk authored and ahilles107 committed Jan 19, 2016
1 parent 2733268 commit 7555ea6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Hateoas/UrlGenerator/SymfonyUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function __construct(SymfonyUrlGeneratorInterface $urlGenerator)
*/
public function generate($name, array $parameters, $absolute = false)
{
// If is it at least Symfony 2.8 and $absolute is passed as boolean
if (SymfonyUrlGeneratorInterface::ABSOLUTE_PATH === 1 && is_bool($absolute)) {
$absolute = $absolute
? SymfonyUrlGeneratorInterface::ABSOLUTE_URL
: SymfonyUrlGeneratorInterface::ABSOLUTE_PATH
;
}

return $this->urlGenerator->generate($name, $parameters, $absolute);
}
}
4 changes: 4 additions & 0 deletions tests/Hateoas/Tests/UrlGenerator/SymfonyUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public function test()
$absolute = true;
$expectedResult = '/users/42';

if (\Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH === 1) {
$absolute = \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL;
}

$symfonyUrlGeneratorProphecy = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$symfonyUrlGeneratorProphecy
->generate($name, $parameters, $absolute)
Expand Down

2 comments on commit 7555ea6

@ggioffreda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks guys for the great job, this library is really useful. Any chance we can include this commit in a new tag, ie v2.9.1 so I can fix the dependency in my projects. I had to point to dev-master#7555ea6 because of hundreds of deprecation errors in my functional tests. Cheers

@willdurand
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.