Skip to content

Commit 9a2d09f

Browse files
authored
clarify how to enqueue the middleware via an event (#81)
Clarify how to enqueue the middleware via an event
1 parent 6599807 commit 9a2d09f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ $middleware->add('Muffin/Footprint.Footprint');
5454
It must be added **after** `AuthenticationMiddleware` to ensure that it can read
5555
the identify info after authentication is done.
5656

57+
If you don't have direct access to the place where `AuthenticationMiddleware` is added then check [here](#adding-middleware-via-event).
58+
5759
### Behavior
5860

5961
To use the included behavior to automatically update the `created_by` and `modified_by`
@@ -85,6 +87,25 @@ fields when creating a record, on the `modified_by` field again when updating
8587
the record and it will use the associated user record's company `id` in the
8688
`company_id` field when creating a record.
8789

90+
### Adding middleware via event
91+
92+
In some cases you don't have direct access to the place where the `AuthenticationMiddleware` is added. Then you will have to add this to your `src/Application.php`
93+
94+
```php
95+
use Authentication\Middleware\AuthenticationMiddleware;
96+
use Cake\Event\EventInterface;
97+
use Cake\Http\MiddlewareQueue;
98+
use Muffin\Footprint\Middleware\FootprintMiddleware;
99+
100+
// inside the bootstrap() method
101+
$this->getEventManager()->on(
102+
'Server.buildMiddleware',
103+
function (EventInterface $event, MiddlewareQueue $middleware) {
104+
$middleware->insertAfter(AuthenticationMiddleware::class, FootprintMiddleware::class);
105+
}
106+
);
107+
```
108+
88109
## Patches & Features
89110

90111
* Fork

0 commit comments

Comments
 (0)