diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Controllers/BaseController.php | 8 | ||||
-rw-r--r-- | src/Controllers/CreditsController.php | 24 | ||||
-rw-r--r-- | src/Middleware/LegacyMiddleware.php | 6 | ||||
-rw-r--r-- | src/Middleware/RequestHandler.php | 31 |
4 files changed, 62 insertions, 7 deletions
diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php new file mode 100644 index 00000000..6a27a066 --- /dev/null +++ b/src/Controllers/BaseController.php @@ -0,0 +1,8 @@ +<?php + +namespace Engelsystem\Controllers; + +abstract class BaseController +{ + +} diff --git a/src/Controllers/CreditsController.php b/src/Controllers/CreditsController.php new file mode 100644 index 00000000..568811c7 --- /dev/null +++ b/src/Controllers/CreditsController.php @@ -0,0 +1,24 @@ +<?php + +namespace Engelsystem\Controllers; + +use Engelsystem\Http\Response; + +class CreditsController extends BaseController +{ + /** @var Response */ + protected $response; + + public function __construct(Response $response) + { + $this->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); + } } |