@@ -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,1445 +21,1445 @@ 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 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
957 | - // load_espresso_template_tags |
|
958 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
959 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
960 | - } |
|
961 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
962 | - $this->loader->getShared('EE_Session'); |
|
963 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
964 | - wp_enqueue_script('espresso_core'); |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - |
|
969 | - /** |
|
970 | - * initialize |
|
971 | - * this is the best place to begin initializing client code |
|
972 | - * |
|
973 | - * @access public |
|
974 | - * @return void |
|
975 | - */ |
|
976 | - public function initialize() |
|
977 | - { |
|
978 | - do_action('AHEE__EE_System__initialize'); |
|
979 | - } |
|
980 | - |
|
981 | - |
|
982 | - |
|
983 | - /** |
|
984 | - * initialize_last |
|
985 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
986 | - * initialize has done so |
|
987 | - * |
|
988 | - * @access public |
|
989 | - * @return void |
|
990 | - */ |
|
991 | - public function initialize_last() |
|
992 | - { |
|
993 | - do_action('AHEE__EE_System__initialize_last'); |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * set_hooks_for_shortcodes_modules_and_addons |
|
1000 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1001 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
1002 | - * |
|
1003 | - * @access public |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
1007 | - { |
|
1008 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * do_not_cache |
|
1015 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1016 | - * |
|
1017 | - * @access public |
|
1018 | - * @return void |
|
1019 | - */ |
|
1020 | - public static function do_not_cache() |
|
1021 | - { |
|
1022 | - // set no cache constants |
|
1023 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
1024 | - define('DONOTCACHEPAGE', true); |
|
1025 | - } |
|
1026 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1027 | - define('DONOTCACHCEOBJECT', true); |
|
1028 | - } |
|
1029 | - if ( ! defined('DONOTCACHEDB')) { |
|
1030 | - define('DONOTCACHEDB', true); |
|
1031 | - } |
|
1032 | - // add no cache headers |
|
1033 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1034 | - // plus a little extra for nginx and Google Chrome |
|
1035 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1036 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1037 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1038 | - } |
|
1039 | - |
|
1040 | - |
|
1041 | - |
|
1042 | - /** |
|
1043 | - * extra_nocache_headers |
|
1044 | - * |
|
1045 | - * @access public |
|
1046 | - * @param $headers |
|
1047 | - * @return array |
|
1048 | - */ |
|
1049 | - public static function extra_nocache_headers($headers) |
|
1050 | - { |
|
1051 | - // for NGINX |
|
1052 | - $headers['X-Accel-Expires'] = 0; |
|
1053 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1054 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1055 | - return $headers; |
|
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * nocache_headers |
|
1062 | - * |
|
1063 | - * @access public |
|
1064 | - * @return void |
|
1065 | - */ |
|
1066 | - public static function nocache_headers() |
|
1067 | - { |
|
1068 | - nocache_headers(); |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * espresso_toolbar_items |
|
1075 | - * |
|
1076 | - * @access public |
|
1077 | - * @param WP_Admin_Bar $admin_bar |
|
1078 | - * @return void |
|
1079 | - */ |
|
1080 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1081 | - { |
|
1082 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1083 | - if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1084 | - || defined('DOING_AJAX') |
|
1085 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1086 | - ) { |
|
1087 | - return; |
|
1088 | - } |
|
1089 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1090 | - $menu_class = 'espresso_menu_item_class'; |
|
1091 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1092 | - //because they're only defined in each of their respective constructors |
|
1093 | - //and this might be a frontend request, in which case they aren't available |
|
1094 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1095 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1096 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1097 | - //Top Level |
|
1098 | - $admin_bar->add_menu(array( |
|
1099 | - 'id' => 'espresso-toolbar', |
|
1100 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1101 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1102 | - . '</span>', |
|
1103 | - 'href' => $events_admin_url, |
|
1104 | - 'meta' => array( |
|
1105 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1106 | - 'class' => $menu_class . 'first', |
|
1107 | - ), |
|
1108 | - )); |
|
1109 | - //Events |
|
1110 | - if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1111 | - $admin_bar->add_menu(array( |
|
1112 | - 'id' => 'espresso-toolbar-events', |
|
1113 | - 'parent' => 'espresso-toolbar', |
|
1114 | - 'title' => __('Events', 'event_espresso'), |
|
1115 | - 'href' => $events_admin_url, |
|
1116 | - 'meta' => array( |
|
1117 | - 'title' => __('Events', 'event_espresso'), |
|
1118 | - 'target' => '', |
|
1119 | - 'class' => $menu_class, |
|
1120 | - ), |
|
1121 | - )); |
|
1122 | - } |
|
1123 | - if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1124 | - //Events Add New |
|
1125 | - $admin_bar->add_menu(array( |
|
1126 | - 'id' => 'espresso-toolbar-events-new', |
|
1127 | - 'parent' => 'espresso-toolbar-events', |
|
1128 | - 'title' => __('Add New', 'event_espresso'), |
|
1129 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1130 | - 'meta' => array( |
|
1131 | - 'title' => __('Add New', 'event_espresso'), |
|
1132 | - 'target' => '', |
|
1133 | - 'class' => $menu_class, |
|
1134 | - ), |
|
1135 | - )); |
|
1136 | - } |
|
1137 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1138 | - //Current post |
|
1139 | - global $post; |
|
1140 | - if ($this->capabilities->current_user_can('ee_edit_event', |
|
1141 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1142 | - ) { |
|
1143 | - //Events Edit Current Event |
|
1144 | - $admin_bar->add_menu(array( |
|
1145 | - 'id' => 'espresso-toolbar-events-edit', |
|
1146 | - 'parent' => 'espresso-toolbar-events', |
|
1147 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1148 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1149 | - $events_admin_url), |
|
1150 | - 'meta' => array( |
|
1151 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1152 | - 'target' => '', |
|
1153 | - 'class' => $menu_class, |
|
1154 | - ), |
|
1155 | - )); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - //Events View |
|
1159 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1160 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1161 | - ) { |
|
1162 | - $admin_bar->add_menu(array( |
|
1163 | - 'id' => 'espresso-toolbar-events-view', |
|
1164 | - 'parent' => 'espresso-toolbar-events', |
|
1165 | - 'title' => __('View', 'event_espresso'), |
|
1166 | - 'href' => $events_admin_url, |
|
1167 | - 'meta' => array( |
|
1168 | - 'title' => __('View', 'event_espresso'), |
|
1169 | - 'target' => '', |
|
1170 | - 'class' => $menu_class, |
|
1171 | - ), |
|
1172 | - )); |
|
1173 | - } |
|
1174 | - if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1175 | - //Events View All |
|
1176 | - $admin_bar->add_menu(array( |
|
1177 | - 'id' => 'espresso-toolbar-events-all', |
|
1178 | - 'parent' => 'espresso-toolbar-events-view', |
|
1179 | - 'title' => __('All', 'event_espresso'), |
|
1180 | - 'href' => $events_admin_url, |
|
1181 | - 'meta' => array( |
|
1182 | - 'title' => __('All', 'event_espresso'), |
|
1183 | - 'target' => '', |
|
1184 | - 'class' => $menu_class, |
|
1185 | - ), |
|
1186 | - )); |
|
1187 | - } |
|
1188 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1189 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1190 | - ) { |
|
1191 | - //Events View Today |
|
1192 | - $admin_bar->add_menu(array( |
|
1193 | - 'id' => 'espresso-toolbar-events-today', |
|
1194 | - 'parent' => 'espresso-toolbar-events-view', |
|
1195 | - 'title' => __('Today', 'event_espresso'), |
|
1196 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1197 | - $events_admin_url), |
|
1198 | - 'meta' => array( |
|
1199 | - 'title' => __('Today', 'event_espresso'), |
|
1200 | - 'target' => '', |
|
1201 | - 'class' => $menu_class, |
|
1202 | - ), |
|
1203 | - )); |
|
1204 | - } |
|
1205 | - if ($this->capabilities->current_user_can('ee_read_events', |
|
1206 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1207 | - ) { |
|
1208 | - //Events View This Month |
|
1209 | - $admin_bar->add_menu(array( |
|
1210 | - 'id' => 'espresso-toolbar-events-month', |
|
1211 | - 'parent' => 'espresso-toolbar-events-view', |
|
1212 | - 'title' => __('This Month', 'event_espresso'), |
|
1213 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1214 | - $events_admin_url), |
|
1215 | - 'meta' => array( |
|
1216 | - 'title' => __('This Month', 'event_espresso'), |
|
1217 | - 'target' => '', |
|
1218 | - 'class' => $menu_class, |
|
1219 | - ), |
|
1220 | - )); |
|
1221 | - } |
|
1222 | - //Registration Overview |
|
1223 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1224 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1225 | - ) { |
|
1226 | - $admin_bar->add_menu(array( |
|
1227 | - 'id' => 'espresso-toolbar-registrations', |
|
1228 | - 'parent' => 'espresso-toolbar', |
|
1229 | - 'title' => __('Registrations', 'event_espresso'), |
|
1230 | - 'href' => $reg_admin_url, |
|
1231 | - 'meta' => array( |
|
1232 | - 'title' => __('Registrations', 'event_espresso'), |
|
1233 | - 'target' => '', |
|
1234 | - 'class' => $menu_class, |
|
1235 | - ), |
|
1236 | - )); |
|
1237 | - } |
|
1238 | - //Registration Overview Today |
|
1239 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1240 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1241 | - ) { |
|
1242 | - $admin_bar->add_menu(array( |
|
1243 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1244 | - 'parent' => 'espresso-toolbar-registrations', |
|
1245 | - 'title' => __('Today', 'event_espresso'), |
|
1246 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1247 | - $reg_admin_url), |
|
1248 | - 'meta' => array( |
|
1249 | - 'title' => __('Today', 'event_espresso'), |
|
1250 | - 'target' => '', |
|
1251 | - 'class' => $menu_class, |
|
1252 | - ), |
|
1253 | - )); |
|
1254 | - } |
|
1255 | - //Registration Overview Today Completed |
|
1256 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1257 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1258 | - ) { |
|
1259 | - $admin_bar->add_menu(array( |
|
1260 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1261 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1262 | - 'title' => __('Approved', 'event_espresso'), |
|
1263 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1264 | - 'action' => 'default', |
|
1265 | - 'status' => 'today', |
|
1266 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1267 | - ), $reg_admin_url), |
|
1268 | - 'meta' => array( |
|
1269 | - 'title' => __('Approved', 'event_espresso'), |
|
1270 | - 'target' => '', |
|
1271 | - 'class' => $menu_class, |
|
1272 | - ), |
|
1273 | - )); |
|
1274 | - } |
|
1275 | - //Registration Overview Today Pending\ |
|
1276 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1277 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1278 | - ) { |
|
1279 | - $admin_bar->add_menu(array( |
|
1280 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1281 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1282 | - 'title' => __('Pending', 'event_espresso'), |
|
1283 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1284 | - 'action' => 'default', |
|
1285 | - 'status' => 'today', |
|
1286 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1287 | - ), $reg_admin_url), |
|
1288 | - 'meta' => array( |
|
1289 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1290 | - 'target' => '', |
|
1291 | - 'class' => $menu_class, |
|
1292 | - ), |
|
1293 | - )); |
|
1294 | - } |
|
1295 | - //Registration Overview Today Incomplete |
|
1296 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1297 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1298 | - ) { |
|
1299 | - $admin_bar->add_menu(array( |
|
1300 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1301 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1302 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1303 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1304 | - 'action' => 'default', |
|
1305 | - 'status' => 'today', |
|
1306 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1307 | - ), $reg_admin_url), |
|
1308 | - 'meta' => array( |
|
1309 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1310 | - 'target' => '', |
|
1311 | - 'class' => $menu_class, |
|
1312 | - ), |
|
1313 | - )); |
|
1314 | - } |
|
1315 | - //Registration Overview Today Incomplete |
|
1316 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1317 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1318 | - ) { |
|
1319 | - $admin_bar->add_menu(array( |
|
1320 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1321 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1322 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1323 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1324 | - 'action' => 'default', |
|
1325 | - 'status' => 'today', |
|
1326 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1327 | - ), $reg_admin_url), |
|
1328 | - 'meta' => array( |
|
1329 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1330 | - 'target' => '', |
|
1331 | - 'class' => $menu_class, |
|
1332 | - ), |
|
1333 | - )); |
|
1334 | - } |
|
1335 | - //Registration Overview This Month |
|
1336 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1337 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1338 | - ) { |
|
1339 | - $admin_bar->add_menu(array( |
|
1340 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1341 | - 'parent' => 'espresso-toolbar-registrations', |
|
1342 | - 'title' => __('This Month', 'event_espresso'), |
|
1343 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1344 | - $reg_admin_url), |
|
1345 | - 'meta' => array( |
|
1346 | - 'title' => __('This Month', 'event_espresso'), |
|
1347 | - 'target' => '', |
|
1348 | - 'class' => $menu_class, |
|
1349 | - ), |
|
1350 | - )); |
|
1351 | - } |
|
1352 | - //Registration Overview This Month Approved |
|
1353 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1354 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1355 | - ) { |
|
1356 | - $admin_bar->add_menu(array( |
|
1357 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1358 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1359 | - 'title' => __('Approved', 'event_espresso'), |
|
1360 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1361 | - 'action' => 'default', |
|
1362 | - 'status' => 'month', |
|
1363 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1364 | - ), $reg_admin_url), |
|
1365 | - 'meta' => array( |
|
1366 | - 'title' => __('Approved', 'event_espresso'), |
|
1367 | - 'target' => '', |
|
1368 | - 'class' => $menu_class, |
|
1369 | - ), |
|
1370 | - )); |
|
1371 | - } |
|
1372 | - //Registration Overview This Month Pending |
|
1373 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1374 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1375 | - ) { |
|
1376 | - $admin_bar->add_menu(array( |
|
1377 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1378 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1379 | - 'title' => __('Pending', 'event_espresso'), |
|
1380 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1381 | - 'action' => 'default', |
|
1382 | - 'status' => 'month', |
|
1383 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1384 | - ), $reg_admin_url), |
|
1385 | - 'meta' => array( |
|
1386 | - 'title' => __('Pending', 'event_espresso'), |
|
1387 | - 'target' => '', |
|
1388 | - 'class' => $menu_class, |
|
1389 | - ), |
|
1390 | - )); |
|
1391 | - } |
|
1392 | - //Registration Overview This Month Not Approved |
|
1393 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1394 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1395 | - ) { |
|
1396 | - $admin_bar->add_menu(array( |
|
1397 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1398 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1399 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1400 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1401 | - 'action' => 'default', |
|
1402 | - 'status' => 'month', |
|
1403 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1404 | - ), $reg_admin_url), |
|
1405 | - 'meta' => array( |
|
1406 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1407 | - 'target' => '', |
|
1408 | - 'class' => $menu_class, |
|
1409 | - ), |
|
1410 | - )); |
|
1411 | - } |
|
1412 | - //Registration Overview This Month Cancelled |
|
1413 | - if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1414 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1415 | - ) { |
|
1416 | - $admin_bar->add_menu(array( |
|
1417 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1418 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1419 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1420 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1421 | - 'action' => 'default', |
|
1422 | - 'status' => 'month', |
|
1423 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1424 | - ), $reg_admin_url), |
|
1425 | - 'meta' => array( |
|
1426 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1427 | - 'target' => '', |
|
1428 | - 'class' => $menu_class, |
|
1429 | - ), |
|
1430 | - )); |
|
1431 | - } |
|
1432 | - //Extensions & Services |
|
1433 | - if ($this->capabilities->current_user_can('ee_read_ee', |
|
1434 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1435 | - ) { |
|
1436 | - $admin_bar->add_menu(array( |
|
1437 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1438 | - 'parent' => 'espresso-toolbar', |
|
1439 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1440 | - 'href' => $extensions_admin_url, |
|
1441 | - 'meta' => array( |
|
1442 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1443 | - 'target' => '', |
|
1444 | - 'class' => $menu_class, |
|
1445 | - ), |
|
1446 | - )); |
|
1447 | - } |
|
1448 | - } |
|
1449 | - |
|
1450 | - |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1454 | - * never returned with the function. |
|
1455 | - * |
|
1456 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1457 | - * @return array |
|
1458 | - */ |
|
1459 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1460 | - { |
|
1461 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1462 | - } |
|
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 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
957 | + // load_espresso_template_tags |
|
958 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
959 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
960 | + } |
|
961 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
962 | + $this->loader->getShared('EE_Session'); |
|
963 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
964 | + wp_enqueue_script('espresso_core'); |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + |
|
969 | + /** |
|
970 | + * initialize |
|
971 | + * this is the best place to begin initializing client code |
|
972 | + * |
|
973 | + * @access public |
|
974 | + * @return void |
|
975 | + */ |
|
976 | + public function initialize() |
|
977 | + { |
|
978 | + do_action('AHEE__EE_System__initialize'); |
|
979 | + } |
|
980 | + |
|
981 | + |
|
982 | + |
|
983 | + /** |
|
984 | + * initialize_last |
|
985 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
986 | + * initialize has done so |
|
987 | + * |
|
988 | + * @access public |
|
989 | + * @return void |
|
990 | + */ |
|
991 | + public function initialize_last() |
|
992 | + { |
|
993 | + do_action('AHEE__EE_System__initialize_last'); |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * set_hooks_for_shortcodes_modules_and_addons |
|
1000 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1001 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
1002 | + * |
|
1003 | + * @access public |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
1007 | + { |
|
1008 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * do_not_cache |
|
1015 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1016 | + * |
|
1017 | + * @access public |
|
1018 | + * @return void |
|
1019 | + */ |
|
1020 | + public static function do_not_cache() |
|
1021 | + { |
|
1022 | + // set no cache constants |
|
1023 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1024 | + define('DONOTCACHEPAGE', true); |
|
1025 | + } |
|
1026 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1027 | + define('DONOTCACHCEOBJECT', true); |
|
1028 | + } |
|
1029 | + if ( ! defined('DONOTCACHEDB')) { |
|
1030 | + define('DONOTCACHEDB', true); |
|
1031 | + } |
|
1032 | + // add no cache headers |
|
1033 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1034 | + // plus a little extra for nginx and Google Chrome |
|
1035 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1036 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1037 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1038 | + } |
|
1039 | + |
|
1040 | + |
|
1041 | + |
|
1042 | + /** |
|
1043 | + * extra_nocache_headers |
|
1044 | + * |
|
1045 | + * @access public |
|
1046 | + * @param $headers |
|
1047 | + * @return array |
|
1048 | + */ |
|
1049 | + public static function extra_nocache_headers($headers) |
|
1050 | + { |
|
1051 | + // for NGINX |
|
1052 | + $headers['X-Accel-Expires'] = 0; |
|
1053 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1054 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1055 | + return $headers; |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * nocache_headers |
|
1062 | + * |
|
1063 | + * @access public |
|
1064 | + * @return void |
|
1065 | + */ |
|
1066 | + public static function nocache_headers() |
|
1067 | + { |
|
1068 | + nocache_headers(); |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * espresso_toolbar_items |
|
1075 | + * |
|
1076 | + * @access public |
|
1077 | + * @param WP_Admin_Bar $admin_bar |
|
1078 | + * @return void |
|
1079 | + */ |
|
1080 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1081 | + { |
|
1082 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1083 | + if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1084 | + || defined('DOING_AJAX') |
|
1085 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1086 | + ) { |
|
1087 | + return; |
|
1088 | + } |
|
1089 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1090 | + $menu_class = 'espresso_menu_item_class'; |
|
1091 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1092 | + //because they're only defined in each of their respective constructors |
|
1093 | + //and this might be a frontend request, in which case they aren't available |
|
1094 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1095 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1096 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1097 | + //Top Level |
|
1098 | + $admin_bar->add_menu(array( |
|
1099 | + 'id' => 'espresso-toolbar', |
|
1100 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1101 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1102 | + . '</span>', |
|
1103 | + 'href' => $events_admin_url, |
|
1104 | + 'meta' => array( |
|
1105 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1106 | + 'class' => $menu_class . 'first', |
|
1107 | + ), |
|
1108 | + )); |
|
1109 | + //Events |
|
1110 | + if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1111 | + $admin_bar->add_menu(array( |
|
1112 | + 'id' => 'espresso-toolbar-events', |
|
1113 | + 'parent' => 'espresso-toolbar', |
|
1114 | + 'title' => __('Events', 'event_espresso'), |
|
1115 | + 'href' => $events_admin_url, |
|
1116 | + 'meta' => array( |
|
1117 | + 'title' => __('Events', 'event_espresso'), |
|
1118 | + 'target' => '', |
|
1119 | + 'class' => $menu_class, |
|
1120 | + ), |
|
1121 | + )); |
|
1122 | + } |
|
1123 | + if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1124 | + //Events Add New |
|
1125 | + $admin_bar->add_menu(array( |
|
1126 | + 'id' => 'espresso-toolbar-events-new', |
|
1127 | + 'parent' => 'espresso-toolbar-events', |
|
1128 | + 'title' => __('Add New', 'event_espresso'), |
|
1129 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1130 | + 'meta' => array( |
|
1131 | + 'title' => __('Add New', 'event_espresso'), |
|
1132 | + 'target' => '', |
|
1133 | + 'class' => $menu_class, |
|
1134 | + ), |
|
1135 | + )); |
|
1136 | + } |
|
1137 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1138 | + //Current post |
|
1139 | + global $post; |
|
1140 | + if ($this->capabilities->current_user_can('ee_edit_event', |
|
1141 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1142 | + ) { |
|
1143 | + //Events Edit Current Event |
|
1144 | + $admin_bar->add_menu(array( |
|
1145 | + 'id' => 'espresso-toolbar-events-edit', |
|
1146 | + 'parent' => 'espresso-toolbar-events', |
|
1147 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1148 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1149 | + $events_admin_url), |
|
1150 | + 'meta' => array( |
|
1151 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1152 | + 'target' => '', |
|
1153 | + 'class' => $menu_class, |
|
1154 | + ), |
|
1155 | + )); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + //Events View |
|
1159 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1160 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1161 | + ) { |
|
1162 | + $admin_bar->add_menu(array( |
|
1163 | + 'id' => 'espresso-toolbar-events-view', |
|
1164 | + 'parent' => 'espresso-toolbar-events', |
|
1165 | + 'title' => __('View', 'event_espresso'), |
|
1166 | + 'href' => $events_admin_url, |
|
1167 | + 'meta' => array( |
|
1168 | + 'title' => __('View', 'event_espresso'), |
|
1169 | + 'target' => '', |
|
1170 | + 'class' => $menu_class, |
|
1171 | + ), |
|
1172 | + )); |
|
1173 | + } |
|
1174 | + if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1175 | + //Events View All |
|
1176 | + $admin_bar->add_menu(array( |
|
1177 | + 'id' => 'espresso-toolbar-events-all', |
|
1178 | + 'parent' => 'espresso-toolbar-events-view', |
|
1179 | + 'title' => __('All', 'event_espresso'), |
|
1180 | + 'href' => $events_admin_url, |
|
1181 | + 'meta' => array( |
|
1182 | + 'title' => __('All', 'event_espresso'), |
|
1183 | + 'target' => '', |
|
1184 | + 'class' => $menu_class, |
|
1185 | + ), |
|
1186 | + )); |
|
1187 | + } |
|
1188 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1189 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1190 | + ) { |
|
1191 | + //Events View Today |
|
1192 | + $admin_bar->add_menu(array( |
|
1193 | + 'id' => 'espresso-toolbar-events-today', |
|
1194 | + 'parent' => 'espresso-toolbar-events-view', |
|
1195 | + 'title' => __('Today', 'event_espresso'), |
|
1196 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1197 | + $events_admin_url), |
|
1198 | + 'meta' => array( |
|
1199 | + 'title' => __('Today', 'event_espresso'), |
|
1200 | + 'target' => '', |
|
1201 | + 'class' => $menu_class, |
|
1202 | + ), |
|
1203 | + )); |
|
1204 | + } |
|
1205 | + if ($this->capabilities->current_user_can('ee_read_events', |
|
1206 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1207 | + ) { |
|
1208 | + //Events View This Month |
|
1209 | + $admin_bar->add_menu(array( |
|
1210 | + 'id' => 'espresso-toolbar-events-month', |
|
1211 | + 'parent' => 'espresso-toolbar-events-view', |
|
1212 | + 'title' => __('This Month', 'event_espresso'), |
|
1213 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1214 | + $events_admin_url), |
|
1215 | + 'meta' => array( |
|
1216 | + 'title' => __('This Month', 'event_espresso'), |
|
1217 | + 'target' => '', |
|
1218 | + 'class' => $menu_class, |
|
1219 | + ), |
|
1220 | + )); |
|
1221 | + } |
|
1222 | + //Registration Overview |
|
1223 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1224 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1225 | + ) { |
|
1226 | + $admin_bar->add_menu(array( |
|
1227 | + 'id' => 'espresso-toolbar-registrations', |
|
1228 | + 'parent' => 'espresso-toolbar', |
|
1229 | + 'title' => __('Registrations', 'event_espresso'), |
|
1230 | + 'href' => $reg_admin_url, |
|
1231 | + 'meta' => array( |
|
1232 | + 'title' => __('Registrations', 'event_espresso'), |
|
1233 | + 'target' => '', |
|
1234 | + 'class' => $menu_class, |
|
1235 | + ), |
|
1236 | + )); |
|
1237 | + } |
|
1238 | + //Registration Overview Today |
|
1239 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1240 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1241 | + ) { |
|
1242 | + $admin_bar->add_menu(array( |
|
1243 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1244 | + 'parent' => 'espresso-toolbar-registrations', |
|
1245 | + 'title' => __('Today', 'event_espresso'), |
|
1246 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1247 | + $reg_admin_url), |
|
1248 | + 'meta' => array( |
|
1249 | + 'title' => __('Today', 'event_espresso'), |
|
1250 | + 'target' => '', |
|
1251 | + 'class' => $menu_class, |
|
1252 | + ), |
|
1253 | + )); |
|
1254 | + } |
|
1255 | + //Registration Overview Today Completed |
|
1256 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1257 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1258 | + ) { |
|
1259 | + $admin_bar->add_menu(array( |
|
1260 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1261 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1262 | + 'title' => __('Approved', 'event_espresso'), |
|
1263 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1264 | + 'action' => 'default', |
|
1265 | + 'status' => 'today', |
|
1266 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1267 | + ), $reg_admin_url), |
|
1268 | + 'meta' => array( |
|
1269 | + 'title' => __('Approved', 'event_espresso'), |
|
1270 | + 'target' => '', |
|
1271 | + 'class' => $menu_class, |
|
1272 | + ), |
|
1273 | + )); |
|
1274 | + } |
|
1275 | + //Registration Overview Today Pending\ |
|
1276 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1277 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1278 | + ) { |
|
1279 | + $admin_bar->add_menu(array( |
|
1280 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1281 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1282 | + 'title' => __('Pending', 'event_espresso'), |
|
1283 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1284 | + 'action' => 'default', |
|
1285 | + 'status' => 'today', |
|
1286 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1287 | + ), $reg_admin_url), |
|
1288 | + 'meta' => array( |
|
1289 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1290 | + 'target' => '', |
|
1291 | + 'class' => $menu_class, |
|
1292 | + ), |
|
1293 | + )); |
|
1294 | + } |
|
1295 | + //Registration Overview Today Incomplete |
|
1296 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1297 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1298 | + ) { |
|
1299 | + $admin_bar->add_menu(array( |
|
1300 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1301 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1302 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1303 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1304 | + 'action' => 'default', |
|
1305 | + 'status' => 'today', |
|
1306 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1307 | + ), $reg_admin_url), |
|
1308 | + 'meta' => array( |
|
1309 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1310 | + 'target' => '', |
|
1311 | + 'class' => $menu_class, |
|
1312 | + ), |
|
1313 | + )); |
|
1314 | + } |
|
1315 | + //Registration Overview Today Incomplete |
|
1316 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1317 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1318 | + ) { |
|
1319 | + $admin_bar->add_menu(array( |
|
1320 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1321 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1322 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1323 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1324 | + 'action' => 'default', |
|
1325 | + 'status' => 'today', |
|
1326 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1327 | + ), $reg_admin_url), |
|
1328 | + 'meta' => array( |
|
1329 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1330 | + 'target' => '', |
|
1331 | + 'class' => $menu_class, |
|
1332 | + ), |
|
1333 | + )); |
|
1334 | + } |
|
1335 | + //Registration Overview This Month |
|
1336 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1337 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1338 | + ) { |
|
1339 | + $admin_bar->add_menu(array( |
|
1340 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1341 | + 'parent' => 'espresso-toolbar-registrations', |
|
1342 | + 'title' => __('This Month', 'event_espresso'), |
|
1343 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1344 | + $reg_admin_url), |
|
1345 | + 'meta' => array( |
|
1346 | + 'title' => __('This Month', 'event_espresso'), |
|
1347 | + 'target' => '', |
|
1348 | + 'class' => $menu_class, |
|
1349 | + ), |
|
1350 | + )); |
|
1351 | + } |
|
1352 | + //Registration Overview This Month Approved |
|
1353 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1354 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1355 | + ) { |
|
1356 | + $admin_bar->add_menu(array( |
|
1357 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1358 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1359 | + 'title' => __('Approved', 'event_espresso'), |
|
1360 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1361 | + 'action' => 'default', |
|
1362 | + 'status' => 'month', |
|
1363 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1364 | + ), $reg_admin_url), |
|
1365 | + 'meta' => array( |
|
1366 | + 'title' => __('Approved', 'event_espresso'), |
|
1367 | + 'target' => '', |
|
1368 | + 'class' => $menu_class, |
|
1369 | + ), |
|
1370 | + )); |
|
1371 | + } |
|
1372 | + //Registration Overview This Month Pending |
|
1373 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1374 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1375 | + ) { |
|
1376 | + $admin_bar->add_menu(array( |
|
1377 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1378 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1379 | + 'title' => __('Pending', 'event_espresso'), |
|
1380 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1381 | + 'action' => 'default', |
|
1382 | + 'status' => 'month', |
|
1383 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1384 | + ), $reg_admin_url), |
|
1385 | + 'meta' => array( |
|
1386 | + 'title' => __('Pending', 'event_espresso'), |
|
1387 | + 'target' => '', |
|
1388 | + 'class' => $menu_class, |
|
1389 | + ), |
|
1390 | + )); |
|
1391 | + } |
|
1392 | + //Registration Overview This Month Not Approved |
|
1393 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1394 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1395 | + ) { |
|
1396 | + $admin_bar->add_menu(array( |
|
1397 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1398 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1399 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1400 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1401 | + 'action' => 'default', |
|
1402 | + 'status' => 'month', |
|
1403 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1404 | + ), $reg_admin_url), |
|
1405 | + 'meta' => array( |
|
1406 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1407 | + 'target' => '', |
|
1408 | + 'class' => $menu_class, |
|
1409 | + ), |
|
1410 | + )); |
|
1411 | + } |
|
1412 | + //Registration Overview This Month Cancelled |
|
1413 | + if ($this->capabilities->current_user_can('ee_read_registrations', |
|
1414 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1415 | + ) { |
|
1416 | + $admin_bar->add_menu(array( |
|
1417 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1418 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1419 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1420 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1421 | + 'action' => 'default', |
|
1422 | + 'status' => 'month', |
|
1423 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1424 | + ), $reg_admin_url), |
|
1425 | + 'meta' => array( |
|
1426 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1427 | + 'target' => '', |
|
1428 | + 'class' => $menu_class, |
|
1429 | + ), |
|
1430 | + )); |
|
1431 | + } |
|
1432 | + //Extensions & Services |
|
1433 | + if ($this->capabilities->current_user_can('ee_read_ee', |
|
1434 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1435 | + ) { |
|
1436 | + $admin_bar->add_menu(array( |
|
1437 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1438 | + 'parent' => 'espresso-toolbar', |
|
1439 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1440 | + 'href' => $extensions_admin_url, |
|
1441 | + 'meta' => array( |
|
1442 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1443 | + 'target' => '', |
|
1444 | + 'class' => $menu_class, |
|
1445 | + ), |
|
1446 | + )); |
|
1447 | + } |
|
1448 | + } |
|
1449 | + |
|
1450 | + |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1454 | + * never returned with the function. |
|
1455 | + * |
|
1456 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1457 | + * @return array |
|
1458 | + */ |
|
1459 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1460 | + { |
|
1461 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1462 | + } |
|
1463 | 1463 | |
1464 | 1464 | |
1465 | 1465 |
@@ -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.', |
@@ -955,8 +955,8 @@ discard block |
||
955 | 955 | { |
956 | 956 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
957 | 957 | // load_espresso_template_tags |
958 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
959 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
958 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
959 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
960 | 960 | } |
961 | 961 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
962 | 962 | $this->loader->getShared('EE_Session'); |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | 'href' => $events_admin_url, |
1104 | 1104 | 'meta' => array( |
1105 | 1105 | 'title' => __('Event Espresso', 'event_espresso'), |
1106 | - 'class' => $menu_class . 'first', |
|
1106 | + 'class' => $menu_class.'first', |
|
1107 | 1107 | ), |
1108 | 1108 | )); |
1109 | 1109 | //Events |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace EventEspresso\core\exceptions; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -18,32 +18,32 @@ discard block |
||
18 | 18 | class InvalidEntityException extends \InvalidArgumentException |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * InvalidInterfaceException constructor. |
|
23 | - * |
|
24 | - * @param string $actual classname of what we got |
|
25 | - * @param string $expected classname of the entity we wanted |
|
26 | - * @param string $message |
|
27 | - * @param int $code |
|
28 | - * @param \Exception $previous |
|
29 | - */ |
|
30 | - public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
31 | - { |
|
32 | - if (empty($message)) { |
|
33 | - $message = sprintf( |
|
34 | - __( |
|
35 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - is_object($actual) |
|
39 | - ? get_class($actual) |
|
40 | - : gettype($actual), |
|
41 | - $expected, |
|
42 | - var_export($actual, true) |
|
43 | - ); |
|
44 | - } |
|
45 | - parent::__construct($message, $code, $previous); |
|
46 | - } |
|
21 | + /** |
|
22 | + * InvalidInterfaceException constructor. |
|
23 | + * |
|
24 | + * @param string $actual classname of what we got |
|
25 | + * @param string $expected classname of the entity we wanted |
|
26 | + * @param string $message |
|
27 | + * @param int $code |
|
28 | + * @param \Exception $previous |
|
29 | + */ |
|
30 | + public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
31 | + { |
|
32 | + if (empty($message)) { |
|
33 | + $message = sprintf( |
|
34 | + __( |
|
35 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + is_object($actual) |
|
39 | + ? get_class($actual) |
|
40 | + : gettype($actual), |
|
41 | + $expected, |
|
42 | + var_export($actual, true) |
|
43 | + ); |
|
44 | + } |
|
45 | + parent::__construct($message, $code, $previous); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | // End of file InvalidEntityException.php |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace EventEspresso\core\exceptions; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('No direct script access allowed'); |
7 | 7 | } |
8 | 8 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -22,657 +22,657 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | - */ |
|
34 | - const load_new_object = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | - */ |
|
40 | - const load_from_cache = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Dependency_Map $_instance |
|
44 | - */ |
|
45 | - protected static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - protected $_request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @type EE_Response $response |
|
54 | - */ |
|
55 | - protected $_response; |
|
56 | - |
|
57 | - /** |
|
58 | - * @type LoaderInterface $loader |
|
59 | - */ |
|
60 | - protected $loader; |
|
61 | - |
|
62 | - /** |
|
63 | - * @type array $_dependency_map |
|
64 | - */ |
|
65 | - protected $_dependency_map = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @type array $_class_loaders |
|
69 | - */ |
|
70 | - protected $_class_loaders = array(); |
|
71 | - |
|
72 | - /** |
|
73 | - * @type array $_aliases |
|
74 | - */ |
|
75 | - protected $_aliases = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_Dependency_Map constructor. |
|
81 | - * |
|
82 | - * @param EE_Request $request |
|
83 | - * @param EE_Response $response |
|
84 | - */ |
|
85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | - { |
|
87 | - $this->_request = $request; |
|
88 | - $this->_response = $response; |
|
89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | - do_action('EE_Dependency_Map____construct'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidArgumentException |
|
99 | - */ |
|
100 | - public function initialize() |
|
101 | - { |
|
102 | - $this->_register_core_dependencies(); |
|
103 | - $this->_register_core_class_loaders(); |
|
104 | - $this->_register_core_aliases(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @singleton method used to instantiate class object |
|
111 | - * @access public |
|
112 | - * @param EE_Request $request |
|
113 | - * @param EE_Response $response |
|
114 | - * @return EE_Dependency_Map |
|
115 | - */ |
|
116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | - { |
|
118 | - // check if class object is instantiated, and instantiated properly |
|
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | - } |
|
122 | - return self::$_instance; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param LoaderInterface $loader |
|
129 | - */ |
|
130 | - public function setLoader(LoaderInterface $loader) |
|
131 | - { |
|
132 | - $this->loader = $loader; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $class |
|
139 | - * @param array $dependencies |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - public static function register_dependencies($class, $dependencies) |
|
143 | - { |
|
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | - // we need to make sure that any aliases used when registering a dependency |
|
146 | - // get resolved to the correct class name |
|
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | - $alias = self::$_instance->get_alias($dependency); |
|
149 | - unset($dependencies[$dependency]); |
|
150 | - $dependencies[$alias] = $load_source; |
|
151 | - } |
|
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | - return true; |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $class_name |
|
162 | - * @param string $loader |
|
163 | - * @return bool |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | - { |
|
168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | - if ( |
|
170 | - ! is_callable($loader) |
|
171 | - && ( |
|
172 | - strpos($loader, 'load_') !== 0 |
|
173 | - || ! method_exists('EE_Registry', $loader) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | - $loader |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - $class_name = self::$_instance->get_alias($class_name); |
|
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | - return true; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function dependency_map() |
|
197 | - { |
|
198 | - return $this->_dependency_map; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | - * |
|
206 | - * @param string $class_name |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function has($class_name = '') |
|
210 | - { |
|
211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | - * |
|
219 | - * @param string $class_name |
|
220 | - * @param string $dependency |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | - { |
|
225 | - $dependency = $this->get_alias($dependency); |
|
226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | - ? true |
|
228 | - : false; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | - * |
|
236 | - * @param string $class_name |
|
237 | - * @param string $dependency |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | - { |
|
242 | - $dependency = $this->get_alias($dependency); |
|
243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
245 | - : EE_Dependency_Map::not_registered; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $class_name |
|
252 | - * @return string | Closure |
|
253 | - */ |
|
254 | - public function class_loader($class_name) |
|
255 | - { |
|
256 | - $class_name = $this->get_alias($class_name); |
|
257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - public function class_loaders() |
|
266 | - { |
|
267 | - return $this->_class_loaders; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * adds an alias for a classname |
|
274 | - * |
|
275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | - */ |
|
279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
280 | - { |
|
281 | - if ($for_class !== '') { |
|
282 | - if (! isset($this->_aliases[$for_class])) { |
|
283 | - $this->_aliases[$for_class] = array(); |
|
284 | - } |
|
285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | - } |
|
287 | - $this->_aliases[$class_name] = $alias; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * returns TRUE if the provided class name has an alias |
|
294 | - * |
|
295 | - * @param string $class_name |
|
296 | - * @param string $for_class |
|
297 | - * @return bool |
|
298 | - */ |
|
299 | - public function has_alias($class_name = '', $for_class = '') |
|
300 | - { |
|
301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | - || ( |
|
303 | - isset($this->_aliases[$class_name]) |
|
304 | - && ! is_array($this->_aliases[$class_name]) |
|
305 | - ); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | - * for example: |
|
314 | - * if the following two entries were added to the _aliases array: |
|
315 | - * array( |
|
316 | - * 'interface_alias' => 'some\namespace\interface' |
|
317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | - * ) |
|
319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | - * to load an instance of 'some\namespace\classname' |
|
321 | - * |
|
322 | - * @param string $class_name |
|
323 | - * @param string $for_class |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_alias($class_name = '', $for_class = '') |
|
327 | - { |
|
328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
329 | - return $class_name; |
|
330 | - } |
|
331 | - if ($for_class !== '') { |
|
332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | - } |
|
334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | - * This is done by using the following class constants: |
|
343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | - */ |
|
346 | - protected function _register_core_dependencies() |
|
347 | - { |
|
348 | - $this->_dependency_map = array( |
|
349 | - 'EE_Request_Handler' => array( |
|
350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | - ), |
|
352 | - 'EE_System' => array( |
|
353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
355 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
356 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
357 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
358 | - ), |
|
359 | - 'EE_Session' => array( |
|
360 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
361 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
362 | - ), |
|
363 | - 'EE_Cart' => array( |
|
364 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
365 | - ), |
|
366 | - 'EE_Front_Controller' => array( |
|
367 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
368 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
369 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
370 | - ), |
|
371 | - 'EE_Messenger_Collection_Loader' => array( |
|
372 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
373 | - ), |
|
374 | - 'EE_Message_Type_Collection_Loader' => array( |
|
375 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
376 | - ), |
|
377 | - 'EE_Message_Resource_Manager' => array( |
|
378 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
379 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
380 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
381 | - ), |
|
382 | - 'EE_Message_Factory' => array( |
|
383 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | - ), |
|
385 | - 'EE_messages' => array( |
|
386 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
387 | - ), |
|
388 | - 'EE_Messages_Generator' => array( |
|
389 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
390 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
391 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
392 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
393 | - ), |
|
394 | - 'EE_Messages_Processor' => array( |
|
395 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
396 | - ), |
|
397 | - 'EE_Messages_Queue' => array( |
|
398 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
399 | - ), |
|
400 | - 'EE_Messages_Template_Defaults' => array( |
|
401 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
402 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
403 | - ), |
|
404 | - 'EE_Message_To_Generate_From_Request' => array( |
|
405 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
406 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
407 | - ), |
|
408 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
409 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
410 | - ), |
|
411 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
412 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
413 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
414 | - ), |
|
415 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
416 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
417 | - ), |
|
418 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
419 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
420 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
421 | - ), |
|
422 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
423 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
424 | - ), |
|
425 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
426 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
429 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
430 | - ), |
|
431 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
432 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
433 | - ), |
|
434 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
435 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
436 | - ), |
|
437 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
438 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | - ), |
|
440 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
441 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
442 | - ), |
|
443 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
444 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | - ), |
|
446 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
447 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
450 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
451 | - ), |
|
452 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
453 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
456 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
457 | - ), |
|
458 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
459 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Data_Migration_Class_Base' => array( |
|
462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_DMS_Core_4_1_0' => array( |
|
466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | - ), |
|
469 | - 'EE_DMS_Core_4_2_0' => array( |
|
470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_DMS_Core_4_3_0' => array( |
|
474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_DMS_Core_4_4_0' => array( |
|
478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_DMS_Core_4_5_0' => array( |
|
482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_DMS_Core_4_6_0' => array( |
|
486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ), |
|
489 | - 'EE_DMS_Core_4_7_0' => array( |
|
490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_DMS_Core_4_8_0' => array( |
|
494 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
495 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
496 | - ), |
|
497 | - 'EE_DMS_Core_4_9_0' => array( |
|
498 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
499 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
502 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
503 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
506 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
509 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
512 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
515 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
518 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
521 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
522 | - ), |
|
523 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
524 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
525 | - ), |
|
526 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
527 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
530 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - ); |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Registers how core classes are loaded. |
|
539 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
540 | - * 'EE_Request_Handler' => 'load_core' |
|
541 | - * 'EE_Messages_Queue' => 'load_lib' |
|
542 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
543 | - * or, if greater control is required, by providing a custom closure. For example: |
|
544 | - * 'Some_Class' => function () { |
|
545 | - * return new Some_Class(); |
|
546 | - * }, |
|
547 | - * This is required for instantiating dependencies |
|
548 | - * where an interface has been type hinted in a class constructor. For example: |
|
549 | - * 'Required_Interface' => function () { |
|
550 | - * return new A_Class_That_Implements_Required_Interface(); |
|
551 | - * }, |
|
552 | - */ |
|
553 | - protected function _register_core_class_loaders() |
|
554 | - { |
|
555 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
556 | - //be used in a closure. |
|
557 | - $request = &$this->_request; |
|
558 | - $response = &$this->_response; |
|
559 | - $loader = &$this->loader; |
|
560 | - $this->_class_loaders = array( |
|
561 | - //load_core |
|
562 | - 'EE_Capabilities' => 'load_core', |
|
563 | - 'EE_Encryption' => 'load_core', |
|
564 | - 'EE_Front_Controller' => 'load_core', |
|
565 | - 'EE_Module_Request_Router' => 'load_core', |
|
566 | - 'EE_Registry' => 'load_core', |
|
567 | - 'EE_Request' => function () use (&$request) { |
|
568 | - return $request; |
|
569 | - }, |
|
570 | - 'EE_Response' => function () use (&$response) { |
|
571 | - return $response; |
|
572 | - }, |
|
573 | - 'EE_Request_Handler' => 'load_core', |
|
574 | - 'EE_Session' => 'load_core', |
|
575 | - 'EE_System' => 'load_core', |
|
576 | - //load_lib |
|
577 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
578 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
579 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
580 | - 'EE_Messenger_Collection' => 'load_lib', |
|
581 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
582 | - 'EE_Messages_Processor' => 'load_lib', |
|
583 | - 'EE_Message_Repository' => 'load_lib', |
|
584 | - 'EE_Messages_Queue' => 'load_lib', |
|
585 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
586 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
587 | - 'EE_Messages_Generator' => function () { |
|
588 | - return EE_Registry::instance()->load_lib( |
|
589 | - 'Messages_Generator', |
|
590 | - array(), |
|
591 | - false, |
|
592 | - false |
|
593 | - ); |
|
594 | - }, |
|
595 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
596 | - return EE_Registry::instance()->load_lib( |
|
597 | - 'Messages_Template_Defaults', |
|
598 | - $arguments, |
|
599 | - false, |
|
600 | - false |
|
601 | - ); |
|
602 | - }, |
|
603 | - //load_model |
|
604 | - 'EEM_Message_Template_Group' => 'load_model', |
|
605 | - 'EEM_Message_Template' => 'load_model', |
|
606 | - //load_helper |
|
607 | - 'EEH_Parse_Shortcodes' => function () { |
|
608 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
609 | - return new EEH_Parse_Shortcodes(); |
|
610 | - } |
|
611 | - return null; |
|
612 | - }, |
|
613 | - 'EE_Template_Config' => function () { |
|
614 | - return EE_Config::instance()->template_settings; |
|
615 | - }, |
|
616 | - 'EE_Currency_Config' => function () { |
|
617 | - return EE_Config::instance()->currency; |
|
618 | - }, |
|
619 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
620 | - return $loader; |
|
621 | - }, |
|
622 | - ); |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * can be used for supplying alternate names for classes, |
|
629 | - * or for connecting interface names to instantiable classes |
|
630 | - */ |
|
631 | - protected function _register_core_aliases() |
|
632 | - { |
|
633 | - $this->_aliases = array( |
|
634 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
635 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
636 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
637 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
638 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
639 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
640 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
641 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
642 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
643 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
644 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
645 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
646 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
647 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
648 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
649 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
650 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
651 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
652 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
653 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
654 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
655 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
656 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
657 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
658 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
659 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
660 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
661 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
662 | - ); |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
669 | - * request Primarily used by unit tests. |
|
670 | - */ |
|
671 | - public function reset() |
|
672 | - { |
|
673 | - $this->_register_core_class_loaders(); |
|
674 | - $this->_register_core_dependencies(); |
|
675 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | + */ |
|
34 | + const load_new_object = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | + */ |
|
40 | + const load_from_cache = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Dependency_Map $_instance |
|
44 | + */ |
|
45 | + protected static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + protected $_request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @type EE_Response $response |
|
54 | + */ |
|
55 | + protected $_response; |
|
56 | + |
|
57 | + /** |
|
58 | + * @type LoaderInterface $loader |
|
59 | + */ |
|
60 | + protected $loader; |
|
61 | + |
|
62 | + /** |
|
63 | + * @type array $_dependency_map |
|
64 | + */ |
|
65 | + protected $_dependency_map = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @type array $_class_loaders |
|
69 | + */ |
|
70 | + protected $_class_loaders = array(); |
|
71 | + |
|
72 | + /** |
|
73 | + * @type array $_aliases |
|
74 | + */ |
|
75 | + protected $_aliases = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_Dependency_Map constructor. |
|
81 | + * |
|
82 | + * @param EE_Request $request |
|
83 | + * @param EE_Response $response |
|
84 | + */ |
|
85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | + { |
|
87 | + $this->_request = $request; |
|
88 | + $this->_response = $response; |
|
89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | + do_action('EE_Dependency_Map____construct'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidArgumentException |
|
99 | + */ |
|
100 | + public function initialize() |
|
101 | + { |
|
102 | + $this->_register_core_dependencies(); |
|
103 | + $this->_register_core_class_loaders(); |
|
104 | + $this->_register_core_aliases(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @singleton method used to instantiate class object |
|
111 | + * @access public |
|
112 | + * @param EE_Request $request |
|
113 | + * @param EE_Response $response |
|
114 | + * @return EE_Dependency_Map |
|
115 | + */ |
|
116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | + { |
|
118 | + // check if class object is instantiated, and instantiated properly |
|
119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | + } |
|
122 | + return self::$_instance; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param LoaderInterface $loader |
|
129 | + */ |
|
130 | + public function setLoader(LoaderInterface $loader) |
|
131 | + { |
|
132 | + $this->loader = $loader; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $class |
|
139 | + * @param array $dependencies |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + public static function register_dependencies($class, $dependencies) |
|
143 | + { |
|
144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | + // we need to make sure that any aliases used when registering a dependency |
|
146 | + // get resolved to the correct class name |
|
147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | + $alias = self::$_instance->get_alias($dependency); |
|
149 | + unset($dependencies[$dependency]); |
|
150 | + $dependencies[$alias] = $load_source; |
|
151 | + } |
|
152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | + return true; |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $class_name |
|
162 | + * @param string $loader |
|
163 | + * @return bool |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | + { |
|
168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | + if ( |
|
170 | + ! is_callable($loader) |
|
171 | + && ( |
|
172 | + strpos($loader, 'load_') !== 0 |
|
173 | + || ! method_exists('EE_Registry', $loader) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | + $loader |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + $class_name = self::$_instance->get_alias($class_name); |
|
184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | + return true; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function dependency_map() |
|
197 | + { |
|
198 | + return $this->_dependency_map; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | + * |
|
206 | + * @param string $class_name |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function has($class_name = '') |
|
210 | + { |
|
211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | + * |
|
219 | + * @param string $class_name |
|
220 | + * @param string $dependency |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | + { |
|
225 | + $dependency = $this->get_alias($dependency); |
|
226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | + ? true |
|
228 | + : false; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | + * |
|
236 | + * @param string $class_name |
|
237 | + * @param string $dependency |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | + { |
|
242 | + $dependency = $this->get_alias($dependency); |
|
243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
245 | + : EE_Dependency_Map::not_registered; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $class_name |
|
252 | + * @return string | Closure |
|
253 | + */ |
|
254 | + public function class_loader($class_name) |
|
255 | + { |
|
256 | + $class_name = $this->get_alias($class_name); |
|
257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + public function class_loaders() |
|
266 | + { |
|
267 | + return $this->_class_loaders; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * adds an alias for a classname |
|
274 | + * |
|
275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | + */ |
|
279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
280 | + { |
|
281 | + if ($for_class !== '') { |
|
282 | + if (! isset($this->_aliases[$for_class])) { |
|
283 | + $this->_aliases[$for_class] = array(); |
|
284 | + } |
|
285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | + } |
|
287 | + $this->_aliases[$class_name] = $alias; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * returns TRUE if the provided class name has an alias |
|
294 | + * |
|
295 | + * @param string $class_name |
|
296 | + * @param string $for_class |
|
297 | + * @return bool |
|
298 | + */ |
|
299 | + public function has_alias($class_name = '', $for_class = '') |
|
300 | + { |
|
301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | + || ( |
|
303 | + isset($this->_aliases[$class_name]) |
|
304 | + && ! is_array($this->_aliases[$class_name]) |
|
305 | + ); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | + * for example: |
|
314 | + * if the following two entries were added to the _aliases array: |
|
315 | + * array( |
|
316 | + * 'interface_alias' => 'some\namespace\interface' |
|
317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | + * ) |
|
319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | + * to load an instance of 'some\namespace\classname' |
|
321 | + * |
|
322 | + * @param string $class_name |
|
323 | + * @param string $for_class |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_alias($class_name = '', $for_class = '') |
|
327 | + { |
|
328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
329 | + return $class_name; |
|
330 | + } |
|
331 | + if ($for_class !== '') { |
|
332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | + } |
|
334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | + * This is done by using the following class constants: |
|
343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | + */ |
|
346 | + protected function _register_core_dependencies() |
|
347 | + { |
|
348 | + $this->_dependency_map = array( |
|
349 | + 'EE_Request_Handler' => array( |
|
350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | + ), |
|
352 | + 'EE_System' => array( |
|
353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
355 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
356 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
357 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
358 | + ), |
|
359 | + 'EE_Session' => array( |
|
360 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
361 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
362 | + ), |
|
363 | + 'EE_Cart' => array( |
|
364 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
365 | + ), |
|
366 | + 'EE_Front_Controller' => array( |
|
367 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
368 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
369 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
370 | + ), |
|
371 | + 'EE_Messenger_Collection_Loader' => array( |
|
372 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
373 | + ), |
|
374 | + 'EE_Message_Type_Collection_Loader' => array( |
|
375 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
376 | + ), |
|
377 | + 'EE_Message_Resource_Manager' => array( |
|
378 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
379 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
380 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
381 | + ), |
|
382 | + 'EE_Message_Factory' => array( |
|
383 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
384 | + ), |
|
385 | + 'EE_messages' => array( |
|
386 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
387 | + ), |
|
388 | + 'EE_Messages_Generator' => array( |
|
389 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
390 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
391 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
392 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
393 | + ), |
|
394 | + 'EE_Messages_Processor' => array( |
|
395 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
396 | + ), |
|
397 | + 'EE_Messages_Queue' => array( |
|
398 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
399 | + ), |
|
400 | + 'EE_Messages_Template_Defaults' => array( |
|
401 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
402 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
403 | + ), |
|
404 | + 'EE_Message_To_Generate_From_Request' => array( |
|
405 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
406 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
407 | + ), |
|
408 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
409 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
410 | + ), |
|
411 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
412 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
413 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
414 | + ), |
|
415 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
416 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
417 | + ), |
|
418 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
419 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
420 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
421 | + ), |
|
422 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
423 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
424 | + ), |
|
425 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
426 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
429 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
430 | + ), |
|
431 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
432 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
433 | + ), |
|
434 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
435 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
436 | + ), |
|
437 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
438 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | + ), |
|
440 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
441 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
442 | + ), |
|
443 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
444 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | + ), |
|
446 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
447 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
450 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
451 | + ), |
|
452 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
453 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
456 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
457 | + ), |
|
458 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
459 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Data_Migration_Class_Base' => array( |
|
462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_DMS_Core_4_1_0' => array( |
|
466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | + ), |
|
469 | + 'EE_DMS_Core_4_2_0' => array( |
|
470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_DMS_Core_4_3_0' => array( |
|
474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_DMS_Core_4_4_0' => array( |
|
478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_DMS_Core_4_5_0' => array( |
|
482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_DMS_Core_4_6_0' => array( |
|
486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ), |
|
489 | + 'EE_DMS_Core_4_7_0' => array( |
|
490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_DMS_Core_4_8_0' => array( |
|
494 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
495 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
496 | + ), |
|
497 | + 'EE_DMS_Core_4_9_0' => array( |
|
498 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
499 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
502 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
503 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
506 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
509 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
512 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
515 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
518 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
521 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
522 | + ), |
|
523 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
524 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
525 | + ), |
|
526 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
527 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
530 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + ); |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Registers how core classes are loaded. |
|
539 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
540 | + * 'EE_Request_Handler' => 'load_core' |
|
541 | + * 'EE_Messages_Queue' => 'load_lib' |
|
542 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
543 | + * or, if greater control is required, by providing a custom closure. For example: |
|
544 | + * 'Some_Class' => function () { |
|
545 | + * return new Some_Class(); |
|
546 | + * }, |
|
547 | + * This is required for instantiating dependencies |
|
548 | + * where an interface has been type hinted in a class constructor. For example: |
|
549 | + * 'Required_Interface' => function () { |
|
550 | + * return new A_Class_That_Implements_Required_Interface(); |
|
551 | + * }, |
|
552 | + */ |
|
553 | + protected function _register_core_class_loaders() |
|
554 | + { |
|
555 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
556 | + //be used in a closure. |
|
557 | + $request = &$this->_request; |
|
558 | + $response = &$this->_response; |
|
559 | + $loader = &$this->loader; |
|
560 | + $this->_class_loaders = array( |
|
561 | + //load_core |
|
562 | + 'EE_Capabilities' => 'load_core', |
|
563 | + 'EE_Encryption' => 'load_core', |
|
564 | + 'EE_Front_Controller' => 'load_core', |
|
565 | + 'EE_Module_Request_Router' => 'load_core', |
|
566 | + 'EE_Registry' => 'load_core', |
|
567 | + 'EE_Request' => function () use (&$request) { |
|
568 | + return $request; |
|
569 | + }, |
|
570 | + 'EE_Response' => function () use (&$response) { |
|
571 | + return $response; |
|
572 | + }, |
|
573 | + 'EE_Request_Handler' => 'load_core', |
|
574 | + 'EE_Session' => 'load_core', |
|
575 | + 'EE_System' => 'load_core', |
|
576 | + //load_lib |
|
577 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
578 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
579 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
580 | + 'EE_Messenger_Collection' => 'load_lib', |
|
581 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
582 | + 'EE_Messages_Processor' => 'load_lib', |
|
583 | + 'EE_Message_Repository' => 'load_lib', |
|
584 | + 'EE_Messages_Queue' => 'load_lib', |
|
585 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
586 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
587 | + 'EE_Messages_Generator' => function () { |
|
588 | + return EE_Registry::instance()->load_lib( |
|
589 | + 'Messages_Generator', |
|
590 | + array(), |
|
591 | + false, |
|
592 | + false |
|
593 | + ); |
|
594 | + }, |
|
595 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
596 | + return EE_Registry::instance()->load_lib( |
|
597 | + 'Messages_Template_Defaults', |
|
598 | + $arguments, |
|
599 | + false, |
|
600 | + false |
|
601 | + ); |
|
602 | + }, |
|
603 | + //load_model |
|
604 | + 'EEM_Message_Template_Group' => 'load_model', |
|
605 | + 'EEM_Message_Template' => 'load_model', |
|
606 | + //load_helper |
|
607 | + 'EEH_Parse_Shortcodes' => function () { |
|
608 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
609 | + return new EEH_Parse_Shortcodes(); |
|
610 | + } |
|
611 | + return null; |
|
612 | + }, |
|
613 | + 'EE_Template_Config' => function () { |
|
614 | + return EE_Config::instance()->template_settings; |
|
615 | + }, |
|
616 | + 'EE_Currency_Config' => function () { |
|
617 | + return EE_Config::instance()->currency; |
|
618 | + }, |
|
619 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
620 | + return $loader; |
|
621 | + }, |
|
622 | + ); |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * can be used for supplying alternate names for classes, |
|
629 | + * or for connecting interface names to instantiable classes |
|
630 | + */ |
|
631 | + protected function _register_core_aliases() |
|
632 | + { |
|
633 | + $this->_aliases = array( |
|
634 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
635 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
636 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
637 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
638 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
639 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
640 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
641 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
642 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
643 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
644 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
645 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
646 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
647 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
648 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
649 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
650 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
651 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
652 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
653 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
654 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
655 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
656 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
657 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
658 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
659 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
660 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
661 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
662 | + ); |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
669 | + * request Primarily used by unit tests. |
|
670 | + */ |
|
671 | + public function reset() |
|
672 | + { |
|
673 | + $this->_register_core_class_loaders(); |
|
674 | + $this->_register_core_dependencies(); |
|
675 | + } |
|
676 | 676 | |
677 | 677 | |
678 | 678 | } |
@@ -23,80 +23,80 @@ |
||
23 | 23 | class CoreLoader implements LoaderDecoratorInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry|CoffeeShop $generator |
|
28 | - */ |
|
29 | - private $generator; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * CoreLoader constructor. |
|
35 | - * |
|
36 | - * @param EE_Registry|CoffeeShop $generator |
|
37 | - * @throws InvalidArgumentException |
|
38 | - */ |
|
39 | - public function __construct($generator) |
|
40 | - { |
|
41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | - throw new InvalidArgumentException( |
|
43 | - esc_html__( |
|
44 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
49 | - $this->generator = $generator; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $fqcn |
|
56 | - * @param array $arguments |
|
57 | - * @return mixed |
|
58 | - * @throws ServiceNotFoundException |
|
59 | - */ |
|
60 | - public function load($fqcn, $arguments = array()) |
|
61 | - { |
|
62 | - $object = $this->generator instanceof EE_Registry |
|
63 | - ? $this->generator->create($fqcn, $arguments) |
|
64 | - : $this->generator->brew($fqcn, $arguments); |
|
65 | - // if we did NOT receive an instance of the requested object from EE_Registry |
|
66 | - if(! $object instanceof $fqcn && $this->generator instanceof EE_Registry) { |
|
67 | - // then we need to try some of these other loading methods |
|
68 | - $alternate_loaders = array( |
|
69 | - 'load_core', |
|
70 | - 'load_class', |
|
71 | - 'load_model', |
|
72 | - 'load_helper', |
|
73 | - 'load_lib', |
|
74 | - 'load_model_class', |
|
75 | - 'load_service', |
|
76 | - 'load_dms', |
|
77 | - ); |
|
78 | - foreach ($alternate_loaders as $alternate_loader) { |
|
79 | - $object = $this->generator->{$alternate_loader}($fqcn, $arguments); |
|
80 | - // but then break out of the loop as soon as we find what we are looking for |
|
81 | - if ($object instanceof $fqcn) { |
|
82 | - break; |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
86 | - return $object; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * calls reset() on generator if method exists |
|
93 | - */ |
|
94 | - public function reset() |
|
95 | - { |
|
96 | - if (method_exists($this->generator, 'reset')) { |
|
97 | - $this->generator->reset(); |
|
98 | - } |
|
99 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry|CoffeeShop $generator |
|
28 | + */ |
|
29 | + private $generator; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * CoreLoader constructor. |
|
35 | + * |
|
36 | + * @param EE_Registry|CoffeeShop $generator |
|
37 | + * @throws InvalidArgumentException |
|
38 | + */ |
|
39 | + public function __construct($generator) |
|
40 | + { |
|
41 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | + throw new InvalidArgumentException( |
|
43 | + esc_html__( |
|
44 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | + $this->generator = $generator; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $fqcn |
|
56 | + * @param array $arguments |
|
57 | + * @return mixed |
|
58 | + * @throws ServiceNotFoundException |
|
59 | + */ |
|
60 | + public function load($fqcn, $arguments = array()) |
|
61 | + { |
|
62 | + $object = $this->generator instanceof EE_Registry |
|
63 | + ? $this->generator->create($fqcn, $arguments) |
|
64 | + : $this->generator->brew($fqcn, $arguments); |
|
65 | + // if we did NOT receive an instance of the requested object from EE_Registry |
|
66 | + if(! $object instanceof $fqcn && $this->generator instanceof EE_Registry) { |
|
67 | + // then we need to try some of these other loading methods |
|
68 | + $alternate_loaders = array( |
|
69 | + 'load_core', |
|
70 | + 'load_class', |
|
71 | + 'load_model', |
|
72 | + 'load_helper', |
|
73 | + 'load_lib', |
|
74 | + 'load_model_class', |
|
75 | + 'load_service', |
|
76 | + 'load_dms', |
|
77 | + ); |
|
78 | + foreach ($alternate_loaders as $alternate_loader) { |
|
79 | + $object = $this->generator->{$alternate_loader}($fqcn, $arguments); |
|
80 | + // but then break out of the loop as soon as we find what we are looking for |
|
81 | + if ($object instanceof $fqcn) { |
|
82 | + break; |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | + return $object; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * calls reset() on generator if method exists |
|
93 | + */ |
|
94 | + public function reset() |
|
95 | + { |
|
96 | + if (method_exists($this->generator, 'reset')) { |
|
97 | + $this->generator->reset(); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | // End of file CoreLoader.php |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct($generator) |
40 | 40 | { |
41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
41 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | 42 | throw new InvalidArgumentException( |
43 | 43 | esc_html__( |
44 | 44 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ? $this->generator->create($fqcn, $arguments) |
64 | 64 | : $this->generator->brew($fqcn, $arguments); |
65 | 65 | // if we did NOT receive an instance of the requested object from EE_Registry |
66 | - if(! $object instanceof $fqcn && $this->generator instanceof EE_Registry) { |
|
66 | + if ( ! $object instanceof $fqcn && $this->generator instanceof EE_Registry) { |
|
67 | 67 | // then we need to try some of these other loading methods |
68 | 68 | $alternate_loaders = array( |
69 | 69 | 'load_core', |
@@ -16,1377 +16,1377 @@ |
||
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 | - * @return \EE_Registry |
|
224 | - */ |
|
225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | - { |
|
227 | - $this->_dependency_map = $dependency_map; |
|
228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize |
|
235 | - */ |
|
236 | - public function initialize() |
|
237 | - { |
|
238 | - $this->_class_abbreviations = apply_filters( |
|
239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | - array( |
|
241 | - 'EE_Config' => 'CFG', |
|
242 | - 'EE_Session' => 'SSN', |
|
243 | - 'EE_Capabilities' => 'CAP', |
|
244 | - 'EE_Cart' => 'CART', |
|
245 | - 'EE_Network_Config' => 'NET_CFG', |
|
246 | - 'EE_Request_Handler' => 'REQ', |
|
247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
250 | - ) |
|
251 | - ); |
|
252 | - // class library |
|
253 | - $this->LIB = new stdClass(); |
|
254 | - $this->addons = new stdClass(); |
|
255 | - $this->modules = new stdClass(); |
|
256 | - $this->shortcodes = new stdClass(); |
|
257 | - $this->widgets = new stdClass(); |
|
258 | - $this->load_core('Base', array(), true); |
|
259 | - // add our request and response objects to the cache |
|
260 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
261 | - $this->_set_cached_class( |
|
262 | - $request_loader(), |
|
263 | - 'EE_Request' |
|
264 | - ); |
|
265 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
266 | - $this->_set_cached_class( |
|
267 | - $response_loader(), |
|
268 | - 'EE_Response' |
|
269 | - ); |
|
270 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * init |
|
277 | - * |
|
278 | - * @access public |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function init() |
|
282 | - { |
|
283 | - // Get current page protocol |
|
284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | - // Output admin-ajax.php URL with same protocol as current page |
|
286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * localize_i18n_js_strings |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function localize_i18n_js_strings() |
|
298 | - { |
|
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | - foreach ($i18n_js_strings as $key => $value) { |
|
301 | - if (is_scalar($value)) { |
|
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | - } |
|
304 | - } |
|
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param mixed string | EED_Module $module |
|
312 | - */ |
|
313 | - public function add_module($module) |
|
314 | - { |
|
315 | - if ($module instanceof EED_Module) { |
|
316 | - $module_class = get_class($module); |
|
317 | - $this->modules->{$module_class} = $module; |
|
318 | - } else { |
|
319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | - $this->load_core('Module_Request_Router'); |
|
321 | - } |
|
322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param string $module_name |
|
330 | - * @return mixed EED_Module | NULL |
|
331 | - */ |
|
332 | - public function get_module($module_name = '') |
|
333 | - { |
|
334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * loads core classes - must be singletons |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param string $class_name - simple class name ie: session |
|
344 | - * @param mixed $arguments |
|
345 | - * @param bool $load_only |
|
346 | - * @return mixed |
|
347 | - */ |
|
348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | - { |
|
350 | - $core_paths = apply_filters( |
|
351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | - array( |
|
353 | - EE_CORE, |
|
354 | - EE_ADMIN, |
|
355 | - EE_CPTS, |
|
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
359 | - ) |
|
360 | - ); |
|
361 | - // retrieve instantiated class |
|
362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * loads service classes |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @param string $class_name - simple class name ie: session |
|
372 | - * @param mixed $arguments |
|
373 | - * @param bool $load_only |
|
374 | - * @return mixed |
|
375 | - */ |
|
376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | - { |
|
378 | - $service_paths = apply_filters( |
|
379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | - array( |
|
381 | - EE_CORE . 'services' . DS, |
|
382 | - ) |
|
383 | - ); |
|
384 | - // retrieve instantiated class |
|
385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * loads data_migration_scripts |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | - * @param mixed $arguments |
|
396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
397 | - */ |
|
398 | - public function load_dms($class_name, $arguments = array()) |
|
399 | - { |
|
400 | - // retrieve instantiated class |
|
401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * loads object creating classes - must be singletons |
|
408 | - * |
|
409 | - * @param string $class_name - simple class name ie: attendee |
|
410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | - * @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) |
|
413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | - * @return EE_Base_Class | bool |
|
415 | - */ |
|
416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | - { |
|
418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | - EE_CORE, |
|
420 | - EE_CLASSES, |
|
421 | - EE_BUSINESS, |
|
422 | - )); |
|
423 | - // retrieve instantiated class |
|
424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads helper classes - must be singletons |
|
431 | - * |
|
432 | - * @param string $class_name - simple class name ie: price |
|
433 | - * @param mixed $arguments |
|
434 | - * @param bool $load_only |
|
435 | - * @return EEH_Base | bool |
|
436 | - */ |
|
437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | - { |
|
439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | - // retrieve instantiated class |
|
442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * loads core classes - must be singletons |
|
449 | - * |
|
450 | - * @access public |
|
451 | - * @param string $class_name - simple class name ie: session |
|
452 | - * @param mixed $arguments |
|
453 | - * @param bool $load_only |
|
454 | - * @param bool $cache whether to cache the object or not. |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | - { |
|
459 | - $paths = array( |
|
460 | - EE_LIBRARIES, |
|
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | - ); |
|
466 | - // retrieve instantiated class |
|
467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * loads model classes - must be singletons |
|
474 | - * |
|
475 | - * @param string $class_name - simple class name ie: price |
|
476 | - * @param mixed $arguments |
|
477 | - * @param bool $load_only |
|
478 | - * @return EEM_Base | bool |
|
479 | - */ |
|
480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | - { |
|
482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | - EE_MODELS, |
|
484 | - EE_CORE, |
|
485 | - )); |
|
486 | - // retrieve instantiated class |
|
487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * loads model classes - must be singletons |
|
494 | - * |
|
495 | - * @param string $class_name - simple class name ie: price |
|
496 | - * @param mixed $arguments |
|
497 | - * @param bool $load_only |
|
498 | - * @return mixed | bool |
|
499 | - */ |
|
500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | - { |
|
502 | - $paths = array( |
|
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
507 | - ); |
|
508 | - // retrieve instantiated class |
|
509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Determines if $model_name is the name of an actual EE model. |
|
516 | - * |
|
517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | - * @return boolean |
|
519 | - */ |
|
520 | - public function is_model_name($model_name) |
|
521 | - { |
|
522 | - return isset($this->models[$model_name]) ? true : false; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * generic class loader |
|
529 | - * |
|
530 | - * @param string $path_to_file - directory path to file location, not including filename |
|
531 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | - * @param string $type - file type - core? class? helper? model? |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @return mixed |
|
536 | - */ |
|
537 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | - { |
|
539 | - // retrieve instantiated class |
|
540 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * load_addon |
|
547 | - * |
|
548 | - * @param string $path_to_file - directory path to file location, not including filename |
|
549 | - * @param string $class_name - full class name ie: My_Class |
|
550 | - * @param string $type - file type - core? class? helper? model? |
|
551 | - * @param mixed $arguments |
|
552 | - * @param bool $load_only |
|
553 | - * @return EE_Addon |
|
554 | - */ |
|
555 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | - { |
|
557 | - // retrieve instantiated class |
|
558 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * instantiates, caches, and automatically resolves dependencies |
|
565 | - * for classes that use a Fully Qualified Class Name. |
|
566 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | - * then you need to use one of the existing load_*() methods |
|
568 | - * which can resolve the classname and filepath from the passed arguments |
|
569 | - * |
|
570 | - * @param bool|string $class_name Fully Qualified Class Name |
|
571 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | - * @param bool $from_db some classes are instantiated from the db |
|
574 | - * and thus call a different method to instantiate |
|
575 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | - * @return mixed null = failure to load or instantiate class object. |
|
578 | - * object = class loaded and instantiated successfully. |
|
579 | - * bool = fail or success when $load_only is true |
|
580 | - */ |
|
581 | - public function create( |
|
582 | - $class_name = false, |
|
583 | - $arguments = array(), |
|
584 | - $cache = false, |
|
585 | - $from_db = false, |
|
586 | - $load_only = false, |
|
587 | - $addon = false |
|
588 | - ) { |
|
589 | - $class_name = ltrim($class_name, '\\'); |
|
590 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | - if ( ! class_exists($class_name)) { |
|
592 | - // maybe the class is registered with a preceding \ |
|
593 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | - // still doesn't exist ? |
|
595 | - if ( ! class_exists($class_name)) { |
|
596 | - return null; |
|
597 | - } |
|
598 | - } |
|
599 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | - if ($load_only) { |
|
601 | - return true; |
|
602 | - } |
|
603 | - $addon = $addon ? 'addon' : ''; |
|
604 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | - // return object if it's already cached |
|
609 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | - if ($cached_class !== null) { |
|
611 | - return $cached_class; |
|
612 | - } |
|
613 | - } |
|
614 | - // instantiate the requested object |
|
615 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | - // if caching is turned on OR this class is cached in a class property |
|
617 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
618 | - // save it for later... kinda like gum { : $ |
|
619 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
620 | - } |
|
621 | - $this->_cache_on = true; |
|
622 | - return $class_obj; |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * instantiates, caches, and injects dependencies for classes |
|
629 | - * |
|
630 | - * @param array $file_paths an array of paths to folders to look in |
|
631 | - * @param string $class_prefix EE or EEM or... ??? |
|
632 | - * @param bool|string $class_name $class name |
|
633 | - * @param string $type file type - core? class? helper? model? |
|
634 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
635 | - * @param bool $from_db some classes are instantiated from the db |
|
636 | - * and thus call a different method to instantiate |
|
637 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
638 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
639 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
640 | - * object = class loaded and instantiated successfully. |
|
641 | - * bool = fail or success when $load_only is true |
|
642 | - */ |
|
643 | - protected function _load( |
|
644 | - $file_paths = array(), |
|
645 | - $class_prefix = 'EE_', |
|
646 | - $class_name = false, |
|
647 | - $type = 'class', |
|
648 | - $arguments = array(), |
|
649 | - $from_db = false, |
|
650 | - $cache = true, |
|
651 | - $load_only = false |
|
652 | - ) { |
|
653 | - $class_name = ltrim($class_name, '\\'); |
|
654 | - // strip php file extension |
|
655 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
656 | - // does the class have a prefix ? |
|
657 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
658 | - // make sure $class_prefix is uppercase |
|
659 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
660 | - // add class prefix ONCE!!! |
|
661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
662 | - } |
|
663 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
664 | - $class_exists = class_exists($class_name); |
|
665 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
666 | - if ($load_only && $class_exists) { |
|
667 | - return true; |
|
668 | - } |
|
669 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
670 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
671 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
672 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
673 | - // return object if it's already cached |
|
674 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
675 | - if ($cached_class !== null) { |
|
676 | - return $cached_class; |
|
677 | - } |
|
678 | - } |
|
679 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
680 | - if ( ! $class_exists) { |
|
681 | - // get full path to file |
|
682 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
683 | - // load the file |
|
684 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
685 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
686 | - if ( ! $loaded || $load_only) { |
|
687 | - // return boolean if only loading, or null if an object was expected |
|
688 | - return $load_only ? $loaded : null; |
|
689 | - } |
|
690 | - } |
|
691 | - // instantiate the requested object |
|
692 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
693 | - if ($this->_cache_on && $cache) { |
|
694 | - // save it for later... kinda like gum { : $ |
|
695 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
696 | - } |
|
697 | - $this->_cache_on = true; |
|
698 | - return $class_obj; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * _get_cached_class |
|
705 | - * attempts to find a cached version of the requested class |
|
706 | - * by looking in the following places: |
|
707 | - * $this->{$class_abbreviation} ie: $this->CART |
|
708 | - * $this->{$class_name} ie: $this->Some_Class |
|
709 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
710 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
711 | - * |
|
712 | - * @access protected |
|
713 | - * @param string $class_name |
|
714 | - * @param string $class_prefix |
|
715 | - * @return mixed |
|
716 | - */ |
|
717 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
718 | - { |
|
719 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
720 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
721 | - } else { |
|
722 | - // have to specify something, but not anything that will conflict |
|
723 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
724 | - } |
|
725 | - // check if class has already been loaded, and return it if it has been |
|
726 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
727 | - return $this->{$class_abbreviation}; |
|
728 | - } else if (isset ($this->{$class_name})) { |
|
729 | - return $this->{$class_name}; |
|
730 | - } else if (isset ($this->LIB->{$class_name})) { |
|
731 | - return $this->LIB->{$class_name}; |
|
732 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
733 | - return $this->addons->{$class_name}; |
|
734 | - } |
|
735 | - return null; |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * _resolve_path |
|
742 | - * attempts to find a full valid filepath for the requested class. |
|
743 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
744 | - * then returns that path if the target file has been found and is readable |
|
745 | - * |
|
746 | - * @access protected |
|
747 | - * @param string $class_name |
|
748 | - * @param string $type |
|
749 | - * @param array $file_paths |
|
750 | - * @return string | bool |
|
751 | - */ |
|
752 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
753 | - { |
|
754 | - // make sure $file_paths is an array |
|
755 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
756 | - // cycle thru paths |
|
757 | - foreach ($file_paths as $key => $file_path) { |
|
758 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
759 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
760 | - // prep file type |
|
761 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
762 | - // build full file path |
|
763 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
764 | - //does the file exist and can be read ? |
|
765 | - if (is_readable($file_paths[$key])) { |
|
766 | - return $file_paths[$key]; |
|
767 | - } |
|
768 | - } |
|
769 | - return false; |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * _require_file |
|
776 | - * basically just performs a require_once() |
|
777 | - * but with some error handling |
|
778 | - * |
|
779 | - * @access protected |
|
780 | - * @param string $path |
|
781 | - * @param string $class_name |
|
782 | - * @param string $type |
|
783 | - * @param array $file_paths |
|
784 | - * @return boolean |
|
785 | - * @throws \EE_Error |
|
786 | - */ |
|
787 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
788 | - { |
|
789 | - // don't give up! you gotta... |
|
790 | - try { |
|
791 | - //does the file exist and can it be read ? |
|
792 | - if ( ! $path) { |
|
793 | - // so sorry, can't find the file |
|
794 | - throw new EE_Error ( |
|
795 | - sprintf( |
|
796 | - __('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'), |
|
797 | - trim($type, '.'), |
|
798 | - $class_name, |
|
799 | - '<br />' . implode(',<br />', $file_paths) |
|
800 | - ) |
|
801 | - ); |
|
802 | - } |
|
803 | - // get the file |
|
804 | - require_once($path); |
|
805 | - // if the class isn't already declared somewhere |
|
806 | - if (class_exists($class_name, false) === false) { |
|
807 | - // so sorry, not a class |
|
808 | - throw new EE_Error( |
|
809 | - sprintf( |
|
810 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
811 | - $type, |
|
812 | - $path, |
|
813 | - $class_name |
|
814 | - ) |
|
815 | - ); |
|
816 | - } |
|
817 | - } catch (EE_Error $e) { |
|
818 | - $e->get_error(); |
|
819 | - return false; |
|
820 | - } |
|
821 | - return true; |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * _create_object |
|
828 | - * Attempts to instantiate the requested class via any of the |
|
829 | - * commonly used instantiation methods employed throughout EE. |
|
830 | - * The priority for instantiation is as follows: |
|
831 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
832 | - * - model objects via their 'new_instance_from_db' method |
|
833 | - * - model objects via their 'new_instance' method |
|
834 | - * - "singleton" classes" via their 'instance' method |
|
835 | - * - standard instantiable classes via their __constructor |
|
836 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
837 | - * then the constructor for the requested class will be examined to determine |
|
838 | - * if any dependencies exist, and if they can be injected. |
|
839 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
840 | - * |
|
841 | - * @access protected |
|
842 | - * @param string $class_name |
|
843 | - * @param array $arguments |
|
844 | - * @param string $type |
|
845 | - * @param bool $from_db |
|
846 | - * @return null | object |
|
847 | - * @throws \EE_Error |
|
848 | - */ |
|
849 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
850 | - { |
|
851 | - $class_obj = null; |
|
852 | - $instantiation_mode = '0) none'; |
|
853 | - // don't give up! you gotta... |
|
854 | - try { |
|
855 | - // create reflection |
|
856 | - $reflector = $this->get_ReflectionClass($class_name); |
|
857 | - // make sure arguments are an array |
|
858 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
859 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
860 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
861 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
862 | - ? $arguments |
|
863 | - : array($arguments); |
|
864 | - // attempt to inject dependencies ? |
|
865 | - if ($this->_dependency_map->has($class_name)) { |
|
866 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
867 | - } |
|
868 | - // instantiate the class if possible |
|
869 | - if ($reflector->isAbstract()) { |
|
870 | - // nothing to instantiate, loading file was enough |
|
871 | - // does not throw an exception so $instantiation_mode is unused |
|
872 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
873 | - $class_obj = true; |
|
874 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
875 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
876 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
877 | - $class_obj = $reflector->newInstance(); |
|
878 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
879 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
880 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
881 | - } else if (method_exists($class_name, 'new_instance')) { |
|
882 | - $instantiation_mode = "4) new_instance()"; |
|
883 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
884 | - } else if (method_exists($class_name, 'instance')) { |
|
885 | - $instantiation_mode = "5) instance()"; |
|
886 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
887 | - } else if ($reflector->isInstantiable()) { |
|
888 | - $instantiation_mode = "6) constructor"; |
|
889 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
890 | - } else { |
|
891 | - // heh ? something's not right ! |
|
892 | - throw new EE_Error( |
|
893 | - sprintf( |
|
894 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
895 | - $type, |
|
896 | - $class_name |
|
897 | - ) |
|
898 | - ); |
|
899 | - } |
|
900 | - } catch (Exception $e) { |
|
901 | - if ( ! $e instanceof EE_Error) { |
|
902 | - $e = new EE_Error( |
|
903 | - sprintf( |
|
904 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
905 | - $class_name, |
|
906 | - '<br />', |
|
907 | - $e->getMessage(), |
|
908 | - $instantiation_mode |
|
909 | - ) |
|
910 | - ); |
|
911 | - } |
|
912 | - $e->get_error(); |
|
913 | - } |
|
914 | - return $class_obj; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
921 | - * @param array $array |
|
922 | - * @return bool |
|
923 | - */ |
|
924 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
925 | - { |
|
926 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * getReflectionClass |
|
933 | - * checks if a ReflectionClass object has already been generated for a class |
|
934 | - * and returns that instead of creating a new one |
|
935 | - * |
|
936 | - * @access public |
|
937 | - * @param string $class_name |
|
938 | - * @return ReflectionClass |
|
939 | - */ |
|
940 | - public function get_ReflectionClass($class_name) |
|
941 | - { |
|
942 | - if ( |
|
943 | - ! isset($this->_reflectors[$class_name]) |
|
944 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
945 | - ) { |
|
946 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
947 | - } |
|
948 | - return $this->_reflectors[$class_name]; |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * _resolve_dependencies |
|
955 | - * examines the constructor for the requested class to determine |
|
956 | - * if any dependencies exist, and if they can be injected. |
|
957 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
958 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
959 | - * For example: |
|
960 | - * if attempting to load a class "Foo" with the following constructor: |
|
961 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
962 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
963 | - * but only IF they are NOT already present in the incoming arguments array, |
|
964 | - * and the correct classes can be loaded |
|
965 | - * |
|
966 | - * @access protected |
|
967 | - * @param ReflectionClass $reflector |
|
968 | - * @param string $class_name |
|
969 | - * @param array $arguments |
|
970 | - * @return array |
|
971 | - * @throws \ReflectionException |
|
972 | - */ |
|
973 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
974 | - { |
|
975 | - // let's examine the constructor |
|
976 | - $constructor = $reflector->getConstructor(); |
|
977 | - // whu? huh? nothing? |
|
978 | - if ( ! $constructor) { |
|
979 | - return $arguments; |
|
980 | - } |
|
981 | - // get constructor parameters |
|
982 | - $params = $constructor->getParameters(); |
|
983 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
984 | - $argument_keys = array_keys($arguments); |
|
985 | - // now loop thru all of the constructors expected parameters |
|
986 | - foreach ($params as $index => $param) { |
|
987 | - // is this a dependency for a specific class ? |
|
988 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
989 | - if ( |
|
990 | - // param is not even a class |
|
991 | - empty($param_class) |
|
992 | - // and something already exists in the incoming arguments for this param |
|
993 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
994 | - ) { |
|
995 | - // so let's skip this argument and move on to the next |
|
996 | - continue; |
|
997 | - } else if ( |
|
998 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
999 | - ! empty($param_class) |
|
1000 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1001 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1002 | - ) { |
|
1003 | - // skip this argument and move on to the next |
|
1004 | - continue; |
|
1005 | - } else if ( |
|
1006 | - // parameter is type hinted as a class, and should be injected |
|
1007 | - ! empty($param_class) |
|
1008 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1009 | - ) { |
|
1010 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1011 | - } else { |
|
1012 | - try { |
|
1013 | - $arguments[$index] = $param->getDefaultValue(); |
|
1014 | - } catch (ReflectionException $e) { |
|
1015 | - throw new ReflectionException( |
|
1016 | - sprintf( |
|
1017 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1018 | - $e->getMessage(), |
|
1019 | - $param->getName() |
|
1020 | - ) |
|
1021 | - ); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - } |
|
1025 | - return $arguments; |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * @access protected |
|
1032 | - * @param string $class_name |
|
1033 | - * @param string $param_class |
|
1034 | - * @param array $arguments |
|
1035 | - * @param mixed $index |
|
1036 | - * @return array |
|
1037 | - */ |
|
1038 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1039 | - { |
|
1040 | - $dependency = null; |
|
1041 | - // should dependency be loaded from cache ? |
|
1042 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1043 | - !== EE_Dependency_Map::load_new_object |
|
1044 | - ? true |
|
1045 | - : false; |
|
1046 | - // we might have a dependency... |
|
1047 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1048 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1049 | - // and grab it if it exists |
|
1050 | - if ($cached_class instanceof $param_class) { |
|
1051 | - $dependency = $cached_class; |
|
1052 | - } else if ($param_class != $class_name) { |
|
1053 | - // obtain the loader method from the dependency map |
|
1054 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1055 | - // is loader a custom closure ? |
|
1056 | - if ($loader instanceof Closure) { |
|
1057 | - $dependency = $loader(); |
|
1058 | - } else { |
|
1059 | - // set the cache on property for the recursive loading call |
|
1060 | - $this->_cache_on = $cache_on; |
|
1061 | - // if not, then let's try and load it via the registry |
|
1062 | - if (method_exists($this, $loader)) { |
|
1063 | - $dependency = $this->{$loader}($param_class); |
|
1064 | - } else { |
|
1065 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1066 | - } |
|
1067 | - } |
|
1068 | - } |
|
1069 | - // did we successfully find the correct dependency ? |
|
1070 | - if ($dependency instanceof $param_class) { |
|
1071 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1072 | - if (isset($argument_keys[$index])) { |
|
1073 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1074 | - } else { |
|
1075 | - $arguments[$index] = $dependency; |
|
1076 | - } |
|
1077 | - } |
|
1078 | - return $arguments; |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * _set_cached_class |
|
1085 | - * attempts to cache the instantiated class locally |
|
1086 | - * in one of the following places, in the following order: |
|
1087 | - * $this->{class_abbreviation} ie: $this->CART |
|
1088 | - * $this->{$class_name} ie: $this->Some_Class |
|
1089 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1090 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1091 | - * |
|
1092 | - * @access protected |
|
1093 | - * @param object $class_obj |
|
1094 | - * @param string $class_name |
|
1095 | - * @param string $class_prefix |
|
1096 | - * @param bool $from_db |
|
1097 | - * @return void |
|
1098 | - */ |
|
1099 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1100 | - { |
|
1101 | - if (empty($class_obj)) { |
|
1102 | - return; |
|
1103 | - } |
|
1104 | - // return newly instantiated class |
|
1105 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1106 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1107 | - $this->{$class_abbreviation} = $class_obj; |
|
1108 | - } else if (property_exists($this, $class_name)) { |
|
1109 | - $this->{$class_name} = $class_obj; |
|
1110 | - } else if ($class_prefix == 'addon') { |
|
1111 | - $this->addons->{$class_name} = $class_obj; |
|
1112 | - } else if ( ! $from_db) { |
|
1113 | - $this->LIB->{$class_name} = $class_obj; |
|
1114 | - } |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1121 | - * |
|
1122 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1123 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1124 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1125 | - * @param array $arguments |
|
1126 | - * @return object |
|
1127 | - */ |
|
1128 | - public static function factory($classname, $arguments = array()) |
|
1129 | - { |
|
1130 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1131 | - if ($loader instanceof Closure) { |
|
1132 | - return $loader($arguments); |
|
1133 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1134 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1135 | - } |
|
1136 | - return null; |
|
1137 | - } |
|
1138 | - |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1143 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1144 | - * |
|
1145 | - * @param string $name |
|
1146 | - * @return EE_Addon |
|
1147 | - */ |
|
1148 | - public function get_addon_by_name($name) |
|
1149 | - { |
|
1150 | - foreach ($this->addons as $addon) { |
|
1151 | - if ($addon->name() == $name) { |
|
1152 | - return $addon; |
|
1153 | - } |
|
1154 | - } |
|
1155 | - return null; |
|
1156 | - } |
|
1157 | - |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * 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 |
|
1162 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1163 | - * |
|
1164 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1165 | - */ |
|
1166 | - public function get_addons_by_name() |
|
1167 | - { |
|
1168 | - $addons = array(); |
|
1169 | - foreach ($this->addons as $addon) { |
|
1170 | - $addons[$addon->name()] = $addon; |
|
1171 | - } |
|
1172 | - return $addons; |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1179 | - * a stale copy of it around |
|
1180 | - * |
|
1181 | - * @param string $model_name |
|
1182 | - * @return \EEM_Base |
|
1183 | - * @throws \EE_Error |
|
1184 | - */ |
|
1185 | - public function reset_model($model_name) |
|
1186 | - { |
|
1187 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1188 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1189 | - return null; |
|
1190 | - } |
|
1191 | - //get that model reset it and make sure we nuke the old reference to it |
|
1192 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1193 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1194 | - } else { |
|
1195 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1196 | - } |
|
1197 | - return $this->LIB->{$model_class_name}; |
|
1198 | - } |
|
1199 | - |
|
1200 | - |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * Resets the registry. |
|
1204 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1205 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1206 | - * - $_dependency_map |
|
1207 | - * - $_class_abbreviations |
|
1208 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1209 | - * - $REQ: Still on the same request so no need to change. |
|
1210 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1211 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1212 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1213 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1214 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1215 | - * switch or on the restore. |
|
1216 | - * - $modules |
|
1217 | - * - $shortcodes |
|
1218 | - * - $widgets |
|
1219 | - * |
|
1220 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1221 | - * the Registry to its state at the beginning of the request |
|
1222 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1223 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1224 | - * currently reinstantiate the singletons at the moment) |
|
1225 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1226 | - * code instead can just change the model context to a different blog id if necessary |
|
1227 | - * @return EE_Registry |
|
1228 | - */ |
|
1229 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1230 | - { |
|
1231 | - $instance = self::instance(); |
|
1232 | - EEH_Activation::reset(); |
|
1233 | - //properties that get reset |
|
1234 | - $instance->_cache_on = true; |
|
1235 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1236 | - $instance->CART = null; |
|
1237 | - $instance->MRM = null; |
|
1238 | - $instance->AssetsRegistry = null; |
|
1239 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1240 | - //messages reset |
|
1241 | - EED_Messages::reset(); |
|
1242 | - if ($reset_models) { |
|
1243 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1244 | - $instance->reset_model($model_name); |
|
1245 | - } |
|
1246 | - } |
|
1247 | - $instance->LIB = new stdClass(); |
|
1248 | - return $instance; |
|
1249 | - } |
|
1250 | - |
|
1251 | - |
|
1252 | - |
|
1253 | - /** |
|
1254 | - * @override magic methods |
|
1255 | - * @return void |
|
1256 | - */ |
|
1257 | - public final function __destruct() |
|
1258 | - { |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * @param $a |
|
1265 | - * @param $b |
|
1266 | - */ |
|
1267 | - public final function __call($a, $b) |
|
1268 | - { |
|
1269 | - } |
|
1270 | - |
|
1271 | - |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * @param $a |
|
1275 | - */ |
|
1276 | - public final function __get($a) |
|
1277 | - { |
|
1278 | - } |
|
1279 | - |
|
1280 | - |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * @param $a |
|
1284 | - * @param $b |
|
1285 | - */ |
|
1286 | - public final function __set($a, $b) |
|
1287 | - { |
|
1288 | - } |
|
1289 | - |
|
1290 | - |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * @param $a |
|
1294 | - */ |
|
1295 | - public final function __isset($a) |
|
1296 | - { |
|
1297 | - } |
|
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 | + * @return \EE_Registry |
|
224 | + */ |
|
225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | + { |
|
227 | + $this->_dependency_map = $dependency_map; |
|
228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize |
|
235 | + */ |
|
236 | + public function initialize() |
|
237 | + { |
|
238 | + $this->_class_abbreviations = apply_filters( |
|
239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | + array( |
|
241 | + 'EE_Config' => 'CFG', |
|
242 | + 'EE_Session' => 'SSN', |
|
243 | + 'EE_Capabilities' => 'CAP', |
|
244 | + 'EE_Cart' => 'CART', |
|
245 | + 'EE_Network_Config' => 'NET_CFG', |
|
246 | + 'EE_Request_Handler' => 'REQ', |
|
247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
250 | + ) |
|
251 | + ); |
|
252 | + // class library |
|
253 | + $this->LIB = new stdClass(); |
|
254 | + $this->addons = new stdClass(); |
|
255 | + $this->modules = new stdClass(); |
|
256 | + $this->shortcodes = new stdClass(); |
|
257 | + $this->widgets = new stdClass(); |
|
258 | + $this->load_core('Base', array(), true); |
|
259 | + // add our request and response objects to the cache |
|
260 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
261 | + $this->_set_cached_class( |
|
262 | + $request_loader(), |
|
263 | + 'EE_Request' |
|
264 | + ); |
|
265 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
266 | + $this->_set_cached_class( |
|
267 | + $response_loader(), |
|
268 | + 'EE_Response' |
|
269 | + ); |
|
270 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * init |
|
277 | + * |
|
278 | + * @access public |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function init() |
|
282 | + { |
|
283 | + // Get current page protocol |
|
284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | + // Output admin-ajax.php URL with same protocol as current page |
|
286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * localize_i18n_js_strings |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function localize_i18n_js_strings() |
|
298 | + { |
|
299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + foreach ($i18n_js_strings as $key => $value) { |
|
301 | + if (is_scalar($value)) { |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + } |
|
304 | + } |
|
305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param mixed string | EED_Module $module |
|
312 | + */ |
|
313 | + public function add_module($module) |
|
314 | + { |
|
315 | + if ($module instanceof EED_Module) { |
|
316 | + $module_class = get_class($module); |
|
317 | + $this->modules->{$module_class} = $module; |
|
318 | + } else { |
|
319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | + $this->load_core('Module_Request_Router'); |
|
321 | + } |
|
322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param string $module_name |
|
330 | + * @return mixed EED_Module | NULL |
|
331 | + */ |
|
332 | + public function get_module($module_name = '') |
|
333 | + { |
|
334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * loads core classes - must be singletons |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param string $class_name - simple class name ie: session |
|
344 | + * @param mixed $arguments |
|
345 | + * @param bool $load_only |
|
346 | + * @return mixed |
|
347 | + */ |
|
348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | + { |
|
350 | + $core_paths = apply_filters( |
|
351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | + array( |
|
353 | + EE_CORE, |
|
354 | + EE_ADMIN, |
|
355 | + EE_CPTS, |
|
356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
357 | + EE_CORE . 'request_stack' . DS, |
|
358 | + EE_CORE . 'middleware' . DS, |
|
359 | + ) |
|
360 | + ); |
|
361 | + // retrieve instantiated class |
|
362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * loads service classes |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @param string $class_name - simple class name ie: session |
|
372 | + * @param mixed $arguments |
|
373 | + * @param bool $load_only |
|
374 | + * @return mixed |
|
375 | + */ |
|
376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | + { |
|
378 | + $service_paths = apply_filters( |
|
379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | + array( |
|
381 | + EE_CORE . 'services' . DS, |
|
382 | + ) |
|
383 | + ); |
|
384 | + // retrieve instantiated class |
|
385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * loads data_migration_scripts |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | + * @param mixed $arguments |
|
396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
397 | + */ |
|
398 | + public function load_dms($class_name, $arguments = array()) |
|
399 | + { |
|
400 | + // retrieve instantiated class |
|
401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * loads object creating classes - must be singletons |
|
408 | + * |
|
409 | + * @param string $class_name - simple class name ie: attendee |
|
410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | + * @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) |
|
413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | + * @return EE_Base_Class | bool |
|
415 | + */ |
|
416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | + { |
|
418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | + EE_CORE, |
|
420 | + EE_CLASSES, |
|
421 | + EE_BUSINESS, |
|
422 | + )); |
|
423 | + // retrieve instantiated class |
|
424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads helper classes - must be singletons |
|
431 | + * |
|
432 | + * @param string $class_name - simple class name ie: price |
|
433 | + * @param mixed $arguments |
|
434 | + * @param bool $load_only |
|
435 | + * @return EEH_Base | bool |
|
436 | + */ |
|
437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | + { |
|
439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | + // retrieve instantiated class |
|
442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * loads core classes - must be singletons |
|
449 | + * |
|
450 | + * @access public |
|
451 | + * @param string $class_name - simple class name ie: session |
|
452 | + * @param mixed $arguments |
|
453 | + * @param bool $load_only |
|
454 | + * @param bool $cache whether to cache the object or not. |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | + { |
|
459 | + $paths = array( |
|
460 | + EE_LIBRARIES, |
|
461 | + EE_LIBRARIES . 'messages' . DS, |
|
462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | + EE_LIBRARIES . 'qtips' . DS, |
|
464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | + ); |
|
466 | + // retrieve instantiated class |
|
467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * loads model classes - must be singletons |
|
474 | + * |
|
475 | + * @param string $class_name - simple class name ie: price |
|
476 | + * @param mixed $arguments |
|
477 | + * @param bool $load_only |
|
478 | + * @return EEM_Base | bool |
|
479 | + */ |
|
480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | + { |
|
482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | + EE_MODELS, |
|
484 | + EE_CORE, |
|
485 | + )); |
|
486 | + // retrieve instantiated class |
|
487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * loads model classes - must be singletons |
|
494 | + * |
|
495 | + * @param string $class_name - simple class name ie: price |
|
496 | + * @param mixed $arguments |
|
497 | + * @param bool $load_only |
|
498 | + * @return mixed | bool |
|
499 | + */ |
|
500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | + { |
|
502 | + $paths = array( |
|
503 | + EE_MODELS . 'fields' . DS, |
|
504 | + EE_MODELS . 'helpers' . DS, |
|
505 | + EE_MODELS . 'relations' . DS, |
|
506 | + EE_MODELS . 'strategies' . DS, |
|
507 | + ); |
|
508 | + // retrieve instantiated class |
|
509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Determines if $model_name is the name of an actual EE model. |
|
516 | + * |
|
517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | + * @return boolean |
|
519 | + */ |
|
520 | + public function is_model_name($model_name) |
|
521 | + { |
|
522 | + return isset($this->models[$model_name]) ? true : false; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * generic class loader |
|
529 | + * |
|
530 | + * @param string $path_to_file - directory path to file location, not including filename |
|
531 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
532 | + * @param string $type - file type - core? class? helper? model? |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @return mixed |
|
536 | + */ |
|
537 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
538 | + { |
|
539 | + // retrieve instantiated class |
|
540 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * load_addon |
|
547 | + * |
|
548 | + * @param string $path_to_file - directory path to file location, not including filename |
|
549 | + * @param string $class_name - full class name ie: My_Class |
|
550 | + * @param string $type - file type - core? class? helper? model? |
|
551 | + * @param mixed $arguments |
|
552 | + * @param bool $load_only |
|
553 | + * @return EE_Addon |
|
554 | + */ |
|
555 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
556 | + { |
|
557 | + // retrieve instantiated class |
|
558 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * instantiates, caches, and automatically resolves dependencies |
|
565 | + * for classes that use a Fully Qualified Class Name. |
|
566 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
567 | + * then you need to use one of the existing load_*() methods |
|
568 | + * which can resolve the classname and filepath from the passed arguments |
|
569 | + * |
|
570 | + * @param bool|string $class_name Fully Qualified Class Name |
|
571 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
572 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
573 | + * @param bool $from_db some classes are instantiated from the db |
|
574 | + * and thus call a different method to instantiate |
|
575 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
576 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
577 | + * @return mixed null = failure to load or instantiate class object. |
|
578 | + * object = class loaded and instantiated successfully. |
|
579 | + * bool = fail or success when $load_only is true |
|
580 | + */ |
|
581 | + public function create( |
|
582 | + $class_name = false, |
|
583 | + $arguments = array(), |
|
584 | + $cache = false, |
|
585 | + $from_db = false, |
|
586 | + $load_only = false, |
|
587 | + $addon = false |
|
588 | + ) { |
|
589 | + $class_name = ltrim($class_name, '\\'); |
|
590 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
591 | + if ( ! class_exists($class_name)) { |
|
592 | + // maybe the class is registered with a preceding \ |
|
593 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | + // still doesn't exist ? |
|
595 | + if ( ! class_exists($class_name)) { |
|
596 | + return null; |
|
597 | + } |
|
598 | + } |
|
599 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
600 | + if ($load_only) { |
|
601 | + return true; |
|
602 | + } |
|
603 | + $addon = $addon ? 'addon' : ''; |
|
604 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
605 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
606 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
607 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
608 | + // return object if it's already cached |
|
609 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
610 | + if ($cached_class !== null) { |
|
611 | + return $cached_class; |
|
612 | + } |
|
613 | + } |
|
614 | + // instantiate the requested object |
|
615 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
616 | + // if caching is turned on OR this class is cached in a class property |
|
617 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
618 | + // save it for later... kinda like gum { : $ |
|
619 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
620 | + } |
|
621 | + $this->_cache_on = true; |
|
622 | + return $class_obj; |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * instantiates, caches, and injects dependencies for classes |
|
629 | + * |
|
630 | + * @param array $file_paths an array of paths to folders to look in |
|
631 | + * @param string $class_prefix EE or EEM or... ??? |
|
632 | + * @param bool|string $class_name $class name |
|
633 | + * @param string $type file type - core? class? helper? model? |
|
634 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
635 | + * @param bool $from_db some classes are instantiated from the db |
|
636 | + * and thus call a different method to instantiate |
|
637 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
638 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
639 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
640 | + * object = class loaded and instantiated successfully. |
|
641 | + * bool = fail or success when $load_only is true |
|
642 | + */ |
|
643 | + protected function _load( |
|
644 | + $file_paths = array(), |
|
645 | + $class_prefix = 'EE_', |
|
646 | + $class_name = false, |
|
647 | + $type = 'class', |
|
648 | + $arguments = array(), |
|
649 | + $from_db = false, |
|
650 | + $cache = true, |
|
651 | + $load_only = false |
|
652 | + ) { |
|
653 | + $class_name = ltrim($class_name, '\\'); |
|
654 | + // strip php file extension |
|
655 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
656 | + // does the class have a prefix ? |
|
657 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
658 | + // make sure $class_prefix is uppercase |
|
659 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
660 | + // add class prefix ONCE!!! |
|
661 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
662 | + } |
|
663 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
664 | + $class_exists = class_exists($class_name); |
|
665 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
666 | + if ($load_only && $class_exists) { |
|
667 | + return true; |
|
668 | + } |
|
669 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
670 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
671 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
672 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
673 | + // return object if it's already cached |
|
674 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
675 | + if ($cached_class !== null) { |
|
676 | + return $cached_class; |
|
677 | + } |
|
678 | + } |
|
679 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
680 | + if ( ! $class_exists) { |
|
681 | + // get full path to file |
|
682 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
683 | + // load the file |
|
684 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
685 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
686 | + if ( ! $loaded || $load_only) { |
|
687 | + // return boolean if only loading, or null if an object was expected |
|
688 | + return $load_only ? $loaded : null; |
|
689 | + } |
|
690 | + } |
|
691 | + // instantiate the requested object |
|
692 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
693 | + if ($this->_cache_on && $cache) { |
|
694 | + // save it for later... kinda like gum { : $ |
|
695 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
696 | + } |
|
697 | + $this->_cache_on = true; |
|
698 | + return $class_obj; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * _get_cached_class |
|
705 | + * attempts to find a cached version of the requested class |
|
706 | + * by looking in the following places: |
|
707 | + * $this->{$class_abbreviation} ie: $this->CART |
|
708 | + * $this->{$class_name} ie: $this->Some_Class |
|
709 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
710 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
711 | + * |
|
712 | + * @access protected |
|
713 | + * @param string $class_name |
|
714 | + * @param string $class_prefix |
|
715 | + * @return mixed |
|
716 | + */ |
|
717 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
718 | + { |
|
719 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
720 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
721 | + } else { |
|
722 | + // have to specify something, but not anything that will conflict |
|
723 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
724 | + } |
|
725 | + // check if class has already been loaded, and return it if it has been |
|
726 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
727 | + return $this->{$class_abbreviation}; |
|
728 | + } else if (isset ($this->{$class_name})) { |
|
729 | + return $this->{$class_name}; |
|
730 | + } else if (isset ($this->LIB->{$class_name})) { |
|
731 | + return $this->LIB->{$class_name}; |
|
732 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
733 | + return $this->addons->{$class_name}; |
|
734 | + } |
|
735 | + return null; |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * _resolve_path |
|
742 | + * attempts to find a full valid filepath for the requested class. |
|
743 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
744 | + * then returns that path if the target file has been found and is readable |
|
745 | + * |
|
746 | + * @access protected |
|
747 | + * @param string $class_name |
|
748 | + * @param string $type |
|
749 | + * @param array $file_paths |
|
750 | + * @return string | bool |
|
751 | + */ |
|
752 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
753 | + { |
|
754 | + // make sure $file_paths is an array |
|
755 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
756 | + // cycle thru paths |
|
757 | + foreach ($file_paths as $key => $file_path) { |
|
758 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
759 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
760 | + // prep file type |
|
761 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
762 | + // build full file path |
|
763 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
764 | + //does the file exist and can be read ? |
|
765 | + if (is_readable($file_paths[$key])) { |
|
766 | + return $file_paths[$key]; |
|
767 | + } |
|
768 | + } |
|
769 | + return false; |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * _require_file |
|
776 | + * basically just performs a require_once() |
|
777 | + * but with some error handling |
|
778 | + * |
|
779 | + * @access protected |
|
780 | + * @param string $path |
|
781 | + * @param string $class_name |
|
782 | + * @param string $type |
|
783 | + * @param array $file_paths |
|
784 | + * @return boolean |
|
785 | + * @throws \EE_Error |
|
786 | + */ |
|
787 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
788 | + { |
|
789 | + // don't give up! you gotta... |
|
790 | + try { |
|
791 | + //does the file exist and can it be read ? |
|
792 | + if ( ! $path) { |
|
793 | + // so sorry, can't find the file |
|
794 | + throw new EE_Error ( |
|
795 | + sprintf( |
|
796 | + __('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'), |
|
797 | + trim($type, '.'), |
|
798 | + $class_name, |
|
799 | + '<br />' . implode(',<br />', $file_paths) |
|
800 | + ) |
|
801 | + ); |
|
802 | + } |
|
803 | + // get the file |
|
804 | + require_once($path); |
|
805 | + // if the class isn't already declared somewhere |
|
806 | + if (class_exists($class_name, false) === false) { |
|
807 | + // so sorry, not a class |
|
808 | + throw new EE_Error( |
|
809 | + sprintf( |
|
810 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
811 | + $type, |
|
812 | + $path, |
|
813 | + $class_name |
|
814 | + ) |
|
815 | + ); |
|
816 | + } |
|
817 | + } catch (EE_Error $e) { |
|
818 | + $e->get_error(); |
|
819 | + return false; |
|
820 | + } |
|
821 | + return true; |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * _create_object |
|
828 | + * Attempts to instantiate the requested class via any of the |
|
829 | + * commonly used instantiation methods employed throughout EE. |
|
830 | + * The priority for instantiation is as follows: |
|
831 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
832 | + * - model objects via their 'new_instance_from_db' method |
|
833 | + * - model objects via their 'new_instance' method |
|
834 | + * - "singleton" classes" via their 'instance' method |
|
835 | + * - standard instantiable classes via their __constructor |
|
836 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
837 | + * then the constructor for the requested class will be examined to determine |
|
838 | + * if any dependencies exist, and if they can be injected. |
|
839 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
840 | + * |
|
841 | + * @access protected |
|
842 | + * @param string $class_name |
|
843 | + * @param array $arguments |
|
844 | + * @param string $type |
|
845 | + * @param bool $from_db |
|
846 | + * @return null | object |
|
847 | + * @throws \EE_Error |
|
848 | + */ |
|
849 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
850 | + { |
|
851 | + $class_obj = null; |
|
852 | + $instantiation_mode = '0) none'; |
|
853 | + // don't give up! you gotta... |
|
854 | + try { |
|
855 | + // create reflection |
|
856 | + $reflector = $this->get_ReflectionClass($class_name); |
|
857 | + // make sure arguments are an array |
|
858 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
859 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
860 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
861 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
862 | + ? $arguments |
|
863 | + : array($arguments); |
|
864 | + // attempt to inject dependencies ? |
|
865 | + if ($this->_dependency_map->has($class_name)) { |
|
866 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
867 | + } |
|
868 | + // instantiate the class if possible |
|
869 | + if ($reflector->isAbstract()) { |
|
870 | + // nothing to instantiate, loading file was enough |
|
871 | + // does not throw an exception so $instantiation_mode is unused |
|
872 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
873 | + $class_obj = true; |
|
874 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
875 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
876 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
877 | + $class_obj = $reflector->newInstance(); |
|
878 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
879 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
880 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
881 | + } else if (method_exists($class_name, 'new_instance')) { |
|
882 | + $instantiation_mode = "4) new_instance()"; |
|
883 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
884 | + } else if (method_exists($class_name, 'instance')) { |
|
885 | + $instantiation_mode = "5) instance()"; |
|
886 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
887 | + } else if ($reflector->isInstantiable()) { |
|
888 | + $instantiation_mode = "6) constructor"; |
|
889 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
890 | + } else { |
|
891 | + // heh ? something's not right ! |
|
892 | + throw new EE_Error( |
|
893 | + sprintf( |
|
894 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
895 | + $type, |
|
896 | + $class_name |
|
897 | + ) |
|
898 | + ); |
|
899 | + } |
|
900 | + } catch (Exception $e) { |
|
901 | + if ( ! $e instanceof EE_Error) { |
|
902 | + $e = new EE_Error( |
|
903 | + sprintf( |
|
904 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
905 | + $class_name, |
|
906 | + '<br />', |
|
907 | + $e->getMessage(), |
|
908 | + $instantiation_mode |
|
909 | + ) |
|
910 | + ); |
|
911 | + } |
|
912 | + $e->get_error(); |
|
913 | + } |
|
914 | + return $class_obj; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
921 | + * @param array $array |
|
922 | + * @return bool |
|
923 | + */ |
|
924 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
925 | + { |
|
926 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * getReflectionClass |
|
933 | + * checks if a ReflectionClass object has already been generated for a class |
|
934 | + * and returns that instead of creating a new one |
|
935 | + * |
|
936 | + * @access public |
|
937 | + * @param string $class_name |
|
938 | + * @return ReflectionClass |
|
939 | + */ |
|
940 | + public function get_ReflectionClass($class_name) |
|
941 | + { |
|
942 | + if ( |
|
943 | + ! isset($this->_reflectors[$class_name]) |
|
944 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
945 | + ) { |
|
946 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
947 | + } |
|
948 | + return $this->_reflectors[$class_name]; |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * _resolve_dependencies |
|
955 | + * examines the constructor for the requested class to determine |
|
956 | + * if any dependencies exist, and if they can be injected. |
|
957 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
958 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
959 | + * For example: |
|
960 | + * if attempting to load a class "Foo" with the following constructor: |
|
961 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
962 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
963 | + * but only IF they are NOT already present in the incoming arguments array, |
|
964 | + * and the correct classes can be loaded |
|
965 | + * |
|
966 | + * @access protected |
|
967 | + * @param ReflectionClass $reflector |
|
968 | + * @param string $class_name |
|
969 | + * @param array $arguments |
|
970 | + * @return array |
|
971 | + * @throws \ReflectionException |
|
972 | + */ |
|
973 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
974 | + { |
|
975 | + // let's examine the constructor |
|
976 | + $constructor = $reflector->getConstructor(); |
|
977 | + // whu? huh? nothing? |
|
978 | + if ( ! $constructor) { |
|
979 | + return $arguments; |
|
980 | + } |
|
981 | + // get constructor parameters |
|
982 | + $params = $constructor->getParameters(); |
|
983 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
984 | + $argument_keys = array_keys($arguments); |
|
985 | + // now loop thru all of the constructors expected parameters |
|
986 | + foreach ($params as $index => $param) { |
|
987 | + // is this a dependency for a specific class ? |
|
988 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
989 | + if ( |
|
990 | + // param is not even a class |
|
991 | + empty($param_class) |
|
992 | + // and something already exists in the incoming arguments for this param |
|
993 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
994 | + ) { |
|
995 | + // so let's skip this argument and move on to the next |
|
996 | + continue; |
|
997 | + } else if ( |
|
998 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
999 | + ! empty($param_class) |
|
1000 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1001 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1002 | + ) { |
|
1003 | + // skip this argument and move on to the next |
|
1004 | + continue; |
|
1005 | + } else if ( |
|
1006 | + // parameter is type hinted as a class, and should be injected |
|
1007 | + ! empty($param_class) |
|
1008 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1009 | + ) { |
|
1010 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1011 | + } else { |
|
1012 | + try { |
|
1013 | + $arguments[$index] = $param->getDefaultValue(); |
|
1014 | + } catch (ReflectionException $e) { |
|
1015 | + throw new ReflectionException( |
|
1016 | + sprintf( |
|
1017 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1018 | + $e->getMessage(), |
|
1019 | + $param->getName() |
|
1020 | + ) |
|
1021 | + ); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + } |
|
1025 | + return $arguments; |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * @access protected |
|
1032 | + * @param string $class_name |
|
1033 | + * @param string $param_class |
|
1034 | + * @param array $arguments |
|
1035 | + * @param mixed $index |
|
1036 | + * @return array |
|
1037 | + */ |
|
1038 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1039 | + { |
|
1040 | + $dependency = null; |
|
1041 | + // should dependency be loaded from cache ? |
|
1042 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1043 | + !== EE_Dependency_Map::load_new_object |
|
1044 | + ? true |
|
1045 | + : false; |
|
1046 | + // we might have a dependency... |
|
1047 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1048 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1049 | + // and grab it if it exists |
|
1050 | + if ($cached_class instanceof $param_class) { |
|
1051 | + $dependency = $cached_class; |
|
1052 | + } else if ($param_class != $class_name) { |
|
1053 | + // obtain the loader method from the dependency map |
|
1054 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1055 | + // is loader a custom closure ? |
|
1056 | + if ($loader instanceof Closure) { |
|
1057 | + $dependency = $loader(); |
|
1058 | + } else { |
|
1059 | + // set the cache on property for the recursive loading call |
|
1060 | + $this->_cache_on = $cache_on; |
|
1061 | + // if not, then let's try and load it via the registry |
|
1062 | + if (method_exists($this, $loader)) { |
|
1063 | + $dependency = $this->{$loader}($param_class); |
|
1064 | + } else { |
|
1065 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1066 | + } |
|
1067 | + } |
|
1068 | + } |
|
1069 | + // did we successfully find the correct dependency ? |
|
1070 | + if ($dependency instanceof $param_class) { |
|
1071 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1072 | + if (isset($argument_keys[$index])) { |
|
1073 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1074 | + } else { |
|
1075 | + $arguments[$index] = $dependency; |
|
1076 | + } |
|
1077 | + } |
|
1078 | + return $arguments; |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * _set_cached_class |
|
1085 | + * attempts to cache the instantiated class locally |
|
1086 | + * in one of the following places, in the following order: |
|
1087 | + * $this->{class_abbreviation} ie: $this->CART |
|
1088 | + * $this->{$class_name} ie: $this->Some_Class |
|
1089 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1090 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1091 | + * |
|
1092 | + * @access protected |
|
1093 | + * @param object $class_obj |
|
1094 | + * @param string $class_name |
|
1095 | + * @param string $class_prefix |
|
1096 | + * @param bool $from_db |
|
1097 | + * @return void |
|
1098 | + */ |
|
1099 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1100 | + { |
|
1101 | + if (empty($class_obj)) { |
|
1102 | + return; |
|
1103 | + } |
|
1104 | + // return newly instantiated class |
|
1105 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1106 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1107 | + $this->{$class_abbreviation} = $class_obj; |
|
1108 | + } else if (property_exists($this, $class_name)) { |
|
1109 | + $this->{$class_name} = $class_obj; |
|
1110 | + } else if ($class_prefix == 'addon') { |
|
1111 | + $this->addons->{$class_name} = $class_obj; |
|
1112 | + } else if ( ! $from_db) { |
|
1113 | + $this->LIB->{$class_name} = $class_obj; |
|
1114 | + } |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1121 | + * |
|
1122 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1123 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1124 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1125 | + * @param array $arguments |
|
1126 | + * @return object |
|
1127 | + */ |
|
1128 | + public static function factory($classname, $arguments = array()) |
|
1129 | + { |
|
1130 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1131 | + if ($loader instanceof Closure) { |
|
1132 | + return $loader($arguments); |
|
1133 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1134 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1135 | + } |
|
1136 | + return null; |
|
1137 | + } |
|
1138 | + |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1143 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1144 | + * |
|
1145 | + * @param string $name |
|
1146 | + * @return EE_Addon |
|
1147 | + */ |
|
1148 | + public function get_addon_by_name($name) |
|
1149 | + { |
|
1150 | + foreach ($this->addons as $addon) { |
|
1151 | + if ($addon->name() == $name) { |
|
1152 | + return $addon; |
|
1153 | + } |
|
1154 | + } |
|
1155 | + return null; |
|
1156 | + } |
|
1157 | + |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * 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 |
|
1162 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1163 | + * |
|
1164 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1165 | + */ |
|
1166 | + public function get_addons_by_name() |
|
1167 | + { |
|
1168 | + $addons = array(); |
|
1169 | + foreach ($this->addons as $addon) { |
|
1170 | + $addons[$addon->name()] = $addon; |
|
1171 | + } |
|
1172 | + return $addons; |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1179 | + * a stale copy of it around |
|
1180 | + * |
|
1181 | + * @param string $model_name |
|
1182 | + * @return \EEM_Base |
|
1183 | + * @throws \EE_Error |
|
1184 | + */ |
|
1185 | + public function reset_model($model_name) |
|
1186 | + { |
|
1187 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1188 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1189 | + return null; |
|
1190 | + } |
|
1191 | + //get that model reset it and make sure we nuke the old reference to it |
|
1192 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1193 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1194 | + } else { |
|
1195 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1196 | + } |
|
1197 | + return $this->LIB->{$model_class_name}; |
|
1198 | + } |
|
1199 | + |
|
1200 | + |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * Resets the registry. |
|
1204 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1205 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1206 | + * - $_dependency_map |
|
1207 | + * - $_class_abbreviations |
|
1208 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1209 | + * - $REQ: Still on the same request so no need to change. |
|
1210 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1211 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1212 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1213 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1214 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1215 | + * switch or on the restore. |
|
1216 | + * - $modules |
|
1217 | + * - $shortcodes |
|
1218 | + * - $widgets |
|
1219 | + * |
|
1220 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1221 | + * the Registry to its state at the beginning of the request |
|
1222 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1223 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1224 | + * currently reinstantiate the singletons at the moment) |
|
1225 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1226 | + * code instead can just change the model context to a different blog id if necessary |
|
1227 | + * @return EE_Registry |
|
1228 | + */ |
|
1229 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1230 | + { |
|
1231 | + $instance = self::instance(); |
|
1232 | + EEH_Activation::reset(); |
|
1233 | + //properties that get reset |
|
1234 | + $instance->_cache_on = true; |
|
1235 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1236 | + $instance->CART = null; |
|
1237 | + $instance->MRM = null; |
|
1238 | + $instance->AssetsRegistry = null; |
|
1239 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1240 | + //messages reset |
|
1241 | + EED_Messages::reset(); |
|
1242 | + if ($reset_models) { |
|
1243 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1244 | + $instance->reset_model($model_name); |
|
1245 | + } |
|
1246 | + } |
|
1247 | + $instance->LIB = new stdClass(); |
|
1248 | + return $instance; |
|
1249 | + } |
|
1250 | + |
|
1251 | + |
|
1252 | + |
|
1253 | + /** |
|
1254 | + * @override magic methods |
|
1255 | + * @return void |
|
1256 | + */ |
|
1257 | + public final function __destruct() |
|
1258 | + { |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + |
|
1263 | + /** |
|
1264 | + * @param $a |
|
1265 | + * @param $b |
|
1266 | + */ |
|
1267 | + public final function __call($a, $b) |
|
1268 | + { |
|
1269 | + } |
|
1270 | + |
|
1271 | + |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * @param $a |
|
1275 | + */ |
|
1276 | + public final function __get($a) |
|
1277 | + { |
|
1278 | + } |
|
1279 | + |
|
1280 | + |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * @param $a |
|
1284 | + * @param $b |
|
1285 | + */ |
|
1286 | + public final function __set($a, $b) |
|
1287 | + { |
|
1288 | + } |
|
1289 | + |
|
1290 | + |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * @param $a |
|
1294 | + */ |
|
1295 | + public final function __isset($a) |
|
1296 | + { |
|
1297 | + } |
|
1298 | 1298 | |
1299 | 1299 | |
1300 | 1300 | |
1301 | - /** |
|
1302 | - * @param $a |
|
1303 | - */ |
|
1304 | - public final function __unset($a) |
|
1305 | - { |
|
1306 | - } |
|
1301 | + /** |
|
1302 | + * @param $a |
|
1303 | + */ |
|
1304 | + public final function __unset($a) |
|
1305 | + { |
|
1306 | + } |
|
1307 | 1307 | |
1308 | 1308 | |
1309 | 1309 | |
1310 | - /** |
|
1311 | - * @return array |
|
1312 | - */ |
|
1313 | - public final function __sleep() |
|
1314 | - { |
|
1315 | - return array(); |
|
1316 | - } |
|
1310 | + /** |
|
1311 | + * @return array |
|
1312 | + */ |
|
1313 | + public final function __sleep() |
|
1314 | + { |
|
1315 | + return array(); |
|
1316 | + } |
|
1317 | 1317 | |
1318 | 1318 | |
1319 | 1319 | |
1320 | - public final function __wakeup() |
|
1321 | - { |
|
1322 | - } |
|
1320 | + public final function __wakeup() |
|
1321 | + { |
|
1322 | + } |
|
1323 | 1323 | |
1324 | 1324 | |
1325 | 1325 | |
1326 | - /** |
|
1327 | - * @return string |
|
1328 | - */ |
|
1329 | - public final function __toString() |
|
1330 | - { |
|
1331 | - return ''; |
|
1332 | - } |
|
1326 | + /** |
|
1327 | + * @return string |
|
1328 | + */ |
|
1329 | + public final function __toString() |
|
1330 | + { |
|
1331 | + return ''; |
|
1332 | + } |
|
1333 | 1333 | |
1334 | 1334 | |
1335 | 1335 | |
1336 | - public final function __invoke() |
|
1337 | - { |
|
1338 | - } |
|
1336 | + public final function __invoke() |
|
1337 | + { |
|
1338 | + } |
|
1339 | 1339 | |
1340 | 1340 | |
1341 | 1341 | |
1342 | - public final static function __set_state($array = array()) |
|
1343 | - { |
|
1344 | - return EE_Registry::instance(); |
|
1345 | - } |
|
1342 | + public final static function __set_state($array = array()) |
|
1343 | + { |
|
1344 | + return EE_Registry::instance(); |
|
1345 | + } |
|
1346 | 1346 | |
1347 | 1347 | |
1348 | 1348 | |
1349 | - public final function __clone() |
|
1350 | - { |
|
1351 | - } |
|
1349 | + public final function __clone() |
|
1350 | + { |
|
1351 | + } |
|
1352 | 1352 | |
1353 | 1353 | |
1354 | 1354 | |
1355 | - /** |
|
1356 | - * @param $a |
|
1357 | - * @param $b |
|
1358 | - */ |
|
1359 | - public final static function __callStatic($a, $b) |
|
1360 | - { |
|
1361 | - } |
|
1355 | + /** |
|
1356 | + * @param $a |
|
1357 | + * @param $b |
|
1358 | + */ |
|
1359 | + public final static function __callStatic($a, $b) |
|
1360 | + { |
|
1361 | + } |
|
1362 | 1362 | |
1363 | 1363 | |
1364 | 1364 | |
1365 | - /** |
|
1366 | - * Gets all the custom post type models defined |
|
1367 | - * |
|
1368 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1369 | - */ |
|
1370 | - public function cpt_models() |
|
1371 | - { |
|
1372 | - $cpt_models = array(); |
|
1373 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1374 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1375 | - $cpt_models[$short_name] = $classname; |
|
1376 | - } |
|
1377 | - } |
|
1378 | - return $cpt_models; |
|
1379 | - } |
|
1365 | + /** |
|
1366 | + * Gets all the custom post type models defined |
|
1367 | + * |
|
1368 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1369 | + */ |
|
1370 | + public function cpt_models() |
|
1371 | + { |
|
1372 | + $cpt_models = array(); |
|
1373 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1374 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1375 | + $cpt_models[$short_name] = $classname; |
|
1376 | + } |
|
1377 | + } |
|
1378 | + return $cpt_models; |
|
1379 | + } |
|
1380 | 1380 | |
1381 | 1381 | |
1382 | 1382 | |
1383 | - /** |
|
1384 | - * @return \EE_Config |
|
1385 | - */ |
|
1386 | - public static function CFG() |
|
1387 | - { |
|
1388 | - return self::instance()->CFG; |
|
1389 | - } |
|
1383 | + /** |
|
1384 | + * @return \EE_Config |
|
1385 | + */ |
|
1386 | + public static function CFG() |
|
1387 | + { |
|
1388 | + return self::instance()->CFG; |
|
1389 | + } |
|
1390 | 1390 | |
1391 | 1391 | |
1392 | 1392 | } |
@@ -296,13 +296,13 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public static function localize_i18n_js_strings() |
298 | 298 | { |
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
299 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
300 | 300 | foreach ($i18n_js_strings as $key => $value) { |
301 | 301 | if (is_scalar($value)) { |
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
303 | 303 | } |
304 | 304 | } |
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
305 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
@@ -353,9 +353,9 @@ discard block |
||
353 | 353 | EE_CORE, |
354 | 354 | EE_ADMIN, |
355 | 355 | EE_CPTS, |
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
356 | + EE_CORE.'data_migration_scripts'.DS, |
|
357 | + EE_CORE.'request_stack'.DS, |
|
358 | + EE_CORE.'middleware'.DS, |
|
359 | 359 | ) |
360 | 360 | ); |
361 | 361 | // retrieve instantiated class |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $service_paths = apply_filters( |
379 | 379 | 'FHEE__EE_Registry__load_service__service_paths', |
380 | 380 | array( |
381 | - EE_CORE . 'services' . DS, |
|
381 | + EE_CORE.'services'.DS, |
|
382 | 382 | ) |
383 | 383 | ); |
384 | 384 | // retrieve instantiated class |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | { |
459 | 459 | $paths = array( |
460 | 460 | EE_LIBRARIES, |
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
461 | + EE_LIBRARIES.'messages'.DS, |
|
462 | + EE_LIBRARIES.'shortcodes'.DS, |
|
463 | + EE_LIBRARIES.'qtips'.DS, |
|
464 | + EE_LIBRARIES.'payment_methods'.DS, |
|
465 | 465 | ); |
466 | 466 | // retrieve instantiated class |
467 | 467 | return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
@@ -500,10 +500,10 @@ discard block |
||
500 | 500 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
501 | 501 | { |
502 | 502 | $paths = array( |
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
503 | + EE_MODELS.'fields'.DS, |
|
504 | + EE_MODELS.'helpers'.DS, |
|
505 | + EE_MODELS.'relations'.DS, |
|
506 | + EE_MODELS.'strategies'.DS, |
|
507 | 507 | ); |
508 | 508 | // retrieve instantiated class |
509 | 509 | return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | $class_name = $this->_dependency_map->get_alias($class_name); |
591 | 591 | if ( ! class_exists($class_name)) { |
592 | 592 | // maybe the class is registered with a preceding \ |
593 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
593 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name; |
|
594 | 594 | // still doesn't exist ? |
595 | 595 | if ( ! class_exists($class_name)) { |
596 | 596 | return null; |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | // instantiate the requested object |
615 | 615 | $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
616 | 616 | // if caching is turned on OR this class is cached in a class property |
617 | - if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) { |
|
617 | + if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[$class_name])) { |
|
618 | 618 | // save it for later... kinda like gum { : $ |
619 | 619 | $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
620 | 620 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | // make sure $class_prefix is uppercase |
659 | 659 | $class_prefix = strtoupper(trim($class_prefix)); |
660 | 660 | // add class prefix ONCE!!! |
661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
662 | 662 | } |
663 | 663 | $class_name = $this->_dependency_map->get_alias($class_name); |
664 | 664 | $class_exists = class_exists($class_name); |
@@ -758,9 +758,9 @@ discard block |
||
758 | 758 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
759 | 759 | $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
760 | 760 | // prep file type |
761 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
761 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
762 | 762 | // build full file path |
763 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
763 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
764 | 764 | //does the file exist and can be read ? |
765 | 765 | if (is_readable($file_paths[$key])) { |
766 | 766 | return $file_paths[$key]; |
@@ -791,12 +791,12 @@ discard block |
||
791 | 791 | //does the file exist and can it be read ? |
792 | 792 | if ( ! $path) { |
793 | 793 | // so sorry, can't find the file |
794 | - throw new EE_Error ( |
|
794 | + throw new EE_Error( |
|
795 | 795 | sprintf( |
796 | 796 | __('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'), |
797 | 797 | trim($type, '.'), |
798 | 798 | $class_name, |
799 | - '<br />' . implode(',<br />', $file_paths) |
|
799 | + '<br />'.implode(',<br />', $file_paths) |
|
800 | 800 | ) |
801 | 801 | ); |
802 | 802 | } |