@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | - * @param mixed $var |
|
| 378 | + * @param string $var |
|
| 379 | 379 | * @param string $var_name |
| 380 | 380 | * @param string $file |
| 381 | 381 | * @param int|string $line |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | * @param mixed $var |
| 514 | 514 | * @param string $var_name |
| 515 | 515 | * @param string $file |
| 516 | - * @param int|string $line |
|
| 516 | + * @param integer $line |
|
| 517 | 517 | * @param int $heading_tag |
| 518 | 518 | * @param bool $die |
| 519 | 519 | */ |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | |
| 577 | 577 | /** |
| 578 | 578 | * @deprecated 4.9.39.rc.034 |
| 579 | - * @param null $timer_name |
|
| 579 | + * @param string $timer_name |
|
| 580 | 580 | */ |
| 581 | 581 | public function start_timer($timer_name = null) |
| 582 | 582 | { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -17,632 +17,632 @@ discard block |
||
| 17 | 17 | class EEH_Debug_Tools |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * instance of the EEH_Autoloader object |
|
| 22 | - * |
|
| 23 | - * @var $_instance |
|
| 24 | - * @access private |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $_memory_usage_points = array(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @singleton method used to instantiate class object |
|
| 37 | - * @access public |
|
| 38 | - * @return EEH_Debug_Tools |
|
| 39 | - */ |
|
| 40 | - public static function instance() |
|
| 41 | - { |
|
| 42 | - // check if class object is instantiated, and instantiated properly |
|
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | - self::$_instance = new self(); |
|
| 45 | - } |
|
| 46 | - return self::$_instance; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * private class constructor |
|
| 53 | - */ |
|
| 54 | - private function __construct() |
|
| 55 | - { |
|
| 56 | - // load Kint PHP debugging library |
|
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | - } |
|
| 65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | - // } |
|
| 68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * show_db_name |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function show_db_name() |
|
| 82 | - { |
|
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | - . DB_NAME |
|
| 86 | - . '</p>'; |
|
| 87 | - } |
|
| 88 | - if (EE_DEBUG) { |
|
| 89 | - Benchmark::displayResults(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function espresso_session_footer_dump() |
|
| 101 | - { |
|
| 102 | - if ( |
|
| 103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | - && ! defined('DOING_AJAX') |
|
| 105 | - && class_exists('Kint') |
|
| 106 | - && function_exists('wp_get_current_user') |
|
| 107 | - && current_user_can('update_core') |
|
| 108 | - && class_exists('EE_Registry') |
|
| 109 | - ) { |
|
| 110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | - $this->espresso_list_hooked_functions(); |
|
| 114 | - Benchmark::displayResults(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * List All Hooked Functions |
|
| 122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | - * |
|
| 125 | - * @param string $tag |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function espresso_list_hooked_functions($tag = '') |
|
| 129 | - { |
|
| 130 | - global $wp_filter; |
|
| 131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | - if ($tag) { |
|
| 133 | - $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | - if (! is_array($hook[$tag])) { |
|
| 135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | - } else { |
|
| 140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | - ksort($hook); |
|
| 142 | - } |
|
| 143 | - foreach ($hook as $tag_name => $priorities) { |
|
| 144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | - ksort($priorities); |
|
| 146 | - foreach ($priorities as $priority => $function) { |
|
| 147 | - echo $priority; |
|
| 148 | - foreach ($function as $name => $properties) { |
|
| 149 | - echo "\t$name<br />"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * registered_filter_callbacks |
|
| 159 | - * |
|
| 160 | - * @param string $hook_name |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | - { |
|
| 165 | - $filters = array(); |
|
| 166 | - global $wp_filter; |
|
| 167 | - if (isset($wp_filter[$hook_name])) { |
|
| 168 | - $filters[$hook_name] = array(); |
|
| 169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | - $filters[$hook_name][$priority] = array(); |
|
| 171 | - foreach ($callbacks as $callback) { |
|
| 172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $filters; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * captures plugin activation errors for debugging |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws EE_Error |
|
| 186 | - */ |
|
| 187 | - public static function ee_plugin_activation_errors() |
|
| 188 | - { |
|
| 189 | - if (WP_DEBUG) { |
|
| 190 | - $activation_errors = ob_get_contents(); |
|
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | - } |
|
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | - if (class_exists('EEH_File')) { |
|
| 196 | - try { |
|
| 197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | - ); |
|
| 200 | - EEH_File::write_to_file( |
|
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | - $activation_errors |
|
| 203 | - ); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - EE_Error::add_error( |
|
| 206 | - sprintf( |
|
| 207 | - __( |
|
| 208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - $e->getMessage() |
|
| 212 | - ), |
|
| 213 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } else { |
|
| 217 | - // old school attempt |
|
| 218 | - file_put_contents( |
|
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | - $activation_errors |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | - * or we want to make sure they use something the right way. |
|
| 234 | - * |
|
| 235 | - * @access public |
|
| 236 | - * @param string $function The function that was called |
|
| 237 | - * @param string $message A message explaining what has been done incorrectly |
|
| 238 | - * @param string $version The version of Event Espresso where the error was added |
|
| 239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | - * but not have any notices appear until a later version. This allows developers |
|
| 242 | - * extra time to update their code before notices appear. |
|
| 243 | - * @param int $error_type |
|
| 244 | - * @uses trigger_error() |
|
| 245 | - */ |
|
| 246 | - public function doing_it_wrong( |
|
| 247 | - $function, |
|
| 248 | - $message, |
|
| 249 | - $version, |
|
| 250 | - $applies_when = '', |
|
| 251 | - $error_type = null |
|
| 252 | - ) { |
|
| 253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | - // because we swapped the parameter order around for the last two params, |
|
| 256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | - if (is_int($applies_when)) { |
|
| 258 | - $error_type = $applies_when; |
|
| 259 | - $applies_when = espresso_version(); |
|
| 260 | - } |
|
| 261 | - // if not displaying notices yet, then just leave |
|
| 262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | - $version = $version === null |
|
| 267 | - ? '' |
|
| 268 | - : sprintf( |
|
| 269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | - $version |
|
| 271 | - ); |
|
| 272 | - $error_message = sprintf( |
|
| 273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | - $function, |
|
| 275 | - '<strong>', |
|
| 276 | - '</strong>', |
|
| 277 | - $message, |
|
| 278 | - $version |
|
| 279 | - ); |
|
| 280 | - // don't trigger error if doing ajax, |
|
| 281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | - 'event_espresso' |
|
| 286 | - ); |
|
| 287 | - $error_message .= '<ul><li>'; |
|
| 288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | - $error_message .= '</ul>'; |
|
| 290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | - //now we set this on the transient so it shows up on the next request. |
|
| 292 | - EE_Error::get_notices(false, true); |
|
| 293 | - } else { |
|
| 294 | - trigger_error($error_message, $error_type); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Logger helpers |
|
| 303 | - */ |
|
| 304 | - /** |
|
| 305 | - * debug |
|
| 306 | - * |
|
| 307 | - * @param string $class |
|
| 308 | - * @param string $func |
|
| 309 | - * @param string $line |
|
| 310 | - * @param array $info |
|
| 311 | - * @param bool $display_request |
|
| 312 | - * @param string $debug_index |
|
| 313 | - * @param string $debug_key |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | - */ |
|
| 317 | - public static function log( |
|
| 318 | - $class = '', |
|
| 319 | - $func = '', |
|
| 320 | - $line = '', |
|
| 321 | - $info = array(), |
|
| 322 | - $display_request = false, |
|
| 323 | - $debug_index = '', |
|
| 324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | - ) { |
|
| 326 | - if (WP_DEBUG) { |
|
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | - $debug_data = get_option($debug_key, array()); |
|
| 329 | - $default_data = array( |
|
| 330 | - $class => $func . '() : ' . $line, |
|
| 331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | - ); |
|
| 333 | - // don't serialize objects |
|
| 334 | - $info = self::strip_objects($info); |
|
| 335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | - if (! isset($debug_data[$index])) { |
|
| 337 | - $debug_data[$index] = array(); |
|
| 338 | - } |
|
| 339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | - update_option($debug_key, $debug_data); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * strip_objects |
|
| 348 | - * |
|
| 349 | - * @param array $info |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - public static function strip_objects($info = array()) |
|
| 353 | - { |
|
| 354 | - foreach ($info as $key => $value) { |
|
| 355 | - if (is_array($value)) { |
|
| 356 | - $info[$key] = self::strip_objects($value); |
|
| 357 | - } else if (is_object($value)) { |
|
| 358 | - $object_class = get_class($value); |
|
| 359 | - $info[$object_class] = array(); |
|
| 360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | - if (method_exists($value, 'ID')) { |
|
| 362 | - $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | - } |
|
| 364 | - if (method_exists($value, 'status')) { |
|
| 365 | - $info[$object_class]['status'] = $value->status(); |
|
| 366 | - } else if (method_exists($value, 'status_ID')) { |
|
| 367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | - } |
|
| 369 | - unset($info[$key]); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return (array)$info; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param mixed $var |
|
| 379 | - * @param string $var_name |
|
| 380 | - * @param string $file |
|
| 381 | - * @param int|string $line |
|
| 382 | - * @param int $heading_tag |
|
| 383 | - * @param bool $die |
|
| 384 | - * @param string $margin |
|
| 385 | - */ |
|
| 386 | - public static function printv( |
|
| 387 | - $var, |
|
| 388 | - $var_name = '', |
|
| 389 | - $file = '', |
|
| 390 | - $line = '', |
|
| 391 | - $heading_tag = 5, |
|
| 392 | - $die = false, |
|
| 393 | - $margin = '' |
|
| 394 | - ) { |
|
| 395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | - $is_method = method_exists($var_name, $var); |
|
| 398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | - $result .= $is_method |
|
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | - if ($die) { |
|
| 407 | - die($result); |
|
| 408 | - } |
|
| 409 | - echo $result; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $var_name |
|
| 416 | - * @param string $heading_tag |
|
| 417 | - * @param string $margin |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | - { |
|
| 422 | - if (defined('EE_TESTS_DIR')) { |
|
| 423 | - return "\n{$var_name}"; |
|
| 424 | - } |
|
| 425 | - $margin = "25px 0 0 {$margin}"; |
|
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @param string $heading_tag |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - protected static function headingX($heading_tag = 'h5') |
|
| 436 | - { |
|
| 437 | - if (defined('EE_TESTS_DIR')) { |
|
| 438 | - return ''; |
|
| 439 | - } |
|
| 440 | - return '</' . $heading_tag . '>'; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param string $content |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - protected static function grey_span($content = '') |
|
| 450 | - { |
|
| 451 | - if (defined('EE_TESTS_DIR')) { |
|
| 452 | - return $content; |
|
| 453 | - } |
|
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @param string $file |
|
| 461 | - * @param int $line |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - protected static function file_and_line($file, $line) |
|
| 465 | - { |
|
| 466 | - if ($file === '' || $line === '') { |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - if (defined('EE_TESTS_DIR')) { |
|
| 470 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
| 471 | - } |
|
| 472 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 473 | - . $file |
|
| 474 | - . '<br />line no: ' |
|
| 475 | - . $line |
|
| 476 | - . '</span>'; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param string $content |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - protected static function orange_span($content = '') |
|
| 486 | - { |
|
| 487 | - if (defined('EE_TESTS_DIR')) { |
|
| 488 | - return $content; |
|
| 489 | - } |
|
| 490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @param mixed $var |
|
| 497 | - * @return string |
|
| 498 | - */ |
|
| 499 | - protected static function pre_span($var) |
|
| 500 | - { |
|
| 501 | - ob_start(); |
|
| 502 | - var_dump($var); |
|
| 503 | - $var = ob_get_clean(); |
|
| 504 | - if (defined('EE_TESTS_DIR')) { |
|
| 505 | - return "\n" . $var; |
|
| 506 | - } |
|
| 507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @param mixed $var |
|
| 514 | - * @param string $var_name |
|
| 515 | - * @param string $file |
|
| 516 | - * @param int|string $line |
|
| 517 | - * @param int $heading_tag |
|
| 518 | - * @param bool $die |
|
| 519 | - */ |
|
| 520 | - public static function printr( |
|
| 521 | - $var, |
|
| 522 | - $var_name = '', |
|
| 523 | - $file = '', |
|
| 524 | - $line = '', |
|
| 525 | - $heading_tag = 5, |
|
| 526 | - $die = false |
|
| 527 | - ) { |
|
| 528 | - // return; |
|
| 529 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 530 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 531 | - //$print_r = false; |
|
| 532 | - if (is_string($var)) { |
|
| 533 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 534 | - return; |
|
| 535 | - } |
|
| 536 | - if (is_object($var)) { |
|
| 537 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 538 | - //$print_r = true; |
|
| 539 | - } else if (is_array($var)) { |
|
| 540 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 541 | - //$print_r = true; |
|
| 542 | - } else if (is_numeric($var)) { |
|
| 543 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 544 | - } else if ($var === null) { |
|
| 545 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 546 | - } |
|
| 547 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 548 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 549 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 551 | - EEH_Debug_Tools::pre_span($var) |
|
| 552 | - ); |
|
| 553 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 554 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 555 | - if ($die) { |
|
| 556 | - die($result); |
|
| 557 | - } |
|
| 558 | - echo $result; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /******************** deprecated ********************/ |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * @deprecated 4.9.39.rc.034 |
|
| 569 | - */ |
|
| 570 | - public function reset_times() |
|
| 571 | - { |
|
| 572 | - Benchmark::resetTimes(); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @deprecated 4.9.39.rc.034 |
|
| 579 | - * @param null $timer_name |
|
| 580 | - */ |
|
| 581 | - public function start_timer($timer_name = null) |
|
| 582 | - { |
|
| 583 | - Benchmark::startTimer($timer_name); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @deprecated 4.9.39.rc.034 |
|
| 590 | - * @param string $timer_name |
|
| 591 | - */ |
|
| 592 | - public function stop_timer($timer_name = '') |
|
| 593 | - { |
|
| 594 | - Benchmark::stopTimer($timer_name); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @deprecated 4.9.39.rc.034 |
|
| 601 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 602 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 603 | - * @return void |
|
| 604 | - */ |
|
| 605 | - public function measure_memory($label, $output_now = false) |
|
| 606 | - { |
|
| 607 | - Benchmark::measureMemory($label, $output_now); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * @deprecated 4.9.39.rc.034 |
|
| 614 | - * @param int $size |
|
| 615 | - * @return string |
|
| 616 | - */ |
|
| 617 | - public function convert($size) |
|
| 618 | - { |
|
| 619 | - return Benchmark::convert($size); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * @deprecated 4.9.39.rc.034 |
|
| 626 | - * @param bool $output_now |
|
| 627 | - * @return string |
|
| 628 | - */ |
|
| 629 | - public function show_times($output_now = true) |
|
| 630 | - { |
|
| 631 | - return Benchmark::displayResults($output_now); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * @deprecated 4.9.39.rc.034 |
|
| 638 | - * @param string $timer_name |
|
| 639 | - * @param float $total_time |
|
| 640 | - * @return string |
|
| 641 | - */ |
|
| 642 | - public function format_time($timer_name, $total_time) |
|
| 643 | - { |
|
| 644 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 645 | - } |
|
| 20 | + /** |
|
| 21 | + * instance of the EEH_Autoloader object |
|
| 22 | + * |
|
| 23 | + * @var $_instance |
|
| 24 | + * @access private |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $_memory_usage_points = array(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @singleton method used to instantiate class object |
|
| 37 | + * @access public |
|
| 38 | + * @return EEH_Debug_Tools |
|
| 39 | + */ |
|
| 40 | + public static function instance() |
|
| 41 | + { |
|
| 42 | + // check if class object is instantiated, and instantiated properly |
|
| 43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | + self::$_instance = new self(); |
|
| 45 | + } |
|
| 46 | + return self::$_instance; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * private class constructor |
|
| 53 | + */ |
|
| 54 | + private function __construct() |
|
| 55 | + { |
|
| 56 | + // load Kint PHP debugging library |
|
| 57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | + } |
|
| 65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | + // } |
|
| 68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * show_db_name |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function show_db_name() |
|
| 82 | + { |
|
| 83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | + . DB_NAME |
|
| 86 | + . '</p>'; |
|
| 87 | + } |
|
| 88 | + if (EE_DEBUG) { |
|
| 89 | + Benchmark::displayResults(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function espresso_session_footer_dump() |
|
| 101 | + { |
|
| 102 | + if ( |
|
| 103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | + && ! defined('DOING_AJAX') |
|
| 105 | + && class_exists('Kint') |
|
| 106 | + && function_exists('wp_get_current_user') |
|
| 107 | + && current_user_can('update_core') |
|
| 108 | + && class_exists('EE_Registry') |
|
| 109 | + ) { |
|
| 110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | + $this->espresso_list_hooked_functions(); |
|
| 114 | + Benchmark::displayResults(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * List All Hooked Functions |
|
| 122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | + * |
|
| 125 | + * @param string $tag |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function espresso_list_hooked_functions($tag = '') |
|
| 129 | + { |
|
| 130 | + global $wp_filter; |
|
| 131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | + if ($tag) { |
|
| 133 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | + if (! is_array($hook[$tag])) { |
|
| 135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | + } else { |
|
| 140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | + ksort($hook); |
|
| 142 | + } |
|
| 143 | + foreach ($hook as $tag_name => $priorities) { |
|
| 144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | + ksort($priorities); |
|
| 146 | + foreach ($priorities as $priority => $function) { |
|
| 147 | + echo $priority; |
|
| 148 | + foreach ($function as $name => $properties) { |
|
| 149 | + echo "\t$name<br />"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * registered_filter_callbacks |
|
| 159 | + * |
|
| 160 | + * @param string $hook_name |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | + { |
|
| 165 | + $filters = array(); |
|
| 166 | + global $wp_filter; |
|
| 167 | + if (isset($wp_filter[$hook_name])) { |
|
| 168 | + $filters[$hook_name] = array(); |
|
| 169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | + $filters[$hook_name][$priority] = array(); |
|
| 171 | + foreach ($callbacks as $callback) { |
|
| 172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $filters; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * captures plugin activation errors for debugging |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws EE_Error |
|
| 186 | + */ |
|
| 187 | + public static function ee_plugin_activation_errors() |
|
| 188 | + { |
|
| 189 | + if (WP_DEBUG) { |
|
| 190 | + $activation_errors = ob_get_contents(); |
|
| 191 | + if (! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | + } |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | + if (class_exists('EEH_File')) { |
|
| 196 | + try { |
|
| 197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | + ); |
|
| 200 | + EEH_File::write_to_file( |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | + $activation_errors |
|
| 203 | + ); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + EE_Error::add_error( |
|
| 206 | + sprintf( |
|
| 207 | + __( |
|
| 208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + $e->getMessage() |
|
| 212 | + ), |
|
| 213 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } else { |
|
| 217 | + // old school attempt |
|
| 218 | + file_put_contents( |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | + $activation_errors |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | + * or we want to make sure they use something the right way. |
|
| 234 | + * |
|
| 235 | + * @access public |
|
| 236 | + * @param string $function The function that was called |
|
| 237 | + * @param string $message A message explaining what has been done incorrectly |
|
| 238 | + * @param string $version The version of Event Espresso where the error was added |
|
| 239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | + * but not have any notices appear until a later version. This allows developers |
|
| 242 | + * extra time to update their code before notices appear. |
|
| 243 | + * @param int $error_type |
|
| 244 | + * @uses trigger_error() |
|
| 245 | + */ |
|
| 246 | + public function doing_it_wrong( |
|
| 247 | + $function, |
|
| 248 | + $message, |
|
| 249 | + $version, |
|
| 250 | + $applies_when = '', |
|
| 251 | + $error_type = null |
|
| 252 | + ) { |
|
| 253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | + // because we swapped the parameter order around for the last two params, |
|
| 256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | + if (is_int($applies_when)) { |
|
| 258 | + $error_type = $applies_when; |
|
| 259 | + $applies_when = espresso_version(); |
|
| 260 | + } |
|
| 261 | + // if not displaying notices yet, then just leave |
|
| 262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | + $version = $version === null |
|
| 267 | + ? '' |
|
| 268 | + : sprintf( |
|
| 269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | + $version |
|
| 271 | + ); |
|
| 272 | + $error_message = sprintf( |
|
| 273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | + $function, |
|
| 275 | + '<strong>', |
|
| 276 | + '</strong>', |
|
| 277 | + $message, |
|
| 278 | + $version |
|
| 279 | + ); |
|
| 280 | + // don't trigger error if doing ajax, |
|
| 281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | + $error_message .= ' ' . esc_html__( |
|
| 284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | + 'event_espresso' |
|
| 286 | + ); |
|
| 287 | + $error_message .= '<ul><li>'; |
|
| 288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | + $error_message .= '</ul>'; |
|
| 290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | + //now we set this on the transient so it shows up on the next request. |
|
| 292 | + EE_Error::get_notices(false, true); |
|
| 293 | + } else { |
|
| 294 | + trigger_error($error_message, $error_type); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Logger helpers |
|
| 303 | + */ |
|
| 304 | + /** |
|
| 305 | + * debug |
|
| 306 | + * |
|
| 307 | + * @param string $class |
|
| 308 | + * @param string $func |
|
| 309 | + * @param string $line |
|
| 310 | + * @param array $info |
|
| 311 | + * @param bool $display_request |
|
| 312 | + * @param string $debug_index |
|
| 313 | + * @param string $debug_key |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | + */ |
|
| 317 | + public static function log( |
|
| 318 | + $class = '', |
|
| 319 | + $func = '', |
|
| 320 | + $line = '', |
|
| 321 | + $info = array(), |
|
| 322 | + $display_request = false, |
|
| 323 | + $debug_index = '', |
|
| 324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | + ) { |
|
| 326 | + if (WP_DEBUG) { |
|
| 327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | + $debug_data = get_option($debug_key, array()); |
|
| 329 | + $default_data = array( |
|
| 330 | + $class => $func . '() : ' . $line, |
|
| 331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | + ); |
|
| 333 | + // don't serialize objects |
|
| 334 | + $info = self::strip_objects($info); |
|
| 335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | + if (! isset($debug_data[$index])) { |
|
| 337 | + $debug_data[$index] = array(); |
|
| 338 | + } |
|
| 339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | + update_option($debug_key, $debug_data); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * strip_objects |
|
| 348 | + * |
|
| 349 | + * @param array $info |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + public static function strip_objects($info = array()) |
|
| 353 | + { |
|
| 354 | + foreach ($info as $key => $value) { |
|
| 355 | + if (is_array($value)) { |
|
| 356 | + $info[$key] = self::strip_objects($value); |
|
| 357 | + } else if (is_object($value)) { |
|
| 358 | + $object_class = get_class($value); |
|
| 359 | + $info[$object_class] = array(); |
|
| 360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | + if (method_exists($value, 'ID')) { |
|
| 362 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | + } |
|
| 364 | + if (method_exists($value, 'status')) { |
|
| 365 | + $info[$object_class]['status'] = $value->status(); |
|
| 366 | + } else if (method_exists($value, 'status_ID')) { |
|
| 367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | + } |
|
| 369 | + unset($info[$key]); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return (array)$info; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param mixed $var |
|
| 379 | + * @param string $var_name |
|
| 380 | + * @param string $file |
|
| 381 | + * @param int|string $line |
|
| 382 | + * @param int $heading_tag |
|
| 383 | + * @param bool $die |
|
| 384 | + * @param string $margin |
|
| 385 | + */ |
|
| 386 | + public static function printv( |
|
| 387 | + $var, |
|
| 388 | + $var_name = '', |
|
| 389 | + $file = '', |
|
| 390 | + $line = '', |
|
| 391 | + $heading_tag = 5, |
|
| 392 | + $die = false, |
|
| 393 | + $margin = '' |
|
| 394 | + ) { |
|
| 395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | + $is_method = method_exists($var_name, $var); |
|
| 398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | + $result .= $is_method |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | + if ($die) { |
|
| 407 | + die($result); |
|
| 408 | + } |
|
| 409 | + echo $result; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $var_name |
|
| 416 | + * @param string $heading_tag |
|
| 417 | + * @param string $margin |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | + { |
|
| 422 | + if (defined('EE_TESTS_DIR')) { |
|
| 423 | + return "\n{$var_name}"; |
|
| 424 | + } |
|
| 425 | + $margin = "25px 0 0 {$margin}"; |
|
| 426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @param string $heading_tag |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + protected static function headingX($heading_tag = 'h5') |
|
| 436 | + { |
|
| 437 | + if (defined('EE_TESTS_DIR')) { |
|
| 438 | + return ''; |
|
| 439 | + } |
|
| 440 | + return '</' . $heading_tag . '>'; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param string $content |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + protected static function grey_span($content = '') |
|
| 450 | + { |
|
| 451 | + if (defined('EE_TESTS_DIR')) { |
|
| 452 | + return $content; |
|
| 453 | + } |
|
| 454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @param string $file |
|
| 461 | + * @param int $line |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + protected static function file_and_line($file, $line) |
|
| 465 | + { |
|
| 466 | + if ($file === '' || $line === '') { |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + if (defined('EE_TESTS_DIR')) { |
|
| 470 | + return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
| 471 | + } |
|
| 472 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 473 | + . $file |
|
| 474 | + . '<br />line no: ' |
|
| 475 | + . $line |
|
| 476 | + . '</span>'; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param string $content |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + protected static function orange_span($content = '') |
|
| 486 | + { |
|
| 487 | + if (defined('EE_TESTS_DIR')) { |
|
| 488 | + return $content; |
|
| 489 | + } |
|
| 490 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param mixed $var |
|
| 497 | + * @return string |
|
| 498 | + */ |
|
| 499 | + protected static function pre_span($var) |
|
| 500 | + { |
|
| 501 | + ob_start(); |
|
| 502 | + var_dump($var); |
|
| 503 | + $var = ob_get_clean(); |
|
| 504 | + if (defined('EE_TESTS_DIR')) { |
|
| 505 | + return "\n" . $var; |
|
| 506 | + } |
|
| 507 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @param mixed $var |
|
| 514 | + * @param string $var_name |
|
| 515 | + * @param string $file |
|
| 516 | + * @param int|string $line |
|
| 517 | + * @param int $heading_tag |
|
| 518 | + * @param bool $die |
|
| 519 | + */ |
|
| 520 | + public static function printr( |
|
| 521 | + $var, |
|
| 522 | + $var_name = '', |
|
| 523 | + $file = '', |
|
| 524 | + $line = '', |
|
| 525 | + $heading_tag = 5, |
|
| 526 | + $die = false |
|
| 527 | + ) { |
|
| 528 | + // return; |
|
| 529 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 530 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 531 | + //$print_r = false; |
|
| 532 | + if (is_string($var)) { |
|
| 533 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 534 | + return; |
|
| 535 | + } |
|
| 536 | + if (is_object($var)) { |
|
| 537 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 538 | + //$print_r = true; |
|
| 539 | + } else if (is_array($var)) { |
|
| 540 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 541 | + //$print_r = true; |
|
| 542 | + } else if (is_numeric($var)) { |
|
| 543 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 544 | + } else if ($var === null) { |
|
| 545 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 546 | + } |
|
| 547 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 548 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 549 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 550 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 551 | + EEH_Debug_Tools::pre_span($var) |
|
| 552 | + ); |
|
| 553 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 554 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 555 | + if ($die) { |
|
| 556 | + die($result); |
|
| 557 | + } |
|
| 558 | + echo $result; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /******************** deprecated ********************/ |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * @deprecated 4.9.39.rc.034 |
|
| 569 | + */ |
|
| 570 | + public function reset_times() |
|
| 571 | + { |
|
| 572 | + Benchmark::resetTimes(); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @deprecated 4.9.39.rc.034 |
|
| 579 | + * @param null $timer_name |
|
| 580 | + */ |
|
| 581 | + public function start_timer($timer_name = null) |
|
| 582 | + { |
|
| 583 | + Benchmark::startTimer($timer_name); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @deprecated 4.9.39.rc.034 |
|
| 590 | + * @param string $timer_name |
|
| 591 | + */ |
|
| 592 | + public function stop_timer($timer_name = '') |
|
| 593 | + { |
|
| 594 | + Benchmark::stopTimer($timer_name); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @deprecated 4.9.39.rc.034 |
|
| 601 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 602 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 603 | + * @return void |
|
| 604 | + */ |
|
| 605 | + public function measure_memory($label, $output_now = false) |
|
| 606 | + { |
|
| 607 | + Benchmark::measureMemory($label, $output_now); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * @deprecated 4.9.39.rc.034 |
|
| 614 | + * @param int $size |
|
| 615 | + * @return string |
|
| 616 | + */ |
|
| 617 | + public function convert($size) |
|
| 618 | + { |
|
| 619 | + return Benchmark::convert($size); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * @deprecated 4.9.39.rc.034 |
|
| 626 | + * @param bool $output_now |
|
| 627 | + * @return string |
|
| 628 | + */ |
|
| 629 | + public function show_times($output_now = true) |
|
| 630 | + { |
|
| 631 | + return Benchmark::displayResults($output_now); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * @deprecated 4.9.39.rc.034 |
|
| 638 | + * @param string $timer_name |
|
| 639 | + * @param float $total_time |
|
| 640 | + * @return string |
|
| 641 | + */ |
|
| 642 | + public function format_time($timer_name, $total_time) |
|
| 643 | + { |
|
| 644 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 645 | + } |
|
| 646 | 646 | |
| 647 | 647 | |
| 648 | 648 | |
@@ -655,31 +655,31 @@ discard block |
||
| 655 | 655 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 656 | 656 | */ |
| 657 | 657 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 658 | - function dump_wp_query() |
|
| 659 | - { |
|
| 660 | - global $wp_query; |
|
| 661 | - d($wp_query); |
|
| 662 | - } |
|
| 658 | + function dump_wp_query() |
|
| 659 | + { |
|
| 660 | + global $wp_query; |
|
| 661 | + d($wp_query); |
|
| 662 | + } |
|
| 663 | 663 | } |
| 664 | 664 | /** |
| 665 | 665 | * borrowed from Kint Debugger |
| 666 | 666 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 667 | 667 | */ |
| 668 | 668 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 669 | - function dump_wp() |
|
| 670 | - { |
|
| 671 | - global $wp; |
|
| 672 | - d($wp); |
|
| 673 | - } |
|
| 669 | + function dump_wp() |
|
| 670 | + { |
|
| 671 | + global $wp; |
|
| 672 | + d($wp); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | /** |
| 676 | 676 | * borrowed from Kint Debugger |
| 677 | 677 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 678 | 678 | */ |
| 679 | 679 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 680 | - function dump_post() |
|
| 681 | - { |
|
| 682 | - global $post; |
|
| 683 | - d($post); |
|
| 684 | - } |
|
| 680 | + function dump_post() |
|
| 681 | + { |
|
| 682 | + global $post; |
|
| 683 | + d($post); |
|
| 684 | + } |
|
| 685 | 685 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public static function instance() |
| 41 | 41 | { |
| 42 | 42 | // check if class object is instantiated, and instantiated properly |
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | private function __construct() |
| 55 | 55 | { |
| 56 | 56 | // load Kint PHP debugging library |
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
| 58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
| 62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
| 64 | 64 | } |
| 65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function show_db_name() |
| 82 | 82 | { |
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 85 | 85 | . DB_NAME |
| 86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 132 | 132 | if ($tag) { |
| 133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
| 134 | - if (! is_array($hook[$tag])) { |
|
| 134 | + if ( ! is_array($hook[$tag])) { |
|
| 135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 139 | 139 | } else { |
| 140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | if (WP_DEBUG) { |
| 190 | 190 | $activation_errors = ob_get_contents(); |
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | + if ( ! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 193 | 193 | } |
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 195 | 195 | if (class_exists('EEH_File')) { |
| 196 | 196 | try { |
| 197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
| 199 | 199 | ); |
| 200 | 200 | EEH_File::write_to_file( |
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 202 | 202 | $activation_errors |
| 203 | 203 | ); |
| 204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | } else { |
| 217 | 217 | // old school attempt |
| 218 | 218 | file_put_contents( |
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 220 | 220 | $activation_errors |
| 221 | 221 | ); |
| 222 | 222 | } |
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // don't trigger error if doing ajax, |
| 281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 283 | + $error_message .= ' '.esc_html__( |
|
| 284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 285 | 285 | 'event_espresso' |
| 286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
| 325 | 325 | ) { |
| 326 | 326 | if (WP_DEBUG) { |
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 328 | 328 | $debug_data = get_option($debug_key, array()); |
| 329 | 329 | $default_data = array( |
| 330 | - $class => $func . '() : ' . $line, |
|
| 330 | + $class => $func.'() : '.$line, |
|
| 331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
| 332 | 332 | ); |
| 333 | 333 | // don't serialize objects |
| 334 | 334 | $info = self::strip_objects($info); |
| 335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 336 | - if (! isset($debug_data[$index])) { |
|
| 336 | + if ( ! isset($debug_data[$index])) { |
|
| 337 | 337 | $debug_data[$index] = array(); |
| 338 | 338 | } |
| 339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | unset($info[$key]); |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | - return (array)$info; |
|
| 372 | + return (array) $info; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 401 | 401 | $result .= $is_method |
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
| 405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | return "\n{$var_name}"; |
| 424 | 424 | } |
| 425 | 425 | $margin = "25px 0 0 {$margin}"; |
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | if (defined('EE_TESTS_DIR')) { |
| 438 | 438 | return ''; |
| 439 | 439 | } |
| 440 | - return '</' . $heading_tag . '>'; |
|
| 440 | + return '</'.$heading_tag.'>'; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | if (defined('EE_TESTS_DIR')) { |
| 452 | 452 | return $content; |
| 453 | 453 | } |
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | return ''; |
| 468 | 468 | } |
| 469 | 469 | if (defined('EE_TESTS_DIR')) { |
| 470 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
| 470 | + return "\n (".$file.' line no: '.$line.' ) '; |
|
| 471 | 471 | } |
| 472 | 472 | return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
| 473 | 473 | . $file |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | if (defined('EE_TESTS_DIR')) { |
| 488 | 488 | return $content; |
| 489 | 489 | } |
| 490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 490 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | |
@@ -502,9 +502,9 @@ discard block |
||
| 502 | 502 | var_dump($var); |
| 503 | 503 | $var = ob_get_clean(); |
| 504 | 504 | if (defined('EE_TESTS_DIR')) { |
| 505 | - return "\n" . $var; |
|
| 505 | + return "\n".$var; |
|
| 506 | 506 | } |
| 507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 507 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
| 548 | 548 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 549 | 549 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 550 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 551 | 551 | EEH_Debug_Tools::pre_span($var) |
| 552 | 552 | ); |
| 553 | 553 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -14,121 +14,121 @@ |
||
| 14 | 14 | abstract class EED_Module extends EE_Configurable implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * rendered output to be returned to WP |
|
| 19 | - * |
|
| 20 | - * @var string $output |
|
| 21 | - */ |
|
| 22 | - protected $output = ''; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * the current active espresso template theme |
|
| 26 | - * |
|
| 27 | - * @var string $theme |
|
| 28 | - */ |
|
| 29 | - protected $theme = ''; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public static function reset() |
|
| 37 | - { |
|
| 38 | - $module_name = get_called_class(); |
|
| 39 | - new $module_name(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 46 | - * |
|
| 47 | - * @access public |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public static function set_hooks() |
|
| 51 | - { |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 58 | - * |
|
| 59 | - * @access public |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public static function set_hooks_admin() |
|
| 63 | - { |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * run - initial module setup |
|
| 70 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
| 71 | - * |
|
| 72 | - * @access public |
|
| 73 | - * @var WP $WP |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - abstract public function run($WP); |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * EED_Module constructor. |
|
| 82 | - */ |
|
| 83 | - final public function __construct() |
|
| 84 | - { |
|
| 85 | - $this->theme = EE_Config::get_current_theme(); |
|
| 86 | - $module_name = $this->module_name(); |
|
| 87 | - EE_Registry::instance()->modules->{$module_name} = $this; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param $module_name |
|
| 94 | - * @return EED_Module |
|
| 95 | - */ |
|
| 96 | - protected static function get_instance($module_name = '') |
|
| 97 | - { |
|
| 98 | - $module_name = ! empty($module_name) |
|
| 99 | - ? $module_name |
|
| 100 | - : get_called_class(); |
|
| 101 | - if ( |
|
| 102 | - ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
| 103 | - || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
| 104 | - ) { |
|
| 105 | - EE_Registry::instance()->add_module($module_name); |
|
| 106 | - } |
|
| 107 | - return EE_Registry::instance()->get_module($module_name); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * module_name |
|
| 114 | - * |
|
| 115 | - * @access public |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function module_name() |
|
| 119 | - { |
|
| 120 | - return get_class($this); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function theme() |
|
| 129 | - { |
|
| 130 | - return $this->theme; |
|
| 131 | - } |
|
| 17 | + /** |
|
| 18 | + * rendered output to be returned to WP |
|
| 19 | + * |
|
| 20 | + * @var string $output |
|
| 21 | + */ |
|
| 22 | + protected $output = ''; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * the current active espresso template theme |
|
| 26 | + * |
|
| 27 | + * @var string $theme |
|
| 28 | + */ |
|
| 29 | + protected $theme = ''; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public static function reset() |
|
| 37 | + { |
|
| 38 | + $module_name = get_called_class(); |
|
| 39 | + new $module_name(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 46 | + * |
|
| 47 | + * @access public |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public static function set_hooks() |
|
| 51 | + { |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 58 | + * |
|
| 59 | + * @access public |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public static function set_hooks_admin() |
|
| 63 | + { |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * run - initial module setup |
|
| 70 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
| 71 | + * |
|
| 72 | + * @access public |
|
| 73 | + * @var WP $WP |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + abstract public function run($WP); |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * EED_Module constructor. |
|
| 82 | + */ |
|
| 83 | + final public function __construct() |
|
| 84 | + { |
|
| 85 | + $this->theme = EE_Config::get_current_theme(); |
|
| 86 | + $module_name = $this->module_name(); |
|
| 87 | + EE_Registry::instance()->modules->{$module_name} = $this; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param $module_name |
|
| 94 | + * @return EED_Module |
|
| 95 | + */ |
|
| 96 | + protected static function get_instance($module_name = '') |
|
| 97 | + { |
|
| 98 | + $module_name = ! empty($module_name) |
|
| 99 | + ? $module_name |
|
| 100 | + : get_called_class(); |
|
| 101 | + if ( |
|
| 102 | + ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
| 103 | + || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
| 104 | + ) { |
|
| 105 | + EE_Registry::instance()->add_module($module_name); |
|
| 106 | + } |
|
| 107 | + return EE_Registry::instance()->get_module($module_name); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * module_name |
|
| 114 | + * |
|
| 115 | + * @access public |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function module_name() |
|
| 119 | + { |
|
| 120 | + return get_class($this); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function theme() |
|
| 129 | + { |
|
| 130 | + return $this->theme; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | |
| 134 | 134 | |
@@ -19,1470 +19,1470 @@ |
||
| 19 | 19 | class EE_Registry implements ResettableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * EE_Registry Object |
|
| 24 | - * |
|
| 25 | - * @var EE_Registry $_instance |
|
| 26 | - * @access private |
|
| 27 | - */ |
|
| 28 | - private static $_instance = null; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var EE_Dependency_Map $_dependency_map |
|
| 32 | - * @access protected |
|
| 33 | - */ |
|
| 34 | - protected $_dependency_map = null; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_class_abbreviations |
|
| 38 | - * @access protected |
|
| 39 | - */ |
|
| 40 | - protected $_class_abbreviations = array(); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @access public |
|
| 44 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
| 45 | - */ |
|
| 46 | - public $BUS; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * EE_Cart Object |
|
| 50 | - * |
|
| 51 | - * @access public |
|
| 52 | - * @var EE_Cart $CART |
|
| 53 | - */ |
|
| 54 | - public $CART = null; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * EE_Config Object |
|
| 58 | - * |
|
| 59 | - * @access public |
|
| 60 | - * @var EE_Config $CFG |
|
| 61 | - */ |
|
| 62 | - public $CFG = null; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * EE_Network_Config Object |
|
| 66 | - * |
|
| 67 | - * @access public |
|
| 68 | - * @var EE_Network_Config $NET_CFG |
|
| 69 | - */ |
|
| 70 | - public $NET_CFG = null; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * StdClass object for storing library classes in |
|
| 74 | - * |
|
| 75 | - * @public LIB |
|
| 76 | - * @var StdClass $LIB |
|
| 77 | - */ |
|
| 78 | - public $LIB = null; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * EE_Request_Handler Object |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @var EE_Request_Handler $REQ |
|
| 85 | - */ |
|
| 86 | - public $REQ = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * EE_Session Object |
|
| 90 | - * |
|
| 91 | - * @access public |
|
| 92 | - * @var EE_Session $SSN |
|
| 93 | - */ |
|
| 94 | - public $SSN = null; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * holds the ee capabilities object. |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - * @var EE_Capabilities |
|
| 101 | - */ |
|
| 102 | - public $CAP = null; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * holds the EE_Message_Resource_Manager object. |
|
| 106 | - * |
|
| 107 | - * @since 4.9.0 |
|
| 108 | - * @var EE_Message_Resource_Manager |
|
| 109 | - */ |
|
| 110 | - public $MRM = null; |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Holds the Assets Registry instance |
|
| 115 | - * @var Registry |
|
| 116 | - */ |
|
| 117 | - public $AssetsRegistry = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
| 121 | - * |
|
| 122 | - * @access public |
|
| 123 | - * @var EE_Addon[] |
|
| 124 | - */ |
|
| 125 | - public $addons = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * $models |
|
| 129 | - * @access public |
|
| 130 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 131 | - */ |
|
| 132 | - public $models = array(); |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * $modules |
|
| 136 | - * @access public |
|
| 137 | - * @var EED_Module[] $modules |
|
| 138 | - */ |
|
| 139 | - public $modules = null; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * $shortcodes |
|
| 143 | - * @access public |
|
| 144 | - * @var EES_Shortcode[] $shortcodes |
|
| 145 | - */ |
|
| 146 | - public $shortcodes = null; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * $widgets |
|
| 150 | - * @access public |
|
| 151 | - * @var WP_Widget[] $widgets |
|
| 152 | - */ |
|
| 153 | - public $widgets = null; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * $non_abstract_db_models |
|
| 157 | - * @access public |
|
| 158 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 159 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 160 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 161 | - * classnames (eg "EEM_Event") |
|
| 162 | - */ |
|
| 163 | - public $non_abstract_db_models = array(); |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * $i18n_js_strings - internationalization for JS strings |
|
| 168 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
| 169 | - * in js file: var translatedString = eei18n.string_key; |
|
| 170 | - * |
|
| 171 | - * @access public |
|
| 172 | - * @var array |
|
| 173 | - */ |
|
| 174 | - public static $i18n_js_strings = array(); |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * $main_file - path to espresso.php |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - * @var array |
|
| 182 | - */ |
|
| 183 | - public $main_file; |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * array of ReflectionClass objects where the key is the class name |
|
| 187 | - * |
|
| 188 | - * @access public |
|
| 189 | - * @var ReflectionClass[] |
|
| 190 | - */ |
|
| 191 | - public $_reflectors; |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 195 | - * |
|
| 196 | - * @access protected |
|
| 197 | - * @var boolean $_cache_on |
|
| 198 | - */ |
|
| 199 | - protected $_cache_on = true; |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @singleton method used to instantiate class object |
|
| 205 | - * @access public |
|
| 206 | - * @param \EE_Dependency_Map $dependency_map |
|
| 207 | - * @return \EE_Registry instance |
|
| 208 | - */ |
|
| 209 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
| 210 | - { |
|
| 211 | - // check if class object is instantiated |
|
| 212 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
| 213 | - self::$_instance = new EE_Registry($dependency_map); |
|
| 214 | - } |
|
| 215 | - return self::$_instance; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - *protected constructor to prevent direct creation |
|
| 222 | - * |
|
| 223 | - * @Constructor |
|
| 224 | - * @access protected |
|
| 225 | - * @param \EE_Dependency_Map $dependency_map |
|
| 226 | - */ |
|
| 227 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
| 228 | - { |
|
| 229 | - $this->_dependency_map = $dependency_map; |
|
| 230 | - $this->LIB = new stdClass(); |
|
| 231 | - $this->addons = new stdClass(); |
|
| 232 | - $this->modules = new stdClass(); |
|
| 233 | - $this->shortcodes = new stdClass(); |
|
| 234 | - $this->widgets = new stdClass(); |
|
| 235 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * initialize |
|
| 242 | - */ |
|
| 243 | - public function initialize() |
|
| 244 | - { |
|
| 245 | - $this->_class_abbreviations = apply_filters( |
|
| 246 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 247 | - array( |
|
| 248 | - 'EE_Config' => 'CFG', |
|
| 249 | - 'EE_Session' => 'SSN', |
|
| 250 | - 'EE_Capabilities' => 'CAP', |
|
| 251 | - 'EE_Cart' => 'CART', |
|
| 252 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 253 | - 'EE_Request_Handler' => 'REQ', |
|
| 254 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 255 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 256 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 257 | - ) |
|
| 258 | - ); |
|
| 259 | - $this->load_core('Base', array(), true); |
|
| 260 | - // add our request and response objects to the cache |
|
| 261 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 262 | - $this->_set_cached_class( |
|
| 263 | - $request_loader(), |
|
| 264 | - 'EE_Request' |
|
| 265 | - ); |
|
| 266 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 267 | - $this->_set_cached_class( |
|
| 268 | - $response_loader(), |
|
| 269 | - 'EE_Response' |
|
| 270 | - ); |
|
| 271 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * init |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @return void |
|
| 281 | - */ |
|
| 282 | - public function init() |
|
| 283 | - { |
|
| 284 | - // Get current page protocol |
|
| 285 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 286 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 287 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 288 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * localize_i18n_js_strings |
|
| 295 | - * |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - public static function localize_i18n_js_strings() |
|
| 299 | - { |
|
| 300 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
| 301 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 302 | - if (is_scalar($value)) { |
|
| 303 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @param mixed string | EED_Module $module |
|
| 313 | - */ |
|
| 314 | - public function add_module($module) |
|
| 315 | - { |
|
| 316 | - if ($module instanceof EED_Module) { |
|
| 317 | - $module_class = get_class($module); |
|
| 318 | - $this->modules->{$module_class} = $module; |
|
| 319 | - } else { |
|
| 320 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 321 | - $this->load_core('Module_Request_Router'); |
|
| 322 | - } |
|
| 323 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @param string $module_name |
|
| 331 | - * @return mixed EED_Module | NULL |
|
| 332 | - */ |
|
| 333 | - public function get_module($module_name = '') |
|
| 334 | - { |
|
| 335 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * loads core classes - must be singletons |
|
| 342 | - * |
|
| 343 | - * @access public |
|
| 344 | - * @param string $class_name - simple class name ie: session |
|
| 345 | - * @param mixed $arguments |
|
| 346 | - * @param bool $load_only |
|
| 347 | - * @return mixed |
|
| 348 | - */ |
|
| 349 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 350 | - { |
|
| 351 | - $core_paths = apply_filters( |
|
| 352 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 353 | - array( |
|
| 354 | - EE_CORE, |
|
| 355 | - EE_ADMIN, |
|
| 356 | - EE_CPTS, |
|
| 357 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 358 | - EE_CORE . 'request_stack' . DS, |
|
| 359 | - EE_CORE . 'middleware' . DS, |
|
| 360 | - ) |
|
| 361 | - ); |
|
| 362 | - // retrieve instantiated class |
|
| 363 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * loads service classes |
|
| 370 | - * |
|
| 371 | - * @access public |
|
| 372 | - * @param string $class_name - simple class name ie: session |
|
| 373 | - * @param mixed $arguments |
|
| 374 | - * @param bool $load_only |
|
| 375 | - * @return mixed |
|
| 376 | - */ |
|
| 377 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 378 | - { |
|
| 379 | - $service_paths = apply_filters( |
|
| 380 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 381 | - array( |
|
| 382 | - EE_CORE . 'services' . DS, |
|
| 383 | - ) |
|
| 384 | - ); |
|
| 385 | - // retrieve instantiated class |
|
| 386 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * loads data_migration_scripts |
|
| 393 | - * |
|
| 394 | - * @access public |
|
| 395 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 396 | - * @param mixed $arguments |
|
| 397 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 398 | - */ |
|
| 399 | - public function load_dms($class_name, $arguments = array()) |
|
| 400 | - { |
|
| 401 | - // retrieve instantiated class |
|
| 402 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * loads object creating classes - must be singletons |
|
| 409 | - * |
|
| 410 | - * @param string $class_name - simple class name ie: attendee |
|
| 411 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 412 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
| 413 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 414 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
| 415 | - * @return EE_Base_Class | bool |
|
| 416 | - */ |
|
| 417 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 418 | - { |
|
| 419 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
| 420 | - EE_CORE, |
|
| 421 | - EE_CLASSES, |
|
| 422 | - EE_BUSINESS, |
|
| 423 | - )); |
|
| 424 | - // retrieve instantiated class |
|
| 425 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * loads helper classes - must be singletons |
|
| 432 | - * |
|
| 433 | - * @param string $class_name - simple class name ie: price |
|
| 434 | - * @param mixed $arguments |
|
| 435 | - * @param bool $load_only |
|
| 436 | - * @return EEH_Base | bool |
|
| 437 | - */ |
|
| 438 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 439 | - { |
|
| 440 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 441 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 442 | - // retrieve instantiated class |
|
| 443 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * loads core classes - must be singletons |
|
| 450 | - * |
|
| 451 | - * @access public |
|
| 452 | - * @param string $class_name - simple class name ie: session |
|
| 453 | - * @param mixed $arguments |
|
| 454 | - * @param bool $load_only |
|
| 455 | - * @param bool $cache whether to cache the object or not. |
|
| 456 | - * @return mixed |
|
| 457 | - */ |
|
| 458 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 459 | - { |
|
| 460 | - $paths = array( |
|
| 461 | - EE_LIBRARIES, |
|
| 462 | - EE_LIBRARIES . 'messages' . DS, |
|
| 463 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 464 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 465 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 466 | - ); |
|
| 467 | - // retrieve instantiated class |
|
| 468 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * loads model classes - must be singletons |
|
| 475 | - * |
|
| 476 | - * @param string $class_name - simple class name ie: price |
|
| 477 | - * @param mixed $arguments |
|
| 478 | - * @param bool $load_only |
|
| 479 | - * @return EEM_Base | bool |
|
| 480 | - */ |
|
| 481 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 482 | - { |
|
| 483 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
| 484 | - EE_MODELS, |
|
| 485 | - EE_CORE, |
|
| 486 | - )); |
|
| 487 | - // retrieve instantiated class |
|
| 488 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * loads model classes - must be singletons |
|
| 495 | - * |
|
| 496 | - * @param string $class_name - simple class name ie: price |
|
| 497 | - * @param mixed $arguments |
|
| 498 | - * @param bool $load_only |
|
| 499 | - * @return mixed | bool |
|
| 500 | - */ |
|
| 501 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 502 | - { |
|
| 503 | - $paths = array( |
|
| 504 | - EE_MODELS . 'fields' . DS, |
|
| 505 | - EE_MODELS . 'helpers' . DS, |
|
| 506 | - EE_MODELS . 'relations' . DS, |
|
| 507 | - EE_MODELS . 'strategies' . DS, |
|
| 508 | - ); |
|
| 509 | - // retrieve instantiated class |
|
| 510 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Determines if $model_name is the name of an actual EE model. |
|
| 517 | - * |
|
| 518 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 519 | - * @return boolean |
|
| 520 | - */ |
|
| 521 | - public function is_model_name($model_name) |
|
| 522 | - { |
|
| 523 | - return isset($this->models[$model_name]) ? true : false; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * generic class loader |
|
| 530 | - * |
|
| 531 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 532 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 533 | - * @param string $type - file type - core? class? helper? model? |
|
| 534 | - * @param mixed $arguments |
|
| 535 | - * @param bool $load_only |
|
| 536 | - * @return mixed |
|
| 537 | - */ |
|
| 538 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 539 | - { |
|
| 540 | - // retrieve instantiated class |
|
| 541 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * load_addon |
|
| 548 | - * |
|
| 549 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 550 | - * @param string $class_name - full class name ie: My_Class |
|
| 551 | - * @param string $type - file type - core? class? helper? model? |
|
| 552 | - * @param mixed $arguments |
|
| 553 | - * @param bool $load_only |
|
| 554 | - * @return EE_Addon |
|
| 555 | - */ |
|
| 556 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 557 | - { |
|
| 558 | - // retrieve instantiated class |
|
| 559 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * instantiates, caches, and automatically resolves dependencies |
|
| 566 | - * for classes that use a Fully Qualified Class Name. |
|
| 567 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 568 | - * then you need to use one of the existing load_*() methods |
|
| 569 | - * which can resolve the classname and filepath from the passed arguments |
|
| 570 | - * |
|
| 571 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 572 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 573 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 574 | - * @param bool $from_db some classes are instantiated from the db |
|
| 575 | - * and thus call a different method to instantiate |
|
| 576 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 577 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 578 | - * @return mixed null = failure to load or instantiate class object. |
|
| 579 | - * object = class loaded and instantiated successfully. |
|
| 580 | - * bool = fail or success when $load_only is true |
|
| 581 | - */ |
|
| 582 | - public function create( |
|
| 583 | - $class_name = false, |
|
| 584 | - $arguments = array(), |
|
| 585 | - $cache = false, |
|
| 586 | - $from_db = false, |
|
| 587 | - $load_only = false, |
|
| 588 | - $addon = false |
|
| 589 | - ) { |
|
| 590 | - $class_name = ltrim($class_name, '\\'); |
|
| 591 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 592 | - if ( ! class_exists($class_name)) { |
|
| 593 | - // maybe the class is registered with a preceding \ |
|
| 594 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
| 595 | - // still doesn't exist ? |
|
| 596 | - if ( ! class_exists($class_name)) { |
|
| 597 | - return null; |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 601 | - if ($load_only) { |
|
| 602 | - return true; |
|
| 603 | - } |
|
| 604 | - $addon = $addon ? 'addon' : ''; |
|
| 605 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 606 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 607 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 608 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 609 | - // return object if it's already cached |
|
| 610 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 611 | - if ($cached_class !== null) { |
|
| 612 | - return $cached_class; |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - // instantiate the requested object |
|
| 616 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 617 | - if ($this->_cache_on && $cache) { |
|
| 618 | - // save it for later... kinda like gum { : $ |
|
| 619 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 620 | - } |
|
| 621 | - $this->_cache_on = true; |
|
| 622 | - return $class_obj; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * instantiates, caches, and injects dependencies for classes |
|
| 629 | - * |
|
| 630 | - * @param array $file_paths an array of paths to folders to look in |
|
| 631 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 632 | - * @param bool|string $class_name $class name |
|
| 633 | - * @param string $type file type - core? class? helper? model? |
|
| 634 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 635 | - * @param bool $from_db some classes are instantiated from the db |
|
| 636 | - * and thus call a different method to instantiate |
|
| 637 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 638 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 639 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
| 640 | - * object = class loaded and instantiated successfully. |
|
| 641 | - * bool = fail or success when $load_only is true |
|
| 642 | - */ |
|
| 643 | - protected function _load( |
|
| 644 | - $file_paths = array(), |
|
| 645 | - $class_prefix = 'EE_', |
|
| 646 | - $class_name = false, |
|
| 647 | - $type = 'class', |
|
| 648 | - $arguments = array(), |
|
| 649 | - $from_db = false, |
|
| 650 | - $cache = true, |
|
| 651 | - $load_only = false |
|
| 652 | - ) { |
|
| 653 | - $class_name = ltrim($class_name, '\\'); |
|
| 654 | - // strip php file extension |
|
| 655 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 656 | - // does the class have a prefix ? |
|
| 657 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
| 658 | - // make sure $class_prefix is uppercase |
|
| 659 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 660 | - // add class prefix ONCE!!! |
|
| 661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 662 | - } |
|
| 663 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 664 | - $class_exists = class_exists($class_name); |
|
| 665 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 666 | - if ($load_only && $class_exists) { |
|
| 667 | - return true; |
|
| 668 | - } |
|
| 669 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 670 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 671 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 672 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 673 | - // return object if it's already cached |
|
| 674 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 675 | - if ($cached_class !== null) { |
|
| 676 | - return $cached_class; |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 680 | - if ( ! $class_exists) { |
|
| 681 | - // get full path to file |
|
| 682 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 683 | - // load the file |
|
| 684 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 685 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 686 | - if ( ! $loaded || $load_only) { |
|
| 687 | - // return boolean if only loading, or null if an object was expected |
|
| 688 | - return $load_only ? $loaded : null; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - // instantiate the requested object |
|
| 692 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 693 | - if ($this->_cache_on && $cache) { |
|
| 694 | - // save it for later... kinda like gum { : $ |
|
| 695 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 696 | - } |
|
| 697 | - $this->_cache_on = true; |
|
| 698 | - return $class_obj; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * _get_cached_class |
|
| 706 | - * attempts to find a cached version of the requested class |
|
| 707 | - * by looking in the following places: |
|
| 708 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 709 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 710 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 711 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 712 | - * |
|
| 713 | - * @access protected |
|
| 714 | - * @param string $class_name |
|
| 715 | - * @param string $class_prefix |
|
| 716 | - * @return mixed |
|
| 717 | - */ |
|
| 718 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 719 | - { |
|
| 720 | - if ($class_name === 'EE_Registry') { |
|
| 721 | - return $this; |
|
| 722 | - } |
|
| 723 | - // have to specify something, but not anything that will conflict |
|
| 724 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 725 | - ? $this->_class_abbreviations[ $class_name ] |
|
| 726 | - : 'FANCY_BATMAN_PANTS'; |
|
| 727 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 728 | - // check if class has already been loaded, and return it if it has been |
|
| 729 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 730 | - return $this->{$class_abbreviation}; |
|
| 731 | - } |
|
| 732 | - if (isset ($this->{$class_name})) { |
|
| 733 | - return $this->{$class_name}; |
|
| 734 | - } |
|
| 735 | - if (isset ($this->LIB->{$class_name})) { |
|
| 736 | - return $this->LIB->{$class_name}; |
|
| 737 | - } |
|
| 738 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 739 | - return $this->addons->{$class_name}; |
|
| 740 | - } |
|
| 741 | - return null; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * removes a cached version of the requested class |
|
| 748 | - * |
|
| 749 | - * @param string $class_name |
|
| 750 | - * @param boolean $addon |
|
| 751 | - * @return boolean |
|
| 752 | - */ |
|
| 753 | - public function clear_cached_class($class_name, $addon = false) |
|
| 754 | - { |
|
| 755 | - // have to specify something, but not anything that will conflict |
|
| 756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 757 | - ? $this->_class_abbreviations[ $class_name ] |
|
| 758 | - : 'FANCY_BATMAN_PANTS'; |
|
| 759 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 760 | - // check if class has already been loaded, and return it if it has been |
|
| 761 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 762 | - $this->{$class_abbreviation} = null; |
|
| 763 | - return true; |
|
| 764 | - } |
|
| 765 | - if (isset($this->{$class_name})) { |
|
| 766 | - $this->{$class_name} = null; |
|
| 767 | - return true; |
|
| 768 | - } |
|
| 769 | - if (isset($this->LIB->{$class_name})) { |
|
| 770 | - unset($this->LIB->{$class_name}); |
|
| 771 | - return true; |
|
| 772 | - } |
|
| 773 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 774 | - unset($this->addons->{$class_name}); |
|
| 775 | - return true; |
|
| 776 | - } |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * _resolve_path |
|
| 783 | - * attempts to find a full valid filepath for the requested class. |
|
| 784 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 785 | - * then returns that path if the target file has been found and is readable |
|
| 786 | - * |
|
| 787 | - * @access protected |
|
| 788 | - * @param string $class_name |
|
| 789 | - * @param string $type |
|
| 790 | - * @param array $file_paths |
|
| 791 | - * @return string | bool |
|
| 792 | - */ |
|
| 793 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 794 | - { |
|
| 795 | - // make sure $file_paths is an array |
|
| 796 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
| 797 | - // cycle thru paths |
|
| 798 | - foreach ($file_paths as $key => $file_path) { |
|
| 799 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 800 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
| 801 | - // prep file type |
|
| 802 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
| 803 | - // build full file path |
|
| 804 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 805 | - //does the file exist and can be read ? |
|
| 806 | - if (is_readable($file_paths[$key])) { |
|
| 807 | - return $file_paths[$key]; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * _require_file |
|
| 817 | - * basically just performs a require_once() |
|
| 818 | - * but with some error handling |
|
| 819 | - * |
|
| 820 | - * @access protected |
|
| 821 | - * @param string $path |
|
| 822 | - * @param string $class_name |
|
| 823 | - * @param string $type |
|
| 824 | - * @param array $file_paths |
|
| 825 | - * @return boolean |
|
| 826 | - * @throws \EE_Error |
|
| 827 | - */ |
|
| 828 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 829 | - { |
|
| 830 | - // don't give up! you gotta... |
|
| 831 | - try { |
|
| 832 | - //does the file exist and can it be read ? |
|
| 833 | - if ( ! $path) { |
|
| 834 | - // so sorry, can't find the file |
|
| 835 | - throw new EE_Error ( |
|
| 836 | - sprintf( |
|
| 837 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
| 838 | - trim($type, '.'), |
|
| 839 | - $class_name, |
|
| 840 | - '<br />' . implode(',<br />', $file_paths) |
|
| 841 | - ) |
|
| 842 | - ); |
|
| 843 | - } |
|
| 844 | - // get the file |
|
| 845 | - require_once($path); |
|
| 846 | - // if the class isn't already declared somewhere |
|
| 847 | - if (class_exists($class_name, false) === false) { |
|
| 848 | - // so sorry, not a class |
|
| 849 | - throw new EE_Error( |
|
| 850 | - sprintf( |
|
| 851 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 852 | - $type, |
|
| 853 | - $path, |
|
| 854 | - $class_name |
|
| 855 | - ) |
|
| 856 | - ); |
|
| 857 | - } |
|
| 858 | - } catch (EE_Error $e) { |
|
| 859 | - $e->get_error(); |
|
| 860 | - return false; |
|
| 861 | - } |
|
| 862 | - return true; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * _create_object |
|
| 869 | - * Attempts to instantiate the requested class via any of the |
|
| 870 | - * commonly used instantiation methods employed throughout EE. |
|
| 871 | - * The priority for instantiation is as follows: |
|
| 872 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 873 | - * - model objects via their 'new_instance_from_db' method |
|
| 874 | - * - model objects via their 'new_instance' method |
|
| 875 | - * - "singleton" classes" via their 'instance' method |
|
| 876 | - * - standard instantiable classes via their __constructor |
|
| 877 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 878 | - * then the constructor for the requested class will be examined to determine |
|
| 879 | - * if any dependencies exist, and if they can be injected. |
|
| 880 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 881 | - * |
|
| 882 | - * @access protected |
|
| 883 | - * @param string $class_name |
|
| 884 | - * @param array $arguments |
|
| 885 | - * @param string $type |
|
| 886 | - * @param bool $from_db |
|
| 887 | - * @return null | object |
|
| 888 | - * @throws \EE_Error |
|
| 889 | - */ |
|
| 890 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 891 | - { |
|
| 892 | - $class_obj = null; |
|
| 893 | - $instantiation_mode = '0) none'; |
|
| 894 | - // don't give up! you gotta... |
|
| 895 | - try { |
|
| 896 | - // create reflection |
|
| 897 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 898 | - // make sure arguments are an array |
|
| 899 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
| 900 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 901 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 902 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 903 | - ? $arguments |
|
| 904 | - : array($arguments); |
|
| 905 | - // attempt to inject dependencies ? |
|
| 906 | - if ($this->_dependency_map->has($class_name)) { |
|
| 907 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 908 | - } |
|
| 909 | - // instantiate the class if possible |
|
| 910 | - if ($reflector->isAbstract()) { |
|
| 911 | - // nothing to instantiate, loading file was enough |
|
| 912 | - // does not throw an exception so $instantiation_mode is unused |
|
| 913 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 914 | - $class_obj = true; |
|
| 915 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
| 916 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 917 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
| 918 | - $class_obj = $reflector->newInstance(); |
|
| 919 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 920 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
| 921 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 922 | - } else if (method_exists($class_name, 'new_instance')) { |
|
| 923 | - $instantiation_mode = "4) new_instance()"; |
|
| 924 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 925 | - } else if (method_exists($class_name, 'instance')) { |
|
| 926 | - $instantiation_mode = "5) instance()"; |
|
| 927 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 928 | - } else if ($reflector->isInstantiable()) { |
|
| 929 | - $instantiation_mode = "6) constructor"; |
|
| 930 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 931 | - } else { |
|
| 932 | - // heh ? something's not right ! |
|
| 933 | - throw new EE_Error( |
|
| 934 | - sprintf( |
|
| 935 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 936 | - $type, |
|
| 937 | - $class_name |
|
| 938 | - ) |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - } catch (Exception $e) { |
|
| 942 | - if ( ! $e instanceof EE_Error) { |
|
| 943 | - $e = new EE_Error( |
|
| 944 | - sprintf( |
|
| 945 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
| 946 | - $class_name, |
|
| 947 | - '<br />', |
|
| 948 | - $e->getMessage(), |
|
| 949 | - $instantiation_mode |
|
| 950 | - ) |
|
| 951 | - ); |
|
| 952 | - } |
|
| 953 | - $e->get_error(); |
|
| 954 | - } |
|
| 955 | - return $class_obj; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 962 | - * @param array $array |
|
| 963 | - * @return bool |
|
| 964 | - */ |
|
| 965 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 966 | - { |
|
| 967 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * getReflectionClass |
|
| 974 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 975 | - * and returns that instead of creating a new one |
|
| 976 | - * |
|
| 977 | - * @access public |
|
| 978 | - * @param string $class_name |
|
| 979 | - * @return ReflectionClass |
|
| 980 | - */ |
|
| 981 | - public function get_ReflectionClass($class_name) |
|
| 982 | - { |
|
| 983 | - if ( |
|
| 984 | - ! isset($this->_reflectors[$class_name]) |
|
| 985 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 986 | - ) { |
|
| 987 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 988 | - } |
|
| 989 | - return $this->_reflectors[$class_name]; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * _resolve_dependencies |
|
| 996 | - * examines the constructor for the requested class to determine |
|
| 997 | - * if any dependencies exist, and if they can be injected. |
|
| 998 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 999 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1000 | - * For example: |
|
| 1001 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1002 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1003 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1004 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1005 | - * and the correct classes can be loaded |
|
| 1006 | - * |
|
| 1007 | - * @access protected |
|
| 1008 | - * @param ReflectionClass $reflector |
|
| 1009 | - * @param string $class_name |
|
| 1010 | - * @param array $arguments |
|
| 1011 | - * @return array |
|
| 1012 | - * @throws \ReflectionException |
|
| 1013 | - */ |
|
| 1014 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1015 | - { |
|
| 1016 | - // let's examine the constructor |
|
| 1017 | - $constructor = $reflector->getConstructor(); |
|
| 1018 | - // whu? huh? nothing? |
|
| 1019 | - if ( ! $constructor) { |
|
| 1020 | - return $arguments; |
|
| 1021 | - } |
|
| 1022 | - // get constructor parameters |
|
| 1023 | - $params = $constructor->getParameters(); |
|
| 1024 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1025 | - $argument_keys = array_keys($arguments); |
|
| 1026 | - // now loop thru all of the constructors expected parameters |
|
| 1027 | - foreach ($params as $index => $param) { |
|
| 1028 | - // is this a dependency for a specific class ? |
|
| 1029 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
| 1030 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1031 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1032 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1033 | - : $param_class; |
|
| 1034 | - if ( |
|
| 1035 | - // param is not even a class |
|
| 1036 | - empty($param_class) |
|
| 1037 | - // and something already exists in the incoming arguments for this param |
|
| 1038 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1039 | - ) { |
|
| 1040 | - // so let's skip this argument and move on to the next |
|
| 1041 | - continue; |
|
| 1042 | - } |
|
| 1043 | - if ( |
|
| 1044 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1045 | - ! empty($param_class) |
|
| 1046 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1047 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1048 | - ) { |
|
| 1049 | - // skip this argument and move on to the next |
|
| 1050 | - continue; |
|
| 1051 | - } |
|
| 1052 | - if ( |
|
| 1053 | - // parameter is type hinted as a class, and should be injected |
|
| 1054 | - ! empty($param_class) |
|
| 1055 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1056 | - ) { |
|
| 1057 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1058 | - } else { |
|
| 1059 | - try { |
|
| 1060 | - $arguments[$index] = $param->getDefaultValue(); |
|
| 1061 | - } catch (ReflectionException $e) { |
|
| 1062 | - throw new ReflectionException( |
|
| 1063 | - sprintf( |
|
| 1064 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1065 | - $e->getMessage(), |
|
| 1066 | - $param->getName() |
|
| 1067 | - ) |
|
| 1068 | - ); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - return $arguments; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * @access protected |
|
| 1079 | - * @param string $class_name |
|
| 1080 | - * @param string $param_class |
|
| 1081 | - * @param array $arguments |
|
| 1082 | - * @param mixed $index |
|
| 1083 | - * @return array |
|
| 1084 | - */ |
|
| 1085 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1086 | - { |
|
| 1087 | - $dependency = null; |
|
| 1088 | - // should dependency be loaded from cache ? |
|
| 1089 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1090 | - !== EE_Dependency_Map::load_new_object |
|
| 1091 | - ? true |
|
| 1092 | - : false; |
|
| 1093 | - // we might have a dependency... |
|
| 1094 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1095 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
| 1096 | - // and grab it if it exists |
|
| 1097 | - if ($cached_class instanceof $param_class) { |
|
| 1098 | - $dependency = $cached_class; |
|
| 1099 | - } else if ($param_class !== $class_name) { |
|
| 1100 | - // obtain the loader method from the dependency map |
|
| 1101 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1102 | - // is loader a custom closure ? |
|
| 1103 | - if ($loader instanceof Closure) { |
|
| 1104 | - $dependency = $loader(); |
|
| 1105 | - } else { |
|
| 1106 | - // set the cache on property for the recursive loading call |
|
| 1107 | - $this->_cache_on = $cache_on; |
|
| 1108 | - // if not, then let's try and load it via the registry |
|
| 1109 | - if ($loader && method_exists($this, $loader)) { |
|
| 1110 | - $dependency = $this->{$loader}($param_class); |
|
| 1111 | - } else { |
|
| 1112 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1115 | - } |
|
| 1116 | - // did we successfully find the correct dependency ? |
|
| 1117 | - if ($dependency instanceof $param_class) { |
|
| 1118 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1119 | - if (isset($argument_keys[$index])) { |
|
| 1120 | - $arguments[$argument_keys[$index]] = $dependency; |
|
| 1121 | - } else { |
|
| 1122 | - $arguments[$index] = $dependency; |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - return $arguments; |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * _set_cached_class |
|
| 1132 | - * attempts to cache the instantiated class locally |
|
| 1133 | - * in one of the following places, in the following order: |
|
| 1134 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1135 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1136 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1137 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1138 | - * |
|
| 1139 | - * @access protected |
|
| 1140 | - * @param object $class_obj |
|
| 1141 | - * @param string $class_name |
|
| 1142 | - * @param string $class_prefix |
|
| 1143 | - * @param bool $from_db |
|
| 1144 | - * @return void |
|
| 1145 | - */ |
|
| 1146 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1147 | - { |
|
| 1148 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1149 | - return; |
|
| 1150 | - } |
|
| 1151 | - // return newly instantiated class |
|
| 1152 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1153 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1154 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1155 | - return; |
|
| 1156 | - } |
|
| 1157 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1158 | - if (property_exists($this, $class_name)) { |
|
| 1159 | - $this->{$class_name} = $class_obj; |
|
| 1160 | - return; |
|
| 1161 | - } |
|
| 1162 | - if ($class_prefix === 'addon') { |
|
| 1163 | - $this->addons->{$class_name} = $class_obj; |
|
| 1164 | - return; |
|
| 1165 | - } |
|
| 1166 | - if ( ! $from_db) { |
|
| 1167 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - /** |
|
| 1174 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1175 | - * |
|
| 1176 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1177 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1178 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1179 | - * @param array $arguments |
|
| 1180 | - * @return object |
|
| 1181 | - */ |
|
| 1182 | - public static function factory($classname, $arguments = array()) |
|
| 1183 | - { |
|
| 1184 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1185 | - if ($loader instanceof Closure) { |
|
| 1186 | - return $loader($arguments); |
|
| 1187 | - } |
|
| 1188 | - if (method_exists(EE_Registry::instance(), $loader)) { |
|
| 1189 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
| 1190 | - } |
|
| 1191 | - return null; |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1198 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1199 | - * |
|
| 1200 | - * @param string $name |
|
| 1201 | - * @return EE_Addon |
|
| 1202 | - */ |
|
| 1203 | - public function get_addon_by_name($name) |
|
| 1204 | - { |
|
| 1205 | - foreach ($this->addons as $addon) { |
|
| 1206 | - if ($addon->name() == $name) { |
|
| 1207 | - return $addon; |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - return null; |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
| 1217 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
| 1218 | - * |
|
| 1219 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1220 | - */ |
|
| 1221 | - public function get_addons_by_name() |
|
| 1222 | - { |
|
| 1223 | - $addons = array(); |
|
| 1224 | - foreach ($this->addons as $addon) { |
|
| 1225 | - $addons[$addon->name()] = $addon; |
|
| 1226 | - } |
|
| 1227 | - return $addons; |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1234 | - * a stale copy of it around |
|
| 1235 | - * |
|
| 1236 | - * @param string $model_name |
|
| 1237 | - * @return \EEM_Base |
|
| 1238 | - * @throws \EE_Error |
|
| 1239 | - */ |
|
| 1240 | - public function reset_model($model_name) |
|
| 1241 | - { |
|
| 1242 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
| 1243 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1244 | - return null; |
|
| 1245 | - } |
|
| 1246 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1247 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
| 1248 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1249 | - } else { |
|
| 1250 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1251 | - } |
|
| 1252 | - return $this->LIB->{$model_class_name}; |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * Resets the registry. |
|
| 1259 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
| 1260 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1261 | - * - $_dependency_map |
|
| 1262 | - * - $_class_abbreviations |
|
| 1263 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1264 | - * - $REQ: Still on the same request so no need to change. |
|
| 1265 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1266 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
| 1267 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1268 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1269 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1270 | - * switch or on the restore. |
|
| 1271 | - * - $modules |
|
| 1272 | - * - $shortcodes |
|
| 1273 | - * - $widgets |
|
| 1274 | - * |
|
| 1275 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1276 | - * the Registry to its state at the beginning of the request |
|
| 1277 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1278 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
| 1279 | - * currently reinstantiate the singletons at the moment) |
|
| 1280 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
| 1281 | - * code instead can just change the model context to a different blog id if necessary |
|
| 1282 | - * @return EE_Registry |
|
| 1283 | - */ |
|
| 1284 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1285 | - { |
|
| 1286 | - $instance = self::instance(); |
|
| 1287 | - $instance->_cache_on = true; |
|
| 1288 | - // reset some "special" classes |
|
| 1289 | - EEH_Activation::reset(); |
|
| 1290 | - $instance->CFG = $instance->CFG->reset($hard, $reinstantiate); |
|
| 1291 | - $instance->CART = null; |
|
| 1292 | - $instance->MRM = null; |
|
| 1293 | - $instance->AssetsRegistry = null; |
|
| 1294 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1295 | - //messages reset |
|
| 1296 | - EED_Messages::reset(); |
|
| 1297 | - //handle of objects cached on LIB |
|
| 1298 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1299 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1300 | - if (EE_Registry::_reset_and_unset_object($class, $reset_models)) { |
|
| 1301 | - unset($instance->{$cache}->{$class_name}); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1305 | - return $instance; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1312 | - * if passed object implements InterminableInterface, then return false, |
|
| 1313 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1314 | - * |
|
| 1315 | - * @param $object |
|
| 1316 | - * @param bool $reset_models |
|
| 1317 | - * @return bool returns true if cached object should be unset |
|
| 1318 | - */ |
|
| 1319 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1320 | - { |
|
| 1321 | - if (! is_object($object)) { |
|
| 1322 | - // don't unset anything that's not an object |
|
| 1323 | - return false; |
|
| 1324 | - } |
|
| 1325 | - if ($object instanceof EED_Module) { |
|
| 1326 | - $object::reset(); |
|
| 1327 | - // don't unset modules |
|
| 1328 | - return false; |
|
| 1329 | - } |
|
| 1330 | - if ($object instanceof ResettableInterface) { |
|
| 1331 | - if ($object instanceof EEM_Base) { |
|
| 1332 | - if ($reset_models) { |
|
| 1333 | - $object->reset(); |
|
| 1334 | - return true; |
|
| 1335 | - } |
|
| 1336 | - return false; |
|
| 1337 | - } |
|
| 1338 | - $object->reset(); |
|
| 1339 | - return true; |
|
| 1340 | - } |
|
| 1341 | - if ( ! $object instanceof InterminableInterface) { |
|
| 1342 | - return true; |
|
| 1343 | - } |
|
| 1344 | - return false; |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - /** |
|
| 1350 | - * @override magic methods |
|
| 1351 | - * @return void |
|
| 1352 | - */ |
|
| 1353 | - public final function __destruct() |
|
| 1354 | - { |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * @param $a |
|
| 1361 | - * @param $b |
|
| 1362 | - */ |
|
| 1363 | - public final function __call($a, $b) |
|
| 1364 | - { |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * @param $a |
|
| 1371 | - */ |
|
| 1372 | - public final function __get($a) |
|
| 1373 | - { |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @param $a |
|
| 1380 | - * @param $b |
|
| 1381 | - */ |
|
| 1382 | - public final function __set($a, $b) |
|
| 1383 | - { |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * @param $a |
|
| 1390 | - */ |
|
| 1391 | - public final function __isset($a) |
|
| 1392 | - { |
|
| 1393 | - } |
|
| 22 | + /** |
|
| 23 | + * EE_Registry Object |
|
| 24 | + * |
|
| 25 | + * @var EE_Registry $_instance |
|
| 26 | + * @access private |
|
| 27 | + */ |
|
| 28 | + private static $_instance = null; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var EE_Dependency_Map $_dependency_map |
|
| 32 | + * @access protected |
|
| 33 | + */ |
|
| 34 | + protected $_dependency_map = null; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_class_abbreviations |
|
| 38 | + * @access protected |
|
| 39 | + */ |
|
| 40 | + protected $_class_abbreviations = array(); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @access public |
|
| 44 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
| 45 | + */ |
|
| 46 | + public $BUS; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * EE_Cart Object |
|
| 50 | + * |
|
| 51 | + * @access public |
|
| 52 | + * @var EE_Cart $CART |
|
| 53 | + */ |
|
| 54 | + public $CART = null; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * EE_Config Object |
|
| 58 | + * |
|
| 59 | + * @access public |
|
| 60 | + * @var EE_Config $CFG |
|
| 61 | + */ |
|
| 62 | + public $CFG = null; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * EE_Network_Config Object |
|
| 66 | + * |
|
| 67 | + * @access public |
|
| 68 | + * @var EE_Network_Config $NET_CFG |
|
| 69 | + */ |
|
| 70 | + public $NET_CFG = null; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * StdClass object for storing library classes in |
|
| 74 | + * |
|
| 75 | + * @public LIB |
|
| 76 | + * @var StdClass $LIB |
|
| 77 | + */ |
|
| 78 | + public $LIB = null; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * EE_Request_Handler Object |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @var EE_Request_Handler $REQ |
|
| 85 | + */ |
|
| 86 | + public $REQ = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * EE_Session Object |
|
| 90 | + * |
|
| 91 | + * @access public |
|
| 92 | + * @var EE_Session $SSN |
|
| 93 | + */ |
|
| 94 | + public $SSN = null; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * holds the ee capabilities object. |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + * @var EE_Capabilities |
|
| 101 | + */ |
|
| 102 | + public $CAP = null; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * holds the EE_Message_Resource_Manager object. |
|
| 106 | + * |
|
| 107 | + * @since 4.9.0 |
|
| 108 | + * @var EE_Message_Resource_Manager |
|
| 109 | + */ |
|
| 110 | + public $MRM = null; |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Holds the Assets Registry instance |
|
| 115 | + * @var Registry |
|
| 116 | + */ |
|
| 117 | + public $AssetsRegistry = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
| 121 | + * |
|
| 122 | + * @access public |
|
| 123 | + * @var EE_Addon[] |
|
| 124 | + */ |
|
| 125 | + public $addons = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * $models |
|
| 129 | + * @access public |
|
| 130 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 131 | + */ |
|
| 132 | + public $models = array(); |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * $modules |
|
| 136 | + * @access public |
|
| 137 | + * @var EED_Module[] $modules |
|
| 138 | + */ |
|
| 139 | + public $modules = null; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * $shortcodes |
|
| 143 | + * @access public |
|
| 144 | + * @var EES_Shortcode[] $shortcodes |
|
| 145 | + */ |
|
| 146 | + public $shortcodes = null; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * $widgets |
|
| 150 | + * @access public |
|
| 151 | + * @var WP_Widget[] $widgets |
|
| 152 | + */ |
|
| 153 | + public $widgets = null; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * $non_abstract_db_models |
|
| 157 | + * @access public |
|
| 158 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 159 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 160 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 161 | + * classnames (eg "EEM_Event") |
|
| 162 | + */ |
|
| 163 | + public $non_abstract_db_models = array(); |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * $i18n_js_strings - internationalization for JS strings |
|
| 168 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
| 169 | + * in js file: var translatedString = eei18n.string_key; |
|
| 170 | + * |
|
| 171 | + * @access public |
|
| 172 | + * @var array |
|
| 173 | + */ |
|
| 174 | + public static $i18n_js_strings = array(); |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * $main_file - path to espresso.php |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + * @var array |
|
| 182 | + */ |
|
| 183 | + public $main_file; |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * array of ReflectionClass objects where the key is the class name |
|
| 187 | + * |
|
| 188 | + * @access public |
|
| 189 | + * @var ReflectionClass[] |
|
| 190 | + */ |
|
| 191 | + public $_reflectors; |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 195 | + * |
|
| 196 | + * @access protected |
|
| 197 | + * @var boolean $_cache_on |
|
| 198 | + */ |
|
| 199 | + protected $_cache_on = true; |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @singleton method used to instantiate class object |
|
| 205 | + * @access public |
|
| 206 | + * @param \EE_Dependency_Map $dependency_map |
|
| 207 | + * @return \EE_Registry instance |
|
| 208 | + */ |
|
| 209 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
| 210 | + { |
|
| 211 | + // check if class object is instantiated |
|
| 212 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
| 213 | + self::$_instance = new EE_Registry($dependency_map); |
|
| 214 | + } |
|
| 215 | + return self::$_instance; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + *protected constructor to prevent direct creation |
|
| 222 | + * |
|
| 223 | + * @Constructor |
|
| 224 | + * @access protected |
|
| 225 | + * @param \EE_Dependency_Map $dependency_map |
|
| 226 | + */ |
|
| 227 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
| 228 | + { |
|
| 229 | + $this->_dependency_map = $dependency_map; |
|
| 230 | + $this->LIB = new stdClass(); |
|
| 231 | + $this->addons = new stdClass(); |
|
| 232 | + $this->modules = new stdClass(); |
|
| 233 | + $this->shortcodes = new stdClass(); |
|
| 234 | + $this->widgets = new stdClass(); |
|
| 235 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * initialize |
|
| 242 | + */ |
|
| 243 | + public function initialize() |
|
| 244 | + { |
|
| 245 | + $this->_class_abbreviations = apply_filters( |
|
| 246 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 247 | + array( |
|
| 248 | + 'EE_Config' => 'CFG', |
|
| 249 | + 'EE_Session' => 'SSN', |
|
| 250 | + 'EE_Capabilities' => 'CAP', |
|
| 251 | + 'EE_Cart' => 'CART', |
|
| 252 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 253 | + 'EE_Request_Handler' => 'REQ', |
|
| 254 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 255 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 256 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 257 | + ) |
|
| 258 | + ); |
|
| 259 | + $this->load_core('Base', array(), true); |
|
| 260 | + // add our request and response objects to the cache |
|
| 261 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 262 | + $this->_set_cached_class( |
|
| 263 | + $request_loader(), |
|
| 264 | + 'EE_Request' |
|
| 265 | + ); |
|
| 266 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 267 | + $this->_set_cached_class( |
|
| 268 | + $response_loader(), |
|
| 269 | + 'EE_Response' |
|
| 270 | + ); |
|
| 271 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * init |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @return void |
|
| 281 | + */ |
|
| 282 | + public function init() |
|
| 283 | + { |
|
| 284 | + // Get current page protocol |
|
| 285 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 286 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 287 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 288 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * localize_i18n_js_strings |
|
| 295 | + * |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | + public static function localize_i18n_js_strings() |
|
| 299 | + { |
|
| 300 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
| 301 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 302 | + if (is_scalar($value)) { |
|
| 303 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @param mixed string | EED_Module $module |
|
| 313 | + */ |
|
| 314 | + public function add_module($module) |
|
| 315 | + { |
|
| 316 | + if ($module instanceof EED_Module) { |
|
| 317 | + $module_class = get_class($module); |
|
| 318 | + $this->modules->{$module_class} = $module; |
|
| 319 | + } else { |
|
| 320 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 321 | + $this->load_core('Module_Request_Router'); |
|
| 322 | + } |
|
| 323 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @param string $module_name |
|
| 331 | + * @return mixed EED_Module | NULL |
|
| 332 | + */ |
|
| 333 | + public function get_module($module_name = '') |
|
| 334 | + { |
|
| 335 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * loads core classes - must be singletons |
|
| 342 | + * |
|
| 343 | + * @access public |
|
| 344 | + * @param string $class_name - simple class name ie: session |
|
| 345 | + * @param mixed $arguments |
|
| 346 | + * @param bool $load_only |
|
| 347 | + * @return mixed |
|
| 348 | + */ |
|
| 349 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 350 | + { |
|
| 351 | + $core_paths = apply_filters( |
|
| 352 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 353 | + array( |
|
| 354 | + EE_CORE, |
|
| 355 | + EE_ADMIN, |
|
| 356 | + EE_CPTS, |
|
| 357 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 358 | + EE_CORE . 'request_stack' . DS, |
|
| 359 | + EE_CORE . 'middleware' . DS, |
|
| 360 | + ) |
|
| 361 | + ); |
|
| 362 | + // retrieve instantiated class |
|
| 363 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * loads service classes |
|
| 370 | + * |
|
| 371 | + * @access public |
|
| 372 | + * @param string $class_name - simple class name ie: session |
|
| 373 | + * @param mixed $arguments |
|
| 374 | + * @param bool $load_only |
|
| 375 | + * @return mixed |
|
| 376 | + */ |
|
| 377 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 378 | + { |
|
| 379 | + $service_paths = apply_filters( |
|
| 380 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 381 | + array( |
|
| 382 | + EE_CORE . 'services' . DS, |
|
| 383 | + ) |
|
| 384 | + ); |
|
| 385 | + // retrieve instantiated class |
|
| 386 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * loads data_migration_scripts |
|
| 393 | + * |
|
| 394 | + * @access public |
|
| 395 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 396 | + * @param mixed $arguments |
|
| 397 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 398 | + */ |
|
| 399 | + public function load_dms($class_name, $arguments = array()) |
|
| 400 | + { |
|
| 401 | + // retrieve instantiated class |
|
| 402 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * loads object creating classes - must be singletons |
|
| 409 | + * |
|
| 410 | + * @param string $class_name - simple class name ie: attendee |
|
| 411 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 412 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
| 413 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 414 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
| 415 | + * @return EE_Base_Class | bool |
|
| 416 | + */ |
|
| 417 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 418 | + { |
|
| 419 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
| 420 | + EE_CORE, |
|
| 421 | + EE_CLASSES, |
|
| 422 | + EE_BUSINESS, |
|
| 423 | + )); |
|
| 424 | + // retrieve instantiated class |
|
| 425 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * loads helper classes - must be singletons |
|
| 432 | + * |
|
| 433 | + * @param string $class_name - simple class name ie: price |
|
| 434 | + * @param mixed $arguments |
|
| 435 | + * @param bool $load_only |
|
| 436 | + * @return EEH_Base | bool |
|
| 437 | + */ |
|
| 438 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 439 | + { |
|
| 440 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 441 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 442 | + // retrieve instantiated class |
|
| 443 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * loads core classes - must be singletons |
|
| 450 | + * |
|
| 451 | + * @access public |
|
| 452 | + * @param string $class_name - simple class name ie: session |
|
| 453 | + * @param mixed $arguments |
|
| 454 | + * @param bool $load_only |
|
| 455 | + * @param bool $cache whether to cache the object or not. |
|
| 456 | + * @return mixed |
|
| 457 | + */ |
|
| 458 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 459 | + { |
|
| 460 | + $paths = array( |
|
| 461 | + EE_LIBRARIES, |
|
| 462 | + EE_LIBRARIES . 'messages' . DS, |
|
| 463 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 464 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 465 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 466 | + ); |
|
| 467 | + // retrieve instantiated class |
|
| 468 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * loads model classes - must be singletons |
|
| 475 | + * |
|
| 476 | + * @param string $class_name - simple class name ie: price |
|
| 477 | + * @param mixed $arguments |
|
| 478 | + * @param bool $load_only |
|
| 479 | + * @return EEM_Base | bool |
|
| 480 | + */ |
|
| 481 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 482 | + { |
|
| 483 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
| 484 | + EE_MODELS, |
|
| 485 | + EE_CORE, |
|
| 486 | + )); |
|
| 487 | + // retrieve instantiated class |
|
| 488 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * loads model classes - must be singletons |
|
| 495 | + * |
|
| 496 | + * @param string $class_name - simple class name ie: price |
|
| 497 | + * @param mixed $arguments |
|
| 498 | + * @param bool $load_only |
|
| 499 | + * @return mixed | bool |
|
| 500 | + */ |
|
| 501 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 502 | + { |
|
| 503 | + $paths = array( |
|
| 504 | + EE_MODELS . 'fields' . DS, |
|
| 505 | + EE_MODELS . 'helpers' . DS, |
|
| 506 | + EE_MODELS . 'relations' . DS, |
|
| 507 | + EE_MODELS . 'strategies' . DS, |
|
| 508 | + ); |
|
| 509 | + // retrieve instantiated class |
|
| 510 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Determines if $model_name is the name of an actual EE model. |
|
| 517 | + * |
|
| 518 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 519 | + * @return boolean |
|
| 520 | + */ |
|
| 521 | + public function is_model_name($model_name) |
|
| 522 | + { |
|
| 523 | + return isset($this->models[$model_name]) ? true : false; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * generic class loader |
|
| 530 | + * |
|
| 531 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 532 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 533 | + * @param string $type - file type - core? class? helper? model? |
|
| 534 | + * @param mixed $arguments |
|
| 535 | + * @param bool $load_only |
|
| 536 | + * @return mixed |
|
| 537 | + */ |
|
| 538 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 539 | + { |
|
| 540 | + // retrieve instantiated class |
|
| 541 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * load_addon |
|
| 548 | + * |
|
| 549 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 550 | + * @param string $class_name - full class name ie: My_Class |
|
| 551 | + * @param string $type - file type - core? class? helper? model? |
|
| 552 | + * @param mixed $arguments |
|
| 553 | + * @param bool $load_only |
|
| 554 | + * @return EE_Addon |
|
| 555 | + */ |
|
| 556 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 557 | + { |
|
| 558 | + // retrieve instantiated class |
|
| 559 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * instantiates, caches, and automatically resolves dependencies |
|
| 566 | + * for classes that use a Fully Qualified Class Name. |
|
| 567 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 568 | + * then you need to use one of the existing load_*() methods |
|
| 569 | + * which can resolve the classname and filepath from the passed arguments |
|
| 570 | + * |
|
| 571 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 572 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 573 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 574 | + * @param bool $from_db some classes are instantiated from the db |
|
| 575 | + * and thus call a different method to instantiate |
|
| 576 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 577 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 578 | + * @return mixed null = failure to load or instantiate class object. |
|
| 579 | + * object = class loaded and instantiated successfully. |
|
| 580 | + * bool = fail or success when $load_only is true |
|
| 581 | + */ |
|
| 582 | + public function create( |
|
| 583 | + $class_name = false, |
|
| 584 | + $arguments = array(), |
|
| 585 | + $cache = false, |
|
| 586 | + $from_db = false, |
|
| 587 | + $load_only = false, |
|
| 588 | + $addon = false |
|
| 589 | + ) { |
|
| 590 | + $class_name = ltrim($class_name, '\\'); |
|
| 591 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 592 | + if ( ! class_exists($class_name)) { |
|
| 593 | + // maybe the class is registered with a preceding \ |
|
| 594 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
| 595 | + // still doesn't exist ? |
|
| 596 | + if ( ! class_exists($class_name)) { |
|
| 597 | + return null; |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 601 | + if ($load_only) { |
|
| 602 | + return true; |
|
| 603 | + } |
|
| 604 | + $addon = $addon ? 'addon' : ''; |
|
| 605 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 606 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 607 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 608 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 609 | + // return object if it's already cached |
|
| 610 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 611 | + if ($cached_class !== null) { |
|
| 612 | + return $cached_class; |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + // instantiate the requested object |
|
| 616 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 617 | + if ($this->_cache_on && $cache) { |
|
| 618 | + // save it for later... kinda like gum { : $ |
|
| 619 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 620 | + } |
|
| 621 | + $this->_cache_on = true; |
|
| 622 | + return $class_obj; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * instantiates, caches, and injects dependencies for classes |
|
| 629 | + * |
|
| 630 | + * @param array $file_paths an array of paths to folders to look in |
|
| 631 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 632 | + * @param bool|string $class_name $class name |
|
| 633 | + * @param string $type file type - core? class? helper? model? |
|
| 634 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 635 | + * @param bool $from_db some classes are instantiated from the db |
|
| 636 | + * and thus call a different method to instantiate |
|
| 637 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 638 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 639 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
| 640 | + * object = class loaded and instantiated successfully. |
|
| 641 | + * bool = fail or success when $load_only is true |
|
| 642 | + */ |
|
| 643 | + protected function _load( |
|
| 644 | + $file_paths = array(), |
|
| 645 | + $class_prefix = 'EE_', |
|
| 646 | + $class_name = false, |
|
| 647 | + $type = 'class', |
|
| 648 | + $arguments = array(), |
|
| 649 | + $from_db = false, |
|
| 650 | + $cache = true, |
|
| 651 | + $load_only = false |
|
| 652 | + ) { |
|
| 653 | + $class_name = ltrim($class_name, '\\'); |
|
| 654 | + // strip php file extension |
|
| 655 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 656 | + // does the class have a prefix ? |
|
| 657 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
| 658 | + // make sure $class_prefix is uppercase |
|
| 659 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 660 | + // add class prefix ONCE!!! |
|
| 661 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 662 | + } |
|
| 663 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 664 | + $class_exists = class_exists($class_name); |
|
| 665 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 666 | + if ($load_only && $class_exists) { |
|
| 667 | + return true; |
|
| 668 | + } |
|
| 669 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 670 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 671 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 672 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 673 | + // return object if it's already cached |
|
| 674 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 675 | + if ($cached_class !== null) { |
|
| 676 | + return $cached_class; |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 680 | + if ( ! $class_exists) { |
|
| 681 | + // get full path to file |
|
| 682 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 683 | + // load the file |
|
| 684 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 685 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 686 | + if ( ! $loaded || $load_only) { |
|
| 687 | + // return boolean if only loading, or null if an object was expected |
|
| 688 | + return $load_only ? $loaded : null; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + // instantiate the requested object |
|
| 692 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 693 | + if ($this->_cache_on && $cache) { |
|
| 694 | + // save it for later... kinda like gum { : $ |
|
| 695 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 696 | + } |
|
| 697 | + $this->_cache_on = true; |
|
| 698 | + return $class_obj; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * _get_cached_class |
|
| 706 | + * attempts to find a cached version of the requested class |
|
| 707 | + * by looking in the following places: |
|
| 708 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 709 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 710 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 711 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 712 | + * |
|
| 713 | + * @access protected |
|
| 714 | + * @param string $class_name |
|
| 715 | + * @param string $class_prefix |
|
| 716 | + * @return mixed |
|
| 717 | + */ |
|
| 718 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 719 | + { |
|
| 720 | + if ($class_name === 'EE_Registry') { |
|
| 721 | + return $this; |
|
| 722 | + } |
|
| 723 | + // have to specify something, but not anything that will conflict |
|
| 724 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 725 | + ? $this->_class_abbreviations[ $class_name ] |
|
| 726 | + : 'FANCY_BATMAN_PANTS'; |
|
| 727 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 728 | + // check if class has already been loaded, and return it if it has been |
|
| 729 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 730 | + return $this->{$class_abbreviation}; |
|
| 731 | + } |
|
| 732 | + if (isset ($this->{$class_name})) { |
|
| 733 | + return $this->{$class_name}; |
|
| 734 | + } |
|
| 735 | + if (isset ($this->LIB->{$class_name})) { |
|
| 736 | + return $this->LIB->{$class_name}; |
|
| 737 | + } |
|
| 738 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 739 | + return $this->addons->{$class_name}; |
|
| 740 | + } |
|
| 741 | + return null; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * removes a cached version of the requested class |
|
| 748 | + * |
|
| 749 | + * @param string $class_name |
|
| 750 | + * @param boolean $addon |
|
| 751 | + * @return boolean |
|
| 752 | + */ |
|
| 753 | + public function clear_cached_class($class_name, $addon = false) |
|
| 754 | + { |
|
| 755 | + // have to specify something, but not anything that will conflict |
|
| 756 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 757 | + ? $this->_class_abbreviations[ $class_name ] |
|
| 758 | + : 'FANCY_BATMAN_PANTS'; |
|
| 759 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 760 | + // check if class has already been loaded, and return it if it has been |
|
| 761 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 762 | + $this->{$class_abbreviation} = null; |
|
| 763 | + return true; |
|
| 764 | + } |
|
| 765 | + if (isset($this->{$class_name})) { |
|
| 766 | + $this->{$class_name} = null; |
|
| 767 | + return true; |
|
| 768 | + } |
|
| 769 | + if (isset($this->LIB->{$class_name})) { |
|
| 770 | + unset($this->LIB->{$class_name}); |
|
| 771 | + return true; |
|
| 772 | + } |
|
| 773 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 774 | + unset($this->addons->{$class_name}); |
|
| 775 | + return true; |
|
| 776 | + } |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * _resolve_path |
|
| 783 | + * attempts to find a full valid filepath for the requested class. |
|
| 784 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 785 | + * then returns that path if the target file has been found and is readable |
|
| 786 | + * |
|
| 787 | + * @access protected |
|
| 788 | + * @param string $class_name |
|
| 789 | + * @param string $type |
|
| 790 | + * @param array $file_paths |
|
| 791 | + * @return string | bool |
|
| 792 | + */ |
|
| 793 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 794 | + { |
|
| 795 | + // make sure $file_paths is an array |
|
| 796 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
| 797 | + // cycle thru paths |
|
| 798 | + foreach ($file_paths as $key => $file_path) { |
|
| 799 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 800 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
| 801 | + // prep file type |
|
| 802 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
| 803 | + // build full file path |
|
| 804 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 805 | + //does the file exist and can be read ? |
|
| 806 | + if (is_readable($file_paths[$key])) { |
|
| 807 | + return $file_paths[$key]; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * _require_file |
|
| 817 | + * basically just performs a require_once() |
|
| 818 | + * but with some error handling |
|
| 819 | + * |
|
| 820 | + * @access protected |
|
| 821 | + * @param string $path |
|
| 822 | + * @param string $class_name |
|
| 823 | + * @param string $type |
|
| 824 | + * @param array $file_paths |
|
| 825 | + * @return boolean |
|
| 826 | + * @throws \EE_Error |
|
| 827 | + */ |
|
| 828 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 829 | + { |
|
| 830 | + // don't give up! you gotta... |
|
| 831 | + try { |
|
| 832 | + //does the file exist and can it be read ? |
|
| 833 | + if ( ! $path) { |
|
| 834 | + // so sorry, can't find the file |
|
| 835 | + throw new EE_Error ( |
|
| 836 | + sprintf( |
|
| 837 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
| 838 | + trim($type, '.'), |
|
| 839 | + $class_name, |
|
| 840 | + '<br />' . implode(',<br />', $file_paths) |
|
| 841 | + ) |
|
| 842 | + ); |
|
| 843 | + } |
|
| 844 | + // get the file |
|
| 845 | + require_once($path); |
|
| 846 | + // if the class isn't already declared somewhere |
|
| 847 | + if (class_exists($class_name, false) === false) { |
|
| 848 | + // so sorry, not a class |
|
| 849 | + throw new EE_Error( |
|
| 850 | + sprintf( |
|
| 851 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 852 | + $type, |
|
| 853 | + $path, |
|
| 854 | + $class_name |
|
| 855 | + ) |
|
| 856 | + ); |
|
| 857 | + } |
|
| 858 | + } catch (EE_Error $e) { |
|
| 859 | + $e->get_error(); |
|
| 860 | + return false; |
|
| 861 | + } |
|
| 862 | + return true; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * _create_object |
|
| 869 | + * Attempts to instantiate the requested class via any of the |
|
| 870 | + * commonly used instantiation methods employed throughout EE. |
|
| 871 | + * The priority for instantiation is as follows: |
|
| 872 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 873 | + * - model objects via their 'new_instance_from_db' method |
|
| 874 | + * - model objects via their 'new_instance' method |
|
| 875 | + * - "singleton" classes" via their 'instance' method |
|
| 876 | + * - standard instantiable classes via their __constructor |
|
| 877 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 878 | + * then the constructor for the requested class will be examined to determine |
|
| 879 | + * if any dependencies exist, and if they can be injected. |
|
| 880 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 881 | + * |
|
| 882 | + * @access protected |
|
| 883 | + * @param string $class_name |
|
| 884 | + * @param array $arguments |
|
| 885 | + * @param string $type |
|
| 886 | + * @param bool $from_db |
|
| 887 | + * @return null | object |
|
| 888 | + * @throws \EE_Error |
|
| 889 | + */ |
|
| 890 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 891 | + { |
|
| 892 | + $class_obj = null; |
|
| 893 | + $instantiation_mode = '0) none'; |
|
| 894 | + // don't give up! you gotta... |
|
| 895 | + try { |
|
| 896 | + // create reflection |
|
| 897 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 898 | + // make sure arguments are an array |
|
| 899 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
| 900 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 901 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 902 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 903 | + ? $arguments |
|
| 904 | + : array($arguments); |
|
| 905 | + // attempt to inject dependencies ? |
|
| 906 | + if ($this->_dependency_map->has($class_name)) { |
|
| 907 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 908 | + } |
|
| 909 | + // instantiate the class if possible |
|
| 910 | + if ($reflector->isAbstract()) { |
|
| 911 | + // nothing to instantiate, loading file was enough |
|
| 912 | + // does not throw an exception so $instantiation_mode is unused |
|
| 913 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 914 | + $class_obj = true; |
|
| 915 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
| 916 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 917 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
| 918 | + $class_obj = $reflector->newInstance(); |
|
| 919 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 920 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
| 921 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 922 | + } else if (method_exists($class_name, 'new_instance')) { |
|
| 923 | + $instantiation_mode = "4) new_instance()"; |
|
| 924 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 925 | + } else if (method_exists($class_name, 'instance')) { |
|
| 926 | + $instantiation_mode = "5) instance()"; |
|
| 927 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 928 | + } else if ($reflector->isInstantiable()) { |
|
| 929 | + $instantiation_mode = "6) constructor"; |
|
| 930 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 931 | + } else { |
|
| 932 | + // heh ? something's not right ! |
|
| 933 | + throw new EE_Error( |
|
| 934 | + sprintf( |
|
| 935 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 936 | + $type, |
|
| 937 | + $class_name |
|
| 938 | + ) |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + } catch (Exception $e) { |
|
| 942 | + if ( ! $e instanceof EE_Error) { |
|
| 943 | + $e = new EE_Error( |
|
| 944 | + sprintf( |
|
| 945 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
| 946 | + $class_name, |
|
| 947 | + '<br />', |
|
| 948 | + $e->getMessage(), |
|
| 949 | + $instantiation_mode |
|
| 950 | + ) |
|
| 951 | + ); |
|
| 952 | + } |
|
| 953 | + $e->get_error(); |
|
| 954 | + } |
|
| 955 | + return $class_obj; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 962 | + * @param array $array |
|
| 963 | + * @return bool |
|
| 964 | + */ |
|
| 965 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 966 | + { |
|
| 967 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * getReflectionClass |
|
| 974 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 975 | + * and returns that instead of creating a new one |
|
| 976 | + * |
|
| 977 | + * @access public |
|
| 978 | + * @param string $class_name |
|
| 979 | + * @return ReflectionClass |
|
| 980 | + */ |
|
| 981 | + public function get_ReflectionClass($class_name) |
|
| 982 | + { |
|
| 983 | + if ( |
|
| 984 | + ! isset($this->_reflectors[$class_name]) |
|
| 985 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 986 | + ) { |
|
| 987 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 988 | + } |
|
| 989 | + return $this->_reflectors[$class_name]; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * _resolve_dependencies |
|
| 996 | + * examines the constructor for the requested class to determine |
|
| 997 | + * if any dependencies exist, and if they can be injected. |
|
| 998 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 999 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1000 | + * For example: |
|
| 1001 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1002 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1003 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1004 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1005 | + * and the correct classes can be loaded |
|
| 1006 | + * |
|
| 1007 | + * @access protected |
|
| 1008 | + * @param ReflectionClass $reflector |
|
| 1009 | + * @param string $class_name |
|
| 1010 | + * @param array $arguments |
|
| 1011 | + * @return array |
|
| 1012 | + * @throws \ReflectionException |
|
| 1013 | + */ |
|
| 1014 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1015 | + { |
|
| 1016 | + // let's examine the constructor |
|
| 1017 | + $constructor = $reflector->getConstructor(); |
|
| 1018 | + // whu? huh? nothing? |
|
| 1019 | + if ( ! $constructor) { |
|
| 1020 | + return $arguments; |
|
| 1021 | + } |
|
| 1022 | + // get constructor parameters |
|
| 1023 | + $params = $constructor->getParameters(); |
|
| 1024 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1025 | + $argument_keys = array_keys($arguments); |
|
| 1026 | + // now loop thru all of the constructors expected parameters |
|
| 1027 | + foreach ($params as $index => $param) { |
|
| 1028 | + // is this a dependency for a specific class ? |
|
| 1029 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
| 1030 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1031 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1032 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1033 | + : $param_class; |
|
| 1034 | + if ( |
|
| 1035 | + // param is not even a class |
|
| 1036 | + empty($param_class) |
|
| 1037 | + // and something already exists in the incoming arguments for this param |
|
| 1038 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1039 | + ) { |
|
| 1040 | + // so let's skip this argument and move on to the next |
|
| 1041 | + continue; |
|
| 1042 | + } |
|
| 1043 | + if ( |
|
| 1044 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1045 | + ! empty($param_class) |
|
| 1046 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1047 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1048 | + ) { |
|
| 1049 | + // skip this argument and move on to the next |
|
| 1050 | + continue; |
|
| 1051 | + } |
|
| 1052 | + if ( |
|
| 1053 | + // parameter is type hinted as a class, and should be injected |
|
| 1054 | + ! empty($param_class) |
|
| 1055 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1056 | + ) { |
|
| 1057 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1058 | + } else { |
|
| 1059 | + try { |
|
| 1060 | + $arguments[$index] = $param->getDefaultValue(); |
|
| 1061 | + } catch (ReflectionException $e) { |
|
| 1062 | + throw new ReflectionException( |
|
| 1063 | + sprintf( |
|
| 1064 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1065 | + $e->getMessage(), |
|
| 1066 | + $param->getName() |
|
| 1067 | + ) |
|
| 1068 | + ); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + return $arguments; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * @access protected |
|
| 1079 | + * @param string $class_name |
|
| 1080 | + * @param string $param_class |
|
| 1081 | + * @param array $arguments |
|
| 1082 | + * @param mixed $index |
|
| 1083 | + * @return array |
|
| 1084 | + */ |
|
| 1085 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1086 | + { |
|
| 1087 | + $dependency = null; |
|
| 1088 | + // should dependency be loaded from cache ? |
|
| 1089 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1090 | + !== EE_Dependency_Map::load_new_object |
|
| 1091 | + ? true |
|
| 1092 | + : false; |
|
| 1093 | + // we might have a dependency... |
|
| 1094 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1095 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
| 1096 | + // and grab it if it exists |
|
| 1097 | + if ($cached_class instanceof $param_class) { |
|
| 1098 | + $dependency = $cached_class; |
|
| 1099 | + } else if ($param_class !== $class_name) { |
|
| 1100 | + // obtain the loader method from the dependency map |
|
| 1101 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1102 | + // is loader a custom closure ? |
|
| 1103 | + if ($loader instanceof Closure) { |
|
| 1104 | + $dependency = $loader(); |
|
| 1105 | + } else { |
|
| 1106 | + // set the cache on property for the recursive loading call |
|
| 1107 | + $this->_cache_on = $cache_on; |
|
| 1108 | + // if not, then let's try and load it via the registry |
|
| 1109 | + if ($loader && method_exists($this, $loader)) { |
|
| 1110 | + $dependency = $this->{$loader}($param_class); |
|
| 1111 | + } else { |
|
| 1112 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | + } |
|
| 1116 | + // did we successfully find the correct dependency ? |
|
| 1117 | + if ($dependency instanceof $param_class) { |
|
| 1118 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1119 | + if (isset($argument_keys[$index])) { |
|
| 1120 | + $arguments[$argument_keys[$index]] = $dependency; |
|
| 1121 | + } else { |
|
| 1122 | + $arguments[$index] = $dependency; |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + return $arguments; |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * _set_cached_class |
|
| 1132 | + * attempts to cache the instantiated class locally |
|
| 1133 | + * in one of the following places, in the following order: |
|
| 1134 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1135 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1136 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1137 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1138 | + * |
|
| 1139 | + * @access protected |
|
| 1140 | + * @param object $class_obj |
|
| 1141 | + * @param string $class_name |
|
| 1142 | + * @param string $class_prefix |
|
| 1143 | + * @param bool $from_db |
|
| 1144 | + * @return void |
|
| 1145 | + */ |
|
| 1146 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1147 | + { |
|
| 1148 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1149 | + return; |
|
| 1150 | + } |
|
| 1151 | + // return newly instantiated class |
|
| 1152 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1153 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1154 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1155 | + return; |
|
| 1156 | + } |
|
| 1157 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1158 | + if (property_exists($this, $class_name)) { |
|
| 1159 | + $this->{$class_name} = $class_obj; |
|
| 1160 | + return; |
|
| 1161 | + } |
|
| 1162 | + if ($class_prefix === 'addon') { |
|
| 1163 | + $this->addons->{$class_name} = $class_obj; |
|
| 1164 | + return; |
|
| 1165 | + } |
|
| 1166 | + if ( ! $from_db) { |
|
| 1167 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + /** |
|
| 1174 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1175 | + * |
|
| 1176 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1177 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1178 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1179 | + * @param array $arguments |
|
| 1180 | + * @return object |
|
| 1181 | + */ |
|
| 1182 | + public static function factory($classname, $arguments = array()) |
|
| 1183 | + { |
|
| 1184 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1185 | + if ($loader instanceof Closure) { |
|
| 1186 | + return $loader($arguments); |
|
| 1187 | + } |
|
| 1188 | + if (method_exists(EE_Registry::instance(), $loader)) { |
|
| 1189 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
| 1190 | + } |
|
| 1191 | + return null; |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1198 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1199 | + * |
|
| 1200 | + * @param string $name |
|
| 1201 | + * @return EE_Addon |
|
| 1202 | + */ |
|
| 1203 | + public function get_addon_by_name($name) |
|
| 1204 | + { |
|
| 1205 | + foreach ($this->addons as $addon) { |
|
| 1206 | + if ($addon->name() == $name) { |
|
| 1207 | + return $addon; |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | + return null; |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
| 1217 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
| 1218 | + * |
|
| 1219 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1220 | + */ |
|
| 1221 | + public function get_addons_by_name() |
|
| 1222 | + { |
|
| 1223 | + $addons = array(); |
|
| 1224 | + foreach ($this->addons as $addon) { |
|
| 1225 | + $addons[$addon->name()] = $addon; |
|
| 1226 | + } |
|
| 1227 | + return $addons; |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1234 | + * a stale copy of it around |
|
| 1235 | + * |
|
| 1236 | + * @param string $model_name |
|
| 1237 | + * @return \EEM_Base |
|
| 1238 | + * @throws \EE_Error |
|
| 1239 | + */ |
|
| 1240 | + public function reset_model($model_name) |
|
| 1241 | + { |
|
| 1242 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
| 1243 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1244 | + return null; |
|
| 1245 | + } |
|
| 1246 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1247 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
| 1248 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1249 | + } else { |
|
| 1250 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1251 | + } |
|
| 1252 | + return $this->LIB->{$model_class_name}; |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * Resets the registry. |
|
| 1259 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
| 1260 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1261 | + * - $_dependency_map |
|
| 1262 | + * - $_class_abbreviations |
|
| 1263 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1264 | + * - $REQ: Still on the same request so no need to change. |
|
| 1265 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1266 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
| 1267 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1268 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1269 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1270 | + * switch or on the restore. |
|
| 1271 | + * - $modules |
|
| 1272 | + * - $shortcodes |
|
| 1273 | + * - $widgets |
|
| 1274 | + * |
|
| 1275 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1276 | + * the Registry to its state at the beginning of the request |
|
| 1277 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1278 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
| 1279 | + * currently reinstantiate the singletons at the moment) |
|
| 1280 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
| 1281 | + * code instead can just change the model context to a different blog id if necessary |
|
| 1282 | + * @return EE_Registry |
|
| 1283 | + */ |
|
| 1284 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1285 | + { |
|
| 1286 | + $instance = self::instance(); |
|
| 1287 | + $instance->_cache_on = true; |
|
| 1288 | + // reset some "special" classes |
|
| 1289 | + EEH_Activation::reset(); |
|
| 1290 | + $instance->CFG = $instance->CFG->reset($hard, $reinstantiate); |
|
| 1291 | + $instance->CART = null; |
|
| 1292 | + $instance->MRM = null; |
|
| 1293 | + $instance->AssetsRegistry = null; |
|
| 1294 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1295 | + //messages reset |
|
| 1296 | + EED_Messages::reset(); |
|
| 1297 | + //handle of objects cached on LIB |
|
| 1298 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1299 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1300 | + if (EE_Registry::_reset_and_unset_object($class, $reset_models)) { |
|
| 1301 | + unset($instance->{$cache}->{$class_name}); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | + return $instance; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1312 | + * if passed object implements InterminableInterface, then return false, |
|
| 1313 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1314 | + * |
|
| 1315 | + * @param $object |
|
| 1316 | + * @param bool $reset_models |
|
| 1317 | + * @return bool returns true if cached object should be unset |
|
| 1318 | + */ |
|
| 1319 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1320 | + { |
|
| 1321 | + if (! is_object($object)) { |
|
| 1322 | + // don't unset anything that's not an object |
|
| 1323 | + return false; |
|
| 1324 | + } |
|
| 1325 | + if ($object instanceof EED_Module) { |
|
| 1326 | + $object::reset(); |
|
| 1327 | + // don't unset modules |
|
| 1328 | + return false; |
|
| 1329 | + } |
|
| 1330 | + if ($object instanceof ResettableInterface) { |
|
| 1331 | + if ($object instanceof EEM_Base) { |
|
| 1332 | + if ($reset_models) { |
|
| 1333 | + $object->reset(); |
|
| 1334 | + return true; |
|
| 1335 | + } |
|
| 1336 | + return false; |
|
| 1337 | + } |
|
| 1338 | + $object->reset(); |
|
| 1339 | + return true; |
|
| 1340 | + } |
|
| 1341 | + if ( ! $object instanceof InterminableInterface) { |
|
| 1342 | + return true; |
|
| 1343 | + } |
|
| 1344 | + return false; |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + /** |
|
| 1350 | + * @override magic methods |
|
| 1351 | + * @return void |
|
| 1352 | + */ |
|
| 1353 | + public final function __destruct() |
|
| 1354 | + { |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + |
|
| 1359 | + /** |
|
| 1360 | + * @param $a |
|
| 1361 | + * @param $b |
|
| 1362 | + */ |
|
| 1363 | + public final function __call($a, $b) |
|
| 1364 | + { |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * @param $a |
|
| 1371 | + */ |
|
| 1372 | + public final function __get($a) |
|
| 1373 | + { |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @param $a |
|
| 1380 | + * @param $b |
|
| 1381 | + */ |
|
| 1382 | + public final function __set($a, $b) |
|
| 1383 | + { |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * @param $a |
|
| 1390 | + */ |
|
| 1391 | + public final function __isset($a) |
|
| 1392 | + { |
|
| 1393 | + } |
|
| 1394 | 1394 | |
| 1395 | 1395 | |
| 1396 | 1396 | |
| 1397 | - /** |
|
| 1398 | - * @param $a |
|
| 1399 | - */ |
|
| 1400 | - public final function __unset($a) |
|
| 1401 | - { |
|
| 1402 | - } |
|
| 1397 | + /** |
|
| 1398 | + * @param $a |
|
| 1399 | + */ |
|
| 1400 | + public final function __unset($a) |
|
| 1401 | + { |
|
| 1402 | + } |
|
| 1403 | 1403 | |
| 1404 | 1404 | |
| 1405 | 1405 | |
| 1406 | - /** |
|
| 1407 | - * @return array |
|
| 1408 | - */ |
|
| 1409 | - public final function __sleep() |
|
| 1410 | - { |
|
| 1411 | - return array(); |
|
| 1412 | - } |
|
| 1406 | + /** |
|
| 1407 | + * @return array |
|
| 1408 | + */ |
|
| 1409 | + public final function __sleep() |
|
| 1410 | + { |
|
| 1411 | + return array(); |
|
| 1412 | + } |
|
| 1413 | 1413 | |
| 1414 | 1414 | |
| 1415 | 1415 | |
| 1416 | - public final function __wakeup() |
|
| 1417 | - { |
|
| 1418 | - } |
|
| 1416 | + public final function __wakeup() |
|
| 1417 | + { |
|
| 1418 | + } |
|
| 1419 | 1419 | |
| 1420 | 1420 | |
| 1421 | 1421 | |
| 1422 | - /** |
|
| 1423 | - * @return string |
|
| 1424 | - */ |
|
| 1425 | - public final function __toString() |
|
| 1426 | - { |
|
| 1427 | - return ''; |
|
| 1428 | - } |
|
| 1422 | + /** |
|
| 1423 | + * @return string |
|
| 1424 | + */ |
|
| 1425 | + public final function __toString() |
|
| 1426 | + { |
|
| 1427 | + return ''; |
|
| 1428 | + } |
|
| 1429 | 1429 | |
| 1430 | 1430 | |
| 1431 | 1431 | |
| 1432 | - public final function __invoke() |
|
| 1433 | - { |
|
| 1434 | - } |
|
| 1432 | + public final function __invoke() |
|
| 1433 | + { |
|
| 1434 | + } |
|
| 1435 | 1435 | |
| 1436 | 1436 | |
| 1437 | 1437 | |
| 1438 | - public final static function __set_state($array = array()) |
|
| 1439 | - { |
|
| 1440 | - return EE_Registry::instance(); |
|
| 1441 | - } |
|
| 1438 | + public final static function __set_state($array = array()) |
|
| 1439 | + { |
|
| 1440 | + return EE_Registry::instance(); |
|
| 1441 | + } |
|
| 1442 | 1442 | |
| 1443 | 1443 | |
| 1444 | 1444 | |
| 1445 | - public final function __clone() |
|
| 1446 | - { |
|
| 1447 | - } |
|
| 1445 | + public final function __clone() |
|
| 1446 | + { |
|
| 1447 | + } |
|
| 1448 | 1448 | |
| 1449 | 1449 | |
| 1450 | 1450 | |
| 1451 | - /** |
|
| 1452 | - * @param $a |
|
| 1453 | - * @param $b |
|
| 1454 | - */ |
|
| 1455 | - public final static function __callStatic($a, $b) |
|
| 1456 | - { |
|
| 1457 | - } |
|
| 1451 | + /** |
|
| 1452 | + * @param $a |
|
| 1453 | + * @param $b |
|
| 1454 | + */ |
|
| 1455 | + public final static function __callStatic($a, $b) |
|
| 1456 | + { |
|
| 1457 | + } |
|
| 1458 | 1458 | |
| 1459 | 1459 | |
| 1460 | 1460 | |
| 1461 | - /** |
|
| 1462 | - * Gets all the custom post type models defined |
|
| 1463 | - * |
|
| 1464 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1465 | - */ |
|
| 1466 | - public function cpt_models() |
|
| 1467 | - { |
|
| 1468 | - $cpt_models = array(); |
|
| 1469 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1470 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1471 | - $cpt_models[$short_name] = $classname; |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - return $cpt_models; |
|
| 1475 | - } |
|
| 1461 | + /** |
|
| 1462 | + * Gets all the custom post type models defined |
|
| 1463 | + * |
|
| 1464 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1465 | + */ |
|
| 1466 | + public function cpt_models() |
|
| 1467 | + { |
|
| 1468 | + $cpt_models = array(); |
|
| 1469 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1470 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1471 | + $cpt_models[$short_name] = $classname; |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + return $cpt_models; |
|
| 1475 | + } |
|
| 1476 | 1476 | |
| 1477 | 1477 | |
| 1478 | 1478 | |
| 1479 | - /** |
|
| 1480 | - * @return \EE_Config |
|
| 1481 | - */ |
|
| 1482 | - public static function CFG() |
|
| 1483 | - { |
|
| 1484 | - return self::instance()->CFG; |
|
| 1485 | - } |
|
| 1479 | + /** |
|
| 1480 | + * @return \EE_Config |
|
| 1481 | + */ |
|
| 1482 | + public static function CFG() |
|
| 1483 | + { |
|
| 1484 | + return self::instance()->CFG; |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | 1487 | |
| 1488 | 1488 | } |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public static function localize_i18n_js_strings() |
| 299 | 299 | { |
| 300 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
| 300 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
| 301 | 301 | foreach ($i18n_js_strings as $key => $value) { |
| 302 | 302 | if (is_scalar($value)) { |
| 303 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 303 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 306 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | EE_CORE, |
| 355 | 355 | EE_ADMIN, |
| 356 | 356 | EE_CPTS, |
| 357 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 358 | - EE_CORE . 'request_stack' . DS, |
|
| 359 | - EE_CORE . 'middleware' . DS, |
|
| 357 | + EE_CORE.'data_migration_scripts'.DS, |
|
| 358 | + EE_CORE.'request_stack'.DS, |
|
| 359 | + EE_CORE.'middleware'.DS, |
|
| 360 | 360 | ) |
| 361 | 361 | ); |
| 362 | 362 | // retrieve instantiated class |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $service_paths = apply_filters( |
| 380 | 380 | 'FHEE__EE_Registry__load_service__service_paths', |
| 381 | 381 | array( |
| 382 | - EE_CORE . 'services' . DS, |
|
| 382 | + EE_CORE.'services'.DS, |
|
| 383 | 383 | ) |
| 384 | 384 | ); |
| 385 | 385 | // retrieve instantiated class |
@@ -459,10 +459,10 @@ discard block |
||
| 459 | 459 | { |
| 460 | 460 | $paths = array( |
| 461 | 461 | EE_LIBRARIES, |
| 462 | - EE_LIBRARIES . 'messages' . DS, |
|
| 463 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 464 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 465 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 462 | + EE_LIBRARIES.'messages'.DS, |
|
| 463 | + EE_LIBRARIES.'shortcodes'.DS, |
|
| 464 | + EE_LIBRARIES.'qtips'.DS, |
|
| 465 | + EE_LIBRARIES.'payment_methods'.DS, |
|
| 466 | 466 | ); |
| 467 | 467 | // retrieve instantiated class |
| 468 | 468 | return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
@@ -501,10 +501,10 @@ discard block |
||
| 501 | 501 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
| 502 | 502 | { |
| 503 | 503 | $paths = array( |
| 504 | - EE_MODELS . 'fields' . DS, |
|
| 505 | - EE_MODELS . 'helpers' . DS, |
|
| 506 | - EE_MODELS . 'relations' . DS, |
|
| 507 | - EE_MODELS . 'strategies' . DS, |
|
| 504 | + EE_MODELS.'fields'.DS, |
|
| 505 | + EE_MODELS.'helpers'.DS, |
|
| 506 | + EE_MODELS.'relations'.DS, |
|
| 507 | + EE_MODELS.'strategies'.DS, |
|
| 508 | 508 | ); |
| 509 | 509 | // retrieve instantiated class |
| 510 | 510 | return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 592 | 592 | if ( ! class_exists($class_name)) { |
| 593 | 593 | // maybe the class is registered with a preceding \ |
| 594 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
| 594 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name; |
|
| 595 | 595 | // still doesn't exist ? |
| 596 | 596 | if ( ! class_exists($class_name)) { |
| 597 | 597 | return null; |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | // make sure $class_prefix is uppercase |
| 659 | 659 | $class_prefix = strtoupper(trim($class_prefix)); |
| 660 | 660 | // add class prefix ONCE!!! |
| 661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 661 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
| 662 | 662 | } |
| 663 | 663 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 664 | 664 | $class_exists = class_exists($class_name); |
@@ -721,8 +721,8 @@ discard block |
||
| 721 | 721 | return $this; |
| 722 | 722 | } |
| 723 | 723 | // have to specify something, but not anything that will conflict |
| 724 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 725 | - ? $this->_class_abbreviations[ $class_name ] |
|
| 724 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 725 | + ? $this->_class_abbreviations[$class_name] |
|
| 726 | 726 | : 'FANCY_BATMAN_PANTS'; |
| 727 | 727 | $class_name = str_replace('\\', '_', $class_name); |
| 728 | 728 | // check if class has already been loaded, and return it if it has been |
@@ -753,8 +753,8 @@ discard block |
||
| 753 | 753 | public function clear_cached_class($class_name, $addon = false) |
| 754 | 754 | { |
| 755 | 755 | // have to specify something, but not anything that will conflict |
| 756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
| 757 | - ? $this->_class_abbreviations[ $class_name ] |
|
| 756 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 757 | + ? $this->_class_abbreviations[$class_name] |
|
| 758 | 758 | : 'FANCY_BATMAN_PANTS'; |
| 759 | 759 | $class_name = str_replace('\\', '_', $class_name); |
| 760 | 760 | // check if class has already been loaded, and return it if it has been |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
| 800 | 800 | $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
| 801 | 801 | // prep file type |
| 802 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
| 802 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
| 803 | 803 | // build full file path |
| 804 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 804 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
| 805 | 805 | //does the file exist and can be read ? |
| 806 | 806 | if (is_readable($file_paths[$key])) { |
| 807 | 807 | return $file_paths[$key]; |
@@ -832,12 +832,12 @@ discard block |
||
| 832 | 832 | //does the file exist and can it be read ? |
| 833 | 833 | if ( ! $path) { |
| 834 | 834 | // so sorry, can't find the file |
| 835 | - throw new EE_Error ( |
|
| 835 | + throw new EE_Error( |
|
| 836 | 836 | sprintf( |
| 837 | 837 | __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
| 838 | 838 | trim($type, '.'), |
| 839 | 839 | $class_name, |
| 840 | - '<br />' . implode(',<br />', $file_paths) |
|
| 840 | + '<br />'.implode(',<br />', $file_paths) |
|
| 841 | 841 | ) |
| 842 | 842 | ); |
| 843 | 843 | } |
@@ -1318,7 +1318,7 @@ discard block |
||
| 1318 | 1318 | */ |
| 1319 | 1319 | private static function _reset_and_unset_object($object, $reset_models) |
| 1320 | 1320 | { |
| 1321 | - if (! is_object($object)) { |
|
| 1321 | + if ( ! is_object($object)) { |
|
| 1322 | 1322 | // don't unset anything that's not an object |
| 1323 | 1323 | return false; |
| 1324 | 1324 | } |