@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
6 | 6 | |
7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -21,1446 +21,1446 @@ discard block |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
26 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
27 | - */ |
|
28 | - const req_type_normal = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * Indicates this is a brand new installation of EE so we should install |
|
32 | - * tables and default data etc |
|
33 | - */ |
|
34 | - const req_type_new_activation = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
38 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
39 | - * and that default data is setup too |
|
40 | - */ |
|
41 | - const req_type_reactivation = 2; |
|
42 | - |
|
43 | - /** |
|
44 | - * indicates that EE has been upgraded since its previous request. |
|
45 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
46 | - */ |
|
47 | - const req_type_upgrade = 3; |
|
48 | - |
|
49 | - /** |
|
50 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
51 | - */ |
|
52 | - const req_type_downgrade = 4; |
|
53 | - |
|
54 | - /** |
|
55 | - * @deprecated since version 4.6.0.dev.006 |
|
56 | - * Now whenever a new_activation is detected the request type is still just |
|
57 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
58 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
59 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
60 | - * (Specifically, when the migration manager indicates migrations are finished |
|
61 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
62 | - */ |
|
63 | - const req_type_activation_but_not_installed = 5; |
|
64 | - |
|
65 | - /** |
|
66 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
67 | - */ |
|
68 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @var EE_System $_instance |
|
73 | - */ |
|
74 | - private static $_instance = null; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var EE_Registry $registry |
|
78 | - */ |
|
79 | - protected $registry; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var LoaderInterface $loader |
|
83 | - */ |
|
84 | - protected $loader; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var EE_Capabilities $capabilities |
|
88 | - */ |
|
89 | - protected $capabilities; |
|
90 | - |
|
91 | - /** |
|
92 | - * @var EE_Request $request |
|
93 | - */ |
|
94 | - protected $request; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
98 | - */ |
|
99 | - protected $maintenance_mode; |
|
100 | - |
|
101 | - /** |
|
102 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
103 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
104 | - * |
|
105 | - * @var int |
|
106 | - */ |
|
107 | - private $_req_type; |
|
108 | - |
|
109 | - /** |
|
110 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
111 | - * |
|
112 | - * @var boolean |
|
113 | - */ |
|
114 | - private $_major_version_change = false; |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @singleton method used to instantiate class object |
|
120 | - * @param EE_Registry|null $registry |
|
121 | - * @param LoaderInterface|null $loader |
|
122 | - * @param EE_Capabilities|null $capabilities |
|
123 | - * @param EE_Request|null $request |
|
124 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
125 | - * @return EE_System |
|
126 | - */ |
|
127 | - public static function instance( |
|
128 | - EE_Registry $registry = null, |
|
129 | - LoaderInterface $loader = null, |
|
130 | - EE_Capabilities $capabilities = null, |
|
131 | - EE_Request $request = null, |
|
132 | - EE_Maintenance_Mode $maintenance_mode = null |
|
133 | - ) |
|
134 | - { |
|
135 | - // check if class object is instantiated |
|
136 | - if ( ! self::$_instance instanceof EE_System) { |
|
137 | - self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
138 | - } |
|
139 | - return self::$_instance; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * resets the instance and returns it |
|
146 | - * |
|
147 | - * @return EE_System |
|
148 | - */ |
|
149 | - public static function reset() |
|
150 | - { |
|
151 | - self::$_instance->_req_type = null; |
|
152 | - //make sure none of the old hooks are left hanging around |
|
153 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
154 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
155 | - EE_Data_Migration_Manager::reset(); |
|
156 | - self::instance()->detect_activations_or_upgrades(); |
|
157 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
158 | - return self::instance(); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * sets hooks for running rest of system |
|
165 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
166 | - * starting EE Addons from any other point may lead to problems |
|
167 | - * |
|
168 | - * @param EE_Registry $registry |
|
169 | - * @param LoaderInterface $loader |
|
170 | - * @param EE_Capabilities $capabilities |
|
171 | - * @param EE_Request $request |
|
172 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
173 | - */ |
|
174 | - private function __construct( |
|
175 | - EE_Registry $registry, |
|
176 | - LoaderInterface $loader, |
|
177 | - EE_Capabilities $capabilities, |
|
178 | - EE_Request $request, |
|
179 | - EE_Maintenance_Mode $maintenance_mode |
|
180 | - ) { |
|
181 | - $this->registry = $registry; |
|
182 | - $this->loader = $loader; |
|
183 | - $this->capabilities = $capabilities; |
|
184 | - $this->request = $request; |
|
185 | - $this->maintenance_mode = $maintenance_mode; |
|
186 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
187 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
188 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
189 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
190 | - // because the newly-activated addon didn't get a chance to run at all |
|
191 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
192 | - // detect whether install or upgrade |
|
193 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
194 | - 3); |
|
195 | - // load EE_Config, EE_Textdomain, etc |
|
196 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
197 | - // load EE_Config, EE_Textdomain, etc |
|
198 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
199 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
200 | - // you wanna get going? I wanna get going... let's get going! |
|
201 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
202 | - //other housekeeping |
|
203 | - //exclude EE critical pages from wp_list_pages |
|
204 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
205 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
206 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
207 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * load_espresso_addons |
|
214 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
215 | - * this is hooked into both: |
|
216 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
217 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
218 | - * and the WP 'activate_plugin' hookpoint |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return void |
|
222 | - */ |
|
223 | - public function load_espresso_addons() |
|
224 | - { |
|
225 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
226 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
227 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
228 | - //caps need to be initialized on every request so that capability maps are set. |
|
229 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
230 | - $this->capabilities->init_caps(); |
|
231 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
232 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
233 | - //We want it for mobile apps. Just include the entire plugin |
|
234 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
235 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
236 | - //and causes a fatal error |
|
237 | - if ( ! function_exists('json_basic_auth_handler') |
|
238 | - && ! function_exists('json_basic_auth_error') |
|
239 | - && ! ( |
|
240 | - isset($_GET['action']) |
|
241 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
242 | - ) |
|
243 | - && ! ( |
|
244 | - isset($_GET['activate']) |
|
245 | - && $_GET['activate'] === 'true' |
|
246 | - ) |
|
247 | - ) { |
|
248 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
249 | - } |
|
250 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * detect_activations_or_upgrades |
|
257 | - * Checks for activation or upgrade of core first; |
|
258 | - * then also checks if any registered addons have been activated or upgraded |
|
259 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
260 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
261 | - * |
|
262 | - * @access public |
|
263 | - * @return void |
|
264 | - */ |
|
265 | - public function detect_activations_or_upgrades() |
|
266 | - { |
|
267 | - //first off: let's make sure to handle core |
|
268 | - $this->detect_if_activation_or_upgrade(); |
|
269 | - foreach ($this->registry->addons as $addon) { |
|
270 | - //detect teh request type for that addon |
|
271 | - $addon->detect_activation_or_upgrade(); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * detect_if_activation_or_upgrade |
|
279 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
280 | - * and either setting up the DB or setting up maintenance mode etc. |
|
281 | - * |
|
282 | - * @access public |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - public function detect_if_activation_or_upgrade() |
|
286 | - { |
|
287 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
288 | - // check if db has been updated, or if its a brand-new installation |
|
289 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
290 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
291 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
292 | - switch ($request_type) { |
|
293 | - case EE_System::req_type_new_activation: |
|
294 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
295 | - $this->_handle_core_version_change($espresso_db_update); |
|
296 | - break; |
|
297 | - case EE_System::req_type_reactivation: |
|
298 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
299 | - $this->_handle_core_version_change($espresso_db_update); |
|
300 | - break; |
|
301 | - case EE_System::req_type_upgrade: |
|
302 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
303 | - //migrations may be required now that we've upgraded |
|
304 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
305 | - $this->_handle_core_version_change($espresso_db_update); |
|
306 | - // echo "done upgrade";die; |
|
307 | - break; |
|
308 | - case EE_System::req_type_downgrade: |
|
309 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
310 | - //its possible migrations are no longer required |
|
311 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
312 | - $this->_handle_core_version_change($espresso_db_update); |
|
313 | - break; |
|
314 | - case EE_System::req_type_normal: |
|
315 | - default: |
|
316 | - // $this->_maybe_redirect_to_ee_about(); |
|
317 | - break; |
|
318 | - } |
|
319 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Updates the list of installed versions and sets hooks for |
|
326 | - * initializing the database later during the request |
|
327 | - * |
|
328 | - * @param array $espresso_db_update |
|
329 | - */ |
|
330 | - protected function _handle_core_version_change($espresso_db_update) |
|
331 | - { |
|
332 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
333 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
334 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
335 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
342 | - * information about what versions of EE have been installed and activated, |
|
343 | - * NOT necessarily the state of the database |
|
344 | - * |
|
345 | - * @param null $espresso_db_update |
|
346 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
347 | - * from the options table |
|
348 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
349 | - */ |
|
350 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
351 | - { |
|
352 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
353 | - if ( ! $espresso_db_update) { |
|
354 | - $espresso_db_update = get_option('espresso_db_update'); |
|
355 | - } |
|
356 | - // check that option is an array |
|
357 | - if ( ! is_array($espresso_db_update)) { |
|
358 | - // if option is FALSE, then it never existed |
|
359 | - if ($espresso_db_update === false) { |
|
360 | - // make $espresso_db_update an array and save option with autoload OFF |
|
361 | - $espresso_db_update = array(); |
|
362 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
363 | - } else { |
|
364 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
365 | - $espresso_db_update = array($espresso_db_update => array()); |
|
366 | - update_option('espresso_db_update', $espresso_db_update); |
|
367 | - } |
|
368 | - } else { |
|
369 | - $corrected_db_update = array(); |
|
370 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
371 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
372 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
373 | - //the key is an int, and the value IS NOT an array |
|
374 | - //so it must be numerically-indexed, where values are versions installed... |
|
375 | - //fix it! |
|
376 | - $version_string = $should_be_array; |
|
377 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
378 | - } else { |
|
379 | - //ok it checks out |
|
380 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
381 | - } |
|
382 | - } |
|
383 | - $espresso_db_update = $corrected_db_update; |
|
384 | - update_option('espresso_db_update', $espresso_db_update); |
|
385 | - } |
|
386 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
387 | - return $espresso_db_update; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
394 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
395 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
396 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
397 | - * so that it will be done when migrations are finished |
|
398 | - * |
|
399 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
400 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
401 | - * This is a resource-intensive job |
|
402 | - * so we prefer to only do it when necessary |
|
403 | - * @return void |
|
404 | - */ |
|
405 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
406 | - { |
|
407 | - $request_type = $this->detect_req_type(); |
|
408 | - //only initialize system if we're not in maintenance mode. |
|
409 | - if ($this->maintenance_mode->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
410 | - update_option('ee_flush_rewrite_rules', true); |
|
411 | - if ($verify_schema) { |
|
412 | - EEH_Activation::initialize_db_and_folders(); |
|
413 | - } |
|
414 | - EEH_Activation::initialize_db_content(); |
|
415 | - EEH_Activation::system_initialization(); |
|
416 | - if ($initialize_addons_too) { |
|
417 | - $this->initialize_addons(); |
|
418 | - } |
|
419 | - } else { |
|
420 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
421 | - } |
|
422 | - if ($request_type === EE_System::req_type_new_activation |
|
423 | - || $request_type === EE_System::req_type_reactivation |
|
424 | - || ( |
|
425 | - $request_type === EE_System::req_type_upgrade |
|
426 | - && $this->is_major_version_change() |
|
427 | - ) |
|
428 | - ) { |
|
429 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Initializes the db for all registered addons |
|
437 | - */ |
|
438 | - public function initialize_addons() |
|
439 | - { |
|
440 | - //foreach registered addon, make sure its db is up-to-date too |
|
441 | - foreach ($this->registry->addons as $addon) { |
|
442 | - $addon->initialize_db_if_no_migrations_required(); |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
450 | - * |
|
451 | - * @param array $version_history |
|
452 | - * @param string $current_version_to_add version to be added to the version history |
|
453 | - * @return boolean success as to whether or not this option was changed |
|
454 | - */ |
|
455 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
456 | - { |
|
457 | - if ( ! $version_history) { |
|
458 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
459 | - } |
|
460 | - if ($current_version_to_add == null) { |
|
461 | - $current_version_to_add = espresso_version(); |
|
462 | - } |
|
463 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
464 | - // re-save |
|
465 | - return update_option('espresso_db_update', $version_history); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Detects if the current version indicated in the has existed in the list of |
|
472 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
473 | - * |
|
474 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
475 | - * If not supplied, fetches it from the options table. |
|
476 | - * Also, caches its result so later parts of the code can also know whether |
|
477 | - * there's been an update or not. This way we can add the current version to |
|
478 | - * espresso_db_update, but still know if this is a new install or not |
|
479 | - * @return int one of the constants on EE_System::req_type_ |
|
480 | - */ |
|
481 | - public function detect_req_type($espresso_db_update = null) |
|
482 | - { |
|
483 | - if ($this->_req_type === null) { |
|
484 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
485 | - : $this->fix_espresso_db_upgrade_option(); |
|
486 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
487 | - 'ee_espresso_activation', espresso_version()); |
|
488 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
489 | - } |
|
490 | - return $this->_req_type; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
497 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
498 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
499 | - * |
|
500 | - * @param $activation_history |
|
501 | - * @return bool |
|
502 | - */ |
|
503 | - protected function _detect_major_version_change($activation_history) |
|
504 | - { |
|
505 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
506 | - $previous_version_parts = explode('.', $previous_version); |
|
507 | - $current_version_parts = explode('.', espresso_version()); |
|
508 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
509 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
510 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
511 | - ); |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * Returns true if either the major or minor version of EE changed during this request. |
|
518 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
519 | - * |
|
520 | - * @return bool |
|
521 | - */ |
|
522 | - public function is_major_version_change() |
|
523 | - { |
|
524 | - return $this->_major_version_change; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
531 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
532 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
533 | - * just activated to (for core that will always be espresso_version()) |
|
534 | - * |
|
535 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
536 | - * ee plugin. for core that's 'espresso_db_update' |
|
537 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
538 | - * indicate that this plugin was just activated |
|
539 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
540 | - * espresso_version()) |
|
541 | - * @return int one of the constants on EE_System::req_type_* |
|
542 | - */ |
|
543 | - public static function detect_req_type_given_activation_history( |
|
544 | - $activation_history_for_addon, |
|
545 | - $activation_indicator_option_name, |
|
546 | - $version_to_upgrade_to |
|
547 | - ) { |
|
548 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
549 | - if ($activation_history_for_addon) { |
|
550 | - //it exists, so this isn't a completely new install |
|
551 | - //check if this version already in that list of previously installed versions |
|
552 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
553 | - //it a version we haven't seen before |
|
554 | - if ($version_is_higher === 1) { |
|
555 | - $req_type = EE_System::req_type_upgrade; |
|
556 | - } else { |
|
557 | - $req_type = EE_System::req_type_downgrade; |
|
558 | - } |
|
559 | - delete_option($activation_indicator_option_name); |
|
560 | - } else { |
|
561 | - // its not an update. maybe a reactivation? |
|
562 | - if (get_option($activation_indicator_option_name, false)) { |
|
563 | - if ($version_is_higher === -1) { |
|
564 | - $req_type = EE_System::req_type_downgrade; |
|
565 | - } elseif ($version_is_higher === 0) { |
|
566 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
567 | - $req_type = EE_System::req_type_reactivation; |
|
568 | - } else {//$version_is_higher === 1 |
|
569 | - $req_type = EE_System::req_type_upgrade; |
|
570 | - } |
|
571 | - delete_option($activation_indicator_option_name); |
|
572 | - } else { |
|
573 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
574 | - if ($version_is_higher === -1) { |
|
575 | - $req_type = EE_System::req_type_downgrade; |
|
576 | - } elseif ($version_is_higher === 0) { |
|
577 | - //we've seen this version before and it's not an activation. its normal request |
|
578 | - $req_type = EE_System::req_type_normal; |
|
579 | - } else {//$version_is_higher === 1 |
|
580 | - $req_type = EE_System::req_type_upgrade; |
|
581 | - } |
|
582 | - } |
|
583 | - } |
|
584 | - } else { |
|
585 | - //brand new install |
|
586 | - $req_type = EE_System::req_type_new_activation; |
|
587 | - delete_option($activation_indicator_option_name); |
|
588 | - } |
|
589 | - return $req_type; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
596 | - * the $activation_history_for_addon |
|
597 | - * |
|
598 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
599 | - * sometimes containing 'unknown-date' |
|
600 | - * @param string $version_to_upgrade_to (current version) |
|
601 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
602 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
603 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
604 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
605 | - */ |
|
606 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
607 | - { |
|
608 | - //find the most recently-activated version |
|
609 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
610 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Gets the most recently active version listed in the activation history, |
|
617 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
618 | - * |
|
619 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
620 | - * sometimes containing 'unknown-date' |
|
621 | - * @return string |
|
622 | - */ |
|
623 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
624 | - { |
|
625 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
626 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
627 | - if (is_array($activation_history)) { |
|
628 | - foreach ($activation_history as $version => $times_activated) { |
|
629 | - //check there is a record of when this version was activated. Otherwise, |
|
630 | - //mark it as unknown |
|
631 | - if ( ! $times_activated) { |
|
632 | - $times_activated = array('unknown-date'); |
|
633 | - } |
|
634 | - if (is_string($times_activated)) { |
|
635 | - $times_activated = array($times_activated); |
|
636 | - } |
|
637 | - foreach ($times_activated as $an_activation) { |
|
638 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
639 | - $most_recently_active_version = $version; |
|
640 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
641 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
642 | - } |
|
643 | - } |
|
644 | - } |
|
645 | - } |
|
646 | - return $most_recently_active_version; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * This redirects to the about EE page after activation |
|
653 | - * |
|
654 | - * @return void |
|
655 | - */ |
|
656 | - public function redirect_to_about_ee() |
|
657 | - { |
|
658 | - $notices = EE_Error::get_notices(false); |
|
659 | - //if current user is an admin and it's not an ajax or rest request |
|
660 | - if ( |
|
661 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
662 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
663 | - && ! isset($notices['errors']) |
|
664 | - && apply_filters( |
|
665 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
666 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
667 | - ) |
|
668 | - ) { |
|
669 | - $query_params = array('page' => 'espresso_about'); |
|
670 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
671 | - $query_params['new_activation'] = true; |
|
672 | - } |
|
673 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
674 | - $query_params['reactivation'] = true; |
|
675 | - } |
|
676 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
677 | - wp_safe_redirect($url); |
|
678 | - exit(); |
|
679 | - } |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * load_core_configuration |
|
686 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
687 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
688 | - * |
|
689 | - * @return void |
|
690 | - */ |
|
691 | - public function load_core_configuration() |
|
692 | - { |
|
693 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
694 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
695 | - //load textdomain |
|
696 | - EE_Load_Textdomain::load_textdomain(); |
|
697 | - // load and setup EE_Config and EE_Network_Config |
|
698 | - $config = $this->loader->getShared('EE_Config'); |
|
699 | - $this->loader->getShared('EE_Network_Config'); |
|
700 | - // setup autoloaders |
|
701 | - // enable logging? |
|
702 | - if ($config->admin->use_full_logging) { |
|
703 | - $this->loader->getShared('EE_Log'); |
|
704 | - } |
|
705 | - // check for activation errors |
|
706 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
707 | - if ($activation_errors) { |
|
708 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
709 | - update_option('ee_plugin_activation_errors', false); |
|
710 | - } |
|
711 | - // get model names |
|
712 | - $this->_parse_model_names(); |
|
713 | - //load caf stuff a chance to play during the activation process too. |
|
714 | - $this->_maybe_brew_regular(); |
|
715 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
722 | - * |
|
723 | - * @return void |
|
724 | - */ |
|
725 | - private function _parse_model_names() |
|
726 | - { |
|
727 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
728 | - $models = glob(EE_MODELS . '*.model.php'); |
|
729 | - $model_names = array(); |
|
730 | - $non_abstract_db_models = array(); |
|
731 | - foreach ($models as $model) { |
|
732 | - // get model classname |
|
733 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
734 | - $short_name = str_replace('EEM_', '', $classname); |
|
735 | - $reflectionClass = new ReflectionClass($classname); |
|
736 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
737 | - $non_abstract_db_models[$short_name] = $classname; |
|
738 | - } |
|
739 | - $model_names[$short_name] = $classname; |
|
740 | - } |
|
741 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
742 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
743 | - $non_abstract_db_models); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
750 | - * that need to be setup before our EE_System launches. |
|
751 | - * |
|
752 | - * @return void |
|
753 | - */ |
|
754 | - private function _maybe_brew_regular() |
|
755 | - { |
|
756 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
757 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
758 | - } |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * register_shortcodes_modules_and_widgets |
|
765 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
766 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
767 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
768 | - * |
|
769 | - * @access public |
|
770 | - * @return void |
|
771 | - */ |
|
772 | - public function register_shortcodes_modules_and_widgets() |
|
773 | - { |
|
774 | - try { |
|
775 | - // load, register, and add shortcodes the new way |
|
776 | - new ShortcodesManager( |
|
777 | - // and the old way, but we'll put it under control of the new system |
|
778 | - EE_Config::getLegacyShortcodesManager() |
|
779 | - ); |
|
780 | - } catch (Exception $exception) { |
|
781 | - new ExceptionStackTraceDisplay($exception); |
|
782 | - } |
|
783 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
784 | - // check for addons using old hookpoint |
|
785 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
786 | - $this->_incompatible_addon_error(); |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * _incompatible_addon_error |
|
794 | - * |
|
795 | - * @access public |
|
796 | - * @return void |
|
797 | - */ |
|
798 | - private function _incompatible_addon_error() |
|
799 | - { |
|
800 | - // get array of classes hooking into here |
|
801 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
802 | - if ( ! empty($class_names)) { |
|
803 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
804 | - 'event_espresso'); |
|
805 | - $msg .= '<ul>'; |
|
806 | - foreach ($class_names as $class_name) { |
|
807 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
808 | - $class_name) . '</b></li>'; |
|
809 | - } |
|
810 | - $msg .= '</ul>'; |
|
811 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
812 | - 'event_espresso'); |
|
813 | - // save list of incompatible addons to wp-options for later use |
|
814 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
815 | - if (is_admin()) { |
|
816 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
817 | - } |
|
818 | - } |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - |
|
823 | - /** |
|
824 | - * brew_espresso |
|
825 | - * begins the process of setting hooks for initializing EE in the correct order |
|
826 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
827 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
828 | - * |
|
829 | - * @return void |
|
830 | - */ |
|
831 | - public function brew_espresso() |
|
832 | - { |
|
833 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
834 | - // load some final core systems |
|
835 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
836 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
837 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
838 | - add_action('init', array($this, 'load_controllers'), 7); |
|
839 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
840 | - add_action('init', array($this, 'initialize'), 10); |
|
841 | - add_action('init', array($this, 'initialize_last'), 100); |
|
842 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
843 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
844 | - // pew pew pew |
|
845 | - $this->loader->getShared('EE_PUE'); |
|
846 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
847 | - } |
|
848 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * set_hooks_for_core |
|
855 | - * |
|
856 | - * @access public |
|
857 | - * @return void |
|
858 | - */ |
|
859 | - public function set_hooks_for_core() |
|
860 | - { |
|
861 | - $this->_deactivate_incompatible_addons(); |
|
862 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
869 | - * deactivates any addons considered incompatible with the current version of EE |
|
870 | - */ |
|
871 | - private function _deactivate_incompatible_addons() |
|
872 | - { |
|
873 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
874 | - if ( ! empty($incompatible_addons)) { |
|
875 | - $active_plugins = get_option('active_plugins', array()); |
|
876 | - foreach ($active_plugins as $active_plugin) { |
|
877 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
878 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
879 | - unset($_GET['activate']); |
|
880 | - espresso_deactivate_plugin($active_plugin); |
|
881 | - } |
|
882 | - } |
|
883 | - } |
|
884 | - } |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * perform_activations_upgrades_and_migrations |
|
891 | - * |
|
892 | - * @access public |
|
893 | - * @return void |
|
894 | - */ |
|
895 | - public function perform_activations_upgrades_and_migrations() |
|
896 | - { |
|
897 | - //first check if we had previously attempted to setup EE's directories but failed |
|
898 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
899 | - EEH_Activation::create_upload_directories(); |
|
900 | - } |
|
901 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * load_CPTs_and_session |
|
908 | - * |
|
909 | - * @access public |
|
910 | - * @return void |
|
911 | - */ |
|
912 | - public function load_CPTs_and_session() |
|
913 | - { |
|
914 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
915 | - // register Custom Post Types |
|
916 | - $this->loader->getShared('EE_Register_CPTs'); |
|
917 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - |
|
922 | - /** |
|
923 | - * load_controllers |
|
924 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
925 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
926 | - * time |
|
927 | - * |
|
928 | - * @access public |
|
929 | - * @return void |
|
930 | - */ |
|
931 | - public function load_controllers() |
|
932 | - { |
|
933 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
934 | - // let's get it started |
|
935 | - if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
936 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
937 | - $this->loader->getShared('EE_Front_Controller'); |
|
938 | - } else if ( ! EE_FRONT_AJAX) { |
|
939 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
940 | - $this->loader->getShared('EE_Admin'); |
|
941 | - } |
|
942 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * core_loaded_and_ready |
|
949 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
950 | - * |
|
951 | - * @access public |
|
952 | - * @return void |
|
953 | - */ |
|
954 | - public function core_loaded_and_ready() |
|
955 | - { |
|
956 | - $this->registry->load_core('Session'); |
|
957 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
958 | - // load_espresso_template_tags |
|
959 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
960 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
961 | - } |
|
962 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
963 | - $this->loader->getShared('EE_Session'); |
|
964 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
965 | - wp_enqueue_script('espresso_core'); |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * initialize |
|
972 | - * this is the best place to begin initializing client code |
|
973 | - * |
|
974 | - * @access public |
|
975 | - * @return void |
|
976 | - */ |
|
977 | - public function initialize() |
|
978 | - { |
|
979 | - do_action('AHEE__EE_System__initialize'); |
|
980 | - } |
|
981 | - |
|
982 | - |
|
983 | - |
|
984 | - /** |
|
985 | - * initialize_last |
|
986 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
987 | - * initialize has done so |
|
988 | - * |
|
989 | - * @access public |
|
990 | - * @return void |
|
991 | - */ |
|
992 | - public function initialize_last() |
|
993 | - { |
|
994 | - do_action('AHEE__EE_System__initialize_last'); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * set_hooks_for_shortcodes_modules_and_addons |
|
1001 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1002 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
1003 | - * |
|
1004 | - * @access public |
|
1005 | - * @return void |
|
1006 | - */ |
|
1007 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
1008 | - { |
|
1009 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1010 | - } |
|
1011 | - |
|
1012 | - |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * do_not_cache |
|
1016 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1017 | - * |
|
1018 | - * @access public |
|
1019 | - * @return void |
|
1020 | - */ |
|
1021 | - public static function do_not_cache() |
|
1022 | - { |
|
1023 | - // set no cache constants |
|
1024 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
1025 | - define('DONOTCACHEPAGE', true); |
|
1026 | - } |
|
1027 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1028 | - define('DONOTCACHCEOBJECT', true); |
|
1029 | - } |
|
1030 | - if ( ! defined('DONOTCACHEDB')) { |
|
1031 | - define('DONOTCACHEDB', true); |
|
1032 | - } |
|
1033 | - // add no cache headers |
|
1034 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1035 | - // plus a little extra for nginx and Google Chrome |
|
1036 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1037 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1038 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1039 | - } |
|
1040 | - |
|
1041 | - |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * extra_nocache_headers |
|
1045 | - * |
|
1046 | - * @access public |
|
1047 | - * @param $headers |
|
1048 | - * @return array |
|
1049 | - */ |
|
1050 | - public static function extra_nocache_headers($headers) |
|
1051 | - { |
|
1052 | - // for NGINX |
|
1053 | - $headers['X-Accel-Expires'] = 0; |
|
1054 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1055 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1056 | - return $headers; |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * nocache_headers |
|
1063 | - * |
|
1064 | - * @access public |
|
1065 | - * @return void |
|
1066 | - */ |
|
1067 | - public static function nocache_headers() |
|
1068 | - { |
|
1069 | - nocache_headers(); |
|
1070 | - } |
|
1071 | - |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * espresso_toolbar_items |
|
1076 | - * |
|
1077 | - * @access public |
|
1078 | - * @param WP_Admin_Bar $admin_bar |
|
1079 | - * @return void |
|
1080 | - */ |
|
1081 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1082 | - { |
|
1083 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1084 | - if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1085 | - || defined('DOING_AJAX') |
|
1086 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1087 | - ) { |
|
1088 | - return; |
|
1089 | - } |
|
1090 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1091 | - $menu_class = 'espresso_menu_item_class'; |
|
1092 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1093 | - //because they're only defined in each of their respective constructors |
|
1094 | - //and this might be a frontend request, in which case they aren't available |
|
1095 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1096 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1097 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1098 | - //Top Level |
|
1099 | - $admin_bar->add_menu(array( |
|
1100 | - 'id' => 'espresso-toolbar', |
|
1101 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1102 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1103 | - . '</span>', |
|
1104 | - 'href' => $events_admin_url, |
|
1105 | - 'meta' => array( |
|
1106 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1107 | - 'class' => $menu_class . 'first', |
|
1108 | - ), |
|
1109 | - )); |
|
1110 | - //Events |
|
1111 | - if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1112 | - $admin_bar->add_menu(array( |
|
1113 | - 'id' => 'espresso-toolbar-events', |
|
1114 | - 'parent' => 'espresso-toolbar', |
|
1115 | - 'title' => __('Events', 'event_espresso'), |
|
1116 | - 'href' => $events_admin_url, |
|
1117 | - 'meta' => array( |
|
1118 | - 'title' => __('Events', 'event_espresso'), |
|
1119 | - 'target' => '', |
|
1120 | - 'class' => $menu_class, |
|
1121 | - ), |
|
1122 | - )); |
|
1123 | - } |
|
1124 | - if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1125 | - //Events Add New |
|
1126 | - $admin_bar->add_menu(array( |
|
1127 | - 'id' => 'espresso-toolbar-events-new', |
|
1128 | - 'parent' => 'espresso-toolbar-events', |
|
1129 | - 'title' => __('Add New', 'event_espresso'), |
|
1130 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1131 | - 'meta' => array( |
|
1132 | - 'title' => __('Add New', 'event_espresso'), |
|
1133 | - 'target' => '', |
|
1134 | - 'class' => $menu_class, |
|
1135 | - ), |
|
1136 | - )); |
|
1137 | - } |
|
1138 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1139 | - //Current post |
|
1140 | - global $post; |
|
1141 | - if ($this->capabilities->current_user_can('ee_edit_event', |
|
1142 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1143 | - ) { |
|
1144 | - //Events Edit Current Event |
|
1145 | - $admin_bar->add_menu(array( |
|
1146 | - 'id' => 'espresso-toolbar-events-edit', |
|
1147 | - 'parent' => 'espresso-toolbar-events', |
|
1148 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1149 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1150 | - $events_admin_url), |
|
1151 | - 'meta' => array( |
|
1152 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1153 | - 'target' => '', |
|
1154 | - 'class' => $menu_class, |
|
1155 | - ), |
|
1156 | - )); |
|
1157 | - } |
|
1158 | - } |
|
1159 | - //Events View |
|
1160 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1161 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1162 | - ) { |
|
1163 | - $admin_bar->add_menu(array( |
|
1164 | - 'id' => 'espresso-toolbar-events-view', |
|
1165 | - 'parent' => 'espresso-toolbar-events', |
|
1166 | - 'title' => __('View', 'event_espresso'), |
|
1167 | - 'href' => $events_admin_url, |
|
1168 | - 'meta' => array( |
|
1169 | - 'title' => __('View', 'event_espresso'), |
|
1170 | - 'target' => '', |
|
1171 | - 'class' => $menu_class, |
|
1172 | - ), |
|
1173 | - )); |
|
1174 | - } |
|
1175 | - if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1176 | - //Events View All |
|
1177 | - $admin_bar->add_menu(array( |
|
1178 | - 'id' => 'espresso-toolbar-events-all', |
|
1179 | - 'parent' => 'espresso-toolbar-events-view', |
|
1180 | - 'title' => __('All', 'event_espresso'), |
|
1181 | - 'href' => $events_admin_url, |
|
1182 | - 'meta' => array( |
|
1183 | - 'title' => __('All', 'event_espresso'), |
|
1184 | - 'target' => '', |
|
1185 | - 'class' => $menu_class, |
|
1186 | - ), |
|
1187 | - )); |
|
1188 | - } |
|
1189 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1190 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1191 | - ) { |
|
1192 | - //Events View Today |
|
1193 | - $admin_bar->add_menu(array( |
|
1194 | - 'id' => 'espresso-toolbar-events-today', |
|
1195 | - 'parent' => 'espresso-toolbar-events-view', |
|
1196 | - 'title' => __('Today', 'event_espresso'), |
|
1197 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1198 | - $events_admin_url), |
|
1199 | - 'meta' => array( |
|
1200 | - 'title' => __('Today', 'event_espresso'), |
|
1201 | - 'target' => '', |
|
1202 | - 'class' => $menu_class, |
|
1203 | - ), |
|
1204 | - )); |
|
1205 | - } |
|
1206 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1207 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1208 | - ) { |
|
1209 | - //Events View This Month |
|
1210 | - $admin_bar->add_menu(array( |
|
1211 | - 'id' => 'espresso-toolbar-events-month', |
|
1212 | - 'parent' => 'espresso-toolbar-events-view', |
|
1213 | - 'title' => __('This Month', 'event_espresso'), |
|
1214 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1215 | - $events_admin_url), |
|
1216 | - 'meta' => array( |
|
1217 | - 'title' => __('This Month', 'event_espresso'), |
|
1218 | - 'target' => '', |
|
1219 | - 'class' => $menu_class, |
|
1220 | - ), |
|
1221 | - )); |
|
1222 | - } |
|
1223 | - //Registration Overview |
|
1224 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1225 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1226 | - ) { |
|
1227 | - $admin_bar->add_menu(array( |
|
1228 | - 'id' => 'espresso-toolbar-registrations', |
|
1229 | - 'parent' => 'espresso-toolbar', |
|
1230 | - 'title' => __('Registrations', 'event_espresso'), |
|
1231 | - 'href' => $reg_admin_url, |
|
1232 | - 'meta' => array( |
|
1233 | - 'title' => __('Registrations', 'event_espresso'), |
|
1234 | - 'target' => '', |
|
1235 | - 'class' => $menu_class, |
|
1236 | - ), |
|
1237 | - )); |
|
1238 | - } |
|
1239 | - //Registration Overview Today |
|
1240 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1241 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1242 | - ) { |
|
1243 | - $admin_bar->add_menu(array( |
|
1244 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1245 | - 'parent' => 'espresso-toolbar-registrations', |
|
1246 | - 'title' => __('Today', 'event_espresso'), |
|
1247 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1248 | - $reg_admin_url), |
|
1249 | - 'meta' => array( |
|
1250 | - 'title' => __('Today', 'event_espresso'), |
|
1251 | - 'target' => '', |
|
1252 | - 'class' => $menu_class, |
|
1253 | - ), |
|
1254 | - )); |
|
1255 | - } |
|
1256 | - //Registration Overview Today Completed |
|
1257 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1258 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1259 | - ) { |
|
1260 | - $admin_bar->add_menu(array( |
|
1261 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1262 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1263 | - 'title' => __('Approved', 'event_espresso'), |
|
1264 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1265 | - 'action' => 'default', |
|
1266 | - 'status' => 'today', |
|
1267 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1268 | - ), $reg_admin_url), |
|
1269 | - 'meta' => array( |
|
1270 | - 'title' => __('Approved', 'event_espresso'), |
|
1271 | - 'target' => '', |
|
1272 | - 'class' => $menu_class, |
|
1273 | - ), |
|
1274 | - )); |
|
1275 | - } |
|
1276 | - //Registration Overview Today Pending\ |
|
1277 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1278 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1279 | - ) { |
|
1280 | - $admin_bar->add_menu(array( |
|
1281 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1282 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1283 | - 'title' => __('Pending', 'event_espresso'), |
|
1284 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1285 | - 'action' => 'default', |
|
1286 | - 'status' => 'today', |
|
1287 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1288 | - ), $reg_admin_url), |
|
1289 | - 'meta' => array( |
|
1290 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1291 | - 'target' => '', |
|
1292 | - 'class' => $menu_class, |
|
1293 | - ), |
|
1294 | - )); |
|
1295 | - } |
|
1296 | - //Registration Overview Today Incomplete |
|
1297 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1298 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1299 | - ) { |
|
1300 | - $admin_bar->add_menu(array( |
|
1301 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1302 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1303 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1304 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1305 | - 'action' => 'default', |
|
1306 | - 'status' => 'today', |
|
1307 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1308 | - ), $reg_admin_url), |
|
1309 | - 'meta' => array( |
|
1310 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1311 | - 'target' => '', |
|
1312 | - 'class' => $menu_class, |
|
1313 | - ), |
|
1314 | - )); |
|
1315 | - } |
|
1316 | - //Registration Overview Today Incomplete |
|
1317 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1318 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1319 | - ) { |
|
1320 | - $admin_bar->add_menu(array( |
|
1321 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1322 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1323 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1324 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1325 | - 'action' => 'default', |
|
1326 | - 'status' => 'today', |
|
1327 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1328 | - ), $reg_admin_url), |
|
1329 | - 'meta' => array( |
|
1330 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1331 | - 'target' => '', |
|
1332 | - 'class' => $menu_class, |
|
1333 | - ), |
|
1334 | - )); |
|
1335 | - } |
|
1336 | - //Registration Overview This Month |
|
1337 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1338 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1339 | - ) { |
|
1340 | - $admin_bar->add_menu(array( |
|
1341 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1342 | - 'parent' => 'espresso-toolbar-registrations', |
|
1343 | - 'title' => __('This Month', 'event_espresso'), |
|
1344 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1345 | - $reg_admin_url), |
|
1346 | - 'meta' => array( |
|
1347 | - 'title' => __('This Month', 'event_espresso'), |
|
1348 | - 'target' => '', |
|
1349 | - 'class' => $menu_class, |
|
1350 | - ), |
|
1351 | - )); |
|
1352 | - } |
|
1353 | - //Registration Overview This Month Approved |
|
1354 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1355 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1356 | - ) { |
|
1357 | - $admin_bar->add_menu(array( |
|
1358 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1359 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1360 | - 'title' => __('Approved', 'event_espresso'), |
|
1361 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1362 | - 'action' => 'default', |
|
1363 | - 'status' => 'month', |
|
1364 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1365 | - ), $reg_admin_url), |
|
1366 | - 'meta' => array( |
|
1367 | - 'title' => __('Approved', 'event_espresso'), |
|
1368 | - 'target' => '', |
|
1369 | - 'class' => $menu_class, |
|
1370 | - ), |
|
1371 | - )); |
|
1372 | - } |
|
1373 | - //Registration Overview This Month Pending |
|
1374 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1375 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1376 | - ) { |
|
1377 | - $admin_bar->add_menu(array( |
|
1378 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1379 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1380 | - 'title' => __('Pending', 'event_espresso'), |
|
1381 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1382 | - 'action' => 'default', |
|
1383 | - 'status' => 'month', |
|
1384 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1385 | - ), $reg_admin_url), |
|
1386 | - 'meta' => array( |
|
1387 | - 'title' => __('Pending', 'event_espresso'), |
|
1388 | - 'target' => '', |
|
1389 | - 'class' => $menu_class, |
|
1390 | - ), |
|
1391 | - )); |
|
1392 | - } |
|
1393 | - //Registration Overview This Month Not Approved |
|
1394 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1395 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1396 | - ) { |
|
1397 | - $admin_bar->add_menu(array( |
|
1398 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1399 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1400 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1401 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1402 | - 'action' => 'default', |
|
1403 | - 'status' => 'month', |
|
1404 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1405 | - ), $reg_admin_url), |
|
1406 | - 'meta' => array( |
|
1407 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1408 | - 'target' => '', |
|
1409 | - 'class' => $menu_class, |
|
1410 | - ), |
|
1411 | - )); |
|
1412 | - } |
|
1413 | - //Registration Overview This Month Cancelled |
|
1414 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1415 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1416 | - ) { |
|
1417 | - $admin_bar->add_menu(array( |
|
1418 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1419 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1420 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1421 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1422 | - 'action' => 'default', |
|
1423 | - 'status' => 'month', |
|
1424 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1425 | - ), $reg_admin_url), |
|
1426 | - 'meta' => array( |
|
1427 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1428 | - 'target' => '', |
|
1429 | - 'class' => $menu_class, |
|
1430 | - ), |
|
1431 | - )); |
|
1432 | - } |
|
1433 | - //Extensions & Services |
|
1434 | - if ($this->capabilities->current_user_can('ee_read_ee', |
|
1435 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1436 | - ) { |
|
1437 | - $admin_bar->add_menu(array( |
|
1438 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1439 | - 'parent' => 'espresso-toolbar', |
|
1440 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1441 | - 'href' => $extensions_admin_url, |
|
1442 | - 'meta' => array( |
|
1443 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1444 | - 'target' => '', |
|
1445 | - 'class' => $menu_class, |
|
1446 | - ), |
|
1447 | - )); |
|
1448 | - } |
|
1449 | - } |
|
1450 | - |
|
1451 | - |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1455 | - * never returned with the function. |
|
1456 | - * |
|
1457 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1458 | - * @return array |
|
1459 | - */ |
|
1460 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1461 | - { |
|
1462 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1463 | - } |
|
24 | + /** |
|
25 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
26 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
27 | + */ |
|
28 | + const req_type_normal = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * Indicates this is a brand new installation of EE so we should install |
|
32 | + * tables and default data etc |
|
33 | + */ |
|
34 | + const req_type_new_activation = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
38 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
39 | + * and that default data is setup too |
|
40 | + */ |
|
41 | + const req_type_reactivation = 2; |
|
42 | + |
|
43 | + /** |
|
44 | + * indicates that EE has been upgraded since its previous request. |
|
45 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
46 | + */ |
|
47 | + const req_type_upgrade = 3; |
|
48 | + |
|
49 | + /** |
|
50 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
51 | + */ |
|
52 | + const req_type_downgrade = 4; |
|
53 | + |
|
54 | + /** |
|
55 | + * @deprecated since version 4.6.0.dev.006 |
|
56 | + * Now whenever a new_activation is detected the request type is still just |
|
57 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
58 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
59 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
60 | + * (Specifically, when the migration manager indicates migrations are finished |
|
61 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
62 | + */ |
|
63 | + const req_type_activation_but_not_installed = 5; |
|
64 | + |
|
65 | + /** |
|
66 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
67 | + */ |
|
68 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @var EE_System $_instance |
|
73 | + */ |
|
74 | + private static $_instance = null; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var EE_Registry $registry |
|
78 | + */ |
|
79 | + protected $registry; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var LoaderInterface $loader |
|
83 | + */ |
|
84 | + protected $loader; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var EE_Capabilities $capabilities |
|
88 | + */ |
|
89 | + protected $capabilities; |
|
90 | + |
|
91 | + /** |
|
92 | + * @var EE_Request $request |
|
93 | + */ |
|
94 | + protected $request; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
98 | + */ |
|
99 | + protected $maintenance_mode; |
|
100 | + |
|
101 | + /** |
|
102 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
103 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
104 | + * |
|
105 | + * @var int |
|
106 | + */ |
|
107 | + private $_req_type; |
|
108 | + |
|
109 | + /** |
|
110 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
111 | + * |
|
112 | + * @var boolean |
|
113 | + */ |
|
114 | + private $_major_version_change = false; |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @singleton method used to instantiate class object |
|
120 | + * @param EE_Registry|null $registry |
|
121 | + * @param LoaderInterface|null $loader |
|
122 | + * @param EE_Capabilities|null $capabilities |
|
123 | + * @param EE_Request|null $request |
|
124 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
125 | + * @return EE_System |
|
126 | + */ |
|
127 | + public static function instance( |
|
128 | + EE_Registry $registry = null, |
|
129 | + LoaderInterface $loader = null, |
|
130 | + EE_Capabilities $capabilities = null, |
|
131 | + EE_Request $request = null, |
|
132 | + EE_Maintenance_Mode $maintenance_mode = null |
|
133 | + ) |
|
134 | + { |
|
135 | + // check if class object is instantiated |
|
136 | + if ( ! self::$_instance instanceof EE_System) { |
|
137 | + self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
138 | + } |
|
139 | + return self::$_instance; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * resets the instance and returns it |
|
146 | + * |
|
147 | + * @return EE_System |
|
148 | + */ |
|
149 | + public static function reset() |
|
150 | + { |
|
151 | + self::$_instance->_req_type = null; |
|
152 | + //make sure none of the old hooks are left hanging around |
|
153 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
154 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
155 | + EE_Data_Migration_Manager::reset(); |
|
156 | + self::instance()->detect_activations_or_upgrades(); |
|
157 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
158 | + return self::instance(); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * sets hooks for running rest of system |
|
165 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
166 | + * starting EE Addons from any other point may lead to problems |
|
167 | + * |
|
168 | + * @param EE_Registry $registry |
|
169 | + * @param LoaderInterface $loader |
|
170 | + * @param EE_Capabilities $capabilities |
|
171 | + * @param EE_Request $request |
|
172 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
173 | + */ |
|
174 | + private function __construct( |
|
175 | + EE_Registry $registry, |
|
176 | + LoaderInterface $loader, |
|
177 | + EE_Capabilities $capabilities, |
|
178 | + EE_Request $request, |
|
179 | + EE_Maintenance_Mode $maintenance_mode |
|
180 | + ) { |
|
181 | + $this->registry = $registry; |
|
182 | + $this->loader = $loader; |
|
183 | + $this->capabilities = $capabilities; |
|
184 | + $this->request = $request; |
|
185 | + $this->maintenance_mode = $maintenance_mode; |
|
186 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
187 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
188 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
189 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
190 | + // because the newly-activated addon didn't get a chance to run at all |
|
191 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
192 | + // detect whether install or upgrade |
|
193 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
194 | + 3); |
|
195 | + // load EE_Config, EE_Textdomain, etc |
|
196 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
197 | + // load EE_Config, EE_Textdomain, etc |
|
198 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
199 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
200 | + // you wanna get going? I wanna get going... let's get going! |
|
201 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
202 | + //other housekeeping |
|
203 | + //exclude EE critical pages from wp_list_pages |
|
204 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
205 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
206 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
207 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * load_espresso_addons |
|
214 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
215 | + * this is hooked into both: |
|
216 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
217 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
218 | + * and the WP 'activate_plugin' hookpoint |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return void |
|
222 | + */ |
|
223 | + public function load_espresso_addons() |
|
224 | + { |
|
225 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
226 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
227 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
228 | + //caps need to be initialized on every request so that capability maps are set. |
|
229 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
230 | + $this->capabilities->init_caps(); |
|
231 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
232 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
233 | + //We want it for mobile apps. Just include the entire plugin |
|
234 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
235 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
236 | + //and causes a fatal error |
|
237 | + if ( ! function_exists('json_basic_auth_handler') |
|
238 | + && ! function_exists('json_basic_auth_error') |
|
239 | + && ! ( |
|
240 | + isset($_GET['action']) |
|
241 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
242 | + ) |
|
243 | + && ! ( |
|
244 | + isset($_GET['activate']) |
|
245 | + && $_GET['activate'] === 'true' |
|
246 | + ) |
|
247 | + ) { |
|
248 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
249 | + } |
|
250 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * detect_activations_or_upgrades |
|
257 | + * Checks for activation or upgrade of core first; |
|
258 | + * then also checks if any registered addons have been activated or upgraded |
|
259 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
260 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
261 | + * |
|
262 | + * @access public |
|
263 | + * @return void |
|
264 | + */ |
|
265 | + public function detect_activations_or_upgrades() |
|
266 | + { |
|
267 | + //first off: let's make sure to handle core |
|
268 | + $this->detect_if_activation_or_upgrade(); |
|
269 | + foreach ($this->registry->addons as $addon) { |
|
270 | + //detect teh request type for that addon |
|
271 | + $addon->detect_activation_or_upgrade(); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * detect_if_activation_or_upgrade |
|
279 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
280 | + * and either setting up the DB or setting up maintenance mode etc. |
|
281 | + * |
|
282 | + * @access public |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + public function detect_if_activation_or_upgrade() |
|
286 | + { |
|
287 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
288 | + // check if db has been updated, or if its a brand-new installation |
|
289 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
290 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
291 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
292 | + switch ($request_type) { |
|
293 | + case EE_System::req_type_new_activation: |
|
294 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
295 | + $this->_handle_core_version_change($espresso_db_update); |
|
296 | + break; |
|
297 | + case EE_System::req_type_reactivation: |
|
298 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
299 | + $this->_handle_core_version_change($espresso_db_update); |
|
300 | + break; |
|
301 | + case EE_System::req_type_upgrade: |
|
302 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
303 | + //migrations may be required now that we've upgraded |
|
304 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
305 | + $this->_handle_core_version_change($espresso_db_update); |
|
306 | + // echo "done upgrade";die; |
|
307 | + break; |
|
308 | + case EE_System::req_type_downgrade: |
|
309 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
310 | + //its possible migrations are no longer required |
|
311 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
312 | + $this->_handle_core_version_change($espresso_db_update); |
|
313 | + break; |
|
314 | + case EE_System::req_type_normal: |
|
315 | + default: |
|
316 | + // $this->_maybe_redirect_to_ee_about(); |
|
317 | + break; |
|
318 | + } |
|
319 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Updates the list of installed versions and sets hooks for |
|
326 | + * initializing the database later during the request |
|
327 | + * |
|
328 | + * @param array $espresso_db_update |
|
329 | + */ |
|
330 | + protected function _handle_core_version_change($espresso_db_update) |
|
331 | + { |
|
332 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
333 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
334 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
335 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
342 | + * information about what versions of EE have been installed and activated, |
|
343 | + * NOT necessarily the state of the database |
|
344 | + * |
|
345 | + * @param null $espresso_db_update |
|
346 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
347 | + * from the options table |
|
348 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
349 | + */ |
|
350 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
351 | + { |
|
352 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
353 | + if ( ! $espresso_db_update) { |
|
354 | + $espresso_db_update = get_option('espresso_db_update'); |
|
355 | + } |
|
356 | + // check that option is an array |
|
357 | + if ( ! is_array($espresso_db_update)) { |
|
358 | + // if option is FALSE, then it never existed |
|
359 | + if ($espresso_db_update === false) { |
|
360 | + // make $espresso_db_update an array and save option with autoload OFF |
|
361 | + $espresso_db_update = array(); |
|
362 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
363 | + } else { |
|
364 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
365 | + $espresso_db_update = array($espresso_db_update => array()); |
|
366 | + update_option('espresso_db_update', $espresso_db_update); |
|
367 | + } |
|
368 | + } else { |
|
369 | + $corrected_db_update = array(); |
|
370 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
371 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
372 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
373 | + //the key is an int, and the value IS NOT an array |
|
374 | + //so it must be numerically-indexed, where values are versions installed... |
|
375 | + //fix it! |
|
376 | + $version_string = $should_be_array; |
|
377 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
378 | + } else { |
|
379 | + //ok it checks out |
|
380 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
381 | + } |
|
382 | + } |
|
383 | + $espresso_db_update = $corrected_db_update; |
|
384 | + update_option('espresso_db_update', $espresso_db_update); |
|
385 | + } |
|
386 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
387 | + return $espresso_db_update; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
394 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
395 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
396 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
397 | + * so that it will be done when migrations are finished |
|
398 | + * |
|
399 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
400 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
401 | + * This is a resource-intensive job |
|
402 | + * so we prefer to only do it when necessary |
|
403 | + * @return void |
|
404 | + */ |
|
405 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
406 | + { |
|
407 | + $request_type = $this->detect_req_type(); |
|
408 | + //only initialize system if we're not in maintenance mode. |
|
409 | + if ($this->maintenance_mode->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
410 | + update_option('ee_flush_rewrite_rules', true); |
|
411 | + if ($verify_schema) { |
|
412 | + EEH_Activation::initialize_db_and_folders(); |
|
413 | + } |
|
414 | + EEH_Activation::initialize_db_content(); |
|
415 | + EEH_Activation::system_initialization(); |
|
416 | + if ($initialize_addons_too) { |
|
417 | + $this->initialize_addons(); |
|
418 | + } |
|
419 | + } else { |
|
420 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
421 | + } |
|
422 | + if ($request_type === EE_System::req_type_new_activation |
|
423 | + || $request_type === EE_System::req_type_reactivation |
|
424 | + || ( |
|
425 | + $request_type === EE_System::req_type_upgrade |
|
426 | + && $this->is_major_version_change() |
|
427 | + ) |
|
428 | + ) { |
|
429 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Initializes the db for all registered addons |
|
437 | + */ |
|
438 | + public function initialize_addons() |
|
439 | + { |
|
440 | + //foreach registered addon, make sure its db is up-to-date too |
|
441 | + foreach ($this->registry->addons as $addon) { |
|
442 | + $addon->initialize_db_if_no_migrations_required(); |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
450 | + * |
|
451 | + * @param array $version_history |
|
452 | + * @param string $current_version_to_add version to be added to the version history |
|
453 | + * @return boolean success as to whether or not this option was changed |
|
454 | + */ |
|
455 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
456 | + { |
|
457 | + if ( ! $version_history) { |
|
458 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
459 | + } |
|
460 | + if ($current_version_to_add == null) { |
|
461 | + $current_version_to_add = espresso_version(); |
|
462 | + } |
|
463 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
464 | + // re-save |
|
465 | + return update_option('espresso_db_update', $version_history); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Detects if the current version indicated in the has existed in the list of |
|
472 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
473 | + * |
|
474 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
475 | + * If not supplied, fetches it from the options table. |
|
476 | + * Also, caches its result so later parts of the code can also know whether |
|
477 | + * there's been an update or not. This way we can add the current version to |
|
478 | + * espresso_db_update, but still know if this is a new install or not |
|
479 | + * @return int one of the constants on EE_System::req_type_ |
|
480 | + */ |
|
481 | + public function detect_req_type($espresso_db_update = null) |
|
482 | + { |
|
483 | + if ($this->_req_type === null) { |
|
484 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
485 | + : $this->fix_espresso_db_upgrade_option(); |
|
486 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
487 | + 'ee_espresso_activation', espresso_version()); |
|
488 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
489 | + } |
|
490 | + return $this->_req_type; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
497 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
498 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
499 | + * |
|
500 | + * @param $activation_history |
|
501 | + * @return bool |
|
502 | + */ |
|
503 | + protected function _detect_major_version_change($activation_history) |
|
504 | + { |
|
505 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
506 | + $previous_version_parts = explode('.', $previous_version); |
|
507 | + $current_version_parts = explode('.', espresso_version()); |
|
508 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
509 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
510 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
511 | + ); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * Returns true if either the major or minor version of EE changed during this request. |
|
518 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
519 | + * |
|
520 | + * @return bool |
|
521 | + */ |
|
522 | + public function is_major_version_change() |
|
523 | + { |
|
524 | + return $this->_major_version_change; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
531 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
532 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
533 | + * just activated to (for core that will always be espresso_version()) |
|
534 | + * |
|
535 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
536 | + * ee plugin. for core that's 'espresso_db_update' |
|
537 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
538 | + * indicate that this plugin was just activated |
|
539 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
540 | + * espresso_version()) |
|
541 | + * @return int one of the constants on EE_System::req_type_* |
|
542 | + */ |
|
543 | + public static function detect_req_type_given_activation_history( |
|
544 | + $activation_history_for_addon, |
|
545 | + $activation_indicator_option_name, |
|
546 | + $version_to_upgrade_to |
|
547 | + ) { |
|
548 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
549 | + if ($activation_history_for_addon) { |
|
550 | + //it exists, so this isn't a completely new install |
|
551 | + //check if this version already in that list of previously installed versions |
|
552 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
553 | + //it a version we haven't seen before |
|
554 | + if ($version_is_higher === 1) { |
|
555 | + $req_type = EE_System::req_type_upgrade; |
|
556 | + } else { |
|
557 | + $req_type = EE_System::req_type_downgrade; |
|
558 | + } |
|
559 | + delete_option($activation_indicator_option_name); |
|
560 | + } else { |
|
561 | + // its not an update. maybe a reactivation? |
|
562 | + if (get_option($activation_indicator_option_name, false)) { |
|
563 | + if ($version_is_higher === -1) { |
|
564 | + $req_type = EE_System::req_type_downgrade; |
|
565 | + } elseif ($version_is_higher === 0) { |
|
566 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
567 | + $req_type = EE_System::req_type_reactivation; |
|
568 | + } else {//$version_is_higher === 1 |
|
569 | + $req_type = EE_System::req_type_upgrade; |
|
570 | + } |
|
571 | + delete_option($activation_indicator_option_name); |
|
572 | + } else { |
|
573 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
574 | + if ($version_is_higher === -1) { |
|
575 | + $req_type = EE_System::req_type_downgrade; |
|
576 | + } elseif ($version_is_higher === 0) { |
|
577 | + //we've seen this version before and it's not an activation. its normal request |
|
578 | + $req_type = EE_System::req_type_normal; |
|
579 | + } else {//$version_is_higher === 1 |
|
580 | + $req_type = EE_System::req_type_upgrade; |
|
581 | + } |
|
582 | + } |
|
583 | + } |
|
584 | + } else { |
|
585 | + //brand new install |
|
586 | + $req_type = EE_System::req_type_new_activation; |
|
587 | + delete_option($activation_indicator_option_name); |
|
588 | + } |
|
589 | + return $req_type; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
596 | + * the $activation_history_for_addon |
|
597 | + * |
|
598 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
599 | + * sometimes containing 'unknown-date' |
|
600 | + * @param string $version_to_upgrade_to (current version) |
|
601 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
602 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
603 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
604 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
605 | + */ |
|
606 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
607 | + { |
|
608 | + //find the most recently-activated version |
|
609 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
610 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Gets the most recently active version listed in the activation history, |
|
617 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
618 | + * |
|
619 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
620 | + * sometimes containing 'unknown-date' |
|
621 | + * @return string |
|
622 | + */ |
|
623 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
624 | + { |
|
625 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
626 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
627 | + if (is_array($activation_history)) { |
|
628 | + foreach ($activation_history as $version => $times_activated) { |
|
629 | + //check there is a record of when this version was activated. Otherwise, |
|
630 | + //mark it as unknown |
|
631 | + if ( ! $times_activated) { |
|
632 | + $times_activated = array('unknown-date'); |
|
633 | + } |
|
634 | + if (is_string($times_activated)) { |
|
635 | + $times_activated = array($times_activated); |
|
636 | + } |
|
637 | + foreach ($times_activated as $an_activation) { |
|
638 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
639 | + $most_recently_active_version = $version; |
|
640 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
641 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
642 | + } |
|
643 | + } |
|
644 | + } |
|
645 | + } |
|
646 | + return $most_recently_active_version; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * This redirects to the about EE page after activation |
|
653 | + * |
|
654 | + * @return void |
|
655 | + */ |
|
656 | + public function redirect_to_about_ee() |
|
657 | + { |
|
658 | + $notices = EE_Error::get_notices(false); |
|
659 | + //if current user is an admin and it's not an ajax or rest request |
|
660 | + if ( |
|
661 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
662 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
663 | + && ! isset($notices['errors']) |
|
664 | + && apply_filters( |
|
665 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
666 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
667 | + ) |
|
668 | + ) { |
|
669 | + $query_params = array('page' => 'espresso_about'); |
|
670 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
671 | + $query_params['new_activation'] = true; |
|
672 | + } |
|
673 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
674 | + $query_params['reactivation'] = true; |
|
675 | + } |
|
676 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
677 | + wp_safe_redirect($url); |
|
678 | + exit(); |
|
679 | + } |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * load_core_configuration |
|
686 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
687 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
688 | + * |
|
689 | + * @return void |
|
690 | + */ |
|
691 | + public function load_core_configuration() |
|
692 | + { |
|
693 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
694 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
695 | + //load textdomain |
|
696 | + EE_Load_Textdomain::load_textdomain(); |
|
697 | + // load and setup EE_Config and EE_Network_Config |
|
698 | + $config = $this->loader->getShared('EE_Config'); |
|
699 | + $this->loader->getShared('EE_Network_Config'); |
|
700 | + // setup autoloaders |
|
701 | + // enable logging? |
|
702 | + if ($config->admin->use_full_logging) { |
|
703 | + $this->loader->getShared('EE_Log'); |
|
704 | + } |
|
705 | + // check for activation errors |
|
706 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
707 | + if ($activation_errors) { |
|
708 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
709 | + update_option('ee_plugin_activation_errors', false); |
|
710 | + } |
|
711 | + // get model names |
|
712 | + $this->_parse_model_names(); |
|
713 | + //load caf stuff a chance to play during the activation process too. |
|
714 | + $this->_maybe_brew_regular(); |
|
715 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
722 | + * |
|
723 | + * @return void |
|
724 | + */ |
|
725 | + private function _parse_model_names() |
|
726 | + { |
|
727 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
728 | + $models = glob(EE_MODELS . '*.model.php'); |
|
729 | + $model_names = array(); |
|
730 | + $non_abstract_db_models = array(); |
|
731 | + foreach ($models as $model) { |
|
732 | + // get model classname |
|
733 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
734 | + $short_name = str_replace('EEM_', '', $classname); |
|
735 | + $reflectionClass = new ReflectionClass($classname); |
|
736 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
737 | + $non_abstract_db_models[$short_name] = $classname; |
|
738 | + } |
|
739 | + $model_names[$short_name] = $classname; |
|
740 | + } |
|
741 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
742 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
743 | + $non_abstract_db_models); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
750 | + * that need to be setup before our EE_System launches. |
|
751 | + * |
|
752 | + * @return void |
|
753 | + */ |
|
754 | + private function _maybe_brew_regular() |
|
755 | + { |
|
756 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
757 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
758 | + } |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * register_shortcodes_modules_and_widgets |
|
765 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
766 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
767 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
768 | + * |
|
769 | + * @access public |
|
770 | + * @return void |
|
771 | + */ |
|
772 | + public function register_shortcodes_modules_and_widgets() |
|
773 | + { |
|
774 | + try { |
|
775 | + // load, register, and add shortcodes the new way |
|
776 | + new ShortcodesManager( |
|
777 | + // and the old way, but we'll put it under control of the new system |
|
778 | + EE_Config::getLegacyShortcodesManager() |
|
779 | + ); |
|
780 | + } catch (Exception $exception) { |
|
781 | + new ExceptionStackTraceDisplay($exception); |
|
782 | + } |
|
783 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
784 | + // check for addons using old hookpoint |
|
785 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
786 | + $this->_incompatible_addon_error(); |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * _incompatible_addon_error |
|
794 | + * |
|
795 | + * @access public |
|
796 | + * @return void |
|
797 | + */ |
|
798 | + private function _incompatible_addon_error() |
|
799 | + { |
|
800 | + // get array of classes hooking into here |
|
801 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
802 | + if ( ! empty($class_names)) { |
|
803 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
804 | + 'event_espresso'); |
|
805 | + $msg .= '<ul>'; |
|
806 | + foreach ($class_names as $class_name) { |
|
807 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
808 | + $class_name) . '</b></li>'; |
|
809 | + } |
|
810 | + $msg .= '</ul>'; |
|
811 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
812 | + 'event_espresso'); |
|
813 | + // save list of incompatible addons to wp-options for later use |
|
814 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
815 | + if (is_admin()) { |
|
816 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
817 | + } |
|
818 | + } |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + |
|
823 | + /** |
|
824 | + * brew_espresso |
|
825 | + * begins the process of setting hooks for initializing EE in the correct order |
|
826 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
827 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
828 | + * |
|
829 | + * @return void |
|
830 | + */ |
|
831 | + public function brew_espresso() |
|
832 | + { |
|
833 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
834 | + // load some final core systems |
|
835 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
836 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
837 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
838 | + add_action('init', array($this, 'load_controllers'), 7); |
|
839 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
840 | + add_action('init', array($this, 'initialize'), 10); |
|
841 | + add_action('init', array($this, 'initialize_last'), 100); |
|
842 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
843 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
844 | + // pew pew pew |
|
845 | + $this->loader->getShared('EE_PUE'); |
|
846 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
847 | + } |
|
848 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * set_hooks_for_core |
|
855 | + * |
|
856 | + * @access public |
|
857 | + * @return void |
|
858 | + */ |
|
859 | + public function set_hooks_for_core() |
|
860 | + { |
|
861 | + $this->_deactivate_incompatible_addons(); |
|
862 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
869 | + * deactivates any addons considered incompatible with the current version of EE |
|
870 | + */ |
|
871 | + private function _deactivate_incompatible_addons() |
|
872 | + { |
|
873 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
874 | + if ( ! empty($incompatible_addons)) { |
|
875 | + $active_plugins = get_option('active_plugins', array()); |
|
876 | + foreach ($active_plugins as $active_plugin) { |
|
877 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
878 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
879 | + unset($_GET['activate']); |
|
880 | + espresso_deactivate_plugin($active_plugin); |
|
881 | + } |
|
882 | + } |
|
883 | + } |
|
884 | + } |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * perform_activations_upgrades_and_migrations |
|
891 | + * |
|
892 | + * @access public |
|
893 | + * @return void |
|
894 | + */ |
|
895 | + public function perform_activations_upgrades_and_migrations() |
|
896 | + { |
|
897 | + //first check if we had previously attempted to setup EE's directories but failed |
|
898 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
899 | + EEH_Activation::create_upload_directories(); |
|
900 | + } |
|
901 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * load_CPTs_and_session |
|
908 | + * |
|
909 | + * @access public |
|
910 | + * @return void |
|
911 | + */ |
|
912 | + public function load_CPTs_and_session() |
|
913 | + { |
|
914 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
915 | + // register Custom Post Types |
|
916 | + $this->loader->getShared('EE_Register_CPTs'); |
|
917 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + |
|
922 | + /** |
|
923 | + * load_controllers |
|
924 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
925 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
926 | + * time |
|
927 | + * |
|
928 | + * @access public |
|
929 | + * @return void |
|
930 | + */ |
|
931 | + public function load_controllers() |
|
932 | + { |
|
933 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
934 | + // let's get it started |
|
935 | + if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
936 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
937 | + $this->loader->getShared('EE_Front_Controller'); |
|
938 | + } else if ( ! EE_FRONT_AJAX) { |
|
939 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
940 | + $this->loader->getShared('EE_Admin'); |
|
941 | + } |
|
942 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * core_loaded_and_ready |
|
949 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
950 | + * |
|
951 | + * @access public |
|
952 | + * @return void |
|
953 | + */ |
|
954 | + public function core_loaded_and_ready() |
|
955 | + { |
|
956 | + $this->registry->load_core('Session'); |
|
957 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
958 | + // load_espresso_template_tags |
|
959 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
960 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
961 | + } |
|
962 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
963 | + $this->loader->getShared('EE_Session'); |
|
964 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
965 | + wp_enqueue_script('espresso_core'); |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * initialize |
|
972 | + * this is the best place to begin initializing client code |
|
973 | + * |
|
974 | + * @access public |
|
975 | + * @return void |
|
976 | + */ |
|
977 | + public function initialize() |
|
978 | + { |
|
979 | + do_action('AHEE__EE_System__initialize'); |
|
980 | + } |
|
981 | + |
|
982 | + |
|
983 | + |
|
984 | + /** |
|
985 | + * initialize_last |
|
986 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
987 | + * initialize has done so |
|
988 | + * |
|
989 | + * @access public |
|
990 | + * @return void |
|
991 | + */ |
|
992 | + public function initialize_last() |
|
993 | + { |
|
994 | + do_action('AHEE__EE_System__initialize_last'); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * set_hooks_for_shortcodes_modules_and_addons |
|
1001 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1002 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
1003 | + * |
|
1004 | + * @access public |
|
1005 | + * @return void |
|
1006 | + */ |
|
1007 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
1008 | + { |
|
1009 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1010 | + } |
|
1011 | + |
|
1012 | + |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * do_not_cache |
|
1016 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1017 | + * |
|
1018 | + * @access public |
|
1019 | + * @return void |
|
1020 | + */ |
|
1021 | + public static function do_not_cache() |
|
1022 | + { |
|
1023 | + // set no cache constants |
|
1024 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1025 | + define('DONOTCACHEPAGE', true); |
|
1026 | + } |
|
1027 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1028 | + define('DONOTCACHCEOBJECT', true); |
|
1029 | + } |
|
1030 | + if ( ! defined('DONOTCACHEDB')) { |
|
1031 | + define('DONOTCACHEDB', true); |
|
1032 | + } |
|
1033 | + // add no cache headers |
|
1034 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1035 | + // plus a little extra for nginx and Google Chrome |
|
1036 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1037 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1038 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1039 | + } |
|
1040 | + |
|
1041 | + |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * extra_nocache_headers |
|
1045 | + * |
|
1046 | + * @access public |
|
1047 | + * @param $headers |
|
1048 | + * @return array |
|
1049 | + */ |
|
1050 | + public static function extra_nocache_headers($headers) |
|
1051 | + { |
|
1052 | + // for NGINX |
|
1053 | + $headers['X-Accel-Expires'] = 0; |
|
1054 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1055 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1056 | + return $headers; |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * nocache_headers |
|
1063 | + * |
|
1064 | + * @access public |
|
1065 | + * @return void |
|
1066 | + */ |
|
1067 | + public static function nocache_headers() |
|
1068 | + { |
|
1069 | + nocache_headers(); |
|
1070 | + } |
|
1071 | + |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * espresso_toolbar_items |
|
1076 | + * |
|
1077 | + * @access public |
|
1078 | + * @param WP_Admin_Bar $admin_bar |
|
1079 | + * @return void |
|
1080 | + */ |
|
1081 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1082 | + { |
|
1083 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1084 | + if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1085 | + || defined('DOING_AJAX') |
|
1086 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1087 | + ) { |
|
1088 | + return; |
|
1089 | + } |
|
1090 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1091 | + $menu_class = 'espresso_menu_item_class'; |
|
1092 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1093 | + //because they're only defined in each of their respective constructors |
|
1094 | + //and this might be a frontend request, in which case they aren't available |
|
1095 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1096 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1097 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1098 | + //Top Level |
|
1099 | + $admin_bar->add_menu(array( |
|
1100 | + 'id' => 'espresso-toolbar', |
|
1101 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1102 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1103 | + . '</span>', |
|
1104 | + 'href' => $events_admin_url, |
|
1105 | + 'meta' => array( |
|
1106 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1107 | + 'class' => $menu_class . 'first', |
|
1108 | + ), |
|
1109 | + )); |
|
1110 | + //Events |
|
1111 | + if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1112 | + $admin_bar->add_menu(array( |
|
1113 | + 'id' => 'espresso-toolbar-events', |
|
1114 | + 'parent' => 'espresso-toolbar', |
|
1115 | + 'title' => __('Events', 'event_espresso'), |
|
1116 | + 'href' => $events_admin_url, |
|
1117 | + 'meta' => array( |
|
1118 | + 'title' => __('Events', 'event_espresso'), |
|
1119 | + 'target' => '', |
|
1120 | + 'class' => $menu_class, |
|
1121 | + ), |
|
1122 | + )); |
|
1123 | + } |
|
1124 | + if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1125 | + //Events Add New |
|
1126 | + $admin_bar->add_menu(array( |
|
1127 | + 'id' => 'espresso-toolbar-events-new', |
|
1128 | + 'parent' => 'espresso-toolbar-events', |
|
1129 | + 'title' => __('Add New', 'event_espresso'), |
|
1130 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1131 | + 'meta' => array( |
|
1132 | + 'title' => __('Add New', 'event_espresso'), |
|
1133 | + 'target' => '', |
|
1134 | + 'class' => $menu_class, |
|
1135 | + ), |
|
1136 | + )); |
|
1137 | + } |
|
1138 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1139 | + //Current post |
|
1140 | + global $post; |
|
1141 | + if ($this->capabilities->current_user_can('ee_edit_event', |
|
1142 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1143 | + ) { |
|
1144 | + //Events Edit Current Event |
|
1145 | + $admin_bar->add_menu(array( |
|
1146 | + 'id' => 'espresso-toolbar-events-edit', |
|
1147 | + 'parent' => 'espresso-toolbar-events', |
|
1148 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1149 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1150 | + $events_admin_url), |
|
1151 | + 'meta' => array( |
|
1152 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1153 | + 'target' => '', |
|
1154 | + 'class' => $menu_class, |
|
1155 | + ), |
|
1156 | + )); |
|
1157 | + } |
|
1158 | + } |
|
1159 | + //Events View |
|
1160 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1161 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1162 | + ) { |
|
1163 | + $admin_bar->add_menu(array( |
|
1164 | + 'id' => 'espresso-toolbar-events-view', |
|
1165 | + 'parent' => 'espresso-toolbar-events', |
|
1166 | + 'title' => __('View', 'event_espresso'), |
|
1167 | + 'href' => $events_admin_url, |
|
1168 | + 'meta' => array( |
|
1169 | + 'title' => __('View', 'event_espresso'), |
|
1170 | + 'target' => '', |
|
1171 | + 'class' => $menu_class, |
|
1172 | + ), |
|
1173 | + )); |
|
1174 | + } |
|
1175 | + if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1176 | + //Events View All |
|
1177 | + $admin_bar->add_menu(array( |
|
1178 | + 'id' => 'espresso-toolbar-events-all', |
|
1179 | + 'parent' => 'espresso-toolbar-events-view', |
|
1180 | + 'title' => __('All', 'event_espresso'), |
|
1181 | + 'href' => $events_admin_url, |
|
1182 | + 'meta' => array( |
|
1183 | + 'title' => __('All', 'event_espresso'), |
|
1184 | + 'target' => '', |
|
1185 | + 'class' => $menu_class, |
|
1186 | + ), |
|
1187 | + )); |
|
1188 | + } |
|
1189 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1190 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1191 | + ) { |
|
1192 | + //Events View Today |
|
1193 | + $admin_bar->add_menu(array( |
|
1194 | + 'id' => 'espresso-toolbar-events-today', |
|
1195 | + 'parent' => 'espresso-toolbar-events-view', |
|
1196 | + 'title' => __('Today', 'event_espresso'), |
|
1197 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1198 | + $events_admin_url), |
|
1199 | + 'meta' => array( |
|
1200 | + 'title' => __('Today', 'event_espresso'), |
|
1201 | + 'target' => '', |
|
1202 | + 'class' => $menu_class, |
|
1203 | + ), |
|
1204 | + )); |
|
1205 | + } |
|
1206 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1207 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1208 | + ) { |
|
1209 | + //Events View This Month |
|
1210 | + $admin_bar->add_menu(array( |
|
1211 | + 'id' => 'espresso-toolbar-events-month', |
|
1212 | + 'parent' => 'espresso-toolbar-events-view', |
|
1213 | + 'title' => __('This Month', 'event_espresso'), |
|
1214 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1215 | + $events_admin_url), |
|
1216 | + 'meta' => array( |
|
1217 | + 'title' => __('This Month', 'event_espresso'), |
|
1218 | + 'target' => '', |
|
1219 | + 'class' => $menu_class, |
|
1220 | + ), |
|
1221 | + )); |
|
1222 | + } |
|
1223 | + //Registration Overview |
|
1224 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1225 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1226 | + ) { |
|
1227 | + $admin_bar->add_menu(array( |
|
1228 | + 'id' => 'espresso-toolbar-registrations', |
|
1229 | + 'parent' => 'espresso-toolbar', |
|
1230 | + 'title' => __('Registrations', 'event_espresso'), |
|
1231 | + 'href' => $reg_admin_url, |
|
1232 | + 'meta' => array( |
|
1233 | + 'title' => __('Registrations', 'event_espresso'), |
|
1234 | + 'target' => '', |
|
1235 | + 'class' => $menu_class, |
|
1236 | + ), |
|
1237 | + )); |
|
1238 | + } |
|
1239 | + //Registration Overview Today |
|
1240 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1241 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1242 | + ) { |
|
1243 | + $admin_bar->add_menu(array( |
|
1244 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1245 | + 'parent' => 'espresso-toolbar-registrations', |
|
1246 | + 'title' => __('Today', 'event_espresso'), |
|
1247 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1248 | + $reg_admin_url), |
|
1249 | + 'meta' => array( |
|
1250 | + 'title' => __('Today', 'event_espresso'), |
|
1251 | + 'target' => '', |
|
1252 | + 'class' => $menu_class, |
|
1253 | + ), |
|
1254 | + )); |
|
1255 | + } |
|
1256 | + //Registration Overview Today Completed |
|
1257 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1258 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1259 | + ) { |
|
1260 | + $admin_bar->add_menu(array( |
|
1261 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1262 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1263 | + 'title' => __('Approved', 'event_espresso'), |
|
1264 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1265 | + 'action' => 'default', |
|
1266 | + 'status' => 'today', |
|
1267 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1268 | + ), $reg_admin_url), |
|
1269 | + 'meta' => array( |
|
1270 | + 'title' => __('Approved', 'event_espresso'), |
|
1271 | + 'target' => '', |
|
1272 | + 'class' => $menu_class, |
|
1273 | + ), |
|
1274 | + )); |
|
1275 | + } |
|
1276 | + //Registration Overview Today Pending\ |
|
1277 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1278 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1279 | + ) { |
|
1280 | + $admin_bar->add_menu(array( |
|
1281 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1282 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1283 | + 'title' => __('Pending', 'event_espresso'), |
|
1284 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1285 | + 'action' => 'default', |
|
1286 | + 'status' => 'today', |
|
1287 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1288 | + ), $reg_admin_url), |
|
1289 | + 'meta' => array( |
|
1290 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1291 | + 'target' => '', |
|
1292 | + 'class' => $menu_class, |
|
1293 | + ), |
|
1294 | + )); |
|
1295 | + } |
|
1296 | + //Registration Overview Today Incomplete |
|
1297 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1298 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1299 | + ) { |
|
1300 | + $admin_bar->add_menu(array( |
|
1301 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1302 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1303 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1304 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1305 | + 'action' => 'default', |
|
1306 | + 'status' => 'today', |
|
1307 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1308 | + ), $reg_admin_url), |
|
1309 | + 'meta' => array( |
|
1310 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1311 | + 'target' => '', |
|
1312 | + 'class' => $menu_class, |
|
1313 | + ), |
|
1314 | + )); |
|
1315 | + } |
|
1316 | + //Registration Overview Today Incomplete |
|
1317 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1318 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1319 | + ) { |
|
1320 | + $admin_bar->add_menu(array( |
|
1321 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1322 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1323 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1324 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1325 | + 'action' => 'default', |
|
1326 | + 'status' => 'today', |
|
1327 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1328 | + ), $reg_admin_url), |
|
1329 | + 'meta' => array( |
|
1330 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1331 | + 'target' => '', |
|
1332 | + 'class' => $menu_class, |
|
1333 | + ), |
|
1334 | + )); |
|
1335 | + } |
|
1336 | + //Registration Overview This Month |
|
1337 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1338 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1339 | + ) { |
|
1340 | + $admin_bar->add_menu(array( |
|
1341 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1342 | + 'parent' => 'espresso-toolbar-registrations', |
|
1343 | + 'title' => __('This Month', 'event_espresso'), |
|
1344 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1345 | + $reg_admin_url), |
|
1346 | + 'meta' => array( |
|
1347 | + 'title' => __('This Month', 'event_espresso'), |
|
1348 | + 'target' => '', |
|
1349 | + 'class' => $menu_class, |
|
1350 | + ), |
|
1351 | + )); |
|
1352 | + } |
|
1353 | + //Registration Overview This Month Approved |
|
1354 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1355 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1356 | + ) { |
|
1357 | + $admin_bar->add_menu(array( |
|
1358 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1359 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1360 | + 'title' => __('Approved', 'event_espresso'), |
|
1361 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1362 | + 'action' => 'default', |
|
1363 | + 'status' => 'month', |
|
1364 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1365 | + ), $reg_admin_url), |
|
1366 | + 'meta' => array( |
|
1367 | + 'title' => __('Approved', 'event_espresso'), |
|
1368 | + 'target' => '', |
|
1369 | + 'class' => $menu_class, |
|
1370 | + ), |
|
1371 | + )); |
|
1372 | + } |
|
1373 | + //Registration Overview This Month Pending |
|
1374 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1375 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1376 | + ) { |
|
1377 | + $admin_bar->add_menu(array( |
|
1378 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1379 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1380 | + 'title' => __('Pending', 'event_espresso'), |
|
1381 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1382 | + 'action' => 'default', |
|
1383 | + 'status' => 'month', |
|
1384 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1385 | + ), $reg_admin_url), |
|
1386 | + 'meta' => array( |
|
1387 | + 'title' => __('Pending', 'event_espresso'), |
|
1388 | + 'target' => '', |
|
1389 | + 'class' => $menu_class, |
|
1390 | + ), |
|
1391 | + )); |
|
1392 | + } |
|
1393 | + //Registration Overview This Month Not Approved |
|
1394 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1395 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1396 | + ) { |
|
1397 | + $admin_bar->add_menu(array( |
|
1398 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1399 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1400 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1401 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1402 | + 'action' => 'default', |
|
1403 | + 'status' => 'month', |
|
1404 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1405 | + ), $reg_admin_url), |
|
1406 | + 'meta' => array( |
|
1407 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1408 | + 'target' => '', |
|
1409 | + 'class' => $menu_class, |
|
1410 | + ), |
|
1411 | + )); |
|
1412 | + } |
|
1413 | + //Registration Overview This Month Cancelled |
|
1414 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1415 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1416 | + ) { |
|
1417 | + $admin_bar->add_menu(array( |
|
1418 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1419 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1420 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1421 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1422 | + 'action' => 'default', |
|
1423 | + 'status' => 'month', |
|
1424 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1425 | + ), $reg_admin_url), |
|
1426 | + 'meta' => array( |
|
1427 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1428 | + 'target' => '', |
|
1429 | + 'class' => $menu_class, |
|
1430 | + ), |
|
1431 | + )); |
|
1432 | + } |
|
1433 | + //Extensions & Services |
|
1434 | + if ($this->capabilities->current_user_can('ee_read_ee', |
|
1435 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1436 | + ) { |
|
1437 | + $admin_bar->add_menu(array( |
|
1438 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1439 | + 'parent' => 'espresso-toolbar', |
|
1440 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1441 | + 'href' => $extensions_admin_url, |
|
1442 | + 'meta' => array( |
|
1443 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1444 | + 'target' => '', |
|
1445 | + 'class' => $menu_class, |
|
1446 | + ), |
|
1447 | + )); |
|
1448 | + } |
|
1449 | + } |
|
1450 | + |
|
1451 | + |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1455 | + * never returned with the function. |
|
1456 | + * |
|
1457 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1458 | + * @return array |
|
1459 | + */ |
|
1460 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1461 | + { |
|
1462 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1463 | + } |
|
1464 | 1464 | |
1465 | 1465 | |
1466 | 1466 |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | { |
225 | 225 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
226 | 226 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
227 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
227 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
228 | 228 | //caps need to be initialized on every request so that capability maps are set. |
229 | 229 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
230 | 230 | $this->capabilities->init_caps(); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | && $_GET['activate'] === 'true' |
246 | 246 | ) |
247 | 247 | ) { |
248 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
248 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
249 | 249 | } |
250 | 250 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
251 | 251 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | private function _parse_model_names() |
726 | 726 | { |
727 | 727 | //get all the files in the EE_MODELS folder that end in .model.php |
728 | - $models = glob(EE_MODELS . '*.model.php'); |
|
728 | + $models = glob(EE_MODELS.'*.model.php'); |
|
729 | 729 | $model_names = array(); |
730 | 730 | $non_abstract_db_models = array(); |
731 | 731 | foreach ($models as $model) { |
@@ -753,8 +753,8 @@ discard block |
||
753 | 753 | */ |
754 | 754 | private function _maybe_brew_regular() |
755 | 755 | { |
756 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
757 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
756 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
757 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | 'event_espresso'); |
805 | 805 | $msg .= '<ul>'; |
806 | 806 | foreach ($class_names as $class_name) { |
807 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
808 | - $class_name) . '</b></li>'; |
|
807 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
808 | + $class_name).'</b></li>'; |
|
809 | 809 | } |
810 | 810 | $msg .= '</ul>'; |
811 | 811 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -956,8 +956,8 @@ discard block |
||
956 | 956 | $this->registry->load_core('Session'); |
957 | 957 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
958 | 958 | // load_espresso_template_tags |
959 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
960 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
959 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
960 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
961 | 961 | } |
962 | 962 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
963 | 963 | $this->loader->getShared('EE_Session'); |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | 'href' => $events_admin_url, |
1105 | 1105 | 'meta' => array( |
1106 | 1106 | 'title' => __('Event Espresso', 'event_espresso'), |
1107 | - 'class' => $menu_class . 'first', |
|
1107 | + 'class' => $menu_class.'first', |
|
1108 | 1108 | ), |
1109 | 1109 | )); |
1110 | 1110 | //Events |
@@ -16,1464 +16,1464 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - */ |
|
224 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
225 | - { |
|
226 | - $this->_dependency_map = $dependency_map; |
|
227 | - $this->LIB = new stdClass(); |
|
228 | - $this->addons = new stdClass(); |
|
229 | - $this->modules = new stdClass(); |
|
230 | - $this->shortcodes = new stdClass(); |
|
231 | - $this->widgets = new stdClass(); |
|
232 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * initialize |
|
239 | - */ |
|
240 | - public function initialize() |
|
241 | - { |
|
242 | - $this->_class_abbreviations = apply_filters( |
|
243 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
244 | - array( |
|
245 | - 'EE_Config' => 'CFG', |
|
246 | - 'EE_Session' => 'SSN', |
|
247 | - 'EE_Capabilities' => 'CAP', |
|
248 | - 'EE_Cart' => 'CART', |
|
249 | - 'EE_Network_Config' => 'NET_CFG', |
|
250 | - 'EE_Request_Handler' => 'REQ', |
|
251 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
252 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
253 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
254 | - ) |
|
255 | - ); |
|
256 | - $this->load_core('Base', array(), true); |
|
257 | - // add our request and response objects to the cache |
|
258 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
259 | - $this->_set_cached_class( |
|
260 | - $request_loader(), |
|
261 | - 'EE_Request' |
|
262 | - ); |
|
263 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
264 | - $this->_set_cached_class( |
|
265 | - $response_loader(), |
|
266 | - 'EE_Response' |
|
267 | - ); |
|
268 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * init |
|
275 | - * |
|
276 | - * @access public |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - public function init() |
|
280 | - { |
|
281 | - // Get current page protocol |
|
282 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
283 | - // Output admin-ajax.php URL with same protocol as current page |
|
284 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
285 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * localize_i18n_js_strings |
|
292 | - * |
|
293 | - * @return string |
|
294 | - */ |
|
295 | - public static function localize_i18n_js_strings() |
|
296 | - { |
|
297 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
298 | - foreach ($i18n_js_strings as $key => $value) { |
|
299 | - if (is_scalar($value)) { |
|
300 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
301 | - } |
|
302 | - } |
|
303 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param mixed string | EED_Module $module |
|
310 | - */ |
|
311 | - public function add_module($module) |
|
312 | - { |
|
313 | - if ($module instanceof EED_Module) { |
|
314 | - $module_class = get_class($module); |
|
315 | - $this->modules->{$module_class} = $module; |
|
316 | - } else { |
|
317 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
318 | - $this->load_core('Module_Request_Router'); |
|
319 | - } |
|
320 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string $module_name |
|
328 | - * @return mixed EED_Module | NULL |
|
329 | - */ |
|
330 | - public function get_module($module_name = '') |
|
331 | - { |
|
332 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * loads core classes - must be singletons |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @param string $class_name - simple class name ie: session |
|
342 | - * @param mixed $arguments |
|
343 | - * @param bool $load_only |
|
344 | - * @return mixed |
|
345 | - */ |
|
346 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
347 | - { |
|
348 | - $core_paths = apply_filters( |
|
349 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
350 | - array( |
|
351 | - EE_CORE, |
|
352 | - EE_ADMIN, |
|
353 | - EE_CPTS, |
|
354 | - EE_CORE . 'data_migration_scripts' . DS, |
|
355 | - EE_CORE . 'request_stack' . DS, |
|
356 | - EE_CORE . 'middleware' . DS, |
|
357 | - ) |
|
358 | - ); |
|
359 | - // retrieve instantiated class |
|
360 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * loads service classes |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $class_name - simple class name ie: session |
|
370 | - * @param mixed $arguments |
|
371 | - * @param bool $load_only |
|
372 | - * @return mixed |
|
373 | - */ |
|
374 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
375 | - { |
|
376 | - $service_paths = apply_filters( |
|
377 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
378 | - array( |
|
379 | - EE_CORE . 'services' . DS, |
|
380 | - ) |
|
381 | - ); |
|
382 | - // retrieve instantiated class |
|
383 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * loads data_migration_scripts |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
393 | - * @param mixed $arguments |
|
394 | - * @return EE_Data_Migration_Script_Base|mixed |
|
395 | - */ |
|
396 | - public function load_dms($class_name, $arguments = array()) |
|
397 | - { |
|
398 | - // retrieve instantiated class |
|
399 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * loads object creating classes - must be singletons |
|
406 | - * |
|
407 | - * @param string $class_name - simple class name ie: attendee |
|
408 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
409 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
410 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
411 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
412 | - * @return EE_Base_Class | bool |
|
413 | - */ |
|
414 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
415 | - { |
|
416 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
417 | - EE_CORE, |
|
418 | - EE_CLASSES, |
|
419 | - EE_BUSINESS, |
|
420 | - )); |
|
421 | - // retrieve instantiated class |
|
422 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * loads helper classes - must be singletons |
|
429 | - * |
|
430 | - * @param string $class_name - simple class name ie: price |
|
431 | - * @param mixed $arguments |
|
432 | - * @param bool $load_only |
|
433 | - * @return EEH_Base | bool |
|
434 | - */ |
|
435 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
436 | - { |
|
437 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
438 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
439 | - // retrieve instantiated class |
|
440 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * loads core classes - must be singletons |
|
447 | - * |
|
448 | - * @access public |
|
449 | - * @param string $class_name - simple class name ie: session |
|
450 | - * @param mixed $arguments |
|
451 | - * @param bool $load_only |
|
452 | - * @param bool $cache whether to cache the object or not. |
|
453 | - * @return mixed |
|
454 | - */ |
|
455 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
456 | - { |
|
457 | - $paths = array( |
|
458 | - EE_LIBRARIES, |
|
459 | - EE_LIBRARIES . 'messages' . DS, |
|
460 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
461 | - EE_LIBRARIES . 'qtips' . DS, |
|
462 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
463 | - ); |
|
464 | - // retrieve instantiated class |
|
465 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * loads model classes - must be singletons |
|
472 | - * |
|
473 | - * @param string $class_name - simple class name ie: price |
|
474 | - * @param mixed $arguments |
|
475 | - * @param bool $load_only |
|
476 | - * @return EEM_Base | bool |
|
477 | - */ |
|
478 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
479 | - { |
|
480 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
481 | - EE_MODELS, |
|
482 | - EE_CORE, |
|
483 | - )); |
|
484 | - // retrieve instantiated class |
|
485 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * loads model classes - must be singletons |
|
492 | - * |
|
493 | - * @param string $class_name - simple class name ie: price |
|
494 | - * @param mixed $arguments |
|
495 | - * @param bool $load_only |
|
496 | - * @return mixed | bool |
|
497 | - */ |
|
498 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
499 | - { |
|
500 | - $paths = array( |
|
501 | - EE_MODELS . 'fields' . DS, |
|
502 | - EE_MODELS . 'helpers' . DS, |
|
503 | - EE_MODELS . 'relations' . DS, |
|
504 | - EE_MODELS . 'strategies' . DS, |
|
505 | - ); |
|
506 | - // retrieve instantiated class |
|
507 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Determines if $model_name is the name of an actual EE model. |
|
514 | - * |
|
515 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
516 | - * @return boolean |
|
517 | - */ |
|
518 | - public function is_model_name($model_name) |
|
519 | - { |
|
520 | - return isset($this->models[$model_name]) ? true : false; |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * generic class loader |
|
527 | - * |
|
528 | - * @param string $path_to_file - directory path to file location, not including filename |
|
529 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
530 | - * @param string $type - file type - core? class? helper? model? |
|
531 | - * @param mixed $arguments |
|
532 | - * @param bool $load_only |
|
533 | - * @return mixed |
|
534 | - */ |
|
535 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
536 | - { |
|
537 | - // retrieve instantiated class |
|
538 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * load_addon |
|
545 | - * |
|
546 | - * @param string $path_to_file - directory path to file location, not including filename |
|
547 | - * @param string $class_name - full class name ie: My_Class |
|
548 | - * @param string $type - file type - core? class? helper? model? |
|
549 | - * @param mixed $arguments |
|
550 | - * @param bool $load_only |
|
551 | - * @return EE_Addon |
|
552 | - */ |
|
553 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
554 | - { |
|
555 | - // retrieve instantiated class |
|
556 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * instantiates, caches, and automatically resolves dependencies |
|
563 | - * for classes that use a Fully Qualified Class Name. |
|
564 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
565 | - * then you need to use one of the existing load_*() methods |
|
566 | - * which can resolve the classname and filepath from the passed arguments |
|
567 | - * |
|
568 | - * @param bool|string $class_name Fully Qualified Class Name |
|
569 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
570 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
571 | - * @param bool $from_db some classes are instantiated from the db |
|
572 | - * and thus call a different method to instantiate |
|
573 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
574 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
575 | - * @return mixed null = failure to load or instantiate class object. |
|
576 | - * object = class loaded and instantiated successfully. |
|
577 | - * bool = fail or success when $load_only is true |
|
578 | - * @throws EE_Error |
|
579 | - */ |
|
580 | - public function create( |
|
581 | - $class_name = false, |
|
582 | - $arguments = array(), |
|
583 | - $cache = false, |
|
584 | - $from_db = false, |
|
585 | - $load_only = false, |
|
586 | - $addon = false |
|
587 | - ) { |
|
588 | - $class_name = ltrim($class_name, '\\'); |
|
589 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | - $class_exists = $this->loadOrVerifyClassExists($class_name); |
|
591 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
592 | - // or it could return null if the class just could not be found anywhere |
|
593 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
594 | - // either way, return the results |
|
595 | - return $class_name; |
|
596 | - } |
|
597 | - $class_name = $class_exists; |
|
598 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | - if ($load_only) { |
|
600 | - return true; |
|
601 | - } |
|
602 | - $addon = $addon ? 'addon' : ''; |
|
603 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | - // return object if it's already cached |
|
608 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | - if ($cached_class !== null) { |
|
610 | - return $cached_class; |
|
611 | - } |
|
612 | - } |
|
613 | - // instantiate the requested object |
|
614 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | - // if caching is turned on OR this class is cached in a class property |
|
616 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
617 | - // save it for later... kinda like gum { : $ |
|
618 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | - } |
|
620 | - $this->_cache_on = true; |
|
621 | - return $class_obj; |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
628 | - * |
|
629 | - * @param string $class_name |
|
630 | - * @param int $attempt |
|
631 | - * @return mixed |
|
632 | - */ |
|
633 | - private function loadOrVerifyClassExists($class_name, $attempt = 1) { |
|
634 | - if (is_object($class_name) || class_exists($class_name)) { |
|
635 | - return $class_name; |
|
636 | - } |
|
637 | - switch ($attempt) { |
|
638 | - case 1: |
|
639 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
640 | - $class_name = strpos($class_name, '\\') !== false |
|
641 | - ? '\\' . ltrim($class_name, '\\') |
|
642 | - : $class_name; |
|
643 | - break; |
|
644 | - case 2: |
|
645 | - // |
|
646 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
647 | - if ($loader && method_exists($this, $loader)) { |
|
648 | - return $this->{$loader}($class_name); |
|
649 | - } |
|
650 | - break; |
|
651 | - case 3: |
|
652 | - default; |
|
653 | - return null; |
|
654 | - } |
|
655 | - $attempt++; |
|
656 | - return $this->loadOrVerifyClassExists($class_name, $attempt); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * instantiates, caches, and injects dependencies for classes |
|
663 | - * |
|
664 | - * @param array $file_paths an array of paths to folders to look in |
|
665 | - * @param string $class_prefix EE or EEM or... ??? |
|
666 | - * @param bool|string $class_name $class name |
|
667 | - * @param string $type file type - core? class? helper? model? |
|
668 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
669 | - * @param bool $from_db some classes are instantiated from the db |
|
670 | - * and thus call a different method to instantiate |
|
671 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
672 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
673 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
674 | - * object = class loaded and instantiated successfully. |
|
675 | - * bool = fail or success when $load_only is true |
|
676 | - * @throws EE_Error |
|
677 | - */ |
|
678 | - protected function _load( |
|
679 | - $file_paths = array(), |
|
680 | - $class_prefix = 'EE_', |
|
681 | - $class_name = false, |
|
682 | - $type = 'class', |
|
683 | - $arguments = array(), |
|
684 | - $from_db = false, |
|
685 | - $cache = true, |
|
686 | - $load_only = false |
|
687 | - ) { |
|
688 | - $class_name = ltrim($class_name, '\\'); |
|
689 | - // strip php file extension |
|
690 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
691 | - // does the class have a prefix ? |
|
692 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
693 | - // make sure $class_prefix is uppercase |
|
694 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
695 | - // add class prefix ONCE!!! |
|
696 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
697 | - } |
|
698 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
699 | - $class_exists = class_exists($class_name); |
|
700 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
701 | - if ($load_only && $class_exists) { |
|
702 | - return true; |
|
703 | - } |
|
704 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
705 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
706 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
707 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
708 | - // return object if it's already cached |
|
709 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
710 | - if ($cached_class !== null) { |
|
711 | - return $cached_class; |
|
712 | - } |
|
713 | - } |
|
714 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
715 | - if ( ! $class_exists) { |
|
716 | - // get full path to file |
|
717 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
718 | - // load the file |
|
719 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
720 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
721 | - if ( ! $loaded || $load_only) { |
|
722 | - // return boolean if only loading, or null if an object was expected |
|
723 | - return $load_only ? $loaded : null; |
|
724 | - } |
|
725 | - } |
|
726 | - // instantiate the requested object |
|
727 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
728 | - if ($this->_cache_on && $cache) { |
|
729 | - // save it for later... kinda like gum { : $ |
|
730 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
731 | - } |
|
732 | - $this->_cache_on = true; |
|
733 | - return $class_obj; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * _get_cached_class |
|
741 | - * attempts to find a cached version of the requested class |
|
742 | - * by looking in the following places: |
|
743 | - * $this->{$class_abbreviation} ie: $this->CART |
|
744 | - * $this->{$class_name} ie: $this->Some_Class |
|
745 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
746 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
747 | - * |
|
748 | - * @access protected |
|
749 | - * @param string $class_name |
|
750 | - * @param string $class_prefix |
|
751 | - * @return mixed |
|
752 | - */ |
|
753 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
754 | - { |
|
755 | - // have to specify something, but not anything that will conflict |
|
756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
757 | - ? $this->_class_abbreviations[ $class_name ] |
|
758 | - : 'FANCY_BATMAN_PANTS'; |
|
759 | - $class_name = str_replace('\\', '_', $class_name); |
|
760 | - // check if class has already been loaded, and return it if it has been |
|
761 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
762 | - return $this->{$class_abbreviation}; |
|
763 | - } |
|
764 | - if (isset ($this->{$class_name})) { |
|
765 | - return $this->{$class_name}; |
|
766 | - } |
|
767 | - if (isset ($this->LIB->{$class_name})) { |
|
768 | - return $this->LIB->{$class_name}; |
|
769 | - } |
|
770 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
771 | - return $this->addons->{$class_name}; |
|
772 | - } |
|
773 | - return null; |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * removes a cached version of the requested class |
|
780 | - * |
|
781 | - * @param string $class_name |
|
782 | - * @param boolean $addon |
|
783 | - * @return boolean |
|
784 | - */ |
|
785 | - public function clear_cached_class($class_name, $addon = false) |
|
786 | - { |
|
787 | - // have to specify something, but not anything that will conflict |
|
788 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
789 | - ? $this->_class_abbreviations[ $class_name ] |
|
790 | - : 'FANCY_BATMAN_PANTS'; |
|
791 | - $class_name = str_replace('\\', '_', $class_name); |
|
792 | - // check if class has already been loaded, and return it if it has been |
|
793 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
794 | - $this->{$class_abbreviation} = null; |
|
795 | - return true; |
|
796 | - } |
|
797 | - if (isset($this->{$class_name})) { |
|
798 | - $this->{$class_name} = null; |
|
799 | - return true; |
|
800 | - } |
|
801 | - if (isset($this->LIB->{$class_name})) { |
|
802 | - unset($this->LIB->{$class_name}); |
|
803 | - return true; |
|
804 | - } |
|
805 | - if ($addon && isset($this->addons->{$class_name})) { |
|
806 | - unset($this->addons->{$class_name}); |
|
807 | - return true; |
|
808 | - } |
|
809 | - return false; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - /** |
|
814 | - * _resolve_path |
|
815 | - * attempts to find a full valid filepath for the requested class. |
|
816 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
817 | - * then returns that path if the target file has been found and is readable |
|
818 | - * |
|
819 | - * @access protected |
|
820 | - * @param string $class_name |
|
821 | - * @param string $type |
|
822 | - * @param array $file_paths |
|
823 | - * @return string | bool |
|
824 | - */ |
|
825 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
826 | - { |
|
827 | - // make sure $file_paths is an array |
|
828 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
829 | - // cycle thru paths |
|
830 | - foreach ($file_paths as $key => $file_path) { |
|
831 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
832 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
833 | - // prep file type |
|
834 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
835 | - // build full file path |
|
836 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
837 | - //does the file exist and can be read ? |
|
838 | - if (is_readable($file_paths[$key])) { |
|
839 | - return $file_paths[$key]; |
|
840 | - } |
|
841 | - } |
|
842 | - return false; |
|
843 | - } |
|
844 | - |
|
845 | - |
|
846 | - |
|
847 | - /** |
|
848 | - * _require_file |
|
849 | - * basically just performs a require_once() |
|
850 | - * but with some error handling |
|
851 | - * |
|
852 | - * @access protected |
|
853 | - * @param string $path |
|
854 | - * @param string $class_name |
|
855 | - * @param string $type |
|
856 | - * @param array $file_paths |
|
857 | - * @return boolean |
|
858 | - * @throws \EE_Error |
|
859 | - */ |
|
860 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
861 | - { |
|
862 | - // don't give up! you gotta... |
|
863 | - try { |
|
864 | - //does the file exist and can it be read ? |
|
865 | - if ( ! $path) { |
|
866 | - // so sorry, can't find the file |
|
867 | - throw new EE_Error ( |
|
868 | - sprintf( |
|
869 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
870 | - trim($type, '.'), |
|
871 | - $class_name, |
|
872 | - '<br />' . implode(',<br />', $file_paths) |
|
873 | - ) |
|
874 | - ); |
|
875 | - } |
|
876 | - // get the file |
|
877 | - require_once($path); |
|
878 | - // if the class isn't already declared somewhere |
|
879 | - if (class_exists($class_name, false) === false) { |
|
880 | - // so sorry, not a class |
|
881 | - throw new EE_Error( |
|
882 | - sprintf( |
|
883 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
884 | - $type, |
|
885 | - $path, |
|
886 | - $class_name |
|
887 | - ) |
|
888 | - ); |
|
889 | - } |
|
890 | - } catch (EE_Error $e) { |
|
891 | - $e->get_error(); |
|
892 | - return false; |
|
893 | - } |
|
894 | - return true; |
|
895 | - } |
|
896 | - |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * _create_object |
|
901 | - * Attempts to instantiate the requested class via any of the |
|
902 | - * commonly used instantiation methods employed throughout EE. |
|
903 | - * The priority for instantiation is as follows: |
|
904 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
905 | - * - model objects via their 'new_instance_from_db' method |
|
906 | - * - model objects via their 'new_instance' method |
|
907 | - * - "singleton" classes" via their 'instance' method |
|
908 | - * - standard instantiable classes via their __constructor |
|
909 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
910 | - * then the constructor for the requested class will be examined to determine |
|
911 | - * if any dependencies exist, and if they can be injected. |
|
912 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
913 | - * |
|
914 | - * @access protected |
|
915 | - * @param string $class_name |
|
916 | - * @param array $arguments |
|
917 | - * @param string $type |
|
918 | - * @param bool $from_db |
|
919 | - * @return null | object |
|
920 | - * @throws \EE_Error |
|
921 | - */ |
|
922 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
923 | - { |
|
924 | - $class_obj = null; |
|
925 | - $instantiation_mode = '0) none'; |
|
926 | - // don't give up! you gotta... |
|
927 | - try { |
|
928 | - // create reflection |
|
929 | - $reflector = $this->get_ReflectionClass($class_name); |
|
930 | - // make sure arguments are an array |
|
931 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
932 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
933 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
934 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
935 | - ? $arguments |
|
936 | - : array($arguments); |
|
937 | - // attempt to inject dependencies ? |
|
938 | - if ($this->_dependency_map->has($class_name)) { |
|
939 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
940 | - } |
|
941 | - // instantiate the class if possible |
|
942 | - if ($reflector->isAbstract()) { |
|
943 | - // nothing to instantiate, loading file was enough |
|
944 | - // does not throw an exception so $instantiation_mode is unused |
|
945 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
946 | - $class_obj = true; |
|
947 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
948 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
949 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
950 | - $class_obj = $reflector->newInstance(); |
|
951 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
952 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
953 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
954 | - } else if (method_exists($class_name, 'new_instance')) { |
|
955 | - $instantiation_mode = "4) new_instance()"; |
|
956 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
957 | - } else if (method_exists($class_name, 'instance')) { |
|
958 | - $instantiation_mode = "5) instance()"; |
|
959 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
960 | - } else if ($reflector->isInstantiable()) { |
|
961 | - $instantiation_mode = "6) constructor"; |
|
962 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
963 | - } else { |
|
964 | - // heh ? something's not right ! |
|
965 | - throw new EE_Error( |
|
966 | - sprintf( |
|
967 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
968 | - $type, |
|
969 | - $class_name |
|
970 | - ) |
|
971 | - ); |
|
972 | - } |
|
973 | - } catch (Exception $e) { |
|
974 | - if ( ! $e instanceof EE_Error) { |
|
975 | - $e = new EE_Error( |
|
976 | - sprintf( |
|
977 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
978 | - $class_name, |
|
979 | - '<br />', |
|
980 | - $e->getMessage(), |
|
981 | - $instantiation_mode |
|
982 | - ) |
|
983 | - ); |
|
984 | - } |
|
985 | - $e->get_error(); |
|
986 | - } |
|
987 | - return $class_obj; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - |
|
992 | - /** |
|
993 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
994 | - * @param array $array |
|
995 | - * @return bool |
|
996 | - */ |
|
997 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
998 | - { |
|
999 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
1000 | - } |
|
1001 | - |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * getReflectionClass |
|
1006 | - * checks if a ReflectionClass object has already been generated for a class |
|
1007 | - * and returns that instead of creating a new one |
|
1008 | - * |
|
1009 | - * @access public |
|
1010 | - * @param string $class_name |
|
1011 | - * @return ReflectionClass |
|
1012 | - */ |
|
1013 | - public function get_ReflectionClass($class_name) |
|
1014 | - { |
|
1015 | - if ( |
|
1016 | - ! isset($this->_reflectors[$class_name]) |
|
1017 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1018 | - ) { |
|
1019 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1020 | - } |
|
1021 | - return $this->_reflectors[$class_name]; |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * _resolve_dependencies |
|
1028 | - * examines the constructor for the requested class to determine |
|
1029 | - * if any dependencies exist, and if they can be injected. |
|
1030 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1031 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1032 | - * For example: |
|
1033 | - * if attempting to load a class "Foo" with the following constructor: |
|
1034 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1035 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1036 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1037 | - * and the correct classes can be loaded |
|
1038 | - * |
|
1039 | - * @access protected |
|
1040 | - * @param ReflectionClass $reflector |
|
1041 | - * @param string $class_name |
|
1042 | - * @param array $arguments |
|
1043 | - * @return array |
|
1044 | - * @throws \ReflectionException |
|
1045 | - */ |
|
1046 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1047 | - { |
|
1048 | - // let's examine the constructor |
|
1049 | - $constructor = $reflector->getConstructor(); |
|
1050 | - // whu? huh? nothing? |
|
1051 | - if ( ! $constructor) { |
|
1052 | - return $arguments; |
|
1053 | - } |
|
1054 | - // get constructor parameters |
|
1055 | - $params = $constructor->getParameters(); |
|
1056 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1057 | - $argument_keys = array_keys($arguments); |
|
1058 | - // now loop thru all of the constructors expected parameters |
|
1059 | - foreach ($params as $index => $param) { |
|
1060 | - // is this a dependency for a specific class ? |
|
1061 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1062 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1063 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1064 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1065 | - : $param_class; |
|
1066 | - if ( |
|
1067 | - // param is not even a class |
|
1068 | - empty($param_class) |
|
1069 | - // and something already exists in the incoming arguments for this param |
|
1070 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1071 | - ) { |
|
1072 | - // so let's skip this argument and move on to the next |
|
1073 | - continue; |
|
1074 | - } |
|
1075 | - if ( |
|
1076 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1077 | - ! empty($param_class) |
|
1078 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1079 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1080 | - ) { |
|
1081 | - // skip this argument and move on to the next |
|
1082 | - continue; |
|
1083 | - } |
|
1084 | - if ( |
|
1085 | - // parameter is type hinted as a class, and should be injected |
|
1086 | - ! empty($param_class) |
|
1087 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1088 | - ) { |
|
1089 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1090 | - } else { |
|
1091 | - try { |
|
1092 | - $arguments[$index] = $param->getDefaultValue(); |
|
1093 | - } catch (ReflectionException $e) { |
|
1094 | - throw new ReflectionException( |
|
1095 | - sprintf( |
|
1096 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1097 | - $e->getMessage(), |
|
1098 | - $param->getName() |
|
1099 | - ) |
|
1100 | - ); |
|
1101 | - } |
|
1102 | - } |
|
1103 | - } |
|
1104 | - return $arguments; |
|
1105 | - } |
|
1106 | - |
|
1107 | - |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * @access protected |
|
1111 | - * @param string $class_name |
|
1112 | - * @param string $param_class |
|
1113 | - * @param array $arguments |
|
1114 | - * @param mixed $index |
|
1115 | - * @return array |
|
1116 | - */ |
|
1117 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1118 | - { |
|
1119 | - $dependency = null; |
|
1120 | - // should dependency be loaded from cache ? |
|
1121 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1122 | - !== EE_Dependency_Map::load_new_object |
|
1123 | - ? true |
|
1124 | - : false; |
|
1125 | - // we might have a dependency... |
|
1126 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1127 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1128 | - // and grab it if it exists |
|
1129 | - if ($cached_class instanceof $param_class) { |
|
1130 | - $dependency = $cached_class; |
|
1131 | - } else if ($param_class !== $class_name) { |
|
1132 | - // obtain the loader method from the dependency map |
|
1133 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1134 | - // is loader a custom closure ? |
|
1135 | - if ($loader instanceof Closure) { |
|
1136 | - $dependency = $loader(); |
|
1137 | - } else { |
|
1138 | - // set the cache on property for the recursive loading call |
|
1139 | - $this->_cache_on = $cache_on; |
|
1140 | - // if not, then let's try and load it via the registry |
|
1141 | - if ($loader && method_exists($this, $loader)) { |
|
1142 | - $dependency = $this->{$loader}($param_class); |
|
1143 | - } else { |
|
1144 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1145 | - } |
|
1146 | - } |
|
1147 | - } |
|
1148 | - // did we successfully find the correct dependency ? |
|
1149 | - if ($dependency instanceof $param_class) { |
|
1150 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1151 | - if (isset($argument_keys[$index])) { |
|
1152 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1153 | - } else { |
|
1154 | - $arguments[$index] = $dependency; |
|
1155 | - } |
|
1156 | - } |
|
1157 | - return $arguments; |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * _set_cached_class |
|
1164 | - * attempts to cache the instantiated class locally |
|
1165 | - * in one of the following places, in the following order: |
|
1166 | - * $this->{class_abbreviation} ie: $this->CART |
|
1167 | - * $this->{$class_name} ie: $this->Some_Class |
|
1168 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1169 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1170 | - * |
|
1171 | - * @access protected |
|
1172 | - * @param object $class_obj |
|
1173 | - * @param string $class_name |
|
1174 | - * @param string $class_prefix |
|
1175 | - * @param bool $from_db |
|
1176 | - * @return void |
|
1177 | - */ |
|
1178 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1179 | - { |
|
1180 | - if (empty($class_obj)) { |
|
1181 | - return; |
|
1182 | - } |
|
1183 | - // return newly instantiated class |
|
1184 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1185 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1186 | - $this->{$class_abbreviation} = $class_obj; |
|
1187 | - return; |
|
1188 | - } |
|
1189 | - $class_name = str_replace('\\', '_', $class_name); |
|
1190 | - if (property_exists($this, $class_name)) { |
|
1191 | - $this->{$class_name} = $class_obj; |
|
1192 | - return; |
|
1193 | - } |
|
1194 | - if ($class_prefix === 'addon') { |
|
1195 | - $this->addons->{$class_name} = $class_obj; |
|
1196 | - return; |
|
1197 | - } |
|
1198 | - if ( ! $from_db) { |
|
1199 | - $this->LIB->{$class_name} = $class_obj; |
|
1200 | - } |
|
1201 | - } |
|
1202 | - |
|
1203 | - |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1207 | - * |
|
1208 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1209 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1210 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1211 | - * @param array $arguments |
|
1212 | - * @return object |
|
1213 | - */ |
|
1214 | - public static function factory($classname, $arguments = array()) |
|
1215 | - { |
|
1216 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1217 | - if ($loader instanceof Closure) { |
|
1218 | - return $loader($arguments); |
|
1219 | - } |
|
1220 | - if (method_exists(EE_Registry::instance(), $loader)) { |
|
1221 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1222 | - } |
|
1223 | - return null; |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1230 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1231 | - * |
|
1232 | - * @param string $name |
|
1233 | - * @return EE_Addon |
|
1234 | - */ |
|
1235 | - public function get_addon_by_name($name) |
|
1236 | - { |
|
1237 | - foreach ($this->addons as $addon) { |
|
1238 | - if ($addon->name() == $name) { |
|
1239 | - return $addon; |
|
1240 | - } |
|
1241 | - } |
|
1242 | - return null; |
|
1243 | - } |
|
1244 | - |
|
1245 | - |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1249 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1250 | - * |
|
1251 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1252 | - */ |
|
1253 | - public function get_addons_by_name() |
|
1254 | - { |
|
1255 | - $addons = array(); |
|
1256 | - foreach ($this->addons as $addon) { |
|
1257 | - $addons[$addon->name()] = $addon; |
|
1258 | - } |
|
1259 | - return $addons; |
|
1260 | - } |
|
1261 | - |
|
1262 | - |
|
1263 | - |
|
1264 | - /** |
|
1265 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1266 | - * a stale copy of it around |
|
1267 | - * |
|
1268 | - * @param string $model_name |
|
1269 | - * @return \EEM_Base |
|
1270 | - * @throws \EE_Error |
|
1271 | - */ |
|
1272 | - public function reset_model($model_name) |
|
1273 | - { |
|
1274 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1275 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1276 | - return null; |
|
1277 | - } |
|
1278 | - //get that model reset it and make sure we nuke the old reference to it |
|
1279 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1280 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1281 | - } else { |
|
1282 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1283 | - } |
|
1284 | - return $this->LIB->{$model_class_name}; |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * Resets the registry. |
|
1291 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1292 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1293 | - * - $_dependency_map |
|
1294 | - * - $_class_abbreviations |
|
1295 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1296 | - * - $REQ: Still on the same request so no need to change. |
|
1297 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1298 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1299 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1300 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1301 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1302 | - * switch or on the restore. |
|
1303 | - * - $modules |
|
1304 | - * - $shortcodes |
|
1305 | - * - $widgets |
|
1306 | - * |
|
1307 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1308 | - * the Registry to its state at the beginning of the request |
|
1309 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1310 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1311 | - * currently reinstantiate the singletons at the moment) |
|
1312 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1313 | - * code instead can just change the model context to a different blog id if necessary |
|
1314 | - * @return EE_Registry |
|
1315 | - */ |
|
1316 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1317 | - { |
|
1318 | - $instance = self::instance(); |
|
1319 | - EEH_Activation::reset(); |
|
1320 | - //properties that get reset |
|
1321 | - $instance->_cache_on = true; |
|
1322 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1323 | - $instance->CART = null; |
|
1324 | - $instance->MRM = null; |
|
1325 | - $instance->AssetsRegistry = null; |
|
1326 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1327 | - //messages reset |
|
1328 | - EED_Messages::reset(); |
|
1329 | - if ($reset_models) { |
|
1330 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1331 | - $instance->reset_model($model_name); |
|
1332 | - } |
|
1333 | - } |
|
1334 | - $instance->LIB = new stdClass(); |
|
1335 | - return $instance; |
|
1336 | - } |
|
1337 | - |
|
1338 | - |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * @override magic methods |
|
1342 | - * @return void |
|
1343 | - */ |
|
1344 | - public final function __destruct() |
|
1345 | - { |
|
1346 | - } |
|
1347 | - |
|
1348 | - |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * @param $a |
|
1352 | - * @param $b |
|
1353 | - */ |
|
1354 | - public final function __call($a, $b) |
|
1355 | - { |
|
1356 | - } |
|
1357 | - |
|
1358 | - |
|
1359 | - |
|
1360 | - /** |
|
1361 | - * @param $a |
|
1362 | - */ |
|
1363 | - public final function __get($a) |
|
1364 | - { |
|
1365 | - } |
|
1366 | - |
|
1367 | - |
|
1368 | - |
|
1369 | - /** |
|
1370 | - * @param $a |
|
1371 | - * @param $b |
|
1372 | - */ |
|
1373 | - public final function __set($a, $b) |
|
1374 | - { |
|
1375 | - } |
|
1376 | - |
|
1377 | - |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * @param $a |
|
1381 | - */ |
|
1382 | - public final function __isset($a) |
|
1383 | - { |
|
1384 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + */ |
|
224 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
225 | + { |
|
226 | + $this->_dependency_map = $dependency_map; |
|
227 | + $this->LIB = new stdClass(); |
|
228 | + $this->addons = new stdClass(); |
|
229 | + $this->modules = new stdClass(); |
|
230 | + $this->shortcodes = new stdClass(); |
|
231 | + $this->widgets = new stdClass(); |
|
232 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * initialize |
|
239 | + */ |
|
240 | + public function initialize() |
|
241 | + { |
|
242 | + $this->_class_abbreviations = apply_filters( |
|
243 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
244 | + array( |
|
245 | + 'EE_Config' => 'CFG', |
|
246 | + 'EE_Session' => 'SSN', |
|
247 | + 'EE_Capabilities' => 'CAP', |
|
248 | + 'EE_Cart' => 'CART', |
|
249 | + 'EE_Network_Config' => 'NET_CFG', |
|
250 | + 'EE_Request_Handler' => 'REQ', |
|
251 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
252 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
253 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
254 | + ) |
|
255 | + ); |
|
256 | + $this->load_core('Base', array(), true); |
|
257 | + // add our request and response objects to the cache |
|
258 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
259 | + $this->_set_cached_class( |
|
260 | + $request_loader(), |
|
261 | + 'EE_Request' |
|
262 | + ); |
|
263 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
264 | + $this->_set_cached_class( |
|
265 | + $response_loader(), |
|
266 | + 'EE_Response' |
|
267 | + ); |
|
268 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * init |
|
275 | + * |
|
276 | + * @access public |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + public function init() |
|
280 | + { |
|
281 | + // Get current page protocol |
|
282 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
283 | + // Output admin-ajax.php URL with same protocol as current page |
|
284 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
285 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * localize_i18n_js_strings |
|
292 | + * |
|
293 | + * @return string |
|
294 | + */ |
|
295 | + public static function localize_i18n_js_strings() |
|
296 | + { |
|
297 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
298 | + foreach ($i18n_js_strings as $key => $value) { |
|
299 | + if (is_scalar($value)) { |
|
300 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
301 | + } |
|
302 | + } |
|
303 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param mixed string | EED_Module $module |
|
310 | + */ |
|
311 | + public function add_module($module) |
|
312 | + { |
|
313 | + if ($module instanceof EED_Module) { |
|
314 | + $module_class = get_class($module); |
|
315 | + $this->modules->{$module_class} = $module; |
|
316 | + } else { |
|
317 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
318 | + $this->load_core('Module_Request_Router'); |
|
319 | + } |
|
320 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string $module_name |
|
328 | + * @return mixed EED_Module | NULL |
|
329 | + */ |
|
330 | + public function get_module($module_name = '') |
|
331 | + { |
|
332 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * loads core classes - must be singletons |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @param string $class_name - simple class name ie: session |
|
342 | + * @param mixed $arguments |
|
343 | + * @param bool $load_only |
|
344 | + * @return mixed |
|
345 | + */ |
|
346 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
347 | + { |
|
348 | + $core_paths = apply_filters( |
|
349 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
350 | + array( |
|
351 | + EE_CORE, |
|
352 | + EE_ADMIN, |
|
353 | + EE_CPTS, |
|
354 | + EE_CORE . 'data_migration_scripts' . DS, |
|
355 | + EE_CORE . 'request_stack' . DS, |
|
356 | + EE_CORE . 'middleware' . DS, |
|
357 | + ) |
|
358 | + ); |
|
359 | + // retrieve instantiated class |
|
360 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * loads service classes |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $class_name - simple class name ie: session |
|
370 | + * @param mixed $arguments |
|
371 | + * @param bool $load_only |
|
372 | + * @return mixed |
|
373 | + */ |
|
374 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
375 | + { |
|
376 | + $service_paths = apply_filters( |
|
377 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
378 | + array( |
|
379 | + EE_CORE . 'services' . DS, |
|
380 | + ) |
|
381 | + ); |
|
382 | + // retrieve instantiated class |
|
383 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * loads data_migration_scripts |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
393 | + * @param mixed $arguments |
|
394 | + * @return EE_Data_Migration_Script_Base|mixed |
|
395 | + */ |
|
396 | + public function load_dms($class_name, $arguments = array()) |
|
397 | + { |
|
398 | + // retrieve instantiated class |
|
399 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * loads object creating classes - must be singletons |
|
406 | + * |
|
407 | + * @param string $class_name - simple class name ie: attendee |
|
408 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
409 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
410 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
411 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
412 | + * @return EE_Base_Class | bool |
|
413 | + */ |
|
414 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
415 | + { |
|
416 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
417 | + EE_CORE, |
|
418 | + EE_CLASSES, |
|
419 | + EE_BUSINESS, |
|
420 | + )); |
|
421 | + // retrieve instantiated class |
|
422 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * loads helper classes - must be singletons |
|
429 | + * |
|
430 | + * @param string $class_name - simple class name ie: price |
|
431 | + * @param mixed $arguments |
|
432 | + * @param bool $load_only |
|
433 | + * @return EEH_Base | bool |
|
434 | + */ |
|
435 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
436 | + { |
|
437 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
438 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
439 | + // retrieve instantiated class |
|
440 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * loads core classes - must be singletons |
|
447 | + * |
|
448 | + * @access public |
|
449 | + * @param string $class_name - simple class name ie: session |
|
450 | + * @param mixed $arguments |
|
451 | + * @param bool $load_only |
|
452 | + * @param bool $cache whether to cache the object or not. |
|
453 | + * @return mixed |
|
454 | + */ |
|
455 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
456 | + { |
|
457 | + $paths = array( |
|
458 | + EE_LIBRARIES, |
|
459 | + EE_LIBRARIES . 'messages' . DS, |
|
460 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
461 | + EE_LIBRARIES . 'qtips' . DS, |
|
462 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
463 | + ); |
|
464 | + // retrieve instantiated class |
|
465 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * loads model classes - must be singletons |
|
472 | + * |
|
473 | + * @param string $class_name - simple class name ie: price |
|
474 | + * @param mixed $arguments |
|
475 | + * @param bool $load_only |
|
476 | + * @return EEM_Base | bool |
|
477 | + */ |
|
478 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
479 | + { |
|
480 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
481 | + EE_MODELS, |
|
482 | + EE_CORE, |
|
483 | + )); |
|
484 | + // retrieve instantiated class |
|
485 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * loads model classes - must be singletons |
|
492 | + * |
|
493 | + * @param string $class_name - simple class name ie: price |
|
494 | + * @param mixed $arguments |
|
495 | + * @param bool $load_only |
|
496 | + * @return mixed | bool |
|
497 | + */ |
|
498 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
499 | + { |
|
500 | + $paths = array( |
|
501 | + EE_MODELS . 'fields' . DS, |
|
502 | + EE_MODELS . 'helpers' . DS, |
|
503 | + EE_MODELS . 'relations' . DS, |
|
504 | + EE_MODELS . 'strategies' . DS, |
|
505 | + ); |
|
506 | + // retrieve instantiated class |
|
507 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Determines if $model_name is the name of an actual EE model. |
|
514 | + * |
|
515 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
516 | + * @return boolean |
|
517 | + */ |
|
518 | + public function is_model_name($model_name) |
|
519 | + { |
|
520 | + return isset($this->models[$model_name]) ? true : false; |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * generic class loader |
|
527 | + * |
|
528 | + * @param string $path_to_file - directory path to file location, not including filename |
|
529 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
530 | + * @param string $type - file type - core? class? helper? model? |
|
531 | + * @param mixed $arguments |
|
532 | + * @param bool $load_only |
|
533 | + * @return mixed |
|
534 | + */ |
|
535 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
536 | + { |
|
537 | + // retrieve instantiated class |
|
538 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * load_addon |
|
545 | + * |
|
546 | + * @param string $path_to_file - directory path to file location, not including filename |
|
547 | + * @param string $class_name - full class name ie: My_Class |
|
548 | + * @param string $type - file type - core? class? helper? model? |
|
549 | + * @param mixed $arguments |
|
550 | + * @param bool $load_only |
|
551 | + * @return EE_Addon |
|
552 | + */ |
|
553 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
554 | + { |
|
555 | + // retrieve instantiated class |
|
556 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * instantiates, caches, and automatically resolves dependencies |
|
563 | + * for classes that use a Fully Qualified Class Name. |
|
564 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
565 | + * then you need to use one of the existing load_*() methods |
|
566 | + * which can resolve the classname and filepath from the passed arguments |
|
567 | + * |
|
568 | + * @param bool|string $class_name Fully Qualified Class Name |
|
569 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
570 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
571 | + * @param bool $from_db some classes are instantiated from the db |
|
572 | + * and thus call a different method to instantiate |
|
573 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
574 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
575 | + * @return mixed null = failure to load or instantiate class object. |
|
576 | + * object = class loaded and instantiated successfully. |
|
577 | + * bool = fail or success when $load_only is true |
|
578 | + * @throws EE_Error |
|
579 | + */ |
|
580 | + public function create( |
|
581 | + $class_name = false, |
|
582 | + $arguments = array(), |
|
583 | + $cache = false, |
|
584 | + $from_db = false, |
|
585 | + $load_only = false, |
|
586 | + $addon = false |
|
587 | + ) { |
|
588 | + $class_name = ltrim($class_name, '\\'); |
|
589 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
590 | + $class_exists = $this->loadOrVerifyClassExists($class_name); |
|
591 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
592 | + // or it could return null if the class just could not be found anywhere |
|
593 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
594 | + // either way, return the results |
|
595 | + return $class_name; |
|
596 | + } |
|
597 | + $class_name = $class_exists; |
|
598 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
599 | + if ($load_only) { |
|
600 | + return true; |
|
601 | + } |
|
602 | + $addon = $addon ? 'addon' : ''; |
|
603 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
604 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
605 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
606 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
607 | + // return object if it's already cached |
|
608 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
609 | + if ($cached_class !== null) { |
|
610 | + return $cached_class; |
|
611 | + } |
|
612 | + } |
|
613 | + // instantiate the requested object |
|
614 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
615 | + // if caching is turned on OR this class is cached in a class property |
|
616 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
617 | + // save it for later... kinda like gum { : $ |
|
618 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
619 | + } |
|
620 | + $this->_cache_on = true; |
|
621 | + return $class_obj; |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
628 | + * |
|
629 | + * @param string $class_name |
|
630 | + * @param int $attempt |
|
631 | + * @return mixed |
|
632 | + */ |
|
633 | + private function loadOrVerifyClassExists($class_name, $attempt = 1) { |
|
634 | + if (is_object($class_name) || class_exists($class_name)) { |
|
635 | + return $class_name; |
|
636 | + } |
|
637 | + switch ($attempt) { |
|
638 | + case 1: |
|
639 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
640 | + $class_name = strpos($class_name, '\\') !== false |
|
641 | + ? '\\' . ltrim($class_name, '\\') |
|
642 | + : $class_name; |
|
643 | + break; |
|
644 | + case 2: |
|
645 | + // |
|
646 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
647 | + if ($loader && method_exists($this, $loader)) { |
|
648 | + return $this->{$loader}($class_name); |
|
649 | + } |
|
650 | + break; |
|
651 | + case 3: |
|
652 | + default; |
|
653 | + return null; |
|
654 | + } |
|
655 | + $attempt++; |
|
656 | + return $this->loadOrVerifyClassExists($class_name, $attempt); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * instantiates, caches, and injects dependencies for classes |
|
663 | + * |
|
664 | + * @param array $file_paths an array of paths to folders to look in |
|
665 | + * @param string $class_prefix EE or EEM or... ??? |
|
666 | + * @param bool|string $class_name $class name |
|
667 | + * @param string $type file type - core? class? helper? model? |
|
668 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
669 | + * @param bool $from_db some classes are instantiated from the db |
|
670 | + * and thus call a different method to instantiate |
|
671 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
672 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
673 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
674 | + * object = class loaded and instantiated successfully. |
|
675 | + * bool = fail or success when $load_only is true |
|
676 | + * @throws EE_Error |
|
677 | + */ |
|
678 | + protected function _load( |
|
679 | + $file_paths = array(), |
|
680 | + $class_prefix = 'EE_', |
|
681 | + $class_name = false, |
|
682 | + $type = 'class', |
|
683 | + $arguments = array(), |
|
684 | + $from_db = false, |
|
685 | + $cache = true, |
|
686 | + $load_only = false |
|
687 | + ) { |
|
688 | + $class_name = ltrim($class_name, '\\'); |
|
689 | + // strip php file extension |
|
690 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
691 | + // does the class have a prefix ? |
|
692 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
693 | + // make sure $class_prefix is uppercase |
|
694 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
695 | + // add class prefix ONCE!!! |
|
696 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
697 | + } |
|
698 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
699 | + $class_exists = class_exists($class_name); |
|
700 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
701 | + if ($load_only && $class_exists) { |
|
702 | + return true; |
|
703 | + } |
|
704 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
705 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
706 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
707 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
708 | + // return object if it's already cached |
|
709 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
710 | + if ($cached_class !== null) { |
|
711 | + return $cached_class; |
|
712 | + } |
|
713 | + } |
|
714 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
715 | + if ( ! $class_exists) { |
|
716 | + // get full path to file |
|
717 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
718 | + // load the file |
|
719 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
720 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
721 | + if ( ! $loaded || $load_only) { |
|
722 | + // return boolean if only loading, or null if an object was expected |
|
723 | + return $load_only ? $loaded : null; |
|
724 | + } |
|
725 | + } |
|
726 | + // instantiate the requested object |
|
727 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
728 | + if ($this->_cache_on && $cache) { |
|
729 | + // save it for later... kinda like gum { : $ |
|
730 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
731 | + } |
|
732 | + $this->_cache_on = true; |
|
733 | + return $class_obj; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * _get_cached_class |
|
741 | + * attempts to find a cached version of the requested class |
|
742 | + * by looking in the following places: |
|
743 | + * $this->{$class_abbreviation} ie: $this->CART |
|
744 | + * $this->{$class_name} ie: $this->Some_Class |
|
745 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
746 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
747 | + * |
|
748 | + * @access protected |
|
749 | + * @param string $class_name |
|
750 | + * @param string $class_prefix |
|
751 | + * @return mixed |
|
752 | + */ |
|
753 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
754 | + { |
|
755 | + // have to specify something, but not anything that will conflict |
|
756 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
757 | + ? $this->_class_abbreviations[ $class_name ] |
|
758 | + : 'FANCY_BATMAN_PANTS'; |
|
759 | + $class_name = str_replace('\\', '_', $class_name); |
|
760 | + // check if class has already been loaded, and return it if it has been |
|
761 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
762 | + return $this->{$class_abbreviation}; |
|
763 | + } |
|
764 | + if (isset ($this->{$class_name})) { |
|
765 | + return $this->{$class_name}; |
|
766 | + } |
|
767 | + if (isset ($this->LIB->{$class_name})) { |
|
768 | + return $this->LIB->{$class_name}; |
|
769 | + } |
|
770 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
771 | + return $this->addons->{$class_name}; |
|
772 | + } |
|
773 | + return null; |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * removes a cached version of the requested class |
|
780 | + * |
|
781 | + * @param string $class_name |
|
782 | + * @param boolean $addon |
|
783 | + * @return boolean |
|
784 | + */ |
|
785 | + public function clear_cached_class($class_name, $addon = false) |
|
786 | + { |
|
787 | + // have to specify something, but not anything that will conflict |
|
788 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
789 | + ? $this->_class_abbreviations[ $class_name ] |
|
790 | + : 'FANCY_BATMAN_PANTS'; |
|
791 | + $class_name = str_replace('\\', '_', $class_name); |
|
792 | + // check if class has already been loaded, and return it if it has been |
|
793 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
794 | + $this->{$class_abbreviation} = null; |
|
795 | + return true; |
|
796 | + } |
|
797 | + if (isset($this->{$class_name})) { |
|
798 | + $this->{$class_name} = null; |
|
799 | + return true; |
|
800 | + } |
|
801 | + if (isset($this->LIB->{$class_name})) { |
|
802 | + unset($this->LIB->{$class_name}); |
|
803 | + return true; |
|
804 | + } |
|
805 | + if ($addon && isset($this->addons->{$class_name})) { |
|
806 | + unset($this->addons->{$class_name}); |
|
807 | + return true; |
|
808 | + } |
|
809 | + return false; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + /** |
|
814 | + * _resolve_path |
|
815 | + * attempts to find a full valid filepath for the requested class. |
|
816 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
817 | + * then returns that path if the target file has been found and is readable |
|
818 | + * |
|
819 | + * @access protected |
|
820 | + * @param string $class_name |
|
821 | + * @param string $type |
|
822 | + * @param array $file_paths |
|
823 | + * @return string | bool |
|
824 | + */ |
|
825 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
826 | + { |
|
827 | + // make sure $file_paths is an array |
|
828 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
829 | + // cycle thru paths |
|
830 | + foreach ($file_paths as $key => $file_path) { |
|
831 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
832 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
833 | + // prep file type |
|
834 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
835 | + // build full file path |
|
836 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
837 | + //does the file exist and can be read ? |
|
838 | + if (is_readable($file_paths[$key])) { |
|
839 | + return $file_paths[$key]; |
|
840 | + } |
|
841 | + } |
|
842 | + return false; |
|
843 | + } |
|
844 | + |
|
845 | + |
|
846 | + |
|
847 | + /** |
|
848 | + * _require_file |
|
849 | + * basically just performs a require_once() |
|
850 | + * but with some error handling |
|
851 | + * |
|
852 | + * @access protected |
|
853 | + * @param string $path |
|
854 | + * @param string $class_name |
|
855 | + * @param string $type |
|
856 | + * @param array $file_paths |
|
857 | + * @return boolean |
|
858 | + * @throws \EE_Error |
|
859 | + */ |
|
860 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
861 | + { |
|
862 | + // don't give up! you gotta... |
|
863 | + try { |
|
864 | + //does the file exist and can it be read ? |
|
865 | + if ( ! $path) { |
|
866 | + // so sorry, can't find the file |
|
867 | + throw new EE_Error ( |
|
868 | + sprintf( |
|
869 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
870 | + trim($type, '.'), |
|
871 | + $class_name, |
|
872 | + '<br />' . implode(',<br />', $file_paths) |
|
873 | + ) |
|
874 | + ); |
|
875 | + } |
|
876 | + // get the file |
|
877 | + require_once($path); |
|
878 | + // if the class isn't already declared somewhere |
|
879 | + if (class_exists($class_name, false) === false) { |
|
880 | + // so sorry, not a class |
|
881 | + throw new EE_Error( |
|
882 | + sprintf( |
|
883 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
884 | + $type, |
|
885 | + $path, |
|
886 | + $class_name |
|
887 | + ) |
|
888 | + ); |
|
889 | + } |
|
890 | + } catch (EE_Error $e) { |
|
891 | + $e->get_error(); |
|
892 | + return false; |
|
893 | + } |
|
894 | + return true; |
|
895 | + } |
|
896 | + |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * _create_object |
|
901 | + * Attempts to instantiate the requested class via any of the |
|
902 | + * commonly used instantiation methods employed throughout EE. |
|
903 | + * The priority for instantiation is as follows: |
|
904 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
905 | + * - model objects via their 'new_instance_from_db' method |
|
906 | + * - model objects via their 'new_instance' method |
|
907 | + * - "singleton" classes" via their 'instance' method |
|
908 | + * - standard instantiable classes via their __constructor |
|
909 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
910 | + * then the constructor for the requested class will be examined to determine |
|
911 | + * if any dependencies exist, and if they can be injected. |
|
912 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
913 | + * |
|
914 | + * @access protected |
|
915 | + * @param string $class_name |
|
916 | + * @param array $arguments |
|
917 | + * @param string $type |
|
918 | + * @param bool $from_db |
|
919 | + * @return null | object |
|
920 | + * @throws \EE_Error |
|
921 | + */ |
|
922 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
923 | + { |
|
924 | + $class_obj = null; |
|
925 | + $instantiation_mode = '0) none'; |
|
926 | + // don't give up! you gotta... |
|
927 | + try { |
|
928 | + // create reflection |
|
929 | + $reflector = $this->get_ReflectionClass($class_name); |
|
930 | + // make sure arguments are an array |
|
931 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
932 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
933 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
934 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
935 | + ? $arguments |
|
936 | + : array($arguments); |
|
937 | + // attempt to inject dependencies ? |
|
938 | + if ($this->_dependency_map->has($class_name)) { |
|
939 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
940 | + } |
|
941 | + // instantiate the class if possible |
|
942 | + if ($reflector->isAbstract()) { |
|
943 | + // nothing to instantiate, loading file was enough |
|
944 | + // does not throw an exception so $instantiation_mode is unused |
|
945 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
946 | + $class_obj = true; |
|
947 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
948 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
949 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
950 | + $class_obj = $reflector->newInstance(); |
|
951 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
952 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
953 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
954 | + } else if (method_exists($class_name, 'new_instance')) { |
|
955 | + $instantiation_mode = "4) new_instance()"; |
|
956 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
957 | + } else if (method_exists($class_name, 'instance')) { |
|
958 | + $instantiation_mode = "5) instance()"; |
|
959 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
960 | + } else if ($reflector->isInstantiable()) { |
|
961 | + $instantiation_mode = "6) constructor"; |
|
962 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
963 | + } else { |
|
964 | + // heh ? something's not right ! |
|
965 | + throw new EE_Error( |
|
966 | + sprintf( |
|
967 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
968 | + $type, |
|
969 | + $class_name |
|
970 | + ) |
|
971 | + ); |
|
972 | + } |
|
973 | + } catch (Exception $e) { |
|
974 | + if ( ! $e instanceof EE_Error) { |
|
975 | + $e = new EE_Error( |
|
976 | + sprintf( |
|
977 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
978 | + $class_name, |
|
979 | + '<br />', |
|
980 | + $e->getMessage(), |
|
981 | + $instantiation_mode |
|
982 | + ) |
|
983 | + ); |
|
984 | + } |
|
985 | + $e->get_error(); |
|
986 | + } |
|
987 | + return $class_obj; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + |
|
992 | + /** |
|
993 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
994 | + * @param array $array |
|
995 | + * @return bool |
|
996 | + */ |
|
997 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
998 | + { |
|
999 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
1000 | + } |
|
1001 | + |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * getReflectionClass |
|
1006 | + * checks if a ReflectionClass object has already been generated for a class |
|
1007 | + * and returns that instead of creating a new one |
|
1008 | + * |
|
1009 | + * @access public |
|
1010 | + * @param string $class_name |
|
1011 | + * @return ReflectionClass |
|
1012 | + */ |
|
1013 | + public function get_ReflectionClass($class_name) |
|
1014 | + { |
|
1015 | + if ( |
|
1016 | + ! isset($this->_reflectors[$class_name]) |
|
1017 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1018 | + ) { |
|
1019 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1020 | + } |
|
1021 | + return $this->_reflectors[$class_name]; |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * _resolve_dependencies |
|
1028 | + * examines the constructor for the requested class to determine |
|
1029 | + * if any dependencies exist, and if they can be injected. |
|
1030 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1031 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1032 | + * For example: |
|
1033 | + * if attempting to load a class "Foo" with the following constructor: |
|
1034 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1035 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1036 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1037 | + * and the correct classes can be loaded |
|
1038 | + * |
|
1039 | + * @access protected |
|
1040 | + * @param ReflectionClass $reflector |
|
1041 | + * @param string $class_name |
|
1042 | + * @param array $arguments |
|
1043 | + * @return array |
|
1044 | + * @throws \ReflectionException |
|
1045 | + */ |
|
1046 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1047 | + { |
|
1048 | + // let's examine the constructor |
|
1049 | + $constructor = $reflector->getConstructor(); |
|
1050 | + // whu? huh? nothing? |
|
1051 | + if ( ! $constructor) { |
|
1052 | + return $arguments; |
|
1053 | + } |
|
1054 | + // get constructor parameters |
|
1055 | + $params = $constructor->getParameters(); |
|
1056 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1057 | + $argument_keys = array_keys($arguments); |
|
1058 | + // now loop thru all of the constructors expected parameters |
|
1059 | + foreach ($params as $index => $param) { |
|
1060 | + // is this a dependency for a specific class ? |
|
1061 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1062 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1063 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1064 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1065 | + : $param_class; |
|
1066 | + if ( |
|
1067 | + // param is not even a class |
|
1068 | + empty($param_class) |
|
1069 | + // and something already exists in the incoming arguments for this param |
|
1070 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1071 | + ) { |
|
1072 | + // so let's skip this argument and move on to the next |
|
1073 | + continue; |
|
1074 | + } |
|
1075 | + if ( |
|
1076 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1077 | + ! empty($param_class) |
|
1078 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1079 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1080 | + ) { |
|
1081 | + // skip this argument and move on to the next |
|
1082 | + continue; |
|
1083 | + } |
|
1084 | + if ( |
|
1085 | + // parameter is type hinted as a class, and should be injected |
|
1086 | + ! empty($param_class) |
|
1087 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1088 | + ) { |
|
1089 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1090 | + } else { |
|
1091 | + try { |
|
1092 | + $arguments[$index] = $param->getDefaultValue(); |
|
1093 | + } catch (ReflectionException $e) { |
|
1094 | + throw new ReflectionException( |
|
1095 | + sprintf( |
|
1096 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1097 | + $e->getMessage(), |
|
1098 | + $param->getName() |
|
1099 | + ) |
|
1100 | + ); |
|
1101 | + } |
|
1102 | + } |
|
1103 | + } |
|
1104 | + return $arguments; |
|
1105 | + } |
|
1106 | + |
|
1107 | + |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * @access protected |
|
1111 | + * @param string $class_name |
|
1112 | + * @param string $param_class |
|
1113 | + * @param array $arguments |
|
1114 | + * @param mixed $index |
|
1115 | + * @return array |
|
1116 | + */ |
|
1117 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1118 | + { |
|
1119 | + $dependency = null; |
|
1120 | + // should dependency be loaded from cache ? |
|
1121 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1122 | + !== EE_Dependency_Map::load_new_object |
|
1123 | + ? true |
|
1124 | + : false; |
|
1125 | + // we might have a dependency... |
|
1126 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1127 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1128 | + // and grab it if it exists |
|
1129 | + if ($cached_class instanceof $param_class) { |
|
1130 | + $dependency = $cached_class; |
|
1131 | + } else if ($param_class !== $class_name) { |
|
1132 | + // obtain the loader method from the dependency map |
|
1133 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1134 | + // is loader a custom closure ? |
|
1135 | + if ($loader instanceof Closure) { |
|
1136 | + $dependency = $loader(); |
|
1137 | + } else { |
|
1138 | + // set the cache on property for the recursive loading call |
|
1139 | + $this->_cache_on = $cache_on; |
|
1140 | + // if not, then let's try and load it via the registry |
|
1141 | + if ($loader && method_exists($this, $loader)) { |
|
1142 | + $dependency = $this->{$loader}($param_class); |
|
1143 | + } else { |
|
1144 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1145 | + } |
|
1146 | + } |
|
1147 | + } |
|
1148 | + // did we successfully find the correct dependency ? |
|
1149 | + if ($dependency instanceof $param_class) { |
|
1150 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1151 | + if (isset($argument_keys[$index])) { |
|
1152 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1153 | + } else { |
|
1154 | + $arguments[$index] = $dependency; |
|
1155 | + } |
|
1156 | + } |
|
1157 | + return $arguments; |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * _set_cached_class |
|
1164 | + * attempts to cache the instantiated class locally |
|
1165 | + * in one of the following places, in the following order: |
|
1166 | + * $this->{class_abbreviation} ie: $this->CART |
|
1167 | + * $this->{$class_name} ie: $this->Some_Class |
|
1168 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1169 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1170 | + * |
|
1171 | + * @access protected |
|
1172 | + * @param object $class_obj |
|
1173 | + * @param string $class_name |
|
1174 | + * @param string $class_prefix |
|
1175 | + * @param bool $from_db |
|
1176 | + * @return void |
|
1177 | + */ |
|
1178 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1179 | + { |
|
1180 | + if (empty($class_obj)) { |
|
1181 | + return; |
|
1182 | + } |
|
1183 | + // return newly instantiated class |
|
1184 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1185 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1186 | + $this->{$class_abbreviation} = $class_obj; |
|
1187 | + return; |
|
1188 | + } |
|
1189 | + $class_name = str_replace('\\', '_', $class_name); |
|
1190 | + if (property_exists($this, $class_name)) { |
|
1191 | + $this->{$class_name} = $class_obj; |
|
1192 | + return; |
|
1193 | + } |
|
1194 | + if ($class_prefix === 'addon') { |
|
1195 | + $this->addons->{$class_name} = $class_obj; |
|
1196 | + return; |
|
1197 | + } |
|
1198 | + if ( ! $from_db) { |
|
1199 | + $this->LIB->{$class_name} = $class_obj; |
|
1200 | + } |
|
1201 | + } |
|
1202 | + |
|
1203 | + |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1207 | + * |
|
1208 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1209 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1210 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1211 | + * @param array $arguments |
|
1212 | + * @return object |
|
1213 | + */ |
|
1214 | + public static function factory($classname, $arguments = array()) |
|
1215 | + { |
|
1216 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1217 | + if ($loader instanceof Closure) { |
|
1218 | + return $loader($arguments); |
|
1219 | + } |
|
1220 | + if (method_exists(EE_Registry::instance(), $loader)) { |
|
1221 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1222 | + } |
|
1223 | + return null; |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1230 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1231 | + * |
|
1232 | + * @param string $name |
|
1233 | + * @return EE_Addon |
|
1234 | + */ |
|
1235 | + public function get_addon_by_name($name) |
|
1236 | + { |
|
1237 | + foreach ($this->addons as $addon) { |
|
1238 | + if ($addon->name() == $name) { |
|
1239 | + return $addon; |
|
1240 | + } |
|
1241 | + } |
|
1242 | + return null; |
|
1243 | + } |
|
1244 | + |
|
1245 | + |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1249 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1250 | + * |
|
1251 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1252 | + */ |
|
1253 | + public function get_addons_by_name() |
|
1254 | + { |
|
1255 | + $addons = array(); |
|
1256 | + foreach ($this->addons as $addon) { |
|
1257 | + $addons[$addon->name()] = $addon; |
|
1258 | + } |
|
1259 | + return $addons; |
|
1260 | + } |
|
1261 | + |
|
1262 | + |
|
1263 | + |
|
1264 | + /** |
|
1265 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1266 | + * a stale copy of it around |
|
1267 | + * |
|
1268 | + * @param string $model_name |
|
1269 | + * @return \EEM_Base |
|
1270 | + * @throws \EE_Error |
|
1271 | + */ |
|
1272 | + public function reset_model($model_name) |
|
1273 | + { |
|
1274 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1275 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1276 | + return null; |
|
1277 | + } |
|
1278 | + //get that model reset it and make sure we nuke the old reference to it |
|
1279 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1280 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1281 | + } else { |
|
1282 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1283 | + } |
|
1284 | + return $this->LIB->{$model_class_name}; |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * Resets the registry. |
|
1291 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1292 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1293 | + * - $_dependency_map |
|
1294 | + * - $_class_abbreviations |
|
1295 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1296 | + * - $REQ: Still on the same request so no need to change. |
|
1297 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1298 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1299 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1300 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1301 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1302 | + * switch or on the restore. |
|
1303 | + * - $modules |
|
1304 | + * - $shortcodes |
|
1305 | + * - $widgets |
|
1306 | + * |
|
1307 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1308 | + * the Registry to its state at the beginning of the request |
|
1309 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1310 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1311 | + * currently reinstantiate the singletons at the moment) |
|
1312 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1313 | + * code instead can just change the model context to a different blog id if necessary |
|
1314 | + * @return EE_Registry |
|
1315 | + */ |
|
1316 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1317 | + { |
|
1318 | + $instance = self::instance(); |
|
1319 | + EEH_Activation::reset(); |
|
1320 | + //properties that get reset |
|
1321 | + $instance->_cache_on = true; |
|
1322 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1323 | + $instance->CART = null; |
|
1324 | + $instance->MRM = null; |
|
1325 | + $instance->AssetsRegistry = null; |
|
1326 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1327 | + //messages reset |
|
1328 | + EED_Messages::reset(); |
|
1329 | + if ($reset_models) { |
|
1330 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1331 | + $instance->reset_model($model_name); |
|
1332 | + } |
|
1333 | + } |
|
1334 | + $instance->LIB = new stdClass(); |
|
1335 | + return $instance; |
|
1336 | + } |
|
1337 | + |
|
1338 | + |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * @override magic methods |
|
1342 | + * @return void |
|
1343 | + */ |
|
1344 | + public final function __destruct() |
|
1345 | + { |
|
1346 | + } |
|
1347 | + |
|
1348 | + |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * @param $a |
|
1352 | + * @param $b |
|
1353 | + */ |
|
1354 | + public final function __call($a, $b) |
|
1355 | + { |
|
1356 | + } |
|
1357 | + |
|
1358 | + |
|
1359 | + |
|
1360 | + /** |
|
1361 | + * @param $a |
|
1362 | + */ |
|
1363 | + public final function __get($a) |
|
1364 | + { |
|
1365 | + } |
|
1366 | + |
|
1367 | + |
|
1368 | + |
|
1369 | + /** |
|
1370 | + * @param $a |
|
1371 | + * @param $b |
|
1372 | + */ |
|
1373 | + public final function __set($a, $b) |
|
1374 | + { |
|
1375 | + } |
|
1376 | + |
|
1377 | + |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * @param $a |
|
1381 | + */ |
|
1382 | + public final function __isset($a) |
|
1383 | + { |
|
1384 | + } |
|
1385 | 1385 | |
1386 | 1386 | |
1387 | 1387 | |
1388 | - /** |
|
1389 | - * @param $a |
|
1390 | - */ |
|
1391 | - public final function __unset($a) |
|
1392 | - { |
|
1393 | - } |
|
1388 | + /** |
|
1389 | + * @param $a |
|
1390 | + */ |
|
1391 | + public final function __unset($a) |
|
1392 | + { |
|
1393 | + } |
|
1394 | 1394 | |
1395 | 1395 | |
1396 | 1396 | |
1397 | - /** |
|
1398 | - * @return array |
|
1399 | - */ |
|
1400 | - public final function __sleep() |
|
1401 | - { |
|
1402 | - return array(); |
|
1403 | - } |
|
1397 | + /** |
|
1398 | + * @return array |
|
1399 | + */ |
|
1400 | + public final function __sleep() |
|
1401 | + { |
|
1402 | + return array(); |
|
1403 | + } |
|
1404 | 1404 | |
1405 | 1405 | |
1406 | 1406 | |
1407 | - public final function __wakeup() |
|
1408 | - { |
|
1409 | - } |
|
1407 | + public final function __wakeup() |
|
1408 | + { |
|
1409 | + } |
|
1410 | 1410 | |
1411 | 1411 | |
1412 | 1412 | |
1413 | - /** |
|
1414 | - * @return string |
|
1415 | - */ |
|
1416 | - public final function __toString() |
|
1417 | - { |
|
1418 | - return ''; |
|
1419 | - } |
|
1413 | + /** |
|
1414 | + * @return string |
|
1415 | + */ |
|
1416 | + public final function __toString() |
|
1417 | + { |
|
1418 | + return ''; |
|
1419 | + } |
|
1420 | 1420 | |
1421 | 1421 | |
1422 | 1422 | |
1423 | - public final function __invoke() |
|
1424 | - { |
|
1425 | - } |
|
1423 | + public final function __invoke() |
|
1424 | + { |
|
1425 | + } |
|
1426 | 1426 | |
1427 | 1427 | |
1428 | 1428 | |
1429 | - public final static function __set_state($array = array()) |
|
1430 | - { |
|
1431 | - return EE_Registry::instance(); |
|
1432 | - } |
|
1429 | + public final static function __set_state($array = array()) |
|
1430 | + { |
|
1431 | + return EE_Registry::instance(); |
|
1432 | + } |
|
1433 | 1433 | |
1434 | 1434 | |
1435 | 1435 | |
1436 | - public final function __clone() |
|
1437 | - { |
|
1438 | - } |
|
1436 | + public final function __clone() |
|
1437 | + { |
|
1438 | + } |
|
1439 | 1439 | |
1440 | 1440 | |
1441 | 1441 | |
1442 | - /** |
|
1443 | - * @param $a |
|
1444 | - * @param $b |
|
1445 | - */ |
|
1446 | - public final static function __callStatic($a, $b) |
|
1447 | - { |
|
1448 | - } |
|
1442 | + /** |
|
1443 | + * @param $a |
|
1444 | + * @param $b |
|
1445 | + */ |
|
1446 | + public final static function __callStatic($a, $b) |
|
1447 | + { |
|
1448 | + } |
|
1449 | 1449 | |
1450 | 1450 | |
1451 | 1451 | |
1452 | - /** |
|
1453 | - * Gets all the custom post type models defined |
|
1454 | - * |
|
1455 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1456 | - */ |
|
1457 | - public function cpt_models() |
|
1458 | - { |
|
1459 | - $cpt_models = array(); |
|
1460 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1461 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1462 | - $cpt_models[$short_name] = $classname; |
|
1463 | - } |
|
1464 | - } |
|
1465 | - return $cpt_models; |
|
1466 | - } |
|
1452 | + /** |
|
1453 | + * Gets all the custom post type models defined |
|
1454 | + * |
|
1455 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1456 | + */ |
|
1457 | + public function cpt_models() |
|
1458 | + { |
|
1459 | + $cpt_models = array(); |
|
1460 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1461 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1462 | + $cpt_models[$short_name] = $classname; |
|
1463 | + } |
|
1464 | + } |
|
1465 | + return $cpt_models; |
|
1466 | + } |
|
1467 | 1467 | |
1468 | 1468 | |
1469 | 1469 | |
1470 | - /** |
|
1471 | - * @return \EE_Config |
|
1472 | - */ |
|
1473 | - public static function CFG() |
|
1474 | - { |
|
1475 | - return self::instance()->CFG; |
|
1476 | - } |
|
1470 | + /** |
|
1471 | + * @return \EE_Config |
|
1472 | + */ |
|
1473 | + public static function CFG() |
|
1474 | + { |
|
1475 | + return self::instance()->CFG; |
|
1476 | + } |
|
1477 | 1477 | |
1478 | 1478 | |
1479 | 1479 | } |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public static function localize_i18n_js_strings() |
296 | 296 | { |
297 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
297 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
298 | 298 | foreach ($i18n_js_strings as $key => $value) { |
299 | 299 | if (is_scalar($value)) { |
300 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
300 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
301 | 301 | } |
302 | 302 | } |
303 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
303 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | |
@@ -351,9 +351,9 @@ discard block |
||
351 | 351 | EE_CORE, |
352 | 352 | EE_ADMIN, |
353 | 353 | EE_CPTS, |
354 | - EE_CORE . 'data_migration_scripts' . DS, |
|
355 | - EE_CORE . 'request_stack' . DS, |
|
356 | - EE_CORE . 'middleware' . DS, |
|
354 | + EE_CORE.'data_migration_scripts'.DS, |
|
355 | + EE_CORE.'request_stack'.DS, |
|
356 | + EE_CORE.'middleware'.DS, |
|
357 | 357 | ) |
358 | 358 | ); |
359 | 359 | // retrieve instantiated class |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $service_paths = apply_filters( |
377 | 377 | 'FHEE__EE_Registry__load_service__service_paths', |
378 | 378 | array( |
379 | - EE_CORE . 'services' . DS, |
|
379 | + EE_CORE.'services'.DS, |
|
380 | 380 | ) |
381 | 381 | ); |
382 | 382 | // retrieve instantiated class |
@@ -456,10 +456,10 @@ discard block |
||
456 | 456 | { |
457 | 457 | $paths = array( |
458 | 458 | EE_LIBRARIES, |
459 | - EE_LIBRARIES . 'messages' . DS, |
|
460 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
461 | - EE_LIBRARIES . 'qtips' . DS, |
|
462 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
459 | + EE_LIBRARIES.'messages'.DS, |
|
460 | + EE_LIBRARIES.'shortcodes'.DS, |
|
461 | + EE_LIBRARIES.'qtips'.DS, |
|
462 | + EE_LIBRARIES.'payment_methods'.DS, |
|
463 | 463 | ); |
464 | 464 | // retrieve instantiated class |
465 | 465 | return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
@@ -498,10 +498,10 @@ discard block |
||
498 | 498 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
499 | 499 | { |
500 | 500 | $paths = array( |
501 | - EE_MODELS . 'fields' . DS, |
|
502 | - EE_MODELS . 'helpers' . DS, |
|
503 | - EE_MODELS . 'relations' . DS, |
|
504 | - EE_MODELS . 'strategies' . DS, |
|
501 | + EE_MODELS.'fields'.DS, |
|
502 | + EE_MODELS.'helpers'.DS, |
|
503 | + EE_MODELS.'relations'.DS, |
|
504 | + EE_MODELS.'strategies'.DS, |
|
505 | 505 | ); |
506 | 506 | // retrieve instantiated class |
507 | 507 | return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | $class_exists = $this->loadOrVerifyClassExists($class_name); |
591 | 591 | // if a non-FQCN was passed, then verifyClassExists() might return an object |
592 | 592 | // or it could return null if the class just could not be found anywhere |
593 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
593 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
594 | 594 | // either way, return the results |
595 | 595 | return $class_name; |
596 | 596 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | // instantiate the requested object |
614 | 614 | $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
615 | 615 | // if caching is turned on OR this class is cached in a class property |
616 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
616 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[$class_name])) { |
|
617 | 617 | // save it for later... kinda like gum { : $ |
618 | 618 | $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
619 | 619 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | case 1: |
639 | 639 | // if it's a FQCN then maybe the class is registered with a preceding \ |
640 | 640 | $class_name = strpos($class_name, '\\') !== false |
641 | - ? '\\' . ltrim($class_name, '\\') |
|
641 | + ? '\\'.ltrim($class_name, '\\') |
|
642 | 642 | : $class_name; |
643 | 643 | break; |
644 | 644 | case 2: |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | // make sure $class_prefix is uppercase |
694 | 694 | $class_prefix = strtoupper(trim($class_prefix)); |
695 | 695 | // add class prefix ONCE!!! |
696 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
696 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
697 | 697 | } |
698 | 698 | $class_name = $this->_dependency_map->get_alias($class_name); |
699 | 699 | $class_exists = class_exists($class_name); |
@@ -753,8 +753,8 @@ discard block |
||
753 | 753 | protected function _get_cached_class($class_name, $class_prefix = '') |
754 | 754 | { |
755 | 755 | // have to specify something, but not anything that will conflict |
756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
757 | - ? $this->_class_abbreviations[ $class_name ] |
|
756 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
757 | + ? $this->_class_abbreviations[$class_name] |
|
758 | 758 | : 'FANCY_BATMAN_PANTS'; |
759 | 759 | $class_name = str_replace('\\', '_', $class_name); |
760 | 760 | // check if class has already been loaded, and return it if it has been |
@@ -785,8 +785,8 @@ discard block |
||
785 | 785 | public function clear_cached_class($class_name, $addon = false) |
786 | 786 | { |
787 | 787 | // have to specify something, but not anything that will conflict |
788 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
789 | - ? $this->_class_abbreviations[ $class_name ] |
|
788 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
789 | + ? $this->_class_abbreviations[$class_name] |
|
790 | 790 | : 'FANCY_BATMAN_PANTS'; |
791 | 791 | $class_name = str_replace('\\', '_', $class_name); |
792 | 792 | // check if class has already been loaded, and return it if it has been |
@@ -831,9 +831,9 @@ discard block |
||
831 | 831 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
832 | 832 | $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
833 | 833 | // prep file type |
834 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
834 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
835 | 835 | // build full file path |
836 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
836 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
837 | 837 | //does the file exist and can be read ? |
838 | 838 | if (is_readable($file_paths[$key])) { |
839 | 839 | return $file_paths[$key]; |
@@ -864,12 +864,12 @@ discard block |
||
864 | 864 | //does the file exist and can it be read ? |
865 | 865 | if ( ! $path) { |
866 | 866 | // so sorry, can't find the file |
867 | - throw new EE_Error ( |
|
867 | + throw new EE_Error( |
|
868 | 868 | sprintf( |
869 | 869 | __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
870 | 870 | trim($type, '.'), |
871 | 871 | $class_name, |
872 | - '<br />' . implode(',<br />', $file_paths) |
|
872 | + '<br />'.implode(',<br />', $file_paths) |
|
873 | 873 | ) |
874 | 874 | ); |
875 | 875 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,738 +21,738 @@ discard block |
||
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 | - |
|
55 | - /** |
|
56 | - * @type EE_Dependency_Map $_instance |
|
57 | - */ |
|
58 | - protected static $_instance; |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Request $request |
|
62 | - */ |
|
63 | - protected $_request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @type EE_Response $response |
|
67 | - */ |
|
68 | - protected $_response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type LoaderInterface $loader |
|
72 | - */ |
|
73 | - protected $loader; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type array $_dependency_map |
|
77 | - */ |
|
78 | - protected $_dependency_map = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * @type array $_class_loaders |
|
82 | - */ |
|
83 | - protected $_class_loaders = array(); |
|
84 | - |
|
85 | - /** |
|
86 | - * @type array $_aliases |
|
87 | - */ |
|
88 | - protected $_aliases = array(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * EE_Dependency_Map constructor. |
|
94 | - * |
|
95 | - * @param EE_Request $request |
|
96 | - * @param EE_Response $response |
|
97 | - */ |
|
98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | - { |
|
100 | - $this->_request = $request; |
|
101 | - $this->_response = $response; |
|
102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | - do_action('EE_Dependency_Map____construct'); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws InvalidArgumentException |
|
112 | - */ |
|
113 | - public function initialize() |
|
114 | - { |
|
115 | - $this->_register_core_dependencies(); |
|
116 | - $this->_register_core_class_loaders(); |
|
117 | - $this->_register_core_aliases(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @singleton method used to instantiate class object |
|
124 | - * @access public |
|
125 | - * @param EE_Request $request |
|
126 | - * @param EE_Response $response |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | - { |
|
131 | - // check if class object is instantiated, and instantiated properly |
|
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | - } |
|
135 | - return self::$_instance; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param LoaderInterface $loader |
|
142 | - */ |
|
143 | - public function setLoader(LoaderInterface $loader) |
|
144 | - { |
|
145 | - $this->loader = $loader; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $class |
|
152 | - * @param array $dependencies |
|
153 | - * @param int $overwrite |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public static function register_dependencies( |
|
157 | - $class, |
|
158 | - array $dependencies, |
|
159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | - ) { |
|
161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | - * to the class specified by the first parameter. |
|
169 | - * IMPORTANT !!! |
|
170 | - * The order of elements in the incoming $dependencies array MUST match |
|
171 | - * the order of the constructor parameters for the class in question. |
|
172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | - * |
|
175 | - * @param string $class |
|
176 | - * @param array $dependencies |
|
177 | - * @param int $overwrite |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function registerDependencies( |
|
181 | - $class, |
|
182 | - array $dependencies, |
|
183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | - ) { |
|
185 | - $registered = false; |
|
186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | - } |
|
189 | - // we need to make sure that any aliases used when registering a dependency |
|
190 | - // get resolved to the correct class name |
|
191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | - $alias = self::$_instance->get_alias($dependency); |
|
193 | - if ( |
|
194 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | - ) { |
|
197 | - unset($dependencies[$dependency]); |
|
198 | - $dependencies[$alias] = $load_source; |
|
199 | - $registered = true; |
|
200 | - } |
|
201 | - } |
|
202 | - // now add our two lists of dependencies together. |
|
203 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | - // so $dependencies is NOT overwritten because it is listed first |
|
205 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | - // Union is way faster than array_merge() but should be used with caution... |
|
207 | - // especially with numerically indexed arrays |
|
208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | - // now we need to ensure that the resulting dependencies |
|
210 | - // array only has the entries that are required for the class |
|
211 | - // so first count how many dependencies were originally registered for the class |
|
212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | - // if that count is non-zero (meaning dependencies were already registered) |
|
214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | - // then truncate the final array to match that count |
|
216 | - ? array_slice($dependencies, 0, $dependency_count) |
|
217 | - // otherwise just take the incoming array because nothing previously existed |
|
218 | - : $dependencies; |
|
219 | - return $registered; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $class_name |
|
226 | - * @param string $loader |
|
227 | - * @return bool |
|
228 | - * @throws DomainException |
|
229 | - */ |
|
230 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | - { |
|
232 | - if (strpos($class_name, '\\') !== false) { |
|
233 | - throw new DomainException( |
|
234 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | - ); |
|
236 | - } |
|
237 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | - if ( |
|
239 | - ! is_callable($loader) |
|
240 | - && ( |
|
241 | - strpos($loader, 'load_') !== 0 |
|
242 | - || ! method_exists('EE_Registry', $loader) |
|
243 | - ) |
|
244 | - ) { |
|
245 | - throw new DomainException( |
|
246 | - sprintf( |
|
247 | - esc_html__( |
|
248 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | - 'event_espresso' |
|
250 | - ), |
|
251 | - $loader |
|
252 | - ) |
|
253 | - ); |
|
254 | - } |
|
255 | - $class_name = self::$_instance->get_alias($class_name); |
|
256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | - return true; |
|
259 | - } |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function dependency_map() |
|
269 | - { |
|
270 | - return $this->_dependency_map; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | - * |
|
278 | - * @param string $class_name |
|
279 | - * @return boolean |
|
280 | - */ |
|
281 | - public function has($class_name = '') |
|
282 | - { |
|
283 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | - * |
|
291 | - * @param string $class_name |
|
292 | - * @param string $dependency |
|
293 | - * @return bool |
|
294 | - */ |
|
295 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | - { |
|
297 | - $dependency = $this->get_alias($dependency); |
|
298 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | - ? true |
|
300 | - : false; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @param string $dependency |
|
310 | - * @return int |
|
311 | - */ |
|
312 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | - { |
|
314 | - $dependency = $this->get_alias($dependency); |
|
315 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | - ? $this->_dependency_map[$class_name][$dependency] |
|
317 | - : EE_Dependency_Map::not_registered; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $class_name |
|
324 | - * @return string | Closure |
|
325 | - */ |
|
326 | - public function class_loader($class_name) |
|
327 | - { |
|
328 | - // don't use loaders for FQCNs |
|
329 | - if(strpos($class_name, '\\') !== false){ |
|
330 | - return ''; |
|
331 | - } |
|
332 | - $class_name = $this->get_alias($class_name); |
|
333 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @return array |
|
340 | - */ |
|
341 | - public function class_loaders() |
|
342 | - { |
|
343 | - return $this->_class_loaders; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * adds an alias for a classname |
|
350 | - * |
|
351 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | - */ |
|
355 | - public function add_alias($class_name, $alias, $for_class = '') |
|
356 | - { |
|
357 | - if ($for_class !== '') { |
|
358 | - if (! isset($this->_aliases[$for_class])) { |
|
359 | - $this->_aliases[$for_class] = array(); |
|
360 | - } |
|
361 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | - } |
|
363 | - $this->_aliases[$class_name] = $alias; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * returns TRUE if the provided class name has an alias |
|
370 | - * |
|
371 | - * @param string $class_name |
|
372 | - * @param string $for_class |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function has_alias($class_name = '', $for_class = '') |
|
376 | - { |
|
377 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | - || ( |
|
379 | - isset($this->_aliases[$class_name]) |
|
380 | - && ! is_array($this->_aliases[$class_name]) |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | - * for example: |
|
390 | - * if the following two entries were added to the _aliases array: |
|
391 | - * array( |
|
392 | - * 'interface_alias' => 'some\namespace\interface' |
|
393 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | - * ) |
|
395 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | - * to load an instance of 'some\namespace\classname' |
|
397 | - * |
|
398 | - * @param string $class_name |
|
399 | - * @param string $for_class |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_alias($class_name = '', $for_class = '') |
|
403 | - { |
|
404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
405 | - return $class_name; |
|
406 | - } |
|
407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | - } |
|
410 | - return $this->get_alias($this->_aliases[$class_name]); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | - * This is done by using the following class constants: |
|
419 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | - */ |
|
422 | - protected function _register_core_dependencies() |
|
423 | - { |
|
424 | - $this->_dependency_map = array( |
|
425 | - 'EE_Request_Handler' => array( |
|
426 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EE_System' => array( |
|
429 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
431 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
432 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
433 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
434 | - ), |
|
435 | - 'EE_Session' => array( |
|
436 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
437 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
438 | - ), |
|
439 | - 'EE_Cart' => array( |
|
440 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_Front_Controller' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
446 | - ), |
|
447 | - 'EE_Messenger_Collection_Loader' => array( |
|
448 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | - ), |
|
450 | - 'EE_Message_Type_Collection_Loader' => array( |
|
451 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
452 | - ), |
|
453 | - 'EE_Message_Resource_Manager' => array( |
|
454 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
455 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
456 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
457 | - ), |
|
458 | - 'EE_Message_Factory' => array( |
|
459 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_messages' => array( |
|
462 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_Messages_Generator' => array( |
|
465 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
466 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
468 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messages_Processor' => array( |
|
471 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_Messages_Queue' => array( |
|
474 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Messages_Template_Defaults' => array( |
|
477 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
478 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Message_To_Generate_From_Request' => array( |
|
481 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
485 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
488 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
489 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
490 | - ), |
|
491 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
492 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
495 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
496 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
499 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
502 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
503 | - ), |
|
504 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
505 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
508 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
511 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
514 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
517 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
520 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
523 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
529 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
532 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EE_Data_Migration_Class_Base' => array( |
|
538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EE_DMS_Core_4_1_0' => array( |
|
542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EE_DMS_Core_4_2_0' => array( |
|
546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EE_DMS_Core_4_3_0' => array( |
|
550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EE_DMS_Core_4_4_0' => array( |
|
554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EE_DMS_Core_4_5_0' => array( |
|
558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | - ), |
|
561 | - 'EE_DMS_Core_4_6_0' => array( |
|
562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | - ), |
|
565 | - 'EE_DMS_Core_4_7_0' => array( |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EE_DMS_Core_4_8_0' => array( |
|
570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | - ), |
|
573 | - 'EE_DMS_Core_4_9_0' => array( |
|
574 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | - ), |
|
577 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | - ), |
|
581 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ), |
|
584 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | - ), |
|
593 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ), |
|
596 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
608 | - ), |
|
609 | - ); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * Registers how core classes are loaded. |
|
616 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
617 | - * 'EE_Request_Handler' => 'load_core' |
|
618 | - * 'EE_Messages_Queue' => 'load_lib' |
|
619 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
620 | - * or, if greater control is required, by providing a custom closure. For example: |
|
621 | - * 'Some_Class' => function () { |
|
622 | - * return new Some_Class(); |
|
623 | - * }, |
|
624 | - * This is required for instantiating dependencies |
|
625 | - * where an interface has been type hinted in a class constructor. For example: |
|
626 | - * 'Required_Interface' => function () { |
|
627 | - * return new A_Class_That_Implements_Required_Interface(); |
|
628 | - * }, |
|
629 | - */ |
|
630 | - protected function _register_core_class_loaders() |
|
631 | - { |
|
632 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
633 | - //be used in a closure. |
|
634 | - $request = &$this->_request; |
|
635 | - $response = &$this->_response; |
|
636 | - $loader = &$this->loader; |
|
637 | - $this->_class_loaders = array( |
|
638 | - //load_core |
|
639 | - 'EE_Capabilities' => 'load_core', |
|
640 | - 'EE_Encryption' => 'load_core', |
|
641 | - 'EE_Front_Controller' => 'load_core', |
|
642 | - 'EE_Module_Request_Router' => 'load_core', |
|
643 | - 'EE_Registry' => 'load_core', |
|
644 | - 'EE_Request' => function () use (&$request) { |
|
645 | - return $request; |
|
646 | - }, |
|
647 | - 'EE_Response' => function () use (&$response) { |
|
648 | - return $response; |
|
649 | - }, |
|
650 | - 'EE_Request_Handler' => 'load_core', |
|
651 | - 'EE_Session' => 'load_core', |
|
652 | - 'EE_System' => 'load_core', |
|
653 | - 'EE_Maintenance_Mode' => 'load_core', |
|
654 | - 'EE_Register_CPTs' => 'load_core', |
|
655 | - //load_lib |
|
656 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
657 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
658 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
659 | - 'EE_Messenger_Collection' => 'load_lib', |
|
660 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
661 | - 'EE_Messages_Processor' => 'load_lib', |
|
662 | - 'EE_Message_Repository' => 'load_lib', |
|
663 | - 'EE_Messages_Queue' => 'load_lib', |
|
664 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
665 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
666 | - 'EE_Messages_Generator' => function () { |
|
667 | - return EE_Registry::instance()->load_lib( |
|
668 | - 'Messages_Generator', |
|
669 | - array(), |
|
670 | - false, |
|
671 | - false |
|
672 | - ); |
|
673 | - }, |
|
674 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
675 | - return EE_Registry::instance()->load_lib( |
|
676 | - 'Messages_Template_Defaults', |
|
677 | - $arguments, |
|
678 | - false, |
|
679 | - false |
|
680 | - ); |
|
681 | - }, |
|
682 | - //load_model |
|
683 | - 'EEM_Message_Template_Group' => 'load_model', |
|
684 | - 'EEM_Message_Template' => 'load_model', |
|
685 | - //load_helper |
|
686 | - 'EEH_Parse_Shortcodes' => function () { |
|
687 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
688 | - return new EEH_Parse_Shortcodes(); |
|
689 | - } |
|
690 | - return null; |
|
691 | - }, |
|
692 | - 'EE_Template_Config' => function () { |
|
693 | - return EE_Config::instance()->template_settings; |
|
694 | - }, |
|
695 | - 'EE_Currency_Config' => function () { |
|
696 | - return EE_Config::instance()->currency; |
|
697 | - }, |
|
698 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
699 | - return $loader; |
|
700 | - }, |
|
701 | - ); |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * can be used for supplying alternate names for classes, |
|
708 | - * or for connecting interface names to instantiable classes |
|
709 | - */ |
|
710 | - protected function _register_core_aliases() |
|
711 | - { |
|
712 | - $this->_aliases = array( |
|
713 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
714 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
715 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
716 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
717 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
718 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
719 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
720 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
721 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
722 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
723 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
724 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
725 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
726 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
727 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
728 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
729 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
730 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
731 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
732 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
733 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
734 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
735 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
736 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
737 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
738 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
739 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
740 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
741 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
742 | - ); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
749 | - * request Primarily used by unit tests. |
|
750 | - */ |
|
751 | - public function reset() |
|
752 | - { |
|
753 | - $this->_register_core_class_loaders(); |
|
754 | - $this->_register_core_dependencies(); |
|
755 | - } |
|
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 | + |
|
55 | + /** |
|
56 | + * @type EE_Dependency_Map $_instance |
|
57 | + */ |
|
58 | + protected static $_instance; |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Request $request |
|
62 | + */ |
|
63 | + protected $_request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @type EE_Response $response |
|
67 | + */ |
|
68 | + protected $_response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type LoaderInterface $loader |
|
72 | + */ |
|
73 | + protected $loader; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type array $_dependency_map |
|
77 | + */ |
|
78 | + protected $_dependency_map = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * @type array $_class_loaders |
|
82 | + */ |
|
83 | + protected $_class_loaders = array(); |
|
84 | + |
|
85 | + /** |
|
86 | + * @type array $_aliases |
|
87 | + */ |
|
88 | + protected $_aliases = array(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * EE_Dependency_Map constructor. |
|
94 | + * |
|
95 | + * @param EE_Request $request |
|
96 | + * @param EE_Response $response |
|
97 | + */ |
|
98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | + { |
|
100 | + $this->_request = $request; |
|
101 | + $this->_response = $response; |
|
102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | + do_action('EE_Dependency_Map____construct'); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws InvalidArgumentException |
|
112 | + */ |
|
113 | + public function initialize() |
|
114 | + { |
|
115 | + $this->_register_core_dependencies(); |
|
116 | + $this->_register_core_class_loaders(); |
|
117 | + $this->_register_core_aliases(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @singleton method used to instantiate class object |
|
124 | + * @access public |
|
125 | + * @param EE_Request $request |
|
126 | + * @param EE_Response $response |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | + { |
|
131 | + // check if class object is instantiated, and instantiated properly |
|
132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | + } |
|
135 | + return self::$_instance; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param LoaderInterface $loader |
|
142 | + */ |
|
143 | + public function setLoader(LoaderInterface $loader) |
|
144 | + { |
|
145 | + $this->loader = $loader; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $class |
|
152 | + * @param array $dependencies |
|
153 | + * @param int $overwrite |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public static function register_dependencies( |
|
157 | + $class, |
|
158 | + array $dependencies, |
|
159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | + ) { |
|
161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | + * to the class specified by the first parameter. |
|
169 | + * IMPORTANT !!! |
|
170 | + * The order of elements in the incoming $dependencies array MUST match |
|
171 | + * the order of the constructor parameters for the class in question. |
|
172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | + * |
|
175 | + * @param string $class |
|
176 | + * @param array $dependencies |
|
177 | + * @param int $overwrite |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function registerDependencies( |
|
181 | + $class, |
|
182 | + array $dependencies, |
|
183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | + ) { |
|
185 | + $registered = false; |
|
186 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | + } |
|
189 | + // we need to make sure that any aliases used when registering a dependency |
|
190 | + // get resolved to the correct class name |
|
191 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | + $alias = self::$_instance->get_alias($dependency); |
|
193 | + if ( |
|
194 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | + ) { |
|
197 | + unset($dependencies[$dependency]); |
|
198 | + $dependencies[$alias] = $load_source; |
|
199 | + $registered = true; |
|
200 | + } |
|
201 | + } |
|
202 | + // now add our two lists of dependencies together. |
|
203 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | + // so $dependencies is NOT overwritten because it is listed first |
|
205 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | + // Union is way faster than array_merge() but should be used with caution... |
|
207 | + // especially with numerically indexed arrays |
|
208 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | + // now we need to ensure that the resulting dependencies |
|
210 | + // array only has the entries that are required for the class |
|
211 | + // so first count how many dependencies were originally registered for the class |
|
212 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | + // if that count is non-zero (meaning dependencies were already registered) |
|
214 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | + // then truncate the final array to match that count |
|
216 | + ? array_slice($dependencies, 0, $dependency_count) |
|
217 | + // otherwise just take the incoming array because nothing previously existed |
|
218 | + : $dependencies; |
|
219 | + return $registered; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $class_name |
|
226 | + * @param string $loader |
|
227 | + * @return bool |
|
228 | + * @throws DomainException |
|
229 | + */ |
|
230 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | + { |
|
232 | + if (strpos($class_name, '\\') !== false) { |
|
233 | + throw new DomainException( |
|
234 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | + ); |
|
236 | + } |
|
237 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | + if ( |
|
239 | + ! is_callable($loader) |
|
240 | + && ( |
|
241 | + strpos($loader, 'load_') !== 0 |
|
242 | + || ! method_exists('EE_Registry', $loader) |
|
243 | + ) |
|
244 | + ) { |
|
245 | + throw new DomainException( |
|
246 | + sprintf( |
|
247 | + esc_html__( |
|
248 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | + 'event_espresso' |
|
250 | + ), |
|
251 | + $loader |
|
252 | + ) |
|
253 | + ); |
|
254 | + } |
|
255 | + $class_name = self::$_instance->get_alias($class_name); |
|
256 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | + return true; |
|
259 | + } |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function dependency_map() |
|
269 | + { |
|
270 | + return $this->_dependency_map; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | + * |
|
278 | + * @param string $class_name |
|
279 | + * @return boolean |
|
280 | + */ |
|
281 | + public function has($class_name = '') |
|
282 | + { |
|
283 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | + * |
|
291 | + * @param string $class_name |
|
292 | + * @param string $dependency |
|
293 | + * @return bool |
|
294 | + */ |
|
295 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | + { |
|
297 | + $dependency = $this->get_alias($dependency); |
|
298 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | + ? true |
|
300 | + : false; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @param string $dependency |
|
310 | + * @return int |
|
311 | + */ |
|
312 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | + { |
|
314 | + $dependency = $this->get_alias($dependency); |
|
315 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | + ? $this->_dependency_map[$class_name][$dependency] |
|
317 | + : EE_Dependency_Map::not_registered; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @param string $class_name |
|
324 | + * @return string | Closure |
|
325 | + */ |
|
326 | + public function class_loader($class_name) |
|
327 | + { |
|
328 | + // don't use loaders for FQCNs |
|
329 | + if(strpos($class_name, '\\') !== false){ |
|
330 | + return ''; |
|
331 | + } |
|
332 | + $class_name = $this->get_alias($class_name); |
|
333 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @return array |
|
340 | + */ |
|
341 | + public function class_loaders() |
|
342 | + { |
|
343 | + return $this->_class_loaders; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * adds an alias for a classname |
|
350 | + * |
|
351 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | + */ |
|
355 | + public function add_alias($class_name, $alias, $for_class = '') |
|
356 | + { |
|
357 | + if ($for_class !== '') { |
|
358 | + if (! isset($this->_aliases[$for_class])) { |
|
359 | + $this->_aliases[$for_class] = array(); |
|
360 | + } |
|
361 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | + } |
|
363 | + $this->_aliases[$class_name] = $alias; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * returns TRUE if the provided class name has an alias |
|
370 | + * |
|
371 | + * @param string $class_name |
|
372 | + * @param string $for_class |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function has_alias($class_name = '', $for_class = '') |
|
376 | + { |
|
377 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | + || ( |
|
379 | + isset($this->_aliases[$class_name]) |
|
380 | + && ! is_array($this->_aliases[$class_name]) |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | + * for example: |
|
390 | + * if the following two entries were added to the _aliases array: |
|
391 | + * array( |
|
392 | + * 'interface_alias' => 'some\namespace\interface' |
|
393 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | + * ) |
|
395 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | + * to load an instance of 'some\namespace\classname' |
|
397 | + * |
|
398 | + * @param string $class_name |
|
399 | + * @param string $for_class |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_alias($class_name = '', $for_class = '') |
|
403 | + { |
|
404 | + if (! $this->has_alias($class_name, $for_class)) { |
|
405 | + return $class_name; |
|
406 | + } |
|
407 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | + } |
|
410 | + return $this->get_alias($this->_aliases[$class_name]); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | + * This is done by using the following class constants: |
|
419 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | + */ |
|
422 | + protected function _register_core_dependencies() |
|
423 | + { |
|
424 | + $this->_dependency_map = array( |
|
425 | + 'EE_Request_Handler' => array( |
|
426 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EE_System' => array( |
|
429 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
431 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
432 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
433 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
434 | + ), |
|
435 | + 'EE_Session' => array( |
|
436 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
437 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
438 | + ), |
|
439 | + 'EE_Cart' => array( |
|
440 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_Front_Controller' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
446 | + ), |
|
447 | + 'EE_Messenger_Collection_Loader' => array( |
|
448 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | + ), |
|
450 | + 'EE_Message_Type_Collection_Loader' => array( |
|
451 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
452 | + ), |
|
453 | + 'EE_Message_Resource_Manager' => array( |
|
454 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
455 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
456 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
457 | + ), |
|
458 | + 'EE_Message_Factory' => array( |
|
459 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_messages' => array( |
|
462 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_Messages_Generator' => array( |
|
465 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
466 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
468 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messages_Processor' => array( |
|
471 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_Messages_Queue' => array( |
|
474 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Messages_Template_Defaults' => array( |
|
477 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
478 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Message_To_Generate_From_Request' => array( |
|
481 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
485 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
488 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
489 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
490 | + ), |
|
491 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
492 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
495 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
496 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
499 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
502 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
503 | + ), |
|
504 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
505 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
508 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
511 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
514 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
517 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
520 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
523 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
529 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
532 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EE_Data_Migration_Class_Base' => array( |
|
538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EE_DMS_Core_4_1_0' => array( |
|
542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EE_DMS_Core_4_2_0' => array( |
|
546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EE_DMS_Core_4_3_0' => array( |
|
550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EE_DMS_Core_4_4_0' => array( |
|
554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EE_DMS_Core_4_5_0' => array( |
|
558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | + ), |
|
561 | + 'EE_DMS_Core_4_6_0' => array( |
|
562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | + ), |
|
565 | + 'EE_DMS_Core_4_7_0' => array( |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EE_DMS_Core_4_8_0' => array( |
|
570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | + ), |
|
573 | + 'EE_DMS_Core_4_9_0' => array( |
|
574 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | + ), |
|
577 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | + ), |
|
581 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ), |
|
584 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | + ), |
|
593 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ), |
|
596 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
608 | + ), |
|
609 | + ); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * Registers how core classes are loaded. |
|
616 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
617 | + * 'EE_Request_Handler' => 'load_core' |
|
618 | + * 'EE_Messages_Queue' => 'load_lib' |
|
619 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
620 | + * or, if greater control is required, by providing a custom closure. For example: |
|
621 | + * 'Some_Class' => function () { |
|
622 | + * return new Some_Class(); |
|
623 | + * }, |
|
624 | + * This is required for instantiating dependencies |
|
625 | + * where an interface has been type hinted in a class constructor. For example: |
|
626 | + * 'Required_Interface' => function () { |
|
627 | + * return new A_Class_That_Implements_Required_Interface(); |
|
628 | + * }, |
|
629 | + */ |
|
630 | + protected function _register_core_class_loaders() |
|
631 | + { |
|
632 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
633 | + //be used in a closure. |
|
634 | + $request = &$this->_request; |
|
635 | + $response = &$this->_response; |
|
636 | + $loader = &$this->loader; |
|
637 | + $this->_class_loaders = array( |
|
638 | + //load_core |
|
639 | + 'EE_Capabilities' => 'load_core', |
|
640 | + 'EE_Encryption' => 'load_core', |
|
641 | + 'EE_Front_Controller' => 'load_core', |
|
642 | + 'EE_Module_Request_Router' => 'load_core', |
|
643 | + 'EE_Registry' => 'load_core', |
|
644 | + 'EE_Request' => function () use (&$request) { |
|
645 | + return $request; |
|
646 | + }, |
|
647 | + 'EE_Response' => function () use (&$response) { |
|
648 | + return $response; |
|
649 | + }, |
|
650 | + 'EE_Request_Handler' => 'load_core', |
|
651 | + 'EE_Session' => 'load_core', |
|
652 | + 'EE_System' => 'load_core', |
|
653 | + 'EE_Maintenance_Mode' => 'load_core', |
|
654 | + 'EE_Register_CPTs' => 'load_core', |
|
655 | + //load_lib |
|
656 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
657 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
658 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
659 | + 'EE_Messenger_Collection' => 'load_lib', |
|
660 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
661 | + 'EE_Messages_Processor' => 'load_lib', |
|
662 | + 'EE_Message_Repository' => 'load_lib', |
|
663 | + 'EE_Messages_Queue' => 'load_lib', |
|
664 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
665 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
666 | + 'EE_Messages_Generator' => function () { |
|
667 | + return EE_Registry::instance()->load_lib( |
|
668 | + 'Messages_Generator', |
|
669 | + array(), |
|
670 | + false, |
|
671 | + false |
|
672 | + ); |
|
673 | + }, |
|
674 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
675 | + return EE_Registry::instance()->load_lib( |
|
676 | + 'Messages_Template_Defaults', |
|
677 | + $arguments, |
|
678 | + false, |
|
679 | + false |
|
680 | + ); |
|
681 | + }, |
|
682 | + //load_model |
|
683 | + 'EEM_Message_Template_Group' => 'load_model', |
|
684 | + 'EEM_Message_Template' => 'load_model', |
|
685 | + //load_helper |
|
686 | + 'EEH_Parse_Shortcodes' => function () { |
|
687 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
688 | + return new EEH_Parse_Shortcodes(); |
|
689 | + } |
|
690 | + return null; |
|
691 | + }, |
|
692 | + 'EE_Template_Config' => function () { |
|
693 | + return EE_Config::instance()->template_settings; |
|
694 | + }, |
|
695 | + 'EE_Currency_Config' => function () { |
|
696 | + return EE_Config::instance()->currency; |
|
697 | + }, |
|
698 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
699 | + return $loader; |
|
700 | + }, |
|
701 | + ); |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * can be used for supplying alternate names for classes, |
|
708 | + * or for connecting interface names to instantiable classes |
|
709 | + */ |
|
710 | + protected function _register_core_aliases() |
|
711 | + { |
|
712 | + $this->_aliases = array( |
|
713 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
714 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
715 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
716 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
717 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
718 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
719 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
720 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
721 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
722 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
723 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
724 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
725 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
726 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
727 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
728 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
729 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
730 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
731 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
732 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
733 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
734 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
735 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
736 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
737 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
738 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
739 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
740 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
741 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
742 | + ); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
749 | + * request Primarily used by unit tests. |
|
750 | + */ |
|
751 | + public function reset() |
|
752 | + { |
|
753 | + $this->_register_core_class_loaders(); |
|
754 | + $this->_register_core_dependencies(); |
|
755 | + } |
|
756 | 756 | |
757 | 757 | |
758 | 758 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
130 | 130 | { |
131 | 131 | // check if class object is instantiated, and instantiated properly |
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | 133 | self::$_instance = new EE_Dependency_Map($request, $response); |
134 | 134 | } |
135 | 135 | return self::$_instance; |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
184 | 184 | ) { |
185 | 185 | $registered = false; |
186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
186 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
187 | + self::$_instance->_dependency_map[$class] = array(); |
|
188 | 188 | } |
189 | 189 | // we need to make sure that any aliases used when registering a dependency |
190 | 190 | // get resolved to the correct class name |
191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
191 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
192 | 192 | $alias = self::$_instance->get_alias($dependency); |
193 | 193 | if ( |
194 | 194 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
195 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
196 | 196 | ) { |
197 | 197 | unset($dependencies[$dependency]); |
198 | 198 | $dependencies[$alias] = $load_source; |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
206 | 206 | // Union is way faster than array_merge() but should be used with caution... |
207 | 207 | // especially with numerically indexed arrays |
208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
208 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
209 | 209 | // now we need to ensure that the resulting dependencies |
210 | 210 | // array only has the entries that are required for the class |
211 | 211 | // so first count how many dependencies were originally registered for the class |
212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
212 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
213 | 213 | // if that count is non-zero (meaning dependencies were already registered) |
214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
214 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
215 | 215 | // then truncate the final array to match that count |
216 | 216 | ? array_slice($dependencies, 0, $dependency_count) |
217 | 217 | // otherwise just take the incoming array because nothing previously existed |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | ); |
254 | 254 | } |
255 | 255 | $class_name = self::$_instance->get_alias($class_name); |
256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
256 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | 257 | self::$_instance->_class_loaders[$class_name] = $loader; |
258 | 258 | return true; |
259 | 259 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | public function class_loader($class_name) |
327 | 327 | { |
328 | 328 | // don't use loaders for FQCNs |
329 | - if(strpos($class_name, '\\') !== false){ |
|
329 | + if (strpos($class_name, '\\') !== false) { |
|
330 | 330 | return ''; |
331 | 331 | } |
332 | 332 | $class_name = $this->get_alias($class_name); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | public function add_alias($class_name, $alias, $for_class = '') |
356 | 356 | { |
357 | 357 | if ($for_class !== '') { |
358 | - if (! isset($this->_aliases[$for_class])) { |
|
358 | + if ( ! isset($this->_aliases[$for_class])) { |
|
359 | 359 | $this->_aliases[$for_class] = array(); |
360 | 360 | } |
361 | 361 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -401,10 +401,10 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function get_alias($class_name = '', $for_class = '') |
403 | 403 | { |
404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
404 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
405 | 405 | return $class_name; |
406 | 406 | } |
407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
407 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
408 | 408 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
409 | 409 | } |
410 | 410 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -641,10 +641,10 @@ discard block |
||
641 | 641 | 'EE_Front_Controller' => 'load_core', |
642 | 642 | 'EE_Module_Request_Router' => 'load_core', |
643 | 643 | 'EE_Registry' => 'load_core', |
644 | - 'EE_Request' => function () use (&$request) { |
|
644 | + 'EE_Request' => function() use (&$request) { |
|
645 | 645 | return $request; |
646 | 646 | }, |
647 | - 'EE_Response' => function () use (&$response) { |
|
647 | + 'EE_Response' => function() use (&$response) { |
|
648 | 648 | return $response; |
649 | 649 | }, |
650 | 650 | 'EE_Request_Handler' => 'load_core', |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | 'EE_Messages_Queue' => 'load_lib', |
664 | 664 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
665 | 665 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
666 | - 'EE_Messages_Generator' => function () { |
|
666 | + 'EE_Messages_Generator' => function() { |
|
667 | 667 | return EE_Registry::instance()->load_lib( |
668 | 668 | 'Messages_Generator', |
669 | 669 | array(), |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | false |
672 | 672 | ); |
673 | 673 | }, |
674 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
674 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
675 | 675 | return EE_Registry::instance()->load_lib( |
676 | 676 | 'Messages_Template_Defaults', |
677 | 677 | $arguments, |
@@ -683,19 +683,19 @@ discard block |
||
683 | 683 | 'EEM_Message_Template_Group' => 'load_model', |
684 | 684 | 'EEM_Message_Template' => 'load_model', |
685 | 685 | //load_helper |
686 | - 'EEH_Parse_Shortcodes' => function () { |
|
686 | + 'EEH_Parse_Shortcodes' => function() { |
|
687 | 687 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
688 | 688 | return new EEH_Parse_Shortcodes(); |
689 | 689 | } |
690 | 690 | return null; |
691 | 691 | }, |
692 | - 'EE_Template_Config' => function () { |
|
692 | + 'EE_Template_Config' => function() { |
|
693 | 693 | return EE_Config::instance()->template_settings; |
694 | 694 | }, |
695 | - 'EE_Currency_Config' => function () { |
|
695 | + 'EE_Currency_Config' => function() { |
|
696 | 696 | return EE_Config::instance()->currency; |
697 | 697 | }, |
698 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
698 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
699 | 699 | return $loader; |
700 | 700 | }, |
701 | 701 | ); |
@@ -34,139 +34,139 @@ |
||
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * the actual shortcode tag that gets registered with WordPress |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getTag() |
|
43 | - { |
|
44 | - return 'ESPRESSO_EVENTS'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * the time in seconds to cache the results of the processShortcode() method |
|
51 | - * 0 means the processShortcode() results will NOT be cached at all |
|
52 | - * |
|
53 | - * @return int |
|
54 | - */ |
|
55 | - public function cacheExpiration() |
|
56 | - { |
|
57 | - return 0; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | - * this may be required for shortcodes that utilize a corresponding module, |
|
65 | - * and need to enqueue assets for that module |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function initializeShortcode() |
|
70 | - { |
|
71 | - EED_Events_Archive::instance()->event_list(); |
|
72 | - $this->shortcodeHasBeenInitialized(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * callback that runs when the shortcode is encountered in post content. |
|
79 | - * IMPORTANT !!! |
|
80 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | - * |
|
82 | - * @param array $attributes |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function processShortcode($attributes = array()) |
|
86 | - { |
|
87 | - // grab attributes and merge with defaults |
|
88 | - $attributes = $this->getAttributes($attributes); |
|
89 | - // make sure we use the_excerpt() |
|
90 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | - // apply query filters |
|
92 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | - // run the query |
|
94 | - global $wp_query; |
|
95 | - // yes we have to overwrite the main wp query, but it's ok... |
|
96 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | - $wp_query = new EventListQuery($attributes); |
|
98 | - // check what template is loaded and load filters accordingly |
|
99 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | - // load our template |
|
101 | - $event_list = EEH_Template::locate_template( |
|
102 | - 'loop-espresso_events.php', |
|
103 | - array(), |
|
104 | - true, |
|
105 | - true |
|
106 | - ); |
|
107 | - // now reset the query and post data |
|
108 | - wp_reset_query(); |
|
109 | - wp_reset_postdata(); |
|
110 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | - // remove query filters |
|
112 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | - // pull our content from the output buffer and return it |
|
114 | - return $event_list; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * merge incoming attributes with filtered defaults |
|
121 | - * |
|
122 | - * @param array $attributes |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - private function getAttributes(array $attributes) |
|
126 | - { |
|
127 | - return array_merge( |
|
128 | - (array)apply_filters( |
|
129 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | - array( |
|
131 | - 'title' => '', |
|
132 | - 'limit' => 10, |
|
133 | - 'css_class' => '', |
|
134 | - 'show_expired' => false, |
|
135 | - 'month' => '', |
|
136 | - 'category_slug' => '', |
|
137 | - 'order_by' => 'start_date', |
|
138 | - 'sort' => 'ASC', |
|
139 | - 'show_title' => true, |
|
140 | - ) |
|
141 | - ), |
|
142 | - $attributes |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * array for defining custom attribute sanitization callbacks, |
|
150 | - * where keys match keys in your attributes array, |
|
151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | - * So for example, if you had an integer attribute named "event_id" |
|
153 | - * that you wanted to be sanitized using absint(), |
|
154 | - * then you would pass the following for your $custom_sanitization array: |
|
155 | - * array('event_id' => 'absint') |
|
156 | - * |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - protected function customAttributeSanitizationMap() |
|
160 | - { |
|
161 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | - return array( |
|
163 | - 'category_slug' => 'skip_sanitization', |
|
164 | - 'show_expired' => 'skip_sanitization', |
|
165 | - 'order_by' => 'skip_sanitization', |
|
166 | - 'month' => 'skip_sanitization', |
|
167 | - 'sort' => 'skip_sanitization', |
|
168 | - ); |
|
169 | - } |
|
37 | + /** |
|
38 | + * the actual shortcode tag that gets registered with WordPress |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getTag() |
|
43 | + { |
|
44 | + return 'ESPRESSO_EVENTS'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * the time in seconds to cache the results of the processShortcode() method |
|
51 | + * 0 means the processShortcode() results will NOT be cached at all |
|
52 | + * |
|
53 | + * @return int |
|
54 | + */ |
|
55 | + public function cacheExpiration() |
|
56 | + { |
|
57 | + return 0; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | + * this may be required for shortcodes that utilize a corresponding module, |
|
65 | + * and need to enqueue assets for that module |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function initializeShortcode() |
|
70 | + { |
|
71 | + EED_Events_Archive::instance()->event_list(); |
|
72 | + $this->shortcodeHasBeenInitialized(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * callback that runs when the shortcode is encountered in post content. |
|
79 | + * IMPORTANT !!! |
|
80 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | + * |
|
82 | + * @param array $attributes |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function processShortcode($attributes = array()) |
|
86 | + { |
|
87 | + // grab attributes and merge with defaults |
|
88 | + $attributes = $this->getAttributes($attributes); |
|
89 | + // make sure we use the_excerpt() |
|
90 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | + // apply query filters |
|
92 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | + // run the query |
|
94 | + global $wp_query; |
|
95 | + // yes we have to overwrite the main wp query, but it's ok... |
|
96 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | + $wp_query = new EventListQuery($attributes); |
|
98 | + // check what template is loaded and load filters accordingly |
|
99 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | + // load our template |
|
101 | + $event_list = EEH_Template::locate_template( |
|
102 | + 'loop-espresso_events.php', |
|
103 | + array(), |
|
104 | + true, |
|
105 | + true |
|
106 | + ); |
|
107 | + // now reset the query and post data |
|
108 | + wp_reset_query(); |
|
109 | + wp_reset_postdata(); |
|
110 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | + // remove query filters |
|
112 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | + // pull our content from the output buffer and return it |
|
114 | + return $event_list; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * merge incoming attributes with filtered defaults |
|
121 | + * |
|
122 | + * @param array $attributes |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + private function getAttributes(array $attributes) |
|
126 | + { |
|
127 | + return array_merge( |
|
128 | + (array)apply_filters( |
|
129 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | + array( |
|
131 | + 'title' => '', |
|
132 | + 'limit' => 10, |
|
133 | + 'css_class' => '', |
|
134 | + 'show_expired' => false, |
|
135 | + 'month' => '', |
|
136 | + 'category_slug' => '', |
|
137 | + 'order_by' => 'start_date', |
|
138 | + 'sort' => 'ASC', |
|
139 | + 'show_title' => true, |
|
140 | + ) |
|
141 | + ), |
|
142 | + $attributes |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * array for defining custom attribute sanitization callbacks, |
|
150 | + * where keys match keys in your attributes array, |
|
151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | + * So for example, if you had an integer attribute named "event_id" |
|
153 | + * that you wanted to be sanitized using absint(), |
|
154 | + * then you would pass the following for your $custom_sanitization array: |
|
155 | + * array('event_id' => 'absint') |
|
156 | + * |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + protected function customAttributeSanitizationMap() |
|
160 | + { |
|
161 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | + return array( |
|
163 | + 'category_slug' => 'skip_sanitization', |
|
164 | + 'show_expired' => 'skip_sanitization', |
|
165 | + 'order_by' => 'skip_sanitization', |
|
166 | + 'month' => 'skip_sanitization', |
|
167 | + 'sort' => 'skip_sanitization', |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | 172 |