@@ -21,1024 +21,1024 @@ |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = []; |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = []; |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - * @throws InvalidAliasException |
|
109 | - */ |
|
110 | - public function initialize() |
|
111 | - { |
|
112 | - $this->_register_core_dependencies(); |
|
113 | - $this->_register_core_class_loaders(); |
|
114 | - $this->_register_core_aliases(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @singleton method used to instantiate class object |
|
120 | - * @param ClassInterfaceCache|null $class_cache |
|
121 | - * @return EE_Dependency_Map |
|
122 | - */ |
|
123 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
124 | - { |
|
125 | - // check if class object is instantiated, and instantiated properly |
|
126 | - if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
127 | - && $class_cache instanceof ClassInterfaceCache |
|
128 | - ) { |
|
129 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
130 | - } |
|
131 | - return EE_Dependency_Map::$_instance; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param RequestInterface $request |
|
137 | - */ |
|
138 | - public function setRequest(RequestInterface $request) |
|
139 | - { |
|
140 | - $this->request = $request; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param LegacyRequestInterface $legacy_request |
|
146 | - */ |
|
147 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
148 | - { |
|
149 | - $this->legacy_request = $legacy_request; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param ResponseInterface $response |
|
155 | - */ |
|
156 | - public function setResponse(ResponseInterface $response) |
|
157 | - { |
|
158 | - $this->response = $response; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param LoaderInterface $loader |
|
164 | - */ |
|
165 | - public function setLoader(LoaderInterface $loader) |
|
166 | - { |
|
167 | - $this->loader = $loader; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $class |
|
173 | - * @param array $dependencies |
|
174 | - * @param int $overwrite |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public static function register_dependencies( |
|
178 | - $class, |
|
179 | - array $dependencies, |
|
180 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
181 | - ) { |
|
182 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
188 | - * to the class specified by the first parameter. |
|
189 | - * IMPORTANT !!! |
|
190 | - * The order of elements in the incoming $dependencies array MUST match |
|
191 | - * the order of the constructor parameters for the class in question. |
|
192 | - * This is especially important when overriding any existing dependencies that are registered. |
|
193 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
194 | - * |
|
195 | - * @param string $class |
|
196 | - * @param array $dependencies |
|
197 | - * @param int $overwrite |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function registerDependencies( |
|
201 | - $class, |
|
202 | - array $dependencies, |
|
203 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
204 | - ) { |
|
205 | - $class = trim($class, '\\'); |
|
206 | - $registered = false; |
|
207 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
208 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
209 | - } |
|
210 | - // we need to make sure that any aliases used when registering a dependency |
|
211 | - // get resolved to the correct class name |
|
212 | - foreach ($dependencies as $dependency => $load_source) { |
|
213 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
214 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
215 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
216 | - ) { |
|
217 | - unset($dependencies[ $dependency ]); |
|
218 | - $dependencies[ $alias ] = $load_source; |
|
219 | - $registered = true; |
|
220 | - } |
|
221 | - } |
|
222 | - // now add our two lists of dependencies together. |
|
223 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
224 | - // so $dependencies is NOT overwritten because it is listed first |
|
225 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
226 | - // Union is way faster than array_merge() but should be used with caution... |
|
227 | - // especially with numerically indexed arrays |
|
228 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
229 | - // now we need to ensure that the resulting dependencies |
|
230 | - // array only has the entries that are required for the class |
|
231 | - // so first count how many dependencies were originally registered for the class |
|
232 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
233 | - // if that count is non-zero (meaning dependencies were already registered) |
|
234 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
235 | - // then truncate the final array to match that count |
|
236 | - ? array_slice($dependencies, 0, $dependency_count) |
|
237 | - // otherwise just take the incoming array because nothing previously existed |
|
238 | - : $dependencies; |
|
239 | - return $registered; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $class_name |
|
245 | - * @param string $loader |
|
246 | - * @return bool |
|
247 | - * @throws DomainException |
|
248 | - */ |
|
249 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
250 | - { |
|
251 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $class_name |
|
257 | - * @param string $loader |
|
258 | - * @return bool |
|
259 | - * @throws DomainException |
|
260 | - */ |
|
261 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
262 | - { |
|
263 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
264 | - throw new DomainException( |
|
265 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
266 | - ); |
|
267 | - } |
|
268 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
269 | - if (! is_callable($loader) |
|
270 | - && ( |
|
271 | - strpos($loader, 'load_') !== 0 |
|
272 | - || ! method_exists('EE_Registry', $loader) |
|
273 | - ) |
|
274 | - ) { |
|
275 | - throw new DomainException( |
|
276 | - sprintf( |
|
277 | - esc_html__( |
|
278 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - $loader |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
286 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
287 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
288 | - return true; |
|
289 | - } |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return array |
|
296 | - */ |
|
297 | - public function dependency_map() |
|
298 | - { |
|
299 | - return $this->_dependency_map; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | - * |
|
306 | - * @param string $class_name |
|
307 | - * @return boolean |
|
308 | - */ |
|
309 | - public function has($class_name = '') |
|
310 | - { |
|
311 | - // all legacy models have the same dependencies |
|
312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
313 | - $class_name = 'LEGACY_MODELS'; |
|
314 | - } |
|
315 | - return isset($this->_dependency_map[ $class_name ]); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
321 | - * |
|
322 | - * @param string $class_name |
|
323 | - * @param string $dependency |
|
324 | - * @return bool |
|
325 | - */ |
|
326 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
327 | - { |
|
328 | - // all legacy models have the same dependencies |
|
329 | - if (strpos($class_name, 'EEM_') === 0) { |
|
330 | - $class_name = 'LEGACY_MODELS'; |
|
331 | - } |
|
332 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
333 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
339 | - * |
|
340 | - * @param string $class_name |
|
341 | - * @param string $dependency |
|
342 | - * @return int |
|
343 | - */ |
|
344 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
345 | - { |
|
346 | - // all legacy models have the same dependencies |
|
347 | - if (strpos($class_name, 'EEM_') === 0) { |
|
348 | - $class_name = 'LEGACY_MODELS'; |
|
349 | - } |
|
350 | - $dependency = $this->getFqnForAlias($dependency); |
|
351 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
352 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
353 | - : EE_Dependency_Map::not_registered; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $class_name |
|
359 | - * @return string | Closure |
|
360 | - */ |
|
361 | - public function class_loader($class_name) |
|
362 | - { |
|
363 | - // all legacy models use load_model() |
|
364 | - if (strpos($class_name, 'EEM_') === 0) { |
|
365 | - return 'load_model'; |
|
366 | - } |
|
367 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
368 | - // perform strpos() first to avoid loading regex every time we load a class |
|
369 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
370 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
371 | - ) { |
|
372 | - return 'load_core'; |
|
373 | - } |
|
374 | - $class_name = $this->getFqnForAlias($class_name); |
|
375 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function class_loaders() |
|
383 | - { |
|
384 | - return $this->_class_loaders; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * adds an alias for a classname |
|
390 | - * |
|
391 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | - * @throws InvalidAliasException |
|
395 | - */ |
|
396 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | - { |
|
398 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
404 | - * WHY? |
|
405 | - * Because if a class is type hinting for a concretion, |
|
406 | - * then why would we need to find another class to supply it? |
|
407 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
408 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
409 | - * Don't go looking for some substitute. |
|
410 | - * Whereas if a class is type hinting for an interface... |
|
411 | - * then we need to find an actual class to use. |
|
412 | - * So the interface IS the alias for some other FQN, |
|
413 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
414 | - * represents some other class. |
|
415 | - * |
|
416 | - * @param string $fqn |
|
417 | - * @param string $for_class |
|
418 | - * @return bool |
|
419 | - */ |
|
420 | - public function isAlias($fqn = '', $for_class = '') |
|
421 | - { |
|
422 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
428 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
429 | - * for example: |
|
430 | - * if the following two entries were added to the _aliases array: |
|
431 | - * array( |
|
432 | - * 'interface_alias' => 'some\namespace\interface' |
|
433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | - * ) |
|
435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | - * to load an instance of 'some\namespace\classname' |
|
437 | - * |
|
438 | - * @param string $alias |
|
439 | - * @param string $for_class |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
443 | - { |
|
444 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
450 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
451 | - * This is done by using the following class constants: |
|
452 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
453 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
454 | - */ |
|
455 | - protected function _register_core_dependencies() |
|
456 | - { |
|
457 | - $this->_dependency_map = [ |
|
458 | - 'EE_Request_Handler' => [ |
|
459 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
460 | - ], |
|
461 | - 'EE_System' => [ |
|
462 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
464 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
465 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
467 | - ], |
|
468 | - 'EE_Admin' => [ |
|
469 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | - ], |
|
472 | - 'EE_Cart' => [ |
|
473 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
474 | - ], |
|
475 | - 'EE_Messenger_Collection_Loader' => [ |
|
476 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | - ], |
|
478 | - 'EE_Message_Type_Collection_Loader' => [ |
|
479 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | - ], |
|
481 | - 'EE_Message_Resource_Manager' => [ |
|
482 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | - ], |
|
486 | - 'EE_Message_Factory' => [ |
|
487 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ], |
|
489 | - 'EE_messages' => [ |
|
490 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | - ], |
|
492 | - 'EE_Messages_Generator' => [ |
|
493 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | - ], |
|
498 | - 'EE_Messages_Processor' => [ |
|
499 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ], |
|
501 | - 'EE_Messages_Queue' => [ |
|
502 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | - ], |
|
504 | - 'EE_Messages_Template_Defaults' => [ |
|
505 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | - ], |
|
508 | - 'EE_Message_To_Generate_From_Request' => [ |
|
509 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | - ], |
|
512 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
513 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | - ], |
|
515 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
516 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | - ], |
|
519 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
520 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | - ], |
|
522 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
523 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | - ], |
|
526 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
527 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | - ], |
|
529 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
530 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | - ], |
|
532 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
533 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | - ], |
|
535 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
536 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | - ], |
|
538 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
539 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | - ], |
|
541 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
542 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | - ], |
|
544 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
545 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | - ], |
|
547 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
548 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | - ], |
|
550 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
551 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | - ], |
|
553 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
554 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | - ], |
|
556 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
557 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | - ], |
|
559 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
560 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | - ], |
|
562 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
563 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | - ], |
|
565 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - ], |
|
568 | - 'EE_Data_Migration_Class_Base' => [ |
|
569 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | - ], |
|
572 | - 'EE_DMS_Core_4_1_0' => [ |
|
573 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | - ], |
|
576 | - 'EE_DMS_Core_4_2_0' => [ |
|
577 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | - ], |
|
580 | - 'EE_DMS_Core_4_3_0' => [ |
|
581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ], |
|
584 | - 'EE_DMS_Core_4_4_0' => [ |
|
585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | - ], |
|
588 | - 'EE_DMS_Core_4_5_0' => [ |
|
589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | - ], |
|
592 | - 'EE_DMS_Core_4_6_0' => [ |
|
593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ], |
|
596 | - 'EE_DMS_Core_4_7_0' => [ |
|
597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | - ], |
|
600 | - 'EE_DMS_Core_4_8_0' => [ |
|
601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | - ], |
|
604 | - 'EE_DMS_Core_4_9_0' => [ |
|
605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | - ], |
|
608 | - 'EE_DMS_Core_4_10_0' => [ |
|
609 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
610 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
611 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
612 | - ], |
|
613 | - 'EE_DMS_Core_4_11_0' => [ |
|
614 | - 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
615 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | - ], |
|
618 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
619 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
620 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
621 | - ], |
|
622 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | - ], |
|
625 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
626 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
627 | - ], |
|
628 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
629 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
630 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
631 | - ], |
|
632 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
633 | - null, |
|
634 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
635 | - ], |
|
636 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
637 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
638 | - ], |
|
639 | - 'LEGACY_MODELS' => [ |
|
640 | - null, |
|
641 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
642 | - ], |
|
643 | - 'EE_Module_Request_Router' => [ |
|
644 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
645 | - ], |
|
646 | - 'EE_Registration_Processor' => [ |
|
647 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
648 | - ], |
|
649 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
650 | - null, |
|
651 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
652 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
653 | - ], |
|
654 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
655 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
656 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
657 | - ], |
|
658 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
659 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
660 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
661 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
662 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
663 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
664 | - ], |
|
665 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
666 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
667 | - ], |
|
668 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
669 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
670 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
671 | - ], |
|
672 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
673 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
674 | - ], |
|
675 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
676 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
677 | - ], |
|
678 | - 'EE_CPT_Strategy' => [ |
|
679 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
681 | - ], |
|
682 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
683 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
684 | - ], |
|
685 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
686 | - null, |
|
687 | - null, |
|
688 | - null, |
|
689 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
692 | - ], |
|
693 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
694 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
695 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
696 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
697 | - ], |
|
698 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
699 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
700 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
701 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
702 | - ], |
|
703 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
704 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
705 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
706 | - ], |
|
707 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
708 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
709 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
710 | - ], |
|
711 | - 'EE_URL_Validation_Strategy' => [ |
|
712 | - null, |
|
713 | - null, |
|
714 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
715 | - ], |
|
716 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
717 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
718 | - ], |
|
719 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | - ], |
|
722 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
723 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
724 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
725 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
726 | - null, |
|
727 | - ], |
|
728 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
729 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
731 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
733 | - ], |
|
734 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
735 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
736 | - ], |
|
737 | - 'EventEspresso\core\services\routing\Router' => [ |
|
738 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
741 | - ], |
|
742 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
743 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
744 | - ], |
|
745 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
746 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
747 | - ], |
|
748 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
749 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
750 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
751 | - ], |
|
752 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
753 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
754 | - ], |
|
755 | - 'EventEspresso\core\services\addon\AddonManager' => [ |
|
756 | - 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
757 | - 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
758 | - 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
759 | - 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
760 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
761 | - ], |
|
762 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
763 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
764 | - ], |
|
765 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => [ |
|
766 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
767 | - ], |
|
768 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => [ |
|
769 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache |
|
770 | - ], |
|
771 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => [ |
|
772 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache] |
|
773 | - ]; |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - /** |
|
778 | - * Registers how core classes are loaded. |
|
779 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
780 | - * 'EE_Request_Handler' => 'load_core' |
|
781 | - * 'EE_Messages_Queue' => 'load_lib' |
|
782 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
783 | - * or, if greater control is required, by providing a custom closure. For example: |
|
784 | - * 'Some_Class' => function () { |
|
785 | - * return new Some_Class(); |
|
786 | - * }, |
|
787 | - * This is required for instantiating dependencies |
|
788 | - * where an interface has been type hinted in a class constructor. For example: |
|
789 | - * 'Required_Interface' => function () { |
|
790 | - * return new A_Class_That_Implements_Required_Interface(); |
|
791 | - * }, |
|
792 | - */ |
|
793 | - protected function _register_core_class_loaders() |
|
794 | - { |
|
795 | - $this->_class_loaders = [ |
|
796 | - // load_core |
|
797 | - 'EE_Dependency_Map' => function () { |
|
798 | - return $this; |
|
799 | - }, |
|
800 | - 'EE_Capabilities' => 'load_core', |
|
801 | - 'EE_Encryption' => 'load_core', |
|
802 | - 'EE_Front_Controller' => 'load_core', |
|
803 | - 'EE_Module_Request_Router' => 'load_core', |
|
804 | - 'EE_Registry' => 'load_core', |
|
805 | - 'EE_Request' => function () { |
|
806 | - return $this->legacy_request; |
|
807 | - }, |
|
808 | - 'EventEspresso\core\services\request\Request' => function () { |
|
809 | - return $this->request; |
|
810 | - }, |
|
811 | - 'EventEspresso\core\services\request\Response' => function () { |
|
812 | - return $this->response; |
|
813 | - }, |
|
814 | - 'EE_Base' => 'load_core', |
|
815 | - 'EE_Request_Handler' => 'load_core', |
|
816 | - 'EE_Session' => 'load_core', |
|
817 | - 'EE_Cron_Tasks' => 'load_core', |
|
818 | - 'EE_System' => 'load_core', |
|
819 | - 'EE_Maintenance_Mode' => 'load_core', |
|
820 | - 'EE_Register_CPTs' => 'load_core', |
|
821 | - 'EE_Admin' => 'load_core', |
|
822 | - 'EE_CPT_Strategy' => 'load_core', |
|
823 | - // load_class |
|
824 | - 'EE_Registration_Processor' => 'load_class', |
|
825 | - // load_lib |
|
826 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
827 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
828 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
829 | - 'EE_Messenger_Collection' => 'load_lib', |
|
830 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
831 | - 'EE_Messages_Processor' => 'load_lib', |
|
832 | - 'EE_Message_Repository' => 'load_lib', |
|
833 | - 'EE_Messages_Queue' => 'load_lib', |
|
834 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
835 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
836 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
837 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
838 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
839 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
840 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
841 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
842 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
843 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
844 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
845 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
846 | - 'EE_Messages_Generator' => static function () { |
|
847 | - return EE_Registry::instance()->load_lib( |
|
848 | - 'Messages_Generator', |
|
849 | - [], |
|
850 | - false, |
|
851 | - false |
|
852 | - ); |
|
853 | - }, |
|
854 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
855 | - return EE_Registry::instance()->load_lib( |
|
856 | - 'Messages_Template_Defaults', |
|
857 | - $arguments, |
|
858 | - false, |
|
859 | - false |
|
860 | - ); |
|
861 | - }, |
|
862 | - // load_helper |
|
863 | - 'EEH_Parse_Shortcodes' => static function () { |
|
864 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
865 | - return new EEH_Parse_Shortcodes(); |
|
866 | - } |
|
867 | - return null; |
|
868 | - }, |
|
869 | - 'EE_Template_Config' => static function () { |
|
870 | - return EE_Config::instance()->template_settings; |
|
871 | - }, |
|
872 | - 'EE_Currency_Config' => static function () { |
|
873 | - return EE_Config::instance()->currency; |
|
874 | - }, |
|
875 | - 'EE_Registration_Config' => static function () { |
|
876 | - return EE_Config::instance()->registration; |
|
877 | - }, |
|
878 | - 'EE_Core_Config' => static function () { |
|
879 | - return EE_Config::instance()->core; |
|
880 | - }, |
|
881 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
882 | - return LoaderFactory::getLoader(); |
|
883 | - }, |
|
884 | - 'EE_Network_Config' => static function () { |
|
885 | - return EE_Network_Config::instance(); |
|
886 | - }, |
|
887 | - 'EE_Config' => static function () { |
|
888 | - return EE_Config::instance(); |
|
889 | - }, |
|
890 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
891 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
892 | - }, |
|
893 | - 'EE_Admin_Config' => static function () { |
|
894 | - return EE_Config::instance()->admin; |
|
895 | - }, |
|
896 | - 'EE_Organization_Config' => static function () { |
|
897 | - return EE_Config::instance()->organization; |
|
898 | - }, |
|
899 | - 'EE_Network_Core_Config' => static function () { |
|
900 | - return EE_Network_Config::instance()->core; |
|
901 | - }, |
|
902 | - 'EE_Environment_Config' => static function () { |
|
903 | - return EE_Config::instance()->environment; |
|
904 | - }, |
|
905 | - 'EED_Core_Rest_Api' => static function () { |
|
906 | - return EED_Core_Rest_Api::instance(); |
|
907 | - }, |
|
908 | - 'WP_REST_Server' => static function () { |
|
909 | - return rest_get_server(); |
|
910 | - }, |
|
911 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
912 | - return EE_Psr4AutoloaderInit::psr4_loader(); |
|
913 | - }, |
|
914 | - ]; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * can be used for supplying alternate names for classes, |
|
920 | - * or for connecting interface names to instantiable classes |
|
921 | - * |
|
922 | - * @throws InvalidAliasException |
|
923 | - */ |
|
924 | - protected function _register_core_aliases() |
|
925 | - { |
|
926 | - $aliases = [ |
|
927 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
928 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
929 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
930 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
931 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
932 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
933 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
934 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
935 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
936 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
937 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
938 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
939 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
940 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
941 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
942 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
943 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
944 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
945 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
946 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
947 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
948 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
949 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
950 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
951 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
952 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
953 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
954 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
955 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
956 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
957 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
958 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
959 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
960 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
961 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
962 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
963 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
964 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
965 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
966 | - ]; |
|
967 | - foreach ($aliases as $alias => $fqn) { |
|
968 | - if (is_array($fqn)) { |
|
969 | - foreach ($fqn as $class => $for_class) { |
|
970 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
971 | - } |
|
972 | - continue; |
|
973 | - } |
|
974 | - $this->class_cache->addAlias($fqn, $alias); |
|
975 | - } |
|
976 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
977 | - $this->class_cache->addAlias( |
|
978 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
979 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
980 | - ); |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
987 | - * request Primarily used by unit tests. |
|
988 | - */ |
|
989 | - public function reset() |
|
990 | - { |
|
991 | - $this->_register_core_class_loaders(); |
|
992 | - $this->_register_core_dependencies(); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
998 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
999 | - * WHY? |
|
1000 | - * Because if a class is type hinting for a concretion, |
|
1001 | - * then why would we need to find another class to supply it? |
|
1002 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1003 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1004 | - * Don't go looking for some substitute. |
|
1005 | - * Whereas if a class is type hinting for an interface... |
|
1006 | - * then we need to find an actual class to use. |
|
1007 | - * So the interface IS the alias for some other FQN, |
|
1008 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1009 | - * represents some other class. |
|
1010 | - * |
|
1011 | - * @param string $fqn |
|
1012 | - * @param string $for_class |
|
1013 | - * @return bool |
|
1014 | - * @deprecated 4.9.62.p |
|
1015 | - */ |
|
1016 | - public function has_alias($fqn = '', $for_class = '') |
|
1017 | - { |
|
1018 | - return $this->isAlias($fqn, $for_class); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1024 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1025 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1026 | - * for example: |
|
1027 | - * if the following two entries were added to the _aliases array: |
|
1028 | - * array( |
|
1029 | - * 'interface_alias' => 'some\namespace\interface' |
|
1030 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1031 | - * ) |
|
1032 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1033 | - * to load an instance of 'some\namespace\classname' |
|
1034 | - * |
|
1035 | - * @param string $alias |
|
1036 | - * @param string $for_class |
|
1037 | - * @return string |
|
1038 | - * @deprecated 4.9.62.p |
|
1039 | - */ |
|
1040 | - public function get_alias($alias = '', $for_class = '') |
|
1041 | - { |
|
1042 | - return $this->getFqnForAlias($alias, $for_class); |
|
1043 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = []; |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = []; |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + * @throws InvalidAliasException |
|
109 | + */ |
|
110 | + public function initialize() |
|
111 | + { |
|
112 | + $this->_register_core_dependencies(); |
|
113 | + $this->_register_core_class_loaders(); |
|
114 | + $this->_register_core_aliases(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @singleton method used to instantiate class object |
|
120 | + * @param ClassInterfaceCache|null $class_cache |
|
121 | + * @return EE_Dependency_Map |
|
122 | + */ |
|
123 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
124 | + { |
|
125 | + // check if class object is instantiated, and instantiated properly |
|
126 | + if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
127 | + && $class_cache instanceof ClassInterfaceCache |
|
128 | + ) { |
|
129 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
130 | + } |
|
131 | + return EE_Dependency_Map::$_instance; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param RequestInterface $request |
|
137 | + */ |
|
138 | + public function setRequest(RequestInterface $request) |
|
139 | + { |
|
140 | + $this->request = $request; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param LegacyRequestInterface $legacy_request |
|
146 | + */ |
|
147 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
148 | + { |
|
149 | + $this->legacy_request = $legacy_request; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param ResponseInterface $response |
|
155 | + */ |
|
156 | + public function setResponse(ResponseInterface $response) |
|
157 | + { |
|
158 | + $this->response = $response; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param LoaderInterface $loader |
|
164 | + */ |
|
165 | + public function setLoader(LoaderInterface $loader) |
|
166 | + { |
|
167 | + $this->loader = $loader; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $class |
|
173 | + * @param array $dependencies |
|
174 | + * @param int $overwrite |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public static function register_dependencies( |
|
178 | + $class, |
|
179 | + array $dependencies, |
|
180 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
181 | + ) { |
|
182 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
188 | + * to the class specified by the first parameter. |
|
189 | + * IMPORTANT !!! |
|
190 | + * The order of elements in the incoming $dependencies array MUST match |
|
191 | + * the order of the constructor parameters for the class in question. |
|
192 | + * This is especially important when overriding any existing dependencies that are registered. |
|
193 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
194 | + * |
|
195 | + * @param string $class |
|
196 | + * @param array $dependencies |
|
197 | + * @param int $overwrite |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function registerDependencies( |
|
201 | + $class, |
|
202 | + array $dependencies, |
|
203 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
204 | + ) { |
|
205 | + $class = trim($class, '\\'); |
|
206 | + $registered = false; |
|
207 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
208 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
209 | + } |
|
210 | + // we need to make sure that any aliases used when registering a dependency |
|
211 | + // get resolved to the correct class name |
|
212 | + foreach ($dependencies as $dependency => $load_source) { |
|
213 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
214 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
215 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
216 | + ) { |
|
217 | + unset($dependencies[ $dependency ]); |
|
218 | + $dependencies[ $alias ] = $load_source; |
|
219 | + $registered = true; |
|
220 | + } |
|
221 | + } |
|
222 | + // now add our two lists of dependencies together. |
|
223 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
224 | + // so $dependencies is NOT overwritten because it is listed first |
|
225 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
226 | + // Union is way faster than array_merge() but should be used with caution... |
|
227 | + // especially with numerically indexed arrays |
|
228 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
229 | + // now we need to ensure that the resulting dependencies |
|
230 | + // array only has the entries that are required for the class |
|
231 | + // so first count how many dependencies were originally registered for the class |
|
232 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
233 | + // if that count is non-zero (meaning dependencies were already registered) |
|
234 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
235 | + // then truncate the final array to match that count |
|
236 | + ? array_slice($dependencies, 0, $dependency_count) |
|
237 | + // otherwise just take the incoming array because nothing previously existed |
|
238 | + : $dependencies; |
|
239 | + return $registered; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $class_name |
|
245 | + * @param string $loader |
|
246 | + * @return bool |
|
247 | + * @throws DomainException |
|
248 | + */ |
|
249 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
250 | + { |
|
251 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $class_name |
|
257 | + * @param string $loader |
|
258 | + * @return bool |
|
259 | + * @throws DomainException |
|
260 | + */ |
|
261 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
262 | + { |
|
263 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
264 | + throw new DomainException( |
|
265 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
266 | + ); |
|
267 | + } |
|
268 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
269 | + if (! is_callable($loader) |
|
270 | + && ( |
|
271 | + strpos($loader, 'load_') !== 0 |
|
272 | + || ! method_exists('EE_Registry', $loader) |
|
273 | + ) |
|
274 | + ) { |
|
275 | + throw new DomainException( |
|
276 | + sprintf( |
|
277 | + esc_html__( |
|
278 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + $loader |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
286 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
287 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
288 | + return true; |
|
289 | + } |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return array |
|
296 | + */ |
|
297 | + public function dependency_map() |
|
298 | + { |
|
299 | + return $this->_dependency_map; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | + * |
|
306 | + * @param string $class_name |
|
307 | + * @return boolean |
|
308 | + */ |
|
309 | + public function has($class_name = '') |
|
310 | + { |
|
311 | + // all legacy models have the same dependencies |
|
312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
313 | + $class_name = 'LEGACY_MODELS'; |
|
314 | + } |
|
315 | + return isset($this->_dependency_map[ $class_name ]); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
321 | + * |
|
322 | + * @param string $class_name |
|
323 | + * @param string $dependency |
|
324 | + * @return bool |
|
325 | + */ |
|
326 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
327 | + { |
|
328 | + // all legacy models have the same dependencies |
|
329 | + if (strpos($class_name, 'EEM_') === 0) { |
|
330 | + $class_name = 'LEGACY_MODELS'; |
|
331 | + } |
|
332 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
333 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
339 | + * |
|
340 | + * @param string $class_name |
|
341 | + * @param string $dependency |
|
342 | + * @return int |
|
343 | + */ |
|
344 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
345 | + { |
|
346 | + // all legacy models have the same dependencies |
|
347 | + if (strpos($class_name, 'EEM_') === 0) { |
|
348 | + $class_name = 'LEGACY_MODELS'; |
|
349 | + } |
|
350 | + $dependency = $this->getFqnForAlias($dependency); |
|
351 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
352 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
353 | + : EE_Dependency_Map::not_registered; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $class_name |
|
359 | + * @return string | Closure |
|
360 | + */ |
|
361 | + public function class_loader($class_name) |
|
362 | + { |
|
363 | + // all legacy models use load_model() |
|
364 | + if (strpos($class_name, 'EEM_') === 0) { |
|
365 | + return 'load_model'; |
|
366 | + } |
|
367 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
368 | + // perform strpos() first to avoid loading regex every time we load a class |
|
369 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
370 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
371 | + ) { |
|
372 | + return 'load_core'; |
|
373 | + } |
|
374 | + $class_name = $this->getFqnForAlias($class_name); |
|
375 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function class_loaders() |
|
383 | + { |
|
384 | + return $this->_class_loaders; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * adds an alias for a classname |
|
390 | + * |
|
391 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | + * @throws InvalidAliasException |
|
395 | + */ |
|
396 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | + { |
|
398 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
404 | + * WHY? |
|
405 | + * Because if a class is type hinting for a concretion, |
|
406 | + * then why would we need to find another class to supply it? |
|
407 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
408 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
409 | + * Don't go looking for some substitute. |
|
410 | + * Whereas if a class is type hinting for an interface... |
|
411 | + * then we need to find an actual class to use. |
|
412 | + * So the interface IS the alias for some other FQN, |
|
413 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
414 | + * represents some other class. |
|
415 | + * |
|
416 | + * @param string $fqn |
|
417 | + * @param string $for_class |
|
418 | + * @return bool |
|
419 | + */ |
|
420 | + public function isAlias($fqn = '', $for_class = '') |
|
421 | + { |
|
422 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
428 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
429 | + * for example: |
|
430 | + * if the following two entries were added to the _aliases array: |
|
431 | + * array( |
|
432 | + * 'interface_alias' => 'some\namespace\interface' |
|
433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | + * ) |
|
435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | + * to load an instance of 'some\namespace\classname' |
|
437 | + * |
|
438 | + * @param string $alias |
|
439 | + * @param string $for_class |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
443 | + { |
|
444 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
450 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
451 | + * This is done by using the following class constants: |
|
452 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
453 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
454 | + */ |
|
455 | + protected function _register_core_dependencies() |
|
456 | + { |
|
457 | + $this->_dependency_map = [ |
|
458 | + 'EE_Request_Handler' => [ |
|
459 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
460 | + ], |
|
461 | + 'EE_System' => [ |
|
462 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
464 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
465 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
467 | + ], |
|
468 | + 'EE_Admin' => [ |
|
469 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | + ], |
|
472 | + 'EE_Cart' => [ |
|
473 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
474 | + ], |
|
475 | + 'EE_Messenger_Collection_Loader' => [ |
|
476 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | + ], |
|
478 | + 'EE_Message_Type_Collection_Loader' => [ |
|
479 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | + ], |
|
481 | + 'EE_Message_Resource_Manager' => [ |
|
482 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | + ], |
|
486 | + 'EE_Message_Factory' => [ |
|
487 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ], |
|
489 | + 'EE_messages' => [ |
|
490 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | + ], |
|
492 | + 'EE_Messages_Generator' => [ |
|
493 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | + ], |
|
498 | + 'EE_Messages_Processor' => [ |
|
499 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ], |
|
501 | + 'EE_Messages_Queue' => [ |
|
502 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | + ], |
|
504 | + 'EE_Messages_Template_Defaults' => [ |
|
505 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | + ], |
|
508 | + 'EE_Message_To_Generate_From_Request' => [ |
|
509 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | + ], |
|
512 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
513 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | + ], |
|
515 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
516 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | + ], |
|
519 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
520 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | + ], |
|
522 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
523 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | + ], |
|
526 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
527 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | + ], |
|
529 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
530 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | + ], |
|
532 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
533 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | + ], |
|
535 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
536 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | + ], |
|
538 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
539 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | + ], |
|
541 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
542 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | + ], |
|
544 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
545 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | + ], |
|
547 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
548 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | + ], |
|
550 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
551 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | + ], |
|
553 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
554 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | + ], |
|
556 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
557 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | + ], |
|
559 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
560 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | + ], |
|
562 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
563 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | + ], |
|
565 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + ], |
|
568 | + 'EE_Data_Migration_Class_Base' => [ |
|
569 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | + ], |
|
572 | + 'EE_DMS_Core_4_1_0' => [ |
|
573 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | + ], |
|
576 | + 'EE_DMS_Core_4_2_0' => [ |
|
577 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | + ], |
|
580 | + 'EE_DMS_Core_4_3_0' => [ |
|
581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ], |
|
584 | + 'EE_DMS_Core_4_4_0' => [ |
|
585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | + ], |
|
588 | + 'EE_DMS_Core_4_5_0' => [ |
|
589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | + ], |
|
592 | + 'EE_DMS_Core_4_6_0' => [ |
|
593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ], |
|
596 | + 'EE_DMS_Core_4_7_0' => [ |
|
597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | + ], |
|
600 | + 'EE_DMS_Core_4_8_0' => [ |
|
601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | + ], |
|
604 | + 'EE_DMS_Core_4_9_0' => [ |
|
605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | + ], |
|
608 | + 'EE_DMS_Core_4_10_0' => [ |
|
609 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
610 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
611 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
612 | + ], |
|
613 | + 'EE_DMS_Core_4_11_0' => [ |
|
614 | + 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
615 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | + ], |
|
618 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
619 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
620 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
621 | + ], |
|
622 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | + ], |
|
625 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
626 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
627 | + ], |
|
628 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
629 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
630 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
631 | + ], |
|
632 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
633 | + null, |
|
634 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
635 | + ], |
|
636 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
637 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
638 | + ], |
|
639 | + 'LEGACY_MODELS' => [ |
|
640 | + null, |
|
641 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
642 | + ], |
|
643 | + 'EE_Module_Request_Router' => [ |
|
644 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
645 | + ], |
|
646 | + 'EE_Registration_Processor' => [ |
|
647 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
648 | + ], |
|
649 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
650 | + null, |
|
651 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
652 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
653 | + ], |
|
654 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
655 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
656 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
657 | + ], |
|
658 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
659 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
660 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
661 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
662 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
663 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
664 | + ], |
|
665 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
666 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
667 | + ], |
|
668 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
669 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
670 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
671 | + ], |
|
672 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
673 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
674 | + ], |
|
675 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
676 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
677 | + ], |
|
678 | + 'EE_CPT_Strategy' => [ |
|
679 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
681 | + ], |
|
682 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
683 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
684 | + ], |
|
685 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
686 | + null, |
|
687 | + null, |
|
688 | + null, |
|
689 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
692 | + ], |
|
693 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
694 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
695 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
696 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
697 | + ], |
|
698 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
699 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
700 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
701 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
702 | + ], |
|
703 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
704 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
705 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
706 | + ], |
|
707 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
708 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
709 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
710 | + ], |
|
711 | + 'EE_URL_Validation_Strategy' => [ |
|
712 | + null, |
|
713 | + null, |
|
714 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
715 | + ], |
|
716 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
717 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
718 | + ], |
|
719 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | + ], |
|
722 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
723 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
724 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
725 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
726 | + null, |
|
727 | + ], |
|
728 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
729 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
731 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
733 | + ], |
|
734 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
735 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
736 | + ], |
|
737 | + 'EventEspresso\core\services\routing\Router' => [ |
|
738 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
741 | + ], |
|
742 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
743 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
744 | + ], |
|
745 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
746 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
747 | + ], |
|
748 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
749 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
750 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
751 | + ], |
|
752 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
753 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
754 | + ], |
|
755 | + 'EventEspresso\core\services\addon\AddonManager' => [ |
|
756 | + 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
757 | + 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
758 | + 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
759 | + 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
760 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
761 | + ], |
|
762 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
763 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
764 | + ], |
|
765 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => [ |
|
766 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
767 | + ], |
|
768 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => [ |
|
769 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache |
|
770 | + ], |
|
771 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => [ |
|
772 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache] |
|
773 | + ]; |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + /** |
|
778 | + * Registers how core classes are loaded. |
|
779 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
780 | + * 'EE_Request_Handler' => 'load_core' |
|
781 | + * 'EE_Messages_Queue' => 'load_lib' |
|
782 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
783 | + * or, if greater control is required, by providing a custom closure. For example: |
|
784 | + * 'Some_Class' => function () { |
|
785 | + * return new Some_Class(); |
|
786 | + * }, |
|
787 | + * This is required for instantiating dependencies |
|
788 | + * where an interface has been type hinted in a class constructor. For example: |
|
789 | + * 'Required_Interface' => function () { |
|
790 | + * return new A_Class_That_Implements_Required_Interface(); |
|
791 | + * }, |
|
792 | + */ |
|
793 | + protected function _register_core_class_loaders() |
|
794 | + { |
|
795 | + $this->_class_loaders = [ |
|
796 | + // load_core |
|
797 | + 'EE_Dependency_Map' => function () { |
|
798 | + return $this; |
|
799 | + }, |
|
800 | + 'EE_Capabilities' => 'load_core', |
|
801 | + 'EE_Encryption' => 'load_core', |
|
802 | + 'EE_Front_Controller' => 'load_core', |
|
803 | + 'EE_Module_Request_Router' => 'load_core', |
|
804 | + 'EE_Registry' => 'load_core', |
|
805 | + 'EE_Request' => function () { |
|
806 | + return $this->legacy_request; |
|
807 | + }, |
|
808 | + 'EventEspresso\core\services\request\Request' => function () { |
|
809 | + return $this->request; |
|
810 | + }, |
|
811 | + 'EventEspresso\core\services\request\Response' => function () { |
|
812 | + return $this->response; |
|
813 | + }, |
|
814 | + 'EE_Base' => 'load_core', |
|
815 | + 'EE_Request_Handler' => 'load_core', |
|
816 | + 'EE_Session' => 'load_core', |
|
817 | + 'EE_Cron_Tasks' => 'load_core', |
|
818 | + 'EE_System' => 'load_core', |
|
819 | + 'EE_Maintenance_Mode' => 'load_core', |
|
820 | + 'EE_Register_CPTs' => 'load_core', |
|
821 | + 'EE_Admin' => 'load_core', |
|
822 | + 'EE_CPT_Strategy' => 'load_core', |
|
823 | + // load_class |
|
824 | + 'EE_Registration_Processor' => 'load_class', |
|
825 | + // load_lib |
|
826 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
827 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
828 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
829 | + 'EE_Messenger_Collection' => 'load_lib', |
|
830 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
831 | + 'EE_Messages_Processor' => 'load_lib', |
|
832 | + 'EE_Message_Repository' => 'load_lib', |
|
833 | + 'EE_Messages_Queue' => 'load_lib', |
|
834 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
835 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
836 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
837 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
838 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
839 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
840 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
841 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
842 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
843 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
844 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
845 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
846 | + 'EE_Messages_Generator' => static function () { |
|
847 | + return EE_Registry::instance()->load_lib( |
|
848 | + 'Messages_Generator', |
|
849 | + [], |
|
850 | + false, |
|
851 | + false |
|
852 | + ); |
|
853 | + }, |
|
854 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
855 | + return EE_Registry::instance()->load_lib( |
|
856 | + 'Messages_Template_Defaults', |
|
857 | + $arguments, |
|
858 | + false, |
|
859 | + false |
|
860 | + ); |
|
861 | + }, |
|
862 | + // load_helper |
|
863 | + 'EEH_Parse_Shortcodes' => static function () { |
|
864 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
865 | + return new EEH_Parse_Shortcodes(); |
|
866 | + } |
|
867 | + return null; |
|
868 | + }, |
|
869 | + 'EE_Template_Config' => static function () { |
|
870 | + return EE_Config::instance()->template_settings; |
|
871 | + }, |
|
872 | + 'EE_Currency_Config' => static function () { |
|
873 | + return EE_Config::instance()->currency; |
|
874 | + }, |
|
875 | + 'EE_Registration_Config' => static function () { |
|
876 | + return EE_Config::instance()->registration; |
|
877 | + }, |
|
878 | + 'EE_Core_Config' => static function () { |
|
879 | + return EE_Config::instance()->core; |
|
880 | + }, |
|
881 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
882 | + return LoaderFactory::getLoader(); |
|
883 | + }, |
|
884 | + 'EE_Network_Config' => static function () { |
|
885 | + return EE_Network_Config::instance(); |
|
886 | + }, |
|
887 | + 'EE_Config' => static function () { |
|
888 | + return EE_Config::instance(); |
|
889 | + }, |
|
890 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
891 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
892 | + }, |
|
893 | + 'EE_Admin_Config' => static function () { |
|
894 | + return EE_Config::instance()->admin; |
|
895 | + }, |
|
896 | + 'EE_Organization_Config' => static function () { |
|
897 | + return EE_Config::instance()->organization; |
|
898 | + }, |
|
899 | + 'EE_Network_Core_Config' => static function () { |
|
900 | + return EE_Network_Config::instance()->core; |
|
901 | + }, |
|
902 | + 'EE_Environment_Config' => static function () { |
|
903 | + return EE_Config::instance()->environment; |
|
904 | + }, |
|
905 | + 'EED_Core_Rest_Api' => static function () { |
|
906 | + return EED_Core_Rest_Api::instance(); |
|
907 | + }, |
|
908 | + 'WP_REST_Server' => static function () { |
|
909 | + return rest_get_server(); |
|
910 | + }, |
|
911 | + 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
912 | + return EE_Psr4AutoloaderInit::psr4_loader(); |
|
913 | + }, |
|
914 | + ]; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * can be used for supplying alternate names for classes, |
|
920 | + * or for connecting interface names to instantiable classes |
|
921 | + * |
|
922 | + * @throws InvalidAliasException |
|
923 | + */ |
|
924 | + protected function _register_core_aliases() |
|
925 | + { |
|
926 | + $aliases = [ |
|
927 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
928 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
929 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
930 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
931 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
932 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
933 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
934 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
935 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
936 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
937 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
938 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
939 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
940 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
941 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
942 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
943 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
944 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
945 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
946 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
947 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
948 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
949 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
950 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
951 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
952 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
953 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
954 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
955 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
956 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
957 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
958 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
959 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
960 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
961 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
962 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
963 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
964 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
965 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
966 | + ]; |
|
967 | + foreach ($aliases as $alias => $fqn) { |
|
968 | + if (is_array($fqn)) { |
|
969 | + foreach ($fqn as $class => $for_class) { |
|
970 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
971 | + } |
|
972 | + continue; |
|
973 | + } |
|
974 | + $this->class_cache->addAlias($fqn, $alias); |
|
975 | + } |
|
976 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
977 | + $this->class_cache->addAlias( |
|
978 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
979 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
980 | + ); |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
987 | + * request Primarily used by unit tests. |
|
988 | + */ |
|
989 | + public function reset() |
|
990 | + { |
|
991 | + $this->_register_core_class_loaders(); |
|
992 | + $this->_register_core_dependencies(); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
998 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
999 | + * WHY? |
|
1000 | + * Because if a class is type hinting for a concretion, |
|
1001 | + * then why would we need to find another class to supply it? |
|
1002 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1003 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1004 | + * Don't go looking for some substitute. |
|
1005 | + * Whereas if a class is type hinting for an interface... |
|
1006 | + * then we need to find an actual class to use. |
|
1007 | + * So the interface IS the alias for some other FQN, |
|
1008 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1009 | + * represents some other class. |
|
1010 | + * |
|
1011 | + * @param string $fqn |
|
1012 | + * @param string $for_class |
|
1013 | + * @return bool |
|
1014 | + * @deprecated 4.9.62.p |
|
1015 | + */ |
|
1016 | + public function has_alias($fqn = '', $for_class = '') |
|
1017 | + { |
|
1018 | + return $this->isAlias($fqn, $for_class); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1024 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1025 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1026 | + * for example: |
|
1027 | + * if the following two entries were added to the _aliases array: |
|
1028 | + * array( |
|
1029 | + * 'interface_alias' => 'some\namespace\interface' |
|
1030 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1031 | + * ) |
|
1032 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1033 | + * to load an instance of 'some\namespace\classname' |
|
1034 | + * |
|
1035 | + * @param string $alias |
|
1036 | + * @param string $for_class |
|
1037 | + * @return string |
|
1038 | + * @deprecated 4.9.62.p |
|
1039 | + */ |
|
1040 | + public function get_alias($alias = '', $for_class = '') |
|
1041 | + { |
|
1042 | + return $this->getFqnForAlias($alias, $for_class); |
|
1043 | + } |
|
1044 | 1044 | } |
@@ -16,53 +16,53 @@ |
||
16 | 16 | class RestApiRequests extends Route |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * returns true if the current request matches this route |
|
21 | - * |
|
22 | - * @return bool |
|
23 | - * @since $VID:$ |
|
24 | - */ |
|
25 | - public function matchesCurrentRequest(): bool |
|
26 | - { |
|
27 | - return $this->request->isWordPressApi(); |
|
28 | - } |
|
19 | + /** |
|
20 | + * returns true if the current request matches this route |
|
21 | + * |
|
22 | + * @return bool |
|
23 | + * @since $VID:$ |
|
24 | + */ |
|
25 | + public function matchesCurrentRequest(): bool |
|
26 | + { |
|
27 | + return $this->request->isWordPressApi(); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @since $VID:$ |
|
33 | - */ |
|
34 | - protected function registerDependencies() |
|
35 | - { |
|
36 | - $this->dependency_map->registerDependencies( |
|
37 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime', |
|
38 | - [ |
|
39 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
40 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
41 | - ] |
|
42 | - ); |
|
43 | - $this->dependency_map->registerDependencies( |
|
44 | - 'EventEspresso\core\libraries\rest_api\calculations\Event', |
|
45 | - [ |
|
46 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
47 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
48 | - ] |
|
49 | - ); |
|
50 | - $this->dependency_map->registerDependencies( |
|
51 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration', |
|
52 | - ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
53 | - ); |
|
54 | - } |
|
31 | + /** |
|
32 | + * @since $VID:$ |
|
33 | + */ |
|
34 | + protected function registerDependencies() |
|
35 | + { |
|
36 | + $this->dependency_map->registerDependencies( |
|
37 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime', |
|
38 | + [ |
|
39 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
40 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
41 | + ] |
|
42 | + ); |
|
43 | + $this->dependency_map->registerDependencies( |
|
44 | + 'EventEspresso\core\libraries\rest_api\calculations\Event', |
|
45 | + [ |
|
46 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
47 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
48 | + ] |
|
49 | + ); |
|
50 | + $this->dependency_map->registerDependencies( |
|
51 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration', |
|
52 | + ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * implements logic required to run during request |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - * @since $VID:$ |
|
62 | - */ |
|
63 | - protected function requestHandler(): bool |
|
64 | - { |
|
65 | - // rest api handled by module for now |
|
66 | - return true; |
|
67 | - } |
|
57 | + /** |
|
58 | + * implements logic required to run during request |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + * @since $VID:$ |
|
62 | + */ |
|
63 | + protected function requestHandler(): bool |
|
64 | + { |
|
65 | + // rest api handled by module for now |
|
66 | + return true; |
|
67 | + } |
|
68 | 68 | } |
@@ -19,806 +19,806 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | - * which will be used to store the plugin's activation history |
|
25 | - */ |
|
26 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var $_version |
|
30 | - * @type string |
|
31 | - */ |
|
32 | - protected $_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var $_min_core_version |
|
36 | - * @type string |
|
37 | - */ |
|
38 | - protected $_min_core_version = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * derived from plugin 'main_file_path using plugin_basename() |
|
42 | - * |
|
43 | - * @type string $_plugin_basename |
|
44 | - */ |
|
45 | - protected $_plugin_basename = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | - * |
|
50 | - * @type string $_plugin_slug |
|
51 | - */ |
|
52 | - protected $_plugin_slug = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | - * |
|
57 | - * @type string _addon_name |
|
58 | - */ |
|
59 | - protected $_addon_name = ''; |
|
60 | - |
|
61 | - /** |
|
62 | - * one of the EE_System::req_type_* constants |
|
63 | - * |
|
64 | - * @type int $_req_type |
|
65 | - */ |
|
66 | - protected $_req_type; |
|
67 | - |
|
68 | - /** |
|
69 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | - * |
|
71 | - * @type string $_plugin_action_slug |
|
72 | - */ |
|
73 | - protected $_plugin_action_slug = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | - * that can be used for adding upgrading/marketing info |
|
78 | - * |
|
79 | - * @type array $_plugins_page_row |
|
80 | - */ |
|
81 | - protected $_plugins_page_row = []; |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | - * |
|
87 | - * @type string |
|
88 | - */ |
|
89 | - protected $_main_plugin_file; |
|
90 | - |
|
91 | - /** |
|
92 | - * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | - * |
|
94 | - * @type string |
|
95 | - */ |
|
96 | - protected $pue_slug = ''; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @var EE_Dependency_Map $dependency_map |
|
101 | - */ |
|
102 | - private $dependency_map; |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @var DomainInterface $domain |
|
107 | - */ |
|
108 | - private $domain; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param EE_Dependency_Map|null $dependency_map [optional] |
|
113 | - * @param DomainInterface|null $domain [optional] |
|
114 | - */ |
|
115 | - public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | - { |
|
117 | - if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | - $this->setDependencyMap($dependency_map); |
|
119 | - } |
|
120 | - if ($domain instanceof DomainInterface) { |
|
121 | - $this->setDomain($domain); |
|
122 | - } |
|
123 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', [$this, 'admin_init']); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param EE_Dependency_Map $dependency_map |
|
129 | - */ |
|
130 | - public function setDependencyMap($dependency_map) |
|
131 | - { |
|
132 | - $this->dependency_map = $dependency_map; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return EE_Dependency_Map |
|
138 | - */ |
|
139 | - public function dependencyMap(): ?EE_Dependency_Map |
|
140 | - { |
|
141 | - return $this->dependency_map; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param DomainInterface $domain |
|
147 | - */ |
|
148 | - public function setDomain(DomainInterface $domain) |
|
149 | - { |
|
150 | - $this->domain = $domain; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return DomainInterface |
|
156 | - */ |
|
157 | - public function domain(): ?DomainInterface |
|
158 | - { |
|
159 | - return $this->domain; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param string $version |
|
165 | - */ |
|
166 | - public function set_version(string $version = '') |
|
167 | - { |
|
168 | - $this->_version = $version; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * get__version |
|
174 | - * |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function version(): string |
|
178 | - { |
|
179 | - return $this->_version; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param mixed $min_core_version |
|
185 | - */ |
|
186 | - public function set_min_core_version($min_core_version = null) |
|
187 | - { |
|
188 | - $this->_min_core_version = $min_core_version; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * get__min_core_version |
|
194 | - * |
|
195 | - * @return string |
|
196 | - */ |
|
197 | - public function min_core_version(): string |
|
198 | - { |
|
199 | - return $this->_min_core_version; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Sets addon_name |
|
205 | - * |
|
206 | - * @param string $addon_name |
|
207 | - */ |
|
208 | - public function set_name(string $addon_name) |
|
209 | - { |
|
210 | - $this->_addon_name = $addon_name; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets addon_name |
|
216 | - * |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function name() |
|
220 | - { |
|
221 | - return $this->_addon_name; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function plugin_basename(): string |
|
229 | - { |
|
230 | - |
|
231 | - return $this->_plugin_basename; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $plugin_basename |
|
237 | - */ |
|
238 | - public function set_plugin_basename(string $plugin_basename) |
|
239 | - { |
|
240 | - |
|
241 | - $this->_plugin_basename = $plugin_basename; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function plugin_slug(): string |
|
249 | - { |
|
250 | - |
|
251 | - return $this->_plugin_slug; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $plugin_slug |
|
257 | - */ |
|
258 | - public function set_plugin_slug(string $plugin_slug) |
|
259 | - { |
|
260 | - |
|
261 | - $this->_plugin_slug = $plugin_slug; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function plugin_action_slug(): string |
|
269 | - { |
|
270 | - |
|
271 | - return $this->_plugin_action_slug; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @param string $plugin_action_slug |
|
277 | - */ |
|
278 | - public function set_plugin_action_slug(string $plugin_action_slug) |
|
279 | - { |
|
280 | - |
|
281 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function get_plugins_page_row(): array |
|
289 | - { |
|
290 | - |
|
291 | - return $this->_plugins_page_row; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param array|string $plugins_page_row |
|
297 | - */ |
|
298 | - public function set_plugins_page_row(array $plugins_page_row = []) |
|
299 | - { |
|
300 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | - if (! is_array($plugins_page_row) |
|
302 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
303 | - ) { |
|
304 | - $plugins_page_row = []; |
|
305 | - } |
|
306 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Called when EE core detects this addon has been activated for the first time. |
|
312 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
313 | - * |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function new_install() |
|
317 | - { |
|
318 | - $classname = get_class($this); |
|
319 | - do_action("AHEE__{$classname}__new_install"); |
|
320 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
321 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
322 | - add_action( |
|
323 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
324 | - [$this, 'initialize_db_if_no_migrations_required'] |
|
325 | - ); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
331 | - * it's good to just check that your data is still intact |
|
332 | - * |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public function reactivation() |
|
336 | - { |
|
337 | - $classname = get_class($this); |
|
338 | - do_action("AHEE__{$classname}__reactivation"); |
|
339 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
340 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
341 | - add_action( |
|
342 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
343 | - [$this, 'initialize_db_if_no_migrations_required'] |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Called when the registered deactivation hook for this addon fires. |
|
350 | - * |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function deactivation() |
|
354 | - { |
|
355 | - $classname = get_class($this); |
|
356 | - do_action("AHEE__{$classname}__deactivation"); |
|
357 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
358 | - // check if the site no longer needs to be in maintenance mode |
|
359 | - EE_Register_Addon::deregister($this->name()); |
|
360 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
366 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
367 | - * and reactivations. |
|
368 | - * |
|
369 | - * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
370 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
371 | - * @return void |
|
372 | - * @throws EE_Error |
|
373 | - * @throws InvalidInterfaceException |
|
374 | - * @throws InvalidDataTypeException |
|
375 | - * @throws InvalidArgumentException |
|
376 | - * @throws ReflectionException |
|
377 | - */ |
|
378 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
379 | - { |
|
380 | - if ($verify_schema === '') { |
|
381 | - // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
382 | - // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
383 | - // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
384 | - // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
385 | - $verify_schema = true; |
|
386 | - } |
|
387 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
388 | - if ($verify_schema) { |
|
389 | - $this->initialize_db(); |
|
390 | - } |
|
391 | - $this->initialize_default_data(); |
|
392 | - // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
393 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
394 | - [ |
|
395 | - 'slug' => $this->name(), |
|
396 | - 'version' => $this->version(), |
|
397 | - ] |
|
398 | - ); |
|
399 | - /* make sure core's data is a-ok |
|
22 | + /** |
|
23 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | + * which will be used to store the plugin's activation history |
|
25 | + */ |
|
26 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var $_version |
|
30 | + * @type string |
|
31 | + */ |
|
32 | + protected $_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var $_min_core_version |
|
36 | + * @type string |
|
37 | + */ |
|
38 | + protected $_min_core_version = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * derived from plugin 'main_file_path using plugin_basename() |
|
42 | + * |
|
43 | + * @type string $_plugin_basename |
|
44 | + */ |
|
45 | + protected $_plugin_basename = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | + * |
|
50 | + * @type string $_plugin_slug |
|
51 | + */ |
|
52 | + protected $_plugin_slug = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | + * |
|
57 | + * @type string _addon_name |
|
58 | + */ |
|
59 | + protected $_addon_name = ''; |
|
60 | + |
|
61 | + /** |
|
62 | + * one of the EE_System::req_type_* constants |
|
63 | + * |
|
64 | + * @type int $_req_type |
|
65 | + */ |
|
66 | + protected $_req_type; |
|
67 | + |
|
68 | + /** |
|
69 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | + * |
|
71 | + * @type string $_plugin_action_slug |
|
72 | + */ |
|
73 | + protected $_plugin_action_slug = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | + * that can be used for adding upgrading/marketing info |
|
78 | + * |
|
79 | + * @type array $_plugins_page_row |
|
80 | + */ |
|
81 | + protected $_plugins_page_row = []; |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | + * |
|
87 | + * @type string |
|
88 | + */ |
|
89 | + protected $_main_plugin_file; |
|
90 | + |
|
91 | + /** |
|
92 | + * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | + * |
|
94 | + * @type string |
|
95 | + */ |
|
96 | + protected $pue_slug = ''; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @var EE_Dependency_Map $dependency_map |
|
101 | + */ |
|
102 | + private $dependency_map; |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @var DomainInterface $domain |
|
107 | + */ |
|
108 | + private $domain; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param EE_Dependency_Map|null $dependency_map [optional] |
|
113 | + * @param DomainInterface|null $domain [optional] |
|
114 | + */ |
|
115 | + public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | + { |
|
117 | + if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | + $this->setDependencyMap($dependency_map); |
|
119 | + } |
|
120 | + if ($domain instanceof DomainInterface) { |
|
121 | + $this->setDomain($domain); |
|
122 | + } |
|
123 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', [$this, 'admin_init']); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param EE_Dependency_Map $dependency_map |
|
129 | + */ |
|
130 | + public function setDependencyMap($dependency_map) |
|
131 | + { |
|
132 | + $this->dependency_map = $dependency_map; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return EE_Dependency_Map |
|
138 | + */ |
|
139 | + public function dependencyMap(): ?EE_Dependency_Map |
|
140 | + { |
|
141 | + return $this->dependency_map; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param DomainInterface $domain |
|
147 | + */ |
|
148 | + public function setDomain(DomainInterface $domain) |
|
149 | + { |
|
150 | + $this->domain = $domain; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return DomainInterface |
|
156 | + */ |
|
157 | + public function domain(): ?DomainInterface |
|
158 | + { |
|
159 | + return $this->domain; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param string $version |
|
165 | + */ |
|
166 | + public function set_version(string $version = '') |
|
167 | + { |
|
168 | + $this->_version = $version; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * get__version |
|
174 | + * |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function version(): string |
|
178 | + { |
|
179 | + return $this->_version; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param mixed $min_core_version |
|
185 | + */ |
|
186 | + public function set_min_core_version($min_core_version = null) |
|
187 | + { |
|
188 | + $this->_min_core_version = $min_core_version; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * get__min_core_version |
|
194 | + * |
|
195 | + * @return string |
|
196 | + */ |
|
197 | + public function min_core_version(): string |
|
198 | + { |
|
199 | + return $this->_min_core_version; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Sets addon_name |
|
205 | + * |
|
206 | + * @param string $addon_name |
|
207 | + */ |
|
208 | + public function set_name(string $addon_name) |
|
209 | + { |
|
210 | + $this->_addon_name = $addon_name; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets addon_name |
|
216 | + * |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function name() |
|
220 | + { |
|
221 | + return $this->_addon_name; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function plugin_basename(): string |
|
229 | + { |
|
230 | + |
|
231 | + return $this->_plugin_basename; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $plugin_basename |
|
237 | + */ |
|
238 | + public function set_plugin_basename(string $plugin_basename) |
|
239 | + { |
|
240 | + |
|
241 | + $this->_plugin_basename = $plugin_basename; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function plugin_slug(): string |
|
249 | + { |
|
250 | + |
|
251 | + return $this->_plugin_slug; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $plugin_slug |
|
257 | + */ |
|
258 | + public function set_plugin_slug(string $plugin_slug) |
|
259 | + { |
|
260 | + |
|
261 | + $this->_plugin_slug = $plugin_slug; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function plugin_action_slug(): string |
|
269 | + { |
|
270 | + |
|
271 | + return $this->_plugin_action_slug; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @param string $plugin_action_slug |
|
277 | + */ |
|
278 | + public function set_plugin_action_slug(string $plugin_action_slug) |
|
279 | + { |
|
280 | + |
|
281 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function get_plugins_page_row(): array |
|
289 | + { |
|
290 | + |
|
291 | + return $this->_plugins_page_row; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param array|string $plugins_page_row |
|
297 | + */ |
|
298 | + public function set_plugins_page_row(array $plugins_page_row = []) |
|
299 | + { |
|
300 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | + if (! is_array($plugins_page_row) |
|
302 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
303 | + ) { |
|
304 | + $plugins_page_row = []; |
|
305 | + } |
|
306 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Called when EE core detects this addon has been activated for the first time. |
|
312 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
313 | + * |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function new_install() |
|
317 | + { |
|
318 | + $classname = get_class($this); |
|
319 | + do_action("AHEE__{$classname}__new_install"); |
|
320 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
321 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
322 | + add_action( |
|
323 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
324 | + [$this, 'initialize_db_if_no_migrations_required'] |
|
325 | + ); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
331 | + * it's good to just check that your data is still intact |
|
332 | + * |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public function reactivation() |
|
336 | + { |
|
337 | + $classname = get_class($this); |
|
338 | + do_action("AHEE__{$classname}__reactivation"); |
|
339 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
340 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
341 | + add_action( |
|
342 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
343 | + [$this, 'initialize_db_if_no_migrations_required'] |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Called when the registered deactivation hook for this addon fires. |
|
350 | + * |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function deactivation() |
|
354 | + { |
|
355 | + $classname = get_class($this); |
|
356 | + do_action("AHEE__{$classname}__deactivation"); |
|
357 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
358 | + // check if the site no longer needs to be in maintenance mode |
|
359 | + EE_Register_Addon::deregister($this->name()); |
|
360 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
366 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
367 | + * and reactivations. |
|
368 | + * |
|
369 | + * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
370 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
371 | + * @return void |
|
372 | + * @throws EE_Error |
|
373 | + * @throws InvalidInterfaceException |
|
374 | + * @throws InvalidDataTypeException |
|
375 | + * @throws InvalidArgumentException |
|
376 | + * @throws ReflectionException |
|
377 | + */ |
|
378 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
379 | + { |
|
380 | + if ($verify_schema === '') { |
|
381 | + // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
382 | + // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
383 | + // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
384 | + // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
385 | + $verify_schema = true; |
|
386 | + } |
|
387 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
388 | + if ($verify_schema) { |
|
389 | + $this->initialize_db(); |
|
390 | + } |
|
391 | + $this->initialize_default_data(); |
|
392 | + // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
393 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
394 | + [ |
|
395 | + 'slug' => $this->name(), |
|
396 | + 'version' => $this->version(), |
|
397 | + ] |
|
398 | + ); |
|
399 | + /* make sure core's data is a-ok |
|
400 | 400 | * (at the time of writing, we especially want to verify all the caps are present |
401 | 401 | * because payment method type capabilities are added dynamically, and it's |
402 | 402 | * possible this addon added a payment method. But it's also possible |
403 | 403 | * other data needs to be verified) |
404 | 404 | */ |
405 | - EEH_Activation::initialize_db_content(); |
|
406 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
407 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
408 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
409 | - ); |
|
410 | - $rewrite_rules->flushRewriteRules(); |
|
411 | - // in case there are lots of addons being activated at once, let's force garbage collection |
|
412 | - // to help avoid memory limit errors |
|
413 | - // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
414 | - gc_collect_cycles(); |
|
415 | - } else { |
|
416 | - // ask the data migration manager to init this addon's data |
|
417 | - // when migrations are finished because we can't do it now |
|
418 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * Used to setup this addon's database tables, but not necessarily any default |
|
425 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
426 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
427 | - * methods to setup the db. |
|
428 | - * |
|
429 | - * @throws EE_Error |
|
430 | - * @throws ReflectionException |
|
431 | - */ |
|
432 | - public function initialize_db() |
|
433 | - { |
|
434 | - // find the migration script that sets the database to be compatible with the code |
|
435 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
436 | - if ($current_dms_name) { |
|
437 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
438 | - $current_data_migration_script->set_migrating(false); |
|
439 | - $current_data_migration_script->schema_changes_before_migration(); |
|
440 | - $current_data_migration_script->schema_changes_after_migration(); |
|
441 | - if ($current_data_migration_script->get_errors()) { |
|
442 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
443 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
444 | - } |
|
445 | - } |
|
446 | - } |
|
447 | - // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
448 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
449 | - [ |
|
450 | - 'slug' => $this->name(), |
|
451 | - 'version' => $this->version(), |
|
452 | - ] |
|
453 | - ); |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * If you want to setup default data for the addon, override this method, and call |
|
459 | - * parent::initialize_default_data() from within it. This is normally called |
|
460 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
461 | - * and should verify default data is present (but this is also called |
|
462 | - * on reactivations and just after migrations, so please verify you actually want |
|
463 | - * to ADD default data, because it may already be present). |
|
464 | - * However, please call this parent (currently it just fires a hook which other |
|
465 | - * addons may be depending on) |
|
466 | - */ |
|
467 | - public function initialize_default_data() |
|
468 | - { |
|
469 | - /** |
|
470 | - * Called when an addon is ensuring its default data is set (possibly called |
|
471 | - * on a reactivation, so first check for the absence of other data before setting |
|
472 | - * default data) |
|
473 | - * |
|
474 | - * @param EE_Addon $addon the addon that called this |
|
475 | - */ |
|
476 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
477 | - // override to insert default data. It is safe to use the models here |
|
478 | - // because the site should not be in maintenance mode |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
484 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
485 | - * they're ran |
|
486 | - * |
|
487 | - * @return void |
|
488 | - */ |
|
489 | - public function upgrade() |
|
490 | - { |
|
491 | - $classname = get_class($this); |
|
492 | - do_action("AHEE__{$classname}__upgrade"); |
|
493 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
494 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
495 | - // also it's possible there is new default data that needs to be added |
|
496 | - add_action( |
|
497 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
498 | - [$this, 'initialize_db_if_no_migrations_required'] |
|
499 | - ); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
505 | - */ |
|
506 | - public function downgrade() |
|
507 | - { |
|
508 | - $classname = get_class($this); |
|
509 | - do_action("AHEE__{$classname}__downgrade"); |
|
510 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
511 | - // it's possible there's old default data that needs to be double-checked |
|
512 | - add_action( |
|
513 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
514 | - [$this, 'initialize_db_if_no_migrations_required'] |
|
515 | - ); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * set_db_update_option_name |
|
521 | - * Until we do something better, we'll just check for migration scripts upon |
|
522 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
523 | - * |
|
524 | - * @return bool |
|
525 | - */ |
|
526 | - public function set_db_update_option_name(): bool |
|
527 | - { |
|
528 | - EE_Error::doing_it_wrong( |
|
529 | - __FUNCTION__, |
|
530 | - esc_html__( |
|
531 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
532 | - 'event_espresso' |
|
533 | - ), |
|
534 | - '4.3.0.alpha.016' |
|
535 | - ); |
|
536 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
537 | - return $this->set_activation_indicator_option(); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * Returns the name of the activation indicator option |
|
543 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
544 | - * |
|
545 | - * @return string |
|
546 | - * @deprecated since version 4.3.0.alpha.016 |
|
547 | - */ |
|
548 | - public function get_db_update_option_name(): string |
|
549 | - { |
|
550 | - EE_Error::doing_it_wrong( |
|
551 | - __FUNCTION__, |
|
552 | - esc_html__( |
|
553 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - '4.3.0.alpha.016' |
|
557 | - ); |
|
558 | - return $this->get_activation_indicator_option_name(); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * When the addon is activated, this should be called to set a wordpress option that |
|
564 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
565 | - * |
|
566 | - * @return bool |
|
567 | - */ |
|
568 | - public function set_activation_indicator_option(): bool |
|
569 | - { |
|
570 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
571 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
577 | - * |
|
578 | - * @return string |
|
579 | - */ |
|
580 | - public function get_activation_indicator_option_name(): string |
|
581 | - { |
|
582 | - return 'ee_activation_' . $this->name(); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
588 | - * |
|
589 | - * @param int $req_type |
|
590 | - */ |
|
591 | - public function set_req_type(int $req_type) |
|
592 | - { |
|
593 | - $this->_req_type = $req_type; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
599 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
600 | - * EE_System when it is checking for new install or upgrades of addons |
|
601 | - */ |
|
602 | - public function detect_req_type(): int |
|
603 | - { |
|
604 | - if (! $this->_req_type) { |
|
605 | - $this->detect_activation_or_upgrade(); |
|
606 | - } |
|
607 | - return $this->_req_type; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
613 | - * Should only be called once per request |
|
614 | - * |
|
615 | - * @return void |
|
616 | - */ |
|
617 | - public function detect_activation_or_upgrade() |
|
618 | - { |
|
619 | - $activation_history_for_addon = $this->get_activation_history(); |
|
620 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
621 | - $activation_history_for_addon, |
|
622 | - $this->get_activation_indicator_option_name(), |
|
623 | - $this->version() |
|
624 | - ); |
|
625 | - $this->set_req_type($request_type); |
|
626 | - $classname = get_class($this); |
|
627 | - switch ($request_type) { |
|
628 | - case EE_System::req_type_new_activation: |
|
629 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
630 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
631 | - $this->new_install(); |
|
632 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
633 | - break; |
|
634 | - case EE_System::req_type_reactivation: |
|
635 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
636 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
637 | - $this->reactivation(); |
|
638 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
639 | - break; |
|
640 | - case EE_System::req_type_upgrade: |
|
641 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
642 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
643 | - $this->upgrade(); |
|
644 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
645 | - break; |
|
646 | - case EE_System::req_type_downgrade: |
|
647 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
648 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
649 | - $this->downgrade(); |
|
650 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
651 | - break; |
|
652 | - case EE_System::req_type_normal: |
|
653 | - default: |
|
654 | - break; |
|
655 | - } |
|
656 | - |
|
657 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * Updates the version history for this addon |
|
663 | - * |
|
664 | - * @param array $version_history |
|
665 | - * @param string $current_version_to_add |
|
666 | - * @return boolean success |
|
667 | - */ |
|
668 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool |
|
669 | - { |
|
670 | - if (! $version_history) { |
|
671 | - $version_history = $this->get_activation_history(); |
|
672 | - } |
|
673 | - if ($current_version_to_add === null) { |
|
674 | - $current_version_to_add = $this->version(); |
|
675 | - } |
|
676 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
677 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * Gets the name of the wp option that stores the activation history |
|
683 | - * of this addon |
|
684 | - * |
|
685 | - * @return string |
|
686 | - */ |
|
687 | - public function get_activation_history_option_name(): string |
|
688 | - { |
|
689 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Gets the wp option which stores the activation history for this addon |
|
695 | - * |
|
696 | - * @return array |
|
697 | - */ |
|
698 | - public function get_activation_history(): array |
|
699 | - { |
|
700 | - return get_option($this->get_activation_history_option_name(), []); |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @param string $config_section |
|
706 | - */ |
|
707 | - public function set_config_section($config_section = '') |
|
708 | - { |
|
709 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * Sets the filepath to the main plugin file |
|
715 | - * |
|
716 | - * @param string $filepath |
|
717 | - */ |
|
718 | - public function set_main_plugin_file(string $filepath) |
|
719 | - { |
|
720 | - $this->_main_plugin_file = $filepath; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * gets the filepath to teh main file |
|
726 | - * |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_main_plugin_file(): string |
|
730 | - { |
|
731 | - return $this->_main_plugin_file; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Gets the filename (no path) of the main file (the main file loaded |
|
737 | - * by WP) |
|
738 | - * |
|
739 | - * @return string |
|
740 | - */ |
|
741 | - public function get_main_plugin_file_basename(): string |
|
742 | - { |
|
743 | - return plugin_basename($this->get_main_plugin_file()); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * Gets the folder name which contains the main plugin file |
|
749 | - * |
|
750 | - * @return string |
|
751 | - */ |
|
752 | - public function get_main_plugin_file_dirname(): string |
|
753 | - { |
|
754 | - return dirname($this->get_main_plugin_file()); |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - /** |
|
759 | - * sets hooks used in the admin |
|
760 | - * |
|
761 | - * @return void |
|
762 | - */ |
|
763 | - public function admin_init() |
|
764 | - { |
|
765 | - // is admin and not in M-Mode ? |
|
766 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
767 | - add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2); |
|
768 | - add_filter('after_plugin_row_' . $this->_plugin_basename, [$this, 'after_plugin_row'], 10, 3); |
|
769 | - } |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * plugin_actions |
|
775 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
776 | - * |
|
777 | - * @param array $links |
|
778 | - * @param string $file |
|
779 | - * @return array |
|
780 | - */ |
|
781 | - public function plugin_action_links(array $links, string $file): array |
|
782 | - { |
|
783 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
784 | - // before other links |
|
785 | - array_unshift( |
|
786 | - $links, |
|
787 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
788 | - . esc_html__('Settings', 'event_espresso') |
|
789 | - . '</a>' |
|
790 | - ); |
|
791 | - } |
|
792 | - return $links; |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * after_plugin_row |
|
798 | - * Add additional content to the plugins page plugin row |
|
799 | - * Inserts another row |
|
800 | - * |
|
801 | - * @param string $plugin_file |
|
802 | - * @param array $plugin_data |
|
803 | - * @param string $status |
|
804 | - * @return void |
|
805 | - */ |
|
806 | - public function after_plugin_row(string $plugin_file, array $plugin_data, string $status) |
|
807 | - { |
|
808 | - $after_plugin_row = ''; |
|
809 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
810 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
811 | - $class = $status ? 'active' : 'inactive'; |
|
812 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
813 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
814 | - $description = isset($plugins_page_row['description']) |
|
815 | - ? $plugins_page_row['description'] |
|
816 | - : ''; |
|
817 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
818 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
819 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
820 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
821 | - $after_plugin_row .= '<style> |
|
405 | + EEH_Activation::initialize_db_content(); |
|
406 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
407 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
408 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
409 | + ); |
|
410 | + $rewrite_rules->flushRewriteRules(); |
|
411 | + // in case there are lots of addons being activated at once, let's force garbage collection |
|
412 | + // to help avoid memory limit errors |
|
413 | + // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
414 | + gc_collect_cycles(); |
|
415 | + } else { |
|
416 | + // ask the data migration manager to init this addon's data |
|
417 | + // when migrations are finished because we can't do it now |
|
418 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * Used to setup this addon's database tables, but not necessarily any default |
|
425 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
426 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
427 | + * methods to setup the db. |
|
428 | + * |
|
429 | + * @throws EE_Error |
|
430 | + * @throws ReflectionException |
|
431 | + */ |
|
432 | + public function initialize_db() |
|
433 | + { |
|
434 | + // find the migration script that sets the database to be compatible with the code |
|
435 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
436 | + if ($current_dms_name) { |
|
437 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
438 | + $current_data_migration_script->set_migrating(false); |
|
439 | + $current_data_migration_script->schema_changes_before_migration(); |
|
440 | + $current_data_migration_script->schema_changes_after_migration(); |
|
441 | + if ($current_data_migration_script->get_errors()) { |
|
442 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
443 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
444 | + } |
|
445 | + } |
|
446 | + } |
|
447 | + // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
448 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
449 | + [ |
|
450 | + 'slug' => $this->name(), |
|
451 | + 'version' => $this->version(), |
|
452 | + ] |
|
453 | + ); |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * If you want to setup default data for the addon, override this method, and call |
|
459 | + * parent::initialize_default_data() from within it. This is normally called |
|
460 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
461 | + * and should verify default data is present (but this is also called |
|
462 | + * on reactivations and just after migrations, so please verify you actually want |
|
463 | + * to ADD default data, because it may already be present). |
|
464 | + * However, please call this parent (currently it just fires a hook which other |
|
465 | + * addons may be depending on) |
|
466 | + */ |
|
467 | + public function initialize_default_data() |
|
468 | + { |
|
469 | + /** |
|
470 | + * Called when an addon is ensuring its default data is set (possibly called |
|
471 | + * on a reactivation, so first check for the absence of other data before setting |
|
472 | + * default data) |
|
473 | + * |
|
474 | + * @param EE_Addon $addon the addon that called this |
|
475 | + */ |
|
476 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
477 | + // override to insert default data. It is safe to use the models here |
|
478 | + // because the site should not be in maintenance mode |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
484 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
485 | + * they're ran |
|
486 | + * |
|
487 | + * @return void |
|
488 | + */ |
|
489 | + public function upgrade() |
|
490 | + { |
|
491 | + $classname = get_class($this); |
|
492 | + do_action("AHEE__{$classname}__upgrade"); |
|
493 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
494 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
495 | + // also it's possible there is new default data that needs to be added |
|
496 | + add_action( |
|
497 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
498 | + [$this, 'initialize_db_if_no_migrations_required'] |
|
499 | + ); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
505 | + */ |
|
506 | + public function downgrade() |
|
507 | + { |
|
508 | + $classname = get_class($this); |
|
509 | + do_action("AHEE__{$classname}__downgrade"); |
|
510 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
511 | + // it's possible there's old default data that needs to be double-checked |
|
512 | + add_action( |
|
513 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
514 | + [$this, 'initialize_db_if_no_migrations_required'] |
|
515 | + ); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * set_db_update_option_name |
|
521 | + * Until we do something better, we'll just check for migration scripts upon |
|
522 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
523 | + * |
|
524 | + * @return bool |
|
525 | + */ |
|
526 | + public function set_db_update_option_name(): bool |
|
527 | + { |
|
528 | + EE_Error::doing_it_wrong( |
|
529 | + __FUNCTION__, |
|
530 | + esc_html__( |
|
531 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
532 | + 'event_espresso' |
|
533 | + ), |
|
534 | + '4.3.0.alpha.016' |
|
535 | + ); |
|
536 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
537 | + return $this->set_activation_indicator_option(); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * Returns the name of the activation indicator option |
|
543 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
544 | + * |
|
545 | + * @return string |
|
546 | + * @deprecated since version 4.3.0.alpha.016 |
|
547 | + */ |
|
548 | + public function get_db_update_option_name(): string |
|
549 | + { |
|
550 | + EE_Error::doing_it_wrong( |
|
551 | + __FUNCTION__, |
|
552 | + esc_html__( |
|
553 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + '4.3.0.alpha.016' |
|
557 | + ); |
|
558 | + return $this->get_activation_indicator_option_name(); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * When the addon is activated, this should be called to set a wordpress option that |
|
564 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
565 | + * |
|
566 | + * @return bool |
|
567 | + */ |
|
568 | + public function set_activation_indicator_option(): bool |
|
569 | + { |
|
570 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
571 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
577 | + * |
|
578 | + * @return string |
|
579 | + */ |
|
580 | + public function get_activation_indicator_option_name(): string |
|
581 | + { |
|
582 | + return 'ee_activation_' . $this->name(); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
588 | + * |
|
589 | + * @param int $req_type |
|
590 | + */ |
|
591 | + public function set_req_type(int $req_type) |
|
592 | + { |
|
593 | + $this->_req_type = $req_type; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
599 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
600 | + * EE_System when it is checking for new install or upgrades of addons |
|
601 | + */ |
|
602 | + public function detect_req_type(): int |
|
603 | + { |
|
604 | + if (! $this->_req_type) { |
|
605 | + $this->detect_activation_or_upgrade(); |
|
606 | + } |
|
607 | + return $this->_req_type; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
613 | + * Should only be called once per request |
|
614 | + * |
|
615 | + * @return void |
|
616 | + */ |
|
617 | + public function detect_activation_or_upgrade() |
|
618 | + { |
|
619 | + $activation_history_for_addon = $this->get_activation_history(); |
|
620 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
621 | + $activation_history_for_addon, |
|
622 | + $this->get_activation_indicator_option_name(), |
|
623 | + $this->version() |
|
624 | + ); |
|
625 | + $this->set_req_type($request_type); |
|
626 | + $classname = get_class($this); |
|
627 | + switch ($request_type) { |
|
628 | + case EE_System::req_type_new_activation: |
|
629 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
630 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
631 | + $this->new_install(); |
|
632 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
633 | + break; |
|
634 | + case EE_System::req_type_reactivation: |
|
635 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
636 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
637 | + $this->reactivation(); |
|
638 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
639 | + break; |
|
640 | + case EE_System::req_type_upgrade: |
|
641 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
642 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
643 | + $this->upgrade(); |
|
644 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
645 | + break; |
|
646 | + case EE_System::req_type_downgrade: |
|
647 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
648 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
649 | + $this->downgrade(); |
|
650 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
651 | + break; |
|
652 | + case EE_System::req_type_normal: |
|
653 | + default: |
|
654 | + break; |
|
655 | + } |
|
656 | + |
|
657 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * Updates the version history for this addon |
|
663 | + * |
|
664 | + * @param array $version_history |
|
665 | + * @param string $current_version_to_add |
|
666 | + * @return boolean success |
|
667 | + */ |
|
668 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool |
|
669 | + { |
|
670 | + if (! $version_history) { |
|
671 | + $version_history = $this->get_activation_history(); |
|
672 | + } |
|
673 | + if ($current_version_to_add === null) { |
|
674 | + $current_version_to_add = $this->version(); |
|
675 | + } |
|
676 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
677 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * Gets the name of the wp option that stores the activation history |
|
683 | + * of this addon |
|
684 | + * |
|
685 | + * @return string |
|
686 | + */ |
|
687 | + public function get_activation_history_option_name(): string |
|
688 | + { |
|
689 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Gets the wp option which stores the activation history for this addon |
|
695 | + * |
|
696 | + * @return array |
|
697 | + */ |
|
698 | + public function get_activation_history(): array |
|
699 | + { |
|
700 | + return get_option($this->get_activation_history_option_name(), []); |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @param string $config_section |
|
706 | + */ |
|
707 | + public function set_config_section($config_section = '') |
|
708 | + { |
|
709 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * Sets the filepath to the main plugin file |
|
715 | + * |
|
716 | + * @param string $filepath |
|
717 | + */ |
|
718 | + public function set_main_plugin_file(string $filepath) |
|
719 | + { |
|
720 | + $this->_main_plugin_file = $filepath; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * gets the filepath to teh main file |
|
726 | + * |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_main_plugin_file(): string |
|
730 | + { |
|
731 | + return $this->_main_plugin_file; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Gets the filename (no path) of the main file (the main file loaded |
|
737 | + * by WP) |
|
738 | + * |
|
739 | + * @return string |
|
740 | + */ |
|
741 | + public function get_main_plugin_file_basename(): string |
|
742 | + { |
|
743 | + return plugin_basename($this->get_main_plugin_file()); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * Gets the folder name which contains the main plugin file |
|
749 | + * |
|
750 | + * @return string |
|
751 | + */ |
|
752 | + public function get_main_plugin_file_dirname(): string |
|
753 | + { |
|
754 | + return dirname($this->get_main_plugin_file()); |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + /** |
|
759 | + * sets hooks used in the admin |
|
760 | + * |
|
761 | + * @return void |
|
762 | + */ |
|
763 | + public function admin_init() |
|
764 | + { |
|
765 | + // is admin and not in M-Mode ? |
|
766 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
767 | + add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2); |
|
768 | + add_filter('after_plugin_row_' . $this->_plugin_basename, [$this, 'after_plugin_row'], 10, 3); |
|
769 | + } |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * plugin_actions |
|
775 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
776 | + * |
|
777 | + * @param array $links |
|
778 | + * @param string $file |
|
779 | + * @return array |
|
780 | + */ |
|
781 | + public function plugin_action_links(array $links, string $file): array |
|
782 | + { |
|
783 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
784 | + // before other links |
|
785 | + array_unshift( |
|
786 | + $links, |
|
787 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
788 | + . esc_html__('Settings', 'event_espresso') |
|
789 | + . '</a>' |
|
790 | + ); |
|
791 | + } |
|
792 | + return $links; |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * after_plugin_row |
|
798 | + * Add additional content to the plugins page plugin row |
|
799 | + * Inserts another row |
|
800 | + * |
|
801 | + * @param string $plugin_file |
|
802 | + * @param array $plugin_data |
|
803 | + * @param string $status |
|
804 | + * @return void |
|
805 | + */ |
|
806 | + public function after_plugin_row(string $plugin_file, array $plugin_data, string $status) |
|
807 | + { |
|
808 | + $after_plugin_row = ''; |
|
809 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
810 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
811 | + $class = $status ? 'active' : 'inactive'; |
|
812 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
813 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
814 | + $description = isset($plugins_page_row['description']) |
|
815 | + ? $plugins_page_row['description'] |
|
816 | + : ''; |
|
817 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
818 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
819 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
820 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
821 | + $after_plugin_row .= '<style> |
|
822 | 822 | .ee-button, |
823 | 823 | .ee-button:active, |
824 | 824 | .ee-button:visited { |
@@ -855,67 +855,67 @@ discard block |
||
855 | 855 | } |
856 | 856 | .ee-button:active { top:0; } |
857 | 857 | </style>'; |
858 | - $after_plugin_row .= ' |
|
858 | + $after_plugin_row .= ' |
|
859 | 859 | <p class="ee-addon-upsell-info-dv"> |
860 | 860 | <a class="ee-button" href="' . $link_url . '">' |
861 | - . $link_text |
|
862 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
863 | - . '</a> |
|
861 | + . $link_text |
|
862 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
863 | + . '</a> |
|
864 | 864 | </p>'; |
865 | - $after_plugin_row .= '</td>'; |
|
866 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
867 | - $after_plugin_row .= $description; |
|
868 | - $after_plugin_row .= '</td>'; |
|
869 | - $after_plugin_row .= '</tr>'; |
|
870 | - } else { |
|
871 | - $after_plugin_row .= $description; |
|
872 | - } |
|
873 | - } |
|
874 | - |
|
875 | - echo $after_plugin_row; |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - /** |
|
880 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
881 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
882 | - * for back compat reasons. |
|
883 | - * |
|
884 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
885 | - * |
|
886 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
887 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
888 | - * callback does not get run/set in that request. |
|
889 | - * |
|
890 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
891 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
892 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
893 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
894 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
895 | - * to call `parent::deactivation`. |
|
896 | - * |
|
897 | - * @since 4.9.26 |
|
898 | - */ |
|
899 | - public function after_registration() |
|
900 | - { |
|
901 | - // cricket chirp... cricket chirp... |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * @return string |
|
907 | - */ |
|
908 | - public function getPueSlug(): string |
|
909 | - { |
|
910 | - return $this->pue_slug; |
|
911 | - } |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * @param string $pue_slug |
|
916 | - */ |
|
917 | - public function setPueSlug(string $pue_slug) |
|
918 | - { |
|
919 | - $this->pue_slug = $pue_slug; |
|
920 | - } |
|
865 | + $after_plugin_row .= '</td>'; |
|
866 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
867 | + $after_plugin_row .= $description; |
|
868 | + $after_plugin_row .= '</td>'; |
|
869 | + $after_plugin_row .= '</tr>'; |
|
870 | + } else { |
|
871 | + $after_plugin_row .= $description; |
|
872 | + } |
|
873 | + } |
|
874 | + |
|
875 | + echo $after_plugin_row; |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + /** |
|
880 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
881 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
882 | + * for back compat reasons. |
|
883 | + * |
|
884 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
885 | + * |
|
886 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
887 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
888 | + * callback does not get run/set in that request. |
|
889 | + * |
|
890 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
891 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
892 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
893 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
894 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
895 | + * to call `parent::deactivation`. |
|
896 | + * |
|
897 | + * @since 4.9.26 |
|
898 | + */ |
|
899 | + public function after_registration() |
|
900 | + { |
|
901 | + // cricket chirp... cricket chirp... |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * @return string |
|
907 | + */ |
|
908 | + public function getPueSlug(): string |
|
909 | + { |
|
910 | + return $this->pue_slug; |
|
911 | + } |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * @param string $pue_slug |
|
916 | + */ |
|
917 | + public function setPueSlug(string $pue_slug) |
|
918 | + { |
|
919 | + $this->pue_slug = $pue_slug; |
|
920 | + } |
|
921 | 921 | } |