diff --git a/README.md b/README.md index 0fbfa37..89d2bef 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,8 @@ class TestHandler implements HandlerInterface } ``` -### +- All handlers must implement [HandlerInterface](src/Http/HandlerInterface.php) +- A handler is a middleware, handler is just a fancy name given to it. ### [Example](example) diff --git a/src/Http/Handler.php b/src/Http/Handler.php index 547d521..c94d157 100644 --- a/src/Http/Handler.php +++ b/src/Http/Handler.php @@ -23,6 +23,12 @@ class Handler protected ResponseInterface $response; + /** + * Handler constructor. + * @param array $handlers + * @param ResponseInterface $response + * @throws InvalidArgumentException + */ public function __construct(array $handlers, ResponseInterface $response) { $this->response = $response; diff --git a/src/Http/HandlerInterface.php b/src/Http/HandlerInterface.php index a4b252b..d6a82f3 100644 --- a/src/Http/HandlerInterface.php +++ b/src/Http/HandlerInterface.php @@ -5,12 +5,16 @@ use Nette\Utils\JsonException; +use Throwable; interface HandlerInterface { /** + * This serves like react's __invoke magic method, + * it will be called when request reach this handler * @param ResponseInterface $response * @throws JsonException + * @throws Throwable */ public function handle(ResponseInterface $response): void; } \ No newline at end of file diff --git a/src/Http/Middleware.php b/src/Http/Middleware.php index f56be33..b323179 100644 --- a/src/Http/Middleware.php +++ b/src/Http/Middleware.php @@ -18,6 +18,7 @@ class Middleware /** * Middleware constructor. * @param HandlerInterface ...$handler + * @throws InvalidArgumentException */ public function __construct(...$handler) { @@ -32,6 +33,7 @@ public function __construct(...$handler) * @param ServerRequestInterface $request * @return PromiseInterface * @throws JsonException + * @throws InvalidArgumentException */ public function __invoke(ServerRequestInterface $request): PromiseInterface {