Skip to content

Commit

Permalink
Merge pull request #229 from ahilles107/patch-3
Browse files Browse the repository at this point in the history
Use UrlGeneratorInterface constants for UrlGenerator::generate
  • Loading branch information
willdurand committed Jan 21, 2016
2 parents 2733268 + 778b776 commit 4e90efe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ matrix:
fast_finish: true
allow_failures:
- php: hhvm
env:
- PREFER_LOWEST="--prefer-lowest"
- PREFER_LOWEST=""

before_script:
- composer self-update
- composer install --prefer-dist --no-interaction
- composer update --prefer-dist --no-interaction $PREFER_LOWEST

script:
- ./bin/phpunit --coverage-text
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
"doctrine/annotations": "~1.0",
"jms/metadata": "~1.1",
"jms/serializer": "~1.0",
"symfony/expression-language": "~2.4 || ~3.0"
"symfony/expression-language": "~2.4 || ~3.0",
"phpoption/phpoption": ">=1.1.0,<2.0-dev"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"symfony/yaml": "~2.0 || ~3.0",
"symfony/routing": "~2.0 || ~3.0",
"symfony/dependency-injection": "~2.0 || ~3.0",
"symfony/yaml": "~2.4 || ~3.0",
"symfony/routing": "~2.4 || ~3.0",
"symfony/dependency-injection": "~2.4 || ~3.0",
"pagerfanta/pagerfanta": "~1.0",
"twig/twig": "~1.12"
},
Expand Down
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

0 comments on commit 4e90efe

Please sign in to comment.