Skip to content

Commit

Permalink
Add support for running RequestHandlerInterface queue items
Browse files Browse the repository at this point in the history
This treats RequestHandlerInterface as middleware, which allows Relay to act as a master queue for other PSR-15 compatible sub-queues.
  • Loading branch information
kevinsmith committed Nov 13, 2019
1 parent b5d2f7e commit 3041932
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
*/
namespace Relay;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
*
Expand All @@ -36,6 +37,10 @@ public function handle(ServerRequestInterface $request) : ResponseInterface
return $middleware->process($request, $this);
}

if ($middleware instanceof RequestHandlerInterface) {
return $middleware->handle($request);
}

return $middleware($request, $this);
}
}
14 changes: 14 additions & 0 deletions tests/RelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,18 @@ public function testResolverEntries()

$this->assertRelay(new Relay($queue, $resolver));
}

public function testRequestHandlerInQueue()
{
$queue = [
new FakeMiddleware(),
new FakeMiddleware(),
new FakeMiddleware(),
$this->responder,
];

$requestHandler = new Relay($queue);

$this->assertRelay(new Relay([$requestHandler]));
}
}

0 comments on commit 3041932

Please sign in to comment.