Skip to content

Commit

Permalink
fix passing route object parameter to generator (#254)
Browse files Browse the repository at this point in the history
* fix passing route object parameter to generator
  • Loading branch information
gseidel authored May 27, 2020
1 parent ab47aab commit b0a9609
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ProviderBasedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function generate($name, $parameters = [], $referenceType = self::ABSOLUT
&& $parameters[RouteObjectInterface::ROUTE_OBJECT] instanceof SymfonyRoute
) {
$route = $parameters[RouteObjectInterface::ROUTE_OBJECT];
unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
} elseif (null === $route = $this->provider->getRouteByName($name)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
Expand Down
22 changes: 21 additions & 1 deletion tests/Unit/Routing/ProviderBasedGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Route as SymfonyRoute;

class ProviderBasedGeneratorTest extends TestCase
{
Expand Down Expand Up @@ -106,6 +107,15 @@ public function testGenerateFromRoute(): void
$this->assertEquals('result_url', $url);
}

public function testRemoveRouteObject(): void
{
$url = $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [
RouteObjectInterface::ROUTE_OBJECT => new Proxy('/path'),
]);

$this->assertEquals('result_url', $url);
}

/**
* @group legacy
*
Expand Down Expand Up @@ -172,7 +182,12 @@ class TestableProviderBasedGenerator extends ProviderBasedGenerator
{
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
{
return 'result_url';
$url = 'result_url';
if ($parameters && $query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986)) {
$url .= '?'.$query;
}

return $url;
}
}

Expand All @@ -188,3 +203,8 @@ public function getContent(): ?object
return null;
}
}

class Proxy extends SymfonyRoute
{
public $__isInitialized__ = true;
}

0 comments on commit b0a9609

Please sign in to comment.