getData();
$canWriteCache = self::canWriteCache();
// If skip cache is enabled, do not try to write it
// If no skip cache then try to write if write is possible
if (! $skipCache && $canWriteCache) {
$writeWorks = self::writeCache(
'dispatch($request->getMethod(), rawurldecode($route));
if ($routeInfo[0] === Dispatcher::NOT_FOUND) {
/** @var ResponseRenderer $response */
$response = $container->get(ResponseRenderer::class);
$response->setHttpResponseCode(404);
echo Message::error(sprintf(
__('Error 404! The page %s was not found.'),
'' . htmlspecialchars($route) . '
'
))->getDisplay();
return;
}
if ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
/** @var ResponseRenderer $response */
$response = $container->get(ResponseRenderer::class);
$response->setHttpResponseCode(405);
echo Message::error(__('Error 405! Request method not allowed.'))->getDisplay();
return;
}
if ($routeInfo[0] !== Dispatcher::FOUND) {
return;
}
/** @psalm-var class-string $controllerName */
$controllerName = $routeInfo[1];
/** @var array $vars */
$vars = $routeInfo[2];
/**
* @psalm-var callable(ServerRequest=, array=):void $controller
*/
$controller = $container->get($controllerName);
$controller($request, $vars);
}
/**
* @param mixed $dispatchData
*
* @psalm-assert-if-true array[] $dispatchData
*/
private static function isRoutesCacheFileValid($dispatchData): bool
{
return is_array($dispatchData)
&& isset($dispatchData[0], $dispatchData[1])
&& is_array($dispatchData[0]) && is_array($dispatchData[1])
&& isset($dispatchData[0]['GET']) && is_array($dispatchData[0]['GET'])
&& isset($dispatchData[0]['GET']['/']) && is_string($dispatchData[0]['GET']['/'])
&& $dispatchData[0]['GET']['/'] === HomeController::class;
}
}