-
Notifications
You must be signed in to change notification settings - Fork 454
/
MiddlewareDelegate.php
60 lines (49 loc) · 1.51 KB
/
MiddlewareDelegate.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Concrete\Core\Http\Middleware;
use Psr\Http\Message\ResponseInterface;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* A middleware delegate for running the next middleware
* @package Concrete\Core\Http
*/
final class MiddlewareDelegate implements DelegateInterface
{
/**
* @var \Concrete\Core\Http\Middleware\MiddlewareInterface
*/
private $middleware;
/**
* @var \Concrete\Core\Http\Middleware\DelegateInterface
*/
private $nextDelegate;
/**
* @var \Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory
*/
private $foundationFactory;
public function __construct(
MiddlewareInterface $middleware,
DelegateInterface $nextDelegate,
HttpFoundationFactory $foundationFactory
) {
$this->middleware = $middleware;
$this->nextDelegate = $nextDelegate;
$this->foundationFactory = $foundationFactory;
}
/**
* Dispatch the next available middleware and return the response.
*
* @param Request $request
* @return Response
*/
public function next(Request $request)
{
$response = $this->middleware->process($request, $this->nextDelegate);
// Negotiate PSR7 responses
if ($response instanceof ResponseInterface) {
return $this->foundationFactory->createResponse($response);
}
return $response;
}
}