protected function doMatch($pathinfo, Request $request = null)
{
$matchedRoute = $this->router->match($pathinfo, $request->server->all());
if ($matchedRoute === false) {
throw new ResourceNotFoundException();
}
$routeParams = $matchedRoute->params;
// The 'action' key always exists and defaults to the Route Name, so we check accordingly
if (!isset($routeParams['controller']) && $routeParams['action'] === $matchedRoute->name) {
throw new \Exception('Matched the route: ' . $matchedRoute->name . ' but unable to locate
any controller/action params to dispatch');
}
// We need _controller, to that symfony ControllerResolver can pick this up
if (!isset($routeParams['_controller'])) {
if (isset($routeParams['controller'])) {
$routeParams['_controller'] = $routeParams['controller'];
} elseif (isset($routeParams['action'])) {
$routeParams['_controller'] = $routeParams['action'];
} else {
throw new \Exception('Unable to determine the controller from route: ' . $matchedRoute->name);
}
}
$routeParams['_route'] = $matchedRoute->name;
// If the controller is an Object, and 'action' is defaulted to the route name - we default to __invoke
if ($routeParams['action'] === $matchedRoute->name) {
$routeParams['action'] = '__invoke';
}
if (false === strpos($routeParams['_controller'], '::') && isset($routeParams['action'])) {
$routeParams['_controller'] = sprintf('%s::%s', $routeParams['_controller'], $routeParams['action']);
}
return $routeParams;
}