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