diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-23 19:13:19 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-23 20:11:37 +0200 |
commit | 66038eda14d5d4e624b6636a6156570e3e940e49 (patch) | |
tree | 6e4b7557b7d91786ef47f22f7ddef85eed1dfb42 /src/Middleware/RequestHandler.php | |
parent | 590adffa9316b98544cb8d67b03b80e44ba9c8b7 (diff) | |
parent | 9d34f371cb9c5ab0d60bd3158678b9cc9da6cc80 (diff) |
Merge branch 'twig-templates'
Diffstat (limited to 'src/Middleware/RequestHandler.php')
-rw-r--r-- | src/Middleware/RequestHandler.php | 31 |
1 files changed, 30 insertions, 1 deletions
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); + } } |