/** * @internal param \Auryn\Injector $injector * @internal param $category * @return TextResponse */ function renderCategoryIndex(CategoryNav $categoryNav) { $injectionParams = InjectionParams::fromParams(['pageTitle' => "Imagick demos"]); $callable = getTemplateSetupCallable('title'); // $exampleName = $categoryNav->getExampleName(); // $injectionParams->alias('ImagickDemo\Example', $exampleName); $injectionParams->alias('ImagickDemo\\Navigation\\Nav', 'ImagickDemo\\Navigation\\CategoryNav'); return new Tier($callable, $injectionParams); }
/** * @param \Auryn\Injector $injector * @param $routesFunction * @return \ImagickDemo\Response\Response|StandardHTTPResponse|null */ function servePage() { $routesFunction = getRoutes(); $dispatcher = \FastRoute\simpleDispatcher($routesFunction); $httpMethod = 'GET'; //$uri = '/'; $uri = '/image/Imagick/adaptiveResizeImage'; if (array_key_exists('REQUEST_URI', $_SERVER)) { $uri = $_SERVER['REQUEST_URI']; } ///$uri = '/image/Imagick/adaptiveResizeImage'; $path = $uri; $queryPosition = strpos($path, '?'); if ($queryPosition !== false) { $path = substr($path, 0, $queryPosition); } $routeInfo = $dispatcher->dispatch($httpMethod, $path); $dispatcherResult = $routeInfo[0]; if ($dispatcherResult == \FastRoute\Dispatcher::FOUND) { $handler = $routeInfo[1]; $vars = $routeInfo[2]; if (array_key_exists('category', $vars)) { $className = sprintf('ImagickDemo\\%s\\functions', $vars['category']); $className::load(); } $params = InjectionParams::fromParams($vars); return new Tier($handler, $params); } else { if ($dispatcherResult == \FastRoute\Dispatcher::NOT_FOUND) { return new StandardHTTPResponse(404, $uri, "Route not found"); } } //TODO - need to embed allowedMethods....theoretically. // $allowedMethods = $routeInfo[1]; // ... 405 Method Not Allowed return new StandardHTTPResponse(405, $uri, "Not allowed"); }