diff --git a/src/Hateoas/UrlGenerator/SymfonyUrlGenerator.php b/src/Hateoas/UrlGenerator/SymfonyUrlGenerator.php index d4292633..628940a5 100644 --- a/src/Hateoas/UrlGenerator/SymfonyUrlGenerator.php +++ b/src/Hateoas/UrlGenerator/SymfonyUrlGenerator.php @@ -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); } } diff --git a/tests/Hateoas/Tests/UrlGenerator/SymfonyUrlGeneratorTest.php b/tests/Hateoas/Tests/UrlGenerator/SymfonyUrlGeneratorTest.php index 2db7f59d..66e344d1 100644 --- a/tests/Hateoas/Tests/UrlGenerator/SymfonyUrlGeneratorTest.php +++ b/tests/Hateoas/Tests/UrlGenerator/SymfonyUrlGeneratorTest.php @@ -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)