diff --git a/config/routes.php b/config/routes.php index 5296dbc7..2267bc88 100644 --- a/config/routes.php +++ b/config/routes.php @@ -1,14 +1,7 @@ addRoute('GET', '/hello/{name}', function ($request) { - /** @var ServerRequestInterface $request */ - $name = $request->getAttribute('name'); - - return response(sprintf('Hello %s!', htmlspecialchars($name))); -}); +$route->get('/credits', 'CreditsController@index'); diff --git a/includes/pages/guest_credits.php b/includes/pages/guest_credits.php deleted file mode 100644 index 5f90c97c..00000000 --- a/includes/pages/guest_credits.php +++ /dev/null @@ -1,17 +0,0 @@ -response = $response; + } + + /** + * @return Response + */ + public function index() + { + return $this->response->withView('pages/credits.twig'); + } +} diff --git a/src/Middleware/LegacyMiddleware.php b/src/Middleware/LegacyMiddleware.php index f8c2a205..ebf456eb 100644 --- a/src/Middleware/LegacyMiddleware.php +++ b/src/Middleware/LegacyMiddleware.php @@ -18,7 +18,6 @@ class LegacyMiddleware implements MiddlewareInterface 'angeltypes', 'api', 'atom', - 'credits', 'ical', 'login', 'public_dashboard', @@ -249,11 +248,6 @@ class LegacyMiddleware implements MiddlewareInterface $title = admin_log_title(); $content = admin_log(); return [$title, $content]; - case 'credits': - require_once realpath(__DIR__ . '/../../includes/pages/guest_credits.php'); - $title = credits_title(); - $content = guest_credits(); - return [$title, $content]; } require_once realpath(__DIR__ . '/../../includes/pages/guest_start.php'); diff --git a/src/Middleware/RequestHandler.php b/src/Middleware/RequestHandler.php index e1381abf..ebe1ff9e 100644 --- a/src/Middleware/RequestHandler.php +++ b/src/Middleware/RequestHandler.php @@ -35,7 +35,7 @@ class RequestHandler implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $requestHandler = $request->getAttribute('route-request-handler'); - $requestHandler = $this->resolveMiddleware($requestHandler); + $requestHandler = $this->resolveRequestHandler($requestHandler); if ($requestHandler instanceof MiddlewareInterface) { return $requestHandler->process($request, $handler); @@ -47,4 +47,33 @@ class RequestHandler implements MiddlewareInterface throw new InvalidArgumentException('Unable to process request handler of type ' . gettype($requestHandler)); } + + /** + * @param string|callable|MiddlewareInterface|RequestHandlerInterface $handler + * @return MiddlewareInterface|RequestHandlerInterface + */ + protected function resolveRequestHandler($handler) + { + if (is_string($handler) && strpos($handler, '@') !== false) { + list($class, $method) = explode('@', $handler, 2); + if (!class_exists($class) && !$this->container->has($class)) { + $class = sprintf('Engelsystem\\Controllers\\%s', $class); + } + + $handler = [$class, $method]; + } + + if ( + is_array($handler) + && is_string($handler[0]) + && ( + class_exists($handler[0]) + || $this->container->has($handler[0]) + ) + ) { + $handler[0] = $this->container->make($handler[0]); + } + + return $this->resolveMiddleware($handler); + } } diff --git a/templates/layouts/app.twig b/templates/layouts/app.twig index 20ea853b..4868a714 100644 --- a/templates/layouts/app.twig +++ b/templates/layouts/app.twig @@ -28,8 +28,10 @@ {% endblock %}