Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EE_Request_Stack   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 70
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle_response() 0 9 4
A handle_request() 0 5 1
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
/**
3
 * Class EE_Request_Stack
4
 *
5
 * Basically a container class for holding EE_Middleware classes and the core application
6
 *
7
 * @package 	Event Espresso
8
 * @subpackage 	core
9
 * @author 		Brent Christensen
10
 * @since 		4.8.20
11
 *
12
 */
13
14
class EE_Request_Stack {
15
16
	/**
17
	 * @access 	protected
18
	 * @type    EEI_Request_Decorator $_application
19
	 */
20
	protected $_application;
21
22
	/**
23
	 * @access 	protected
24
	 * @type    array $_middlewares
25
	 */
26
	protected $_middlewares = array();
27
28
	/**
29
	 * @access 	protected
30
	 * @type 	EE_Request $_request
31
	 */
32
	protected $_request;
33
34
	/**
35
	 * @access 	protected
36
	 * @type 	EE_Response $_response
37
	 */
38
	protected $_response;
39
40
41
42
	/**
43
	 * @param 	EEI_Request_Decorator $application
44
	 * @param 	array $middlewares
45
	 */
46
	public function __construct( EEI_Request_Decorator $application, $middlewares = array() ) {
47
		$this->_application = $application;
48
		$this->_middlewares = $middlewares;
49
	}
50
51
52
53
	/**
54
	 * @param 	EE_Request $request
55
	 * @param 	EE_Response $response
56
	 * @return 	EE_Response
57
	 */
58
	public function handle_request( EE_Request $request, EE_Response $response ) {
59
		$this->_request = $request;
60
		$this->_response = $response;
61
		return $this->_application->handle_request( $request, $response );
62
	}
63
64
65
66
	/**
67
	 * handle_response
68
	 * executes the handle_response() method on the EEI_Request_Stack_Core_App object
69
	 * after the request stack has been fully processed
70
	 */
71
	public function handle_response() {
72
		$prev_middleware = null;
73
		foreach ( $this->_middlewares as $middleware ) {
74
			if ( ! $prev_middleware instanceof EEI_Request_Stack_Core_App && $middleware instanceof EEI_Request_Stack_Core_App ) {
75
				$middleware->handle_response( $this->_request, $this->_response );
76
			}
77
			$prev_middleware = $middleware;
78
		}
79
	}
80
81
82
83
}
84
// End of file EE_Request_Stack.core.php
85
// Location: /EE_Request_Stack.core.php