Skip to content

Commit

Permalink
Methods signature update
Browse files Browse the repository at this point in the history
README update
  • Loading branch information
Ahmard authored and Ahmard committed Feb 6, 2021
1 parent f89b13c commit f372b77
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions src/Http/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Http/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/Http/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Middleware
/**
* Middleware constructor.
* @param HandlerInterface ...$handler
* @throws InvalidArgumentException
*/
public function __construct(...$handler)
{
Expand All @@ -32,6 +33,7 @@ public function __construct(...$handler)
* @param ServerRequestInterface $request
* @return PromiseInterface
* @throws JsonException
* @throws InvalidArgumentException
*/
public function __invoke(ServerRequestInterface $request): PromiseInterface
{
Expand Down

0 comments on commit f372b77

Please sign in to comment.