Skip to content

Commit

Permalink
Merge pull request #7 from middlewares/fix/callable-handlers
Browse files Browse the repository at this point in the history
Allow any callable as a handler
  • Loading branch information
oscarotero authored Feb 7, 2018
2 parents 3aa692a + 2feeebc commit 287dc0f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RequestHandler implements MiddlewareInterface
*/
public function __construct(ContainerInterface $container = null)
{
$this->container = $container;
$this->container = $container ?: new RequestHandlerContainer();
}

/**
Expand All @@ -51,8 +51,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$requestHandler = $request->getAttribute($this->handlerAttribute);

if (is_string($requestHandler)) {
$container = $this->container ?: new RequestHandlerContainer();
$requestHandler = $container->get($requestHandler);
$requestHandler = $this->container->get($requestHandler);
}

if ($requestHandler instanceof MiddlewareInterface) {
Expand All @@ -63,7 +62,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $requestHandler->handle($request);
}

if ($requestHandler instanceof Closure) {
if (is_callable($requestHandler)) {
return (new CallableHandler($requestHandler))->process($request, $handler);
}

Expand Down

0 comments on commit 287dc0f

Please sign in to comment.