Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Dec 7, 2023
1 parent d7aa9a3 commit d4b52a4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/components/http-handler/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,34 @@ use SonsOfPHP\Component\HttpHandler\MiddlewareStack;
$stack = new MiddlewareStack();
$stack->add(new RouterMiddleware());
$stack->add(new CookieMiddleware());
$stack->add(function ($request, $handler) {
// ...
});
// ...

$app = new HttpHandler($stack);
$response = $app->handle($request);
```

The `MiddlewareStack` accepts objects that implement `Psr\Http\Server\MiddlewareInterface`
and anonymous functions.

### Middleware Priorities

An optional second argument may be passed to the `MiddlewareStack` which is for
the priority of the middleware. Priorities are ordered in ascending order.

```php
<?php

use SonsOfPHP\Component\HttpHandler\MiddlewareStack;

$stack = new MiddlewareStack();
$stack->add(new NotFoundMiddleware(), 1025);
$stack->add(new RouterMiddleware(), 255);
$stack->add(new CookieMiddleware(), -255);
$stack->add(new DefaultMiddleware());
```

In the above example, the `CookieMiddleware` will be processed first and
`NotFoundMiddleware` will be processed last.

0 comments on commit d4b52a4

Please sign in to comment.