/**
* Route the given route path
*
* This command takes a given path and displays the detected route and
* the selected package, controller and action.
*
* @param string $path The route path to resolve
* @param string $method The request method (GET, POST, PUT, DELETE, ...) to simulate
* @return void
*/
public function routePathCommand($path, $method = 'GET')
{
$server = ['REQUEST_URI' => $path, 'REQUEST_METHOD' => $method];
$httpRequest = new Request([], [], [], $server);
/** @var Route $route */
foreach ($this->router->getRoutes() as $route) {
if ($route->matches($httpRequest) === true) {
$routeValues = $route->getMatchResults();
$this->outputLine('<b>Path:</b>');
$this->outputLine(' ' . $path);
$this->outputLine('<b>Route:</b>');
$this->outputLine(' Name: ' . $route->getName());
$this->outputLine(' Pattern: ' . $route->getUriPattern());
$this->outputLine('<b>Result:</b>');
$this->outputLine(' Package: ' . (isset($routeValues['@package']) ? $routeValues['@package'] : '-'));
$this->outputLine(' Subpackage: ' . (isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : '-'));
$this->outputLine(' Controller: ' . (isset($routeValues['@controller']) ? $routeValues['@controller'] : '-'));
$this->outputLine(' Action: ' . (isset($routeValues['@action']) ? $routeValues['@action'] : '-'));
$this->outputLine(' Format: ' . (isset($routeValues['@format']) ? $routeValues['@format'] : '-'));
$controllerObjectName = $this->getControllerObjectName($routeValues['@package'], isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : null, $routeValues['@controller']);
if ($controllerObjectName === null) {
$this->outputLine('<b>Controller Error:</b>');
$this->outputLine(' !!! No Controller Object found !!!');
$this->quit(1);
}
$this->outputLine('<b>Controller:</b>');
$this->outputLine(' ' . $controllerObjectName);
$this->quit(0);
}
}
$this->outputLine('No matching Route was found');
$this->quit(1);
}