Open weierophinney opened 4 years ago
The problem is this line:
A new RouteParser is created and the existing one is not used. You can't access the routeparser because there is no getter for it on the RouteCollector. Without BC breaks reflection or a PR to FastRoute is needed.
$refRouter = new \ReflectionClass(get_class($this->router));
$refParser = $refRouter->getProperty('routeParser');
$refParser->setAccessible(true);
$parser = $refParser->getValue($this->router);
$routes = array_reverse($parser->parse($route->getPath()));
$missingParameters = [];
It would be better to hide that code into a method and cache it so it is needed only once. Another option is to change the constructor, but that would mean a BC break and rewriting all tests:
public function __construct(
RouteParser $routeParser = null,
DataGenerator $dataGenerator = null,
callable $dispatcherFactory = null,
array $config = null
) {
if (null === $routeParser) {
$routeParser = new RouteParser();
}
if (null === $dataGenerator) {
$dataGenerator = new RouteGenerator();
}
$this->router = new RouteCollector($routeParser, $dataGenerator);
$this->routeParser = $routeParser;
$this->dataGenerator = $dataGenerator;
$this->dispatcherCallback = $dispatcherFactory;
$this->loadConfig($config);
}
Originally posted by @geerteltink at https://github.com/zendframework/zend-expressive-fastroute/pull/63#issuecomment-504010798
Added Unit test to show difference in output between a user defined parser inside of the RouteCollector and the one generated by $router->generateUri
Originally posted by @TaylorSasser at https://github.com/zendframework/zend-expressive-fastroute/pull/63