@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\widgets\EspressoWidget; |
| 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 | /** |
@@ -26,378 +26,378 @@ discard block |
||
| 26 | 26 | final class EE_Front_Controller |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string $_template_path |
|
| 31 | - */ |
|
| 32 | - private $_template_path; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string $_template |
|
| 36 | - */ |
|
| 37 | - private $_template; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @type EE_Registry $Registry |
|
| 41 | - */ |
|
| 42 | - protected $Registry; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @type EE_Request_Handler $Request_Handler |
|
| 46 | - */ |
|
| 47 | - protected $Request_Handler; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
| 51 | - */ |
|
| 52 | - protected $Module_Request_Router; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * class constructor |
|
| 57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 58 | - * |
|
| 59 | - * @access public |
|
| 60 | - * @param \EE_Registry $Registry |
|
| 61 | - * @param \EE_Request_Handler $Request_Handler |
|
| 62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 63 | - */ |
|
| 64 | - public function __construct( |
|
| 65 | - EE_Registry $Registry, |
|
| 66 | - EE_Request_Handler $Request_Handler, |
|
| 67 | - EE_Module_Request_Router $Module_Request_Router |
|
| 68 | - ) { |
|
| 69 | - $this->Registry = $Registry; |
|
| 70 | - $this->Request_Handler = $Request_Handler; |
|
| 71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
| 72 | - // determine how to integrate WP_Query with the EE models |
|
| 73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 74 | - // load other resources and begin to actually run shortcodes and modules |
|
| 75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 76 | - // analyse the incoming WP request |
|
| 77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 78 | - // process request with module factory |
|
| 79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 80 | - // before headers sent |
|
| 81 | - add_action('wp', array($this, 'wp'), 5); |
|
| 82 | - // primarily used to process any content shortcodes |
|
| 83 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
| 84 | - // header |
|
| 85 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 86 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 87 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
| 88 | - // display errors |
|
| 89 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 90 | - // the content |
|
| 91 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 92 | - //exclude our private cpt comments |
|
| 93 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 94 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 95 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 96 | - // action hook EE |
|
| 97 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 98 | - // for checking that browser cookies are enabled |
|
| 99 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return EE_Request_Handler |
|
| 107 | - */ |
|
| 108 | - public function Request_Handler() |
|
| 109 | - { |
|
| 110 | - return $this->Request_Handler; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return EE_Module_Request_Router |
|
| 116 | - */ |
|
| 117 | - public function Module_Request_Router() |
|
| 118 | - { |
|
| 119 | - return $this->Module_Request_Router; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return LegacyShortcodesManager |
|
| 126 | - */ |
|
| 127 | - public function getLegacyShortcodesManager() |
|
| 128 | - { |
|
| 129 | - return EE_Config::getLegacyShortcodesManager(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * filter_wp_comments |
|
| 142 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 143 | - * widgets/queries done on frontend |
|
| 144 | - * |
|
| 145 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 146 | - * @return array array of comment clauses with modifications. |
|
| 147 | - */ |
|
| 148 | - public function filter_wp_comments($clauses) |
|
| 149 | - { |
|
| 150 | - global $wpdb; |
|
| 151 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 152 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 153 | - foreach ($cpts as $cpt => $details) { |
|
| 154 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - return $clauses; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * employ_CPT_Strategy |
|
| 163 | - * |
|
| 164 | - * @access public |
|
| 165 | - * @return void |
|
| 166 | - */ |
|
| 167 | - public function employ_CPT_Strategy() |
|
| 168 | - { |
|
| 169 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 170 | - $this->Registry->load_core('CPT_Strategy'); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 177 | - * |
|
| 178 | - * @param string $url incoming url |
|
| 179 | - * @return string final assembled url |
|
| 180 | - */ |
|
| 181 | - public function maybe_force_admin_ajax_ssl($url) |
|
| 182 | - { |
|
| 183 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 184 | - $url = str_replace('http://', 'https://', $url); |
|
| 185 | - } |
|
| 186 | - return $url; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 199 | - * default priority init phases have run |
|
| 200 | - * |
|
| 201 | - * @access public |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - public function wp_loaded() |
|
| 205 | - { |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 213 | - /** |
|
| 214 | - * _get_request |
|
| 215 | - * |
|
| 216 | - * @access public |
|
| 217 | - * @param WP $WP |
|
| 218 | - * @return void |
|
| 219 | - */ |
|
| 220 | - public function get_request(WP $WP) |
|
| 221 | - { |
|
| 222 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 223 | - $this->Request_Handler->parse_request($WP); |
|
| 224 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 231 | - * |
|
| 232 | - * @access public |
|
| 233 | - * @param WP_Query $WP_Query |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - public function pre_get_posts($WP_Query) |
|
| 237 | - { |
|
| 238 | - // only load Module_Request_Router if this is the main query |
|
| 239 | - if ( |
|
| 240 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 241 | - && $WP_Query->is_main_query() |
|
| 242 | - ) { |
|
| 243 | - // cycle thru module routes |
|
| 244 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 245 | - // determine module and method for route |
|
| 246 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 247 | - if ($module instanceof EED_Module) { |
|
| 248 | - // get registered view for route |
|
| 249 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 250 | - // grab module name |
|
| 251 | - $module_name = $module->module_name(); |
|
| 252 | - // map the module to the module objects |
|
| 253 | - $this->Registry->modules->{$module_name} = $module; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /*********************************************** WP HOOK ***********************************************/ |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * wp - basically last chance to do stuff before headers sent |
|
| 268 | - * |
|
| 269 | - * @access public |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function wp() |
|
| 273 | - { |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * callback for the "template_redirect" hook point |
|
| 284 | - * checks sidebars for EE widgets |
|
| 285 | - * loads resources and assets accordingly |
|
| 286 | - * |
|
| 287 | - * @return void |
|
| 288 | - */ |
|
| 289 | - public function templateRedirect() |
|
| 290 | - { |
|
| 291 | - global $wp_query; |
|
| 292 | - if (empty($wp_query->posts)){ |
|
| 293 | - return; |
|
| 294 | - } |
|
| 295 | - // if we already know this is an espresso page, then load assets |
|
| 296 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
| 297 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
| 298 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
| 299 | - if ( $load_assets){ |
|
| 300 | - wp_enqueue_style('espresso_default'); |
|
| 301 | - wp_enqueue_style('espresso_custom_css'); |
|
| 302 | - wp_enqueue_script('espresso_core'); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * builds list of active widgets then scans active sidebars looking for them |
|
| 310 | - * returns true is an EE widget is found in an active sidebar |
|
| 311 | - * Please Note: this does NOT mean that the sidebar or widget |
|
| 312 | - * is actually in use in a given template, as that is unfortunately not known |
|
| 313 | - * until a sidebar and it's widgets are actually loaded |
|
| 314 | - * |
|
| 315 | - * @return boolean |
|
| 316 | - */ |
|
| 317 | - private function espresso_widgets_in_active_sidebars() |
|
| 318 | - { |
|
| 319 | - $espresso_widgets = array(); |
|
| 320 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
| 321 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
| 322 | - if (is_active_widget(false, false, $id_base)) { |
|
| 323 | - $espresso_widgets[] = $id_base; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
| 327 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
| 328 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
| 329 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
| 330 | - foreach ($espresso_widgets as $espresso_widget) { |
|
| 331 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
| 332 | - return true; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * header_meta_tag |
|
| 346 | - * |
|
| 347 | - * @access public |
|
| 348 | - * @return void |
|
| 349 | - */ |
|
| 350 | - public function header_meta_tag() |
|
| 351 | - { |
|
| 352 | - print( |
|
| 353 | - apply_filters( |
|
| 354 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 355 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 359 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 360 | - //also exclude all critical pages from indexing |
|
| 361 | - if ( |
|
| 362 | - ( |
|
| 363 | - is_tax('espresso_event_type') |
|
| 364 | - && get_option( 'blog_public' ) !== '0' |
|
| 365 | - ) |
|
| 366 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
| 367 | - ) { |
|
| 368 | - print( |
|
| 369 | - apply_filters( |
|
| 370 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 371 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 372 | - ) |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * wp_print_scripts |
|
| 381 | - * |
|
| 382 | - * @return void |
|
| 383 | - */ |
|
| 384 | - public function wp_print_scripts() |
|
| 385 | - { |
|
| 386 | - global $post; |
|
| 387 | - if ( |
|
| 388 | - isset($post->EE_Event) |
|
| 389 | - && $post->EE_Event instanceof EE_Event |
|
| 390 | - && get_post_type() === 'espresso_events' |
|
| 391 | - && is_singular() |
|
| 392 | - ) { |
|
| 393 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
| 29 | + /** |
|
| 30 | + * @var string $_template_path |
|
| 31 | + */ |
|
| 32 | + private $_template_path; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string $_template |
|
| 36 | + */ |
|
| 37 | + private $_template; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @type EE_Registry $Registry |
|
| 41 | + */ |
|
| 42 | + protected $Registry; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @type EE_Request_Handler $Request_Handler |
|
| 46 | + */ |
|
| 47 | + protected $Request_Handler; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
| 51 | + */ |
|
| 52 | + protected $Module_Request_Router; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * class constructor |
|
| 57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 58 | + * |
|
| 59 | + * @access public |
|
| 60 | + * @param \EE_Registry $Registry |
|
| 61 | + * @param \EE_Request_Handler $Request_Handler |
|
| 62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 63 | + */ |
|
| 64 | + public function __construct( |
|
| 65 | + EE_Registry $Registry, |
|
| 66 | + EE_Request_Handler $Request_Handler, |
|
| 67 | + EE_Module_Request_Router $Module_Request_Router |
|
| 68 | + ) { |
|
| 69 | + $this->Registry = $Registry; |
|
| 70 | + $this->Request_Handler = $Request_Handler; |
|
| 71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
| 72 | + // determine how to integrate WP_Query with the EE models |
|
| 73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 74 | + // load other resources and begin to actually run shortcodes and modules |
|
| 75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 76 | + // analyse the incoming WP request |
|
| 77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 78 | + // process request with module factory |
|
| 79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 80 | + // before headers sent |
|
| 81 | + add_action('wp', array($this, 'wp'), 5); |
|
| 82 | + // primarily used to process any content shortcodes |
|
| 83 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
| 84 | + // header |
|
| 85 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 86 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 87 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
| 88 | + // display errors |
|
| 89 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 90 | + // the content |
|
| 91 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 92 | + //exclude our private cpt comments |
|
| 93 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 94 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 95 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 96 | + // action hook EE |
|
| 97 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 98 | + // for checking that browser cookies are enabled |
|
| 99 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 100 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return EE_Request_Handler |
|
| 107 | + */ |
|
| 108 | + public function Request_Handler() |
|
| 109 | + { |
|
| 110 | + return $this->Request_Handler; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return EE_Module_Request_Router |
|
| 116 | + */ |
|
| 117 | + public function Module_Request_Router() |
|
| 118 | + { |
|
| 119 | + return $this->Module_Request_Router; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return LegacyShortcodesManager |
|
| 126 | + */ |
|
| 127 | + public function getLegacyShortcodesManager() |
|
| 128 | + { |
|
| 129 | + return EE_Config::getLegacyShortcodesManager(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * filter_wp_comments |
|
| 142 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 143 | + * widgets/queries done on frontend |
|
| 144 | + * |
|
| 145 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 146 | + * @return array array of comment clauses with modifications. |
|
| 147 | + */ |
|
| 148 | + public function filter_wp_comments($clauses) |
|
| 149 | + { |
|
| 150 | + global $wpdb; |
|
| 151 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 152 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 153 | + foreach ($cpts as $cpt => $details) { |
|
| 154 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + return $clauses; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * employ_CPT_Strategy |
|
| 163 | + * |
|
| 164 | + * @access public |
|
| 165 | + * @return void |
|
| 166 | + */ |
|
| 167 | + public function employ_CPT_Strategy() |
|
| 168 | + { |
|
| 169 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 170 | + $this->Registry->load_core('CPT_Strategy'); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 177 | + * |
|
| 178 | + * @param string $url incoming url |
|
| 179 | + * @return string final assembled url |
|
| 180 | + */ |
|
| 181 | + public function maybe_force_admin_ajax_ssl($url) |
|
| 182 | + { |
|
| 183 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 184 | + $url = str_replace('http://', 'https://', $url); |
|
| 185 | + } |
|
| 186 | + return $url; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 199 | + * default priority init phases have run |
|
| 200 | + * |
|
| 201 | + * @access public |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + public function wp_loaded() |
|
| 205 | + { |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 213 | + /** |
|
| 214 | + * _get_request |
|
| 215 | + * |
|
| 216 | + * @access public |
|
| 217 | + * @param WP $WP |
|
| 218 | + * @return void |
|
| 219 | + */ |
|
| 220 | + public function get_request(WP $WP) |
|
| 221 | + { |
|
| 222 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 223 | + $this->Request_Handler->parse_request($WP); |
|
| 224 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 231 | + * |
|
| 232 | + * @access public |
|
| 233 | + * @param WP_Query $WP_Query |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + public function pre_get_posts($WP_Query) |
|
| 237 | + { |
|
| 238 | + // only load Module_Request_Router if this is the main query |
|
| 239 | + if ( |
|
| 240 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 241 | + && $WP_Query->is_main_query() |
|
| 242 | + ) { |
|
| 243 | + // cycle thru module routes |
|
| 244 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 245 | + // determine module and method for route |
|
| 246 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 247 | + if ($module instanceof EED_Module) { |
|
| 248 | + // get registered view for route |
|
| 249 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 250 | + // grab module name |
|
| 251 | + $module_name = $module->module_name(); |
|
| 252 | + // map the module to the module objects |
|
| 253 | + $this->Registry->modules->{$module_name} = $module; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /*********************************************** WP HOOK ***********************************************/ |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * wp - basically last chance to do stuff before headers sent |
|
| 268 | + * |
|
| 269 | + * @access public |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function wp() |
|
| 273 | + { |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * callback for the "template_redirect" hook point |
|
| 284 | + * checks sidebars for EE widgets |
|
| 285 | + * loads resources and assets accordingly |
|
| 286 | + * |
|
| 287 | + * @return void |
|
| 288 | + */ |
|
| 289 | + public function templateRedirect() |
|
| 290 | + { |
|
| 291 | + global $wp_query; |
|
| 292 | + if (empty($wp_query->posts)){ |
|
| 293 | + return; |
|
| 294 | + } |
|
| 295 | + // if we already know this is an espresso page, then load assets |
|
| 296 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
| 297 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
| 298 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
| 299 | + if ( $load_assets){ |
|
| 300 | + wp_enqueue_style('espresso_default'); |
|
| 301 | + wp_enqueue_style('espresso_custom_css'); |
|
| 302 | + wp_enqueue_script('espresso_core'); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * builds list of active widgets then scans active sidebars looking for them |
|
| 310 | + * returns true is an EE widget is found in an active sidebar |
|
| 311 | + * Please Note: this does NOT mean that the sidebar or widget |
|
| 312 | + * is actually in use in a given template, as that is unfortunately not known |
|
| 313 | + * until a sidebar and it's widgets are actually loaded |
|
| 314 | + * |
|
| 315 | + * @return boolean |
|
| 316 | + */ |
|
| 317 | + private function espresso_widgets_in_active_sidebars() |
|
| 318 | + { |
|
| 319 | + $espresso_widgets = array(); |
|
| 320 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
| 321 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
| 322 | + if (is_active_widget(false, false, $id_base)) { |
|
| 323 | + $espresso_widgets[] = $id_base; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
| 327 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
| 328 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
| 329 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
| 330 | + foreach ($espresso_widgets as $espresso_widget) { |
|
| 331 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
| 332 | + return true; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * header_meta_tag |
|
| 346 | + * |
|
| 347 | + * @access public |
|
| 348 | + * @return void |
|
| 349 | + */ |
|
| 350 | + public function header_meta_tag() |
|
| 351 | + { |
|
| 352 | + print( |
|
| 353 | + apply_filters( |
|
| 354 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 355 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 359 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 360 | + //also exclude all critical pages from indexing |
|
| 361 | + if ( |
|
| 362 | + ( |
|
| 363 | + is_tax('espresso_event_type') |
|
| 364 | + && get_option( 'blog_public' ) !== '0' |
|
| 365 | + ) |
|
| 366 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
| 367 | + ) { |
|
| 368 | + print( |
|
| 369 | + apply_filters( |
|
| 370 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 371 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 372 | + ) |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * wp_print_scripts |
|
| 381 | + * |
|
| 382 | + * @return void |
|
| 383 | + */ |
|
| 384 | + public function wp_print_scripts() |
|
| 385 | + { |
|
| 386 | + global $post; |
|
| 387 | + if ( |
|
| 388 | + isset($post->EE_Event) |
|
| 389 | + && $post->EE_Event instanceof EE_Event |
|
| 390 | + && get_post_type() === 'espresso_events' |
|
| 391 | + && is_singular() |
|
| 392 | + ) { |
|
| 393 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
| 401 | 401 | |
| 402 | 402 | |
| 403 | 403 | |
@@ -408,99 +408,99 @@ discard block |
||
| 408 | 408 | // * @param $the_content |
| 409 | 409 | // * @return string |
| 410 | 410 | // */ |
| 411 | - // public function the_content( $the_content ) { |
|
| 412 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 413 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 414 | - // } |
|
| 415 | - // return $the_content; |
|
| 416 | - // } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * display_errors |
|
| 425 | - * |
|
| 426 | - * @access public |
|
| 427 | - * @return void |
|
| 428 | - */ |
|
| 429 | - public function display_errors() |
|
| 430 | - { |
|
| 431 | - static $shown_already = false; |
|
| 432 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 433 | - if ( |
|
| 434 | - ! $shown_already |
|
| 435 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 436 | - && is_main_query() |
|
| 437 | - && ! is_feed() |
|
| 438 | - && in_the_loop() |
|
| 439 | - && $this->Request_Handler->is_espresso_page() |
|
| 440 | - ) { |
|
| 441 | - echo EE_Error::get_notices(); |
|
| 442 | - $shown_already = true; |
|
| 443 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 444 | - } |
|
| 445 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /*********************************************** UTILITIES ***********************************************/ |
|
| 453 | - /** |
|
| 454 | - * template_include |
|
| 455 | - * |
|
| 456 | - * @access public |
|
| 457 | - * @param string $template_include_path |
|
| 458 | - * @return string |
|
| 459 | - */ |
|
| 460 | - public function template_include($template_include_path = null) |
|
| 461 | - { |
|
| 462 | - if ($this->Request_Handler->is_espresso_page()) { |
|
| 463 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 464 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 465 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 466 | - $this->_template = basename($this->_template_path); |
|
| 467 | - return $this->_template_path; |
|
| 468 | - } |
|
| 469 | - return $template_include_path; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * get_selected_template |
|
| 475 | - * |
|
| 476 | - * @access public |
|
| 477 | - * @param bool $with_path |
|
| 478 | - * @return string |
|
| 479 | - */ |
|
| 480 | - public function get_selected_template($with_path = false) |
|
| 481 | - { |
|
| 482 | - return $with_path ? $this->_template_path : $this->_template; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @deprecated 4.9.26 |
|
| 489 | - * @param string $shortcode_class |
|
| 490 | - * @param \WP $wp |
|
| 491 | - */ |
|
| 492 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
| 493 | - { |
|
| 494 | - \EE_Error::doing_it_wrong( |
|
| 495 | - __METHOD__, |
|
| 496 | - __( |
|
| 497 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
| 498 | - 'event_espresso' |
|
| 499 | - ), |
|
| 500 | - '4.9.26' |
|
| 501 | - ); |
|
| 502 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
| 503 | - } |
|
| 411 | + // public function the_content( $the_content ) { |
|
| 412 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 413 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 414 | + // } |
|
| 415 | + // return $the_content; |
|
| 416 | + // } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * display_errors |
|
| 425 | + * |
|
| 426 | + * @access public |
|
| 427 | + * @return void |
|
| 428 | + */ |
|
| 429 | + public function display_errors() |
|
| 430 | + { |
|
| 431 | + static $shown_already = false; |
|
| 432 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 433 | + if ( |
|
| 434 | + ! $shown_already |
|
| 435 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 436 | + && is_main_query() |
|
| 437 | + && ! is_feed() |
|
| 438 | + && in_the_loop() |
|
| 439 | + && $this->Request_Handler->is_espresso_page() |
|
| 440 | + ) { |
|
| 441 | + echo EE_Error::get_notices(); |
|
| 442 | + $shown_already = true; |
|
| 443 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 444 | + } |
|
| 445 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /*********************************************** UTILITIES ***********************************************/ |
|
| 453 | + /** |
|
| 454 | + * template_include |
|
| 455 | + * |
|
| 456 | + * @access public |
|
| 457 | + * @param string $template_include_path |
|
| 458 | + * @return string |
|
| 459 | + */ |
|
| 460 | + public function template_include($template_include_path = null) |
|
| 461 | + { |
|
| 462 | + if ($this->Request_Handler->is_espresso_page()) { |
|
| 463 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 464 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 465 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 466 | + $this->_template = basename($this->_template_path); |
|
| 467 | + return $this->_template_path; |
|
| 468 | + } |
|
| 469 | + return $template_include_path; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * get_selected_template |
|
| 475 | + * |
|
| 476 | + * @access public |
|
| 477 | + * @param bool $with_path |
|
| 478 | + * @return string |
|
| 479 | + */ |
|
| 480 | + public function get_selected_template($with_path = false) |
|
| 481 | + { |
|
| 482 | + return $with_path ? $this->_template_path : $this->_template; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @deprecated 4.9.26 |
|
| 489 | + * @param string $shortcode_class |
|
| 490 | + * @param \WP $wp |
|
| 491 | + */ |
|
| 492 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
| 493 | + { |
|
| 494 | + \EE_Error::doing_it_wrong( |
|
| 495 | + __METHOD__, |
|
| 496 | + __( |
|
| 497 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
| 498 | + 'event_espresso' |
|
| 499 | + ), |
|
| 500 | + '4.9.26' |
|
| 501 | + ); |
|
| 502 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | 505 | } |
| 506 | 506 | // End of file EE_Front_Controller.core.php |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
| 98 | 98 | // for checking that browser cookies are enabled |
| 99 | 99 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
| 100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 100 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | public function templateRedirect() |
| 290 | 290 | { |
| 291 | 291 | global $wp_query; |
| 292 | - if (empty($wp_query->posts)){ |
|
| 292 | + if (empty($wp_query->posts)) { |
|
| 293 | 293 | return; |
| 294 | 294 | } |
| 295 | 295 | // if we already know this is an espresso page, then load assets |
| 296 | 296 | $load_assets = $this->Request_Handler->is_espresso_page(); |
| 297 | 297 | // if we are already loading assets then just move along, otherwise check for widgets |
| 298 | 298 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
| 299 | - if ( $load_assets){ |
|
| 299 | + if ($load_assets) { |
|
| 300 | 300 | wp_enqueue_style('espresso_default'); |
| 301 | 301 | wp_enqueue_style('espresso_custom_css'); |
| 302 | 302 | wp_enqueue_script('espresso_core'); |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | print( |
| 353 | 353 | apply_filters( |
| 354 | 354 | 'FHEE__EE_Front_Controller__header_meta_tag', |
| 355 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 355 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
| 356 | 356 | ); |
| 357 | 357 | |
| 358 | 358 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | if ( |
| 362 | 362 | ( |
| 363 | 363 | is_tax('espresso_event_type') |
| 364 | - && get_option( 'blog_public' ) !== '0' |
|
| 364 | + && get_option('blog_public') !== '0' |
|
| 365 | 365 | ) |
| 366 | 366 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
| 367 | 367 | ) { |
| 368 | 368 | print( |
| 369 | 369 | apply_filters( |
| 370 | 370 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
| 371 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 371 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
| 372 | 372 | ) |
| 373 | 373 | ); |
| 374 | 374 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | ) { |
| 441 | 441 | echo EE_Error::get_notices(); |
| 442 | 442 | $shown_already = true; |
| 443 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 443 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
| 444 | 444 | } |
| 445 | 445 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
| 446 | 446 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.001'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.001'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -21,749 +21,749 @@ discard block |
||
| 21 | 21 | class EE_Dependency_Map |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * This means that the requested class dependency is not present in the dependency map |
|
| 26 | - */ |
|
| 27 | - const not_registered = 0; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 31 | - */ |
|
| 32 | - const load_new_object = 1; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 37 | - */ |
|
| 38 | - const load_from_cache = 2; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * When registering a dependency, |
|
| 42 | - * this indicates to keep any existing dependencies that already exist, |
|
| 43 | - * and simply discard any new dependencies declared in the incoming data |
|
| 44 | - */ |
|
| 45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * When registering a dependency, |
|
| 49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 50 | - */ |
|
| 51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @type EE_Dependency_Map $_instance |
|
| 57 | - */ |
|
| 58 | - protected static $_instance; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @type EE_Request $request |
|
| 62 | - */ |
|
| 63 | - protected $_request; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @type EE_Response $response |
|
| 67 | - */ |
|
| 68 | - protected $_response; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @type LoaderInterface $loader |
|
| 72 | - */ |
|
| 73 | - protected $loader; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @type array $_dependency_map |
|
| 77 | - */ |
|
| 78 | - protected $_dependency_map = array(); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @type array $_class_loaders |
|
| 82 | - */ |
|
| 83 | - protected $_class_loaders = array(); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @type array $_aliases |
|
| 87 | - */ |
|
| 88 | - protected $_aliases = array(); |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * EE_Dependency_Map constructor. |
|
| 94 | - * |
|
| 95 | - * @param EE_Request $request |
|
| 96 | - * @param EE_Response $response |
|
| 97 | - */ |
|
| 98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 99 | - { |
|
| 100 | - $this->_request = $request; |
|
| 101 | - $this->_response = $response; |
|
| 102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 103 | - do_action('EE_Dependency_Map____construct'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @throws InvalidDataTypeException |
|
| 110 | - * @throws InvalidInterfaceException |
|
| 111 | - * @throws InvalidArgumentException |
|
| 112 | - */ |
|
| 113 | - public function initialize() |
|
| 114 | - { |
|
| 115 | - $this->_register_core_dependencies(); |
|
| 116 | - $this->_register_core_class_loaders(); |
|
| 117 | - $this->_register_core_aliases(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @singleton method used to instantiate class object |
|
| 124 | - * @access public |
|
| 125 | - * @param EE_Request $request |
|
| 126 | - * @param EE_Response $response |
|
| 127 | - * @return EE_Dependency_Map |
|
| 128 | - */ |
|
| 129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 130 | - { |
|
| 131 | - // check if class object is instantiated, and instantiated properly |
|
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 134 | - } |
|
| 135 | - return self::$_instance; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param LoaderInterface $loader |
|
| 142 | - */ |
|
| 143 | - public function setLoader(LoaderInterface $loader) |
|
| 144 | - { |
|
| 145 | - $this->loader = $loader; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param string $class |
|
| 152 | - * @param array $dependencies |
|
| 153 | - * @param int $overwrite |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public static function register_dependencies( |
|
| 157 | - $class, |
|
| 158 | - array $dependencies, |
|
| 159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 160 | - ) { |
|
| 161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 168 | - * to the class specified by the first parameter. |
|
| 169 | - * IMPORTANT !!! |
|
| 170 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 171 | - * the order of the constructor parameters for the class in question. |
|
| 172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 174 | - * |
|
| 175 | - * @param string $class |
|
| 176 | - * @param array $dependencies |
|
| 177 | - * @param int $overwrite |
|
| 178 | - * @return bool |
|
| 179 | - */ |
|
| 180 | - public function registerDependencies( |
|
| 181 | - $class, |
|
| 182 | - array $dependencies, |
|
| 183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 184 | - ) { |
|
| 185 | - $registered = false; |
|
| 186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 188 | - } |
|
| 189 | - // we need to make sure that any aliases used when registering a dependency |
|
| 190 | - // get resolved to the correct class name |
|
| 191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 192 | - $alias = self::$_instance->get_alias($dependency); |
|
| 193 | - if ( |
|
| 194 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 196 | - ) { |
|
| 197 | - unset($dependencies[$dependency]); |
|
| 198 | - $dependencies[$alias] = $load_source; |
|
| 199 | - $registered = true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - // now add our two lists of dependencies together. |
|
| 203 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 204 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 205 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 206 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 207 | - // especially with numerically indexed arrays |
|
| 208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 209 | - // now we need to ensure that the resulting dependencies |
|
| 210 | - // array only has the entries that are required for the class |
|
| 211 | - // so first count how many dependencies were originally registered for the class |
|
| 212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 213 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 215 | - // then truncate the final array to match that count |
|
| 216 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 217 | - // otherwise just take the incoming array because nothing previously existed |
|
| 218 | - : $dependencies; |
|
| 219 | - return $registered; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param string $class_name |
|
| 226 | - * @param string $loader |
|
| 227 | - * @return bool |
|
| 228 | - * @throws DomainException |
|
| 229 | - */ |
|
| 230 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 231 | - { |
|
| 232 | - if (strpos($class_name, '\\') !== false) { |
|
| 233 | - throw new DomainException( |
|
| 234 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 238 | - if ( |
|
| 239 | - ! is_callable($loader) |
|
| 240 | - && ( |
|
| 241 | - strpos($loader, 'load_') !== 0 |
|
| 242 | - || ! method_exists('EE_Registry', $loader) |
|
| 243 | - ) |
|
| 244 | - ) { |
|
| 245 | - throw new DomainException( |
|
| 246 | - sprintf( |
|
| 247 | - esc_html__( |
|
| 248 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 249 | - 'event_espresso' |
|
| 250 | - ), |
|
| 251 | - $loader |
|
| 252 | - ) |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 257 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 258 | - return true; |
|
| 259 | - } |
|
| 260 | - return false; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @return array |
|
| 267 | - */ |
|
| 268 | - public function dependency_map() |
|
| 269 | - { |
|
| 270 | - return $this->_dependency_map; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 277 | - * |
|
| 278 | - * @param string $class_name |
|
| 279 | - * @return boolean |
|
| 280 | - */ |
|
| 281 | - public function has($class_name = '') |
|
| 282 | - { |
|
| 283 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 290 | - * |
|
| 291 | - * @param string $class_name |
|
| 292 | - * @param string $dependency |
|
| 293 | - * @return bool |
|
| 294 | - */ |
|
| 295 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 296 | - { |
|
| 297 | - $dependency = $this->get_alias($dependency); |
|
| 298 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 299 | - ? true |
|
| 300 | - : false; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 307 | - * |
|
| 308 | - * @param string $class_name |
|
| 309 | - * @param string $dependency |
|
| 310 | - * @return int |
|
| 311 | - */ |
|
| 312 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 313 | - { |
|
| 314 | - $dependency = $this->get_alias($dependency); |
|
| 315 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 316 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 317 | - : EE_Dependency_Map::not_registered; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @param string $class_name |
|
| 324 | - * @return string | Closure |
|
| 325 | - */ |
|
| 326 | - public function class_loader($class_name) |
|
| 327 | - { |
|
| 328 | - // don't use loaders for FQCNs |
|
| 329 | - if(strpos($class_name, '\\') !== false){ |
|
| 330 | - return ''; |
|
| 331 | - } |
|
| 332 | - $class_name = $this->get_alias($class_name); |
|
| 333 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @return array |
|
| 340 | - */ |
|
| 341 | - public function class_loaders() |
|
| 342 | - { |
|
| 343 | - return $this->_class_loaders; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * adds an alias for a classname |
|
| 350 | - * |
|
| 351 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 352 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 353 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 354 | - */ |
|
| 355 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 356 | - { |
|
| 357 | - if ($for_class !== '') { |
|
| 358 | - if (! isset($this->_aliases[$for_class])) { |
|
| 359 | - $this->_aliases[$for_class] = array(); |
|
| 360 | - } |
|
| 361 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 362 | - } |
|
| 363 | - $this->_aliases[$class_name] = $alias; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * returns TRUE if the provided class name has an alias |
|
| 370 | - * |
|
| 371 | - * @param string $class_name |
|
| 372 | - * @param string $for_class |
|
| 373 | - * @return bool |
|
| 374 | - */ |
|
| 375 | - public function has_alias($class_name = '', $for_class = '') |
|
| 376 | - { |
|
| 377 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 378 | - || ( |
|
| 379 | - isset($this->_aliases[$class_name]) |
|
| 380 | - && ! is_array($this->_aliases[$class_name]) |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 388 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 389 | - * for example: |
|
| 390 | - * if the following two entries were added to the _aliases array: |
|
| 391 | - * array( |
|
| 392 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 393 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 394 | - * ) |
|
| 395 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 396 | - * to load an instance of 'some\namespace\classname' |
|
| 397 | - * |
|
| 398 | - * @param string $class_name |
|
| 399 | - * @param string $for_class |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function get_alias($class_name = '', $for_class = '') |
|
| 403 | - { |
|
| 404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 405 | - return $class_name; |
|
| 406 | - } |
|
| 407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 408 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 409 | - } |
|
| 410 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 417 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 418 | - * This is done by using the following class constants: |
|
| 419 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 420 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 421 | - */ |
|
| 422 | - protected function _register_core_dependencies() |
|
| 423 | - { |
|
| 424 | - $this->_dependency_map = array( |
|
| 425 | - 'EE_Request_Handler' => array( |
|
| 426 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 427 | - ), |
|
| 428 | - 'EE_System' => array( |
|
| 429 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 430 | - ), |
|
| 431 | - 'EE_Session' => array( |
|
| 432 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 433 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 434 | - ), |
|
| 435 | - 'EE_Cart' => array( |
|
| 436 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 437 | - ), |
|
| 438 | - 'EE_Front_Controller' => array( |
|
| 439 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 440 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 442 | - ), |
|
| 443 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 444 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 445 | - ), |
|
| 446 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 447 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 448 | - ), |
|
| 449 | - 'EE_Message_Resource_Manager' => array( |
|
| 450 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 451 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 452 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EE_Message_Factory' => array( |
|
| 455 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_messages' => array( |
|
| 458 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - ), |
|
| 460 | - 'EE_Messages_Generator' => array( |
|
| 461 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 462 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 465 | - ), |
|
| 466 | - 'EE_Messages_Processor' => array( |
|
| 467 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - ), |
|
| 469 | - 'EE_Messages_Queue' => array( |
|
| 470 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 471 | - ), |
|
| 472 | - 'EE_Messages_Template_Defaults' => array( |
|
| 473 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - ), |
|
| 476 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - ), |
|
| 480 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 481 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 482 | - ), |
|
| 483 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 488 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 489 | - ), |
|
| 490 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 491 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ), |
|
| 494 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 495 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ), |
|
| 497 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 498 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 499 | - ), |
|
| 500 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 501 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 502 | - ), |
|
| 503 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 504 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 505 | - ), |
|
| 506 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 507 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 508 | - ), |
|
| 509 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 510 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ), |
|
| 512 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 513 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - ), |
|
| 515 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 516 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 517 | - ), |
|
| 518 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 519 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 522 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 528 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 531 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 534 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 536 | - ), |
|
| 537 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 540 | - ), |
|
| 541 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 548 | - ), |
|
| 549 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 552 | - ), |
|
| 553 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ), |
|
| 557 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - ), |
|
| 561 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - ), |
|
| 565 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ), |
|
| 569 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - ), |
|
| 573 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 574 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 575 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - ), |
|
| 577 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 578 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | - ), |
|
| 580 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 581 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - ), |
|
| 583 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 584 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - ), |
|
| 586 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 587 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - ), |
|
| 589 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 590 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - ), |
|
| 592 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 593 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - ), |
|
| 595 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 596 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - ), |
|
| 598 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 599 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 602 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 604 | - ), |
|
| 605 | - 'EventEspresso\core\services\validation\EmailValidationService' => array( |
|
| 606 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 608 | - ), |
|
| 609 | - 'EEM_Attendee' => array( |
|
| 610 | - null, |
|
| 611 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EEM_WP_User' => array( |
|
| 614 | - null, |
|
| 615 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 616 | - ), |
|
| 617 | - ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Registers how core classes are loaded. |
|
| 624 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 625 | - * 'EE_Request_Handler' => 'load_core' |
|
| 626 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 627 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 628 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 629 | - * 'Some_Class' => function () { |
|
| 630 | - * return new Some_Class(); |
|
| 631 | - * }, |
|
| 632 | - * This is required for instantiating dependencies |
|
| 633 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 634 | - * 'Required_Interface' => function () { |
|
| 635 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 636 | - * }, |
|
| 637 | - */ |
|
| 638 | - protected function _register_core_class_loaders() |
|
| 639 | - { |
|
| 640 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 641 | - //be used in a closure. |
|
| 642 | - $request = &$this->_request; |
|
| 643 | - $response = &$this->_response; |
|
| 644 | - $loader = &$this->loader; |
|
| 645 | - $this->_class_loaders = array( |
|
| 646 | - //load_core |
|
| 647 | - 'EE_Capabilities' => 'load_core', |
|
| 648 | - 'EE_Encryption' => 'load_core', |
|
| 649 | - 'EE_Front_Controller' => 'load_core', |
|
| 650 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 651 | - 'EE_Registry' => 'load_core', |
|
| 652 | - 'EE_Request' => function () use (&$request) { |
|
| 653 | - return $request; |
|
| 654 | - }, |
|
| 655 | - 'EE_Response' => function () use (&$response) { |
|
| 656 | - return $response; |
|
| 657 | - }, |
|
| 658 | - 'EE_Request_Handler' => 'load_core', |
|
| 659 | - 'EE_Session' => 'load_core', |
|
| 660 | - 'EE_System' => 'load_core', |
|
| 661 | - //load_lib |
|
| 662 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 663 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 664 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 665 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 666 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 667 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 668 | - 'EE_Message_Repository' => 'load_lib', |
|
| 669 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 670 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 671 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 672 | - 'EE_Messages_Generator' => function () { |
|
| 673 | - return EE_Registry::instance()->load_lib( |
|
| 674 | - 'Messages_Generator', |
|
| 675 | - array(), |
|
| 676 | - false, |
|
| 677 | - false |
|
| 678 | - ); |
|
| 679 | - }, |
|
| 680 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 681 | - return EE_Registry::instance()->load_lib( |
|
| 682 | - 'Messages_Template_Defaults', |
|
| 683 | - $arguments, |
|
| 684 | - false, |
|
| 685 | - false |
|
| 686 | - ); |
|
| 687 | - }, |
|
| 688 | - //load_model |
|
| 689 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 690 | - 'EEM_Message_Template' => 'load_model', |
|
| 691 | - //load_helper |
|
| 692 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 693 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 694 | - return new EEH_Parse_Shortcodes(); |
|
| 695 | - } |
|
| 696 | - return null; |
|
| 697 | - }, |
|
| 698 | - 'EE_Template_Config' => function () { |
|
| 699 | - return EE_Config::instance()->template_settings; |
|
| 700 | - }, |
|
| 701 | - 'EE_Currency_Config' => function () { |
|
| 702 | - return EE_Config::instance()->currency; |
|
| 703 | - }, |
|
| 704 | - 'EE_Registration_Config' => function () { |
|
| 705 | - return EE_Config::instance()->registration; |
|
| 706 | - }, |
|
| 707 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 708 | - return $loader; |
|
| 709 | - }, |
|
| 710 | - ); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * can be used for supplying alternate names for classes, |
|
| 717 | - * or for connecting interface names to instantiable classes |
|
| 718 | - */ |
|
| 719 | - protected function _register_core_aliases() |
|
| 720 | - { |
|
| 721 | - $this->_aliases = array( |
|
| 722 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 723 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 724 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 725 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 726 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 727 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 728 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 729 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 730 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 731 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 732 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 733 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 734 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 735 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 736 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 737 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 738 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 739 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 740 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 741 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 742 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 743 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 744 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 745 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 746 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 747 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 748 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 749 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 750 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 751 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\EmailValidatorInterface', |
|
| 752 | - 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' => 'EventEspresso\core\services\validation\EmailValidationService', |
|
| 753 | - ); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 760 | - * request Primarily used by unit tests. |
|
| 761 | - */ |
|
| 762 | - public function reset() |
|
| 763 | - { |
|
| 764 | - $this->_register_core_class_loaders(); |
|
| 765 | - $this->_register_core_dependencies(); |
|
| 766 | - } |
|
| 24 | + /** |
|
| 25 | + * This means that the requested class dependency is not present in the dependency map |
|
| 26 | + */ |
|
| 27 | + const not_registered = 0; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 31 | + */ |
|
| 32 | + const load_new_object = 1; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 37 | + */ |
|
| 38 | + const load_from_cache = 2; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * When registering a dependency, |
|
| 42 | + * this indicates to keep any existing dependencies that already exist, |
|
| 43 | + * and simply discard any new dependencies declared in the incoming data |
|
| 44 | + */ |
|
| 45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * When registering a dependency, |
|
| 49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 50 | + */ |
|
| 51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @type EE_Dependency_Map $_instance |
|
| 57 | + */ |
|
| 58 | + protected static $_instance; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @type EE_Request $request |
|
| 62 | + */ |
|
| 63 | + protected $_request; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @type EE_Response $response |
|
| 67 | + */ |
|
| 68 | + protected $_response; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @type LoaderInterface $loader |
|
| 72 | + */ |
|
| 73 | + protected $loader; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @type array $_dependency_map |
|
| 77 | + */ |
|
| 78 | + protected $_dependency_map = array(); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @type array $_class_loaders |
|
| 82 | + */ |
|
| 83 | + protected $_class_loaders = array(); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @type array $_aliases |
|
| 87 | + */ |
|
| 88 | + protected $_aliases = array(); |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * EE_Dependency_Map constructor. |
|
| 94 | + * |
|
| 95 | + * @param EE_Request $request |
|
| 96 | + * @param EE_Response $response |
|
| 97 | + */ |
|
| 98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 99 | + { |
|
| 100 | + $this->_request = $request; |
|
| 101 | + $this->_response = $response; |
|
| 102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 103 | + do_action('EE_Dependency_Map____construct'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @throws InvalidDataTypeException |
|
| 110 | + * @throws InvalidInterfaceException |
|
| 111 | + * @throws InvalidArgumentException |
|
| 112 | + */ |
|
| 113 | + public function initialize() |
|
| 114 | + { |
|
| 115 | + $this->_register_core_dependencies(); |
|
| 116 | + $this->_register_core_class_loaders(); |
|
| 117 | + $this->_register_core_aliases(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @singleton method used to instantiate class object |
|
| 124 | + * @access public |
|
| 125 | + * @param EE_Request $request |
|
| 126 | + * @param EE_Response $response |
|
| 127 | + * @return EE_Dependency_Map |
|
| 128 | + */ |
|
| 129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 130 | + { |
|
| 131 | + // check if class object is instantiated, and instantiated properly |
|
| 132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 134 | + } |
|
| 135 | + return self::$_instance; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param LoaderInterface $loader |
|
| 142 | + */ |
|
| 143 | + public function setLoader(LoaderInterface $loader) |
|
| 144 | + { |
|
| 145 | + $this->loader = $loader; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param string $class |
|
| 152 | + * @param array $dependencies |
|
| 153 | + * @param int $overwrite |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public static function register_dependencies( |
|
| 157 | + $class, |
|
| 158 | + array $dependencies, |
|
| 159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 160 | + ) { |
|
| 161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 168 | + * to the class specified by the first parameter. |
|
| 169 | + * IMPORTANT !!! |
|
| 170 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 171 | + * the order of the constructor parameters for the class in question. |
|
| 172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 174 | + * |
|
| 175 | + * @param string $class |
|
| 176 | + * @param array $dependencies |
|
| 177 | + * @param int $overwrite |
|
| 178 | + * @return bool |
|
| 179 | + */ |
|
| 180 | + public function registerDependencies( |
|
| 181 | + $class, |
|
| 182 | + array $dependencies, |
|
| 183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 184 | + ) { |
|
| 185 | + $registered = false; |
|
| 186 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 187 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 188 | + } |
|
| 189 | + // we need to make sure that any aliases used when registering a dependency |
|
| 190 | + // get resolved to the correct class name |
|
| 191 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 192 | + $alias = self::$_instance->get_alias($dependency); |
|
| 193 | + if ( |
|
| 194 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 195 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 196 | + ) { |
|
| 197 | + unset($dependencies[$dependency]); |
|
| 198 | + $dependencies[$alias] = $load_source; |
|
| 199 | + $registered = true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + // now add our two lists of dependencies together. |
|
| 203 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 204 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 205 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 206 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 207 | + // especially with numerically indexed arrays |
|
| 208 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 209 | + // now we need to ensure that the resulting dependencies |
|
| 210 | + // array only has the entries that are required for the class |
|
| 211 | + // so first count how many dependencies were originally registered for the class |
|
| 212 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 213 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 214 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 215 | + // then truncate the final array to match that count |
|
| 216 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 217 | + // otherwise just take the incoming array because nothing previously existed |
|
| 218 | + : $dependencies; |
|
| 219 | + return $registered; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param string $class_name |
|
| 226 | + * @param string $loader |
|
| 227 | + * @return bool |
|
| 228 | + * @throws DomainException |
|
| 229 | + */ |
|
| 230 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 231 | + { |
|
| 232 | + if (strpos($class_name, '\\') !== false) { |
|
| 233 | + throw new DomainException( |
|
| 234 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 238 | + if ( |
|
| 239 | + ! is_callable($loader) |
|
| 240 | + && ( |
|
| 241 | + strpos($loader, 'load_') !== 0 |
|
| 242 | + || ! method_exists('EE_Registry', $loader) |
|
| 243 | + ) |
|
| 244 | + ) { |
|
| 245 | + throw new DomainException( |
|
| 246 | + sprintf( |
|
| 247 | + esc_html__( |
|
| 248 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 249 | + 'event_espresso' |
|
| 250 | + ), |
|
| 251 | + $loader |
|
| 252 | + ) |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 256 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 257 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 258 | + return true; |
|
| 259 | + } |
|
| 260 | + return false; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return array |
|
| 267 | + */ |
|
| 268 | + public function dependency_map() |
|
| 269 | + { |
|
| 270 | + return $this->_dependency_map; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 277 | + * |
|
| 278 | + * @param string $class_name |
|
| 279 | + * @return boolean |
|
| 280 | + */ |
|
| 281 | + public function has($class_name = '') |
|
| 282 | + { |
|
| 283 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 290 | + * |
|
| 291 | + * @param string $class_name |
|
| 292 | + * @param string $dependency |
|
| 293 | + * @return bool |
|
| 294 | + */ |
|
| 295 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 296 | + { |
|
| 297 | + $dependency = $this->get_alias($dependency); |
|
| 298 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 299 | + ? true |
|
| 300 | + : false; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 307 | + * |
|
| 308 | + * @param string $class_name |
|
| 309 | + * @param string $dependency |
|
| 310 | + * @return int |
|
| 311 | + */ |
|
| 312 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 313 | + { |
|
| 314 | + $dependency = $this->get_alias($dependency); |
|
| 315 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 316 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 317 | + : EE_Dependency_Map::not_registered; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @param string $class_name |
|
| 324 | + * @return string | Closure |
|
| 325 | + */ |
|
| 326 | + public function class_loader($class_name) |
|
| 327 | + { |
|
| 328 | + // don't use loaders for FQCNs |
|
| 329 | + if(strpos($class_name, '\\') !== false){ |
|
| 330 | + return ''; |
|
| 331 | + } |
|
| 332 | + $class_name = $this->get_alias($class_name); |
|
| 333 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @return array |
|
| 340 | + */ |
|
| 341 | + public function class_loaders() |
|
| 342 | + { |
|
| 343 | + return $this->_class_loaders; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * adds an alias for a classname |
|
| 350 | + * |
|
| 351 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 352 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 353 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 354 | + */ |
|
| 355 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 356 | + { |
|
| 357 | + if ($for_class !== '') { |
|
| 358 | + if (! isset($this->_aliases[$for_class])) { |
|
| 359 | + $this->_aliases[$for_class] = array(); |
|
| 360 | + } |
|
| 361 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 362 | + } |
|
| 363 | + $this->_aliases[$class_name] = $alias; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * returns TRUE if the provided class name has an alias |
|
| 370 | + * |
|
| 371 | + * @param string $class_name |
|
| 372 | + * @param string $for_class |
|
| 373 | + * @return bool |
|
| 374 | + */ |
|
| 375 | + public function has_alias($class_name = '', $for_class = '') |
|
| 376 | + { |
|
| 377 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 378 | + || ( |
|
| 379 | + isset($this->_aliases[$class_name]) |
|
| 380 | + && ! is_array($this->_aliases[$class_name]) |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 388 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 389 | + * for example: |
|
| 390 | + * if the following two entries were added to the _aliases array: |
|
| 391 | + * array( |
|
| 392 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 393 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 394 | + * ) |
|
| 395 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 396 | + * to load an instance of 'some\namespace\classname' |
|
| 397 | + * |
|
| 398 | + * @param string $class_name |
|
| 399 | + * @param string $for_class |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function get_alias($class_name = '', $for_class = '') |
|
| 403 | + { |
|
| 404 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 405 | + return $class_name; |
|
| 406 | + } |
|
| 407 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 408 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 409 | + } |
|
| 410 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 417 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 418 | + * This is done by using the following class constants: |
|
| 419 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 420 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 421 | + */ |
|
| 422 | + protected function _register_core_dependencies() |
|
| 423 | + { |
|
| 424 | + $this->_dependency_map = array( |
|
| 425 | + 'EE_Request_Handler' => array( |
|
| 426 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 427 | + ), |
|
| 428 | + 'EE_System' => array( |
|
| 429 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 430 | + ), |
|
| 431 | + 'EE_Session' => array( |
|
| 432 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 433 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 434 | + ), |
|
| 435 | + 'EE_Cart' => array( |
|
| 436 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 437 | + ), |
|
| 438 | + 'EE_Front_Controller' => array( |
|
| 439 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 440 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 442 | + ), |
|
| 443 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 444 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 445 | + ), |
|
| 446 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 447 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 448 | + ), |
|
| 449 | + 'EE_Message_Resource_Manager' => array( |
|
| 450 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 451 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 452 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EE_Message_Factory' => array( |
|
| 455 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_messages' => array( |
|
| 458 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + ), |
|
| 460 | + 'EE_Messages_Generator' => array( |
|
| 461 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 462 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 465 | + ), |
|
| 466 | + 'EE_Messages_Processor' => array( |
|
| 467 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + ), |
|
| 469 | + 'EE_Messages_Queue' => array( |
|
| 470 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 471 | + ), |
|
| 472 | + 'EE_Messages_Template_Defaults' => array( |
|
| 473 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + ), |
|
| 476 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + ), |
|
| 480 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 481 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 482 | + ), |
|
| 483 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 488 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 489 | + ), |
|
| 490 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 491 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ), |
|
| 494 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 495 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ), |
|
| 497 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 498 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 499 | + ), |
|
| 500 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 501 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 502 | + ), |
|
| 503 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 504 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 505 | + ), |
|
| 506 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 507 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 508 | + ), |
|
| 509 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 510 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ), |
|
| 512 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 513 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + ), |
|
| 515 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 516 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 517 | + ), |
|
| 518 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 519 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 522 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 528 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 531 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 534 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 536 | + ), |
|
| 537 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 540 | + ), |
|
| 541 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 548 | + ), |
|
| 549 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 552 | + ), |
|
| 553 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ), |
|
| 557 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + ), |
|
| 561 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + ), |
|
| 565 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ), |
|
| 569 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + ), |
|
| 573 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 574 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 575 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + ), |
|
| 577 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 578 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | + ), |
|
| 580 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 581 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + ), |
|
| 583 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 584 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + ), |
|
| 586 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 587 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + ), |
|
| 589 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 590 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + ), |
|
| 592 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 593 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + ), |
|
| 595 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 596 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + ), |
|
| 598 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 599 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 602 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 604 | + ), |
|
| 605 | + 'EventEspresso\core\services\validation\EmailValidationService' => array( |
|
| 606 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 608 | + ), |
|
| 609 | + 'EEM_Attendee' => array( |
|
| 610 | + null, |
|
| 611 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EEM_WP_User' => array( |
|
| 614 | + null, |
|
| 615 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 616 | + ), |
|
| 617 | + ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * Registers how core classes are loaded. |
|
| 624 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 625 | + * 'EE_Request_Handler' => 'load_core' |
|
| 626 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 627 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 628 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 629 | + * 'Some_Class' => function () { |
|
| 630 | + * return new Some_Class(); |
|
| 631 | + * }, |
|
| 632 | + * This is required for instantiating dependencies |
|
| 633 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 634 | + * 'Required_Interface' => function () { |
|
| 635 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 636 | + * }, |
|
| 637 | + */ |
|
| 638 | + protected function _register_core_class_loaders() |
|
| 639 | + { |
|
| 640 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 641 | + //be used in a closure. |
|
| 642 | + $request = &$this->_request; |
|
| 643 | + $response = &$this->_response; |
|
| 644 | + $loader = &$this->loader; |
|
| 645 | + $this->_class_loaders = array( |
|
| 646 | + //load_core |
|
| 647 | + 'EE_Capabilities' => 'load_core', |
|
| 648 | + 'EE_Encryption' => 'load_core', |
|
| 649 | + 'EE_Front_Controller' => 'load_core', |
|
| 650 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 651 | + 'EE_Registry' => 'load_core', |
|
| 652 | + 'EE_Request' => function () use (&$request) { |
|
| 653 | + return $request; |
|
| 654 | + }, |
|
| 655 | + 'EE_Response' => function () use (&$response) { |
|
| 656 | + return $response; |
|
| 657 | + }, |
|
| 658 | + 'EE_Request_Handler' => 'load_core', |
|
| 659 | + 'EE_Session' => 'load_core', |
|
| 660 | + 'EE_System' => 'load_core', |
|
| 661 | + //load_lib |
|
| 662 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 663 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 664 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 665 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 666 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 667 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 668 | + 'EE_Message_Repository' => 'load_lib', |
|
| 669 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 670 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 671 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 672 | + 'EE_Messages_Generator' => function () { |
|
| 673 | + return EE_Registry::instance()->load_lib( |
|
| 674 | + 'Messages_Generator', |
|
| 675 | + array(), |
|
| 676 | + false, |
|
| 677 | + false |
|
| 678 | + ); |
|
| 679 | + }, |
|
| 680 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 681 | + return EE_Registry::instance()->load_lib( |
|
| 682 | + 'Messages_Template_Defaults', |
|
| 683 | + $arguments, |
|
| 684 | + false, |
|
| 685 | + false |
|
| 686 | + ); |
|
| 687 | + }, |
|
| 688 | + //load_model |
|
| 689 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 690 | + 'EEM_Message_Template' => 'load_model', |
|
| 691 | + //load_helper |
|
| 692 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 693 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 694 | + return new EEH_Parse_Shortcodes(); |
|
| 695 | + } |
|
| 696 | + return null; |
|
| 697 | + }, |
|
| 698 | + 'EE_Template_Config' => function () { |
|
| 699 | + return EE_Config::instance()->template_settings; |
|
| 700 | + }, |
|
| 701 | + 'EE_Currency_Config' => function () { |
|
| 702 | + return EE_Config::instance()->currency; |
|
| 703 | + }, |
|
| 704 | + 'EE_Registration_Config' => function () { |
|
| 705 | + return EE_Config::instance()->registration; |
|
| 706 | + }, |
|
| 707 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 708 | + return $loader; |
|
| 709 | + }, |
|
| 710 | + ); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * can be used for supplying alternate names for classes, |
|
| 717 | + * or for connecting interface names to instantiable classes |
|
| 718 | + */ |
|
| 719 | + protected function _register_core_aliases() |
|
| 720 | + { |
|
| 721 | + $this->_aliases = array( |
|
| 722 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 723 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 724 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 725 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 726 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 727 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 728 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 729 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 730 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 731 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 732 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 733 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 734 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 735 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 736 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 737 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 738 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 739 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 740 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 741 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 742 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 743 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 744 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 745 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 746 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 747 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 748 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 749 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 750 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 751 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\EmailValidatorInterface', |
|
| 752 | + 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' => 'EventEspresso\core\services\validation\EmailValidationService', |
|
| 753 | + ); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 760 | + * request Primarily used by unit tests. |
|
| 761 | + */ |
|
| 762 | + public function reset() |
|
| 763 | + { |
|
| 764 | + $this->_register_core_class_loaders(); |
|
| 765 | + $this->_register_core_dependencies(); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | 769 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 130 | 130 | { |
| 131 | 131 | // check if class object is instantiated, and instantiated properly |
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | 133 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 134 | 134 | } |
| 135 | 135 | return self::$_instance; |
@@ -183,16 +183,16 @@ discard block |
||
| 183 | 183 | $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
| 184 | 184 | ) { |
| 185 | 185 | $registered = false; |
| 186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 186 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
| 187 | + self::$_instance->_dependency_map[$class] = array(); |
|
| 188 | 188 | } |
| 189 | 189 | // we need to make sure that any aliases used when registering a dependency |
| 190 | 190 | // get resolved to the correct class name |
| 191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 191 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 192 | 192 | $alias = self::$_instance->get_alias($dependency); |
| 193 | 193 | if ( |
| 194 | 194 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
| 195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 195 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
| 196 | 196 | ) { |
| 197 | 197 | unset($dependencies[$dependency]); |
| 198 | 198 | $dependencies[$alias] = $load_source; |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
| 206 | 206 | // Union is way faster than array_merge() but should be used with caution... |
| 207 | 207 | // especially with numerically indexed arrays |
| 208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 208 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
| 209 | 209 | // now we need to ensure that the resulting dependencies |
| 210 | 210 | // array only has the entries that are required for the class |
| 211 | 211 | // so first count how many dependencies were originally registered for the class |
| 212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 212 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
| 213 | 213 | // if that count is non-zero (meaning dependencies were already registered) |
| 214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 214 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
| 215 | 215 | // then truncate the final array to match that count |
| 216 | 216 | ? array_slice($dependencies, 0, $dependency_count) |
| 217 | 217 | // otherwise just take the incoming array because nothing previously existed |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | ); |
| 254 | 254 | } |
| 255 | 255 | $class_name = self::$_instance->get_alias($class_name); |
| 256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 256 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 257 | 257 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 258 | 258 | return true; |
| 259 | 259 | } |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | public function class_loader($class_name) |
| 327 | 327 | { |
| 328 | 328 | // don't use loaders for FQCNs |
| 329 | - if(strpos($class_name, '\\') !== false){ |
|
| 329 | + if (strpos($class_name, '\\') !== false) { |
|
| 330 | 330 | return ''; |
| 331 | 331 | } |
| 332 | 332 | $class_name = $this->get_alias($class_name); |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | public function add_alias($class_name, $alias, $for_class = '') |
| 356 | 356 | { |
| 357 | 357 | if ($for_class !== '') { |
| 358 | - if (! isset($this->_aliases[$for_class])) { |
|
| 358 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 359 | 359 | $this->_aliases[$for_class] = array(); |
| 360 | 360 | } |
| 361 | 361 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -401,10 +401,10 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | public function get_alias($class_name = '', $for_class = '') |
| 403 | 403 | { |
| 404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 404 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 405 | 405 | return $class_name; |
| 406 | 406 | } |
| 407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 407 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
| 408 | 408 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
| 409 | 409 | } |
| 410 | 410 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -649,10 +649,10 @@ discard block |
||
| 649 | 649 | 'EE_Front_Controller' => 'load_core', |
| 650 | 650 | 'EE_Module_Request_Router' => 'load_core', |
| 651 | 651 | 'EE_Registry' => 'load_core', |
| 652 | - 'EE_Request' => function () use (&$request) { |
|
| 652 | + 'EE_Request' => function() use (&$request) { |
|
| 653 | 653 | return $request; |
| 654 | 654 | }, |
| 655 | - 'EE_Response' => function () use (&$response) { |
|
| 655 | + 'EE_Response' => function() use (&$response) { |
|
| 656 | 656 | return $response; |
| 657 | 657 | }, |
| 658 | 658 | 'EE_Request_Handler' => 'load_core', |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | 'EE_Messages_Queue' => 'load_lib', |
| 670 | 670 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 671 | 671 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 672 | - 'EE_Messages_Generator' => function () { |
|
| 672 | + 'EE_Messages_Generator' => function() { |
|
| 673 | 673 | return EE_Registry::instance()->load_lib( |
| 674 | 674 | 'Messages_Generator', |
| 675 | 675 | array(), |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | false |
| 678 | 678 | ); |
| 679 | 679 | }, |
| 680 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 680 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 681 | 681 | return EE_Registry::instance()->load_lib( |
| 682 | 682 | 'Messages_Template_Defaults', |
| 683 | 683 | $arguments, |
@@ -689,22 +689,22 @@ discard block |
||
| 689 | 689 | 'EEM_Message_Template_Group' => 'load_model', |
| 690 | 690 | 'EEM_Message_Template' => 'load_model', |
| 691 | 691 | //load_helper |
| 692 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 692 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 693 | 693 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 694 | 694 | return new EEH_Parse_Shortcodes(); |
| 695 | 695 | } |
| 696 | 696 | return null; |
| 697 | 697 | }, |
| 698 | - 'EE_Template_Config' => function () { |
|
| 698 | + 'EE_Template_Config' => function() { |
|
| 699 | 699 | return EE_Config::instance()->template_settings; |
| 700 | 700 | }, |
| 701 | - 'EE_Currency_Config' => function () { |
|
| 701 | + 'EE_Currency_Config' => function() { |
|
| 702 | 702 | return EE_Config::instance()->currency; |
| 703 | 703 | }, |
| 704 | - 'EE_Registration_Config' => function () { |
|
| 704 | + 'EE_Registration_Config' => function() { |
|
| 705 | 705 | return EE_Config::instance()->registration; |
| 706 | 706 | }, |
| 707 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 707 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
| 708 | 708 | return $loader; |
| 709 | 709 | }, |
| 710 | 710 | ); |
@@ -17,230 +17,230 @@ |
||
| 17 | 17 | class Benchmark |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * array containing the start time for the timers |
|
| 22 | - */ |
|
| 23 | - private static $start_times; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * array containing all the timer'd times, which can be outputted via show_times() |
|
| 27 | - */ |
|
| 28 | - private static $times = array(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected static $memory_usage = array(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * whether to benchmark code or not |
|
| 39 | - */ |
|
| 40 | - public static function doNotRun() |
|
| 41 | - { |
|
| 42 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * resetTimes |
|
| 49 | - */ |
|
| 50 | - public static function resetTimes() |
|
| 51 | - { |
|
| 52 | - Benchmark::$times = array(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 59 | - * |
|
| 60 | - * @param null $timer_name |
|
| 61 | - */ |
|
| 62 | - public static function startTimer($timer_name = null) |
|
| 63 | - { |
|
| 64 | - if (Benchmark::doNotRun()) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 68 | - Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 75 | - * |
|
| 76 | - * @param string $timer_name |
|
| 77 | - */ |
|
| 78 | - public static function stopTimer($timer_name = '') |
|
| 79 | - { |
|
| 80 | - if (Benchmark::doNotRun()) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 84 | - if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 85 | - $start_time = Benchmark::$start_times[$timer_name]; |
|
| 86 | - unset(Benchmark::$start_times[$timer_name]); |
|
| 87 | - } else { |
|
| 88 | - $start_time = array_pop(Benchmark::$start_times); |
|
| 89 | - } |
|
| 90 | - Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Measure the memory usage by PHP so far. |
|
| 97 | - * |
|
| 98 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 99 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public static function measureMemory($label, $output_now = false) |
|
| 103 | - { |
|
| 104 | - if (Benchmark::doNotRun()) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 108 | - Benchmark::$memory_usage[$label] = $memory_used; |
|
| 109 | - if ($output_now) { |
|
| 110 | - echo defined('EE_TESTS_DIR') ? "\r\n " : '<br />'; |
|
| 111 | - echo "$label : $memory_used"; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * will display the benchmarking results at shutdown |
|
| 119 | - * |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public static function displayResultsAtShutdown() |
|
| 123 | - { |
|
| 124 | - add_action( |
|
| 125 | - 'shutdown', |
|
| 126 | - function () { |
|
| 127 | - Benchmark::displayResults(); |
|
| 128 | - } |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * displayResults |
|
| 136 | - * |
|
| 137 | - * @param bool $echo |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public static function displayResults($echo = true) |
|
| 141 | - { |
|
| 142 | - if (Benchmark::doNotRun()) { |
|
| 143 | - return ''; |
|
| 144 | - } |
|
| 145 | - $output = ''; |
|
| 146 | - if (! empty(Benchmark::$times)) { |
|
| 147 | - $total = 0; |
|
| 148 | - $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'; |
|
| 149 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 150 | - $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />'; |
|
| 151 | - $total += $total_time; |
|
| 152 | - } |
|
| 153 | - $output .= '<br />'; |
|
| 154 | - $output .= '<h4>TOTAL TIME</h4>'; |
|
| 155 | - $output .= Benchmark::formatTime('', $total); |
|
| 156 | - $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 157 | - $output .= '<br />'; |
|
| 158 | - $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 159 | - $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 160 | - $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 161 | - $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 162 | - $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 163 | - $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 164 | - $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 165 | - } |
|
| 166 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 167 | - $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage); |
|
| 168 | - } |
|
| 169 | - if (empty($output)) { |
|
| 170 | - return ''; |
|
| 171 | - } |
|
| 172 | - $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 173 | - . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;') |
|
| 174 | - . ' padding:2em;">' |
|
| 175 | - . '<h4>BENCHMARKING</h4>' |
|
| 176 | - . $output |
|
| 177 | - . '</div>'; |
|
| 178 | - if ($echo) { |
|
| 179 | - echo $output; |
|
| 180 | - return ''; |
|
| 181 | - } |
|
| 182 | - return $output; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 189 | - * |
|
| 190 | - * @param int $size |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public static function convert($size) |
|
| 194 | - { |
|
| 195 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 196 | - return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)]; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param string $timer_name |
|
| 203 | - * @param float $total_time |
|
| 204 | - * @return string |
|
| 205 | - */ |
|
| 206 | - public static function formatTime($timer_name, $total_time) |
|
| 207 | - { |
|
| 208 | - $total_time *= 1000; |
|
| 209 | - switch ($total_time) { |
|
| 210 | - case $total_time > 12500 : |
|
| 211 | - $color = 'red'; |
|
| 212 | - $bold = 'bold'; |
|
| 213 | - break; |
|
| 214 | - case $total_time > 2500 : |
|
| 215 | - $color = 'darkorange'; |
|
| 216 | - $bold = 'bold'; |
|
| 217 | - break; |
|
| 218 | - case $total_time > 500 : |
|
| 219 | - $color = 'gold'; |
|
| 220 | - $bold = 'bold'; |
|
| 221 | - break; |
|
| 222 | - case $total_time > 100 : |
|
| 223 | - $color = 'limegreen'; |
|
| 224 | - $bold = 'normal'; |
|
| 225 | - break; |
|
| 226 | - case $total_time > 20 : |
|
| 227 | - $color = 'deepskyblue'; |
|
| 228 | - $bold = 'normal'; |
|
| 229 | - break; |
|
| 230 | - default : |
|
| 231 | - $color = 'mediumpurple'; |
|
| 232 | - $bold = 'normal'; |
|
| 233 | - break; |
|
| 234 | - } |
|
| 235 | - return '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 236 | - . $color |
|
| 237 | - . '; font-weight:' |
|
| 238 | - . $bold |
|
| 239 | - . '; font-size:1.2em;">' |
|
| 240 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 241 | - . '</span> ' |
|
| 242 | - . $timer_name; |
|
| 243 | - } |
|
| 20 | + /** |
|
| 21 | + * array containing the start time for the timers |
|
| 22 | + */ |
|
| 23 | + private static $start_times; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * array containing all the timer'd times, which can be outputted via show_times() |
|
| 27 | + */ |
|
| 28 | + private static $times = array(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected static $memory_usage = array(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * whether to benchmark code or not |
|
| 39 | + */ |
|
| 40 | + public static function doNotRun() |
|
| 41 | + { |
|
| 42 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * resetTimes |
|
| 49 | + */ |
|
| 50 | + public static function resetTimes() |
|
| 51 | + { |
|
| 52 | + Benchmark::$times = array(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 59 | + * |
|
| 60 | + * @param null $timer_name |
|
| 61 | + */ |
|
| 62 | + public static function startTimer($timer_name = null) |
|
| 63 | + { |
|
| 64 | + if (Benchmark::doNotRun()) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 68 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 75 | + * |
|
| 76 | + * @param string $timer_name |
|
| 77 | + */ |
|
| 78 | + public static function stopTimer($timer_name = '') |
|
| 79 | + { |
|
| 80 | + if (Benchmark::doNotRun()) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 84 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 85 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
| 86 | + unset(Benchmark::$start_times[$timer_name]); |
|
| 87 | + } else { |
|
| 88 | + $start_time = array_pop(Benchmark::$start_times); |
|
| 89 | + } |
|
| 90 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Measure the memory usage by PHP so far. |
|
| 97 | + * |
|
| 98 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 99 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public static function measureMemory($label, $output_now = false) |
|
| 103 | + { |
|
| 104 | + if (Benchmark::doNotRun()) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 108 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
| 109 | + if ($output_now) { |
|
| 110 | + echo defined('EE_TESTS_DIR') ? "\r\n " : '<br />'; |
|
| 111 | + echo "$label : $memory_used"; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * will display the benchmarking results at shutdown |
|
| 119 | + * |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public static function displayResultsAtShutdown() |
|
| 123 | + { |
|
| 124 | + add_action( |
|
| 125 | + 'shutdown', |
|
| 126 | + function () { |
|
| 127 | + Benchmark::displayResults(); |
|
| 128 | + } |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * displayResults |
|
| 136 | + * |
|
| 137 | + * @param bool $echo |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public static function displayResults($echo = true) |
|
| 141 | + { |
|
| 142 | + if (Benchmark::doNotRun()) { |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | + $output = ''; |
|
| 146 | + if (! empty(Benchmark::$times)) { |
|
| 147 | + $total = 0; |
|
| 148 | + $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'; |
|
| 149 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 150 | + $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />'; |
|
| 151 | + $total += $total_time; |
|
| 152 | + } |
|
| 153 | + $output .= '<br />'; |
|
| 154 | + $output .= '<h4>TOTAL TIME</h4>'; |
|
| 155 | + $output .= Benchmark::formatTime('', $total); |
|
| 156 | + $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 157 | + $output .= '<br />'; |
|
| 158 | + $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 159 | + $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 160 | + $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 161 | + $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 162 | + $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 163 | + $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 164 | + $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 165 | + } |
|
| 166 | + if (! empty(Benchmark::$memory_usage)) { |
|
| 167 | + $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage); |
|
| 168 | + } |
|
| 169 | + if (empty($output)) { |
|
| 170 | + return ''; |
|
| 171 | + } |
|
| 172 | + $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 173 | + . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;') |
|
| 174 | + . ' padding:2em;">' |
|
| 175 | + . '<h4>BENCHMARKING</h4>' |
|
| 176 | + . $output |
|
| 177 | + . '</div>'; |
|
| 178 | + if ($echo) { |
|
| 179 | + echo $output; |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 182 | + return $output; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 189 | + * |
|
| 190 | + * @param int $size |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public static function convert($size) |
|
| 194 | + { |
|
| 195 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 196 | + return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)]; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param string $timer_name |
|
| 203 | + * @param float $total_time |
|
| 204 | + * @return string |
|
| 205 | + */ |
|
| 206 | + public static function formatTime($timer_name, $total_time) |
|
| 207 | + { |
|
| 208 | + $total_time *= 1000; |
|
| 209 | + switch ($total_time) { |
|
| 210 | + case $total_time > 12500 : |
|
| 211 | + $color = 'red'; |
|
| 212 | + $bold = 'bold'; |
|
| 213 | + break; |
|
| 214 | + case $total_time > 2500 : |
|
| 215 | + $color = 'darkorange'; |
|
| 216 | + $bold = 'bold'; |
|
| 217 | + break; |
|
| 218 | + case $total_time > 500 : |
|
| 219 | + $color = 'gold'; |
|
| 220 | + $bold = 'bold'; |
|
| 221 | + break; |
|
| 222 | + case $total_time > 100 : |
|
| 223 | + $color = 'limegreen'; |
|
| 224 | + $bold = 'normal'; |
|
| 225 | + break; |
|
| 226 | + case $total_time > 20 : |
|
| 227 | + $color = 'deepskyblue'; |
|
| 228 | + $bold = 'normal'; |
|
| 229 | + break; |
|
| 230 | + default : |
|
| 231 | + $color = 'mediumpurple'; |
|
| 232 | + $bold = 'normal'; |
|
| 233 | + break; |
|
| 234 | + } |
|
| 235 | + return '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 236 | + . $color |
|
| 237 | + . '; font-weight:' |
|
| 238 | + . $bold |
|
| 239 | + . '; font-size:1.2em;">' |
|
| 240 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 241 | + . '</span> ' |
|
| 242 | + . $timer_name; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |