Completed
Branch BUG-9019-ticket-selector-submi... (c1f9d8)
by
unknown
435:14 queued 416:01
created

EE_Bootstrap::run_request_stack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4286
cc 1
eloc 10
nc 1
nop 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
/**
3
 * Class EE_Bootstrap
4
 *
5
 * Loads a few required autoloaders, then proceeds to build a request stack
6
 * which consists of an array of EE_Middleware request decorator classes.
7
 * Each middleware class wraps the previous middleware class with itself,
8
 * with the core application loader residing at the center.
9
 * The stack is then processed by passing an EE_Request object to the first class in the stack.
10
 * Each middleware class:
11
 *      accepts the request object
12
 * 		passes the request to the next middleware class in the stack
13
 * 		receives an EE_Response object from that next middleware class
14
 * 		applies it's logic before and/or after doing the above
15
 * 		returns an EE_Response object to the previous middleware class
16
 * 		and can terminate the request at any point during the above
17
 * If none of the middleware classes terminate the request,
18
 * then the Request Stack will terminate itself after everything else is finished.
19
 *
20
 * @package 	Event Espresso
21
 * @subpackage 	core
22
 * @author 		Brent Christensen
23
 * @since 		4.8.20
24
 *
25
 */
26
27
class EE_Bootstrap {
28
29
	/**
30
	 * @access 	protected
31
	 * @type 	EE_Request_Stack_Builder $_request_stack_builder
32
	 */
33
	protected $_request_stack_builder = null;
34
35
	/**
36
	 * @access 	protected
37
	 * @type 	EE_Request_Stack $_request_stack
38
	 */
39
	protected $_request_stack = null;
40
41
42
43
	public function __construct() {
44
		// construct request stack and run middleware apps as soon as all WP plugins are loaded
45
		add_action( 'plugins_loaded', array( $this, 'run_request_stack' ), 0 );
46
		// set framework for the rest of EE to hook into when loading
47
		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_espresso_addons' ), 1 );
48
		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'detect_activations_or_upgrades' ), 3 );
49
		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_core_configuration' ), 5 );
50
		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'register_shortcodes_modules_and_widgets' ), 7 );
51
		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'brew_espresso' ), 9 );
52
	}
53
54
55
56
	/**
57
	 * run_request_stack
58
	 * construct request stack and run middleware apps
59
	 */
60
	public function run_request_stack() {
61
		$this->load_autoloader();
62
		$this->set_autoloaders_for_required_files();
63
		$this->_request_stack_builder = $this->build_request_stack();
64
		$this->_request_stack = $this->_request_stack_builder->resolve(
65
			new EE_Load_Espresso_Core()
66
		);
67
		$this->_request_stack->handle_request(
68
			new EE_Request( $_REQUEST ),
69
			new EE_Response()
70
		);
71
		$this->_request_stack->handle_response();
72
	}
73
74
75
76
	/**
77
	 * load_autoloader
78
	 */
79
	protected function load_autoloader() {
80
		// load interfaces
81
		espresso_load_required( 'EEH_Autoloader', EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' );
82
		EEH_Autoloader::instance();
83
	}
84
85
86
87
	/**
88
	 * load_required_files
89
	 */
90
	protected function set_autoloaders_for_required_files() {
91
		// load interfaces
92
		espresso_load_required( 'EEI_Interfaces', EE_CORE . 'interfaces' . DS . 'EEI_Interfaces.php' );
93
		// load helpers
94
		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_HELPERS );
95
		// load request stack
96
		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'request_stack' . DS );
97
		// load middleware
98
		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'middleware' . DS );
99
	}
100
101
102
103
	/**
104
	 * build_request_stack
105
	 *
106
	 * @return \EE_Request_Stack_Builder
107
	 */
108
	public function build_request_stack() {
109
		$request_stack_builder = new EE_Request_Stack_Builder();
110
		$stack_apps = apply_filters(
111
			'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
112
			array(
113
				'EE_Recommended_Versions',
114
				'EE_Alpha_Banner_Warning',
115
				//'EE_Activation',
116
				//'EE_Cache_Buster',
117
				//'EE_Admin_Bar',
118
			)
119
		);
120
		// load middleware onto stack : FILO (First In Last Out)
121
		foreach ( (array)$stack_apps as $stack_app ) {
122
			//$request_stack_builder->push( $stack_app );
123
			$request_stack_builder->unshift( $stack_app );
124
		}
125
		return apply_filters(
126
			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
127
			$request_stack_builder
128
		);
129
	}
130
131
132
133
	/**
134
	 * load_espresso_addons
135
	 * runs during the WP 'plugins_loaded' action at priority 1
136
	 * and is the initial loading phase for EE addons
137
	 * no other logic should be performed at this point
138
	 */
139
	public static function load_espresso_addons() {
140
		do_action( 'AHEE__EE_Bootstrap__load_espresso_addons' );
141
	}
142
143
144
145
	/**
146
	 * detect_activations_or_upgrades
147
	 * runs during the WP 'plugins_loaded' action at priority 3
148
	 * Now that all of the addons have been loaded,
149
	 * we can determine if anything needs activating or upgrading
150
	 */
151
	public static function detect_activations_or_upgrades() {
152
		do_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' );
153
	}
154
155
156
157
	/**
158
	 * load_core_configuration
159
	 * runs during the WP 'plugins_loaded' action at priority 5
160
	 * Now that the database is assumed to be at the correct version
161
	 * we can load and set all of the system configurations
162
	 */
163
	public static function load_core_configuration() {
164
		do_action( 'AHEE__EE_Bootstrap__load_core_configuration' );
165
	}
166
167
168
169
	/**
170
	 * register_shortcodes_modules_and_widgets
171
	 * runs during the WP 'plugins_loaded' action at priority 7
172
	 * and handles registering all o four shortcodes, modules and widgets
173
	 * so that they are ready to be used throughout the system
174
	 */
175
	public static function register_shortcodes_modules_and_widgets() {
176
		do_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' );
177
	}
178
179
180
181
	/**
182
	 * brew_espresso
183
	 * runs during the WP 'plugins_loaded' action at priority 9
184
	 * bootstrapping is considered complete at this point,
185
	 * so let the fun begin...
186
	 */
187
	public static function brew_espresso() {
188
		do_action( 'AHEE__EE_Bootstrap__brew_espresso' );
189
	}
190
191
192
193
}
194
// End of file EE_Bootstrap.core.php
195
// Location: /EE_Bootstrap.core.php