@@ -20,26 +20,26 @@ |
||
20 | 20 | interface CapabilitiesCheckerInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
25 | - * If any of the individual capability checks fails, then the command will NOT be executed. |
|
26 | - * |
|
27 | - * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
28 | - * @return bool |
|
29 | - * @throws InvalidClassException |
|
30 | - * @throws InsufficientPermissionsException |
|
31 | - */ |
|
32 | - public function processCapCheck($cap_check); |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
38 | - * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
39 | - * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
40 | - * @return bool |
|
41 | - * @throws InsufficientPermissionsException |
|
42 | - * @throws InvalidClassException |
|
43 | - */ |
|
44 | - public function process($capability, $context, $ID = 0); |
|
23 | + /** |
|
24 | + * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
25 | + * If any of the individual capability checks fails, then the command will NOT be executed. |
|
26 | + * |
|
27 | + * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
28 | + * @return bool |
|
29 | + * @throws InvalidClassException |
|
30 | + * @throws InsufficientPermissionsException |
|
31 | + */ |
|
32 | + public function processCapCheck($cap_check); |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
38 | + * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
39 | + * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
40 | + * @return bool |
|
41 | + * @throws InsufficientPermissionsException |
|
42 | + * @throws InvalidClassException |
|
43 | + */ |
|
44 | + public function process($capability, $context, $ID = 0); |
|
45 | 45 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
9 | 9 | |
10 | 10 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
11 | - exit('No direct script access allowed'); |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -24,92 +24,92 @@ discard block |
||
24 | 24 | class CapabilitiesChecker implements CapabilitiesCheckerInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @type EE_Capabilities $capabilities |
|
29 | - */ |
|
30 | - private $capabilities; |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * CapabilitiesChecker constructor |
|
36 | - * |
|
37 | - * @param EE_Capabilities $capabilities |
|
38 | - */ |
|
39 | - public function __construct(EE_Capabilities $capabilities) |
|
40 | - { |
|
41 | - $this->capabilities = $capabilities; |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return EE_Capabilities |
|
48 | - */ |
|
49 | - protected function capabilities() |
|
50 | - { |
|
51 | - return $this->capabilities; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
58 | - * If any of the individual capability checks fails, then the command will NOT be executed. |
|
59 | - * |
|
60 | - * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
61 | - * @return bool |
|
62 | - * @throws InvalidClassException |
|
63 | - * @throws InsufficientPermissionsException |
|
64 | - */ |
|
65 | - public function processCapCheck($cap_check) |
|
66 | - { |
|
67 | - if (is_array($cap_check)) { |
|
68 | - foreach ($cap_check as $check) { |
|
69 | - $this->processCapCheck($check); |
|
70 | - } |
|
71 | - return true; |
|
72 | - } |
|
73 | - // at this point, $cap_check should be an individual instance of CapCheck |
|
74 | - if (! $cap_check instanceof CapCheckInterface) { |
|
75 | - throw new InvalidClassException( |
|
76 | - '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
|
77 | - ); |
|
78 | - } |
|
79 | - // sometimes cap checks are conditional, and no capabilities are required |
|
80 | - if ($cap_check instanceof PublicCapabilities) { |
|
81 | - return true; |
|
82 | - } |
|
83 | - $capabilities = (array)$cap_check->capability(); |
|
84 | - foreach ($capabilities as $capability) { |
|
85 | - if ( |
|
86 | - ! $this->capabilities()->current_user_can( |
|
87 | - $capability, |
|
88 | - $cap_check->context(), |
|
89 | - $cap_check->ID() |
|
90 | - ) |
|
91 | - ) { |
|
92 | - throw new InsufficientPermissionsException($cap_check->context()); |
|
93 | - } |
|
94 | - } |
|
95 | - return true; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
102 | - * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
103 | - * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
104 | - * @return bool |
|
105 | - * @throws InvalidDataTypeException |
|
106 | - * @throws InsufficientPermissionsException |
|
107 | - * @throws InvalidClassException |
|
108 | - */ |
|
109 | - public function process($capability, $context, $ID = 0) |
|
110 | - { |
|
111 | - return $this->processCapCheck(new CapCheck($capability, $context, $ID)); |
|
112 | - } |
|
27 | + /** |
|
28 | + * @type EE_Capabilities $capabilities |
|
29 | + */ |
|
30 | + private $capabilities; |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * CapabilitiesChecker constructor |
|
36 | + * |
|
37 | + * @param EE_Capabilities $capabilities |
|
38 | + */ |
|
39 | + public function __construct(EE_Capabilities $capabilities) |
|
40 | + { |
|
41 | + $this->capabilities = $capabilities; |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return EE_Capabilities |
|
48 | + */ |
|
49 | + protected function capabilities() |
|
50 | + { |
|
51 | + return $this->capabilities; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
58 | + * If any of the individual capability checks fails, then the command will NOT be executed. |
|
59 | + * |
|
60 | + * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
61 | + * @return bool |
|
62 | + * @throws InvalidClassException |
|
63 | + * @throws InsufficientPermissionsException |
|
64 | + */ |
|
65 | + public function processCapCheck($cap_check) |
|
66 | + { |
|
67 | + if (is_array($cap_check)) { |
|
68 | + foreach ($cap_check as $check) { |
|
69 | + $this->processCapCheck($check); |
|
70 | + } |
|
71 | + return true; |
|
72 | + } |
|
73 | + // at this point, $cap_check should be an individual instance of CapCheck |
|
74 | + if (! $cap_check instanceof CapCheckInterface) { |
|
75 | + throw new InvalidClassException( |
|
76 | + '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
|
77 | + ); |
|
78 | + } |
|
79 | + // sometimes cap checks are conditional, and no capabilities are required |
|
80 | + if ($cap_check instanceof PublicCapabilities) { |
|
81 | + return true; |
|
82 | + } |
|
83 | + $capabilities = (array)$cap_check->capability(); |
|
84 | + foreach ($capabilities as $capability) { |
|
85 | + if ( |
|
86 | + ! $this->capabilities()->current_user_can( |
|
87 | + $capability, |
|
88 | + $cap_check->context(), |
|
89 | + $cap_check->ID() |
|
90 | + ) |
|
91 | + ) { |
|
92 | + throw new InsufficientPermissionsException($cap_check->context()); |
|
93 | + } |
|
94 | + } |
|
95 | + return true; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
102 | + * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
103 | + * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
104 | + * @return bool |
|
105 | + * @throws InvalidDataTypeException |
|
106 | + * @throws InsufficientPermissionsException |
|
107 | + * @throws InvalidClassException |
|
108 | + */ |
|
109 | + public function process($capability, $context, $ID = 0) |
|
110 | + { |
|
111 | + return $this->processCapCheck(new CapCheck($capability, $context, $ID)); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use EventEspresso\core\exceptions\InvalidClassException; |
8 | 8 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
9 | 9 | |
10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
11 | 11 | exit('No direct script access allowed'); |
12 | 12 | } |
13 | 13 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | // at this point, $cap_check should be an individual instance of CapCheck |
74 | - if (! $cap_check instanceof CapCheckInterface) { |
|
74 | + if ( ! $cap_check instanceof CapCheckInterface) { |
|
75 | 75 | throw new InvalidClassException( |
76 | 76 | '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
77 | 77 | ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | if ($cap_check instanceof PublicCapabilities) { |
81 | 81 | return true; |
82 | 82 | } |
83 | - $capabilities = (array)$cap_check->capability(); |
|
83 | + $capabilities = (array) $cap_check->capability(); |
|
84 | 84 | foreach ($capabilities as $capability) { |
85 | 85 | if ( |
86 | 86 | ! $this->capabilities()->current_user_can( |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -22,577 +22,577 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | - */ |
|
34 | - const load_new_object = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | - */ |
|
40 | - const load_from_cache = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Dependency_Map $_instance |
|
44 | - */ |
|
45 | - protected static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - protected $_request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @type EE_Response $response |
|
54 | - */ |
|
55 | - protected $_response; |
|
56 | - |
|
57 | - /** |
|
58 | - * @type LoaderInterface $loader |
|
59 | - */ |
|
60 | - protected $loader; |
|
61 | - |
|
62 | - /** |
|
63 | - * @type array $_dependency_map |
|
64 | - */ |
|
65 | - protected $_dependency_map = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @type array $_class_loaders |
|
69 | - */ |
|
70 | - protected $_class_loaders = array(); |
|
71 | - |
|
72 | - /** |
|
73 | - * @type array $_aliases |
|
74 | - */ |
|
75 | - protected $_aliases = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_Dependency_Map constructor. |
|
81 | - * |
|
82 | - * @param EE_Request $request |
|
83 | - * @param EE_Response $response |
|
84 | - */ |
|
85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | - { |
|
87 | - $this->_request = $request; |
|
88 | - $this->_response = $response; |
|
89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | - do_action('EE_Dependency_Map____construct'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidArgumentException |
|
99 | - */ |
|
100 | - public function initialize() |
|
101 | - { |
|
102 | - $this->_register_core_dependencies(); |
|
103 | - $this->_register_core_class_loaders(); |
|
104 | - $this->_register_core_aliases(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @singleton method used to instantiate class object |
|
111 | - * @access public |
|
112 | - * @param EE_Request $request |
|
113 | - * @param EE_Response $response |
|
114 | - * @return EE_Dependency_Map |
|
115 | - */ |
|
116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | - { |
|
118 | - // check if class object is instantiated, and instantiated properly |
|
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | - } |
|
122 | - return self::$_instance; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param LoaderInterface $loader |
|
129 | - */ |
|
130 | - public function setLoader(LoaderInterface $loader) |
|
131 | - { |
|
132 | - $this->loader = $loader; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $class |
|
139 | - * @param array $dependencies |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - public static function register_dependencies($class, $dependencies) |
|
143 | - { |
|
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | - // we need to make sure that any aliases used when registering a dependency |
|
146 | - // get resolved to the correct class name |
|
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | - $alias = self::$_instance->get_alias($dependency); |
|
149 | - unset($dependencies[$dependency]); |
|
150 | - $dependencies[$alias] = $load_source; |
|
151 | - } |
|
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | - return true; |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $class_name |
|
162 | - * @param string $loader |
|
163 | - * @return bool |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | - { |
|
168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | - if ( |
|
170 | - ! is_callable($loader) |
|
171 | - && ( |
|
172 | - strpos($loader, 'load_') !== 0 |
|
173 | - || ! method_exists('EE_Registry', $loader) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | - $loader |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - $class_name = self::$_instance->get_alias($class_name); |
|
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | - return true; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function dependency_map() |
|
197 | - { |
|
198 | - return $this->_dependency_map; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | - * |
|
206 | - * @param string $class_name |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function has($class_name = '') |
|
210 | - { |
|
211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | - * |
|
219 | - * @param string $class_name |
|
220 | - * @param string $dependency |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | - { |
|
225 | - $dependency = $this->get_alias($dependency); |
|
226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | - ? true |
|
228 | - : false; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | - * |
|
236 | - * @param string $class_name |
|
237 | - * @param string $dependency |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | - { |
|
242 | - $dependency = $this->get_alias($dependency); |
|
243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
245 | - : EE_Dependency_Map::not_registered; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $class_name |
|
252 | - * @return string | Closure |
|
253 | - */ |
|
254 | - public function class_loader($class_name) |
|
255 | - { |
|
256 | - $class_name = $this->get_alias($class_name); |
|
257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - public function class_loaders() |
|
266 | - { |
|
267 | - return $this->_class_loaders; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * adds an alias for a classname |
|
274 | - * |
|
275 | - * @param string $class_name |
|
276 | - * @param string $alias |
|
277 | - */ |
|
278 | - public function add_alias($class_name, $alias) |
|
279 | - { |
|
280 | - $this->_aliases[$class_name] = $alias; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * returns TRUE if the provided class name has an alias |
|
287 | - * |
|
288 | - * @param string $class_name |
|
289 | - * @return boolean |
|
290 | - */ |
|
291 | - public function has_alias($class_name = '') |
|
292 | - { |
|
293 | - return isset($this->_aliases[$class_name]) ? true : false; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
300 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
301 | - * for example: |
|
302 | - * if the following two entries were added to the _aliases array: |
|
303 | - * array( |
|
304 | - * 'interface_alias' => 'some\namespace\interface' |
|
305 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
306 | - * ) |
|
307 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
308 | - * to load an instance of 'some\namespace\classname' |
|
309 | - * |
|
310 | - * @param string $class_name |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - public function get_alias($class_name = '') |
|
314 | - { |
|
315 | - return $this->has_alias($class_name) |
|
316 | - ? $this->get_alias($this->_aliases[$class_name]) |
|
317 | - : $class_name; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
324 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
325 | - * This is done by using the following class constants: |
|
326 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
327 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
328 | - */ |
|
329 | - protected function _register_core_dependencies() |
|
330 | - { |
|
331 | - $this->_dependency_map = array( |
|
332 | - 'EE_Request_Handler' => array( |
|
333 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
334 | - ), |
|
335 | - 'EE_System' => array( |
|
336 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
337 | - ), |
|
338 | - 'EE_Session' => array( |
|
339 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
340 | - ), |
|
341 | - 'EE_Cart' => array( |
|
342 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
343 | - ), |
|
344 | - 'EE_Front_Controller' => array( |
|
345 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
346 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
347 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
348 | - ), |
|
349 | - 'EE_Messenger_Collection_Loader' => array( |
|
350 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
351 | - ), |
|
352 | - 'EE_Message_Type_Collection_Loader' => array( |
|
353 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
354 | - ), |
|
355 | - 'EE_Message_Resource_Manager' => array( |
|
356 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
357 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
358 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
359 | - ), |
|
360 | - 'EE_Message_Factory' => array( |
|
361 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
362 | - ), |
|
363 | - 'EE_messages' => array( |
|
364 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
365 | - ), |
|
366 | - 'EE_Messages_Generator' => array( |
|
367 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
368 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
369 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
370 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
371 | - ), |
|
372 | - 'EE_Messages_Processor' => array( |
|
373 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
374 | - ), |
|
375 | - 'EE_Messages_Queue' => array( |
|
376 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
377 | - ), |
|
378 | - 'EE_Messages_Template_Defaults' => array( |
|
379 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
380 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
381 | - ), |
|
382 | - 'EE_Message_To_Generate_From_Request' => array( |
|
383 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
385 | - ), |
|
386 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
387 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
388 | - ), |
|
389 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
390 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
391 | - ), |
|
392 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
393 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
394 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
395 | - ), |
|
396 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
397 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
398 | - ), |
|
399 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
400 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
401 | - ), |
|
402 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
403 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
404 | - ), |
|
405 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
406 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
407 | - ), |
|
408 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
409 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
410 | - ), |
|
411 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
412 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
413 | - ), |
|
414 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
415 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
416 | - ), |
|
417 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
418 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
419 | - ), |
|
420 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
421 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
422 | - ), |
|
423 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
424 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
425 | - ), |
|
426 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
427 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
428 | - ), |
|
429 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
430 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
431 | - ), |
|
432 | - 'EE_Data_Migration_Class_Base' => array( |
|
433 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
434 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
435 | - ), |
|
436 | - 'EE_DMS_Core_4_1_0' => array( |
|
437 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
438 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
439 | - ), |
|
440 | - 'EE_DMS_Core_4_2_0' => array( |
|
441 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
442 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
443 | - ), |
|
444 | - 'EE_DMS_Core_4_3_0' => array( |
|
445 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
447 | - ), |
|
448 | - 'EE_DMS_Core_4_4_0' => array( |
|
449 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
450 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
451 | - ), |
|
452 | - 'EE_DMS_Core_4_5_0' => array( |
|
453 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
454 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
455 | - ), |
|
456 | - 'EE_DMS_Core_4_6_0' => array( |
|
457 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
459 | - ), |
|
460 | - 'EE_DMS_Core_4_7_0' => array( |
|
461 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
462 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_DMS_Core_4_8_0' => array( |
|
465 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
467 | - ), |
|
468 | - 'EE_DMS_Core_4_9_0' => array( |
|
469 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
471 | - ), |
|
472 | - ); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * Registers how core classes are loaded. |
|
479 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
480 | - * 'EE_Request_Handler' => 'load_core' |
|
481 | - * 'EE_Messages_Queue' => 'load_lib' |
|
482 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
483 | - * or, if greater control is required, by providing a custom closure. For example: |
|
484 | - * 'Some_Class' => function () { |
|
485 | - * return new Some_Class(); |
|
486 | - * }, |
|
487 | - * This is required for instantiating dependencies |
|
488 | - * where an interface has been type hinted in a class constructor. For example: |
|
489 | - * 'Required_Interface' => function () { |
|
490 | - * return new A_Class_That_Implements_Required_Interface(); |
|
491 | - * }, |
|
492 | - */ |
|
493 | - protected function _register_core_class_loaders() |
|
494 | - { |
|
495 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
496 | - //be used in a closure. |
|
497 | - $request = &$this->_request; |
|
498 | - $response = &$this->_response; |
|
499 | - $loader = &$this->loader; |
|
500 | - $this->_class_loaders = array( |
|
501 | - //load_core |
|
502 | - 'EE_Capabilities' => 'load_core', |
|
503 | - 'EE_Encryption' => 'load_core', |
|
504 | - 'EE_Front_Controller' => 'load_core', |
|
505 | - 'EE_Module_Request_Router' => 'load_core', |
|
506 | - 'EE_Registry' => 'load_core', |
|
507 | - 'EE_Request' => function () use (&$request) { |
|
508 | - return $request; |
|
509 | - }, |
|
510 | - 'EE_Response' => function () use (&$response) { |
|
511 | - return $response; |
|
512 | - }, |
|
513 | - 'EE_Request_Handler' => 'load_core', |
|
514 | - 'EE_Session' => 'load_core', |
|
515 | - 'EE_System' => 'load_core', |
|
516 | - //load_lib |
|
517 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
518 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
519 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
520 | - 'EE_Messenger_Collection' => 'load_lib', |
|
521 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
522 | - 'EE_Messages_Processor' => 'load_lib', |
|
523 | - 'EE_Message_Repository' => 'load_lib', |
|
524 | - 'EE_Messages_Queue' => 'load_lib', |
|
525 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
526 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
527 | - 'EE_Messages_Generator' => function () { |
|
528 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
529 | - }, |
|
530 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
531 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
532 | - }, |
|
533 | - //load_model |
|
534 | - 'EEM_Message_Template_Group' => 'load_model', |
|
535 | - 'EEM_Message_Template' => 'load_model', |
|
536 | - //load_helper |
|
537 | - 'EEH_Parse_Shortcodes' => function () { |
|
538 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
539 | - return new EEH_Parse_Shortcodes(); |
|
540 | - } |
|
541 | - return null; |
|
542 | - }, |
|
543 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
544 | - return $loader; |
|
545 | - }, |
|
546 | - ); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * can be used for supplying alternate names for classes, |
|
553 | - * or for connecting interface names to instantiable classes |
|
554 | - */ |
|
555 | - protected function _register_core_aliases() |
|
556 | - { |
|
557 | - $this->_aliases = array( |
|
558 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
559 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
560 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
561 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
562 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
563 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
564 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
565 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
566 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
567 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
568 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
569 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
570 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
571 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
572 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
573 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
574 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
575 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
576 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
577 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
578 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
579 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
580 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
581 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
582 | - ); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
589 | - * request Primarily used by unit tests. |
|
590 | - */ |
|
591 | - public function reset() |
|
592 | - { |
|
593 | - $this->_register_core_class_loaders(); |
|
594 | - $this->_register_core_dependencies(); |
|
595 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | + */ |
|
34 | + const load_new_object = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | + */ |
|
40 | + const load_from_cache = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Dependency_Map $_instance |
|
44 | + */ |
|
45 | + protected static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + protected $_request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @type EE_Response $response |
|
54 | + */ |
|
55 | + protected $_response; |
|
56 | + |
|
57 | + /** |
|
58 | + * @type LoaderInterface $loader |
|
59 | + */ |
|
60 | + protected $loader; |
|
61 | + |
|
62 | + /** |
|
63 | + * @type array $_dependency_map |
|
64 | + */ |
|
65 | + protected $_dependency_map = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @type array $_class_loaders |
|
69 | + */ |
|
70 | + protected $_class_loaders = array(); |
|
71 | + |
|
72 | + /** |
|
73 | + * @type array $_aliases |
|
74 | + */ |
|
75 | + protected $_aliases = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_Dependency_Map constructor. |
|
81 | + * |
|
82 | + * @param EE_Request $request |
|
83 | + * @param EE_Response $response |
|
84 | + */ |
|
85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | + { |
|
87 | + $this->_request = $request; |
|
88 | + $this->_response = $response; |
|
89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | + do_action('EE_Dependency_Map____construct'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidArgumentException |
|
99 | + */ |
|
100 | + public function initialize() |
|
101 | + { |
|
102 | + $this->_register_core_dependencies(); |
|
103 | + $this->_register_core_class_loaders(); |
|
104 | + $this->_register_core_aliases(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @singleton method used to instantiate class object |
|
111 | + * @access public |
|
112 | + * @param EE_Request $request |
|
113 | + * @param EE_Response $response |
|
114 | + * @return EE_Dependency_Map |
|
115 | + */ |
|
116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | + { |
|
118 | + // check if class object is instantiated, and instantiated properly |
|
119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | + } |
|
122 | + return self::$_instance; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param LoaderInterface $loader |
|
129 | + */ |
|
130 | + public function setLoader(LoaderInterface $loader) |
|
131 | + { |
|
132 | + $this->loader = $loader; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $class |
|
139 | + * @param array $dependencies |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + public static function register_dependencies($class, $dependencies) |
|
143 | + { |
|
144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | + // we need to make sure that any aliases used when registering a dependency |
|
146 | + // get resolved to the correct class name |
|
147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | + $alias = self::$_instance->get_alias($dependency); |
|
149 | + unset($dependencies[$dependency]); |
|
150 | + $dependencies[$alias] = $load_source; |
|
151 | + } |
|
152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | + return true; |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $class_name |
|
162 | + * @param string $loader |
|
163 | + * @return bool |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | + { |
|
168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | + if ( |
|
170 | + ! is_callable($loader) |
|
171 | + && ( |
|
172 | + strpos($loader, 'load_') !== 0 |
|
173 | + || ! method_exists('EE_Registry', $loader) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | + $loader |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + $class_name = self::$_instance->get_alias($class_name); |
|
184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | + return true; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function dependency_map() |
|
197 | + { |
|
198 | + return $this->_dependency_map; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | + * |
|
206 | + * @param string $class_name |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function has($class_name = '') |
|
210 | + { |
|
211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | + * |
|
219 | + * @param string $class_name |
|
220 | + * @param string $dependency |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | + { |
|
225 | + $dependency = $this->get_alias($dependency); |
|
226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | + ? true |
|
228 | + : false; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | + * |
|
236 | + * @param string $class_name |
|
237 | + * @param string $dependency |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | + { |
|
242 | + $dependency = $this->get_alias($dependency); |
|
243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
245 | + : EE_Dependency_Map::not_registered; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $class_name |
|
252 | + * @return string | Closure |
|
253 | + */ |
|
254 | + public function class_loader($class_name) |
|
255 | + { |
|
256 | + $class_name = $this->get_alias($class_name); |
|
257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + public function class_loaders() |
|
266 | + { |
|
267 | + return $this->_class_loaders; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * adds an alias for a classname |
|
274 | + * |
|
275 | + * @param string $class_name |
|
276 | + * @param string $alias |
|
277 | + */ |
|
278 | + public function add_alias($class_name, $alias) |
|
279 | + { |
|
280 | + $this->_aliases[$class_name] = $alias; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * returns TRUE if the provided class name has an alias |
|
287 | + * |
|
288 | + * @param string $class_name |
|
289 | + * @return boolean |
|
290 | + */ |
|
291 | + public function has_alias($class_name = '') |
|
292 | + { |
|
293 | + return isset($this->_aliases[$class_name]) ? true : false; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
300 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
301 | + * for example: |
|
302 | + * if the following two entries were added to the _aliases array: |
|
303 | + * array( |
|
304 | + * 'interface_alias' => 'some\namespace\interface' |
|
305 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
306 | + * ) |
|
307 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
308 | + * to load an instance of 'some\namespace\classname' |
|
309 | + * |
|
310 | + * @param string $class_name |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + public function get_alias($class_name = '') |
|
314 | + { |
|
315 | + return $this->has_alias($class_name) |
|
316 | + ? $this->get_alias($this->_aliases[$class_name]) |
|
317 | + : $class_name; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
324 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
325 | + * This is done by using the following class constants: |
|
326 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
327 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
328 | + */ |
|
329 | + protected function _register_core_dependencies() |
|
330 | + { |
|
331 | + $this->_dependency_map = array( |
|
332 | + 'EE_Request_Handler' => array( |
|
333 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
334 | + ), |
|
335 | + 'EE_System' => array( |
|
336 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
337 | + ), |
|
338 | + 'EE_Session' => array( |
|
339 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
340 | + ), |
|
341 | + 'EE_Cart' => array( |
|
342 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
343 | + ), |
|
344 | + 'EE_Front_Controller' => array( |
|
345 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
346 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
347 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
348 | + ), |
|
349 | + 'EE_Messenger_Collection_Loader' => array( |
|
350 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
351 | + ), |
|
352 | + 'EE_Message_Type_Collection_Loader' => array( |
|
353 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
354 | + ), |
|
355 | + 'EE_Message_Resource_Manager' => array( |
|
356 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
357 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
358 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
359 | + ), |
|
360 | + 'EE_Message_Factory' => array( |
|
361 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
362 | + ), |
|
363 | + 'EE_messages' => array( |
|
364 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
365 | + ), |
|
366 | + 'EE_Messages_Generator' => array( |
|
367 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
368 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
369 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
370 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
371 | + ), |
|
372 | + 'EE_Messages_Processor' => array( |
|
373 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
374 | + ), |
|
375 | + 'EE_Messages_Queue' => array( |
|
376 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
377 | + ), |
|
378 | + 'EE_Messages_Template_Defaults' => array( |
|
379 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
380 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
381 | + ), |
|
382 | + 'EE_Message_To_Generate_From_Request' => array( |
|
383 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
385 | + ), |
|
386 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
387 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
388 | + ), |
|
389 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
390 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
391 | + ), |
|
392 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
393 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
394 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
395 | + ), |
|
396 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
397 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
398 | + ), |
|
399 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
400 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
401 | + ), |
|
402 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
403 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
404 | + ), |
|
405 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
406 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
407 | + ), |
|
408 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
409 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
410 | + ), |
|
411 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
412 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
413 | + ), |
|
414 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
415 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
416 | + ), |
|
417 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
418 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
419 | + ), |
|
420 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
421 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
422 | + ), |
|
423 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
424 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
425 | + ), |
|
426 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
427 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
428 | + ), |
|
429 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
430 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
431 | + ), |
|
432 | + 'EE_Data_Migration_Class_Base' => array( |
|
433 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
434 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
435 | + ), |
|
436 | + 'EE_DMS_Core_4_1_0' => array( |
|
437 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
438 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
439 | + ), |
|
440 | + 'EE_DMS_Core_4_2_0' => array( |
|
441 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
442 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
443 | + ), |
|
444 | + 'EE_DMS_Core_4_3_0' => array( |
|
445 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
447 | + ), |
|
448 | + 'EE_DMS_Core_4_4_0' => array( |
|
449 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
450 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
451 | + ), |
|
452 | + 'EE_DMS_Core_4_5_0' => array( |
|
453 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
454 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
455 | + ), |
|
456 | + 'EE_DMS_Core_4_6_0' => array( |
|
457 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
459 | + ), |
|
460 | + 'EE_DMS_Core_4_7_0' => array( |
|
461 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
462 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_DMS_Core_4_8_0' => array( |
|
465 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
467 | + ), |
|
468 | + 'EE_DMS_Core_4_9_0' => array( |
|
469 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
471 | + ), |
|
472 | + ); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * Registers how core classes are loaded. |
|
479 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
480 | + * 'EE_Request_Handler' => 'load_core' |
|
481 | + * 'EE_Messages_Queue' => 'load_lib' |
|
482 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
483 | + * or, if greater control is required, by providing a custom closure. For example: |
|
484 | + * 'Some_Class' => function () { |
|
485 | + * return new Some_Class(); |
|
486 | + * }, |
|
487 | + * This is required for instantiating dependencies |
|
488 | + * where an interface has been type hinted in a class constructor. For example: |
|
489 | + * 'Required_Interface' => function () { |
|
490 | + * return new A_Class_That_Implements_Required_Interface(); |
|
491 | + * }, |
|
492 | + */ |
|
493 | + protected function _register_core_class_loaders() |
|
494 | + { |
|
495 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
496 | + //be used in a closure. |
|
497 | + $request = &$this->_request; |
|
498 | + $response = &$this->_response; |
|
499 | + $loader = &$this->loader; |
|
500 | + $this->_class_loaders = array( |
|
501 | + //load_core |
|
502 | + 'EE_Capabilities' => 'load_core', |
|
503 | + 'EE_Encryption' => 'load_core', |
|
504 | + 'EE_Front_Controller' => 'load_core', |
|
505 | + 'EE_Module_Request_Router' => 'load_core', |
|
506 | + 'EE_Registry' => 'load_core', |
|
507 | + 'EE_Request' => function () use (&$request) { |
|
508 | + return $request; |
|
509 | + }, |
|
510 | + 'EE_Response' => function () use (&$response) { |
|
511 | + return $response; |
|
512 | + }, |
|
513 | + 'EE_Request_Handler' => 'load_core', |
|
514 | + 'EE_Session' => 'load_core', |
|
515 | + 'EE_System' => 'load_core', |
|
516 | + //load_lib |
|
517 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
518 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
519 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
520 | + 'EE_Messenger_Collection' => 'load_lib', |
|
521 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
522 | + 'EE_Messages_Processor' => 'load_lib', |
|
523 | + 'EE_Message_Repository' => 'load_lib', |
|
524 | + 'EE_Messages_Queue' => 'load_lib', |
|
525 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
526 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
527 | + 'EE_Messages_Generator' => function () { |
|
528 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
529 | + }, |
|
530 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
531 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
532 | + }, |
|
533 | + //load_model |
|
534 | + 'EEM_Message_Template_Group' => 'load_model', |
|
535 | + 'EEM_Message_Template' => 'load_model', |
|
536 | + //load_helper |
|
537 | + 'EEH_Parse_Shortcodes' => function () { |
|
538 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
539 | + return new EEH_Parse_Shortcodes(); |
|
540 | + } |
|
541 | + return null; |
|
542 | + }, |
|
543 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
544 | + return $loader; |
|
545 | + }, |
|
546 | + ); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * can be used for supplying alternate names for classes, |
|
553 | + * or for connecting interface names to instantiable classes |
|
554 | + */ |
|
555 | + protected function _register_core_aliases() |
|
556 | + { |
|
557 | + $this->_aliases = array( |
|
558 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
559 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
560 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
561 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
562 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
563 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
564 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
565 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
566 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
567 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
568 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
569 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
570 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
571 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
572 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
573 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
574 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
575 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
576 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
577 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
578 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
579 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
580 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
581 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
582 | + ); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
589 | + * request Primarily used by unit tests. |
|
590 | + */ |
|
591 | + public function reset() |
|
592 | + { |
|
593 | + $this->_register_core_class_loaders(); |
|
594 | + $this->_register_core_dependencies(); |
|
595 | + } |
|
596 | 596 | |
597 | 597 | |
598 | 598 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
117 | 117 | { |
118 | 118 | // check if class object is instantiated, and instantiated properly |
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
121 | 121 | } |
122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function register_dependencies($class, $dependencies) |
143 | 143 | { |
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | 145 | // we need to make sure that any aliases used when registering a dependency |
146 | 146 | // get resolved to the correct class name |
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
148 | 148 | $alias = self::$_instance->get_alias($dependency); |
149 | 149 | unset($dependencies[$dependency]); |
150 | 150 | $dependencies[$alias] = $load_source; |
151 | 151 | } |
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
153 | 153 | return true; |
154 | 154 | } |
155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
186 | 186 | return true; |
187 | 187 | } |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | 'EE_Front_Controller' => 'load_core', |
505 | 505 | 'EE_Module_Request_Router' => 'load_core', |
506 | 506 | 'EE_Registry' => 'load_core', |
507 | - 'EE_Request' => function () use (&$request) { |
|
507 | + 'EE_Request' => function() use (&$request) { |
|
508 | 508 | return $request; |
509 | 509 | }, |
510 | - 'EE_Response' => function () use (&$response) { |
|
510 | + 'EE_Response' => function() use (&$response) { |
|
511 | 511 | return $response; |
512 | 512 | }, |
513 | 513 | 'EE_Request_Handler' => 'load_core', |
@@ -524,23 +524,23 @@ discard block |
||
524 | 524 | 'EE_Messages_Queue' => 'load_lib', |
525 | 525 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
526 | 526 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
527 | - 'EE_Messages_Generator' => function () { |
|
527 | + 'EE_Messages_Generator' => function() { |
|
528 | 528 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
529 | 529 | }, |
530 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
530 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
531 | 531 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
532 | 532 | }, |
533 | 533 | //load_model |
534 | 534 | 'EEM_Message_Template_Group' => 'load_model', |
535 | 535 | 'EEM_Message_Template' => 'load_model', |
536 | 536 | //load_helper |
537 | - 'EEH_Parse_Shortcodes' => function () { |
|
537 | + 'EEH_Parse_Shortcodes' => function() { |
|
538 | 538 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
539 | 539 | return new EEH_Parse_Shortcodes(); |
540 | 540 | } |
541 | 541 | return null; |
542 | 542 | }, |
543 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
543 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
544 | 544 | return $loader; |
545 | 545 | }, |
546 | 546 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -24,228 +24,228 @@ discard block |
||
24 | 24 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @type LoaderInterface $loader |
|
29 | - */ |
|
30 | - protected $loader; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Request $request |
|
34 | - */ |
|
35 | - protected $request; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Response $response |
|
39 | - */ |
|
40 | - protected $response; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Dependency_Map $dependency_map |
|
44 | - */ |
|
45 | - protected $dependency_map; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Registry $registry |
|
49 | - */ |
|
50 | - protected $registry; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * EE_Load_Espresso_Core constructor |
|
56 | - */ |
|
57 | - public function __construct() |
|
58 | - { |
|
59 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * handle |
|
66 | - * sets hooks for running rest of system |
|
67 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | - * starting EE Addons from any other point may lead to problems |
|
69 | - * |
|
70 | - * @param EE_Request $request |
|
71 | - * @param EE_Response $response |
|
72 | - * @return EE_Response |
|
73 | - * @throws EE_Error |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidArgumentException |
|
77 | - */ |
|
78 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
79 | - { |
|
80 | - $this->request = $request; |
|
81 | - $this->response = $response; |
|
82 | - // info about how to load classes required by other classes |
|
83 | - $this->dependency_map = $this->_load_dependency_map(); |
|
84 | - // central repository for classes |
|
85 | - $this->registry = $this->_load_registry(); |
|
86 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
87 | - // PSR4 Autoloaders |
|
88 | - $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
89 | - $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader'); |
|
90 | - $this->dependency_map->setLoader($this->loader); |
|
91 | - // build DI container |
|
92 | - $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
93 | - $OpenCoffeeShop->addRecipes(); |
|
94 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
95 | - // create and cache the CommandBus, and also add middleware |
|
96 | - $this->registry->create( |
|
97 | - 'CommandBusInterface', |
|
98 | - array( |
|
99 | - null, |
|
100 | - apply_filters( |
|
101 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
102 | - array( |
|
103 | - $this->registry->create('CapChecker'), |
|
104 | - $this->registry->create('AddActionHook'), |
|
105 | - ) |
|
106 | - ), |
|
107 | - ), |
|
108 | - true |
|
109 | - ); |
|
110 | - // workarounds for PHP < 5.3 |
|
111 | - $this->_load_class_tools(); |
|
112 | - // load interfaces |
|
113 | - espresso_load_required('EEI_Payment_Method_Interfaces', |
|
114 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
115 | - // deprecated functions |
|
116 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
117 | - // WP cron jobs |
|
118 | - $this->registry->load_core('Cron_Tasks'); |
|
119 | - $this->registry->load_core('EE_Request_Handler'); |
|
120 | - $this->registry->load_core('EE_System'); |
|
121 | - return $this->response; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return EE_Request |
|
128 | - */ |
|
129 | - public function request() |
|
130 | - { |
|
131 | - return $this->request; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return EE_Response |
|
138 | - */ |
|
139 | - public function response() |
|
140 | - { |
|
141 | - return $this->response; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return EE_Dependency_Map |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - public function dependency_map() |
|
151 | - { |
|
152 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
153 | - throw new EE_Error( |
|
154 | - sprintf( |
|
155 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
156 | - print_r($this->dependency_map, true) |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - return $this->dependency_map; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return EE_Registry |
|
167 | - * @throws EE_Error |
|
168 | - */ |
|
169 | - public function registry() |
|
170 | - { |
|
171 | - if (! $this->registry instanceof EE_Registry) { |
|
172 | - throw new EE_Error( |
|
173 | - sprintf( |
|
174 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
175 | - print_r($this->registry, true) |
|
176 | - ) |
|
177 | - ); |
|
178 | - } |
|
179 | - return $this->registry; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return EE_Dependency_Map |
|
186 | - */ |
|
187 | - private function _load_dependency_map() |
|
188 | - { |
|
189 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
190 | - EE_Error::add_error( |
|
191 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
192 | - __FILE__, __FUNCTION__, __LINE__ |
|
193 | - ); |
|
194 | - wp_die(EE_Error::get_notices()); |
|
195 | - } |
|
196 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
197 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return EE_Registry |
|
204 | - */ |
|
205 | - private function _load_registry() |
|
206 | - { |
|
207 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
208 | - EE_Error::add_error( |
|
209 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
210 | - __FILE__, __FUNCTION__, __LINE__ |
|
211 | - ); |
|
212 | - wp_die(EE_Error::get_notices()); |
|
213 | - } |
|
214 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
215 | - return EE_Registry::instance($this->dependency_map); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @return void |
|
222 | - */ |
|
223 | - private function _load_class_tools() |
|
224 | - { |
|
225 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
226 | - EE_Error::add_error( |
|
227 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
228 | - __FILE__, __FUNCTION__, __LINE__ |
|
229 | - ); |
|
230 | - } |
|
231 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * called after the request stack has been fully processed |
|
238 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
239 | - * |
|
240 | - * @param EE_Request $request |
|
241 | - * @param EE_Response $response |
|
242 | - */ |
|
243 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
244 | - { |
|
245 | - if ($response->plugin_deactivated()) { |
|
246 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
247 | - } |
|
248 | - } |
|
27 | + /** |
|
28 | + * @type LoaderInterface $loader |
|
29 | + */ |
|
30 | + protected $loader; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Request $request |
|
34 | + */ |
|
35 | + protected $request; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Response $response |
|
39 | + */ |
|
40 | + protected $response; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Dependency_Map $dependency_map |
|
44 | + */ |
|
45 | + protected $dependency_map; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Registry $registry |
|
49 | + */ |
|
50 | + protected $registry; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * EE_Load_Espresso_Core constructor |
|
56 | + */ |
|
57 | + public function __construct() |
|
58 | + { |
|
59 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * handle |
|
66 | + * sets hooks for running rest of system |
|
67 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | + * starting EE Addons from any other point may lead to problems |
|
69 | + * |
|
70 | + * @param EE_Request $request |
|
71 | + * @param EE_Response $response |
|
72 | + * @return EE_Response |
|
73 | + * @throws EE_Error |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidArgumentException |
|
77 | + */ |
|
78 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
79 | + { |
|
80 | + $this->request = $request; |
|
81 | + $this->response = $response; |
|
82 | + // info about how to load classes required by other classes |
|
83 | + $this->dependency_map = $this->_load_dependency_map(); |
|
84 | + // central repository for classes |
|
85 | + $this->registry = $this->_load_registry(); |
|
86 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
87 | + // PSR4 Autoloaders |
|
88 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
89 | + $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader'); |
|
90 | + $this->dependency_map->setLoader($this->loader); |
|
91 | + // build DI container |
|
92 | + $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
93 | + $OpenCoffeeShop->addRecipes(); |
|
94 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
95 | + // create and cache the CommandBus, and also add middleware |
|
96 | + $this->registry->create( |
|
97 | + 'CommandBusInterface', |
|
98 | + array( |
|
99 | + null, |
|
100 | + apply_filters( |
|
101 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
102 | + array( |
|
103 | + $this->registry->create('CapChecker'), |
|
104 | + $this->registry->create('AddActionHook'), |
|
105 | + ) |
|
106 | + ), |
|
107 | + ), |
|
108 | + true |
|
109 | + ); |
|
110 | + // workarounds for PHP < 5.3 |
|
111 | + $this->_load_class_tools(); |
|
112 | + // load interfaces |
|
113 | + espresso_load_required('EEI_Payment_Method_Interfaces', |
|
114 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
115 | + // deprecated functions |
|
116 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
117 | + // WP cron jobs |
|
118 | + $this->registry->load_core('Cron_Tasks'); |
|
119 | + $this->registry->load_core('EE_Request_Handler'); |
|
120 | + $this->registry->load_core('EE_System'); |
|
121 | + return $this->response; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return EE_Request |
|
128 | + */ |
|
129 | + public function request() |
|
130 | + { |
|
131 | + return $this->request; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return EE_Response |
|
138 | + */ |
|
139 | + public function response() |
|
140 | + { |
|
141 | + return $this->response; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return EE_Dependency_Map |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + public function dependency_map() |
|
151 | + { |
|
152 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
153 | + throw new EE_Error( |
|
154 | + sprintf( |
|
155 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
156 | + print_r($this->dependency_map, true) |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + return $this->dependency_map; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return EE_Registry |
|
167 | + * @throws EE_Error |
|
168 | + */ |
|
169 | + public function registry() |
|
170 | + { |
|
171 | + if (! $this->registry instanceof EE_Registry) { |
|
172 | + throw new EE_Error( |
|
173 | + sprintf( |
|
174 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
175 | + print_r($this->registry, true) |
|
176 | + ) |
|
177 | + ); |
|
178 | + } |
|
179 | + return $this->registry; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return EE_Dependency_Map |
|
186 | + */ |
|
187 | + private function _load_dependency_map() |
|
188 | + { |
|
189 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
190 | + EE_Error::add_error( |
|
191 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
192 | + __FILE__, __FUNCTION__, __LINE__ |
|
193 | + ); |
|
194 | + wp_die(EE_Error::get_notices()); |
|
195 | + } |
|
196 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
197 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return EE_Registry |
|
204 | + */ |
|
205 | + private function _load_registry() |
|
206 | + { |
|
207 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
208 | + EE_Error::add_error( |
|
209 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
210 | + __FILE__, __FUNCTION__, __LINE__ |
|
211 | + ); |
|
212 | + wp_die(EE_Error::get_notices()); |
|
213 | + } |
|
214 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
215 | + return EE_Registry::instance($this->dependency_map); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @return void |
|
222 | + */ |
|
223 | + private function _load_class_tools() |
|
224 | + { |
|
225 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
226 | + EE_Error::add_error( |
|
227 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
228 | + __FILE__, __FUNCTION__, __LINE__ |
|
229 | + ); |
|
230 | + } |
|
231 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * called after the request stack has been fully processed |
|
238 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
239 | + * |
|
240 | + * @param EE_Request $request |
|
241 | + * @param EE_Response $response |
|
242 | + */ |
|
243 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
244 | + { |
|
245 | + if ($response->plugin_deactivated()) { |
|
246 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
247 | + } |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | 251 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function __construct() |
58 | 58 | { |
59 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
59 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | $this->_load_class_tools(); |
112 | 112 | // load interfaces |
113 | 113 | espresso_load_required('EEI_Payment_Method_Interfaces', |
114 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
114 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
115 | 115 | // deprecated functions |
116 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
116 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
117 | 117 | // WP cron jobs |
118 | 118 | $this->registry->load_core('Cron_Tasks'); |
119 | 119 | $this->registry->load_core('EE_Request_Handler'); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function dependency_map() |
151 | 151 | { |
152 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
152 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
153 | 153 | throw new EE_Error( |
154 | 154 | sprintf( |
155 | 155 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function registry() |
170 | 170 | { |
171 | - if (! $this->registry instanceof EE_Registry) { |
|
171 | + if ( ! $this->registry instanceof EE_Registry) { |
|
172 | 172 | throw new EE_Error( |
173 | 173 | sprintf( |
174 | 174 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function _load_dependency_map() |
188 | 188 | { |
189 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
189 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
190 | 190 | EE_Error::add_error( |
191 | 191 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
192 | 192 | __FILE__, __FUNCTION__, __LINE__ |
193 | 193 | ); |
194 | 194 | wp_die(EE_Error::get_notices()); |
195 | 195 | } |
196 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
196 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
197 | 197 | return EE_Dependency_Map::instance($this->request, $this->response); |
198 | 198 | } |
199 | 199 | |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | */ |
205 | 205 | private function _load_registry() |
206 | 206 | { |
207 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
207 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
208 | 208 | EE_Error::add_error( |
209 | 209 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
210 | 210 | __FILE__, __FUNCTION__, __LINE__ |
211 | 211 | ); |
212 | 212 | wp_die(EE_Error::get_notices()); |
213 | 213 | } |
214 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
214 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
215 | 215 | return EE_Registry::instance($this->dependency_map); |
216 | 216 | } |
217 | 217 | |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | */ |
223 | 223 | private function _load_class_tools() |
224 | 224 | { |
225 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
225 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
226 | 226 | EE_Error::add_error( |
227 | 227 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
228 | 228 | __FILE__, __FUNCTION__, __LINE__ |
229 | 229 | ); |
230 | 230 | } |
231 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
231 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use EventEspresso\core\services\commands\middleware\InvalidCommandBusMiddlewareException; |
8 | 8 | |
9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -40,78 +40,78 @@ discard block |
||
40 | 40 | class CommandBus implements CommandBusInterface |
41 | 41 | { |
42 | 42 | |
43 | - /** |
|
44 | - * @type CommandHandlerManagerInterface $command_handler_manager |
|
45 | - */ |
|
46 | - private $command_handler_manager; |
|
47 | - |
|
48 | - /** |
|
49 | - * @type CommandBusMiddlewareInterface[] $command_bus_middleware |
|
50 | - */ |
|
51 | - private $command_bus_middleware; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * CommandBus constructor |
|
57 | - * |
|
58 | - * @param CommandHandlerManagerInterface $command_handler_manager |
|
59 | - * @param CommandBusMiddlewareInterface[] $command_bus_middleware |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - CommandHandlerManagerInterface $command_handler_manager, |
|
63 | - $command_bus_middleware = array() |
|
64 | - ) { |
|
65 | - $this->command_handler_manager = $command_handler_manager; |
|
66 | - $this->command_bus_middleware = is_array($command_bus_middleware) |
|
67 | - ? $command_bus_middleware |
|
68 | - : array($command_bus_middleware); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return CommandHandlerManagerInterface |
|
75 | - */ |
|
76 | - public function getCommandHandlerManager() |
|
77 | - { |
|
78 | - return $this->command_handler_manager; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param CommandInterface $command |
|
85 | - * @return mixed |
|
86 | - * @throws InvalidDataTypeException |
|
87 | - * @throws InvalidCommandBusMiddlewareException |
|
88 | - */ |
|
89 | - public function execute($command) |
|
90 | - { |
|
91 | - if (! $command instanceof CommandInterface) { |
|
92 | - throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
93 | - } |
|
94 | - // we're going to add the Command Handler as a callable |
|
95 | - // that will get run at the end of our middleware stack |
|
96 | - // can't pass $this to a Closure, so use a named variable |
|
97 | - $command_bus = $this; |
|
98 | - $middleware = function ($command) use ($command_bus) { |
|
99 | - return $command_bus->getCommandHandlerManager() |
|
100 | - ->getCommandHandler($command, $command_bus) |
|
101 | - ->handle($command); |
|
102 | - }; |
|
103 | - // now build the rest of the middleware stack |
|
104 | - while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
|
105 | - if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
106 | - throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
|
107 | - } |
|
108 | - $middleware = function ($command) use ($command_bus_middleware, $middleware) { |
|
109 | - return $command_bus_middleware->handle($command, $middleware); |
|
110 | - }; |
|
111 | - } |
|
112 | - // and finally, pass the command into the stack and return the results |
|
113 | - return $middleware($command); |
|
114 | - } |
|
43 | + /** |
|
44 | + * @type CommandHandlerManagerInterface $command_handler_manager |
|
45 | + */ |
|
46 | + private $command_handler_manager; |
|
47 | + |
|
48 | + /** |
|
49 | + * @type CommandBusMiddlewareInterface[] $command_bus_middleware |
|
50 | + */ |
|
51 | + private $command_bus_middleware; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * CommandBus constructor |
|
57 | + * |
|
58 | + * @param CommandHandlerManagerInterface $command_handler_manager |
|
59 | + * @param CommandBusMiddlewareInterface[] $command_bus_middleware |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + CommandHandlerManagerInterface $command_handler_manager, |
|
63 | + $command_bus_middleware = array() |
|
64 | + ) { |
|
65 | + $this->command_handler_manager = $command_handler_manager; |
|
66 | + $this->command_bus_middleware = is_array($command_bus_middleware) |
|
67 | + ? $command_bus_middleware |
|
68 | + : array($command_bus_middleware); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return CommandHandlerManagerInterface |
|
75 | + */ |
|
76 | + public function getCommandHandlerManager() |
|
77 | + { |
|
78 | + return $this->command_handler_manager; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param CommandInterface $command |
|
85 | + * @return mixed |
|
86 | + * @throws InvalidDataTypeException |
|
87 | + * @throws InvalidCommandBusMiddlewareException |
|
88 | + */ |
|
89 | + public function execute($command) |
|
90 | + { |
|
91 | + if (! $command instanceof CommandInterface) { |
|
92 | + throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
93 | + } |
|
94 | + // we're going to add the Command Handler as a callable |
|
95 | + // that will get run at the end of our middleware stack |
|
96 | + // can't pass $this to a Closure, so use a named variable |
|
97 | + $command_bus = $this; |
|
98 | + $middleware = function ($command) use ($command_bus) { |
|
99 | + return $command_bus->getCommandHandlerManager() |
|
100 | + ->getCommandHandler($command, $command_bus) |
|
101 | + ->handle($command); |
|
102 | + }; |
|
103 | + // now build the rest of the middleware stack |
|
104 | + while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
|
105 | + if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
106 | + throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
|
107 | + } |
|
108 | + $middleware = function ($command) use ($command_bus_middleware, $middleware) { |
|
109 | + return $command_bus_middleware->handle($command, $middleware); |
|
110 | + }; |
|
111 | + } |
|
112 | + // and finally, pass the command into the stack and return the results |
|
113 | + return $middleware($command); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | 117 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use EventEspresso\core\services\commands\middleware\CommandBusMiddlewareInterface; |
7 | 7 | use EventEspresso\core\services\commands\middleware\InvalidCommandBusMiddlewareException; |
8 | 8 | |
9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | 10 | exit('No direct script access allowed'); |
11 | 11 | } |
12 | 12 | |
@@ -88,24 +88,24 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function execute($command) |
90 | 90 | { |
91 | - if (! $command instanceof CommandInterface) { |
|
92 | - throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
91 | + if ( ! $command instanceof CommandInterface) { |
|
92 | + throw new InvalidDataTypeException(__METHOD__.'( $command )', $command, 'CommandInterface'); |
|
93 | 93 | } |
94 | 94 | // we're going to add the Command Handler as a callable |
95 | 95 | // that will get run at the end of our middleware stack |
96 | 96 | // can't pass $this to a Closure, so use a named variable |
97 | 97 | $command_bus = $this; |
98 | - $middleware = function ($command) use ($command_bus) { |
|
98 | + $middleware = function($command) use ($command_bus) { |
|
99 | 99 | return $command_bus->getCommandHandlerManager() |
100 | 100 | ->getCommandHandler($command, $command_bus) |
101 | 101 | ->handle($command); |
102 | 102 | }; |
103 | 103 | // now build the rest of the middleware stack |
104 | 104 | while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
105 | - if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
105 | + if ( ! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
106 | 106 | throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
107 | 107 | } |
108 | - $middleware = function ($command) use ($command_bus_middleware, $middleware) { |
|
108 | + $middleware = function($command) use ($command_bus_middleware, $middleware) { |
|
109 | 109 | return $command_bus_middleware->handle($command, $middleware); |
110 | 110 | }; |
111 | 111 | } |
@@ -24,40 +24,40 @@ |
||
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var LoaderInterface $loader |
|
29 | - */ |
|
30 | - private $loader; |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * CommandFactory constructor |
|
36 | - * |
|
37 | - * @param LoaderInterface $loader |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidInterfaceException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public function __construct(LoaderInterface $loader = null) |
|
43 | - { |
|
44 | - $this->loader = $loader; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param string $command_fqcn |
|
51 | - * @param array $arguments |
|
52 | - * @return mixed |
|
53 | - * @throws InvalidArgumentException |
|
54 | - * @throws InvalidDataTypeException |
|
55 | - * @throws InvalidInterfaceException |
|
56 | - */ |
|
57 | - public function getNew($command_fqcn, $arguments = array()) |
|
58 | - { |
|
59 | - return $this->loader->getNew($command_fqcn, $arguments); |
|
60 | - } |
|
27 | + /** |
|
28 | + * @var LoaderInterface $loader |
|
29 | + */ |
|
30 | + private $loader; |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * CommandFactory constructor |
|
36 | + * |
|
37 | + * @param LoaderInterface $loader |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidInterfaceException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public function __construct(LoaderInterface $loader = null) |
|
43 | + { |
|
44 | + $this->loader = $loader; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param string $command_fqcn |
|
51 | + * @param array $arguments |
|
52 | + * @return mixed |
|
53 | + * @throws InvalidArgumentException |
|
54 | + * @throws InvalidDataTypeException |
|
55 | + * @throws InvalidInterfaceException |
|
56 | + */ |
|
57 | + public function getNew($command_fqcn, $arguments = array()) |
|
58 | + { |
|
59 | + return $this->loader->getNew($command_fqcn, $arguments); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 |
@@ -13,15 +13,15 @@ |
||
13 | 13 | interface CommandFactoryInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param string $command_fqcn |
|
18 | - * @param array $arguments |
|
19 | - * @return mixed |
|
20 | - * @throws InvalidArgumentException |
|
21 | - * @throws InvalidDataTypeException |
|
22 | - * @throws InvalidInterfaceException |
|
23 | - */ |
|
24 | - public function getNew($command_fqcn, $arguments = array()); |
|
16 | + /** |
|
17 | + * @param string $command_fqcn |
|
18 | + * @param array $arguments |
|
19 | + * @return mixed |
|
20 | + * @throws InvalidArgumentException |
|
21 | + * @throws InvalidDataTypeException |
|
22 | + * @throws InvalidInterfaceException |
|
23 | + */ |
|
24 | + public function getNew($command_fqcn, $arguments = array()); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | // End of file CommandFactoryInterface.php |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use EventEspresso\core\services\loaders\LoaderInterface; |
7 | 7 | |
8 | 8 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
9 | - exit('No direct script access allowed'); |
|
9 | + exit('No direct script access allowed'); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | |
@@ -24,109 +24,109 @@ discard block |
||
24 | 24 | class CommandHandlerManager implements CommandHandlerManagerInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var CommandHandlerInterface[] $command_handlers |
|
29 | - */ |
|
30 | - protected $command_handlers; |
|
31 | - |
|
32 | - /** |
|
33 | - * @type LoaderInterface $loader |
|
34 | - */ |
|
35 | - private $loader; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * CommandHandlerManager constructor |
|
41 | - * |
|
42 | - * @param LoaderInterface $loader |
|
43 | - */ |
|
44 | - public function __construct(LoaderInterface $loader) |
|
45 | - { |
|
46 | - $this->loader = $loader; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * By default, Commands and CommandHandlers would normally |
|
53 | - * reside in the same folder under the same namespace, |
|
54 | - * and the names of the two classes would only differ in that |
|
55 | - * one ends in "Command" and the other ends in "CommandHandler". |
|
56 | - * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
57 | - * then this method allows you to add that CommandHandler and specify the FQCN |
|
58 | - * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
59 | - * For example: |
|
60 | - * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
61 | - * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
62 | - * but if you wanted to instead process that commend using: |
|
63 | - * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
64 | - * then the following code: |
|
65 | - * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
66 | - * $CommandHandlerManager->addCommandHandler( |
|
67 | - * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
68 | - * 'Vendor\some\namespace\DoSomethingCommand' |
|
69 | - * ); |
|
70 | - * would result in the alternate CommandHandler being used to process that Command |
|
71 | - * |
|
72 | - * @param CommandHandlerInterface $command_handler |
|
73 | - * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
74 | - * @return void |
|
75 | - * @throws InvalidCommandHandlerException |
|
76 | - */ |
|
77 | - public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
78 | - { |
|
79 | - $command = ! empty($fqcn_for_command) |
|
80 | - ? $fqcn_for_command |
|
81 | - : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
82 | - if (empty($command)) { |
|
83 | - throw new InvalidCommandHandlerException($command); |
|
84 | - } |
|
85 | - $this->command_handlers[$command] = $command_handler; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param CommandInterface $command |
|
92 | - * @param CommandBusInterface $command_bus |
|
93 | - * @return mixed |
|
94 | - * @throws DomainException |
|
95 | - * @throws CommandHandlerNotFoundException |
|
96 | - */ |
|
97 | - public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
98 | - { |
|
99 | - $command_name = get_class($command); |
|
100 | - $command_handler = apply_filters( |
|
101 | - 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
102 | - str_replace('Command', 'CommandHandler', $command_name), |
|
103 | - $command |
|
104 | - ); |
|
105 | - $handler = null; |
|
106 | - // has a command handler already been set for this class ? |
|
107 | - // if not, can we find one via the FQCN ? |
|
108 | - if (isset($this->command_handlers[$command_name])) { |
|
109 | - $handler = $this->command_handlers[$command_name]; |
|
110 | - } else if (class_exists($command_handler)) { |
|
111 | - $handler = $this->loader->getShared($command_handler); |
|
112 | - } |
|
113 | - // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
114 | - if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
115 | - if (! $command_bus instanceof CommandBusInterface) { |
|
116 | - throw new DomainException( |
|
117 | - esc_html__( |
|
118 | - 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
119 | - 'event_espresso' |
|
120 | - ) |
|
121 | - ); |
|
122 | - } |
|
123 | - $handler->setCommandBus($command_bus); |
|
124 | - } |
|
125 | - if ($handler instanceof CommandHandlerInterface) { |
|
126 | - return $handler; |
|
127 | - } |
|
128 | - throw new CommandHandlerNotFoundException($command_handler); |
|
129 | - } |
|
27 | + /** |
|
28 | + * @var CommandHandlerInterface[] $command_handlers |
|
29 | + */ |
|
30 | + protected $command_handlers; |
|
31 | + |
|
32 | + /** |
|
33 | + * @type LoaderInterface $loader |
|
34 | + */ |
|
35 | + private $loader; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * CommandHandlerManager constructor |
|
41 | + * |
|
42 | + * @param LoaderInterface $loader |
|
43 | + */ |
|
44 | + public function __construct(LoaderInterface $loader) |
|
45 | + { |
|
46 | + $this->loader = $loader; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * By default, Commands and CommandHandlers would normally |
|
53 | + * reside in the same folder under the same namespace, |
|
54 | + * and the names of the two classes would only differ in that |
|
55 | + * one ends in "Command" and the other ends in "CommandHandler". |
|
56 | + * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
57 | + * then this method allows you to add that CommandHandler and specify the FQCN |
|
58 | + * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
59 | + * For example: |
|
60 | + * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
61 | + * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
62 | + * but if you wanted to instead process that commend using: |
|
63 | + * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
64 | + * then the following code: |
|
65 | + * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
66 | + * $CommandHandlerManager->addCommandHandler( |
|
67 | + * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
68 | + * 'Vendor\some\namespace\DoSomethingCommand' |
|
69 | + * ); |
|
70 | + * would result in the alternate CommandHandler being used to process that Command |
|
71 | + * |
|
72 | + * @param CommandHandlerInterface $command_handler |
|
73 | + * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
74 | + * @return void |
|
75 | + * @throws InvalidCommandHandlerException |
|
76 | + */ |
|
77 | + public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
78 | + { |
|
79 | + $command = ! empty($fqcn_for_command) |
|
80 | + ? $fqcn_for_command |
|
81 | + : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
82 | + if (empty($command)) { |
|
83 | + throw new InvalidCommandHandlerException($command); |
|
84 | + } |
|
85 | + $this->command_handlers[$command] = $command_handler; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param CommandInterface $command |
|
92 | + * @param CommandBusInterface $command_bus |
|
93 | + * @return mixed |
|
94 | + * @throws DomainException |
|
95 | + * @throws CommandHandlerNotFoundException |
|
96 | + */ |
|
97 | + public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
98 | + { |
|
99 | + $command_name = get_class($command); |
|
100 | + $command_handler = apply_filters( |
|
101 | + 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
102 | + str_replace('Command', 'CommandHandler', $command_name), |
|
103 | + $command |
|
104 | + ); |
|
105 | + $handler = null; |
|
106 | + // has a command handler already been set for this class ? |
|
107 | + // if not, can we find one via the FQCN ? |
|
108 | + if (isset($this->command_handlers[$command_name])) { |
|
109 | + $handler = $this->command_handlers[$command_name]; |
|
110 | + } else if (class_exists($command_handler)) { |
|
111 | + $handler = $this->loader->getShared($command_handler); |
|
112 | + } |
|
113 | + // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
114 | + if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
115 | + if (! $command_bus instanceof CommandBusInterface) { |
|
116 | + throw new DomainException( |
|
117 | + esc_html__( |
|
118 | + 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
119 | + 'event_espresso' |
|
120 | + ) |
|
121 | + ); |
|
122 | + } |
|
123 | + $handler->setCommandBus($command_bus); |
|
124 | + } |
|
125 | + if ($handler instanceof CommandHandlerInterface) { |
|
126 | + return $handler; |
|
127 | + } |
|
128 | + throw new CommandHandlerNotFoundException($command_handler); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | 132 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use DomainException; |
6 | 6 | use EventEspresso\core\services\loaders\LoaderInterface; |
7 | 7 | |
8 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | 9 | exit('No direct script access allowed'); |
10 | 10 | } |
11 | 11 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | // if Handler requires an instance of the CommandBus, but that has not yet been set |
114 | 114 | if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
115 | - if (! $command_bus instanceof CommandBusInterface) { |
|
115 | + if ( ! $command_bus instanceof CommandBusInterface) { |
|
116 | 116 | throw new DomainException( |
117 | 117 | esc_html__( |
118 | 118 | 'CompositeCommandHandler classes require an instance of the CommandBus.', |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace EventEspresso\core\services\commands; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -21,59 +21,59 @@ discard block |
||
21 | 21 | abstract class CompositeCommandHandler extends CommandHandler |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @type CommandBusInterface $command_bus |
|
26 | - */ |
|
27 | - private $command_bus; |
|
24 | + /** |
|
25 | + * @type CommandBusInterface $command_bus |
|
26 | + */ |
|
27 | + private $command_bus; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @type CommandFactoryInterface $command_factory |
|
31 | - */ |
|
32 | - private $command_factory; |
|
29 | + /** |
|
30 | + * @type CommandFactoryInterface $command_factory |
|
31 | + */ |
|
32 | + private $command_factory; |
|
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * CompositeCommandHandler constructor. |
|
38 | - * |
|
39 | - * @param CommandBusInterface $command_bus |
|
40 | - * @param CommandFactoryInterface $command_factory |
|
41 | - */ |
|
42 | - public function __construct(CommandBusInterface $command_bus, CommandFactoryInterface $command_factory) |
|
43 | - { |
|
44 | - $this->command_bus = $command_bus; |
|
45 | - $this->command_factory = $command_factory; |
|
46 | - } |
|
36 | + /** |
|
37 | + * CompositeCommandHandler constructor. |
|
38 | + * |
|
39 | + * @param CommandBusInterface $command_bus |
|
40 | + * @param CommandFactoryInterface $command_factory |
|
41 | + */ |
|
42 | + public function __construct(CommandBusInterface $command_bus, CommandFactoryInterface $command_factory) |
|
43 | + { |
|
44 | + $this->command_bus = $command_bus; |
|
45 | + $this->command_factory = $command_factory; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param CommandBusInterface $command_bus |
|
52 | - */ |
|
53 | - public function setCommandBus(CommandBusInterface $command_bus) |
|
54 | - { |
|
55 | - $this->command_bus = $command_bus; |
|
56 | - } |
|
50 | + /** |
|
51 | + * @param CommandBusInterface $command_bus |
|
52 | + */ |
|
53 | + public function setCommandBus(CommandBusInterface $command_bus) |
|
54 | + { |
|
55 | + $this->command_bus = $command_bus; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @return CommandBusInterface |
|
62 | - */ |
|
63 | - public function commandBus() |
|
64 | - { |
|
65 | - return $this->command_bus; |
|
66 | - } |
|
60 | + /** |
|
61 | + * @return CommandBusInterface |
|
62 | + */ |
|
63 | + public function commandBus() |
|
64 | + { |
|
65 | + return $this->command_bus; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @return CommandFactoryInterface |
|
72 | - */ |
|
73 | - public function commandFactory() |
|
74 | - { |
|
75 | - return $this->command_factory; |
|
76 | - } |
|
70 | + /** |
|
71 | + * @return CommandFactoryInterface |
|
72 | + */ |
|
73 | + public function commandFactory() |
|
74 | + { |
|
75 | + return $this->command_factory; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 |