-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
MiddlewareInterface.php
33 lines (29 loc) · 1.09 KB
/
MiddlewareInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);
namespace Baldinof\RoadRunnerBundle\Http;
use Iterator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* A middleware that allow to do some work after sending the response.
*/
interface MiddlewareInterface
{
/**
* The traversable should be consumed in 2 times.
* 1. Get the first value that should implement {@link ResponseInterface}, and send the response to the client
* 2. Consumes all other values to terminate the iterator.
*
* This way a middleware can handle heavy jobs after sending the response to the client.
*
* An easy way to implement this method is via Generator:
* ```php
* yield $next->handle($request)->withHeader('X-Middleware', 'MyMiddleware');
* // code here will be executed after sending the response
* ```
*
* @return \Iterator<Response> Only the first item will be sent to the client
*/
public function process(Request $request, HttpKernelInterface $next): \Iterator;
}