@@ -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 | |
@@ -17,74 +17,74 @@ discard block |
||
| 17 | 17 | class EEH_Schema { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * generates JSON-based linked data for an event |
|
| 22 | - * |
|
| 23 | - * @param EE_Event $event |
|
| 24 | - * @throws EE_Error |
|
| 25 | - */ |
|
| 26 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
| 27 | - { |
|
| 28 | - //Check we have a valid datetime for the event |
|
| 29 | - if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - $template_args = array( |
|
| 34 | - 'event_permalink' => '', |
|
| 35 | - 'event_name' => '', |
|
| 36 | - 'event_description' => '', |
|
| 37 | - 'event_start' => '', |
|
| 38 | - 'event_end' => '', |
|
| 39 | - 'currency' => '', |
|
| 40 | - 'event_tickets' => array(), |
|
| 41 | - 'venue_name' => '', |
|
| 42 | - 'venue_url' => '', |
|
| 43 | - 'venue_locality' => '', |
|
| 44 | - 'venue_region' => '', |
|
| 45 | - 'event_image' => '', |
|
| 46 | - ); |
|
| 47 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
| 48 | - $template_args['event_name'] = $event->name(); |
|
| 49 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
| 50 | - // clone datetime so that date formats don't override those for the original datetime |
|
| 51 | - $primary_datetime = clone $event->primary_datetime(); |
|
| 52 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
| 53 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
| 54 | - unset($primary_datetime); |
|
| 55 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 56 | - foreach ($event->tickets() as $original_ticket) { |
|
| 57 | - // clone tickets so that date formats don't override those for the original ticket |
|
| 58 | - $ticket= clone $original_ticket; |
|
| 59 | - $ID = $ticket->ID(); |
|
| 60 | - $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 61 | - $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 62 | - $template_args['event_tickets'][$ID]['price'] = number_format( |
|
| 63 | - $ticket->price(), |
|
| 64 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 65 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 66 | - EE_Registry::instance()->CFG->currency->thsnds |
|
| 67 | - ); |
|
| 68 | - unset($ticket); |
|
| 69 | - } |
|
| 70 | - $VNU_ID = espresso_venue_id(); |
|
| 71 | - if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 72 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 73 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 74 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 75 | - $template_args['venue_locality'] = $venue->city(); |
|
| 76 | - $template_args['venue_region'] = $venue->state_name(); |
|
| 77 | - } |
|
| 78 | - $template_args['event_image'] = $event->feature_image_url(); |
|
| 79 | - $template_args = apply_filters( |
|
| 80 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 81 | - $template_args, |
|
| 82 | - $event, |
|
| 83 | - $VNU_ID |
|
| 84 | - ); |
|
| 85 | - extract($template_args, EXTR_OVERWRITE); |
|
| 86 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 87 | - } |
|
| 20 | + /** |
|
| 21 | + * generates JSON-based linked data for an event |
|
| 22 | + * |
|
| 23 | + * @param EE_Event $event |
|
| 24 | + * @throws EE_Error |
|
| 25 | + */ |
|
| 26 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
| 27 | + { |
|
| 28 | + //Check we have a valid datetime for the event |
|
| 29 | + if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + $template_args = array( |
|
| 34 | + 'event_permalink' => '', |
|
| 35 | + 'event_name' => '', |
|
| 36 | + 'event_description' => '', |
|
| 37 | + 'event_start' => '', |
|
| 38 | + 'event_end' => '', |
|
| 39 | + 'currency' => '', |
|
| 40 | + 'event_tickets' => array(), |
|
| 41 | + 'venue_name' => '', |
|
| 42 | + 'venue_url' => '', |
|
| 43 | + 'venue_locality' => '', |
|
| 44 | + 'venue_region' => '', |
|
| 45 | + 'event_image' => '', |
|
| 46 | + ); |
|
| 47 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
| 48 | + $template_args['event_name'] = $event->name(); |
|
| 49 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
| 50 | + // clone datetime so that date formats don't override those for the original datetime |
|
| 51 | + $primary_datetime = clone $event->primary_datetime(); |
|
| 52 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
| 53 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
| 54 | + unset($primary_datetime); |
|
| 55 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 56 | + foreach ($event->tickets() as $original_ticket) { |
|
| 57 | + // clone tickets so that date formats don't override those for the original ticket |
|
| 58 | + $ticket= clone $original_ticket; |
|
| 59 | + $ID = $ticket->ID(); |
|
| 60 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 61 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 62 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
| 63 | + $ticket->price(), |
|
| 64 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 65 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 66 | + EE_Registry::instance()->CFG->currency->thsnds |
|
| 67 | + ); |
|
| 68 | + unset($ticket); |
|
| 69 | + } |
|
| 70 | + $VNU_ID = espresso_venue_id(); |
|
| 71 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 72 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 73 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 74 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 75 | + $template_args['venue_locality'] = $venue->city(); |
|
| 76 | + $template_args['venue_region'] = $venue->state_name(); |
|
| 77 | + } |
|
| 78 | + $template_args['event_image'] = $event->feature_image_url(); |
|
| 79 | + $template_args = apply_filters( |
|
| 80 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 81 | + $template_args, |
|
| 82 | + $event, |
|
| 83 | + $VNU_ID |
|
| 84 | + ); |
|
| 85 | + extract($template_args, EXTR_OVERWRITE); |
|
| 86 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public static function location( $location = null ) { |
| 100 | 100 | return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
| 101 | - . $location |
|
| 102 | - . '</div>' : ''; |
|
| 101 | + . $location |
|
| 102 | + . '</div>' : ''; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public static function postalCode( EEI_Address $obj_with_address = null ) { |
| 221 | 221 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
| 222 | - . $obj_with_address->zip() |
|
| 223 | - . '</span>' : ''; |
|
| 222 | + . $obj_with_address->zip() |
|
| 223 | + . '</span>' : ''; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | //Check the URL includes a scheme |
| 255 | 255 | $parsed_url = parse_url($url); |
| 256 | 256 | if ( empty($parsed_url['scheme']) ) { |
| 257 | - $url = 'http://' . ltrim($url, '/'); |
|
| 257 | + $url = 'http://' . ltrim($url, '/'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $atts = ''; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public static function add_json_linked_data_for_event(EE_Event $event) |
| 27 | 27 | { |
| 28 | 28 | //Check we have a valid datetime for the event |
| 29 | - if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 29 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 30 | 30 | return; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
| 56 | 56 | foreach ($event->tickets() as $original_ticket) { |
| 57 | 57 | // clone tickets so that date formats don't override those for the original ticket |
| 58 | - $ticket= clone $original_ticket; |
|
| 58 | + $ticket = clone $original_ticket; |
|
| 59 | 59 | $ID = $ticket->ID(); |
| 60 | 60 | $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
| 61 | 61 | $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $VNU_ID |
| 84 | 84 | ); |
| 85 | 85 | extract($template_args, EXTR_OVERWRITE); |
| 86 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 86 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @param string $location |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - public static function location( $location = null ) { |
|
| 100 | - return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 99 | + public static function location($location = null) { |
|
| 100 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 101 | 101 | . $location |
| 102 | 102 | . '</div>' : ''; |
| 103 | 103 | } |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param string $name |
| 113 | 113 | * @return string |
| 114 | 114 | */ |
| 115 | - public static function name( $name = null ) { |
|
| 116 | - return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
| 115 | + public static function name($name = null) { |
|
| 116 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * @param EEI_Address $obj_with_address |
| 127 | 127 | * @return string |
| 128 | 128 | */ |
| 129 | - public static function streetAddress( EEI_Address $obj_with_address = null ) { |
|
| 129 | + public static function streetAddress(EEI_Address $obj_with_address = null) { |
|
| 130 | 130 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
| 131 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
| 131 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | * @param EEI_Address $obj_with_address |
| 142 | 142 | * @return string |
| 143 | 143 | */ |
| 144 | - public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) { |
|
| 144 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) { |
|
| 145 | 145 | // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
| 146 | - if ( preg_match( |
|
| 146 | + if (preg_match( |
|
| 147 | 147 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
| 148 | 148 | $obj_with_address->address2() |
| 149 | - ) ) { |
|
| 149 | + )) { |
|
| 150 | 150 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
| 151 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
| 151 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
| 152 | 152 | } else { |
| 153 | 153 | return $obj_with_address->address2(); |
| 154 | 154 | } |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | * @param EEI_Address $obj_with_address |
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | - public static function addressLocality( EEI_Address $obj_with_address = null ) { |
|
| 167 | + public static function addressLocality(EEI_Address $obj_with_address = null) { |
|
| 168 | 168 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
| 169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
| 169 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | * @param EEI_Address $obj_with_address |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public static function addressRegion( EEI_Address $obj_with_address = null ) { |
|
| 182 | + public static function addressRegion(EEI_Address $obj_with_address = null) { |
|
| 183 | 183 | $state = $obj_with_address->state_name(); |
| 184 | - if ( ! empty( $state ) ) { |
|
| 185 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
| 184 | + if ( ! empty($state)) { |
|
| 185 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
| 186 | 186 | } else { |
| 187 | 187 | return ''; |
| 188 | 188 | } |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | * @param EEI_Address $obj_with_address |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public static function addressCountry( EEI_Address $obj_with_address = null ) { |
|
| 201 | + public static function addressCountry(EEI_Address $obj_with_address = null) { |
|
| 202 | 202 | $country = $obj_with_address->country_name(); |
| 203 | - if ( ! empty( $country ) ) { |
|
| 204 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
| 203 | + if ( ! empty($country)) { |
|
| 204 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
| 205 | 205 | } else { |
| 206 | 206 | return ''; |
| 207 | 207 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @param EEI_Address $obj_with_address |
| 218 | 218 | * @return string |
| 219 | 219 | */ |
| 220 | - public static function postalCode( EEI_Address $obj_with_address = null ) { |
|
| 220 | + public static function postalCode(EEI_Address $obj_with_address = null) { |
|
| 221 | 221 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
| 222 | 222 | . $obj_with_address->zip() |
| 223 | 223 | . '</span>' : ''; |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param string $phone_nmbr |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - public static function telephone( $phone_nmbr = null ) { |
|
| 237 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
| 236 | + public static function telephone($phone_nmbr = null) { |
|
| 237 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
| 238 | 238 | : ''; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
| 251 | 251 | * @return string (link) |
| 252 | 252 | */ |
| 253 | - public static function url( $url = null, $text = null, $attributes = array() ) { |
|
| 253 | + public static function url($url = null, $text = null, $attributes = array()) { |
|
| 254 | 254 | //Check the URL includes a scheme |
| 255 | 255 | $parsed_url = parse_url($url); |
| 256 | - if ( empty($parsed_url['scheme']) ) { |
|
| 257 | - $url = 'http://' . ltrim($url, '/'); |
|
| 256 | + if (empty($parsed_url['scheme'])) { |
|
| 257 | + $url = 'http://'.ltrim($url, '/'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $atts = ''; |
| 261 | - foreach ( $attributes as $attribute => $value ) { |
|
| 262 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
| 261 | + foreach ($attributes as $attribute => $value) { |
|
| 262 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
| 263 | 263 | } |
| 264 | 264 | $text = $text !== null && $text !== '' ? $text : $url; |
| 265 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
| 265 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
| 266 | 266 | : ''; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -17,243 +17,243 @@ |
||
| 17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array $_previous_routes |
|
| 22 | - */ |
|
| 23 | - private static $_previous_routes = array(); |
|
| 20 | + /** |
|
| 21 | + * @var array $_previous_routes |
|
| 22 | + */ |
|
| 23 | + private static $_previous_routes = array(); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var WP_Query $WP_Query |
|
| 27 | - */ |
|
| 28 | - public $WP_Query; |
|
| 25 | + /** |
|
| 26 | + * @var WP_Query $WP_Query |
|
| 27 | + */ |
|
| 28 | + public $WP_Query; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * EE_Module_Request_Router constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - } |
|
| 32 | + /** |
|
| 33 | + * EE_Module_Request_Router constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 43 | - * on subsequent calls to this method, |
|
| 44 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 45 | - * and checks if the last called route has any forwarding routes registered for it |
|
| 46 | - * |
|
| 47 | - * @param WP_Query $WP_Query |
|
| 48 | - * @return NULL|string |
|
| 49 | - * @throws EE_Error |
|
| 50 | - * @throws ReflectionException |
|
| 51 | - */ |
|
| 52 | - public function get_route(WP_Query $WP_Query) |
|
| 53 | - { |
|
| 54 | - $this->WP_Query = $WP_Query; |
|
| 55 | - // assume this if first route being called |
|
| 56 | - $previous_route = false; |
|
| 57 | - // but is it really ??? |
|
| 58 | - if (! empty(self::$_previous_routes)) { |
|
| 59 | - // get last run route |
|
| 60 | - $previous_routes = array_values(self::$_previous_routes); |
|
| 61 | - $previous_route = array_pop($previous_routes); |
|
| 62 | - } |
|
| 63 | - // has another route already been run ? |
|
| 64 | - if ($previous_route) { |
|
| 65 | - // check if forwarding has been set |
|
| 66 | - $current_route = $this->get_forward($previous_route); |
|
| 67 | - try { |
|
| 68 | - //check for recursive forwarding |
|
| 69 | - if (isset(self::$_previous_routes[$current_route])) { |
|
| 70 | - throw new EE_Error( |
|
| 71 | - sprintf( |
|
| 72 | - __( |
|
| 73 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 74 | - 'event_espresso' |
|
| 75 | - ), |
|
| 76 | - $current_route |
|
| 77 | - ) |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - } catch (EE_Error $e) { |
|
| 81 | - $e->get_error(); |
|
| 82 | - return null; |
|
| 83 | - } |
|
| 84 | - } else { |
|
| 85 | - // first route called |
|
| 86 | - $current_route = null; |
|
| 87 | - // grab all routes |
|
| 88 | - $routes = EE_Config::get_routes(); |
|
| 89 | - //d( $routes ); |
|
| 90 | - foreach ($routes as $key => $route) { |
|
| 91 | - // check request for module route |
|
| 92 | - if (EE_Registry::instance()->REQ->is_set($key)) { |
|
| 93 | - //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
| 94 | - $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
| 95 | - if ($current_route) { |
|
| 96 | - $current_route = array($key, $current_route); |
|
| 97 | - //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
| 98 | - break; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - // sorry, but I can't read what you route ! |
|
| 104 | - if (empty($current_route)) { |
|
| 105 | - return null; |
|
| 106 | - } |
|
| 107 | - //add route to previous routes array |
|
| 108 | - self::$_previous_routes[] = $current_route; |
|
| 109 | - return $current_route; |
|
| 110 | - } |
|
| 41 | + /** |
|
| 42 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 43 | + * on subsequent calls to this method, |
|
| 44 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 45 | + * and checks if the last called route has any forwarding routes registered for it |
|
| 46 | + * |
|
| 47 | + * @param WP_Query $WP_Query |
|
| 48 | + * @return NULL|string |
|
| 49 | + * @throws EE_Error |
|
| 50 | + * @throws ReflectionException |
|
| 51 | + */ |
|
| 52 | + public function get_route(WP_Query $WP_Query) |
|
| 53 | + { |
|
| 54 | + $this->WP_Query = $WP_Query; |
|
| 55 | + // assume this if first route being called |
|
| 56 | + $previous_route = false; |
|
| 57 | + // but is it really ??? |
|
| 58 | + if (! empty(self::$_previous_routes)) { |
|
| 59 | + // get last run route |
|
| 60 | + $previous_routes = array_values(self::$_previous_routes); |
|
| 61 | + $previous_route = array_pop($previous_routes); |
|
| 62 | + } |
|
| 63 | + // has another route already been run ? |
|
| 64 | + if ($previous_route) { |
|
| 65 | + // check if forwarding has been set |
|
| 66 | + $current_route = $this->get_forward($previous_route); |
|
| 67 | + try { |
|
| 68 | + //check for recursive forwarding |
|
| 69 | + if (isset(self::$_previous_routes[$current_route])) { |
|
| 70 | + throw new EE_Error( |
|
| 71 | + sprintf( |
|
| 72 | + __( |
|
| 73 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 74 | + 'event_espresso' |
|
| 75 | + ), |
|
| 76 | + $current_route |
|
| 77 | + ) |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + } catch (EE_Error $e) { |
|
| 81 | + $e->get_error(); |
|
| 82 | + return null; |
|
| 83 | + } |
|
| 84 | + } else { |
|
| 85 | + // first route called |
|
| 86 | + $current_route = null; |
|
| 87 | + // grab all routes |
|
| 88 | + $routes = EE_Config::get_routes(); |
|
| 89 | + //d( $routes ); |
|
| 90 | + foreach ($routes as $key => $route) { |
|
| 91 | + // check request for module route |
|
| 92 | + if (EE_Registry::instance()->REQ->is_set($key)) { |
|
| 93 | + //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
| 94 | + $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
| 95 | + if ($current_route) { |
|
| 96 | + $current_route = array($key, $current_route); |
|
| 97 | + //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
| 98 | + break; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + // sorry, but I can't read what you route ! |
|
| 104 | + if (empty($current_route)) { |
|
| 105 | + return null; |
|
| 106 | + } |
|
| 107 | + //add route to previous routes array |
|
| 108 | + self::$_previous_routes[] = $current_route; |
|
| 109 | + return $current_route; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 116 | - * |
|
| 117 | - * @param string $key |
|
| 118 | - * @param string $current_route |
|
| 119 | - * @return mixed EED_Module | boolean |
|
| 120 | - * @throws EE_Error |
|
| 121 | - * @throws ReflectionException |
|
| 122 | - */ |
|
| 123 | - public function resolve_route($key, $current_route) |
|
| 124 | - { |
|
| 125 | - // get module method that route has been mapped to |
|
| 126 | - $module_method = EE_Config::get_route($current_route, $key); |
|
| 127 | - //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 128 | - // verify result was returned |
|
| 129 | - if (empty($module_method)) { |
|
| 130 | - $msg = sprintf( |
|
| 131 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 132 | - $current_route |
|
| 133 | - ); |
|
| 134 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - // verify that result is an array |
|
| 138 | - if (! is_array($module_method)) { |
|
| 139 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 141 | - return false; |
|
| 142 | - } |
|
| 143 | - // grab module name |
|
| 144 | - $module_name = $module_method[0]; |
|
| 145 | - // verify that a class method was registered properly |
|
| 146 | - if (! isset($module_method[1])) { |
|
| 147 | - $msg = sprintf( |
|
| 148 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 149 | - $current_route |
|
| 150 | - ); |
|
| 151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - // grab method |
|
| 155 | - $method = $module_method[1]; |
|
| 156 | - // verify that class exists |
|
| 157 | - if (! class_exists($module_name)) { |
|
| 158 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 159 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 160 | - return false; |
|
| 161 | - } |
|
| 162 | - // verify that method exists |
|
| 163 | - if (! method_exists($module_name, $method)) { |
|
| 164 | - $msg = sprintf( |
|
| 165 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
| 166 | - ); |
|
| 167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - // instantiate module and call route method |
|
| 171 | - return $this->_module_router($module_name, $method); |
|
| 172 | - } |
|
| 114 | + /** |
|
| 115 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 116 | + * |
|
| 117 | + * @param string $key |
|
| 118 | + * @param string $current_route |
|
| 119 | + * @return mixed EED_Module | boolean |
|
| 120 | + * @throws EE_Error |
|
| 121 | + * @throws ReflectionException |
|
| 122 | + */ |
|
| 123 | + public function resolve_route($key, $current_route) |
|
| 124 | + { |
|
| 125 | + // get module method that route has been mapped to |
|
| 126 | + $module_method = EE_Config::get_route($current_route, $key); |
|
| 127 | + //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 128 | + // verify result was returned |
|
| 129 | + if (empty($module_method)) { |
|
| 130 | + $msg = sprintf( |
|
| 131 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 132 | + $current_route |
|
| 133 | + ); |
|
| 134 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + // verify that result is an array |
|
| 138 | + if (! is_array($module_method)) { |
|
| 139 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 140 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | + // grab module name |
|
| 144 | + $module_name = $module_method[0]; |
|
| 145 | + // verify that a class method was registered properly |
|
| 146 | + if (! isset($module_method[1])) { |
|
| 147 | + $msg = sprintf( |
|
| 148 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 149 | + $current_route |
|
| 150 | + ); |
|
| 151 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + // grab method |
|
| 155 | + $method = $module_method[1]; |
|
| 156 | + // verify that class exists |
|
| 157 | + if (! class_exists($module_name)) { |
|
| 158 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 159 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 162 | + // verify that method exists |
|
| 163 | + if (! method_exists($module_name, $method)) { |
|
| 164 | + $msg = sprintf( |
|
| 165 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
| 166 | + ); |
|
| 167 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + // instantiate module and call route method |
|
| 171 | + return $this->_module_router($module_name, $method); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 178 | - * |
|
| 179 | - * @param string $module_name |
|
| 180 | - * @return EED_Module|object|null |
|
| 181 | - * @throws ReflectionException |
|
| 182 | - */ |
|
| 183 | - public static function module_factory($module_name) |
|
| 184 | - { |
|
| 185 | - if ($module_name === 'EED_Module') { |
|
| 186 | - EE_Error::add_error( |
|
| 187 | - sprintf( |
|
| 188 | - __( |
|
| 189 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 190 | - 'event_espresso' |
|
| 191 | - ), $module_name |
|
| 192 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
| 193 | - ); |
|
| 194 | - return null; |
|
| 195 | - } |
|
| 196 | - // instantiate module class |
|
| 197 | - $module = new $module_name(); |
|
| 198 | - // ensure that class is actually a module |
|
| 199 | - if (! $module instanceof EED_Module) { |
|
| 200 | - EE_Error::add_error( |
|
| 201 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 202 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 203 | - ); |
|
| 204 | - return null; |
|
| 205 | - } |
|
| 206 | - return $module; |
|
| 207 | - } |
|
| 176 | + /** |
|
| 177 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 178 | + * |
|
| 179 | + * @param string $module_name |
|
| 180 | + * @return EED_Module|object|null |
|
| 181 | + * @throws ReflectionException |
|
| 182 | + */ |
|
| 183 | + public static function module_factory($module_name) |
|
| 184 | + { |
|
| 185 | + if ($module_name === 'EED_Module') { |
|
| 186 | + EE_Error::add_error( |
|
| 187 | + sprintf( |
|
| 188 | + __( |
|
| 189 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 190 | + 'event_espresso' |
|
| 191 | + ), $module_name |
|
| 192 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
| 193 | + ); |
|
| 194 | + return null; |
|
| 195 | + } |
|
| 196 | + // instantiate module class |
|
| 197 | + $module = new $module_name(); |
|
| 198 | + // ensure that class is actually a module |
|
| 199 | + if (! $module instanceof EED_Module) { |
|
| 200 | + EE_Error::add_error( |
|
| 201 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 202 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 203 | + ); |
|
| 204 | + return null; |
|
| 205 | + } |
|
| 206 | + return $module; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 213 | - * |
|
| 214 | - * @param string $module_name |
|
| 215 | - * @param string $method |
|
| 216 | - * @return EED_Module|null |
|
| 217 | - * @throws EE_Error |
|
| 218 | - * @throws ReflectionException |
|
| 219 | - */ |
|
| 220 | - private function _module_router($module_name, $method) |
|
| 221 | - { |
|
| 222 | - // instantiate module class |
|
| 223 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 224 | - if ($module instanceof EED_Module) { |
|
| 225 | - // and call whatever action the route was for |
|
| 226 | - try { |
|
| 227 | - call_user_func(array($module, $method), $this->WP_Query); |
|
| 228 | - } catch (EE_Error $e) { |
|
| 229 | - $e->get_error(); |
|
| 230 | - return null; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - return $module; |
|
| 234 | - } |
|
| 211 | + /** |
|
| 212 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 213 | + * |
|
| 214 | + * @param string $module_name |
|
| 215 | + * @param string $method |
|
| 216 | + * @return EED_Module|null |
|
| 217 | + * @throws EE_Error |
|
| 218 | + * @throws ReflectionException |
|
| 219 | + */ |
|
| 220 | + private function _module_router($module_name, $method) |
|
| 221 | + { |
|
| 222 | + // instantiate module class |
|
| 223 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 224 | + if ($module instanceof EED_Module) { |
|
| 225 | + // and call whatever action the route was for |
|
| 226 | + try { |
|
| 227 | + call_user_func(array($module, $method), $this->WP_Query); |
|
| 228 | + } catch (EE_Error $e) { |
|
| 229 | + $e->get_error(); |
|
| 230 | + return null; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + return $module; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * @param $current_route |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public function get_forward($current_route) |
|
| 243 | - { |
|
| 244 | - return EE_Config::get_forward($current_route); |
|
| 245 | - } |
|
| 238 | + /** |
|
| 239 | + * @param $current_route |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public function get_forward($current_route) |
|
| 243 | + { |
|
| 244 | + return EE_Config::get_forward($current_route); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * @param $current_route |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function get_view($current_route) |
|
| 254 | - { |
|
| 255 | - return EE_Config::get_view($current_route); |
|
| 256 | - } |
|
| 249 | + /** |
|
| 250 | + * @param $current_route |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function get_view($current_route) |
|
| 254 | + { |
|
| 255 | + return EE_Config::get_view($current_route); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | |
| 259 | 259 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // assume this if first route being called |
| 56 | 56 | $previous_route = false; |
| 57 | 57 | // but is it really ??? |
| 58 | - if (! empty(self::$_previous_routes)) { |
|
| 58 | + if ( ! empty(self::$_previous_routes)) { |
|
| 59 | 59 | // get last run route |
| 60 | 60 | $previous_routes = array_values(self::$_previous_routes); |
| 61 | 61 | $previous_route = array_pop($previous_routes); |
@@ -135,36 +135,36 @@ discard block |
||
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | 137 | // verify that result is an array |
| 138 | - if (! is_array($module_method)) { |
|
| 138 | + if ( ! is_array($module_method)) { |
|
| 139 | 139 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
| 140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 140 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 141 | 141 | return false; |
| 142 | 142 | } |
| 143 | 143 | // grab module name |
| 144 | 144 | $module_name = $module_method[0]; |
| 145 | 145 | // verify that a class method was registered properly |
| 146 | - if (! isset($module_method[1])) { |
|
| 146 | + if ( ! isset($module_method[1])) { |
|
| 147 | 147 | $msg = sprintf( |
| 148 | 148 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
| 149 | 149 | $current_route |
| 150 | 150 | ); |
| 151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 151 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | 152 | return false; |
| 153 | 153 | } |
| 154 | 154 | // grab method |
| 155 | 155 | $method = $module_method[1]; |
| 156 | 156 | // verify that class exists |
| 157 | - if (! class_exists($module_name)) { |
|
| 157 | + if ( ! class_exists($module_name)) { |
|
| 158 | 158 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
| 159 | 159 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 160 | 160 | return false; |
| 161 | 161 | } |
| 162 | 162 | // verify that method exists |
| 163 | - if (! method_exists($module_name, $method)) { |
|
| 163 | + if ( ! method_exists($module_name, $method)) { |
|
| 164 | 164 | $msg = sprintf( |
| 165 | 165 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
| 166 | 166 | ); |
| 167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 167 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | // instantiate module and call route method |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | // instantiate module class |
| 197 | 197 | $module = new $module_name(); |
| 198 | 198 | // ensure that class is actually a module |
| 199 | - if (! $module instanceof EED_Module) { |
|
| 199 | + if ( ! $module instanceof EED_Module) { |
|
| 200 | 200 | EE_Error::add_error( |
| 201 | 201 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
| 202 | 202 | __FILE__, __FUNCTION__, __LINE__ |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function __construct($generator) |
| 41 | 41 | { |
| 42 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 42 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 43 | 43 | throw new InvalidArgumentException( |
| 44 | 44 | esc_html__( |
| 45 | 45 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function load($fqcn, $arguments = array(), $shared = true) |
| 63 | 63 | { |
| 64 | - if($this->generator instanceof EE_Registry) { |
|
| 64 | + if ($this->generator instanceof EE_Registry) { |
|
| 65 | 65 | return $this->generator->create($fqcn, $arguments, $shared); |
| 66 | 66 | } |
| 67 | 67 | $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
@@ -26,67 +26,67 @@ |
||
| 26 | 26 | class CoreLoader implements LoaderDecoratorInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var EE_Registry|CoffeeShop $generator |
|
| 31 | - */ |
|
| 32 | - private $generator; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * CoreLoader constructor. |
|
| 38 | - * |
|
| 39 | - * @param EE_Registry|CoffeeShop $generator |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - */ |
|
| 42 | - public function __construct($generator) |
|
| 43 | - { |
|
| 44 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | - throw new InvalidArgumentException( |
|
| 46 | - esc_html__( |
|
| 47 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 52 | - $this->generator = $generator; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $fqcn |
|
| 59 | - * @param array $arguments |
|
| 60 | - * @param bool $shared |
|
| 61 | - * @return mixed |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ServiceNotFoundException |
|
| 64 | - * @throws ReflectionException |
|
| 65 | - */ |
|
| 66 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | - { |
|
| 68 | - if($this->generator instanceof EE_Registry) { |
|
| 69 | - return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | - } |
|
| 71 | - $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | - return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | - |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * calls reset() on generator if method exists |
|
| 80 | - * |
|
| 81 | - * @throws EE_Error |
|
| 82 | - * @throws ReflectionException |
|
| 83 | - */ |
|
| 84 | - public function reset() |
|
| 85 | - { |
|
| 86 | - if (method_exists($this->generator, 'reset')) { |
|
| 87 | - $this->generator->reset(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 29 | + /** |
|
| 30 | + * @var EE_Registry|CoffeeShop $generator |
|
| 31 | + */ |
|
| 32 | + private $generator; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * CoreLoader constructor. |
|
| 38 | + * |
|
| 39 | + * @param EE_Registry|CoffeeShop $generator |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + */ |
|
| 42 | + public function __construct($generator) |
|
| 43 | + { |
|
| 44 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | + throw new InvalidArgumentException( |
|
| 46 | + esc_html__( |
|
| 47 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + $this->generator = $generator; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $fqcn |
|
| 59 | + * @param array $arguments |
|
| 60 | + * @param bool $shared |
|
| 61 | + * @return mixed |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ServiceNotFoundException |
|
| 64 | + * @throws ReflectionException |
|
| 65 | + */ |
|
| 66 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | + { |
|
| 68 | + if($this->generator instanceof EE_Registry) { |
|
| 69 | + return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | + } |
|
| 71 | + $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | + return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | + |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * calls reset() on generator if method exists |
|
| 80 | + * |
|
| 81 | + * @throws EE_Error |
|
| 82 | + * @throws ReflectionException |
|
| 83 | + */ |
|
| 84 | + public function reset() |
|
| 85 | + { |
|
| 86 | + if (method_exists($this->generator, 'reset')) { |
|
| 87 | + $this->generator->reset(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | // End of file CoreLoader.php |
@@ -13,24 +13,24 @@ discard block |
||
| 13 | 13 | class Events_Admin_List_Table extends EE_Admin_List_Table |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EE_Datetime |
|
| 18 | - */ |
|
| 19 | - private $_dtt; |
|
| 16 | + /** |
|
| 17 | + * @var EE_Datetime |
|
| 18 | + */ |
|
| 19 | + private $_dtt; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var EE_Datetime |
| 23 | 23 | */ |
| 24 | 24 | private $_dtt; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Initial setup of data properties for the list table. |
|
| 28 | - */ |
|
| 29 | - protected function _setup_data() |
|
| 30 | - { |
|
| 31 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 32 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 33 | - } |
|
| 26 | + /** |
|
| 27 | + * Initial setup of data properties for the list table. |
|
| 28 | + */ |
|
| 29 | + protected function _setup_data() |
|
| 30 | + { |
|
| 31 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 32 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Initial setup of data properties for the list table. |
@@ -40,373 +40,373 @@ discard block |
||
| 40 | 40 | $this->_all_data_count = $this->_admin_page->get_events(0,0, TRUE); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Set up of additional properties for the list table. |
|
| 45 | - */ |
|
| 46 | - protected function _set_properties() |
|
| 47 | - { |
|
| 48 | - $this->_wp_list_args = array( |
|
| 49 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
| 50 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
| 51 | - 'ajax' => true, //for now |
|
| 52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - $this->_columns = array( |
|
| 57 | - 'cb' => '<input type="checkbox" />', |
|
| 58 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 59 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 60 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
| 61 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 62 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 63 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 64 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 65 | - . '</span>', |
|
| 66 | - //'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 67 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 68 | - ); |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - $this->_sortable_columns = array( |
|
| 72 | - 'id' => array('EVT_ID' => true), |
|
| 73 | - 'name' => array('EVT_name' => false), |
|
| 74 | - 'author' => array('EVT_wp_user' => false), |
|
| 75 | - 'venue' => array('Venue.VNU_name' => false), |
|
| 76 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 77 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $this->_primary_column = 'id'; |
|
| 81 | - |
|
| 82 | - $this->_hidden_columns = array('author'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - protected function _get_table_filters() |
|
| 90 | - { |
|
| 91 | - return array(); //no filters with decaf |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Setup of views properties. |
|
| 97 | - */ |
|
| 98 | - protected function _add_view_counts() |
|
| 99 | - { |
|
| 100 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 101 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 102 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 103 | - 'ee_delete_events', |
|
| 104 | - 'espresso_events_trash_events' |
|
| 105 | - )) { |
|
| 106 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param EE_Event $item |
|
| 113 | - * @return string |
|
| 114 | - * @throws EE_Error |
|
| 115 | - */ |
|
| 116 | - protected function _get_row_class($item) |
|
| 117 | - { |
|
| 118 | - $class = parent::_get_row_class($item); |
|
| 119 | - //add status class |
|
| 120 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
| 121 | - if ($this->_has_checkbox_column) { |
|
| 122 | - $class .= ' has-checkbox-column'; |
|
| 123 | - } |
|
| 124 | - return $class; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param EE_Event $item |
|
| 130 | - * @return string |
|
| 131 | - * @throws EE_Error |
|
| 132 | - */ |
|
| 133 | - public function column_status(EE_Event $item) |
|
| 134 | - { |
|
| 135 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 136 | - . $item->get_active_status() |
|
| 137 | - . '"></span>'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param EE_Event $item |
|
| 143 | - * @return string |
|
| 144 | - * @throws EE_Error |
|
| 145 | - */ |
|
| 146 | - public function column_cb($item) |
|
| 147 | - { |
|
| 148 | - if (! $item instanceof EE_Event) { |
|
| 149 | - return ''; |
|
| 150 | - } |
|
| 151 | - $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
| 152 | - |
|
| 153 | - //does event have any attached registrations? |
|
| 154 | - $regs = $item->count_related('Registration'); |
|
| 155 | - return $regs > 0 && $this->_view == 'trash' |
|
| 156 | - ? '<span class="ee-lock-icon"></span>' |
|
| 157 | - : sprintf( |
|
| 158 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 159 | - $item->ID() |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param EE_Event $item |
|
| 166 | - * @return mixed|string |
|
| 167 | - * @throws EE_Error |
|
| 168 | - */ |
|
| 169 | - public function column_id(EE_Event $item) |
|
| 170 | - { |
|
| 171 | - $content = $item->ID(); |
|
| 172 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 173 | - return $content; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param EE_Event $item |
|
| 179 | - * @return string |
|
| 180 | - * @throws EE_Error |
|
| 181 | - */ |
|
| 182 | - public function column_name(EE_Event $item) |
|
| 183 | - { |
|
| 184 | - $edit_query_args = array( |
|
| 185 | - 'action' => 'edit', |
|
| 186 | - 'post' => $item->ID(), |
|
| 187 | - ); |
|
| 188 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 189 | - $actions = $this->_column_name_action_setup($item); |
|
| 190 | - $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 191 | - $content = '<strong><a class="row-title" href="' |
|
| 192 | - . $edit_link . '">' |
|
| 193 | - . $item->name() |
|
| 194 | - . '</a></strong>' |
|
| 195 | - . $status; |
|
| 196 | - $content .= '<br><span class="ee-status-text-small">' |
|
| 197 | - . EEH_Template::pretty_status( |
|
| 198 | - $item->get_active_status(), |
|
| 199 | - false, |
|
| 200 | - 'sentence' |
|
| 201 | - ) |
|
| 202 | - . '</span>'; |
|
| 203 | - $content .= $this->row_actions($actions); |
|
| 204 | - return $content; |
|
| 205 | - } |
|
| 43 | + /** |
|
| 44 | + * Set up of additional properties for the list table. |
|
| 45 | + */ |
|
| 46 | + protected function _set_properties() |
|
| 47 | + { |
|
| 48 | + $this->_wp_list_args = array( |
|
| 49 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
| 50 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
| 51 | + 'ajax' => true, //for now |
|
| 52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + $this->_columns = array( |
|
| 57 | + 'cb' => '<input type="checkbox" />', |
|
| 58 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 59 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 60 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
| 61 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 62 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 63 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 64 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 65 | + . '</span>', |
|
| 66 | + //'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 67 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 68 | + ); |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + $this->_sortable_columns = array( |
|
| 72 | + 'id' => array('EVT_ID' => true), |
|
| 73 | + 'name' => array('EVT_name' => false), |
|
| 74 | + 'author' => array('EVT_wp_user' => false), |
|
| 75 | + 'venue' => array('Venue.VNU_name' => false), |
|
| 76 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 77 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $this->_primary_column = 'id'; |
|
| 81 | + |
|
| 82 | + $this->_hidden_columns = array('author'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + protected function _get_table_filters() |
|
| 90 | + { |
|
| 91 | + return array(); //no filters with decaf |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Setup of views properties. |
|
| 97 | + */ |
|
| 98 | + protected function _add_view_counts() |
|
| 99 | + { |
|
| 100 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 101 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 102 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 103 | + 'ee_delete_events', |
|
| 104 | + 'espresso_events_trash_events' |
|
| 105 | + )) { |
|
| 106 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param EE_Event $item |
|
| 113 | + * @return string |
|
| 114 | + * @throws EE_Error |
|
| 115 | + */ |
|
| 116 | + protected function _get_row_class($item) |
|
| 117 | + { |
|
| 118 | + $class = parent::_get_row_class($item); |
|
| 119 | + //add status class |
|
| 120 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
| 121 | + if ($this->_has_checkbox_column) { |
|
| 122 | + $class .= ' has-checkbox-column'; |
|
| 123 | + } |
|
| 124 | + return $class; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param EE_Event $item |
|
| 130 | + * @return string |
|
| 131 | + * @throws EE_Error |
|
| 132 | + */ |
|
| 133 | + public function column_status(EE_Event $item) |
|
| 134 | + { |
|
| 135 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 136 | + . $item->get_active_status() |
|
| 137 | + . '"></span>'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param EE_Event $item |
|
| 143 | + * @return string |
|
| 144 | + * @throws EE_Error |
|
| 145 | + */ |
|
| 146 | + public function column_cb($item) |
|
| 147 | + { |
|
| 148 | + if (! $item instanceof EE_Event) { |
|
| 149 | + return ''; |
|
| 150 | + } |
|
| 151 | + $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
| 152 | + |
|
| 153 | + //does event have any attached registrations? |
|
| 154 | + $regs = $item->count_related('Registration'); |
|
| 155 | + return $regs > 0 && $this->_view == 'trash' |
|
| 156 | + ? '<span class="ee-lock-icon"></span>' |
|
| 157 | + : sprintf( |
|
| 158 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 159 | + $item->ID() |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param EE_Event $item |
|
| 166 | + * @return mixed|string |
|
| 167 | + * @throws EE_Error |
|
| 168 | + */ |
|
| 169 | + public function column_id(EE_Event $item) |
|
| 170 | + { |
|
| 171 | + $content = $item->ID(); |
|
| 172 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 173 | + return $content; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param EE_Event $item |
|
| 179 | + * @return string |
|
| 180 | + * @throws EE_Error |
|
| 181 | + */ |
|
| 182 | + public function column_name(EE_Event $item) |
|
| 183 | + { |
|
| 184 | + $edit_query_args = array( |
|
| 185 | + 'action' => 'edit', |
|
| 186 | + 'post' => $item->ID(), |
|
| 187 | + ); |
|
| 188 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 189 | + $actions = $this->_column_name_action_setup($item); |
|
| 190 | + $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 191 | + $content = '<strong><a class="row-title" href="' |
|
| 192 | + . $edit_link . '">' |
|
| 193 | + . $item->name() |
|
| 194 | + . '</a></strong>' |
|
| 195 | + . $status; |
|
| 196 | + $content .= '<br><span class="ee-status-text-small">' |
|
| 197 | + . EEH_Template::pretty_status( |
|
| 198 | + $item->get_active_status(), |
|
| 199 | + false, |
|
| 200 | + 'sentence' |
|
| 201 | + ) |
|
| 202 | + . '</span>'; |
|
| 203 | + $content .= $this->row_actions($actions); |
|
| 204 | + return $content; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Just a method for setting up the actions for the name column |
|
| 211 | + * |
|
| 212 | + * @param EE_Event $item |
|
| 213 | + * @return array array of actions |
|
| 214 | + * @throws EE_Error |
|
| 215 | + */ |
|
| 216 | + protected function _column_name_action_setup(EE_Event $item) |
|
| 217 | + { |
|
| 218 | + //todo: remove when attendees is active |
|
| 219 | + if (! defined('REG_ADMIN_URL')) { |
|
| 220 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $actions = array(); |
|
| 224 | + |
|
| 225 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 226 | + 'ee_edit_event', |
|
| 227 | + 'espresso_events_edit', |
|
| 228 | + $item->ID() |
|
| 229 | + )) { |
|
| 230 | + $edit_query_args = array( |
|
| 231 | + 'action' => 'edit', |
|
| 232 | + 'post' => $item->ID(), |
|
| 233 | + ); |
|
| 234 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 235 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 236 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 237 | + . esc_html__('Edit', 'event_espresso') |
|
| 238 | + . '</a>'; |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 243 | + 'ee_read_event', |
|
| 244 | + 'espresso_registrations_view_registration', |
|
| 245 | + $item->ID() |
|
| 246 | + ) |
|
| 247 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | + 'ee_read_registrations', |
|
| 249 | + 'espresso_registrations_view_registration' |
|
| 250 | + ) |
|
| 251 | + ) { |
|
| 252 | + $attendees_query_args = array( |
|
| 253 | + 'action' => 'default', |
|
| 254 | + 'event_id' => $item->ID(), |
|
| 255 | + ); |
|
| 256 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 257 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 258 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 259 | + . esc_html__('Registrations', 'event_espresso') |
|
| 260 | + . '</a>'; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 264 | + 'ee_delete_event', |
|
| 265 | + 'espresso_events_trash_event', |
|
| 266 | + $item->ID() |
|
| 267 | + )) { |
|
| 268 | + $trash_event_query_args = array( |
|
| 269 | + 'action' => 'trash_event', |
|
| 270 | + 'EVT_ID' => $item->ID(), |
|
| 271 | + ); |
|
| 272 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | + $trash_event_query_args, |
|
| 274 | + EVENTS_ADMIN_URL |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 279 | + 'ee_delete_event', |
|
| 280 | + 'espresso_events_restore_event', |
|
| 281 | + $item->ID() |
|
| 282 | + )) { |
|
| 283 | + $restore_event_query_args = array( |
|
| 284 | + 'action' => 'restore_event', |
|
| 285 | + 'EVT_ID' => $item->ID(), |
|
| 286 | + ); |
|
| 287 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 288 | + $restore_event_query_args, |
|
| 289 | + EVENTS_ADMIN_URL |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 294 | + 'ee_delete_event', |
|
| 295 | + 'espresso_events_delete_event', |
|
| 296 | + $item->ID() |
|
| 297 | + )) { |
|
| 298 | + $delete_event_query_args = array( |
|
| 299 | + 'action' => 'delete_event', |
|
| 300 | + 'EVT_ID' => $item->ID(), |
|
| 301 | + ); |
|
| 302 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 303 | + $delete_event_query_args, |
|
| 304 | + EVENTS_ADMIN_URL |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $view_link = get_permalink($item->ID()); |
|
| 309 | + |
|
| 310 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
| 311 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 312 | + . esc_html__('View', 'event_espresso') |
|
| 313 | + . '</a>'; |
|
| 314 | + |
|
| 315 | + switch ($item->get('status')) { |
|
| 316 | + case 'trash': |
|
| 317 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 318 | + 'ee_delete_event', |
|
| 319 | + 'espresso_events_restore_event', |
|
| 320 | + $item->ID() |
|
| 321 | + )) { |
|
| 322 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 323 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 324 | + . '">' |
|
| 325 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
| 326 | + . '</a>'; |
|
| 327 | + } |
|
| 328 | + if ($item->count_related('Registration') === 0 |
|
| 329 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 330 | + 'ee_delete_event', |
|
| 331 | + 'espresso_events_delete_event', |
|
| 332 | + $item->ID() |
|
| 333 | + )) { |
|
| 334 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 335 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 336 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
| 337 | + . '</a>'; |
|
| 338 | + } |
|
| 339 | + break; |
|
| 340 | + default: |
|
| 341 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 342 | + 'ee_delete_event', |
|
| 343 | + 'espresso_events_trash_event', |
|
| 344 | + $item->ID() |
|
| 345 | + )) { |
|
| 346 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 347 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 348 | + . esc_html__('Trash', 'event_espresso') |
|
| 349 | + . '</a>'; |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + return $actions; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * @param EE_Event $item |
|
| 358 | + * @return string |
|
| 359 | + * @throws EE_Error |
|
| 360 | + */ |
|
| 361 | + public function column_author(EE_Event $item) |
|
| 362 | + { |
|
| 363 | + //user author info |
|
| 364 | + $event_author = get_userdata($item->wp_user()); |
|
| 365 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 366 | + //filter link |
|
| 367 | + $query_args = array( |
|
| 368 | + 'action' => 'default', |
|
| 369 | + 'EVT_wp_user' => $item->wp_user(), |
|
| 370 | + ); |
|
| 371 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 372 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 373 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 374 | + . $event_author->display_name |
|
| 375 | + . '</a>'; |
|
| 376 | + } |
|
| 377 | + |
|
| 206 | 378 | |
| 379 | + /** |
|
| 380 | + * @param EE_Event $item |
|
| 381 | + * @return string |
|
| 382 | + * @throws EE_Error |
|
| 383 | + */ |
|
| 384 | + public function column_venue(EE_Event $item) |
|
| 385 | + { |
|
| 386 | + $venue = $item->get_first_related('Venue'); |
|
| 387 | + return ! empty($venue) ? $venue->name() : ''; |
|
| 207 | 388 | } |
| 208 | 389 | |
| 209 | - /** |
|
| 210 | - * Just a method for setting up the actions for the name column |
|
| 211 | - * |
|
| 212 | - * @param EE_Event $item |
|
| 213 | - * @return array array of actions |
|
| 214 | - * @throws EE_Error |
|
| 215 | - */ |
|
| 216 | - protected function _column_name_action_setup(EE_Event $item) |
|
| 217 | - { |
|
| 218 | - //todo: remove when attendees is active |
|
| 219 | - if (! defined('REG_ADMIN_URL')) { |
|
| 220 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $actions = array(); |
|
| 224 | - |
|
| 225 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 226 | - 'ee_edit_event', |
|
| 227 | - 'espresso_events_edit', |
|
| 228 | - $item->ID() |
|
| 229 | - )) { |
|
| 230 | - $edit_query_args = array( |
|
| 231 | - 'action' => 'edit', |
|
| 232 | - 'post' => $item->ID(), |
|
| 233 | - ); |
|
| 234 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 235 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 236 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 237 | - . esc_html__('Edit', 'event_espresso') |
|
| 238 | - . '</a>'; |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 243 | - 'ee_read_event', |
|
| 244 | - 'espresso_registrations_view_registration', |
|
| 245 | - $item->ID() |
|
| 246 | - ) |
|
| 247 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | - 'ee_read_registrations', |
|
| 249 | - 'espresso_registrations_view_registration' |
|
| 250 | - ) |
|
| 251 | - ) { |
|
| 252 | - $attendees_query_args = array( |
|
| 253 | - 'action' => 'default', |
|
| 254 | - 'event_id' => $item->ID(), |
|
| 255 | - ); |
|
| 256 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 257 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 258 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 259 | - . esc_html__('Registrations', 'event_espresso') |
|
| 260 | - . '</a>'; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 264 | - 'ee_delete_event', |
|
| 265 | - 'espresso_events_trash_event', |
|
| 266 | - $item->ID() |
|
| 267 | - )) { |
|
| 268 | - $trash_event_query_args = array( |
|
| 269 | - 'action' => 'trash_event', |
|
| 270 | - 'EVT_ID' => $item->ID(), |
|
| 271 | - ); |
|
| 272 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | - $trash_event_query_args, |
|
| 274 | - EVENTS_ADMIN_URL |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 279 | - 'ee_delete_event', |
|
| 280 | - 'espresso_events_restore_event', |
|
| 281 | - $item->ID() |
|
| 282 | - )) { |
|
| 283 | - $restore_event_query_args = array( |
|
| 284 | - 'action' => 'restore_event', |
|
| 285 | - 'EVT_ID' => $item->ID(), |
|
| 286 | - ); |
|
| 287 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 288 | - $restore_event_query_args, |
|
| 289 | - EVENTS_ADMIN_URL |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 294 | - 'ee_delete_event', |
|
| 295 | - 'espresso_events_delete_event', |
|
| 296 | - $item->ID() |
|
| 297 | - )) { |
|
| 298 | - $delete_event_query_args = array( |
|
| 299 | - 'action' => 'delete_event', |
|
| 300 | - 'EVT_ID' => $item->ID(), |
|
| 301 | - ); |
|
| 302 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 303 | - $delete_event_query_args, |
|
| 304 | - EVENTS_ADMIN_URL |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $view_link = get_permalink($item->ID()); |
|
| 309 | - |
|
| 310 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 311 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 312 | - . esc_html__('View', 'event_espresso') |
|
| 313 | - . '</a>'; |
|
| 314 | - |
|
| 315 | - switch ($item->get('status')) { |
|
| 316 | - case 'trash': |
|
| 317 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 318 | - 'ee_delete_event', |
|
| 319 | - 'espresso_events_restore_event', |
|
| 320 | - $item->ID() |
|
| 321 | - )) { |
|
| 322 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 323 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 324 | - . '">' |
|
| 325 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
| 326 | - . '</a>'; |
|
| 327 | - } |
|
| 328 | - if ($item->count_related('Registration') === 0 |
|
| 329 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 330 | - 'ee_delete_event', |
|
| 331 | - 'espresso_events_delete_event', |
|
| 332 | - $item->ID() |
|
| 333 | - )) { |
|
| 334 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 335 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 336 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
| 337 | - . '</a>'; |
|
| 338 | - } |
|
| 339 | - break; |
|
| 340 | - default: |
|
| 341 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 342 | - 'ee_delete_event', |
|
| 343 | - 'espresso_events_trash_event', |
|
| 344 | - $item->ID() |
|
| 345 | - )) { |
|
| 346 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 347 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 348 | - . esc_html__('Trash', 'event_espresso') |
|
| 349 | - . '</a>'; |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - return $actions; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * @param EE_Event $item |
|
| 358 | - * @return string |
|
| 359 | - * @throws EE_Error |
|
| 360 | - */ |
|
| 361 | - public function column_author(EE_Event $item) |
|
| 362 | - { |
|
| 363 | - //user author info |
|
| 364 | - $event_author = get_userdata($item->wp_user()); |
|
| 365 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 366 | - //filter link |
|
| 367 | - $query_args = array( |
|
| 368 | - 'action' => 'default', |
|
| 369 | - 'EVT_wp_user' => $item->wp_user(), |
|
| 370 | - ); |
|
| 371 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 372 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 373 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 374 | - . $event_author->display_name |
|
| 375 | - . '</a>'; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * @param EE_Event $item |
|
| 381 | - * @return string |
|
| 382 | - * @throws EE_Error |
|
| 383 | - */ |
|
| 384 | - public function column_venue(EE_Event $item) |
|
| 385 | - { |
|
| 386 | - $venue = $item->get_first_related('Venue'); |
|
| 387 | - return ! empty($venue) ? $venue->name() : ''; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @param EE_Event $item |
|
| 393 | - * @throws EE_Error |
|
| 394 | - */ |
|
| 395 | - public function column_start_date_time(EE_Event $item) |
|
| 396 | - { |
|
| 397 | - echo ! empty($this->_dtt) |
|
| 398 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 399 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 400 | - //display in user's timezone? |
|
| 401 | - echo ! empty($this->_dtt) |
|
| 402 | - ? $this->_dtt->display_in_my_timezone( |
|
| 403 | - 'DTT_EVT_start', |
|
| 404 | - 'get_i18n_datetime', |
|
| 405 | - '', |
|
| 406 | - 'My Timezone: ' |
|
| 407 | - ) |
|
| 408 | - : ''; |
|
| 409 | - } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @param EE_Event $item |
|
| 393 | + * @throws EE_Error |
|
| 394 | + */ |
|
| 395 | + public function column_start_date_time(EE_Event $item) |
|
| 396 | + { |
|
| 397 | + echo ! empty($this->_dtt) |
|
| 398 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 399 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 400 | + //display in user's timezone? |
|
| 401 | + echo ! empty($this->_dtt) |
|
| 402 | + ? $this->_dtt->display_in_my_timezone( |
|
| 403 | + 'DTT_EVT_start', |
|
| 404 | + 'get_i18n_datetime', |
|
| 405 | + '', |
|
| 406 | + 'My Timezone: ' |
|
| 407 | + ) |
|
| 408 | + : ''; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | 412 | * @param EE_Event $item |
@@ -418,128 +418,128 @@ discard block |
||
| 418 | 418 | return !empty( $venue ) ? $venue->name() : ''; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * @param EE_Event $item |
|
| 423 | - * @throws EE_Error |
|
| 424 | - */ |
|
| 425 | - public function column_reg_begins(EE_Event $item) |
|
| 426 | - { |
|
| 427 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 428 | - echo ! empty($reg_start) |
|
| 429 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 430 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 431 | - //display in user's timezone? |
|
| 432 | - echo ! empty($reg_start) |
|
| 433 | - ? $reg_start->display_in_my_timezone( |
|
| 434 | - 'TKT_start_date', |
|
| 435 | - 'get_i18n_datetime', |
|
| 436 | - '', |
|
| 437 | - 'My Timezone: ' |
|
| 438 | - ) |
|
| 439 | - : ''; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * @param EE_Event $item |
|
| 445 | - * @return int|string |
|
| 446 | - * @throws EE_Error |
|
| 447 | - */ |
|
| 448 | - public function column_attendees(EE_Event $item) |
|
| 449 | - { |
|
| 450 | - $attendees_query_args = array( |
|
| 451 | - 'action' => 'default', |
|
| 452 | - 'event_id' => $item->ID(), |
|
| 453 | - ); |
|
| 454 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 455 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 456 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | - 'ee_read_event', |
|
| 458 | - 'espresso_registrations_view_registration', |
|
| 459 | - $item->ID() |
|
| 460 | - ) |
|
| 461 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 462 | - 'ee_read_registrations', |
|
| 463 | - 'espresso_registrations_view_registration' |
|
| 464 | - ) |
|
| 465 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 466 | - : $registered_attendees; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @param EE_Event $item |
|
| 472 | - * @return float |
|
| 473 | - * @throws EE_Error |
|
| 474 | - */ |
|
| 475 | - public function column_tkts_sold(EE_Event $item) |
|
| 476 | - { |
|
| 477 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param EE_Event $item |
|
| 483 | - * @return string |
|
| 484 | - * @throws EE_Error |
|
| 485 | - */ |
|
| 486 | - public function column_actions(EE_Event $item) |
|
| 487 | - { |
|
| 488 | - //todo: remove when attendees is active |
|
| 489 | - if (! defined('REG_ADMIN_URL')) { |
|
| 490 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 491 | - } |
|
| 492 | - $actionlinks = array(); |
|
| 493 | - |
|
| 494 | - $view_link = get_permalink($item->ID()); |
|
| 495 | - |
|
| 496 | - $actionlinks[] = '<a href="' . $view_link . '"' |
|
| 497 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 498 | - $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 499 | - |
|
| 500 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 501 | - 'ee_edit_event', |
|
| 502 | - 'espresso_events_edit', |
|
| 503 | - $item->ID() |
|
| 504 | - )) { |
|
| 505 | - $edit_query_args = array( |
|
| 506 | - 'action' => 'edit', |
|
| 507 | - 'post' => $item->ID(), |
|
| 508 | - ); |
|
| 509 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 510 | - $actionlinks[] = '<a href="' . $edit_link . '"' |
|
| 511 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 512 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 513 | - . '</a>'; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 517 | - 'ee_read_event', |
|
| 518 | - 'espresso_registrations_view_registration', |
|
| 519 | - $item->ID() |
|
| 520 | - ) |
|
| 521 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 522 | - 'ee_read_registrations', |
|
| 523 | - 'espresso_registrations_view_registration' |
|
| 524 | - ) |
|
| 525 | - ) { |
|
| 526 | - $attendees_query_args = array( |
|
| 527 | - 'action' => 'default', |
|
| 528 | - 'event_id' => $item->ID(), |
|
| 529 | - ); |
|
| 530 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 531 | - $actionlinks[] = '<a href="' . $attendees_link . '"' |
|
| 532 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 533 | - . '<div class="dashicons dashicons-groups"></div>' |
|
| 534 | - . '</a>'; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - $actionlinks = apply_filters( |
|
| 538 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 539 | - $actionlinks, |
|
| 540 | - $item |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
| 544 | - } |
|
| 421 | + /** |
|
| 422 | + * @param EE_Event $item |
|
| 423 | + * @throws EE_Error |
|
| 424 | + */ |
|
| 425 | + public function column_reg_begins(EE_Event $item) |
|
| 426 | + { |
|
| 427 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 428 | + echo ! empty($reg_start) |
|
| 429 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 430 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 431 | + //display in user's timezone? |
|
| 432 | + echo ! empty($reg_start) |
|
| 433 | + ? $reg_start->display_in_my_timezone( |
|
| 434 | + 'TKT_start_date', |
|
| 435 | + 'get_i18n_datetime', |
|
| 436 | + '', |
|
| 437 | + 'My Timezone: ' |
|
| 438 | + ) |
|
| 439 | + : ''; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * @param EE_Event $item |
|
| 445 | + * @return int|string |
|
| 446 | + * @throws EE_Error |
|
| 447 | + */ |
|
| 448 | + public function column_attendees(EE_Event $item) |
|
| 449 | + { |
|
| 450 | + $attendees_query_args = array( |
|
| 451 | + 'action' => 'default', |
|
| 452 | + 'event_id' => $item->ID(), |
|
| 453 | + ); |
|
| 454 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 455 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 456 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | + 'ee_read_event', |
|
| 458 | + 'espresso_registrations_view_registration', |
|
| 459 | + $item->ID() |
|
| 460 | + ) |
|
| 461 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 462 | + 'ee_read_registrations', |
|
| 463 | + 'espresso_registrations_view_registration' |
|
| 464 | + ) |
|
| 465 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 466 | + : $registered_attendees; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @param EE_Event $item |
|
| 472 | + * @return float |
|
| 473 | + * @throws EE_Error |
|
| 474 | + */ |
|
| 475 | + public function column_tkts_sold(EE_Event $item) |
|
| 476 | + { |
|
| 477 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param EE_Event $item |
|
| 483 | + * @return string |
|
| 484 | + * @throws EE_Error |
|
| 485 | + */ |
|
| 486 | + public function column_actions(EE_Event $item) |
|
| 487 | + { |
|
| 488 | + //todo: remove when attendees is active |
|
| 489 | + if (! defined('REG_ADMIN_URL')) { |
|
| 490 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 491 | + } |
|
| 492 | + $actionlinks = array(); |
|
| 493 | + |
|
| 494 | + $view_link = get_permalink($item->ID()); |
|
| 495 | + |
|
| 496 | + $actionlinks[] = '<a href="' . $view_link . '"' |
|
| 497 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 498 | + $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 499 | + |
|
| 500 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 501 | + 'ee_edit_event', |
|
| 502 | + 'espresso_events_edit', |
|
| 503 | + $item->ID() |
|
| 504 | + )) { |
|
| 505 | + $edit_query_args = array( |
|
| 506 | + 'action' => 'edit', |
|
| 507 | + 'post' => $item->ID(), |
|
| 508 | + ); |
|
| 509 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 510 | + $actionlinks[] = '<a href="' . $edit_link . '"' |
|
| 511 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 512 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 513 | + . '</a>'; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 517 | + 'ee_read_event', |
|
| 518 | + 'espresso_registrations_view_registration', |
|
| 519 | + $item->ID() |
|
| 520 | + ) |
|
| 521 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 522 | + 'ee_read_registrations', |
|
| 523 | + 'espresso_registrations_view_registration' |
|
| 524 | + ) |
|
| 525 | + ) { |
|
| 526 | + $attendees_query_args = array( |
|
| 527 | + 'action' => 'default', |
|
| 528 | + 'event_id' => $item->ID(), |
|
| 529 | + ); |
|
| 530 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 531 | + $actionlinks[] = '<a href="' . $attendees_link . '"' |
|
| 532 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 533 | + . '<div class="dashicons dashicons-groups"></div>' |
|
| 534 | + . '</a>'; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + $actionlinks = apply_filters( |
|
| 538 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 539 | + $actionlinks, |
|
| 540 | + $item |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
| 544 | + } |
|
| 545 | 545 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected function _setup_data() { |
| 39 | 39 | $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
| 40 | - $this->_all_data_count = $this->_admin_page->get_events(0,0, TRUE); |
|
| 40 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, TRUE); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $class = parent::_get_row_class($item); |
| 119 | 119 | //add status class |
| 120 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
| 120 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-'.$item->get_active_status() : ''; |
|
| 121 | 121 | if ($this->_has_checkbox_column) { |
| 122 | 122 | $class .= ' has-checkbox-column'; |
| 123 | 123 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function column_cb($item) |
| 147 | 147 | { |
| 148 | - if (! $item instanceof EE_Event) { |
|
| 148 | + if ( ! $item instanceof EE_Event) { |
|
| 149 | 149 | return ''; |
| 150 | 150 | } |
| 151 | 151 | $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | public function column_id(EE_Event $item) |
| 170 | 170 | { |
| 171 | 171 | $content = $item->ID(); |
| 172 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 172 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
| 173 | 173 | return $content; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -189,18 +189,18 @@ discard block |
||
| 189 | 189 | $actions = $this->_column_name_action_setup($item); |
| 190 | 190 | $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
| 191 | 191 | $content = '<strong><a class="row-title" href="' |
| 192 | - . $edit_link . '">' |
|
| 192 | + . $edit_link.'">' |
|
| 193 | 193 | . $item->name() |
| 194 | 194 | . '</a></strong>' |
| 195 | 195 | . $status; |
| 196 | - $content .= '<br><span class="ee-status-text-small">' |
|
| 196 | + $content .= '<br><span class="ee-status-text-small">' |
|
| 197 | 197 | . EEH_Template::pretty_status( |
| 198 | 198 | $item->get_active_status(), |
| 199 | 199 | false, |
| 200 | 200 | 'sentence' |
| 201 | 201 | ) |
| 202 | 202 | . '</span>'; |
| 203 | - $content .= $this->row_actions($actions); |
|
| 203 | + $content .= $this->row_actions($actions); |
|
| 204 | 204 | return $content; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | protected function _column_name_action_setup(EE_Event $item) |
| 217 | 217 | { |
| 218 | 218 | //todo: remove when attendees is active |
| 219 | - if (! defined('REG_ADMIN_URL')) { |
|
| 219 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 220 | 220 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | 'post' => $item->ID(), |
| 233 | 233 | ); |
| 234 | 234 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 235 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 236 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 235 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
| 236 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 237 | 237 | . esc_html__('Edit', 'event_espresso') |
| 238 | 238 | . '</a>'; |
| 239 | 239 | |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | 'event_id' => $item->ID(), |
| 255 | 255 | ); |
| 256 | 256 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 257 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 258 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 257 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
| 258 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
| 259 | 259 | . esc_html__('Registrations', 'event_espresso') |
| 260 | 260 | . '</a>'; |
| 261 | 261 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | 'action' => 'trash_event', |
| 270 | 270 | 'EVT_ID' => $item->ID(), |
| 271 | 271 | ); |
| 272 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 272 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | 273 | $trash_event_query_args, |
| 274 | 274 | EVENTS_ADMIN_URL |
| 275 | 275 | ); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | 'action' => 'restore_event', |
| 285 | 285 | 'EVT_ID' => $item->ID(), |
| 286 | 286 | ); |
| 287 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 287 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 288 | 288 | $restore_event_query_args, |
| 289 | 289 | EVENTS_ADMIN_URL |
| 290 | 290 | ); |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | 'action' => 'delete_event', |
| 300 | 300 | 'EVT_ID' => $item->ID(), |
| 301 | 301 | ); |
| 302 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 302 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 303 | 303 | $delete_event_query_args, |
| 304 | 304 | EVENTS_ADMIN_URL |
| 305 | 305 | ); |
@@ -307,8 +307,8 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | $view_link = get_permalink($item->ID()); |
| 309 | 309 | |
| 310 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 311 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 310 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
| 311 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
| 312 | 312 | . esc_html__('View', 'event_espresso') |
| 313 | 313 | . '</a>'; |
| 314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | 'espresso_events_restore_event', |
| 320 | 320 | $item->ID() |
| 321 | 321 | )) { |
| 322 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 323 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 322 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
| 323 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
| 324 | 324 | . '">' |
| 325 | 325 | . esc_html__('Restore from Trash', 'event_espresso') |
| 326 | 326 | . '</a>'; |
@@ -331,8 +331,8 @@ discard block |
||
| 331 | 331 | 'espresso_events_delete_event', |
| 332 | 332 | $item->ID() |
| 333 | 333 | )) { |
| 334 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 335 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 334 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
| 335 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
| 336 | 336 | . esc_html__('Delete Permanently', 'event_espresso') |
| 337 | 337 | . '</a>'; |
| 338 | 338 | } |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | 'espresso_events_trash_event', |
| 344 | 344 | $item->ID() |
| 345 | 345 | )) { |
| 346 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 347 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 346 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
| 347 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
| 348 | 348 | . esc_html__('Trash', 'event_espresso') |
| 349 | 349 | . '</a>'; |
| 350 | 350 | } |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | 'EVT_wp_user' => $item->wp_user(), |
| 370 | 370 | ); |
| 371 | 371 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
| 372 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 373 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 372 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
| 373 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
| 374 | 374 | . $event_author->display_name |
| 375 | 375 | . '</a>'; |
| 376 | 376 | } |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @return string |
| 415 | 415 | */ |
| 416 | - public function column_venue( EE_Event $item ) { |
|
| 417 | - $venue = $item->get_first_related( 'Venue' ); |
|
| 418 | - return !empty( $venue ) ? $venue->name() : ''; |
|
| 416 | + public function column_venue(EE_Event $item) { |
|
| 417 | + $venue = $item->get_first_related('Venue'); |
|
| 418 | + return ! empty($venue) ? $venue->name() : ''; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | 'ee_read_registrations', |
| 463 | 463 | 'espresso_registrations_view_registration' |
| 464 | 464 | ) |
| 465 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 465 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
| 466 | 466 | : $registered_attendees; |
| 467 | 467 | } |
| 468 | 468 | |
@@ -486,15 +486,15 @@ discard block |
||
| 486 | 486 | public function column_actions(EE_Event $item) |
| 487 | 487 | { |
| 488 | 488 | //todo: remove when attendees is active |
| 489 | - if (! defined('REG_ADMIN_URL')) { |
|
| 489 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 490 | 490 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 491 | 491 | } |
| 492 | 492 | $actionlinks = array(); |
| 493 | 493 | |
| 494 | 494 | $view_link = get_permalink($item->ID()); |
| 495 | 495 | |
| 496 | - $actionlinks[] = '<a href="' . $view_link . '"' |
|
| 497 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 496 | + $actionlinks[] = '<a href="'.$view_link.'"' |
|
| 497 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
| 498 | 498 | $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
| 499 | 499 | |
| 500 | 500 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -507,8 +507,8 @@ discard block |
||
| 507 | 507 | 'post' => $item->ID(), |
| 508 | 508 | ); |
| 509 | 509 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 510 | - $actionlinks[] = '<a href="' . $edit_link . '"' |
|
| 511 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 510 | + $actionlinks[] = '<a href="'.$edit_link.'"' |
|
| 511 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 512 | 512 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
| 513 | 513 | . '</a>'; |
| 514 | 514 | } |
@@ -528,8 +528,8 @@ discard block |
||
| 528 | 528 | 'event_id' => $item->ID(), |
| 529 | 529 | ); |
| 530 | 530 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 531 | - $actionlinks[] = '<a href="' . $attendees_link . '"' |
|
| 532 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 531 | + $actionlinks[] = '<a href="'.$attendees_link.'"' |
|
| 532 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
| 533 | 533 | . '<div class="dashicons dashicons-groups"></div>' |
| 534 | 534 | . '</a>'; |
| 535 | 535 | } |
@@ -22,1501 +22,1501 @@ |
||
| 22 | 22 | class EE_Registry implements ResettableInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var EE_Registry $_instance |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var EE_Dependency_Map $_dependency_map |
|
| 32 | - */ |
|
| 33 | - protected $_dependency_map; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var array $_class_abbreviations |
|
| 37 | - */ |
|
| 38 | - protected $_class_abbreviations = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var CommandBusInterface $BUS |
|
| 42 | - */ |
|
| 43 | - public $BUS; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Cart $CART |
|
| 47 | - */ |
|
| 48 | - public $CART; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var EE_Config $CFG |
|
| 52 | - */ |
|
| 53 | - public $CFG; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EE_Network_Config $NET_CFG |
|
| 57 | - */ |
|
| 58 | - public $NET_CFG; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * StdClass object for storing library classes in |
|
| 62 | - * |
|
| 63 | - * @var StdClass $LIB |
|
| 64 | - */ |
|
| 65 | - public $LIB; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var EE_Request_Handler $REQ |
|
| 69 | - */ |
|
| 70 | - public $REQ; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var EE_Session $SSN |
|
| 74 | - */ |
|
| 75 | - public $SSN; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @since 4.5.0 |
|
| 79 | - * @var EE_Capabilities $CAP |
|
| 80 | - */ |
|
| 81 | - public $CAP; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @since 4.9.0 |
|
| 85 | - * @var EE_Message_Resource_Manager $MRM |
|
| 86 | - */ |
|
| 87 | - public $MRM; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @var Registry $AssetsRegistry |
|
| 92 | - */ |
|
| 93 | - public $AssetsRegistry; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | - * |
|
| 98 | - * @var EE_Addon[] $addons |
|
| 99 | - */ |
|
| 100 | - public $addons; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | - * |
|
| 105 | - * @var EEM_Base[] $models |
|
| 106 | - */ |
|
| 107 | - public $models = array(); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var EED_Module[] $modules |
|
| 111 | - */ |
|
| 112 | - public $modules; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @var EES_Shortcode[] $shortcodes |
|
| 116 | - */ |
|
| 117 | - public $shortcodes; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @var WP_Widget[] $widgets |
|
| 121 | - */ |
|
| 122 | - public $widgets; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | - * classnames (eg "EEM_Event") |
|
| 129 | - * |
|
| 130 | - * @var array $non_abstract_db_models |
|
| 131 | - */ |
|
| 132 | - public $non_abstract_db_models = array(); |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * internationalization for JS strings |
|
| 137 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | - * in js file: var translatedString = eei18n.string_key; |
|
| 139 | - * |
|
| 140 | - * @var array $i18n_js_strings |
|
| 141 | - */ |
|
| 142 | - public static $i18n_js_strings = array(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * $main_file - path to espresso.php |
|
| 147 | - * |
|
| 148 | - * @var array $main_file |
|
| 149 | - */ |
|
| 150 | - public $main_file; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * array of ReflectionClass objects where the key is the class name |
|
| 154 | - * |
|
| 155 | - * @var ReflectionClass[] $_reflectors |
|
| 156 | - */ |
|
| 157 | - public $_reflectors; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | - * |
|
| 162 | - * @var boolean $_cache_on |
|
| 163 | - */ |
|
| 164 | - protected $_cache_on = true; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @singleton method used to instantiate class object |
|
| 170 | - * @param EE_Dependency_Map $dependency_map |
|
| 171 | - * @return EE_Registry instance |
|
| 172 | - * @throws InvalidArgumentException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - * @throws InvalidDataTypeException |
|
| 175 | - */ |
|
| 176 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | - { |
|
| 178 | - // check if class object is instantiated |
|
| 179 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | - self::$_instance = new self($dependency_map); |
|
| 181 | - } |
|
| 182 | - return self::$_instance; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * protected constructor to prevent direct creation |
|
| 189 | - * |
|
| 190 | - * @Constructor |
|
| 191 | - * @param EE_Dependency_Map $dependency_map |
|
| 192 | - * @throws InvalidDataTypeException |
|
| 193 | - * @throws InvalidInterfaceException |
|
| 194 | - * @throws InvalidArgumentException |
|
| 195 | - */ |
|
| 196 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | - { |
|
| 198 | - $this->_dependency_map = $dependency_map; |
|
| 199 | - $this->LIB = new stdClass(); |
|
| 200 | - $this->addons = new stdClass(); |
|
| 201 | - $this->modules = new stdClass(); |
|
| 202 | - $this->shortcodes = new stdClass(); |
|
| 203 | - $this->widgets = new stdClass(); |
|
| 204 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * initialize |
|
| 211 | - * |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - */ |
|
| 215 | - public function initialize() |
|
| 216 | - { |
|
| 217 | - $this->_class_abbreviations = apply_filters( |
|
| 218 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | - array( |
|
| 220 | - 'EE_Config' => 'CFG', |
|
| 221 | - 'EE_Session' => 'SSN', |
|
| 222 | - 'EE_Capabilities' => 'CAP', |
|
| 223 | - 'EE_Cart' => 'CART', |
|
| 224 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | - 'EE_Request_Handler' => 'REQ', |
|
| 226 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - $this->load_core('Base', array(), true); |
|
| 232 | - // add our request and response objects to the cache |
|
| 233 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | - $this->_set_cached_class( |
|
| 235 | - $request_loader(), |
|
| 236 | - 'EE_Request' |
|
| 237 | - ); |
|
| 238 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | - $this->_set_cached_class( |
|
| 240 | - $response_loader(), |
|
| 241 | - 'EE_Response' |
|
| 242 | - ); |
|
| 243 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - public function init() |
|
| 252 | - { |
|
| 253 | - // Get current page protocol |
|
| 254 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * localize_i18n_js_strings |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public static function localize_i18n_js_strings() |
|
| 268 | - { |
|
| 269 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | - if (is_scalar($value)) { |
|
| 272 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param mixed string | EED_Module $module |
|
| 282 | - * @throws EE_Error |
|
| 283 | - * @throws ReflectionException |
|
| 284 | - */ |
|
| 285 | - public function add_module($module) |
|
| 286 | - { |
|
| 287 | - if ($module instanceof EED_Module) { |
|
| 288 | - $module_class = get_class($module); |
|
| 289 | - $this->modules->{$module_class} = $module; |
|
| 290 | - } else { |
|
| 291 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 292 | - $this->load_core('Module_Request_Router'); |
|
| 293 | - } |
|
| 294 | - EE_Module_Request_Router::module_factory($module); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $module_name |
|
| 302 | - * @return mixed EED_Module | NULL |
|
| 303 | - */ |
|
| 304 | - public function get_module($module_name = '') |
|
| 305 | - { |
|
| 306 | - return isset($this->modules->{$module_name}) |
|
| 307 | - ? $this->modules->{$module_name} |
|
| 308 | - : null; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * loads core classes - must be singletons |
|
| 315 | - * |
|
| 316 | - * @param string $class_name - simple class name ie: session |
|
| 317 | - * @param mixed $arguments |
|
| 318 | - * @param bool $load_only |
|
| 319 | - * @return mixed |
|
| 320 | - * @throws EE_Error |
|
| 321 | - * @throws ReflectionException |
|
| 322 | - */ |
|
| 323 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | - { |
|
| 325 | - $core_paths = apply_filters( |
|
| 326 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | - array( |
|
| 328 | - EE_CORE, |
|
| 329 | - EE_ADMIN, |
|
| 330 | - EE_CPTS, |
|
| 331 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | - EE_CORE . 'capabilities' . DS, |
|
| 333 | - EE_CORE . 'request_stack' . DS, |
|
| 334 | - EE_CORE . 'middleware' . DS, |
|
| 335 | - ) |
|
| 336 | - ); |
|
| 337 | - // retrieve instantiated class |
|
| 338 | - return $this->_load( |
|
| 339 | - $core_paths, |
|
| 340 | - 'EE_', |
|
| 341 | - $class_name, |
|
| 342 | - 'core', |
|
| 343 | - $arguments, |
|
| 344 | - false, |
|
| 345 | - true, |
|
| 346 | - $load_only |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * loads service classes |
|
| 354 | - * |
|
| 355 | - * @param string $class_name - simple class name ie: session |
|
| 356 | - * @param mixed $arguments |
|
| 357 | - * @param bool $load_only |
|
| 358 | - * @return mixed |
|
| 359 | - * @throws EE_Error |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - */ |
|
| 362 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | - { |
|
| 364 | - $service_paths = apply_filters( |
|
| 365 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | - array( |
|
| 367 | - EE_CORE . 'services' . DS, |
|
| 368 | - ) |
|
| 369 | - ); |
|
| 370 | - // retrieve instantiated class |
|
| 371 | - return $this->_load( |
|
| 372 | - $service_paths, |
|
| 373 | - 'EE_', |
|
| 374 | - $class_name, |
|
| 375 | - 'class', |
|
| 376 | - $arguments, |
|
| 377 | - false, |
|
| 378 | - true, |
|
| 379 | - $load_only |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * loads data_migration_scripts |
|
| 387 | - * |
|
| 388 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | - * @param mixed $arguments |
|
| 390 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | - * @throws EE_Error |
|
| 392 | - * @throws ReflectionException |
|
| 393 | - */ |
|
| 394 | - public function load_dms($class_name, $arguments = array()) |
|
| 395 | - { |
|
| 396 | - // retrieve instantiated class |
|
| 397 | - return $this->_load( |
|
| 398 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | - 'EE_DMS_', |
|
| 400 | - $class_name, |
|
| 401 | - 'dms', |
|
| 402 | - $arguments, |
|
| 403 | - false, |
|
| 404 | - false |
|
| 405 | - ); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * loads object creating classes - must be singletons |
|
| 412 | - * |
|
| 413 | - * @param string $class_name - simple class name ie: attendee |
|
| 414 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | - * instantiate |
|
| 417 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | - * (default) |
|
| 421 | - * @return EE_Base_Class | bool |
|
| 422 | - * @throws EE_Error |
|
| 423 | - * @throws ReflectionException |
|
| 424 | - */ |
|
| 425 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | - { |
|
| 427 | - $paths = apply_filters( |
|
| 428 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | - EE_CORE, |
|
| 430 | - EE_CLASSES, |
|
| 431 | - EE_BUSINESS, |
|
| 432 | - ) |
|
| 433 | - ); |
|
| 434 | - // retrieve instantiated class |
|
| 435 | - return $this->_load( |
|
| 436 | - $paths, |
|
| 437 | - 'EE_', |
|
| 438 | - $class_name, |
|
| 439 | - 'class', |
|
| 440 | - $arguments, |
|
| 441 | - $from_db, |
|
| 442 | - $cache, |
|
| 443 | - $load_only |
|
| 444 | - ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * loads helper classes - must be singletons |
|
| 451 | - * |
|
| 452 | - * @param string $class_name - simple class name ie: price |
|
| 453 | - * @param mixed $arguments |
|
| 454 | - * @param bool $load_only |
|
| 455 | - * @return EEH_Base | bool |
|
| 456 | - * @throws EE_Error |
|
| 457 | - * @throws ReflectionException |
|
| 458 | - */ |
|
| 459 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | - { |
|
| 461 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | - // retrieve instantiated class |
|
| 464 | - return $this->_load( |
|
| 465 | - $helper_paths, |
|
| 466 | - 'EEH_', |
|
| 467 | - $class_name, |
|
| 468 | - 'helper', |
|
| 469 | - $arguments, |
|
| 470 | - false, |
|
| 471 | - true, |
|
| 472 | - $load_only |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * loads core classes - must be singletons |
|
| 480 | - * |
|
| 481 | - * @param string $class_name - simple class name ie: session |
|
| 482 | - * @param mixed $arguments |
|
| 483 | - * @param bool $load_only |
|
| 484 | - * @param bool $cache whether to cache the object or not. |
|
| 485 | - * @return mixed |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | - { |
|
| 491 | - $paths = array( |
|
| 492 | - EE_LIBRARIES, |
|
| 493 | - EE_LIBRARIES . 'messages' . DS, |
|
| 494 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | - ); |
|
| 498 | - // retrieve instantiated class |
|
| 499 | - return $this->_load( |
|
| 500 | - $paths, |
|
| 501 | - 'EE_', |
|
| 502 | - $class_name, |
|
| 503 | - 'lib', |
|
| 504 | - $arguments, |
|
| 505 | - false, |
|
| 506 | - $cache, |
|
| 507 | - $load_only |
|
| 508 | - ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * loads model classes - must be singletons |
|
| 515 | - * |
|
| 516 | - * @param string $class_name - simple class name ie: price |
|
| 517 | - * @param mixed $arguments |
|
| 518 | - * @param bool $load_only |
|
| 519 | - * @return EEM_Base | bool |
|
| 520 | - * @throws EE_Error |
|
| 521 | - * @throws ReflectionException |
|
| 522 | - */ |
|
| 523 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | - { |
|
| 525 | - $paths = apply_filters( |
|
| 526 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | - EE_MODELS, |
|
| 528 | - EE_CORE, |
|
| 529 | - ) |
|
| 530 | - ); |
|
| 531 | - // retrieve instantiated class |
|
| 532 | - return $this->_load( |
|
| 533 | - $paths, |
|
| 534 | - 'EEM_', |
|
| 535 | - $class_name, |
|
| 536 | - 'model', |
|
| 537 | - $arguments, |
|
| 538 | - false, |
|
| 539 | - true, |
|
| 540 | - $load_only |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * loads model classes - must be singletons |
|
| 548 | - * |
|
| 549 | - * @param string $class_name - simple class name ie: price |
|
| 550 | - * @param mixed $arguments |
|
| 551 | - * @param bool $load_only |
|
| 552 | - * @return mixed | bool |
|
| 553 | - * @throws EE_Error |
|
| 554 | - * @throws ReflectionException |
|
| 555 | - */ |
|
| 556 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | - { |
|
| 558 | - $paths = array( |
|
| 559 | - EE_MODELS . 'fields' . DS, |
|
| 560 | - EE_MODELS . 'helpers' . DS, |
|
| 561 | - EE_MODELS . 'relations' . DS, |
|
| 562 | - EE_MODELS . 'strategies' . DS, |
|
| 563 | - ); |
|
| 564 | - // retrieve instantiated class |
|
| 565 | - return $this->_load( |
|
| 566 | - $paths, |
|
| 567 | - 'EE_', |
|
| 568 | - $class_name, |
|
| 569 | - '', |
|
| 570 | - $arguments, |
|
| 571 | - false, |
|
| 572 | - true, |
|
| 573 | - $load_only |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Determines if $model_name is the name of an actual EE model. |
|
| 581 | - * |
|
| 582 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | - * @return boolean |
|
| 584 | - */ |
|
| 585 | - public function is_model_name($model_name) |
|
| 586 | - { |
|
| 587 | - return isset($this->models[$model_name]); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * generic class loader |
|
| 594 | - * |
|
| 595 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | - * @param string $type - file type - core? class? helper? model? |
|
| 598 | - * @param mixed $arguments |
|
| 599 | - * @param bool $load_only |
|
| 600 | - * @return mixed |
|
| 601 | - * @throws EE_Error |
|
| 602 | - * @throws ReflectionException |
|
| 603 | - */ |
|
| 604 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | - { |
|
| 606 | - // retrieve instantiated class |
|
| 607 | - return $this->_load( |
|
| 608 | - $path_to_file, |
|
| 609 | - '', |
|
| 610 | - $file_name, |
|
| 611 | - $type, |
|
| 612 | - $arguments, |
|
| 613 | - false, |
|
| 614 | - true, |
|
| 615 | - $load_only |
|
| 616 | - ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | - * @param string $class_name - full class name ie: My_Class |
|
| 624 | - * @param string $type - file type - core? class? helper? model? |
|
| 625 | - * @param mixed $arguments |
|
| 626 | - * @param bool $load_only |
|
| 627 | - * @return bool|EE_Addon|object |
|
| 628 | - * @throws EE_Error |
|
| 629 | - * @throws ReflectionException |
|
| 630 | - */ |
|
| 631 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | - { |
|
| 633 | - // retrieve instantiated class |
|
| 634 | - return $this->_load( |
|
| 635 | - $path_to_file, |
|
| 636 | - 'addon', |
|
| 637 | - $class_name, |
|
| 638 | - $type, |
|
| 639 | - $arguments, |
|
| 640 | - false, |
|
| 641 | - true, |
|
| 642 | - $load_only |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * instantiates, caches, and automatically resolves dependencies |
|
| 650 | - * for classes that use a Fully Qualified Class Name. |
|
| 651 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | - * then you need to use one of the existing load_*() methods |
|
| 653 | - * which can resolve the classname and filepath from the passed arguments |
|
| 654 | - * |
|
| 655 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | - * @param bool $from_db some classes are instantiated from the db |
|
| 659 | - * and thus call a different method to instantiate |
|
| 660 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | - * object = class loaded and instantiated successfully. |
|
| 664 | - * bool = fail or success when $load_only is true |
|
| 665 | - * @throws EE_Error |
|
| 666 | - * @throws ReflectionException |
|
| 667 | - */ |
|
| 668 | - public function create( |
|
| 669 | - $class_name = false, |
|
| 670 | - $arguments = array(), |
|
| 671 | - $cache = false, |
|
| 672 | - $from_db = false, |
|
| 673 | - $load_only = false, |
|
| 674 | - $addon = false |
|
| 675 | - ) { |
|
| 676 | - $class_name = ltrim($class_name, '\\'); |
|
| 677 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | - if (! class_exists($class_name)) { |
|
| 679 | - // maybe the class is registered with a preceding \ |
|
| 680 | - $class_name = strpos($class_name, '\\') !== 0 |
|
| 681 | - ? '\\' . $class_name |
|
| 682 | - : $class_name; |
|
| 683 | - // still doesn't exist ? |
|
| 684 | - if (! class_exists($class_name)) { |
|
| 685 | - return null; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 689 | - if ($load_only) { |
|
| 690 | - return true; |
|
| 691 | - } |
|
| 692 | - $addon = $addon |
|
| 693 | - ? 'addon' |
|
| 694 | - : ''; |
|
| 695 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 696 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 697 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 698 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 699 | - // return object if it's already cached |
|
| 700 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 701 | - if ($cached_class !== null) { |
|
| 702 | - return $cached_class; |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - // obtain the loader method from the dependency map |
|
| 706 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 707 | - // instantiate the requested object |
|
| 708 | - if ($loader instanceof Closure) { |
|
| 709 | - $class_obj = $loader($arguments); |
|
| 710 | - } else if ($loader && method_exists($this, $loader)) { |
|
| 711 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 712 | - } else { |
|
| 713 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 714 | - } |
|
| 715 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 716 | - // save it for later... kinda like gum { : $ |
|
| 717 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 718 | - } |
|
| 719 | - $this->_cache_on = true; |
|
| 720 | - return $class_obj; |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * instantiates, caches, and injects dependencies for classes |
|
| 727 | - * |
|
| 728 | - * @param array $file_paths an array of paths to folders to look in |
|
| 729 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 730 | - * @param bool|string $class_name $class name |
|
| 731 | - * @param string $type file type - core? class? helper? model? |
|
| 732 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 733 | - * @param bool $from_db some classes are instantiated from the db |
|
| 734 | - * and thus call a different method to instantiate |
|
| 735 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 736 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 737 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 738 | - * object = class loaded and instantiated successfully. |
|
| 739 | - * bool = fail or success when $load_only is true |
|
| 740 | - * @throws EE_Error |
|
| 741 | - * @throws ReflectionException |
|
| 742 | - */ |
|
| 743 | - protected function _load( |
|
| 744 | - $file_paths = array(), |
|
| 745 | - $class_prefix = 'EE_', |
|
| 746 | - $class_name = false, |
|
| 747 | - $type = 'class', |
|
| 748 | - $arguments = array(), |
|
| 749 | - $from_db = false, |
|
| 750 | - $cache = true, |
|
| 751 | - $load_only = false |
|
| 752 | - ) { |
|
| 753 | - $class_name = ltrim($class_name, '\\'); |
|
| 754 | - // strip php file extension |
|
| 755 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 756 | - // does the class have a prefix ? |
|
| 757 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 758 | - // make sure $class_prefix is uppercase |
|
| 759 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 760 | - // add class prefix ONCE!!! |
|
| 761 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 762 | - } |
|
| 763 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 764 | - $class_exists = class_exists($class_name); |
|
| 765 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 766 | - if ($load_only && $class_exists) { |
|
| 767 | - return true; |
|
| 768 | - } |
|
| 769 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 770 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 771 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 772 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 773 | - // return object if it's already cached |
|
| 774 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 775 | - if ($cached_class !== null) { |
|
| 776 | - return $cached_class; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 780 | - if (! $class_exists) { |
|
| 781 | - // get full path to file |
|
| 782 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 783 | - // load the file |
|
| 784 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 785 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 786 | - if (! $loaded || $load_only) { |
|
| 787 | - // return boolean if only loading, or null if an object was expected |
|
| 788 | - return $load_only |
|
| 789 | - ? $loaded |
|
| 790 | - : null; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - // instantiate the requested object |
|
| 794 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 795 | - if ($this->_cache_on && $cache) { |
|
| 796 | - // save it for later... kinda like gum { : $ |
|
| 797 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 798 | - } |
|
| 799 | - $this->_cache_on = true; |
|
| 800 | - return $class_obj; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * @param string $class_name |
|
| 807 | - * @param string $default have to specify something, but not anything that will conflict |
|
| 808 | - * @return mixed|string |
|
| 809 | - */ |
|
| 810 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 811 | - { |
|
| 812 | - return isset($this->_class_abbreviations[$class_name]) |
|
| 813 | - ? $this->_class_abbreviations[$class_name] |
|
| 814 | - : $default; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * attempts to find a cached version of the requested class |
|
| 819 | - * by looking in the following places: |
|
| 820 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 821 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 822 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 823 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 824 | - * |
|
| 825 | - * @param string $class_name |
|
| 826 | - * @param string $class_prefix |
|
| 827 | - * @return mixed |
|
| 828 | - */ |
|
| 829 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 830 | - { |
|
| 831 | - if ($class_name === 'EE_Registry') { |
|
| 832 | - return $this; |
|
| 833 | - } |
|
| 834 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 835 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 836 | - // check if class has already been loaded, and return it if it has been |
|
| 837 | - if (isset($this->{$class_abbreviation})) { |
|
| 838 | - return $this->{$class_abbreviation}; |
|
| 839 | - } |
|
| 840 | - if (isset ($this->{$class_name})) { |
|
| 841 | - return $this->{$class_name}; |
|
| 842 | - } |
|
| 843 | - if (isset ($this->LIB->{$class_name})) { |
|
| 844 | - return $this->LIB->{$class_name}; |
|
| 845 | - } |
|
| 846 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 847 | - return $this->addons->{$class_name}; |
|
| 848 | - } |
|
| 849 | - return null; |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * removes a cached version of the requested class |
|
| 856 | - * |
|
| 857 | - * @param string $class_name |
|
| 858 | - * @param boolean $addon |
|
| 859 | - * @return boolean |
|
| 860 | - */ |
|
| 861 | - public function clear_cached_class($class_name, $addon = false) |
|
| 862 | - { |
|
| 863 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 864 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 865 | - // check if class has already been loaded, and return it if it has been |
|
| 866 | - if (isset($this->{$class_abbreviation})) { |
|
| 867 | - $this->{$class_abbreviation} = null; |
|
| 868 | - return true; |
|
| 869 | - } |
|
| 870 | - if (isset($this->{$class_name})) { |
|
| 871 | - $this->{$class_name} = null; |
|
| 872 | - return true; |
|
| 873 | - } |
|
| 874 | - if (isset($this->LIB->{$class_name})) { |
|
| 875 | - unset($this->LIB->{$class_name}); |
|
| 876 | - return true; |
|
| 877 | - } |
|
| 878 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 879 | - unset($this->addons->{$class_name}); |
|
| 880 | - return true; |
|
| 881 | - } |
|
| 882 | - return false; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * attempts to find a full valid filepath for the requested class. |
|
| 889 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 890 | - * then returns that path if the target file has been found and is readable |
|
| 891 | - * |
|
| 892 | - * @param string $class_name |
|
| 893 | - * @param string $type |
|
| 894 | - * @param array $file_paths |
|
| 895 | - * @return string | bool |
|
| 896 | - */ |
|
| 897 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 898 | - { |
|
| 899 | - // make sure $file_paths is an array |
|
| 900 | - $file_paths = is_array($file_paths) |
|
| 901 | - ? $file_paths |
|
| 902 | - : array($file_paths); |
|
| 903 | - // cycle thru paths |
|
| 904 | - foreach ($file_paths as $key => $file_path) { |
|
| 905 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 906 | - $file_path = $file_path |
|
| 907 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 908 | - : EE_CLASSES; |
|
| 909 | - // prep file type |
|
| 910 | - $type = ! empty($type) |
|
| 911 | - ? trim($type, '.') . '.' |
|
| 912 | - : ''; |
|
| 913 | - // build full file path |
|
| 914 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 915 | - //does the file exist and can be read ? |
|
| 916 | - if (is_readable($file_paths[$key])) { |
|
| 917 | - return $file_paths[$key]; |
|
| 918 | - } |
|
| 919 | - } |
|
| 920 | - return false; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * basically just performs a require_once() |
|
| 927 | - * but with some error handling |
|
| 928 | - * |
|
| 929 | - * @param string $path |
|
| 930 | - * @param string $class_name |
|
| 931 | - * @param string $type |
|
| 932 | - * @param array $file_paths |
|
| 933 | - * @return bool |
|
| 934 | - * @throws EE_Error |
|
| 935 | - * @throws ReflectionException |
|
| 936 | - */ |
|
| 937 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 938 | - { |
|
| 939 | - // don't give up! you gotta... |
|
| 940 | - try { |
|
| 941 | - //does the file exist and can it be read ? |
|
| 942 | - if (! $path) { |
|
| 943 | - // so sorry, can't find the file |
|
| 944 | - throw new EE_Error ( |
|
| 945 | - sprintf( |
|
| 946 | - esc_html__( |
|
| 947 | - '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', |
|
| 948 | - 'event_espresso' |
|
| 949 | - ), |
|
| 950 | - trim($type, '.'), |
|
| 951 | - $class_name, |
|
| 952 | - '<br />' . implode(',<br />', $file_paths) |
|
| 953 | - ) |
|
| 954 | - ); |
|
| 955 | - } |
|
| 956 | - // get the file |
|
| 957 | - require_once($path); |
|
| 958 | - // if the class isn't already declared somewhere |
|
| 959 | - if (class_exists($class_name, false) === false) { |
|
| 960 | - // so sorry, not a class |
|
| 961 | - throw new EE_Error( |
|
| 962 | - sprintf( |
|
| 963 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 964 | - $type, |
|
| 965 | - $path, |
|
| 966 | - $class_name |
|
| 967 | - ) |
|
| 968 | - ); |
|
| 969 | - } |
|
| 970 | - } catch (EE_Error $e) { |
|
| 971 | - $e->get_error(); |
|
| 972 | - return false; |
|
| 973 | - } |
|
| 974 | - return true; |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * _create_object |
|
| 981 | - * Attempts to instantiate the requested class via any of the |
|
| 982 | - * commonly used instantiation methods employed throughout EE. |
|
| 983 | - * The priority for instantiation is as follows: |
|
| 984 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 985 | - * - model objects via their 'new_instance_from_db' method |
|
| 986 | - * - model objects via their 'new_instance' method |
|
| 987 | - * - "singleton" classes" via their 'instance' method |
|
| 988 | - * - standard instantiable classes via their __constructor |
|
| 989 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 990 | - * then the constructor for the requested class will be examined to determine |
|
| 991 | - * if any dependencies exist, and if they can be injected. |
|
| 992 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 993 | - * |
|
| 994 | - * @param string $class_name |
|
| 995 | - * @param array $arguments |
|
| 996 | - * @param string $type |
|
| 997 | - * @param bool $from_db |
|
| 998 | - * @return null|object |
|
| 999 | - * @throws EE_Error |
|
| 1000 | - * @throws ReflectionException |
|
| 1001 | - */ |
|
| 1002 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1003 | - { |
|
| 1004 | - $class_obj = null; |
|
| 1005 | - $instantiation_mode = '0) none'; |
|
| 1006 | - // don't give up! you gotta... |
|
| 1007 | - try { |
|
| 1008 | - // create reflection |
|
| 1009 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 1010 | - // make sure arguments are an array |
|
| 1011 | - $arguments = is_array($arguments) |
|
| 1012 | - ? $arguments |
|
| 1013 | - : array($arguments); |
|
| 1014 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1015 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1016 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1017 | - ? $arguments |
|
| 1018 | - : array($arguments); |
|
| 1019 | - // attempt to inject dependencies ? |
|
| 1020 | - if ($this->_dependency_map->has($class_name)) { |
|
| 1021 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1022 | - } |
|
| 1023 | - // instantiate the class if possible |
|
| 1024 | - if ($reflector->isAbstract()) { |
|
| 1025 | - // nothing to instantiate, loading file was enough |
|
| 1026 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1027 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1028 | - $class_obj = true; |
|
| 1029 | - } else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1030 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1031 | - $instantiation_mode = '2) no constructor but instantiable'; |
|
| 1032 | - $class_obj = $reflector->newInstance(); |
|
| 1033 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1034 | - $instantiation_mode = '3) new_instance_from_db()'; |
|
| 1035 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1036 | - } else if (method_exists($class_name, 'new_instance')) { |
|
| 1037 | - $instantiation_mode = '4) new_instance()'; |
|
| 1038 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1039 | - } else if (method_exists($class_name, 'instance')) { |
|
| 1040 | - $instantiation_mode = '5) instance()'; |
|
| 1041 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1042 | - } else if ($reflector->isInstantiable()) { |
|
| 1043 | - $instantiation_mode = '6) constructor'; |
|
| 1044 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 1045 | - } else { |
|
| 1046 | - // heh ? something's not right ! |
|
| 1047 | - throw new EE_Error( |
|
| 1048 | - sprintf( |
|
| 1049 | - esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1050 | - $type, |
|
| 1051 | - $class_name |
|
| 1052 | - ) |
|
| 1053 | - ); |
|
| 1054 | - } |
|
| 1055 | - } catch (Exception $e) { |
|
| 1056 | - if (! $e instanceof EE_Error) { |
|
| 1057 | - $e = new EE_Error( |
|
| 1058 | - sprintf( |
|
| 1059 | - esc_html__( |
|
| 1060 | - 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', |
|
| 1061 | - 'event_espresso' |
|
| 1062 | - ), |
|
| 1063 | - $class_name, |
|
| 1064 | - '<br />', |
|
| 1065 | - $e->getMessage(), |
|
| 1066 | - $instantiation_mode |
|
| 1067 | - ) |
|
| 1068 | - ); |
|
| 1069 | - } |
|
| 1070 | - $e->get_error(); |
|
| 1071 | - } |
|
| 1072 | - return $class_obj; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1079 | - * @param array $array |
|
| 1080 | - * @return bool |
|
| 1081 | - */ |
|
| 1082 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1083 | - { |
|
| 1084 | - return ! empty($array) |
|
| 1085 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1086 | - : true; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * getReflectionClass |
|
| 1093 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1094 | - * and returns that instead of creating a new one |
|
| 1095 | - * |
|
| 1096 | - * @param string $class_name |
|
| 1097 | - * @return ReflectionClass |
|
| 1098 | - * @throws ReflectionException |
|
| 1099 | - */ |
|
| 1100 | - public function get_ReflectionClass($class_name) |
|
| 1101 | - { |
|
| 1102 | - if ( |
|
| 1103 | - ! isset($this->_reflectors[$class_name]) |
|
| 1104 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1105 | - ) { |
|
| 1106 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1107 | - } |
|
| 1108 | - return $this->_reflectors[$class_name]; |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * _resolve_dependencies |
|
| 1115 | - * examines the constructor for the requested class to determine |
|
| 1116 | - * if any dependencies exist, and if they can be injected. |
|
| 1117 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1118 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1119 | - * For example: |
|
| 1120 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1121 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1122 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1123 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1124 | - * and the correct classes can be loaded |
|
| 1125 | - * |
|
| 1126 | - * @param ReflectionClass $reflector |
|
| 1127 | - * @param string $class_name |
|
| 1128 | - * @param array $arguments |
|
| 1129 | - * @return array |
|
| 1130 | - * @throws EE_Error |
|
| 1131 | - * @throws ReflectionException |
|
| 1132 | - */ |
|
| 1133 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1134 | - { |
|
| 1135 | - // let's examine the constructor |
|
| 1136 | - $constructor = $reflector->getConstructor(); |
|
| 1137 | - // whu? huh? nothing? |
|
| 1138 | - if (! $constructor) { |
|
| 1139 | - return $arguments; |
|
| 1140 | - } |
|
| 1141 | - // get constructor parameters |
|
| 1142 | - $params = $constructor->getParameters(); |
|
| 1143 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1144 | - $argument_keys = array_keys($arguments); |
|
| 1145 | - // now loop thru all of the constructors expected parameters |
|
| 1146 | - foreach ($params as $index => $param) { |
|
| 1147 | - // is this a dependency for a specific class ? |
|
| 1148 | - $param_class = $param->getClass() |
|
| 1149 | - ? $param->getClass()->name |
|
| 1150 | - : null; |
|
| 1151 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1152 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1153 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1154 | - : $param_class; |
|
| 1155 | - if ( |
|
| 1156 | - // param is not even a class |
|
| 1157 | - $param_class === null |
|
| 1158 | - // and something already exists in the incoming arguments for this param |
|
| 1159 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1160 | - ) { |
|
| 1161 | - // so let's skip this argument and move on to the next |
|
| 1162 | - continue; |
|
| 1163 | - } |
|
| 1164 | - if ( |
|
| 1165 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1166 | - $param_class !== null |
|
| 1167 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1168 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1169 | - ) { |
|
| 1170 | - // skip this argument and move on to the next |
|
| 1171 | - continue; |
|
| 1172 | - } |
|
| 1173 | - if ( |
|
| 1174 | - // parameter is type hinted as a class, and should be injected |
|
| 1175 | - $param_class !== null |
|
| 1176 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1177 | - ) { |
|
| 1178 | - $arguments = $this->_resolve_dependency( |
|
| 1179 | - $class_name, |
|
| 1180 | - $param_class, |
|
| 1181 | - $arguments, |
|
| 1182 | - $index, |
|
| 1183 | - $argument_keys |
|
| 1184 | - ); |
|
| 1185 | - } else { |
|
| 1186 | - try { |
|
| 1187 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1188 | - ? $param->getDefaultValue() |
|
| 1189 | - : null; |
|
| 1190 | - } catch (ReflectionException $e) { |
|
| 1191 | - throw new ReflectionException( |
|
| 1192 | - sprintf( |
|
| 1193 | - esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1194 | - $e->getMessage(), |
|
| 1195 | - $param->getName() |
|
| 1196 | - ) |
|
| 1197 | - ); |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - return $arguments; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * @param string $class_name |
|
| 1208 | - * @param string $param_class |
|
| 1209 | - * @param array $arguments |
|
| 1210 | - * @param mixed $index |
|
| 1211 | - * @param array $argument_keys |
|
| 1212 | - * @return array |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - * @throws ReflectionException |
|
| 1215 | - * @throws InvalidArgumentException |
|
| 1216 | - * @throws InvalidInterfaceException |
|
| 1217 | - * @throws InvalidDataTypeException |
|
| 1218 | - */ |
|
| 1219 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1220 | - { |
|
| 1221 | - $dependency = null; |
|
| 1222 | - // should dependency be loaded from cache ? |
|
| 1223 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1224 | - $class_name, |
|
| 1225 | - $param_class |
|
| 1226 | - ); |
|
| 1227 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1228 | - // we might have a dependency... |
|
| 1229 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1230 | - $cached_class = $cache_on |
|
| 1231 | - ? $this->_get_cached_class($param_class) |
|
| 1232 | - : null; |
|
| 1233 | - // and grab it if it exists |
|
| 1234 | - if ($cached_class instanceof $param_class) { |
|
| 1235 | - $dependency = $cached_class; |
|
| 1236 | - } else if ($param_class !== $class_name) { |
|
| 1237 | - // obtain the loader method from the dependency map |
|
| 1238 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1239 | - // is loader a custom closure ? |
|
| 1240 | - if ($loader instanceof Closure) { |
|
| 1241 | - $dependency = $loader($arguments); |
|
| 1242 | - } else { |
|
| 1243 | - // set the cache on property for the recursive loading call |
|
| 1244 | - $this->_cache_on = $cache_on; |
|
| 1245 | - // if not, then let's try and load it via the registry |
|
| 1246 | - if ($loader && method_exists($this, $loader)) { |
|
| 1247 | - $dependency = $this->{$loader}($param_class); |
|
| 1248 | - } else { |
|
| 1249 | - $dependency = LoaderFactory::getLoader()->load( |
|
| 1250 | - $param_class, |
|
| 1251 | - array(), |
|
| 1252 | - $cache_on |
|
| 1253 | - ); |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - // did we successfully find the correct dependency ? |
|
| 1258 | - if ($dependency instanceof $param_class) { |
|
| 1259 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1260 | - $arguments[$index] = $dependency; |
|
| 1261 | - } |
|
| 1262 | - return $arguments; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * _set_cached_class |
|
| 1269 | - * attempts to cache the instantiated class locally |
|
| 1270 | - * in one of the following places, in the following order: |
|
| 1271 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1272 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1273 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1274 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1275 | - * |
|
| 1276 | - * @param object $class_obj |
|
| 1277 | - * @param string $class_name |
|
| 1278 | - * @param string $class_prefix |
|
| 1279 | - * @param bool $from_db |
|
| 1280 | - * @return void |
|
| 1281 | - */ |
|
| 1282 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1283 | - { |
|
| 1284 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1285 | - return; |
|
| 1286 | - } |
|
| 1287 | - // return newly instantiated class |
|
| 1288 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1289 | - if ($class_abbreviation) { |
|
| 1290 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1291 | - return; |
|
| 1292 | - } |
|
| 1293 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1294 | - if (property_exists($this, $class_name)) { |
|
| 1295 | - $this->{$class_name} = $class_obj; |
|
| 1296 | - return; |
|
| 1297 | - } |
|
| 1298 | - if ($class_prefix === 'addon') { |
|
| 1299 | - $this->addons->{$class_name} = $class_obj; |
|
| 1300 | - return; |
|
| 1301 | - } |
|
| 1302 | - if (! $from_db) { |
|
| 1303 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1311 | - * |
|
| 1312 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1313 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1314 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1315 | - * @param array $arguments |
|
| 1316 | - * @return object |
|
| 1317 | - */ |
|
| 1318 | - public static function factory($classname, $arguments = array()) |
|
| 1319 | - { |
|
| 1320 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1321 | - if ($loader instanceof Closure) { |
|
| 1322 | - return $loader($arguments); |
|
| 1323 | - } |
|
| 1324 | - if (method_exists(self::instance(), $loader)) { |
|
| 1325 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1326 | - } |
|
| 1327 | - return null; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1334 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1335 | - * |
|
| 1336 | - * @param string $name |
|
| 1337 | - * @return EE_Addon |
|
| 1338 | - */ |
|
| 1339 | - public function get_addon_by_name($name) |
|
| 1340 | - { |
|
| 1341 | - foreach ($this->addons as $addon) { |
|
| 1342 | - if ($addon->name() === $name) { |
|
| 1343 | - return $addon; |
|
| 1344 | - } |
|
| 1345 | - } |
|
| 1346 | - return null; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1353 | - * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1354 | - * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1355 | - * EE_Config::instance()->addons->{classname} |
|
| 1356 | - * |
|
| 1357 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1358 | - */ |
|
| 1359 | - public function get_addons_by_name() |
|
| 1360 | - { |
|
| 1361 | - $addons = array(); |
|
| 1362 | - foreach ($this->addons as $addon) { |
|
| 1363 | - $addons[$addon->name()] = $addon; |
|
| 1364 | - } |
|
| 1365 | - return $addons; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1372 | - * a stale copy of it around |
|
| 1373 | - * |
|
| 1374 | - * @param string $model_name |
|
| 1375 | - * @return \EEM_Base |
|
| 1376 | - * @throws \EE_Error |
|
| 1377 | - */ |
|
| 1378 | - public function reset_model($model_name) |
|
| 1379 | - { |
|
| 1380 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1381 | - ? "EEM_{$model_name}" |
|
| 1382 | - : $model_name; |
|
| 1383 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1384 | - return null; |
|
| 1385 | - } |
|
| 1386 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1387 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1388 | - && is_callable( |
|
| 1389 | - array($model_class_name, 'reset') |
|
| 1390 | - )) { |
|
| 1391 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1392 | - } else { |
|
| 1393 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1394 | - } |
|
| 1395 | - return $this->LIB->{$model_class_name}; |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * Resets the registry. |
|
| 1402 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1403 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1404 | - * - $_dependency_map |
|
| 1405 | - * - $_class_abbreviations |
|
| 1406 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1407 | - * - $REQ: Still on the same request so no need to change. |
|
| 1408 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1409 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1410 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1411 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1412 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1413 | - * switch or on the restore. |
|
| 1414 | - * - $modules |
|
| 1415 | - * - $shortcodes |
|
| 1416 | - * - $widgets |
|
| 1417 | - * |
|
| 1418 | - * @param boolean $hard [deprecated] |
|
| 1419 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1420 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1421 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1422 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1423 | - * client |
|
| 1424 | - * code instead can just change the model context to a different blog id if |
|
| 1425 | - * necessary |
|
| 1426 | - * @return EE_Registry |
|
| 1427 | - * @throws EE_Error |
|
| 1428 | - * @throws ReflectionException |
|
| 1429 | - */ |
|
| 1430 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1431 | - { |
|
| 1432 | - $instance = self::instance(); |
|
| 1433 | - $instance->_cache_on = true; |
|
| 1434 | - // reset some "special" classes |
|
| 1435 | - EEH_Activation::reset(); |
|
| 1436 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1437 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1438 | - $instance->CART = null; |
|
| 1439 | - $instance->MRM = null; |
|
| 1440 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1441 | - //messages reset |
|
| 1442 | - EED_Messages::reset(); |
|
| 1443 | - //handle of objects cached on LIB |
|
| 1444 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1445 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1446 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1447 | - unset($instance->{$cache}->{$class_name}); |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1451 | - return $instance; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - |
|
| 1455 | - |
|
| 1456 | - /** |
|
| 1457 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1458 | - * if passed object implements InterminableInterface, then return false, |
|
| 1459 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1460 | - * |
|
| 1461 | - * @param $object |
|
| 1462 | - * @param bool $reset_models |
|
| 1463 | - * @return bool returns true if cached object should be unset |
|
| 1464 | - */ |
|
| 1465 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1466 | - { |
|
| 1467 | - if (! is_object($object)) { |
|
| 1468 | - // don't unset anything that's not an object |
|
| 1469 | - return false; |
|
| 1470 | - } |
|
| 1471 | - if ($object instanceof EED_Module) { |
|
| 1472 | - $object::reset(); |
|
| 1473 | - // don't unset modules |
|
| 1474 | - return false; |
|
| 1475 | - } |
|
| 1476 | - if ($object instanceof ResettableInterface) { |
|
| 1477 | - if ($object instanceof EEM_Base) { |
|
| 1478 | - if ($reset_models) { |
|
| 1479 | - $object->reset(); |
|
| 1480 | - return true; |
|
| 1481 | - } |
|
| 1482 | - return false; |
|
| 1483 | - } |
|
| 1484 | - $object->reset(); |
|
| 1485 | - return true; |
|
| 1486 | - } |
|
| 1487 | - if (! $object instanceof InterminableInterface) { |
|
| 1488 | - return true; |
|
| 1489 | - } |
|
| 1490 | - return false; |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - |
|
| 1494 | - |
|
| 1495 | - /** |
|
| 1496 | - * Gets all the custom post type models defined |
|
| 1497 | - * |
|
| 1498 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1499 | - */ |
|
| 1500 | - public function cpt_models() |
|
| 1501 | - { |
|
| 1502 | - $cpt_models = array(); |
|
| 1503 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1504 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1505 | - $cpt_models[$short_name] = $classname; |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1508 | - return $cpt_models; |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * @return \EE_Config |
|
| 1515 | - */ |
|
| 1516 | - public static function CFG() |
|
| 1517 | - { |
|
| 1518 | - return self::instance()->CFG; |
|
| 1519 | - } |
|
| 25 | + /** |
|
| 26 | + * @var EE_Registry $_instance |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var EE_Dependency_Map $_dependency_map |
|
| 32 | + */ |
|
| 33 | + protected $_dependency_map; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var array $_class_abbreviations |
|
| 37 | + */ |
|
| 38 | + protected $_class_abbreviations = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var CommandBusInterface $BUS |
|
| 42 | + */ |
|
| 43 | + public $BUS; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Cart $CART |
|
| 47 | + */ |
|
| 48 | + public $CART; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var EE_Config $CFG |
|
| 52 | + */ |
|
| 53 | + public $CFG; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EE_Network_Config $NET_CFG |
|
| 57 | + */ |
|
| 58 | + public $NET_CFG; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * StdClass object for storing library classes in |
|
| 62 | + * |
|
| 63 | + * @var StdClass $LIB |
|
| 64 | + */ |
|
| 65 | + public $LIB; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var EE_Request_Handler $REQ |
|
| 69 | + */ |
|
| 70 | + public $REQ; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var EE_Session $SSN |
|
| 74 | + */ |
|
| 75 | + public $SSN; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @since 4.5.0 |
|
| 79 | + * @var EE_Capabilities $CAP |
|
| 80 | + */ |
|
| 81 | + public $CAP; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @since 4.9.0 |
|
| 85 | + * @var EE_Message_Resource_Manager $MRM |
|
| 86 | + */ |
|
| 87 | + public $MRM; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @var Registry $AssetsRegistry |
|
| 92 | + */ |
|
| 93 | + public $AssetsRegistry; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | + * |
|
| 98 | + * @var EE_Addon[] $addons |
|
| 99 | + */ |
|
| 100 | + public $addons; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | + * |
|
| 105 | + * @var EEM_Base[] $models |
|
| 106 | + */ |
|
| 107 | + public $models = array(); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var EED_Module[] $modules |
|
| 111 | + */ |
|
| 112 | + public $modules; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @var EES_Shortcode[] $shortcodes |
|
| 116 | + */ |
|
| 117 | + public $shortcodes; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @var WP_Widget[] $widgets |
|
| 121 | + */ |
|
| 122 | + public $widgets; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | + * classnames (eg "EEM_Event") |
|
| 129 | + * |
|
| 130 | + * @var array $non_abstract_db_models |
|
| 131 | + */ |
|
| 132 | + public $non_abstract_db_models = array(); |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * internationalization for JS strings |
|
| 137 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | + * in js file: var translatedString = eei18n.string_key; |
|
| 139 | + * |
|
| 140 | + * @var array $i18n_js_strings |
|
| 141 | + */ |
|
| 142 | + public static $i18n_js_strings = array(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * $main_file - path to espresso.php |
|
| 147 | + * |
|
| 148 | + * @var array $main_file |
|
| 149 | + */ |
|
| 150 | + public $main_file; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * array of ReflectionClass objects where the key is the class name |
|
| 154 | + * |
|
| 155 | + * @var ReflectionClass[] $_reflectors |
|
| 156 | + */ |
|
| 157 | + public $_reflectors; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | + * |
|
| 162 | + * @var boolean $_cache_on |
|
| 163 | + */ |
|
| 164 | + protected $_cache_on = true; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @singleton method used to instantiate class object |
|
| 170 | + * @param EE_Dependency_Map $dependency_map |
|
| 171 | + * @return EE_Registry instance |
|
| 172 | + * @throws InvalidArgumentException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + * @throws InvalidDataTypeException |
|
| 175 | + */ |
|
| 176 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | + { |
|
| 178 | + // check if class object is instantiated |
|
| 179 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | + self::$_instance = new self($dependency_map); |
|
| 181 | + } |
|
| 182 | + return self::$_instance; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * protected constructor to prevent direct creation |
|
| 189 | + * |
|
| 190 | + * @Constructor |
|
| 191 | + * @param EE_Dependency_Map $dependency_map |
|
| 192 | + * @throws InvalidDataTypeException |
|
| 193 | + * @throws InvalidInterfaceException |
|
| 194 | + * @throws InvalidArgumentException |
|
| 195 | + */ |
|
| 196 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | + { |
|
| 198 | + $this->_dependency_map = $dependency_map; |
|
| 199 | + $this->LIB = new stdClass(); |
|
| 200 | + $this->addons = new stdClass(); |
|
| 201 | + $this->modules = new stdClass(); |
|
| 202 | + $this->shortcodes = new stdClass(); |
|
| 203 | + $this->widgets = new stdClass(); |
|
| 204 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * initialize |
|
| 211 | + * |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + */ |
|
| 215 | + public function initialize() |
|
| 216 | + { |
|
| 217 | + $this->_class_abbreviations = apply_filters( |
|
| 218 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | + array( |
|
| 220 | + 'EE_Config' => 'CFG', |
|
| 221 | + 'EE_Session' => 'SSN', |
|
| 222 | + 'EE_Capabilities' => 'CAP', |
|
| 223 | + 'EE_Cart' => 'CART', |
|
| 224 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | + 'EE_Request_Handler' => 'REQ', |
|
| 226 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + $this->load_core('Base', array(), true); |
|
| 232 | + // add our request and response objects to the cache |
|
| 233 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | + $this->_set_cached_class( |
|
| 235 | + $request_loader(), |
|
| 236 | + 'EE_Request' |
|
| 237 | + ); |
|
| 238 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | + $this->_set_cached_class( |
|
| 240 | + $response_loader(), |
|
| 241 | + 'EE_Response' |
|
| 242 | + ); |
|
| 243 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + public function init() |
|
| 252 | + { |
|
| 253 | + // Get current page protocol |
|
| 254 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * localize_i18n_js_strings |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public static function localize_i18n_js_strings() |
|
| 268 | + { |
|
| 269 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | + if (is_scalar($value)) { |
|
| 272 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param mixed string | EED_Module $module |
|
| 282 | + * @throws EE_Error |
|
| 283 | + * @throws ReflectionException |
|
| 284 | + */ |
|
| 285 | + public function add_module($module) |
|
| 286 | + { |
|
| 287 | + if ($module instanceof EED_Module) { |
|
| 288 | + $module_class = get_class($module); |
|
| 289 | + $this->modules->{$module_class} = $module; |
|
| 290 | + } else { |
|
| 291 | + if (! class_exists('EE_Module_Request_Router')) { |
|
| 292 | + $this->load_core('Module_Request_Router'); |
|
| 293 | + } |
|
| 294 | + EE_Module_Request_Router::module_factory($module); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $module_name |
|
| 302 | + * @return mixed EED_Module | NULL |
|
| 303 | + */ |
|
| 304 | + public function get_module($module_name = '') |
|
| 305 | + { |
|
| 306 | + return isset($this->modules->{$module_name}) |
|
| 307 | + ? $this->modules->{$module_name} |
|
| 308 | + : null; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * loads core classes - must be singletons |
|
| 315 | + * |
|
| 316 | + * @param string $class_name - simple class name ie: session |
|
| 317 | + * @param mixed $arguments |
|
| 318 | + * @param bool $load_only |
|
| 319 | + * @return mixed |
|
| 320 | + * @throws EE_Error |
|
| 321 | + * @throws ReflectionException |
|
| 322 | + */ |
|
| 323 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | + { |
|
| 325 | + $core_paths = apply_filters( |
|
| 326 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | + array( |
|
| 328 | + EE_CORE, |
|
| 329 | + EE_ADMIN, |
|
| 330 | + EE_CPTS, |
|
| 331 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | + EE_CORE . 'capabilities' . DS, |
|
| 333 | + EE_CORE . 'request_stack' . DS, |
|
| 334 | + EE_CORE . 'middleware' . DS, |
|
| 335 | + ) |
|
| 336 | + ); |
|
| 337 | + // retrieve instantiated class |
|
| 338 | + return $this->_load( |
|
| 339 | + $core_paths, |
|
| 340 | + 'EE_', |
|
| 341 | + $class_name, |
|
| 342 | + 'core', |
|
| 343 | + $arguments, |
|
| 344 | + false, |
|
| 345 | + true, |
|
| 346 | + $load_only |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * loads service classes |
|
| 354 | + * |
|
| 355 | + * @param string $class_name - simple class name ie: session |
|
| 356 | + * @param mixed $arguments |
|
| 357 | + * @param bool $load_only |
|
| 358 | + * @return mixed |
|
| 359 | + * @throws EE_Error |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + */ |
|
| 362 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | + { |
|
| 364 | + $service_paths = apply_filters( |
|
| 365 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | + array( |
|
| 367 | + EE_CORE . 'services' . DS, |
|
| 368 | + ) |
|
| 369 | + ); |
|
| 370 | + // retrieve instantiated class |
|
| 371 | + return $this->_load( |
|
| 372 | + $service_paths, |
|
| 373 | + 'EE_', |
|
| 374 | + $class_name, |
|
| 375 | + 'class', |
|
| 376 | + $arguments, |
|
| 377 | + false, |
|
| 378 | + true, |
|
| 379 | + $load_only |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * loads data_migration_scripts |
|
| 387 | + * |
|
| 388 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | + * @param mixed $arguments |
|
| 390 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | + * @throws EE_Error |
|
| 392 | + * @throws ReflectionException |
|
| 393 | + */ |
|
| 394 | + public function load_dms($class_name, $arguments = array()) |
|
| 395 | + { |
|
| 396 | + // retrieve instantiated class |
|
| 397 | + return $this->_load( |
|
| 398 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | + 'EE_DMS_', |
|
| 400 | + $class_name, |
|
| 401 | + 'dms', |
|
| 402 | + $arguments, |
|
| 403 | + false, |
|
| 404 | + false |
|
| 405 | + ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * loads object creating classes - must be singletons |
|
| 412 | + * |
|
| 413 | + * @param string $class_name - simple class name ie: attendee |
|
| 414 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | + * instantiate |
|
| 417 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | + * (default) |
|
| 421 | + * @return EE_Base_Class | bool |
|
| 422 | + * @throws EE_Error |
|
| 423 | + * @throws ReflectionException |
|
| 424 | + */ |
|
| 425 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | + { |
|
| 427 | + $paths = apply_filters( |
|
| 428 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | + EE_CORE, |
|
| 430 | + EE_CLASSES, |
|
| 431 | + EE_BUSINESS, |
|
| 432 | + ) |
|
| 433 | + ); |
|
| 434 | + // retrieve instantiated class |
|
| 435 | + return $this->_load( |
|
| 436 | + $paths, |
|
| 437 | + 'EE_', |
|
| 438 | + $class_name, |
|
| 439 | + 'class', |
|
| 440 | + $arguments, |
|
| 441 | + $from_db, |
|
| 442 | + $cache, |
|
| 443 | + $load_only |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * loads helper classes - must be singletons |
|
| 451 | + * |
|
| 452 | + * @param string $class_name - simple class name ie: price |
|
| 453 | + * @param mixed $arguments |
|
| 454 | + * @param bool $load_only |
|
| 455 | + * @return EEH_Base | bool |
|
| 456 | + * @throws EE_Error |
|
| 457 | + * @throws ReflectionException |
|
| 458 | + */ |
|
| 459 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | + { |
|
| 461 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | + // retrieve instantiated class |
|
| 464 | + return $this->_load( |
|
| 465 | + $helper_paths, |
|
| 466 | + 'EEH_', |
|
| 467 | + $class_name, |
|
| 468 | + 'helper', |
|
| 469 | + $arguments, |
|
| 470 | + false, |
|
| 471 | + true, |
|
| 472 | + $load_only |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * loads core classes - must be singletons |
|
| 480 | + * |
|
| 481 | + * @param string $class_name - simple class name ie: session |
|
| 482 | + * @param mixed $arguments |
|
| 483 | + * @param bool $load_only |
|
| 484 | + * @param bool $cache whether to cache the object or not. |
|
| 485 | + * @return mixed |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | + { |
|
| 491 | + $paths = array( |
|
| 492 | + EE_LIBRARIES, |
|
| 493 | + EE_LIBRARIES . 'messages' . DS, |
|
| 494 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | + ); |
|
| 498 | + // retrieve instantiated class |
|
| 499 | + return $this->_load( |
|
| 500 | + $paths, |
|
| 501 | + 'EE_', |
|
| 502 | + $class_name, |
|
| 503 | + 'lib', |
|
| 504 | + $arguments, |
|
| 505 | + false, |
|
| 506 | + $cache, |
|
| 507 | + $load_only |
|
| 508 | + ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * loads model classes - must be singletons |
|
| 515 | + * |
|
| 516 | + * @param string $class_name - simple class name ie: price |
|
| 517 | + * @param mixed $arguments |
|
| 518 | + * @param bool $load_only |
|
| 519 | + * @return EEM_Base | bool |
|
| 520 | + * @throws EE_Error |
|
| 521 | + * @throws ReflectionException |
|
| 522 | + */ |
|
| 523 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | + { |
|
| 525 | + $paths = apply_filters( |
|
| 526 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | + EE_MODELS, |
|
| 528 | + EE_CORE, |
|
| 529 | + ) |
|
| 530 | + ); |
|
| 531 | + // retrieve instantiated class |
|
| 532 | + return $this->_load( |
|
| 533 | + $paths, |
|
| 534 | + 'EEM_', |
|
| 535 | + $class_name, |
|
| 536 | + 'model', |
|
| 537 | + $arguments, |
|
| 538 | + false, |
|
| 539 | + true, |
|
| 540 | + $load_only |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * loads model classes - must be singletons |
|
| 548 | + * |
|
| 549 | + * @param string $class_name - simple class name ie: price |
|
| 550 | + * @param mixed $arguments |
|
| 551 | + * @param bool $load_only |
|
| 552 | + * @return mixed | bool |
|
| 553 | + * @throws EE_Error |
|
| 554 | + * @throws ReflectionException |
|
| 555 | + */ |
|
| 556 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | + { |
|
| 558 | + $paths = array( |
|
| 559 | + EE_MODELS . 'fields' . DS, |
|
| 560 | + EE_MODELS . 'helpers' . DS, |
|
| 561 | + EE_MODELS . 'relations' . DS, |
|
| 562 | + EE_MODELS . 'strategies' . DS, |
|
| 563 | + ); |
|
| 564 | + // retrieve instantiated class |
|
| 565 | + return $this->_load( |
|
| 566 | + $paths, |
|
| 567 | + 'EE_', |
|
| 568 | + $class_name, |
|
| 569 | + '', |
|
| 570 | + $arguments, |
|
| 571 | + false, |
|
| 572 | + true, |
|
| 573 | + $load_only |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Determines if $model_name is the name of an actual EE model. |
|
| 581 | + * |
|
| 582 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | + * @return boolean |
|
| 584 | + */ |
|
| 585 | + public function is_model_name($model_name) |
|
| 586 | + { |
|
| 587 | + return isset($this->models[$model_name]); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * generic class loader |
|
| 594 | + * |
|
| 595 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | + * @param string $type - file type - core? class? helper? model? |
|
| 598 | + * @param mixed $arguments |
|
| 599 | + * @param bool $load_only |
|
| 600 | + * @return mixed |
|
| 601 | + * @throws EE_Error |
|
| 602 | + * @throws ReflectionException |
|
| 603 | + */ |
|
| 604 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | + { |
|
| 606 | + // retrieve instantiated class |
|
| 607 | + return $this->_load( |
|
| 608 | + $path_to_file, |
|
| 609 | + '', |
|
| 610 | + $file_name, |
|
| 611 | + $type, |
|
| 612 | + $arguments, |
|
| 613 | + false, |
|
| 614 | + true, |
|
| 615 | + $load_only |
|
| 616 | + ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | + * @param string $class_name - full class name ie: My_Class |
|
| 624 | + * @param string $type - file type - core? class? helper? model? |
|
| 625 | + * @param mixed $arguments |
|
| 626 | + * @param bool $load_only |
|
| 627 | + * @return bool|EE_Addon|object |
|
| 628 | + * @throws EE_Error |
|
| 629 | + * @throws ReflectionException |
|
| 630 | + */ |
|
| 631 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | + { |
|
| 633 | + // retrieve instantiated class |
|
| 634 | + return $this->_load( |
|
| 635 | + $path_to_file, |
|
| 636 | + 'addon', |
|
| 637 | + $class_name, |
|
| 638 | + $type, |
|
| 639 | + $arguments, |
|
| 640 | + false, |
|
| 641 | + true, |
|
| 642 | + $load_only |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * instantiates, caches, and automatically resolves dependencies |
|
| 650 | + * for classes that use a Fully Qualified Class Name. |
|
| 651 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | + * then you need to use one of the existing load_*() methods |
|
| 653 | + * which can resolve the classname and filepath from the passed arguments |
|
| 654 | + * |
|
| 655 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | + * @param bool $from_db some classes are instantiated from the db |
|
| 659 | + * and thus call a different method to instantiate |
|
| 660 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | + * object = class loaded and instantiated successfully. |
|
| 664 | + * bool = fail or success when $load_only is true |
|
| 665 | + * @throws EE_Error |
|
| 666 | + * @throws ReflectionException |
|
| 667 | + */ |
|
| 668 | + public function create( |
|
| 669 | + $class_name = false, |
|
| 670 | + $arguments = array(), |
|
| 671 | + $cache = false, |
|
| 672 | + $from_db = false, |
|
| 673 | + $load_only = false, |
|
| 674 | + $addon = false |
|
| 675 | + ) { |
|
| 676 | + $class_name = ltrim($class_name, '\\'); |
|
| 677 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | + if (! class_exists($class_name)) { |
|
| 679 | + // maybe the class is registered with a preceding \ |
|
| 680 | + $class_name = strpos($class_name, '\\') !== 0 |
|
| 681 | + ? '\\' . $class_name |
|
| 682 | + : $class_name; |
|
| 683 | + // still doesn't exist ? |
|
| 684 | + if (! class_exists($class_name)) { |
|
| 685 | + return null; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 689 | + if ($load_only) { |
|
| 690 | + return true; |
|
| 691 | + } |
|
| 692 | + $addon = $addon |
|
| 693 | + ? 'addon' |
|
| 694 | + : ''; |
|
| 695 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 696 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 697 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 698 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 699 | + // return object if it's already cached |
|
| 700 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 701 | + if ($cached_class !== null) { |
|
| 702 | + return $cached_class; |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + // obtain the loader method from the dependency map |
|
| 706 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 707 | + // instantiate the requested object |
|
| 708 | + if ($loader instanceof Closure) { |
|
| 709 | + $class_obj = $loader($arguments); |
|
| 710 | + } else if ($loader && method_exists($this, $loader)) { |
|
| 711 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 712 | + } else { |
|
| 713 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 714 | + } |
|
| 715 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 716 | + // save it for later... kinda like gum { : $ |
|
| 717 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 718 | + } |
|
| 719 | + $this->_cache_on = true; |
|
| 720 | + return $class_obj; |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * instantiates, caches, and injects dependencies for classes |
|
| 727 | + * |
|
| 728 | + * @param array $file_paths an array of paths to folders to look in |
|
| 729 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 730 | + * @param bool|string $class_name $class name |
|
| 731 | + * @param string $type file type - core? class? helper? model? |
|
| 732 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 733 | + * @param bool $from_db some classes are instantiated from the db |
|
| 734 | + * and thus call a different method to instantiate |
|
| 735 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 736 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 737 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 738 | + * object = class loaded and instantiated successfully. |
|
| 739 | + * bool = fail or success when $load_only is true |
|
| 740 | + * @throws EE_Error |
|
| 741 | + * @throws ReflectionException |
|
| 742 | + */ |
|
| 743 | + protected function _load( |
|
| 744 | + $file_paths = array(), |
|
| 745 | + $class_prefix = 'EE_', |
|
| 746 | + $class_name = false, |
|
| 747 | + $type = 'class', |
|
| 748 | + $arguments = array(), |
|
| 749 | + $from_db = false, |
|
| 750 | + $cache = true, |
|
| 751 | + $load_only = false |
|
| 752 | + ) { |
|
| 753 | + $class_name = ltrim($class_name, '\\'); |
|
| 754 | + // strip php file extension |
|
| 755 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 756 | + // does the class have a prefix ? |
|
| 757 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 758 | + // make sure $class_prefix is uppercase |
|
| 759 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 760 | + // add class prefix ONCE!!! |
|
| 761 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 762 | + } |
|
| 763 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 764 | + $class_exists = class_exists($class_name); |
|
| 765 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 766 | + if ($load_only && $class_exists) { |
|
| 767 | + return true; |
|
| 768 | + } |
|
| 769 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 770 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 771 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 772 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 773 | + // return object if it's already cached |
|
| 774 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 775 | + if ($cached_class !== null) { |
|
| 776 | + return $cached_class; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 780 | + if (! $class_exists) { |
|
| 781 | + // get full path to file |
|
| 782 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 783 | + // load the file |
|
| 784 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 785 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 786 | + if (! $loaded || $load_only) { |
|
| 787 | + // return boolean if only loading, or null if an object was expected |
|
| 788 | + return $load_only |
|
| 789 | + ? $loaded |
|
| 790 | + : null; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + // instantiate the requested object |
|
| 794 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 795 | + if ($this->_cache_on && $cache) { |
|
| 796 | + // save it for later... kinda like gum { : $ |
|
| 797 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 798 | + } |
|
| 799 | + $this->_cache_on = true; |
|
| 800 | + return $class_obj; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * @param string $class_name |
|
| 807 | + * @param string $default have to specify something, but not anything that will conflict |
|
| 808 | + * @return mixed|string |
|
| 809 | + */ |
|
| 810 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 811 | + { |
|
| 812 | + return isset($this->_class_abbreviations[$class_name]) |
|
| 813 | + ? $this->_class_abbreviations[$class_name] |
|
| 814 | + : $default; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * attempts to find a cached version of the requested class |
|
| 819 | + * by looking in the following places: |
|
| 820 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 821 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 822 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 823 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 824 | + * |
|
| 825 | + * @param string $class_name |
|
| 826 | + * @param string $class_prefix |
|
| 827 | + * @return mixed |
|
| 828 | + */ |
|
| 829 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 830 | + { |
|
| 831 | + if ($class_name === 'EE_Registry') { |
|
| 832 | + return $this; |
|
| 833 | + } |
|
| 834 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 835 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 836 | + // check if class has already been loaded, and return it if it has been |
|
| 837 | + if (isset($this->{$class_abbreviation})) { |
|
| 838 | + return $this->{$class_abbreviation}; |
|
| 839 | + } |
|
| 840 | + if (isset ($this->{$class_name})) { |
|
| 841 | + return $this->{$class_name}; |
|
| 842 | + } |
|
| 843 | + if (isset ($this->LIB->{$class_name})) { |
|
| 844 | + return $this->LIB->{$class_name}; |
|
| 845 | + } |
|
| 846 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 847 | + return $this->addons->{$class_name}; |
|
| 848 | + } |
|
| 849 | + return null; |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * removes a cached version of the requested class |
|
| 856 | + * |
|
| 857 | + * @param string $class_name |
|
| 858 | + * @param boolean $addon |
|
| 859 | + * @return boolean |
|
| 860 | + */ |
|
| 861 | + public function clear_cached_class($class_name, $addon = false) |
|
| 862 | + { |
|
| 863 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 864 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 865 | + // check if class has already been loaded, and return it if it has been |
|
| 866 | + if (isset($this->{$class_abbreviation})) { |
|
| 867 | + $this->{$class_abbreviation} = null; |
|
| 868 | + return true; |
|
| 869 | + } |
|
| 870 | + if (isset($this->{$class_name})) { |
|
| 871 | + $this->{$class_name} = null; |
|
| 872 | + return true; |
|
| 873 | + } |
|
| 874 | + if (isset($this->LIB->{$class_name})) { |
|
| 875 | + unset($this->LIB->{$class_name}); |
|
| 876 | + return true; |
|
| 877 | + } |
|
| 878 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 879 | + unset($this->addons->{$class_name}); |
|
| 880 | + return true; |
|
| 881 | + } |
|
| 882 | + return false; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * attempts to find a full valid filepath for the requested class. |
|
| 889 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 890 | + * then returns that path if the target file has been found and is readable |
|
| 891 | + * |
|
| 892 | + * @param string $class_name |
|
| 893 | + * @param string $type |
|
| 894 | + * @param array $file_paths |
|
| 895 | + * @return string | bool |
|
| 896 | + */ |
|
| 897 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 898 | + { |
|
| 899 | + // make sure $file_paths is an array |
|
| 900 | + $file_paths = is_array($file_paths) |
|
| 901 | + ? $file_paths |
|
| 902 | + : array($file_paths); |
|
| 903 | + // cycle thru paths |
|
| 904 | + foreach ($file_paths as $key => $file_path) { |
|
| 905 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 906 | + $file_path = $file_path |
|
| 907 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 908 | + : EE_CLASSES; |
|
| 909 | + // prep file type |
|
| 910 | + $type = ! empty($type) |
|
| 911 | + ? trim($type, '.') . '.' |
|
| 912 | + : ''; |
|
| 913 | + // build full file path |
|
| 914 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 915 | + //does the file exist and can be read ? |
|
| 916 | + if (is_readable($file_paths[$key])) { |
|
| 917 | + return $file_paths[$key]; |
|
| 918 | + } |
|
| 919 | + } |
|
| 920 | + return false; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * basically just performs a require_once() |
|
| 927 | + * but with some error handling |
|
| 928 | + * |
|
| 929 | + * @param string $path |
|
| 930 | + * @param string $class_name |
|
| 931 | + * @param string $type |
|
| 932 | + * @param array $file_paths |
|
| 933 | + * @return bool |
|
| 934 | + * @throws EE_Error |
|
| 935 | + * @throws ReflectionException |
|
| 936 | + */ |
|
| 937 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 938 | + { |
|
| 939 | + // don't give up! you gotta... |
|
| 940 | + try { |
|
| 941 | + //does the file exist and can it be read ? |
|
| 942 | + if (! $path) { |
|
| 943 | + // so sorry, can't find the file |
|
| 944 | + throw new EE_Error ( |
|
| 945 | + sprintf( |
|
| 946 | + esc_html__( |
|
| 947 | + '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', |
|
| 948 | + 'event_espresso' |
|
| 949 | + ), |
|
| 950 | + trim($type, '.'), |
|
| 951 | + $class_name, |
|
| 952 | + '<br />' . implode(',<br />', $file_paths) |
|
| 953 | + ) |
|
| 954 | + ); |
|
| 955 | + } |
|
| 956 | + // get the file |
|
| 957 | + require_once($path); |
|
| 958 | + // if the class isn't already declared somewhere |
|
| 959 | + if (class_exists($class_name, false) === false) { |
|
| 960 | + // so sorry, not a class |
|
| 961 | + throw new EE_Error( |
|
| 962 | + sprintf( |
|
| 963 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 964 | + $type, |
|
| 965 | + $path, |
|
| 966 | + $class_name |
|
| 967 | + ) |
|
| 968 | + ); |
|
| 969 | + } |
|
| 970 | + } catch (EE_Error $e) { |
|
| 971 | + $e->get_error(); |
|
| 972 | + return false; |
|
| 973 | + } |
|
| 974 | + return true; |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * _create_object |
|
| 981 | + * Attempts to instantiate the requested class via any of the |
|
| 982 | + * commonly used instantiation methods employed throughout EE. |
|
| 983 | + * The priority for instantiation is as follows: |
|
| 984 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 985 | + * - model objects via their 'new_instance_from_db' method |
|
| 986 | + * - model objects via their 'new_instance' method |
|
| 987 | + * - "singleton" classes" via their 'instance' method |
|
| 988 | + * - standard instantiable classes via their __constructor |
|
| 989 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 990 | + * then the constructor for the requested class will be examined to determine |
|
| 991 | + * if any dependencies exist, and if they can be injected. |
|
| 992 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 993 | + * |
|
| 994 | + * @param string $class_name |
|
| 995 | + * @param array $arguments |
|
| 996 | + * @param string $type |
|
| 997 | + * @param bool $from_db |
|
| 998 | + * @return null|object |
|
| 999 | + * @throws EE_Error |
|
| 1000 | + * @throws ReflectionException |
|
| 1001 | + */ |
|
| 1002 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1003 | + { |
|
| 1004 | + $class_obj = null; |
|
| 1005 | + $instantiation_mode = '0) none'; |
|
| 1006 | + // don't give up! you gotta... |
|
| 1007 | + try { |
|
| 1008 | + // create reflection |
|
| 1009 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 1010 | + // make sure arguments are an array |
|
| 1011 | + $arguments = is_array($arguments) |
|
| 1012 | + ? $arguments |
|
| 1013 | + : array($arguments); |
|
| 1014 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1015 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1016 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1017 | + ? $arguments |
|
| 1018 | + : array($arguments); |
|
| 1019 | + // attempt to inject dependencies ? |
|
| 1020 | + if ($this->_dependency_map->has($class_name)) { |
|
| 1021 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1022 | + } |
|
| 1023 | + // instantiate the class if possible |
|
| 1024 | + if ($reflector->isAbstract()) { |
|
| 1025 | + // nothing to instantiate, loading file was enough |
|
| 1026 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1027 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1028 | + $class_obj = true; |
|
| 1029 | + } else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1030 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1031 | + $instantiation_mode = '2) no constructor but instantiable'; |
|
| 1032 | + $class_obj = $reflector->newInstance(); |
|
| 1033 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1034 | + $instantiation_mode = '3) new_instance_from_db()'; |
|
| 1035 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1036 | + } else if (method_exists($class_name, 'new_instance')) { |
|
| 1037 | + $instantiation_mode = '4) new_instance()'; |
|
| 1038 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1039 | + } else if (method_exists($class_name, 'instance')) { |
|
| 1040 | + $instantiation_mode = '5) instance()'; |
|
| 1041 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1042 | + } else if ($reflector->isInstantiable()) { |
|
| 1043 | + $instantiation_mode = '6) constructor'; |
|
| 1044 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 1045 | + } else { |
|
| 1046 | + // heh ? something's not right ! |
|
| 1047 | + throw new EE_Error( |
|
| 1048 | + sprintf( |
|
| 1049 | + esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1050 | + $type, |
|
| 1051 | + $class_name |
|
| 1052 | + ) |
|
| 1053 | + ); |
|
| 1054 | + } |
|
| 1055 | + } catch (Exception $e) { |
|
| 1056 | + if (! $e instanceof EE_Error) { |
|
| 1057 | + $e = new EE_Error( |
|
| 1058 | + sprintf( |
|
| 1059 | + esc_html__( |
|
| 1060 | + 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', |
|
| 1061 | + 'event_espresso' |
|
| 1062 | + ), |
|
| 1063 | + $class_name, |
|
| 1064 | + '<br />', |
|
| 1065 | + $e->getMessage(), |
|
| 1066 | + $instantiation_mode |
|
| 1067 | + ) |
|
| 1068 | + ); |
|
| 1069 | + } |
|
| 1070 | + $e->get_error(); |
|
| 1071 | + } |
|
| 1072 | + return $class_obj; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1079 | + * @param array $array |
|
| 1080 | + * @return bool |
|
| 1081 | + */ |
|
| 1082 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1083 | + { |
|
| 1084 | + return ! empty($array) |
|
| 1085 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1086 | + : true; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * getReflectionClass |
|
| 1093 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1094 | + * and returns that instead of creating a new one |
|
| 1095 | + * |
|
| 1096 | + * @param string $class_name |
|
| 1097 | + * @return ReflectionClass |
|
| 1098 | + * @throws ReflectionException |
|
| 1099 | + */ |
|
| 1100 | + public function get_ReflectionClass($class_name) |
|
| 1101 | + { |
|
| 1102 | + if ( |
|
| 1103 | + ! isset($this->_reflectors[$class_name]) |
|
| 1104 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1105 | + ) { |
|
| 1106 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1107 | + } |
|
| 1108 | + return $this->_reflectors[$class_name]; |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * _resolve_dependencies |
|
| 1115 | + * examines the constructor for the requested class to determine |
|
| 1116 | + * if any dependencies exist, and if they can be injected. |
|
| 1117 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1118 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1119 | + * For example: |
|
| 1120 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1121 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1122 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1123 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1124 | + * and the correct classes can be loaded |
|
| 1125 | + * |
|
| 1126 | + * @param ReflectionClass $reflector |
|
| 1127 | + * @param string $class_name |
|
| 1128 | + * @param array $arguments |
|
| 1129 | + * @return array |
|
| 1130 | + * @throws EE_Error |
|
| 1131 | + * @throws ReflectionException |
|
| 1132 | + */ |
|
| 1133 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1134 | + { |
|
| 1135 | + // let's examine the constructor |
|
| 1136 | + $constructor = $reflector->getConstructor(); |
|
| 1137 | + // whu? huh? nothing? |
|
| 1138 | + if (! $constructor) { |
|
| 1139 | + return $arguments; |
|
| 1140 | + } |
|
| 1141 | + // get constructor parameters |
|
| 1142 | + $params = $constructor->getParameters(); |
|
| 1143 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1144 | + $argument_keys = array_keys($arguments); |
|
| 1145 | + // now loop thru all of the constructors expected parameters |
|
| 1146 | + foreach ($params as $index => $param) { |
|
| 1147 | + // is this a dependency for a specific class ? |
|
| 1148 | + $param_class = $param->getClass() |
|
| 1149 | + ? $param->getClass()->name |
|
| 1150 | + : null; |
|
| 1151 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1152 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1153 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1154 | + : $param_class; |
|
| 1155 | + if ( |
|
| 1156 | + // param is not even a class |
|
| 1157 | + $param_class === null |
|
| 1158 | + // and something already exists in the incoming arguments for this param |
|
| 1159 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1160 | + ) { |
|
| 1161 | + // so let's skip this argument and move on to the next |
|
| 1162 | + continue; |
|
| 1163 | + } |
|
| 1164 | + if ( |
|
| 1165 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1166 | + $param_class !== null |
|
| 1167 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1168 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1169 | + ) { |
|
| 1170 | + // skip this argument and move on to the next |
|
| 1171 | + continue; |
|
| 1172 | + } |
|
| 1173 | + if ( |
|
| 1174 | + // parameter is type hinted as a class, and should be injected |
|
| 1175 | + $param_class !== null |
|
| 1176 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1177 | + ) { |
|
| 1178 | + $arguments = $this->_resolve_dependency( |
|
| 1179 | + $class_name, |
|
| 1180 | + $param_class, |
|
| 1181 | + $arguments, |
|
| 1182 | + $index, |
|
| 1183 | + $argument_keys |
|
| 1184 | + ); |
|
| 1185 | + } else { |
|
| 1186 | + try { |
|
| 1187 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1188 | + ? $param->getDefaultValue() |
|
| 1189 | + : null; |
|
| 1190 | + } catch (ReflectionException $e) { |
|
| 1191 | + throw new ReflectionException( |
|
| 1192 | + sprintf( |
|
| 1193 | + esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1194 | + $e->getMessage(), |
|
| 1195 | + $param->getName() |
|
| 1196 | + ) |
|
| 1197 | + ); |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + return $arguments; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * @param string $class_name |
|
| 1208 | + * @param string $param_class |
|
| 1209 | + * @param array $arguments |
|
| 1210 | + * @param mixed $index |
|
| 1211 | + * @param array $argument_keys |
|
| 1212 | + * @return array |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + * @throws ReflectionException |
|
| 1215 | + * @throws InvalidArgumentException |
|
| 1216 | + * @throws InvalidInterfaceException |
|
| 1217 | + * @throws InvalidDataTypeException |
|
| 1218 | + */ |
|
| 1219 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1220 | + { |
|
| 1221 | + $dependency = null; |
|
| 1222 | + // should dependency be loaded from cache ? |
|
| 1223 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1224 | + $class_name, |
|
| 1225 | + $param_class |
|
| 1226 | + ); |
|
| 1227 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1228 | + // we might have a dependency... |
|
| 1229 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1230 | + $cached_class = $cache_on |
|
| 1231 | + ? $this->_get_cached_class($param_class) |
|
| 1232 | + : null; |
|
| 1233 | + // and grab it if it exists |
|
| 1234 | + if ($cached_class instanceof $param_class) { |
|
| 1235 | + $dependency = $cached_class; |
|
| 1236 | + } else if ($param_class !== $class_name) { |
|
| 1237 | + // obtain the loader method from the dependency map |
|
| 1238 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1239 | + // is loader a custom closure ? |
|
| 1240 | + if ($loader instanceof Closure) { |
|
| 1241 | + $dependency = $loader($arguments); |
|
| 1242 | + } else { |
|
| 1243 | + // set the cache on property for the recursive loading call |
|
| 1244 | + $this->_cache_on = $cache_on; |
|
| 1245 | + // if not, then let's try and load it via the registry |
|
| 1246 | + if ($loader && method_exists($this, $loader)) { |
|
| 1247 | + $dependency = $this->{$loader}($param_class); |
|
| 1248 | + } else { |
|
| 1249 | + $dependency = LoaderFactory::getLoader()->load( |
|
| 1250 | + $param_class, |
|
| 1251 | + array(), |
|
| 1252 | + $cache_on |
|
| 1253 | + ); |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + // did we successfully find the correct dependency ? |
|
| 1258 | + if ($dependency instanceof $param_class) { |
|
| 1259 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1260 | + $arguments[$index] = $dependency; |
|
| 1261 | + } |
|
| 1262 | + return $arguments; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * _set_cached_class |
|
| 1269 | + * attempts to cache the instantiated class locally |
|
| 1270 | + * in one of the following places, in the following order: |
|
| 1271 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1272 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1273 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1274 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1275 | + * |
|
| 1276 | + * @param object $class_obj |
|
| 1277 | + * @param string $class_name |
|
| 1278 | + * @param string $class_prefix |
|
| 1279 | + * @param bool $from_db |
|
| 1280 | + * @return void |
|
| 1281 | + */ |
|
| 1282 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1283 | + { |
|
| 1284 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1285 | + return; |
|
| 1286 | + } |
|
| 1287 | + // return newly instantiated class |
|
| 1288 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1289 | + if ($class_abbreviation) { |
|
| 1290 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1291 | + return; |
|
| 1292 | + } |
|
| 1293 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1294 | + if (property_exists($this, $class_name)) { |
|
| 1295 | + $this->{$class_name} = $class_obj; |
|
| 1296 | + return; |
|
| 1297 | + } |
|
| 1298 | + if ($class_prefix === 'addon') { |
|
| 1299 | + $this->addons->{$class_name} = $class_obj; |
|
| 1300 | + return; |
|
| 1301 | + } |
|
| 1302 | + if (! $from_db) { |
|
| 1303 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1311 | + * |
|
| 1312 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1313 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1314 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1315 | + * @param array $arguments |
|
| 1316 | + * @return object |
|
| 1317 | + */ |
|
| 1318 | + public static function factory($classname, $arguments = array()) |
|
| 1319 | + { |
|
| 1320 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1321 | + if ($loader instanceof Closure) { |
|
| 1322 | + return $loader($arguments); |
|
| 1323 | + } |
|
| 1324 | + if (method_exists(self::instance(), $loader)) { |
|
| 1325 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1326 | + } |
|
| 1327 | + return null; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1334 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1335 | + * |
|
| 1336 | + * @param string $name |
|
| 1337 | + * @return EE_Addon |
|
| 1338 | + */ |
|
| 1339 | + public function get_addon_by_name($name) |
|
| 1340 | + { |
|
| 1341 | + foreach ($this->addons as $addon) { |
|
| 1342 | + if ($addon->name() === $name) { |
|
| 1343 | + return $addon; |
|
| 1344 | + } |
|
| 1345 | + } |
|
| 1346 | + return null; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1353 | + * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1354 | + * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1355 | + * EE_Config::instance()->addons->{classname} |
|
| 1356 | + * |
|
| 1357 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1358 | + */ |
|
| 1359 | + public function get_addons_by_name() |
|
| 1360 | + { |
|
| 1361 | + $addons = array(); |
|
| 1362 | + foreach ($this->addons as $addon) { |
|
| 1363 | + $addons[$addon->name()] = $addon; |
|
| 1364 | + } |
|
| 1365 | + return $addons; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1372 | + * a stale copy of it around |
|
| 1373 | + * |
|
| 1374 | + * @param string $model_name |
|
| 1375 | + * @return \EEM_Base |
|
| 1376 | + * @throws \EE_Error |
|
| 1377 | + */ |
|
| 1378 | + public function reset_model($model_name) |
|
| 1379 | + { |
|
| 1380 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1381 | + ? "EEM_{$model_name}" |
|
| 1382 | + : $model_name; |
|
| 1383 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1384 | + return null; |
|
| 1385 | + } |
|
| 1386 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1387 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1388 | + && is_callable( |
|
| 1389 | + array($model_class_name, 'reset') |
|
| 1390 | + )) { |
|
| 1391 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1392 | + } else { |
|
| 1393 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1394 | + } |
|
| 1395 | + return $this->LIB->{$model_class_name}; |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * Resets the registry. |
|
| 1402 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1403 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1404 | + * - $_dependency_map |
|
| 1405 | + * - $_class_abbreviations |
|
| 1406 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1407 | + * - $REQ: Still on the same request so no need to change. |
|
| 1408 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1409 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1410 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1411 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1412 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1413 | + * switch or on the restore. |
|
| 1414 | + * - $modules |
|
| 1415 | + * - $shortcodes |
|
| 1416 | + * - $widgets |
|
| 1417 | + * |
|
| 1418 | + * @param boolean $hard [deprecated] |
|
| 1419 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1420 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1421 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1422 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1423 | + * client |
|
| 1424 | + * code instead can just change the model context to a different blog id if |
|
| 1425 | + * necessary |
|
| 1426 | + * @return EE_Registry |
|
| 1427 | + * @throws EE_Error |
|
| 1428 | + * @throws ReflectionException |
|
| 1429 | + */ |
|
| 1430 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1431 | + { |
|
| 1432 | + $instance = self::instance(); |
|
| 1433 | + $instance->_cache_on = true; |
|
| 1434 | + // reset some "special" classes |
|
| 1435 | + EEH_Activation::reset(); |
|
| 1436 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1437 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1438 | + $instance->CART = null; |
|
| 1439 | + $instance->MRM = null; |
|
| 1440 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1441 | + //messages reset |
|
| 1442 | + EED_Messages::reset(); |
|
| 1443 | + //handle of objects cached on LIB |
|
| 1444 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1445 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1446 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1447 | + unset($instance->{$cache}->{$class_name}); |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | + return $instance; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + |
|
| 1455 | + |
|
| 1456 | + /** |
|
| 1457 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1458 | + * if passed object implements InterminableInterface, then return false, |
|
| 1459 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1460 | + * |
|
| 1461 | + * @param $object |
|
| 1462 | + * @param bool $reset_models |
|
| 1463 | + * @return bool returns true if cached object should be unset |
|
| 1464 | + */ |
|
| 1465 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1466 | + { |
|
| 1467 | + if (! is_object($object)) { |
|
| 1468 | + // don't unset anything that's not an object |
|
| 1469 | + return false; |
|
| 1470 | + } |
|
| 1471 | + if ($object instanceof EED_Module) { |
|
| 1472 | + $object::reset(); |
|
| 1473 | + // don't unset modules |
|
| 1474 | + return false; |
|
| 1475 | + } |
|
| 1476 | + if ($object instanceof ResettableInterface) { |
|
| 1477 | + if ($object instanceof EEM_Base) { |
|
| 1478 | + if ($reset_models) { |
|
| 1479 | + $object->reset(); |
|
| 1480 | + return true; |
|
| 1481 | + } |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1484 | + $object->reset(); |
|
| 1485 | + return true; |
|
| 1486 | + } |
|
| 1487 | + if (! $object instanceof InterminableInterface) { |
|
| 1488 | + return true; |
|
| 1489 | + } |
|
| 1490 | + return false; |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + |
|
| 1494 | + |
|
| 1495 | + /** |
|
| 1496 | + * Gets all the custom post type models defined |
|
| 1497 | + * |
|
| 1498 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1499 | + */ |
|
| 1500 | + public function cpt_models() |
|
| 1501 | + { |
|
| 1502 | + $cpt_models = array(); |
|
| 1503 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1504 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1505 | + $cpt_models[$short_name] = $classname; |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | + return $cpt_models; |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * @return \EE_Config |
|
| 1515 | + */ |
|
| 1516 | + public static function CFG() |
|
| 1517 | + { |
|
| 1518 | + return self::instance()->CFG; |
|
| 1519 | + } |
|
| 1520 | 1520 | |
| 1521 | 1521 | |
| 1522 | 1522 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | public static function instance(EE_Dependency_Map $dependency_map = null) |
| 177 | 177 | { |
| 178 | 178 | // check if class object is instantiated |
| 179 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 179 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
| 180 | 180 | self::$_instance = new self($dependency_map); |
| 181 | 181 | } |
| 182 | 182 | return self::$_instance; |
@@ -266,13 +266,13 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public static function localize_i18n_js_strings() |
| 268 | 268 | { |
| 269 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 269 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
| 270 | 270 | foreach ($i18n_js_strings as $key => $value) { |
| 271 | 271 | if (is_scalar($value)) { |
| 272 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 272 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 275 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | $module_class = get_class($module); |
| 289 | 289 | $this->modules->{$module_class} = $module; |
| 290 | 290 | } else { |
| 291 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 291 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 292 | 292 | $this->load_core('Module_Request_Router'); |
| 293 | 293 | } |
| 294 | 294 | EE_Module_Request_Router::module_factory($module); |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | EE_CORE, |
| 329 | 329 | EE_ADMIN, |
| 330 | 330 | EE_CPTS, |
| 331 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | - EE_CORE . 'capabilities' . DS, |
|
| 333 | - EE_CORE . 'request_stack' . DS, |
|
| 334 | - EE_CORE . 'middleware' . DS, |
|
| 331 | + EE_CORE.'data_migration_scripts'.DS, |
|
| 332 | + EE_CORE.'capabilities'.DS, |
|
| 333 | + EE_CORE.'request_stack'.DS, |
|
| 334 | + EE_CORE.'middleware'.DS, |
|
| 335 | 335 | ) |
| 336 | 336 | ); |
| 337 | 337 | // retrieve instantiated class |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $service_paths = apply_filters( |
| 365 | 365 | 'FHEE__EE_Registry__load_service__service_paths', |
| 366 | 366 | array( |
| 367 | - EE_CORE . 'services' . DS, |
|
| 367 | + EE_CORE.'services'.DS, |
|
| 368 | 368 | ) |
| 369 | 369 | ); |
| 370 | 370 | // retrieve instantiated class |
@@ -490,10 +490,10 @@ discard block |
||
| 490 | 490 | { |
| 491 | 491 | $paths = array( |
| 492 | 492 | EE_LIBRARIES, |
| 493 | - EE_LIBRARIES . 'messages' . DS, |
|
| 494 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 493 | + EE_LIBRARIES.'messages'.DS, |
|
| 494 | + EE_LIBRARIES.'shortcodes'.DS, |
|
| 495 | + EE_LIBRARIES.'qtips'.DS, |
|
| 496 | + EE_LIBRARIES.'payment_methods'.DS, |
|
| 497 | 497 | ); |
| 498 | 498 | // retrieve instantiated class |
| 499 | 499 | return $this->_load( |
@@ -556,10 +556,10 @@ discard block |
||
| 556 | 556 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
| 557 | 557 | { |
| 558 | 558 | $paths = array( |
| 559 | - EE_MODELS . 'fields' . DS, |
|
| 560 | - EE_MODELS . 'helpers' . DS, |
|
| 561 | - EE_MODELS . 'relations' . DS, |
|
| 562 | - EE_MODELS . 'strategies' . DS, |
|
| 559 | + EE_MODELS.'fields'.DS, |
|
| 560 | + EE_MODELS.'helpers'.DS, |
|
| 561 | + EE_MODELS.'relations'.DS, |
|
| 562 | + EE_MODELS.'strategies'.DS, |
|
| 563 | 563 | ); |
| 564 | 564 | // retrieve instantiated class |
| 565 | 565 | return $this->_load( |
@@ -675,13 +675,13 @@ discard block |
||
| 675 | 675 | ) { |
| 676 | 676 | $class_name = ltrim($class_name, '\\'); |
| 677 | 677 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 678 | - if (! class_exists($class_name)) { |
|
| 678 | + if ( ! class_exists($class_name)) { |
|
| 679 | 679 | // maybe the class is registered with a preceding \ |
| 680 | 680 | $class_name = strpos($class_name, '\\') !== 0 |
| 681 | - ? '\\' . $class_name |
|
| 681 | + ? '\\'.$class_name |
|
| 682 | 682 | : $class_name; |
| 683 | 683 | // still doesn't exist ? |
| 684 | - if (! class_exists($class_name)) { |
|
| 684 | + if ( ! class_exists($class_name)) { |
|
| 685 | 685 | return null; |
| 686 | 686 | } |
| 687 | 687 | } |
@@ -754,11 +754,11 @@ discard block |
||
| 754 | 754 | // strip php file extension |
| 755 | 755 | $class_name = str_replace('.php', '', trim($class_name)); |
| 756 | 756 | // does the class have a prefix ? |
| 757 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 757 | + if ( ! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 758 | 758 | // make sure $class_prefix is uppercase |
| 759 | 759 | $class_prefix = strtoupper(trim($class_prefix)); |
| 760 | 760 | // add class prefix ONCE!!! |
| 761 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 761 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
| 762 | 762 | } |
| 763 | 763 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 764 | 764 | $class_exists = class_exists($class_name); |
@@ -777,13 +777,13 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | // if the class doesn't already exist.. then we need to try and find the file and load it |
| 780 | - if (! $class_exists) { |
|
| 780 | + if ( ! $class_exists) { |
|
| 781 | 781 | // get full path to file |
| 782 | 782 | $path = $this->_resolve_path($class_name, $type, $file_paths); |
| 783 | 783 | // load the file |
| 784 | 784 | $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
| 785 | 785 | // if loading failed, or we are only loading a file but NOT instantiating an object |
| 786 | - if (! $loaded || $load_only) { |
|
| 786 | + if ( ! $loaded || $load_only) { |
|
| 787 | 787 | // return boolean if only loading, or null if an object was expected |
| 788 | 788 | return $load_only |
| 789 | 789 | ? $loaded |
@@ -908,10 +908,10 @@ discard block |
||
| 908 | 908 | : EE_CLASSES; |
| 909 | 909 | // prep file type |
| 910 | 910 | $type = ! empty($type) |
| 911 | - ? trim($type, '.') . '.' |
|
| 911 | + ? trim($type, '.').'.' |
|
| 912 | 912 | : ''; |
| 913 | 913 | // build full file path |
| 914 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 914 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
| 915 | 915 | //does the file exist and can be read ? |
| 916 | 916 | if (is_readable($file_paths[$key])) { |
| 917 | 917 | return $file_paths[$key]; |
@@ -939,9 +939,9 @@ discard block |
||
| 939 | 939 | // don't give up! you gotta... |
| 940 | 940 | try { |
| 941 | 941 | //does the file exist and can it be read ? |
| 942 | - if (! $path) { |
|
| 942 | + if ( ! $path) { |
|
| 943 | 943 | // so sorry, can't find the file |
| 944 | - throw new EE_Error ( |
|
| 944 | + throw new EE_Error( |
|
| 945 | 945 | sprintf( |
| 946 | 946 | esc_html__( |
| 947 | 947 | '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', |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | ), |
| 950 | 950 | trim($type, '.'), |
| 951 | 951 | $class_name, |
| 952 | - '<br />' . implode(',<br />', $file_paths) |
|
| 952 | + '<br />'.implode(',<br />', $file_paths) |
|
| 953 | 953 | ) |
| 954 | 954 | ); |
| 955 | 955 | } |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | ); |
| 1054 | 1054 | } |
| 1055 | 1055 | } catch (Exception $e) { |
| 1056 | - if (! $e instanceof EE_Error) { |
|
| 1056 | + if ( ! $e instanceof EE_Error) { |
|
| 1057 | 1057 | $e = new EE_Error( |
| 1058 | 1058 | sprintf( |
| 1059 | 1059 | esc_html__( |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | // let's examine the constructor |
| 1136 | 1136 | $constructor = $reflector->getConstructor(); |
| 1137 | 1137 | // whu? huh? nothing? |
| 1138 | - if (! $constructor) { |
|
| 1138 | + if ( ! $constructor) { |
|
| 1139 | 1139 | return $arguments; |
| 1140 | 1140 | } |
| 1141 | 1141 | // get constructor parameters |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | $this->addons->{$class_name} = $class_obj; |
| 1300 | 1300 | return; |
| 1301 | 1301 | } |
| 1302 | - if (! $from_db) { |
|
| 1302 | + if ( ! $from_db) { |
|
| 1303 | 1303 | $this->LIB->{$class_name} = $class_obj; |
| 1304 | 1304 | } |
| 1305 | 1305 | } |
@@ -1380,7 +1380,7 @@ discard block |
||
| 1380 | 1380 | $model_class_name = strpos($model_name, 'EEM_') !== 0 |
| 1381 | 1381 | ? "EEM_{$model_name}" |
| 1382 | 1382 | : $model_name; |
| 1383 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1383 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1384 | 1384 | return null; |
| 1385 | 1385 | } |
| 1386 | 1386 | //get that model reset it and make sure we nuke the old reference to it |
@@ -1433,7 +1433,7 @@ discard block |
||
| 1433 | 1433 | $instance->_cache_on = true; |
| 1434 | 1434 | // reset some "special" classes |
| 1435 | 1435 | EEH_Activation::reset(); |
| 1436 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1436 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
| 1437 | 1437 | $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
| 1438 | 1438 | $instance->CART = null; |
| 1439 | 1439 | $instance->MRM = null; |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | */ |
| 1465 | 1465 | private static function _reset_and_unset_object($object, $reset_models) |
| 1466 | 1466 | { |
| 1467 | - if (! is_object($object)) { |
|
| 1467 | + if ( ! is_object($object)) { |
|
| 1468 | 1468 | // don't unset anything that's not an object |
| 1469 | 1469 | return false; |
| 1470 | 1470 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | $object->reset(); |
| 1485 | 1485 | return true; |
| 1486 | 1486 | } |
| 1487 | - if (! $object instanceof InterminableInterface) { |
|
| 1487 | + if ( ! $object instanceof InterminableInterface) { |
|
| 1488 | 1488 | return true; |
| 1489 | 1489 | } |
| 1490 | 1490 | return false; |
@@ -22,103 +22,103 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var LoaderDecoratorInterface $new_loader |
|
| 27 | - */ |
|
| 28 | - private $new_loader; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | - */ |
|
| 34 | - private $shared_loader; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Loader constructor. |
|
| 40 | - * |
|
| 41 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | - * @throws InvalidInterfaceException |
|
| 44 | - * @throws InvalidArgumentException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | - { |
|
| 49 | - $this->new_loader = $new_loader; |
|
| 50 | - $this->shared_loader = $shared_loader; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return LoaderDecoratorInterface |
|
| 57 | - */ |
|
| 58 | - public function getNewLoader() |
|
| 59 | - { |
|
| 60 | - return $this->new_loader; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return LoaderDecoratorInterface |
|
| 67 | - */ |
|
| 68 | - public function getSharedLoader() |
|
| 69 | - { |
|
| 70 | - return $this->shared_loader; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $fqcn |
|
| 77 | - * @param array $arguments |
|
| 78 | - * @param bool $shared |
|
| 79 | - * @return mixed |
|
| 80 | - */ |
|
| 81 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | - { |
|
| 83 | - return $shared |
|
| 84 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $fqcn |
|
| 92 | - * @param array $arguments |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function getNew($fqcn, $arguments = array()) |
|
| 96 | - { |
|
| 97 | - return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $fqcn |
|
| 104 | - * @param array $arguments |
|
| 105 | - * @return mixed |
|
| 106 | - */ |
|
| 107 | - public function getShared($fqcn, $arguments = array()) |
|
| 108 | - { |
|
| 109 | - return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * calls reset() on loaders if that method exists |
|
| 116 | - */ |
|
| 117 | - public function reset() |
|
| 118 | - { |
|
| 119 | - $this->new_loader->reset(); |
|
| 120 | - $this->shared_loader->reset(); |
|
| 121 | - } |
|
| 25 | + /** |
|
| 26 | + * @var LoaderDecoratorInterface $new_loader |
|
| 27 | + */ |
|
| 28 | + private $new_loader; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | + */ |
|
| 34 | + private $shared_loader; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Loader constructor. |
|
| 40 | + * |
|
| 41 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | + * @throws InvalidInterfaceException |
|
| 44 | + * @throws InvalidArgumentException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | + { |
|
| 49 | + $this->new_loader = $new_loader; |
|
| 50 | + $this->shared_loader = $shared_loader; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return LoaderDecoratorInterface |
|
| 57 | + */ |
|
| 58 | + public function getNewLoader() |
|
| 59 | + { |
|
| 60 | + return $this->new_loader; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return LoaderDecoratorInterface |
|
| 67 | + */ |
|
| 68 | + public function getSharedLoader() |
|
| 69 | + { |
|
| 70 | + return $this->shared_loader; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $fqcn |
|
| 77 | + * @param array $arguments |
|
| 78 | + * @param bool $shared |
|
| 79 | + * @return mixed |
|
| 80 | + */ |
|
| 81 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | + { |
|
| 83 | + return $shared |
|
| 84 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $fqcn |
|
| 92 | + * @param array $arguments |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function getNew($fqcn, $arguments = array()) |
|
| 96 | + { |
|
| 97 | + return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $fqcn |
|
| 104 | + * @param array $arguments |
|
| 105 | + * @return mixed |
|
| 106 | + */ |
|
| 107 | + public function getShared($fqcn, $arguments = array()) |
|
| 108 | + { |
|
| 109 | + return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * calls reset() on loaders if that method exists |
|
| 116 | + */ |
|
| 117 | + public function reset() |
|
| 118 | + { |
|
| 119 | + $this->new_loader->reset(); |
|
| 120 | + $this->shared_loader->reset(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | // End of file Loader.php |