1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\request\middleware; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\services\loaders\LoaderInterface; |
6
|
|
|
use EventEspresso\core\services\request\RequestDecoratorInterface; |
7
|
|
|
use EventEspresso\core\services\request\RequestInterface; |
8
|
|
|
use EventEspresso\core\services\request\ResponseInterface; |
9
|
|
|
|
10
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Middleware |
16
|
|
|
* Parent class for Middleware Request decorators. |
17
|
|
|
* Accepts an instance of another Middleware class, |
18
|
|
|
* and handles the passing of EE_Request and EE_Response objects to and from it |
19
|
|
|
* Middleware classes are for functionality that needs to run on nearly EVERY request. |
20
|
|
|
* They can perform their logic either before or after the core application has run: |
21
|
|
|
* (see documentation for the handle() method below) |
22
|
|
|
* Middleware classes should NOT depend on core functionality, |
23
|
|
|
* because there is no guarantee that the core application has run |
24
|
|
|
* |
25
|
|
|
* @package EventEspresso\core\services\request\middleware |
26
|
|
|
* @author Brent Christensen |
27
|
|
|
* @since 4.9.52 |
28
|
|
|
*/ |
29
|
|
|
abstract class Middleware implements RequestDecoratorInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var RequestDecoratorInterface $request_stack_app |
34
|
|
|
*/ |
35
|
|
|
protected $request_stack_app; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var RequestInterface $request |
39
|
|
|
*/ |
40
|
|
|
protected $request; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ResponseInterface $response |
44
|
|
|
*/ |
45
|
|
|
protected $response; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var LoaderInterface |
49
|
|
|
*/ |
50
|
|
|
protected $loader; |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param RequestDecoratorInterface $request_stack_app |
56
|
|
|
* @param LoaderInterface $loader |
57
|
|
|
*/ |
58
|
|
|
public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader) |
59
|
|
|
{ |
60
|
|
|
$this->request_stack_app = $request_stack_app; |
61
|
|
|
$this->loader = $loader; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* process_request_stack |
68
|
|
|
* |
69
|
|
|
* @param RequestInterface $request |
70
|
|
|
* @param ResponseInterface $response |
71
|
|
|
* @return ResponseInterface |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
protected function processRequestStack(RequestInterface $request, ResponseInterface $response) |
74
|
|
|
{ |
75
|
|
|
$this->request = $request; |
76
|
|
|
$this->response = $response; |
77
|
|
|
if (! $this->response->requestTerminated()) { |
78
|
|
|
$this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
79
|
|
|
} |
80
|
|
|
return $this->response; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
// Location: Middleware.php |
86
|
|
|
|