@@ -375,11 +375,11 @@ 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 |
382 | - * @param int|string $heading_tag |
|
382 | + * @param integer $heading_tag |
|
383 | 383 | * @param bool $die |
384 | 384 | * @param string $margin |
385 | 385 | */ |
@@ -411,6 +411,9 @@ discard block |
||
411 | 411 | } |
412 | 412 | |
413 | 413 | |
414 | + /** |
|
415 | + * @param integer $heading_tag |
|
416 | + */ |
|
414 | 417 | protected static function headingTag($heading_tag) |
415 | 418 | { |
416 | 419 | $heading_tag = absint($heading_tag); |
@@ -532,8 +535,8 @@ discard block |
||
532 | 535 | * @param mixed $var |
533 | 536 | * @param string $var_name |
534 | 537 | * @param string $file |
535 | - * @param int|string $line |
|
536 | - * @param int|string $heading_tag |
|
538 | + * @param integer $line |
|
539 | + * @param integer $heading_tag |
|
537 | 540 | * @param bool $die |
538 | 541 | */ |
539 | 542 | public static function printr( |
@@ -596,7 +599,7 @@ discard block |
||
596 | 599 | |
597 | 600 | /** |
598 | 601 | * @deprecated 4.9.39.rc.034 |
599 | - * @param null $timer_name |
|
602 | + * @param string $timer_name |
|
600 | 603 | */ |
601 | 604 | public function start_timer($timer_name = null) |
602 | 605 | { |
@@ -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,664 +17,664 @@ 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|string $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 = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | - $result .= $is_method |
|
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | - if ($die) { |
|
408 | - die($result); |
|
409 | - } |
|
410 | - echo $result; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - protected static function headingTag($heading_tag) |
|
415 | - { |
|
416 | - $heading_tag = absint($heading_tag); |
|
417 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - protected static function headingSpacer($heading_tag) |
|
422 | - { |
|
423 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | - ? "\n" |
|
425 | - : ''; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - protected static function plainOutput() |
|
430 | - { |
|
431 | - return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $var_name |
|
437 | - * @param string $heading_tag |
|
438 | - * @param string $margin |
|
439 | - * @param int $line |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | - { |
|
444 | - if (EEH_Debug_Tools::plainOutput()) { |
|
445 | - $heading = ''; |
|
446 | - if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | - $heading .= "\n"; |
|
448 | - } |
|
449 | - $heading .= "\n{$line}) {$var_name}"; |
|
450 | - return $heading; |
|
451 | - } |
|
452 | - $margin = "25px 0 0 {$margin}"; |
|
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $heading_tag |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - protected static function headingX($heading_tag = 'h5') |
|
463 | - { |
|
464 | - if (EEH_Debug_Tools::plainOutput()) { |
|
465 | - return ''; |
|
466 | - } |
|
467 | - return '</' . $heading_tag . '>'; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $content |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - protected static function grey_span($content = '') |
|
477 | - { |
|
478 | - if (EEH_Debug_Tools::plainOutput()) { |
|
479 | - return $content; |
|
480 | - } |
|
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $file |
|
488 | - * @param int $line |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - protected static function file_and_line($file, $line, $heading_tag) |
|
492 | - { |
|
493 | - if ($file === '' || $line === '') { |
|
494 | - return ''; |
|
495 | - } |
|
496 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | - if (EEH_Debug_Tools::plainOutput()) { |
|
498 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | - return " ({$file})"; |
|
500 | - } |
|
501 | - return ''; |
|
502 | - } |
|
503 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | - . $file |
|
505 | - . '<br />line no: ' |
|
506 | - . $line |
|
507 | - . '</span>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param string $content |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - protected static function orange_span($content = '') |
|
517 | - { |
|
518 | - if (EEH_Debug_Tools::plainOutput()) { |
|
519 | - return $content; |
|
520 | - } |
|
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param mixed $var |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - protected static function pre_span($var) |
|
531 | - { |
|
532 | - ob_start(); |
|
533 | - var_dump($var); |
|
534 | - $var = ob_get_clean(); |
|
535 | - if (EEH_Debug_Tools::plainOutput()) { |
|
536 | - return $var; |
|
537 | - } |
|
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @param mixed $var |
|
545 | - * @param string $var_name |
|
546 | - * @param string $file |
|
547 | - * @param int|string $line |
|
548 | - * @param int|string $heading_tag |
|
549 | - * @param bool $die |
|
550 | - */ |
|
551 | - public static function printr( |
|
552 | - $var, |
|
553 | - $var_name = '', |
|
554 | - $file = '', |
|
555 | - $line = '', |
|
556 | - $heading_tag = 5, |
|
557 | - $die = false |
|
558 | - ) { |
|
559 | - // return; |
|
560 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | - $margin = is_admin() ? ' 180px' : '0'; |
|
562 | - //$print_r = false; |
|
563 | - if (is_string($var)) { |
|
564 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | - return; |
|
566 | - } |
|
567 | - if (is_object($var)) { |
|
568 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | - //$print_r = true; |
|
570 | - } else if (is_array($var)) { |
|
571 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | - //$print_r = true; |
|
573 | - } else if (is_numeric($var)) { |
|
574 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | - } else if ($var === null) { |
|
576 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | - } |
|
578 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | - EEH_Debug_Tools::pre_span($var) |
|
584 | - ); |
|
585 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | - if ($die) { |
|
588 | - die($result); |
|
589 | - } |
|
590 | - echo $result; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /******************** deprecated ********************/ |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - */ |
|
602 | - public function reset_times() |
|
603 | - { |
|
604 | - Benchmark::resetTimes(); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @deprecated 4.9.39.rc.034 |
|
611 | - * @param null $timer_name |
|
612 | - */ |
|
613 | - public function start_timer($timer_name = null) |
|
614 | - { |
|
615 | - Benchmark::startTimer($timer_name); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @deprecated 4.9.39.rc.034 |
|
622 | - * @param string $timer_name |
|
623 | - */ |
|
624 | - public function stop_timer($timer_name = '') |
|
625 | - { |
|
626 | - Benchmark::stopTimer($timer_name); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * @deprecated 4.9.39.rc.034 |
|
633 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - public function measure_memory($label, $output_now = false) |
|
638 | - { |
|
639 | - Benchmark::measureMemory($label, $output_now); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @deprecated 4.9.39.rc.034 |
|
646 | - * @param int $size |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function convert($size) |
|
650 | - { |
|
651 | - return Benchmark::convert($size); |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @deprecated 4.9.39.rc.034 |
|
658 | - * @param bool $output_now |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function show_times($output_now = true) |
|
662 | - { |
|
663 | - return Benchmark::displayResults($output_now); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * @deprecated 4.9.39.rc.034 |
|
670 | - * @param string $timer_name |
|
671 | - * @param float $total_time |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function format_time($timer_name, $total_time) |
|
675 | - { |
|
676 | - return Benchmark::formatTime($timer_name, $total_time); |
|
677 | - } |
|
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|string $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 = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | + $result .= $is_method |
|
403 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | + if ($die) { |
|
408 | + die($result); |
|
409 | + } |
|
410 | + echo $result; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + protected static function headingTag($heading_tag) |
|
415 | + { |
|
416 | + $heading_tag = absint($heading_tag); |
|
417 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + protected static function headingSpacer($heading_tag) |
|
422 | + { |
|
423 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | + ? "\n" |
|
425 | + : ''; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + protected static function plainOutput() |
|
430 | + { |
|
431 | + return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $var_name |
|
437 | + * @param string $heading_tag |
|
438 | + * @param string $margin |
|
439 | + * @param int $line |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | + { |
|
444 | + if (EEH_Debug_Tools::plainOutput()) { |
|
445 | + $heading = ''; |
|
446 | + if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | + $heading .= "\n"; |
|
448 | + } |
|
449 | + $heading .= "\n{$line}) {$var_name}"; |
|
450 | + return $heading; |
|
451 | + } |
|
452 | + $margin = "25px 0 0 {$margin}"; |
|
453 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $heading_tag |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + protected static function headingX($heading_tag = 'h5') |
|
463 | + { |
|
464 | + if (EEH_Debug_Tools::plainOutput()) { |
|
465 | + return ''; |
|
466 | + } |
|
467 | + return '</' . $heading_tag . '>'; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $content |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + protected static function grey_span($content = '') |
|
477 | + { |
|
478 | + if (EEH_Debug_Tools::plainOutput()) { |
|
479 | + return $content; |
|
480 | + } |
|
481 | + return '<span style="color:#999">' . $content . '</span>'; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $file |
|
488 | + * @param int $line |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + protected static function file_and_line($file, $line, $heading_tag) |
|
492 | + { |
|
493 | + if ($file === '' || $line === '') { |
|
494 | + return ''; |
|
495 | + } |
|
496 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | + if (EEH_Debug_Tools::plainOutput()) { |
|
498 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | + return " ({$file})"; |
|
500 | + } |
|
501 | + return ''; |
|
502 | + } |
|
503 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | + . $file |
|
505 | + . '<br />line no: ' |
|
506 | + . $line |
|
507 | + . '</span>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param string $content |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + protected static function orange_span($content = '') |
|
517 | + { |
|
518 | + if (EEH_Debug_Tools::plainOutput()) { |
|
519 | + return $content; |
|
520 | + } |
|
521 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param mixed $var |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + protected static function pre_span($var) |
|
531 | + { |
|
532 | + ob_start(); |
|
533 | + var_dump($var); |
|
534 | + $var = ob_get_clean(); |
|
535 | + if (EEH_Debug_Tools::plainOutput()) { |
|
536 | + return $var; |
|
537 | + } |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @param mixed $var |
|
545 | + * @param string $var_name |
|
546 | + * @param string $file |
|
547 | + * @param int|string $line |
|
548 | + * @param int|string $heading_tag |
|
549 | + * @param bool $die |
|
550 | + */ |
|
551 | + public static function printr( |
|
552 | + $var, |
|
553 | + $var_name = '', |
|
554 | + $file = '', |
|
555 | + $line = '', |
|
556 | + $heading_tag = 5, |
|
557 | + $die = false |
|
558 | + ) { |
|
559 | + // return; |
|
560 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | + $margin = is_admin() ? ' 180px' : '0'; |
|
562 | + //$print_r = false; |
|
563 | + if (is_string($var)) { |
|
564 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | + return; |
|
566 | + } |
|
567 | + if (is_object($var)) { |
|
568 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | + //$print_r = true; |
|
570 | + } else if (is_array($var)) { |
|
571 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | + //$print_r = true; |
|
573 | + } else if (is_numeric($var)) { |
|
574 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | + } else if ($var === null) { |
|
576 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | + } |
|
578 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | + EEH_Debug_Tools::pre_span($var) |
|
584 | + ); |
|
585 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | + if ($die) { |
|
588 | + die($result); |
|
589 | + } |
|
590 | + echo $result; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /******************** deprecated ********************/ |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + */ |
|
602 | + public function reset_times() |
|
603 | + { |
|
604 | + Benchmark::resetTimes(); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @deprecated 4.9.39.rc.034 |
|
611 | + * @param null $timer_name |
|
612 | + */ |
|
613 | + public function start_timer($timer_name = null) |
|
614 | + { |
|
615 | + Benchmark::startTimer($timer_name); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @deprecated 4.9.39.rc.034 |
|
622 | + * @param string $timer_name |
|
623 | + */ |
|
624 | + public function stop_timer($timer_name = '') |
|
625 | + { |
|
626 | + Benchmark::stopTimer($timer_name); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * @deprecated 4.9.39.rc.034 |
|
633 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + public function measure_memory($label, $output_now = false) |
|
638 | + { |
|
639 | + Benchmark::measureMemory($label, $output_now); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @deprecated 4.9.39.rc.034 |
|
646 | + * @param int $size |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function convert($size) |
|
650 | + { |
|
651 | + return Benchmark::convert($size); |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @deprecated 4.9.39.rc.034 |
|
658 | + * @param bool $output_now |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function show_times($output_now = true) |
|
662 | + { |
|
663 | + return Benchmark::displayResults($output_now); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * @deprecated 4.9.39.rc.034 |
|
670 | + * @param string $timer_name |
|
671 | + * @param float $total_time |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function format_time($timer_name, $total_time) |
|
675 | + { |
|
676 | + return Benchmark::formatTime($timer_name, $total_time); |
|
677 | + } |
|
678 | 678 | |
679 | 679 | |
680 | 680 | |
@@ -687,31 +687,31 @@ discard block |
||
687 | 687 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
688 | 688 | */ |
689 | 689 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
690 | - function dump_wp_query() |
|
691 | - { |
|
692 | - global $wp_query; |
|
693 | - d($wp_query); |
|
694 | - } |
|
690 | + function dump_wp_query() |
|
691 | + { |
|
692 | + global $wp_query; |
|
693 | + d($wp_query); |
|
694 | + } |
|
695 | 695 | } |
696 | 696 | /** |
697 | 697 | * borrowed from Kint Debugger |
698 | 698 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
699 | 699 | */ |
700 | 700 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
701 | - function dump_wp() |
|
702 | - { |
|
703 | - global $wp; |
|
704 | - d($wp); |
|
705 | - } |
|
701 | + function dump_wp() |
|
702 | + { |
|
703 | + global $wp; |
|
704 | + d($wp); |
|
705 | + } |
|
706 | 706 | } |
707 | 707 | /** |
708 | 708 | * borrowed from Kint Debugger |
709 | 709 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
710 | 710 | */ |
711 | 711 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
712 | - function dump_post() |
|
713 | - { |
|
714 | - global $post; |
|
715 | - d($post); |
|
716 | - } |
|
712 | + function dump_post() |
|
713 | + { |
|
714 | + global $post; |
|
715 | + d($post); |
|
716 | + } |
|
717 | 717 | } |
@@ -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 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
401 | 401 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
402 | 402 | $result .= $is_method |
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
403 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
405 | 405 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
406 | 406 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
407 | 407 | if ($die) { |
@@ -443,14 +443,14 @@ discard block |
||
443 | 443 | { |
444 | 444 | if (EEH_Debug_Tools::plainOutput()) { |
445 | 445 | $heading = ''; |
446 | - if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
446 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | 447 | $heading .= "\n"; |
448 | 448 | } |
449 | 449 | $heading .= "\n{$line}) {$var_name}"; |
450 | 450 | return $heading; |
451 | 451 | } |
452 | 452 | $margin = "25px 0 0 {$margin}"; |
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
453 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | if (EEH_Debug_Tools::plainOutput()) { |
465 | 465 | return ''; |
466 | 466 | } |
467 | - return '</' . $heading_tag . '>'; |
|
467 | + return '</'.$heading_tag.'>'; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | if (EEH_Debug_Tools::plainOutput()) { |
479 | 479 | return $content; |
480 | 480 | } |
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
481 | + return '<span style="color:#999">'.$content.'</span>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | if (EEH_Debug_Tools::plainOutput()) { |
519 | 519 | return $content; |
520 | 520 | } |
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
521 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | if (EEH_Debug_Tools::plainOutput()) { |
536 | 536 | return $var; |
537 | 537 | } |
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
580 | 580 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
581 | 581 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
583 | 583 | EEH_Debug_Tools::pre_span($var) |
584 | 584 | ); |
585 | 585 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -28,63 +28,63 @@ |
||
28 | 28 | class DomainFactory |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
33 | - * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
34 | - * constructor. Must at least include the following two value objects: |
|
35 | - * array( |
|
36 | - * EventEspresso\core\domain\values\FilePath $plugin_file |
|
37 | - * EventEspresso\core\domain\values\Version $version |
|
38 | - * ) |
|
39 | - * @return mixed |
|
40 | - * @throws DomainException |
|
41 | - * @throws InvalidArgumentException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - */ |
|
45 | - public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
46 | - { |
|
47 | - if (! isset($arguments[0], $arguments[1])) { |
|
48 | - throw new InvalidArgumentException( |
|
49 | - esc_html__( |
|
50 | - 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
55 | - $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
56 | - if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
57 | - throw new DomainException( |
|
58 | - sprintf( |
|
59 | - esc_html__( |
|
60 | - 'The requested Domain class "%1$s" could not be loaded.', |
|
61 | - 'event_espresso' |
|
62 | - ), |
|
63 | - $domain_fqcn |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - return $domain; |
|
68 | - } |
|
31 | + /** |
|
32 | + * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
33 | + * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
34 | + * constructor. Must at least include the following two value objects: |
|
35 | + * array( |
|
36 | + * EventEspresso\core\domain\values\FilePath $plugin_file |
|
37 | + * EventEspresso\core\domain\values\Version $version |
|
38 | + * ) |
|
39 | + * @return mixed |
|
40 | + * @throws DomainException |
|
41 | + * @throws InvalidArgumentException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + */ |
|
45 | + public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
46 | + { |
|
47 | + if (! isset($arguments[0], $arguments[1])) { |
|
48 | + throw new InvalidArgumentException( |
|
49 | + esc_html__( |
|
50 | + 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | + $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
56 | + if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
57 | + throw new DomainException( |
|
58 | + sprintf( |
|
59 | + esc_html__( |
|
60 | + 'The requested Domain class "%1$s" could not be loaded.', |
|
61 | + 'event_espresso' |
|
62 | + ), |
|
63 | + $domain_fqcn |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + return $domain; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return Domain |
|
73 | - * @throws DomainException |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidFilePathException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - */ |
|
79 | - public static function getEventEspressoCoreDomain() |
|
80 | - { |
|
81 | - $domain = new Domain( |
|
82 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
83 | - Version::fromString(espresso_version()) |
|
84 | - ); |
|
85 | - LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain); |
|
86 | - return $domain; |
|
87 | - } |
|
71 | + /** |
|
72 | + * @return Domain |
|
73 | + * @throws DomainException |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidFilePathException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + */ |
|
79 | + public static function getEventEspressoCoreDomain() |
|
80 | + { |
|
81 | + $domain = new Domain( |
|
82 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
83 | + Version::fromString(espresso_version()) |
|
84 | + ); |
|
85 | + LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain); |
|
86 | + return $domain; |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | |
90 | 90 |
@@ -20,160 +20,160 @@ |
||
20 | 20 | class ClassInterfaceCache |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
25 | - * |
|
26 | - * @var string[][] $interfaces |
|
27 | - */ |
|
28 | - private $interfaces = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @type string[][] $aliases |
|
32 | - */ |
|
33 | - protected $aliases = array(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @param string $fqn |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getFqn($fqn) |
|
41 | - { |
|
42 | - return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $fqn |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function getInterfaces($fqn) |
|
51 | - { |
|
52 | - $fqn = $this->getFqn($fqn); |
|
53 | - // have we already seen this FQCN ? |
|
54 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | - $this->interfaces[ $fqn ] = array(); |
|
56 | - if (class_exists($fqn)) { |
|
57 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | - ? $this->interfaces[ $fqn ] |
|
60 | - : array(); |
|
61 | - } |
|
62 | - } |
|
63 | - return $this->interfaces[ $fqn ]; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $fqn |
|
69 | - * @param string $interface |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function hasInterface($fqn, $interface) |
|
73 | - { |
|
74 | - $fqn = $this->getFqn($fqn); |
|
75 | - $interfaces = $this->getInterfaces($fqn); |
|
76 | - return in_array($interface, $interfaces, true); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * adds an alias for a classname |
|
82 | - * |
|
83 | - * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
84 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
85 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
86 | - */ |
|
87 | - public function addAlias($fqn, $alias, $for_class = '') |
|
88 | - { |
|
89 | - $fqn = $this->getFqn($fqn); |
|
90 | - $alias = $this->getFqn($alias); |
|
91 | - // are we adding an alias for a specific class? |
|
92 | - if ($for_class !== '') { |
|
93 | - // make sure it's set up as an array |
|
94 | - if (! isset($this->aliases[ $for_class ])) { |
|
95 | - $this->aliases[ $for_class ] = array(); |
|
96 | - } |
|
97 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
98 | - return; |
|
99 | - } |
|
100 | - $this->aliases[ $alias ] = $fqn; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * returns TRUE if the provided FQN is an alias |
|
106 | - * |
|
107 | - * @param string $fqn |
|
108 | - * @param string $for_class |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public function isAlias($fqn = '', $for_class = '') |
|
112 | - { |
|
113 | - $fqn = $this->getFqn($fqn); |
|
114 | - if ($this->isAliasForClass($fqn, $for_class)) { |
|
115 | - return true; |
|
116 | - } |
|
117 | - if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
118 | - return true; |
|
119 | - } |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * returns TRUE if the provided FQN is an alias |
|
126 | - * |
|
127 | - * @param string $fqn |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - protected function isDirectAlias($fqn = '') |
|
131 | - { |
|
132 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * returns TRUE if the provided FQN is an alias for the specified class |
|
138 | - * |
|
139 | - * @param string $fqn |
|
140 | - * @param string $for_class |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isAliasForClass($fqn = '', $for_class = '') |
|
144 | - { |
|
145 | - return ( |
|
146 | - $for_class !== '' |
|
147 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
154 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
155 | - * for example: |
|
156 | - * if the following two entries were added to the aliases array: |
|
157 | - * array( |
|
158 | - * 'interface_alias' => 'some\namespace\interface' |
|
159 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
160 | - * ) |
|
161 | - * then one could use Loader::getNew( 'interface_alias' ) |
|
162 | - * to load an instance of 'some\namespace\classname' |
|
163 | - * |
|
164 | - * @param string $alias |
|
165 | - * @param string $for_class |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
169 | - { |
|
170 | - $alias = $this->getFqn($alias); |
|
171 | - if ($this->isAliasForClass($alias, $for_class)) { |
|
172 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
173 | - } |
|
174 | - if ($this->isDirectAlias($alias)) { |
|
175 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
176 | - } |
|
177 | - return $alias; |
|
178 | - } |
|
23 | + /** |
|
24 | + * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
25 | + * |
|
26 | + * @var string[][] $interfaces |
|
27 | + */ |
|
28 | + private $interfaces = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @type string[][] $aliases |
|
32 | + */ |
|
33 | + protected $aliases = array(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @param string $fqn |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getFqn($fqn) |
|
41 | + { |
|
42 | + return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $fqn |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function getInterfaces($fqn) |
|
51 | + { |
|
52 | + $fqn = $this->getFqn($fqn); |
|
53 | + // have we already seen this FQCN ? |
|
54 | + if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | + $this->interfaces[ $fqn ] = array(); |
|
56 | + if (class_exists($fqn)) { |
|
57 | + $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | + $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | + ? $this->interfaces[ $fqn ] |
|
60 | + : array(); |
|
61 | + } |
|
62 | + } |
|
63 | + return $this->interfaces[ $fqn ]; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $fqn |
|
69 | + * @param string $interface |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function hasInterface($fqn, $interface) |
|
73 | + { |
|
74 | + $fqn = $this->getFqn($fqn); |
|
75 | + $interfaces = $this->getInterfaces($fqn); |
|
76 | + return in_array($interface, $interfaces, true); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * adds an alias for a classname |
|
82 | + * |
|
83 | + * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
84 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
85 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
86 | + */ |
|
87 | + public function addAlias($fqn, $alias, $for_class = '') |
|
88 | + { |
|
89 | + $fqn = $this->getFqn($fqn); |
|
90 | + $alias = $this->getFqn($alias); |
|
91 | + // are we adding an alias for a specific class? |
|
92 | + if ($for_class !== '') { |
|
93 | + // make sure it's set up as an array |
|
94 | + if (! isset($this->aliases[ $for_class ])) { |
|
95 | + $this->aliases[ $for_class ] = array(); |
|
96 | + } |
|
97 | + $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
98 | + return; |
|
99 | + } |
|
100 | + $this->aliases[ $alias ] = $fqn; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * returns TRUE if the provided FQN is an alias |
|
106 | + * |
|
107 | + * @param string $fqn |
|
108 | + * @param string $for_class |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public function isAlias($fqn = '', $for_class = '') |
|
112 | + { |
|
113 | + $fqn = $this->getFqn($fqn); |
|
114 | + if ($this->isAliasForClass($fqn, $for_class)) { |
|
115 | + return true; |
|
116 | + } |
|
117 | + if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
118 | + return true; |
|
119 | + } |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * returns TRUE if the provided FQN is an alias |
|
126 | + * |
|
127 | + * @param string $fqn |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + protected function isDirectAlias($fqn = '') |
|
131 | + { |
|
132 | + return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * returns TRUE if the provided FQN is an alias for the specified class |
|
138 | + * |
|
139 | + * @param string $fqn |
|
140 | + * @param string $for_class |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isAliasForClass($fqn = '', $for_class = '') |
|
144 | + { |
|
145 | + return ( |
|
146 | + $for_class !== '' |
|
147 | + && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
154 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
155 | + * for example: |
|
156 | + * if the following two entries were added to the aliases array: |
|
157 | + * array( |
|
158 | + * 'interface_alias' => 'some\namespace\interface' |
|
159 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
160 | + * ) |
|
161 | + * then one could use Loader::getNew( 'interface_alias' ) |
|
162 | + * to load an instance of 'some\namespace\classname' |
|
163 | + * |
|
164 | + * @param string $alias |
|
165 | + * @param string $for_class |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
169 | + { |
|
170 | + $alias = $this->getFqn($alias); |
|
171 | + if ($this->isAliasForClass($alias, $for_class)) { |
|
172 | + return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
173 | + } |
|
174 | + if ($this->isDirectAlias($alias)) { |
|
175 | + return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
176 | + } |
|
177 | + return $alias; |
|
178 | + } |
|
179 | 179 | } |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | { |
52 | 52 | $fqn = $this->getFqn($fqn); |
53 | 53 | // have we already seen this FQCN ? |
54 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | - $this->interfaces[ $fqn ] = array(); |
|
54 | + if ( ! array_key_exists($fqn, $this->interfaces)) { |
|
55 | + $this->interfaces[$fqn] = array(); |
|
56 | 56 | if (class_exists($fqn)) { |
57 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | - ? $this->interfaces[ $fqn ] |
|
57 | + $this->interfaces[$fqn] = class_implements($fqn, false); |
|
58 | + $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false |
|
59 | + ? $this->interfaces[$fqn] |
|
60 | 60 | : array(); |
61 | 61 | } |
62 | 62 | } |
63 | - return $this->interfaces[ $fqn ]; |
|
63 | + return $this->interfaces[$fqn]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | // are we adding an alias for a specific class? |
92 | 92 | if ($for_class !== '') { |
93 | 93 | // make sure it's set up as an array |
94 | - if (! isset($this->aliases[ $for_class ])) { |
|
95 | - $this->aliases[ $for_class ] = array(); |
|
94 | + if ( ! isset($this->aliases[$for_class])) { |
|
95 | + $this->aliases[$for_class] = array(); |
|
96 | 96 | } |
97 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
97 | + $this->aliases[$for_class][$alias] = $fqn; |
|
98 | 98 | return; |
99 | 99 | } |
100 | - $this->aliases[ $alias ] = $fqn; |
|
100 | + $this->aliases[$alias] = $fqn; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function isDirectAlias($fqn = '') |
131 | 131 | { |
132 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
132 | + return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | { |
145 | 145 | return ( |
146 | 146 | $for_class !== '' |
147 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
147 | + && isset($this->aliases[(string) $for_class][(string) $fqn]) |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | { |
170 | 170 | $alias = $this->getFqn($alias); |
171 | 171 | if ($this->isAliasForClass($alias, $for_class)) { |
172 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
172 | + return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class); |
|
173 | 173 | } |
174 | 174 | if ($this->isDirectAlias($alias)) { |
175 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
175 | + return $this->getFqnForAlias($this->aliases[(string) $alias], ''); |
|
176 | 176 | } |
177 | 177 | return $alias; |
178 | 178 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\services\request\RequestInterface; |
9 | 9 | use EventEspresso\core\services\request\ResponseInterface; |
10 | 10 | |
11 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
11 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
12 | 12 | exit('No direct script access allowed'); |
13 | 13 | } |
14 | 14 | |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | ) { |
214 | 214 | $class = trim($class, '\\'); |
215 | 215 | $registered = false; |
216 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
217 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
216 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
217 | + self::$_instance->_dependency_map[$class] = array(); |
|
218 | 218 | } |
219 | 219 | // we need to make sure that any aliases used when registering a dependency |
220 | 220 | // get resolved to the correct class name |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $alias = self::$_instance->getFqnForAlias($dependency); |
223 | 223 | if ( |
224 | 224 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
225 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
225 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
226 | 226 | ) { |
227 | 227 | unset($dependencies[$dependency]); |
228 | 228 | $dependencies[$alias] = $load_source; |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
236 | 236 | // Union is way faster than array_merge() but should be used with caution... |
237 | 237 | // especially with numerically indexed arrays |
238 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
238 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
239 | 239 | // now we need to ensure that the resulting dependencies |
240 | 240 | // array only has the entries that are required for the class |
241 | 241 | // so first count how many dependencies were originally registered for the class |
242 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
242 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
243 | 243 | // if that count is non-zero (meaning dependencies were already registered) |
244 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
244 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
245 | 245 | // then truncate the final array to match that count |
246 | 246 | ? array_slice($dependencies, 0, $dependency_count) |
247 | 247 | // otherwise just take the incoming array because nothing previously existed |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public static function register_class_loader($class_name, $loader = 'load_core') |
261 | 261 | { |
262 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
262 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
263 | 263 | throw new DomainException( |
264 | 264 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
265 | 265 | ); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | ); |
284 | 284 | } |
285 | 285 | $class_name = self::$_instance->getFqnForAlias($class_name); |
286 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
286 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
287 | 287 | self::$_instance->_class_loaders[$class_name] = $loader; |
288 | 288 | return true; |
289 | 289 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | public function class_loader($class_name) |
369 | 369 | { |
370 | 370 | // all legacy models use load_model() |
371 | - if(strpos($class_name, 'EEM_') === 0){ |
|
371 | + if (strpos($class_name, 'EEM_') === 0) { |
|
372 | 372 | return 'load_model'; |
373 | 373 | } |
374 | 374 | $class_name = $this->getFqnForAlias($class_name); |
@@ -766,13 +766,13 @@ discard block |
||
766 | 766 | 'EE_Front_Controller' => 'load_core', |
767 | 767 | 'EE_Module_Request_Router' => 'load_core', |
768 | 768 | 'EE_Registry' => 'load_core', |
769 | - 'EE_Request' => function () use (&$legacy_request) { |
|
769 | + 'EE_Request' => function() use (&$legacy_request) { |
|
770 | 770 | return $legacy_request; |
771 | 771 | }, |
772 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
772 | + 'EventEspresso\core\services\request\Request' => function() use (&$request) { |
|
773 | 773 | return $request; |
774 | 774 | }, |
775 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
775 | + 'EventEspresso\core\services\request\Response' => function() use (&$response) { |
|
776 | 776 | return $response; |
777 | 777 | }, |
778 | 778 | 'EE_Base' => 'load_core', |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
796 | 796 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
797 | 797 | 'EE_Payment_Method_Manager' => 'load_lib', |
798 | - 'EE_Messages_Generator' => function () { |
|
798 | + 'EE_Messages_Generator' => function() { |
|
799 | 799 | return EE_Registry::instance()->load_lib( |
800 | 800 | 'Messages_Generator', |
801 | 801 | array(), |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | false |
804 | 804 | ); |
805 | 805 | }, |
806 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
806 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
807 | 807 | return EE_Registry::instance()->load_lib( |
808 | 808 | 'Messages_Template_Defaults', |
809 | 809 | $arguments, |
@@ -812,34 +812,34 @@ discard block |
||
812 | 812 | ); |
813 | 813 | }, |
814 | 814 | //load_helper |
815 | - 'EEH_Parse_Shortcodes' => function () { |
|
815 | + 'EEH_Parse_Shortcodes' => function() { |
|
816 | 816 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
817 | 817 | return new EEH_Parse_Shortcodes(); |
818 | 818 | } |
819 | 819 | return null; |
820 | 820 | }, |
821 | - 'EE_Template_Config' => function () { |
|
821 | + 'EE_Template_Config' => function() { |
|
822 | 822 | return EE_Config::instance()->template_settings; |
823 | 823 | }, |
824 | - 'EE_Currency_Config' => function () { |
|
824 | + 'EE_Currency_Config' => function() { |
|
825 | 825 | return EE_Config::instance()->currency; |
826 | 826 | }, |
827 | - 'EE_Registration_Config' => function () { |
|
827 | + 'EE_Registration_Config' => function() { |
|
828 | 828 | return EE_Config::instance()->registration; |
829 | 829 | }, |
830 | - 'EE_Core_Config' => function () { |
|
830 | + 'EE_Core_Config' => function() { |
|
831 | 831 | return EE_Config::instance()->core; |
832 | 832 | }, |
833 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
833 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
834 | 834 | return LoaderFactory::getLoader(); |
835 | 835 | }, |
836 | 836 | 'EE_Network_Config' => function() { |
837 | 837 | return EE_Network_Config::instance(); |
838 | 838 | }, |
839 | - 'EE_Config' => function () { |
|
839 | + 'EE_Config' => function() { |
|
840 | 840 | return EE_Config::instance(); |
841 | 841 | }, |
842 | - 'EventEspresso\core\domain\Domain' => function () { |
|
842 | + 'EventEspresso\core\domain\Domain' => function() { |
|
843 | 843 | return DomainFactory::getEventEspressoCoreDomain(); |
844 | 844 | }, |
845 | 845 | ); |
@@ -895,7 +895,7 @@ discard block |
||
895 | 895 | 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
896 | 896 | ); |
897 | 897 | foreach ($aliases as $alias => $fqn) { |
898 | - if(is_array($fqn)) { |
|
898 | + if (is_array($fqn)) { |
|
899 | 899 | foreach ($fqn as $class => $for_class) { |
900 | 900 | $this->class_cache->addAlias($class, $alias, $for_class); |
901 | 901 | } |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | } |
904 | 904 | $this->class_cache->addAlias($fqn, $alias); |
905 | 905 | } |
906 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
906 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
907 | 907 | $this->class_cache->addAlias( |
908 | 908 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
909 | 909 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use EventEspresso\core\services\request\ResponseInterface; |
10 | 10 | |
11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
12 | - exit('No direct script access allowed'); |
|
12 | + exit('No direct script access allowed'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
@@ -26,973 +26,973 @@ discard block |
||
26 | 26 | class EE_Dependency_Map |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * This means that the requested class dependency is not present in the dependency map |
|
31 | - */ |
|
32 | - const not_registered = 0; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
36 | - */ |
|
37 | - const load_new_object = 1; |
|
38 | - |
|
39 | - /** |
|
40 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
41 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
42 | - */ |
|
43 | - const load_from_cache = 2; |
|
44 | - |
|
45 | - /** |
|
46 | - * When registering a dependency, |
|
47 | - * this indicates to keep any existing dependencies that already exist, |
|
48 | - * and simply discard any new dependencies declared in the incoming data |
|
49 | - */ |
|
50 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
51 | - |
|
52 | - /** |
|
53 | - * When registering a dependency, |
|
54 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
55 | - */ |
|
56 | - const OVERWRITE_DEPENDENCIES = 1; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Dependency_Map $_instance |
|
62 | - */ |
|
63 | - protected static $_instance; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var ClassInterfaceCache $class_cache |
|
67 | - */ |
|
68 | - private $class_cache; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type RequestInterface $request |
|
72 | - */ |
|
73 | - protected $request; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type LegacyRequestInterface $legacy_request |
|
77 | - */ |
|
78 | - protected $legacy_request; |
|
79 | - |
|
80 | - /** |
|
81 | - * @type ResponseInterface $response |
|
82 | - */ |
|
83 | - protected $response; |
|
84 | - |
|
85 | - /** |
|
86 | - * @type LoaderInterface $loader |
|
87 | - */ |
|
88 | - protected $loader; |
|
89 | - |
|
90 | - /** |
|
91 | - * @type array $_dependency_map |
|
92 | - */ |
|
93 | - protected $_dependency_map = array(); |
|
94 | - |
|
95 | - /** |
|
96 | - * @type array $_class_loaders |
|
97 | - */ |
|
98 | - protected $_class_loaders = array(); |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * EE_Dependency_Map constructor. |
|
103 | - * |
|
104 | - * @param ClassInterfaceCache $class_cache |
|
105 | - */ |
|
106 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
107 | - { |
|
108 | - $this->class_cache = $class_cache; |
|
109 | - do_action('EE_Dependency_Map____construct', $this); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function initialize() |
|
117 | - { |
|
118 | - $this->_register_core_dependencies(); |
|
119 | - $this->_register_core_class_loaders(); |
|
120 | - $this->_register_core_aliases(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @singleton method used to instantiate class object |
|
126 | - * @param ClassInterfaceCache|null $class_cache |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(ClassInterfaceCache $class_cache = null) { |
|
130 | - // check if class object is instantiated, and instantiated properly |
|
131 | - if ( |
|
132 | - ! self::$_instance instanceof EE_Dependency_Map |
|
133 | - && $class_cache instanceof ClassInterfaceCache |
|
134 | - ) { |
|
135 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
136 | - } |
|
137 | - return self::$_instance; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param RequestInterface $request |
|
143 | - */ |
|
144 | - public function setRequest(RequestInterface $request) |
|
145 | - { |
|
146 | - $this->request = $request; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param LegacyRequestInterface $legacy_request |
|
152 | - */ |
|
153 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
154 | - { |
|
155 | - $this->legacy_request = $legacy_request; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param ResponseInterface $response |
|
161 | - */ |
|
162 | - public function setResponse(ResponseInterface $response) |
|
163 | - { |
|
164 | - $this->response = $response; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param LoaderInterface $loader |
|
171 | - */ |
|
172 | - public function setLoader(LoaderInterface $loader) |
|
173 | - { |
|
174 | - $this->loader = $loader; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param string $class |
|
181 | - * @param array $dependencies |
|
182 | - * @param int $overwrite |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public static function register_dependencies( |
|
186 | - $class, |
|
187 | - array $dependencies, |
|
188 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
189 | - ) { |
|
190 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
197 | - * to the class specified by the first parameter. |
|
198 | - * IMPORTANT !!! |
|
199 | - * The order of elements in the incoming $dependencies array MUST match |
|
200 | - * the order of the constructor parameters for the class in question. |
|
201 | - * This is especially important when overriding any existing dependencies that are registered. |
|
202 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
203 | - * |
|
204 | - * @param string $class |
|
205 | - * @param array $dependencies |
|
206 | - * @param int $overwrite |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function registerDependencies( |
|
210 | - $class, |
|
211 | - array $dependencies, |
|
212 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
213 | - ) { |
|
214 | - $class = trim($class, '\\'); |
|
215 | - $registered = false; |
|
216 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
217 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
218 | - } |
|
219 | - // we need to make sure that any aliases used when registering a dependency |
|
220 | - // get resolved to the correct class name |
|
221 | - foreach ($dependencies as $dependency => $load_source) { |
|
222 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
223 | - if ( |
|
224 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
225 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
226 | - ) { |
|
227 | - unset($dependencies[$dependency]); |
|
228 | - $dependencies[$alias] = $load_source; |
|
229 | - $registered = true; |
|
230 | - } |
|
231 | - } |
|
232 | - // now add our two lists of dependencies together. |
|
233 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
234 | - // so $dependencies is NOT overwritten because it is listed first |
|
235 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
236 | - // Union is way faster than array_merge() but should be used with caution... |
|
237 | - // especially with numerically indexed arrays |
|
238 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
239 | - // now we need to ensure that the resulting dependencies |
|
240 | - // array only has the entries that are required for the class |
|
241 | - // so first count how many dependencies were originally registered for the class |
|
242 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
243 | - // if that count is non-zero (meaning dependencies were already registered) |
|
244 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
245 | - // then truncate the final array to match that count |
|
246 | - ? array_slice($dependencies, 0, $dependency_count) |
|
247 | - // otherwise just take the incoming array because nothing previously existed |
|
248 | - : $dependencies; |
|
249 | - return $registered; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $class_name |
|
256 | - * @param string $loader |
|
257 | - * @return bool |
|
258 | - * @throws DomainException |
|
259 | - */ |
|
260 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
261 | - { |
|
262 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
263 | - throw new DomainException( |
|
264 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
265 | - ); |
|
266 | - } |
|
267 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
268 | - if ( |
|
269 | - ! is_callable($loader) |
|
270 | - && ( |
|
271 | - strpos($loader, 'load_') !== 0 |
|
272 | - || ! method_exists('EE_Registry', $loader) |
|
273 | - ) |
|
274 | - ) { |
|
275 | - throw new DomainException( |
|
276 | - sprintf( |
|
277 | - esc_html__( |
|
278 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - $loader |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
286 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
287 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
288 | - return true; |
|
289 | - } |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return array |
|
297 | - */ |
|
298 | - public function dependency_map() |
|
299 | - { |
|
300 | - return $this->_dependency_map; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @return boolean |
|
310 | - */ |
|
311 | - public function has($class_name = '') |
|
312 | - { |
|
313 | - // all legacy models have the same dependencies |
|
314 | - if (strpos($class_name, 'EEM_') === 0) { |
|
315 | - $class_name = 'LEGACY_MODELS'; |
|
316 | - } |
|
317 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
324 | - * |
|
325 | - * @param string $class_name |
|
326 | - * @param string $dependency |
|
327 | - * @return bool |
|
328 | - */ |
|
329 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
330 | - { |
|
331 | - // all legacy models have the same dependencies |
|
332 | - if (strpos($class_name, 'EEM_') === 0) { |
|
333 | - $class_name = 'LEGACY_MODELS'; |
|
334 | - } |
|
335 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
336 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
337 | - ? true |
|
338 | - : false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
345 | - * |
|
346 | - * @param string $class_name |
|
347 | - * @param string $dependency |
|
348 | - * @return int |
|
349 | - */ |
|
350 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
351 | - { |
|
352 | - // all legacy models have the same dependencies |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - $class_name = 'LEGACY_MODELS'; |
|
355 | - } |
|
356 | - $dependency = $this->getFqnForAlias($dependency); |
|
357 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
358 | - ? $this->_dependency_map[$class_name][$dependency] |
|
359 | - : EE_Dependency_Map::not_registered; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $class_name |
|
366 | - * @return string | Closure |
|
367 | - */ |
|
368 | - public function class_loader($class_name) |
|
369 | - { |
|
370 | - // all legacy models use load_model() |
|
371 | - if(strpos($class_name, 'EEM_') === 0){ |
|
372 | - return 'load_model'; |
|
373 | - } |
|
374 | - $class_name = $this->getFqnForAlias($class_name); |
|
375 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @return array |
|
382 | - */ |
|
383 | - public function class_loaders() |
|
384 | - { |
|
385 | - return $this->_class_loaders; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * adds an alias for a classname |
|
392 | - * |
|
393 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | - */ |
|
397 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
398 | - { |
|
399 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
406 | - * WHY? |
|
407 | - * Because if a class is type hinting for a concretion, |
|
408 | - * then why would we need to find another class to supply it? |
|
409 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
410 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
411 | - * Don't go looking for some substitute. |
|
412 | - * Whereas if a class is type hinting for an interface... |
|
413 | - * then we need to find an actual class to use. |
|
414 | - * So the interface IS the alias for some other FQN, |
|
415 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
416 | - * represents some other class. |
|
417 | - * |
|
418 | - * @param string $fqn |
|
419 | - * @param string $for_class |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - public function isAlias($fqn = '', $for_class = '') |
|
423 | - { |
|
424 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | - * for example: |
|
433 | - * if the following two entries were added to the _aliases array: |
|
434 | - * array( |
|
435 | - * 'interface_alias' => 'some\namespace\interface' |
|
436 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | - * ) |
|
438 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | - * to load an instance of 'some\namespace\classname' |
|
440 | - * |
|
441 | - * @param string $alias |
|
442 | - * @param string $for_class |
|
443 | - * @return string |
|
444 | - */ |
|
445 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | - { |
|
447 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
454 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
455 | - * This is done by using the following class constants: |
|
456 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
457 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
458 | - */ |
|
459 | - protected function _register_core_dependencies() |
|
460 | - { |
|
461 | - $this->_dependency_map = array( |
|
462 | - 'EE_Request_Handler' => array( |
|
463 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_System' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
469 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
470 | - ), |
|
471 | - 'EE_Session' => array( |
|
472 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
473 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
474 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_Cart' => array( |
|
478 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Front_Controller' => array( |
|
481 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
482 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_Messenger_Collection_Loader' => array( |
|
486 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
487 | - ), |
|
488 | - 'EE_Message_Type_Collection_Loader' => array( |
|
489 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - ), |
|
491 | - 'EE_Message_Resource_Manager' => array( |
|
492 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
493 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Message_Factory' => array( |
|
497 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EE_messages' => array( |
|
500 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EE_Messages_Generator' => array( |
|
503 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
504 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
505 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
506 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EE_Messages_Processor' => array( |
|
509 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EE_Messages_Queue' => array( |
|
512 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
513 | - ), |
|
514 | - 'EE_Messages_Template_Defaults' => array( |
|
515 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
516 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
517 | - ), |
|
518 | - 'EE_Message_To_Generate_From_Request' => array( |
|
519 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
520 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
523 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
526 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
527 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
530 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
533 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
534 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
537 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
540 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
543 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
546 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
555 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
558 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
561 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
564 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
567 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
570 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | - ), |
|
572 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
573 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_Data_Migration_Class_Base' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_1_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_2_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_3_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EE_DMS_Core_4_4_0' => array( |
|
595 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EE_DMS_Core_4_5_0' => array( |
|
599 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EE_DMS_Core_4_6_0' => array( |
|
603 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EE_DMS_Core_4_7_0' => array( |
|
607 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | - ), |
|
610 | - 'EE_DMS_Core_4_8_0' => array( |
|
611 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
612 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
613 | - ), |
|
614 | - 'EE_DMS_Core_4_9_0' => array( |
|
615 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | - ), |
|
618 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
619 | - array(), |
|
620 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
621 | - ), |
|
622 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
623 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
626 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
638 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
641 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
644 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
645 | - ), |
|
646 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
647 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
648 | - ), |
|
649 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
650 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
651 | - ), |
|
652 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
653 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
654 | - ), |
|
655 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
656 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
658 | - ), |
|
659 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
660 | - null, |
|
661 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
662 | - ), |
|
663 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
664 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
665 | - ), |
|
666 | - 'LEGACY_MODELS' => array( |
|
667 | - null, |
|
668 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
669 | - ), |
|
670 | - 'EE_Module_Request_Router' => array( |
|
671 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EE_Registration_Processor' => array( |
|
674 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
675 | - ), |
|
676 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
677 | - null, |
|
678 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
680 | - ), |
|
681 | - 'EventEspresso\core\services\editor\EditorBlockRegistrationManager' => array( |
|
682 | - 'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache, |
|
683 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
685 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
686 | - ), |
|
687 | - 'EE_Admin_Transactions_List_Table' => array( |
|
688 | - null, |
|
689 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
690 | - ), |
|
691 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
692 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
694 | - ), |
|
695 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
696 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
697 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
698 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
699 | - ), |
|
700 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
701 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
702 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
703 | - ), |
|
704 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
705 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
706 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
707 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
708 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
709 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
711 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
712 | - ), |
|
713 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
714 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
715 | - ), |
|
716 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
717 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
718 | - ), |
|
719 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
720 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
721 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
722 | - ), |
|
723 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
724 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
725 | - ), |
|
726 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
727 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
728 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
729 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
731 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
732 | - ), |
|
733 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
734 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
735 | - ), |
|
736 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
737 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
739 | - ), |
|
740 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
741 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
742 | - ), |
|
743 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
744 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
745 | - ), |
|
746 | - 'EE_CPT_Strategy' => array( |
|
747 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
748 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
749 | - ), |
|
750 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
751 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
752 | - ), |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * Registers how core classes are loaded. |
|
759 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
760 | - * 'EE_Request_Handler' => 'load_core' |
|
761 | - * 'EE_Messages_Queue' => 'load_lib' |
|
762 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
763 | - * or, if greater control is required, by providing a custom closure. For example: |
|
764 | - * 'Some_Class' => function () { |
|
765 | - * return new Some_Class(); |
|
766 | - * }, |
|
767 | - * This is required for instantiating dependencies |
|
768 | - * where an interface has been type hinted in a class constructor. For example: |
|
769 | - * 'Required_Interface' => function () { |
|
770 | - * return new A_Class_That_Implements_Required_Interface(); |
|
771 | - * }, |
|
772 | - * |
|
773 | - */ |
|
774 | - protected function _register_core_class_loaders() |
|
775 | - { |
|
776 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
777 | - //be used in a closure. |
|
778 | - $request = &$this->request; |
|
779 | - $response = &$this->response; |
|
780 | - $legacy_request = &$this->legacy_request; |
|
781 | - // $loader = &$this->loader; |
|
782 | - $this->_class_loaders = array( |
|
783 | - //load_core |
|
784 | - 'EE_Capabilities' => 'load_core', |
|
785 | - 'EE_Encryption' => 'load_core', |
|
786 | - 'EE_Front_Controller' => 'load_core', |
|
787 | - 'EE_Module_Request_Router' => 'load_core', |
|
788 | - 'EE_Registry' => 'load_core', |
|
789 | - 'EE_Request' => function () use (&$legacy_request) { |
|
790 | - return $legacy_request; |
|
791 | - }, |
|
792 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
793 | - return $request; |
|
794 | - }, |
|
795 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
796 | - return $response; |
|
797 | - }, |
|
798 | - 'EE_Base' => 'load_core', |
|
799 | - 'EE_Request_Handler' => 'load_core', |
|
800 | - 'EE_Session' => 'load_core', |
|
801 | - 'EE_Cron_Tasks' => 'load_core', |
|
802 | - 'EE_System' => 'load_core', |
|
803 | - 'EE_Maintenance_Mode' => 'load_core', |
|
804 | - 'EE_Register_CPTs' => 'load_core', |
|
805 | - 'EE_Admin' => 'load_core', |
|
806 | - 'EE_CPT_Strategy' => 'load_core', |
|
807 | - //load_lib |
|
808 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
809 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
810 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
811 | - 'EE_Messenger_Collection' => 'load_lib', |
|
812 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
813 | - 'EE_Messages_Processor' => 'load_lib', |
|
814 | - 'EE_Message_Repository' => 'load_lib', |
|
815 | - 'EE_Messages_Queue' => 'load_lib', |
|
816 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
817 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
818 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
819 | - 'EE_Messages_Generator' => function () { |
|
820 | - return EE_Registry::instance()->load_lib( |
|
821 | - 'Messages_Generator', |
|
822 | - array(), |
|
823 | - false, |
|
824 | - false |
|
825 | - ); |
|
826 | - }, |
|
827 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
828 | - return EE_Registry::instance()->load_lib( |
|
829 | - 'Messages_Template_Defaults', |
|
830 | - $arguments, |
|
831 | - false, |
|
832 | - false |
|
833 | - ); |
|
834 | - }, |
|
835 | - //load_helper |
|
836 | - 'EEH_Parse_Shortcodes' => function () { |
|
837 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
838 | - return new EEH_Parse_Shortcodes(); |
|
839 | - } |
|
840 | - return null; |
|
841 | - }, |
|
842 | - 'EE_Template_Config' => function () { |
|
843 | - return EE_Config::instance()->template_settings; |
|
844 | - }, |
|
845 | - 'EE_Currency_Config' => function () { |
|
846 | - return EE_Config::instance()->currency; |
|
847 | - }, |
|
848 | - 'EE_Registration_Config' => function () { |
|
849 | - return EE_Config::instance()->registration; |
|
850 | - }, |
|
851 | - 'EE_Core_Config' => function () { |
|
852 | - return EE_Config::instance()->core; |
|
853 | - }, |
|
854 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
855 | - return LoaderFactory::getLoader(); |
|
856 | - }, |
|
857 | - 'EE_Network_Config' => function() { |
|
858 | - return EE_Network_Config::instance(); |
|
859 | - }, |
|
860 | - 'EE_Config' => function () { |
|
861 | - return EE_Config::instance(); |
|
862 | - }, |
|
863 | - 'EventEspresso\core\domain\Domain' => function () { |
|
864 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
865 | - }, |
|
866 | - ); |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - |
|
871 | - |
|
872 | - /** |
|
873 | - * can be used for supplying alternate names for classes, |
|
874 | - * or for connecting interface names to instantiable classes |
|
875 | - */ |
|
876 | - protected function _register_core_aliases() |
|
877 | - { |
|
878 | - $aliases = array( |
|
879 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
880 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
881 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
882 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
883 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
884 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
885 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
886 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
887 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
888 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
889 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
890 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
891 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
892 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
893 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
894 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
895 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
896 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
897 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
898 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
899 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
900 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
901 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
902 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
903 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
904 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
905 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
906 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
907 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
908 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
909 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
910 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
911 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
912 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
913 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
914 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
915 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
916 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
917 | - ); |
|
918 | - foreach ($aliases as $alias => $fqn) { |
|
919 | - if(is_array($fqn)) { |
|
920 | - foreach ($fqn as $class => $for_class) { |
|
921 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
922 | - } |
|
923 | - continue; |
|
924 | - } |
|
925 | - $this->class_cache->addAlias($fqn, $alias); |
|
926 | - } |
|
927 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
928 | - $this->class_cache->addAlias( |
|
929 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
930 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
931 | - ); |
|
932 | - } |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
939 | - * request Primarily used by unit tests. |
|
940 | - */ |
|
941 | - public function reset() |
|
942 | - { |
|
943 | - $this->_register_core_class_loaders(); |
|
944 | - $this->_register_core_dependencies(); |
|
945 | - } |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
950 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
951 | - * WHY? |
|
952 | - * Because if a class is type hinting for a concretion, |
|
953 | - * then why would we need to find another class to supply it? |
|
954 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
955 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
956 | - * Don't go looking for some substitute. |
|
957 | - * Whereas if a class is type hinting for an interface... |
|
958 | - * then we need to find an actual class to use. |
|
959 | - * So the interface IS the alias for some other FQN, |
|
960 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
961 | - * represents some other class. |
|
962 | - * |
|
963 | - * @deprecated $VID:$ |
|
964 | - * @param string $fqn |
|
965 | - * @param string $for_class |
|
966 | - * @return bool |
|
967 | - */ |
|
968 | - public function has_alias($fqn = '', $for_class = '') |
|
969 | - { |
|
970 | - return $this->isAlias($fqn, $for_class); |
|
971 | - } |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
976 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
977 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
978 | - * for example: |
|
979 | - * if the following two entries were added to the _aliases array: |
|
980 | - * array( |
|
981 | - * 'interface_alias' => 'some\namespace\interface' |
|
982 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
983 | - * ) |
|
984 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
985 | - * to load an instance of 'some\namespace\classname' |
|
986 | - * |
|
987 | - * @deprecated $VID:$ |
|
988 | - * @param string $alias |
|
989 | - * @param string $for_class |
|
990 | - * @return string |
|
991 | - */ |
|
992 | - public function get_alias($alias = '', $for_class = '') |
|
993 | - { |
|
994 | - return $this->getFqnForAlias($alias, $for_class); |
|
995 | - } |
|
29 | + /** |
|
30 | + * This means that the requested class dependency is not present in the dependency map |
|
31 | + */ |
|
32 | + const not_registered = 0; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
36 | + */ |
|
37 | + const load_new_object = 1; |
|
38 | + |
|
39 | + /** |
|
40 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
41 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
42 | + */ |
|
43 | + const load_from_cache = 2; |
|
44 | + |
|
45 | + /** |
|
46 | + * When registering a dependency, |
|
47 | + * this indicates to keep any existing dependencies that already exist, |
|
48 | + * and simply discard any new dependencies declared in the incoming data |
|
49 | + */ |
|
50 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
51 | + |
|
52 | + /** |
|
53 | + * When registering a dependency, |
|
54 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
55 | + */ |
|
56 | + const OVERWRITE_DEPENDENCIES = 1; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Dependency_Map $_instance |
|
62 | + */ |
|
63 | + protected static $_instance; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var ClassInterfaceCache $class_cache |
|
67 | + */ |
|
68 | + private $class_cache; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type RequestInterface $request |
|
72 | + */ |
|
73 | + protected $request; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type LegacyRequestInterface $legacy_request |
|
77 | + */ |
|
78 | + protected $legacy_request; |
|
79 | + |
|
80 | + /** |
|
81 | + * @type ResponseInterface $response |
|
82 | + */ |
|
83 | + protected $response; |
|
84 | + |
|
85 | + /** |
|
86 | + * @type LoaderInterface $loader |
|
87 | + */ |
|
88 | + protected $loader; |
|
89 | + |
|
90 | + /** |
|
91 | + * @type array $_dependency_map |
|
92 | + */ |
|
93 | + protected $_dependency_map = array(); |
|
94 | + |
|
95 | + /** |
|
96 | + * @type array $_class_loaders |
|
97 | + */ |
|
98 | + protected $_class_loaders = array(); |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * EE_Dependency_Map constructor. |
|
103 | + * |
|
104 | + * @param ClassInterfaceCache $class_cache |
|
105 | + */ |
|
106 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
107 | + { |
|
108 | + $this->class_cache = $class_cache; |
|
109 | + do_action('EE_Dependency_Map____construct', $this); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function initialize() |
|
117 | + { |
|
118 | + $this->_register_core_dependencies(); |
|
119 | + $this->_register_core_class_loaders(); |
|
120 | + $this->_register_core_aliases(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @singleton method used to instantiate class object |
|
126 | + * @param ClassInterfaceCache|null $class_cache |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(ClassInterfaceCache $class_cache = null) { |
|
130 | + // check if class object is instantiated, and instantiated properly |
|
131 | + if ( |
|
132 | + ! self::$_instance instanceof EE_Dependency_Map |
|
133 | + && $class_cache instanceof ClassInterfaceCache |
|
134 | + ) { |
|
135 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
136 | + } |
|
137 | + return self::$_instance; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param RequestInterface $request |
|
143 | + */ |
|
144 | + public function setRequest(RequestInterface $request) |
|
145 | + { |
|
146 | + $this->request = $request; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param LegacyRequestInterface $legacy_request |
|
152 | + */ |
|
153 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
154 | + { |
|
155 | + $this->legacy_request = $legacy_request; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param ResponseInterface $response |
|
161 | + */ |
|
162 | + public function setResponse(ResponseInterface $response) |
|
163 | + { |
|
164 | + $this->response = $response; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param LoaderInterface $loader |
|
171 | + */ |
|
172 | + public function setLoader(LoaderInterface $loader) |
|
173 | + { |
|
174 | + $this->loader = $loader; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param string $class |
|
181 | + * @param array $dependencies |
|
182 | + * @param int $overwrite |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public static function register_dependencies( |
|
186 | + $class, |
|
187 | + array $dependencies, |
|
188 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
189 | + ) { |
|
190 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
197 | + * to the class specified by the first parameter. |
|
198 | + * IMPORTANT !!! |
|
199 | + * The order of elements in the incoming $dependencies array MUST match |
|
200 | + * the order of the constructor parameters for the class in question. |
|
201 | + * This is especially important when overriding any existing dependencies that are registered. |
|
202 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
203 | + * |
|
204 | + * @param string $class |
|
205 | + * @param array $dependencies |
|
206 | + * @param int $overwrite |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function registerDependencies( |
|
210 | + $class, |
|
211 | + array $dependencies, |
|
212 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
213 | + ) { |
|
214 | + $class = trim($class, '\\'); |
|
215 | + $registered = false; |
|
216 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
217 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
218 | + } |
|
219 | + // we need to make sure that any aliases used when registering a dependency |
|
220 | + // get resolved to the correct class name |
|
221 | + foreach ($dependencies as $dependency => $load_source) { |
|
222 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
223 | + if ( |
|
224 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
225 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
226 | + ) { |
|
227 | + unset($dependencies[$dependency]); |
|
228 | + $dependencies[$alias] = $load_source; |
|
229 | + $registered = true; |
|
230 | + } |
|
231 | + } |
|
232 | + // now add our two lists of dependencies together. |
|
233 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
234 | + // so $dependencies is NOT overwritten because it is listed first |
|
235 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
236 | + // Union is way faster than array_merge() but should be used with caution... |
|
237 | + // especially with numerically indexed arrays |
|
238 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
239 | + // now we need to ensure that the resulting dependencies |
|
240 | + // array only has the entries that are required for the class |
|
241 | + // so first count how many dependencies were originally registered for the class |
|
242 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
243 | + // if that count is non-zero (meaning dependencies were already registered) |
|
244 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
245 | + // then truncate the final array to match that count |
|
246 | + ? array_slice($dependencies, 0, $dependency_count) |
|
247 | + // otherwise just take the incoming array because nothing previously existed |
|
248 | + : $dependencies; |
|
249 | + return $registered; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $class_name |
|
256 | + * @param string $loader |
|
257 | + * @return bool |
|
258 | + * @throws DomainException |
|
259 | + */ |
|
260 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
261 | + { |
|
262 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
263 | + throw new DomainException( |
|
264 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
265 | + ); |
|
266 | + } |
|
267 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
268 | + if ( |
|
269 | + ! is_callable($loader) |
|
270 | + && ( |
|
271 | + strpos($loader, 'load_') !== 0 |
|
272 | + || ! method_exists('EE_Registry', $loader) |
|
273 | + ) |
|
274 | + ) { |
|
275 | + throw new DomainException( |
|
276 | + sprintf( |
|
277 | + esc_html__( |
|
278 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + $loader |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
286 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
287 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
288 | + return true; |
|
289 | + } |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return array |
|
297 | + */ |
|
298 | + public function dependency_map() |
|
299 | + { |
|
300 | + return $this->_dependency_map; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @return boolean |
|
310 | + */ |
|
311 | + public function has($class_name = '') |
|
312 | + { |
|
313 | + // all legacy models have the same dependencies |
|
314 | + if (strpos($class_name, 'EEM_') === 0) { |
|
315 | + $class_name = 'LEGACY_MODELS'; |
|
316 | + } |
|
317 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
324 | + * |
|
325 | + * @param string $class_name |
|
326 | + * @param string $dependency |
|
327 | + * @return bool |
|
328 | + */ |
|
329 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
330 | + { |
|
331 | + // all legacy models have the same dependencies |
|
332 | + if (strpos($class_name, 'EEM_') === 0) { |
|
333 | + $class_name = 'LEGACY_MODELS'; |
|
334 | + } |
|
335 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
336 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
337 | + ? true |
|
338 | + : false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
345 | + * |
|
346 | + * @param string $class_name |
|
347 | + * @param string $dependency |
|
348 | + * @return int |
|
349 | + */ |
|
350 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
351 | + { |
|
352 | + // all legacy models have the same dependencies |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + $class_name = 'LEGACY_MODELS'; |
|
355 | + } |
|
356 | + $dependency = $this->getFqnForAlias($dependency); |
|
357 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
358 | + ? $this->_dependency_map[$class_name][$dependency] |
|
359 | + : EE_Dependency_Map::not_registered; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $class_name |
|
366 | + * @return string | Closure |
|
367 | + */ |
|
368 | + public function class_loader($class_name) |
|
369 | + { |
|
370 | + // all legacy models use load_model() |
|
371 | + if(strpos($class_name, 'EEM_') === 0){ |
|
372 | + return 'load_model'; |
|
373 | + } |
|
374 | + $class_name = $this->getFqnForAlias($class_name); |
|
375 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @return array |
|
382 | + */ |
|
383 | + public function class_loaders() |
|
384 | + { |
|
385 | + return $this->_class_loaders; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * adds an alias for a classname |
|
392 | + * |
|
393 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | + */ |
|
397 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
398 | + { |
|
399 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
406 | + * WHY? |
|
407 | + * Because if a class is type hinting for a concretion, |
|
408 | + * then why would we need to find another class to supply it? |
|
409 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
410 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
411 | + * Don't go looking for some substitute. |
|
412 | + * Whereas if a class is type hinting for an interface... |
|
413 | + * then we need to find an actual class to use. |
|
414 | + * So the interface IS the alias for some other FQN, |
|
415 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
416 | + * represents some other class. |
|
417 | + * |
|
418 | + * @param string $fqn |
|
419 | + * @param string $for_class |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + public function isAlias($fqn = '', $for_class = '') |
|
423 | + { |
|
424 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | + * for example: |
|
433 | + * if the following two entries were added to the _aliases array: |
|
434 | + * array( |
|
435 | + * 'interface_alias' => 'some\namespace\interface' |
|
436 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | + * ) |
|
438 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | + * to load an instance of 'some\namespace\classname' |
|
440 | + * |
|
441 | + * @param string $alias |
|
442 | + * @param string $for_class |
|
443 | + * @return string |
|
444 | + */ |
|
445 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | + { |
|
447 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
454 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
455 | + * This is done by using the following class constants: |
|
456 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
457 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
458 | + */ |
|
459 | + protected function _register_core_dependencies() |
|
460 | + { |
|
461 | + $this->_dependency_map = array( |
|
462 | + 'EE_Request_Handler' => array( |
|
463 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_System' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
469 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
470 | + ), |
|
471 | + 'EE_Session' => array( |
|
472 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
473 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
474 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_Cart' => array( |
|
478 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Front_Controller' => array( |
|
481 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
482 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_Messenger_Collection_Loader' => array( |
|
486 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
487 | + ), |
|
488 | + 'EE_Message_Type_Collection_Loader' => array( |
|
489 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + ), |
|
491 | + 'EE_Message_Resource_Manager' => array( |
|
492 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
493 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Message_Factory' => array( |
|
497 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EE_messages' => array( |
|
500 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EE_Messages_Generator' => array( |
|
503 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
504 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
505 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
506 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EE_Messages_Processor' => array( |
|
509 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EE_Messages_Queue' => array( |
|
512 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
513 | + ), |
|
514 | + 'EE_Messages_Template_Defaults' => array( |
|
515 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
516 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
517 | + ), |
|
518 | + 'EE_Message_To_Generate_From_Request' => array( |
|
519 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
520 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
523 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
526 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
527 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
530 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
533 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
534 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
537 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
540 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
543 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
546 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
555 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
558 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
561 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
564 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
567 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
570 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | + ), |
|
572 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
573 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_Data_Migration_Class_Base' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_1_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_2_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_3_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EE_DMS_Core_4_4_0' => array( |
|
595 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EE_DMS_Core_4_5_0' => array( |
|
599 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EE_DMS_Core_4_6_0' => array( |
|
603 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EE_DMS_Core_4_7_0' => array( |
|
607 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | + ), |
|
610 | + 'EE_DMS_Core_4_8_0' => array( |
|
611 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
612 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
613 | + ), |
|
614 | + 'EE_DMS_Core_4_9_0' => array( |
|
615 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | + ), |
|
618 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
619 | + array(), |
|
620 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
621 | + ), |
|
622 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
623 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
626 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
638 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
641 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
644 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
645 | + ), |
|
646 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
647 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
648 | + ), |
|
649 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
650 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
651 | + ), |
|
652 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
653 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
654 | + ), |
|
655 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
656 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
658 | + ), |
|
659 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
660 | + null, |
|
661 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
662 | + ), |
|
663 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
664 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
665 | + ), |
|
666 | + 'LEGACY_MODELS' => array( |
|
667 | + null, |
|
668 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
669 | + ), |
|
670 | + 'EE_Module_Request_Router' => array( |
|
671 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EE_Registration_Processor' => array( |
|
674 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
675 | + ), |
|
676 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
677 | + null, |
|
678 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
680 | + ), |
|
681 | + 'EventEspresso\core\services\editor\EditorBlockRegistrationManager' => array( |
|
682 | + 'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache, |
|
683 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
685 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
686 | + ), |
|
687 | + 'EE_Admin_Transactions_List_Table' => array( |
|
688 | + null, |
|
689 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
690 | + ), |
|
691 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
692 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
694 | + ), |
|
695 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
696 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
697 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
698 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
699 | + ), |
|
700 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
701 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
702 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
703 | + ), |
|
704 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
705 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
706 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
707 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
708 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
709 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
711 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
712 | + ), |
|
713 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
714 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
715 | + ), |
|
716 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
717 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
718 | + ), |
|
719 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
720 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
721 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
722 | + ), |
|
723 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
724 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
725 | + ), |
|
726 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
727 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
728 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
729 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
731 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
732 | + ), |
|
733 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
734 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
735 | + ), |
|
736 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
737 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
739 | + ), |
|
740 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
741 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
742 | + ), |
|
743 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
744 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
745 | + ), |
|
746 | + 'EE_CPT_Strategy' => array( |
|
747 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
748 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
749 | + ), |
|
750 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
751 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
752 | + ), |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * Registers how core classes are loaded. |
|
759 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
760 | + * 'EE_Request_Handler' => 'load_core' |
|
761 | + * 'EE_Messages_Queue' => 'load_lib' |
|
762 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
763 | + * or, if greater control is required, by providing a custom closure. For example: |
|
764 | + * 'Some_Class' => function () { |
|
765 | + * return new Some_Class(); |
|
766 | + * }, |
|
767 | + * This is required for instantiating dependencies |
|
768 | + * where an interface has been type hinted in a class constructor. For example: |
|
769 | + * 'Required_Interface' => function () { |
|
770 | + * return new A_Class_That_Implements_Required_Interface(); |
|
771 | + * }, |
|
772 | + * |
|
773 | + */ |
|
774 | + protected function _register_core_class_loaders() |
|
775 | + { |
|
776 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
777 | + //be used in a closure. |
|
778 | + $request = &$this->request; |
|
779 | + $response = &$this->response; |
|
780 | + $legacy_request = &$this->legacy_request; |
|
781 | + // $loader = &$this->loader; |
|
782 | + $this->_class_loaders = array( |
|
783 | + //load_core |
|
784 | + 'EE_Capabilities' => 'load_core', |
|
785 | + 'EE_Encryption' => 'load_core', |
|
786 | + 'EE_Front_Controller' => 'load_core', |
|
787 | + 'EE_Module_Request_Router' => 'load_core', |
|
788 | + 'EE_Registry' => 'load_core', |
|
789 | + 'EE_Request' => function () use (&$legacy_request) { |
|
790 | + return $legacy_request; |
|
791 | + }, |
|
792 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
793 | + return $request; |
|
794 | + }, |
|
795 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
796 | + return $response; |
|
797 | + }, |
|
798 | + 'EE_Base' => 'load_core', |
|
799 | + 'EE_Request_Handler' => 'load_core', |
|
800 | + 'EE_Session' => 'load_core', |
|
801 | + 'EE_Cron_Tasks' => 'load_core', |
|
802 | + 'EE_System' => 'load_core', |
|
803 | + 'EE_Maintenance_Mode' => 'load_core', |
|
804 | + 'EE_Register_CPTs' => 'load_core', |
|
805 | + 'EE_Admin' => 'load_core', |
|
806 | + 'EE_CPT_Strategy' => 'load_core', |
|
807 | + //load_lib |
|
808 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
809 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
810 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
811 | + 'EE_Messenger_Collection' => 'load_lib', |
|
812 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
813 | + 'EE_Messages_Processor' => 'load_lib', |
|
814 | + 'EE_Message_Repository' => 'load_lib', |
|
815 | + 'EE_Messages_Queue' => 'load_lib', |
|
816 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
817 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
818 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
819 | + 'EE_Messages_Generator' => function () { |
|
820 | + return EE_Registry::instance()->load_lib( |
|
821 | + 'Messages_Generator', |
|
822 | + array(), |
|
823 | + false, |
|
824 | + false |
|
825 | + ); |
|
826 | + }, |
|
827 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
828 | + return EE_Registry::instance()->load_lib( |
|
829 | + 'Messages_Template_Defaults', |
|
830 | + $arguments, |
|
831 | + false, |
|
832 | + false |
|
833 | + ); |
|
834 | + }, |
|
835 | + //load_helper |
|
836 | + 'EEH_Parse_Shortcodes' => function () { |
|
837 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
838 | + return new EEH_Parse_Shortcodes(); |
|
839 | + } |
|
840 | + return null; |
|
841 | + }, |
|
842 | + 'EE_Template_Config' => function () { |
|
843 | + return EE_Config::instance()->template_settings; |
|
844 | + }, |
|
845 | + 'EE_Currency_Config' => function () { |
|
846 | + return EE_Config::instance()->currency; |
|
847 | + }, |
|
848 | + 'EE_Registration_Config' => function () { |
|
849 | + return EE_Config::instance()->registration; |
|
850 | + }, |
|
851 | + 'EE_Core_Config' => function () { |
|
852 | + return EE_Config::instance()->core; |
|
853 | + }, |
|
854 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
855 | + return LoaderFactory::getLoader(); |
|
856 | + }, |
|
857 | + 'EE_Network_Config' => function() { |
|
858 | + return EE_Network_Config::instance(); |
|
859 | + }, |
|
860 | + 'EE_Config' => function () { |
|
861 | + return EE_Config::instance(); |
|
862 | + }, |
|
863 | + 'EventEspresso\core\domain\Domain' => function () { |
|
864 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
865 | + }, |
|
866 | + ); |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + |
|
871 | + |
|
872 | + /** |
|
873 | + * can be used for supplying alternate names for classes, |
|
874 | + * or for connecting interface names to instantiable classes |
|
875 | + */ |
|
876 | + protected function _register_core_aliases() |
|
877 | + { |
|
878 | + $aliases = array( |
|
879 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
880 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
881 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
882 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
883 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
884 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
885 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
886 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
887 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
888 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
889 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
890 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
891 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
892 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
893 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
894 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
895 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
896 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
897 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
898 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
899 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
900 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
901 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
902 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
903 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
904 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
905 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
906 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
907 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
908 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
909 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
910 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
911 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
912 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
913 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
914 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
915 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
916 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
917 | + ); |
|
918 | + foreach ($aliases as $alias => $fqn) { |
|
919 | + if(is_array($fqn)) { |
|
920 | + foreach ($fqn as $class => $for_class) { |
|
921 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
922 | + } |
|
923 | + continue; |
|
924 | + } |
|
925 | + $this->class_cache->addAlias($fqn, $alias); |
|
926 | + } |
|
927 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
928 | + $this->class_cache->addAlias( |
|
929 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
930 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
931 | + ); |
|
932 | + } |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
939 | + * request Primarily used by unit tests. |
|
940 | + */ |
|
941 | + public function reset() |
|
942 | + { |
|
943 | + $this->_register_core_class_loaders(); |
|
944 | + $this->_register_core_dependencies(); |
|
945 | + } |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
950 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
951 | + * WHY? |
|
952 | + * Because if a class is type hinting for a concretion, |
|
953 | + * then why would we need to find another class to supply it? |
|
954 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
955 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
956 | + * Don't go looking for some substitute. |
|
957 | + * Whereas if a class is type hinting for an interface... |
|
958 | + * then we need to find an actual class to use. |
|
959 | + * So the interface IS the alias for some other FQN, |
|
960 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
961 | + * represents some other class. |
|
962 | + * |
|
963 | + * @deprecated $VID:$ |
|
964 | + * @param string $fqn |
|
965 | + * @param string $for_class |
|
966 | + * @return bool |
|
967 | + */ |
|
968 | + public function has_alias($fqn = '', $for_class = '') |
|
969 | + { |
|
970 | + return $this->isAlias($fqn, $for_class); |
|
971 | + } |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
976 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
977 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
978 | + * for example: |
|
979 | + * if the following two entries were added to the _aliases array: |
|
980 | + * array( |
|
981 | + * 'interface_alias' => 'some\namespace\interface' |
|
982 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
983 | + * ) |
|
984 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
985 | + * to load an instance of 'some\namespace\classname' |
|
986 | + * |
|
987 | + * @deprecated $VID:$ |
|
988 | + * @param string $alias |
|
989 | + * @param string $for_class |
|
990 | + * @return string |
|
991 | + */ |
|
992 | + public function get_alias($alias = '', $for_class = '') |
|
993 | + { |
|
994 | + return $this->getFqnForAlias($alias, $for_class); |
|
995 | + } |
|
996 | 996 | } |
997 | 997 | // End of file EE_Dependency_Map.core.php |
998 | 998 | // Location: /EE_Dependency_Map.core.php |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @access public |
158 | 158 | * @param mixed $identifier |
159 | - * @return mixed |
|
159 | + * @return boolean |
|
160 | 160 | */ |
161 | 161 | public function get($identifier) |
162 | 162 | { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * advances pointer to the provided object |
279 | 279 | * |
280 | 280 | * @access public |
281 | - * @param $object |
|
281 | + * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepForm $object |
|
282 | 282 | * @return boolean |
283 | 283 | */ |
284 | 284 | public function setCurrentUsingObject($object) |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @see http://stackoverflow.com/a/8736013 |
318 | 318 | * @param $object |
319 | - * @return boolean|int|string |
|
319 | + * @return integer |
|
320 | 320 | */ |
321 | 321 | public function indexOf($object) |
322 | 322 | { |
@@ -19,426 +19,426 @@ |
||
19 | 19 | class Collection extends SplObjectStorage implements CollectionInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * a unique string for identifying this collection |
|
24 | - * |
|
25 | - * @type string $collection_identifier |
|
26 | - */ |
|
27 | - protected $collection_identifier; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | - * this should be set from within the child class constructor |
|
33 | - * |
|
34 | - * @type string $interface |
|
35 | - */ |
|
36 | - protected $collection_interface; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Collection constructor |
|
41 | - * |
|
42 | - * @param string $collection_interface |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - */ |
|
45 | - public function __construct($collection_interface) |
|
46 | - { |
|
47 | - $this->setCollectionInterface($collection_interface); |
|
48 | - $this->setCollectionIdentifier(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function collectionIdentifier() |
|
56 | - { |
|
57 | - return $this->collection_identifier; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - protected function setCollectionIdentifier() |
|
68 | - { |
|
69 | - // hash a few collection details |
|
70 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | - // grab a few characters from the start, middle, and end of the hash |
|
72 | - $id = array(); |
|
73 | - for ($x = 0; $x < 19; $x += 9) { |
|
74 | - $id[] = substr($identifier, $x, 3); |
|
75 | - } |
|
76 | - $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | - $this->collection_identifier = $identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * setCollectionInterface |
|
84 | - * |
|
85 | - * @param string $collection_interface |
|
86 | - * @throws InvalidInterfaceException |
|
87 | - */ |
|
88 | - protected function setCollectionInterface($collection_interface) |
|
89 | - { |
|
90 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | - throw new InvalidInterfaceException($collection_interface); |
|
92 | - } |
|
93 | - $this->collection_interface = $collection_interface; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * add |
|
99 | - * attaches an object to the Collection |
|
100 | - * and sets any supplied data associated with the current iterator entry |
|
101 | - * by calling EE_Object_Collection::set_identifier() |
|
102 | - * |
|
103 | - * @param $object |
|
104 | - * @param mixed $identifier |
|
105 | - * @return bool |
|
106 | - * @throws InvalidEntityException |
|
107 | - */ |
|
108 | - public function add($object, $identifier = null) |
|
109 | - { |
|
110 | - if (! $object instanceof $this->collection_interface) { |
|
111 | - throw new InvalidEntityException($object, $this->collection_interface); |
|
112 | - } |
|
113 | - $this->attach($object); |
|
114 | - $this->setIdentifier($object, $identifier); |
|
115 | - return $this->contains($object); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * setIdentifier |
|
121 | - * Sets the data associated with an object in the Collection |
|
122 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param $object |
|
126 | - * @param mixed $identifier |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public function setIdentifier($object, $identifier = null) |
|
130 | - { |
|
131 | - $identifier = ! empty($identifier) |
|
132 | - ? $identifier |
|
133 | - : spl_object_hash($object); |
|
134 | - $this->rewind(); |
|
135 | - while ($this->valid()) { |
|
136 | - if ($object === $this->current()) { |
|
137 | - $this->setInfo($identifier); |
|
138 | - $this->rewind(); |
|
139 | - return true; |
|
140 | - } |
|
141 | - $this->next(); |
|
142 | - } |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * get |
|
149 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
150 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param mixed $identifier |
|
154 | - * @return mixed |
|
155 | - */ |
|
156 | - public function get($identifier) |
|
157 | - { |
|
158 | - $this->rewind(); |
|
159 | - while ($this->valid()) { |
|
160 | - if ($identifier === $this->getInfo()) { |
|
161 | - $object = $this->current(); |
|
162 | - $this->rewind(); |
|
163 | - return $object; |
|
164 | - } |
|
165 | - $this->next(); |
|
166 | - } |
|
167 | - return null; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * has |
|
173 | - * returns TRUE or FALSE |
|
174 | - * depending on whether the object is within the Collection |
|
175 | - * based on the supplied $identifier |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @param mixed $identifier |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function has($identifier) |
|
182 | - { |
|
183 | - $this->rewind(); |
|
184 | - while ($this->valid()) { |
|
185 | - if ($identifier === $this->getInfo()) { |
|
186 | - $this->rewind(); |
|
187 | - return true; |
|
188 | - } |
|
189 | - $this->next(); |
|
190 | - } |
|
191 | - return false; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * hasObject |
|
197 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
198 | - * |
|
199 | - * @access public |
|
200 | - * @param $object |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function hasObject($object) |
|
204 | - { |
|
205 | - return $this->contains($object); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * hasObjects |
|
211 | - * returns true if there are objects within the Collection, and false if it is empty |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function hasObjects() |
|
217 | - { |
|
218 | - return $this->count() !== 0; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * isEmpty |
|
224 | - * returns true if there are no objects within the Collection, and false if there are |
|
225 | - * |
|
226 | - * @access public |
|
227 | - * @return bool |
|
228 | - */ |
|
229 | - public function isEmpty() |
|
230 | - { |
|
231 | - return $this->count() === 0; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * remove |
|
237 | - * detaches an object from the Collection |
|
238 | - * |
|
239 | - * @access public |
|
240 | - * @param $object |
|
241 | - * @return bool |
|
242 | - */ |
|
243 | - public function remove($object) |
|
244 | - { |
|
245 | - $this->detach($object); |
|
246 | - return true; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * setCurrent |
|
252 | - * advances pointer to the object whose identifier matches that which was provided |
|
253 | - * |
|
254 | - * @access public |
|
255 | - * @param mixed $identifier |
|
256 | - * @return boolean |
|
257 | - */ |
|
258 | - public function setCurrent($identifier) |
|
259 | - { |
|
260 | - $this->rewind(); |
|
261 | - while ($this->valid()) { |
|
262 | - if ($identifier === $this->getInfo()) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - $this->next(); |
|
266 | - } |
|
267 | - return false; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * setCurrentUsingObject |
|
273 | - * advances pointer to the provided object |
|
274 | - * |
|
275 | - * @access public |
|
276 | - * @param $object |
|
277 | - * @return boolean |
|
278 | - */ |
|
279 | - public function setCurrentUsingObject($object) |
|
280 | - { |
|
281 | - $this->rewind(); |
|
282 | - while ($this->valid()) { |
|
283 | - if ($this->current() === $object) { |
|
284 | - return true; |
|
285 | - } |
|
286 | - $this->next(); |
|
287 | - } |
|
288 | - return false; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Returns the object occupying the index before the current object, |
|
294 | - * unless this is already the first object, in which case it just returns the first object |
|
295 | - * |
|
296 | - * @return mixed |
|
297 | - */ |
|
298 | - public function previous() |
|
299 | - { |
|
300 | - $index = $this->indexOf($this->current()); |
|
301 | - if ($index === 0) { |
|
302 | - return $this->current(); |
|
303 | - } |
|
304 | - $index--; |
|
305 | - return $this->objectAtIndex($index); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Returns the index of a given object, or false if not found |
|
311 | - * |
|
312 | - * @see http://stackoverflow.com/a/8736013 |
|
313 | - * @param $object |
|
314 | - * @return boolean|int|string |
|
315 | - */ |
|
316 | - public function indexOf($object) |
|
317 | - { |
|
318 | - if (! $this->contains($object)) { |
|
319 | - return false; |
|
320 | - } |
|
321 | - foreach ($this as $index => $obj) { |
|
322 | - if ($obj === $object) { |
|
323 | - return $index; |
|
324 | - } |
|
325 | - } |
|
326 | - return false; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Returns the object at the given index |
|
332 | - * |
|
333 | - * @see http://stackoverflow.com/a/8736013 |
|
334 | - * @param int $index |
|
335 | - * @return mixed |
|
336 | - */ |
|
337 | - public function objectAtIndex($index) |
|
338 | - { |
|
339 | - $iterator = new LimitIterator($this, $index, 1); |
|
340 | - $iterator->rewind(); |
|
341 | - return $iterator->current(); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Returns the sequence of objects as specified by the offset and length |
|
347 | - * |
|
348 | - * @see http://stackoverflow.com/a/8736013 |
|
349 | - * @param int $offset |
|
350 | - * @param int $length |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public function slice($offset, $length) |
|
354 | - { |
|
355 | - $slice = array(); |
|
356 | - $iterator = new LimitIterator($this, $offset, $length); |
|
357 | - foreach ($iterator as $object) { |
|
358 | - $slice[] = $object; |
|
359 | - } |
|
360 | - return $slice; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Inserts an object (or an array of objects) at a certain point |
|
366 | - * |
|
367 | - * @see http://stackoverflow.com/a/8736013 |
|
368 | - * @param mixed $objects A single object or an array of objects |
|
369 | - * @param int $index |
|
370 | - */ |
|
371 | - public function insertAt($objects, $index) |
|
372 | - { |
|
373 | - if (! is_array($objects)) { |
|
374 | - $objects = array($objects); |
|
375 | - } |
|
376 | - // check to ensure that objects don't already exist in the collection |
|
377 | - foreach ($objects as $key => $object) { |
|
378 | - if ($this->contains($object)) { |
|
379 | - unset($objects[ $key ]); |
|
380 | - } |
|
381 | - } |
|
382 | - // do we have any objects left? |
|
383 | - if (! $objects) { |
|
384 | - return; |
|
385 | - } |
|
386 | - // detach any objects at or past this index |
|
387 | - $remaining = array(); |
|
388 | - if ($index < $this->count()) { |
|
389 | - $remaining = $this->slice($index, $this->count() - $index); |
|
390 | - foreach ($remaining as $object) { |
|
391 | - $this->detach($object); |
|
392 | - } |
|
393 | - } |
|
394 | - // add the new objects we're splicing in |
|
395 | - foreach ($objects as $object) { |
|
396 | - $this->attach($object); |
|
397 | - } |
|
398 | - // attach the objects we previously detached |
|
399 | - foreach ($remaining as $object) { |
|
400 | - $this->attach($object); |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Removes the object at the given index |
|
407 | - * |
|
408 | - * @see http://stackoverflow.com/a/8736013 |
|
409 | - * @param int $index |
|
410 | - */ |
|
411 | - public function removeAt($index) |
|
412 | - { |
|
413 | - $this->detach($this->objectAtIndex($index)); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * detaches ALL objects from the Collection |
|
419 | - */ |
|
420 | - public function detachAll() |
|
421 | - { |
|
422 | - $this->rewind(); |
|
423 | - while ($this->valid()) { |
|
424 | - $object = $this->current(); |
|
425 | - $this->next(); |
|
426 | - $this->detach($object); |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * unsets and detaches ALL objects from the Collection |
|
433 | - */ |
|
434 | - public function trashAndDetachAll() |
|
435 | - { |
|
436 | - $this->rewind(); |
|
437 | - while ($this->valid()) { |
|
438 | - $object = $this->current(); |
|
439 | - $this->next(); |
|
440 | - $this->detach($object); |
|
441 | - unset($object); |
|
442 | - } |
|
443 | - } |
|
22 | + /** |
|
23 | + * a unique string for identifying this collection |
|
24 | + * |
|
25 | + * @type string $collection_identifier |
|
26 | + */ |
|
27 | + protected $collection_identifier; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
32 | + * this should be set from within the child class constructor |
|
33 | + * |
|
34 | + * @type string $interface |
|
35 | + */ |
|
36 | + protected $collection_interface; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Collection constructor |
|
41 | + * |
|
42 | + * @param string $collection_interface |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + */ |
|
45 | + public function __construct($collection_interface) |
|
46 | + { |
|
47 | + $this->setCollectionInterface($collection_interface); |
|
48 | + $this->setCollectionIdentifier(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function collectionIdentifier() |
|
56 | + { |
|
57 | + return $this->collection_identifier; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
63 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + protected function setCollectionIdentifier() |
|
68 | + { |
|
69 | + // hash a few collection details |
|
70 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
71 | + // grab a few characters from the start, middle, and end of the hash |
|
72 | + $id = array(); |
|
73 | + for ($x = 0; $x < 19; $x += 9) { |
|
74 | + $id[] = substr($identifier, $x, 3); |
|
75 | + } |
|
76 | + $identifier = basename(str_replace('\\', '/', get_class($this))); |
|
77 | + $identifier .= '-' . strtoupper(implode('-', $id)); |
|
78 | + $this->collection_identifier = $identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * setCollectionInterface |
|
84 | + * |
|
85 | + * @param string $collection_interface |
|
86 | + * @throws InvalidInterfaceException |
|
87 | + */ |
|
88 | + protected function setCollectionInterface($collection_interface) |
|
89 | + { |
|
90 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | + throw new InvalidInterfaceException($collection_interface); |
|
92 | + } |
|
93 | + $this->collection_interface = $collection_interface; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * add |
|
99 | + * attaches an object to the Collection |
|
100 | + * and sets any supplied data associated with the current iterator entry |
|
101 | + * by calling EE_Object_Collection::set_identifier() |
|
102 | + * |
|
103 | + * @param $object |
|
104 | + * @param mixed $identifier |
|
105 | + * @return bool |
|
106 | + * @throws InvalidEntityException |
|
107 | + */ |
|
108 | + public function add($object, $identifier = null) |
|
109 | + { |
|
110 | + if (! $object instanceof $this->collection_interface) { |
|
111 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
112 | + } |
|
113 | + $this->attach($object); |
|
114 | + $this->setIdentifier($object, $identifier); |
|
115 | + return $this->contains($object); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * setIdentifier |
|
121 | + * Sets the data associated with an object in the Collection |
|
122 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param $object |
|
126 | + * @param mixed $identifier |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public function setIdentifier($object, $identifier = null) |
|
130 | + { |
|
131 | + $identifier = ! empty($identifier) |
|
132 | + ? $identifier |
|
133 | + : spl_object_hash($object); |
|
134 | + $this->rewind(); |
|
135 | + while ($this->valid()) { |
|
136 | + if ($object === $this->current()) { |
|
137 | + $this->setInfo($identifier); |
|
138 | + $this->rewind(); |
|
139 | + return true; |
|
140 | + } |
|
141 | + $this->next(); |
|
142 | + } |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * get |
|
149 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
150 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param mixed $identifier |
|
154 | + * @return mixed |
|
155 | + */ |
|
156 | + public function get($identifier) |
|
157 | + { |
|
158 | + $this->rewind(); |
|
159 | + while ($this->valid()) { |
|
160 | + if ($identifier === $this->getInfo()) { |
|
161 | + $object = $this->current(); |
|
162 | + $this->rewind(); |
|
163 | + return $object; |
|
164 | + } |
|
165 | + $this->next(); |
|
166 | + } |
|
167 | + return null; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * has |
|
173 | + * returns TRUE or FALSE |
|
174 | + * depending on whether the object is within the Collection |
|
175 | + * based on the supplied $identifier |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @param mixed $identifier |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function has($identifier) |
|
182 | + { |
|
183 | + $this->rewind(); |
|
184 | + while ($this->valid()) { |
|
185 | + if ($identifier === $this->getInfo()) { |
|
186 | + $this->rewind(); |
|
187 | + return true; |
|
188 | + } |
|
189 | + $this->next(); |
|
190 | + } |
|
191 | + return false; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * hasObject |
|
197 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
198 | + * |
|
199 | + * @access public |
|
200 | + * @param $object |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function hasObject($object) |
|
204 | + { |
|
205 | + return $this->contains($object); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * hasObjects |
|
211 | + * returns true if there are objects within the Collection, and false if it is empty |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function hasObjects() |
|
217 | + { |
|
218 | + return $this->count() !== 0; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * isEmpty |
|
224 | + * returns true if there are no objects within the Collection, and false if there are |
|
225 | + * |
|
226 | + * @access public |
|
227 | + * @return bool |
|
228 | + */ |
|
229 | + public function isEmpty() |
|
230 | + { |
|
231 | + return $this->count() === 0; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * remove |
|
237 | + * detaches an object from the Collection |
|
238 | + * |
|
239 | + * @access public |
|
240 | + * @param $object |
|
241 | + * @return bool |
|
242 | + */ |
|
243 | + public function remove($object) |
|
244 | + { |
|
245 | + $this->detach($object); |
|
246 | + return true; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * setCurrent |
|
252 | + * advances pointer to the object whose identifier matches that which was provided |
|
253 | + * |
|
254 | + * @access public |
|
255 | + * @param mixed $identifier |
|
256 | + * @return boolean |
|
257 | + */ |
|
258 | + public function setCurrent($identifier) |
|
259 | + { |
|
260 | + $this->rewind(); |
|
261 | + while ($this->valid()) { |
|
262 | + if ($identifier === $this->getInfo()) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + $this->next(); |
|
266 | + } |
|
267 | + return false; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * setCurrentUsingObject |
|
273 | + * advances pointer to the provided object |
|
274 | + * |
|
275 | + * @access public |
|
276 | + * @param $object |
|
277 | + * @return boolean |
|
278 | + */ |
|
279 | + public function setCurrentUsingObject($object) |
|
280 | + { |
|
281 | + $this->rewind(); |
|
282 | + while ($this->valid()) { |
|
283 | + if ($this->current() === $object) { |
|
284 | + return true; |
|
285 | + } |
|
286 | + $this->next(); |
|
287 | + } |
|
288 | + return false; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Returns the object occupying the index before the current object, |
|
294 | + * unless this is already the first object, in which case it just returns the first object |
|
295 | + * |
|
296 | + * @return mixed |
|
297 | + */ |
|
298 | + public function previous() |
|
299 | + { |
|
300 | + $index = $this->indexOf($this->current()); |
|
301 | + if ($index === 0) { |
|
302 | + return $this->current(); |
|
303 | + } |
|
304 | + $index--; |
|
305 | + return $this->objectAtIndex($index); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Returns the index of a given object, or false if not found |
|
311 | + * |
|
312 | + * @see http://stackoverflow.com/a/8736013 |
|
313 | + * @param $object |
|
314 | + * @return boolean|int|string |
|
315 | + */ |
|
316 | + public function indexOf($object) |
|
317 | + { |
|
318 | + if (! $this->contains($object)) { |
|
319 | + return false; |
|
320 | + } |
|
321 | + foreach ($this as $index => $obj) { |
|
322 | + if ($obj === $object) { |
|
323 | + return $index; |
|
324 | + } |
|
325 | + } |
|
326 | + return false; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Returns the object at the given index |
|
332 | + * |
|
333 | + * @see http://stackoverflow.com/a/8736013 |
|
334 | + * @param int $index |
|
335 | + * @return mixed |
|
336 | + */ |
|
337 | + public function objectAtIndex($index) |
|
338 | + { |
|
339 | + $iterator = new LimitIterator($this, $index, 1); |
|
340 | + $iterator->rewind(); |
|
341 | + return $iterator->current(); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Returns the sequence of objects as specified by the offset and length |
|
347 | + * |
|
348 | + * @see http://stackoverflow.com/a/8736013 |
|
349 | + * @param int $offset |
|
350 | + * @param int $length |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public function slice($offset, $length) |
|
354 | + { |
|
355 | + $slice = array(); |
|
356 | + $iterator = new LimitIterator($this, $offset, $length); |
|
357 | + foreach ($iterator as $object) { |
|
358 | + $slice[] = $object; |
|
359 | + } |
|
360 | + return $slice; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Inserts an object (or an array of objects) at a certain point |
|
366 | + * |
|
367 | + * @see http://stackoverflow.com/a/8736013 |
|
368 | + * @param mixed $objects A single object or an array of objects |
|
369 | + * @param int $index |
|
370 | + */ |
|
371 | + public function insertAt($objects, $index) |
|
372 | + { |
|
373 | + if (! is_array($objects)) { |
|
374 | + $objects = array($objects); |
|
375 | + } |
|
376 | + // check to ensure that objects don't already exist in the collection |
|
377 | + foreach ($objects as $key => $object) { |
|
378 | + if ($this->contains($object)) { |
|
379 | + unset($objects[ $key ]); |
|
380 | + } |
|
381 | + } |
|
382 | + // do we have any objects left? |
|
383 | + if (! $objects) { |
|
384 | + return; |
|
385 | + } |
|
386 | + // detach any objects at or past this index |
|
387 | + $remaining = array(); |
|
388 | + if ($index < $this->count()) { |
|
389 | + $remaining = $this->slice($index, $this->count() - $index); |
|
390 | + foreach ($remaining as $object) { |
|
391 | + $this->detach($object); |
|
392 | + } |
|
393 | + } |
|
394 | + // add the new objects we're splicing in |
|
395 | + foreach ($objects as $object) { |
|
396 | + $this->attach($object); |
|
397 | + } |
|
398 | + // attach the objects we previously detached |
|
399 | + foreach ($remaining as $object) { |
|
400 | + $this->attach($object); |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Removes the object at the given index |
|
407 | + * |
|
408 | + * @see http://stackoverflow.com/a/8736013 |
|
409 | + * @param int $index |
|
410 | + */ |
|
411 | + public function removeAt($index) |
|
412 | + { |
|
413 | + $this->detach($this->objectAtIndex($index)); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * detaches ALL objects from the Collection |
|
419 | + */ |
|
420 | + public function detachAll() |
|
421 | + { |
|
422 | + $this->rewind(); |
|
423 | + while ($this->valid()) { |
|
424 | + $object = $this->current(); |
|
425 | + $this->next(); |
|
426 | + $this->detach($object); |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * unsets and detaches ALL objects from the Collection |
|
433 | + */ |
|
434 | + public function trashAndDetachAll() |
|
435 | + { |
|
436 | + $this->rewind(); |
|
437 | + while ($this->valid()) { |
|
438 | + $object = $this->current(); |
|
439 | + $this->next(); |
|
440 | + $this->detach($object); |
|
441 | + unset($object); |
|
442 | + } |
|
443 | + } |
|
444 | 444 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | protected function setCollectionIdentifier() |
68 | 68 | { |
69 | 69 | // hash a few collection details |
70 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
70 | + $identifier = md5(spl_object_hash($this).$this->collection_interface.time()); |
|
71 | 71 | // grab a few characters from the start, middle, and end of the hash |
72 | 72 | $id = array(); |
73 | 73 | for ($x = 0; $x < 19; $x += 9) { |
74 | 74 | $id[] = substr($identifier, $x, 3); |
75 | 75 | } |
76 | 76 | $identifier = basename(str_replace('\\', '/', get_class($this))); |
77 | - $identifier .= '-' . strtoupper(implode('-', $id)); |
|
77 | + $identifier .= '-'.strtoupper(implode('-', $id)); |
|
78 | 78 | $this->collection_identifier = $identifier; |
79 | 79 | } |
80 | 80 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function setCollectionInterface($collection_interface) |
89 | 89 | { |
90 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
90 | + if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
91 | 91 | throw new InvalidInterfaceException($collection_interface); |
92 | 92 | } |
93 | 93 | $this->collection_interface = $collection_interface; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function add($object, $identifier = null) |
109 | 109 | { |
110 | - if (! $object instanceof $this->collection_interface) { |
|
110 | + if ( ! $object instanceof $this->collection_interface) { |
|
111 | 111 | throw new InvalidEntityException($object, $this->collection_interface); |
112 | 112 | } |
113 | 113 | $this->attach($object); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function indexOf($object) |
317 | 317 | { |
318 | - if (! $this->contains($object)) { |
|
318 | + if ( ! $this->contains($object)) { |
|
319 | 319 | return false; |
320 | 320 | } |
321 | 321 | foreach ($this as $index => $obj) { |
@@ -370,17 +370,17 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public function insertAt($objects, $index) |
372 | 372 | { |
373 | - if (! is_array($objects)) { |
|
373 | + if ( ! is_array($objects)) { |
|
374 | 374 | $objects = array($objects); |
375 | 375 | } |
376 | 376 | // check to ensure that objects don't already exist in the collection |
377 | 377 | foreach ($objects as $key => $object) { |
378 | 378 | if ($this->contains($object)) { |
379 | - unset($objects[ $key ]); |
|
379 | + unset($objects[$key]); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | // do we have any objects left? |
383 | - if (! $objects) { |
|
383 | + if ( ! $objects) { |
|
384 | 384 | return; |
385 | 385 | } |
386 | 386 | // detach any objects at or past this index |
@@ -37,6 +37,8 @@ discard block |
||
37 | 37 | * @param \EE_State | string $state |
38 | 38 | * @param string $zip |
39 | 39 | * @param \EE_Country | string $country |
40 | + * @param integer $state |
|
41 | + * @param string $country |
|
40 | 42 | * @return GenericAddress |
41 | 43 | */ |
42 | 44 | public function __construct($address, $address2, $city, $state, $zip, $country) |
@@ -130,7 +132,7 @@ discard block |
||
130 | 132 | |
131 | 133 | |
132 | 134 | /** |
133 | - * @return \EE_State |
|
135 | + * @return string |
|
134 | 136 | */ |
135 | 137 | public function state_obj() |
136 | 138 | { |
@@ -183,7 +185,7 @@ discard block |
||
183 | 185 | |
184 | 186 | |
185 | 187 | /** |
186 | - * @return \EE_Country |
|
188 | + * @return string |
|
187 | 189 | */ |
188 | 190 | public function country_obj() |
189 | 191 | { |
@@ -12,205 +12,205 @@ |
||
12 | 12 | */ |
13 | 13 | class GenericAddress implements \EEI_Address |
14 | 14 | { |
15 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
16 | - private $_address = ''; |
|
17 | - |
|
18 | - private $_address2 = ''; |
|
19 | - |
|
20 | - private $_city = ''; |
|
21 | - |
|
22 | - private $_state_ID = ''; |
|
23 | - |
|
24 | - private $_state_obj = ''; |
|
25 | - |
|
26 | - private $_zip = ''; |
|
27 | - |
|
28 | - private $_country_ID = ''; |
|
29 | - |
|
30 | - private $_country_obj = ''; |
|
31 | - // phpcs:enable |
|
32 | - |
|
33 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
34 | - /** |
|
35 | - * @param string $address |
|
36 | - * @param string $address2 |
|
37 | - * @param string $city |
|
38 | - * @param \EE_State | string $state |
|
39 | - * @param string $zip |
|
40 | - * @param \EE_Country | string $country |
|
41 | - * @return GenericAddress |
|
42 | - */ |
|
43 | - public function __construct($address, $address2, $city, $state, $zip, $country) |
|
44 | - { |
|
45 | - $this->_address = $address; |
|
46 | - $this->_address2 = $address2; |
|
47 | - $this->_city = $city; |
|
48 | - if ($state instanceof \EE_State) { |
|
49 | - $this->_state_obj = $state; |
|
50 | - } else { |
|
51 | - $this->_state_ID = $state; |
|
52 | - $this->_state_obj = $this->_get_state_obj(); |
|
53 | - } |
|
54 | - $this->_zip = $zip; |
|
55 | - if ($country instanceof \EE_Country) { |
|
56 | - $this->_country_obj = $country; |
|
57 | - } else { |
|
58 | - $this->_country_ID = $country; |
|
59 | - $this->_country_obj = $this->_get_country_obj(); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function address() |
|
68 | - { |
|
69 | - return $this->_address; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function address2() |
|
77 | - { |
|
78 | - return $this->_address2; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function city() |
|
86 | - { |
|
87 | - return $this->_city; |
|
88 | - } |
|
89 | - |
|
90 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
91 | - |
|
92 | - /** |
|
93 | - * @return \EE_State |
|
94 | - */ |
|
95 | - private function _get_state_obj() |
|
96 | - { |
|
97 | - return $this->_state_obj instanceof \EE_State |
|
98 | - ? $this->_state_obj |
|
99 | - : \EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function state_ID() |
|
107 | - { |
|
108 | - return $this->_state_ID; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function state_abbrev() |
|
116 | - { |
|
117 | - return $this->state_obj() instanceof \EE_State |
|
118 | - ? $this->state_obj()->abbrev() |
|
119 | - : ''; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function state_name() |
|
127 | - { |
|
128 | - return $this->state_obj() instanceof \EE_State |
|
129 | - ? $this->state_obj()->name() |
|
130 | - : ''; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return \EE_State |
|
136 | - */ |
|
137 | - public function state_obj() |
|
138 | - { |
|
139 | - return $this->_state_obj; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function state() |
|
147 | - { |
|
148 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
149 | - return $this->state_obj()->abbrev(); |
|
150 | - } else { |
|
151 | - return $this->state_name(); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @return \EE_Country |
|
158 | - */ |
|
159 | - private function _get_country_obj() |
|
160 | - { |
|
161 | - return $this->_country_obj instanceof \EE_Country |
|
162 | - ? $this->_country_obj |
|
163 | - : \EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function country_ID() |
|
171 | - { |
|
172 | - return $this->_country_ID; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function country_name() |
|
180 | - { |
|
181 | - return $this->country_obj() instanceof \EE_Country |
|
182 | - ? $this->country_obj()->name() |
|
183 | - : ''; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return \EE_Country |
|
189 | - */ |
|
190 | - public function country_obj() |
|
191 | - { |
|
192 | - return $this->_country_obj; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function country() |
|
200 | - { |
|
201 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
202 | - return $this->country_ID(); |
|
203 | - } else { |
|
204 | - return $this->country_name(); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function zip() |
|
213 | - { |
|
214 | - return $this->_zip; |
|
215 | - } |
|
15 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
16 | + private $_address = ''; |
|
17 | + |
|
18 | + private $_address2 = ''; |
|
19 | + |
|
20 | + private $_city = ''; |
|
21 | + |
|
22 | + private $_state_ID = ''; |
|
23 | + |
|
24 | + private $_state_obj = ''; |
|
25 | + |
|
26 | + private $_zip = ''; |
|
27 | + |
|
28 | + private $_country_ID = ''; |
|
29 | + |
|
30 | + private $_country_obj = ''; |
|
31 | + // phpcs:enable |
|
32 | + |
|
33 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
34 | + /** |
|
35 | + * @param string $address |
|
36 | + * @param string $address2 |
|
37 | + * @param string $city |
|
38 | + * @param \EE_State | string $state |
|
39 | + * @param string $zip |
|
40 | + * @param \EE_Country | string $country |
|
41 | + * @return GenericAddress |
|
42 | + */ |
|
43 | + public function __construct($address, $address2, $city, $state, $zip, $country) |
|
44 | + { |
|
45 | + $this->_address = $address; |
|
46 | + $this->_address2 = $address2; |
|
47 | + $this->_city = $city; |
|
48 | + if ($state instanceof \EE_State) { |
|
49 | + $this->_state_obj = $state; |
|
50 | + } else { |
|
51 | + $this->_state_ID = $state; |
|
52 | + $this->_state_obj = $this->_get_state_obj(); |
|
53 | + } |
|
54 | + $this->_zip = $zip; |
|
55 | + if ($country instanceof \EE_Country) { |
|
56 | + $this->_country_obj = $country; |
|
57 | + } else { |
|
58 | + $this->_country_ID = $country; |
|
59 | + $this->_country_obj = $this->_get_country_obj(); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function address() |
|
68 | + { |
|
69 | + return $this->_address; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function address2() |
|
77 | + { |
|
78 | + return $this->_address2; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function city() |
|
86 | + { |
|
87 | + return $this->_city; |
|
88 | + } |
|
89 | + |
|
90 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
91 | + |
|
92 | + /** |
|
93 | + * @return \EE_State |
|
94 | + */ |
|
95 | + private function _get_state_obj() |
|
96 | + { |
|
97 | + return $this->_state_obj instanceof \EE_State |
|
98 | + ? $this->_state_obj |
|
99 | + : \EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function state_ID() |
|
107 | + { |
|
108 | + return $this->_state_ID; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function state_abbrev() |
|
116 | + { |
|
117 | + return $this->state_obj() instanceof \EE_State |
|
118 | + ? $this->state_obj()->abbrev() |
|
119 | + : ''; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function state_name() |
|
127 | + { |
|
128 | + return $this->state_obj() instanceof \EE_State |
|
129 | + ? $this->state_obj()->name() |
|
130 | + : ''; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return \EE_State |
|
136 | + */ |
|
137 | + public function state_obj() |
|
138 | + { |
|
139 | + return $this->_state_obj; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function state() |
|
147 | + { |
|
148 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
149 | + return $this->state_obj()->abbrev(); |
|
150 | + } else { |
|
151 | + return $this->state_name(); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @return \EE_Country |
|
158 | + */ |
|
159 | + private function _get_country_obj() |
|
160 | + { |
|
161 | + return $this->_country_obj instanceof \EE_Country |
|
162 | + ? $this->_country_obj |
|
163 | + : \EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function country_ID() |
|
171 | + { |
|
172 | + return $this->_country_ID; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function country_name() |
|
180 | + { |
|
181 | + return $this->country_obj() instanceof \EE_Country |
|
182 | + ? $this->country_obj()->name() |
|
183 | + : ''; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return \EE_Country |
|
189 | + */ |
|
190 | + public function country_obj() |
|
191 | + { |
|
192 | + return $this->_country_obj; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function country() |
|
200 | + { |
|
201 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
202 | + return $this->country_ID(); |
|
203 | + } else { |
|
204 | + return $this->country_name(); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function zip() |
|
213 | + { |
|
214 | + return $this->_zip; |
|
215 | + } |
|
216 | 216 | } |
@@ -34,8 +34,8 @@ |
||
34 | 34 | * @param EE_Transaction $transaction |
35 | 35 | * @param EE_Ticket $ticket |
36 | 36 | * @param EE_Line_Item $ticket_line_item |
37 | - * @param $reg_count |
|
38 | - * @param $reg_group_size |
|
37 | + * @param integer $reg_count |
|
38 | + * @param integer $reg_group_size |
|
39 | 39 | * @param string $reg_status |
40 | 40 | * @return EE_Registration |
41 | 41 | * @throws OutOfRangeException |
@@ -29,102 +29,102 @@ |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param EE_Event $event |
|
34 | - * @param EE_Transaction $transaction |
|
35 | - * @param EE_Ticket $ticket |
|
36 | - * @param EE_Line_Item $ticket_line_item |
|
37 | - * @param $reg_count |
|
38 | - * @param $reg_group_size |
|
39 | - * @param string $reg_status |
|
40 | - * @return EE_Registration |
|
41 | - * @throws OutOfRangeException |
|
42 | - * @throws EE_Error |
|
43 | - * @throws UnexpectedEntityException |
|
44 | - */ |
|
45 | - public function create( |
|
46 | - EE_Event $event, |
|
47 | - EE_Transaction $transaction, |
|
48 | - EE_Ticket $ticket, |
|
49 | - EE_Line_Item $ticket_line_item, |
|
50 | - $reg_count, |
|
51 | - $reg_group_size, |
|
52 | - $reg_status = EEM_Registration::status_id_incomplete |
|
53 | - ) { |
|
54 | - $registrations = $transaction->registrations(); |
|
55 | - $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
56 | - $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
57 | - $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
58 | - // generate new EE_Registration |
|
59 | - $registration = EE_Registration::new_instance( |
|
60 | - array( |
|
61 | - 'EVT_ID' => $event->ID(), |
|
62 | - 'TXN_ID' => $transaction->ID(), |
|
63 | - 'TKT_ID' => $ticket->ID(), |
|
64 | - 'STS_ID' => $reg_status, |
|
65 | - 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
66 | - 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
67 | - 'REG_count' => $reg_count, |
|
68 | - 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
69 | - 'REG_url_link' => $reg_url_link, |
|
70 | - 'REG_code' => $reg_code, |
|
71 | - ) |
|
72 | - ); |
|
73 | - if (! $registration instanceof EE_Registration) { |
|
74 | - throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
75 | - } |
|
76 | - // save registration so that we have an ID |
|
77 | - $registration->save(); |
|
78 | - // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
79 | - // because that is done as soon as the tickets are added/removed from the cart |
|
80 | - $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
81 | - $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
82 | - $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
83 | - $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
84 | - $registration->save(); |
|
85 | - return $registration; |
|
86 | - } |
|
32 | + /** |
|
33 | + * @param EE_Event $event |
|
34 | + * @param EE_Transaction $transaction |
|
35 | + * @param EE_Ticket $ticket |
|
36 | + * @param EE_Line_Item $ticket_line_item |
|
37 | + * @param $reg_count |
|
38 | + * @param $reg_group_size |
|
39 | + * @param string $reg_status |
|
40 | + * @return EE_Registration |
|
41 | + * @throws OutOfRangeException |
|
42 | + * @throws EE_Error |
|
43 | + * @throws UnexpectedEntityException |
|
44 | + */ |
|
45 | + public function create( |
|
46 | + EE_Event $event, |
|
47 | + EE_Transaction $transaction, |
|
48 | + EE_Ticket $ticket, |
|
49 | + EE_Line_Item $ticket_line_item, |
|
50 | + $reg_count, |
|
51 | + $reg_group_size, |
|
52 | + $reg_status = EEM_Registration::status_id_incomplete |
|
53 | + ) { |
|
54 | + $registrations = $transaction->registrations(); |
|
55 | + $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
56 | + $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
57 | + $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
58 | + // generate new EE_Registration |
|
59 | + $registration = EE_Registration::new_instance( |
|
60 | + array( |
|
61 | + 'EVT_ID' => $event->ID(), |
|
62 | + 'TXN_ID' => $transaction->ID(), |
|
63 | + 'TKT_ID' => $ticket->ID(), |
|
64 | + 'STS_ID' => $reg_status, |
|
65 | + 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
66 | + 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
67 | + 'REG_count' => $reg_count, |
|
68 | + 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
69 | + 'REG_url_link' => $reg_url_link, |
|
70 | + 'REG_code' => $reg_code, |
|
71 | + ) |
|
72 | + ); |
|
73 | + if (! $registration instanceof EE_Registration) { |
|
74 | + throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
75 | + } |
|
76 | + // save registration so that we have an ID |
|
77 | + $registration->save(); |
|
78 | + // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
79 | + // because that is done as soon as the tickets are added/removed from the cart |
|
80 | + $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
81 | + $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
82 | + $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
83 | + $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
84 | + $registration->save(); |
|
85 | + return $registration; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param EE_Transaction $transaction |
|
91 | - * @param EE_Ticket $ticket |
|
92 | - * @param EE_Line_Item $ticket_line_item |
|
93 | - * @return float |
|
94 | - * @throws EE_Error |
|
95 | - * @throws OutOfRangeException |
|
96 | - */ |
|
97 | - protected function resolveFinalPrice( |
|
98 | - EE_Transaction $transaction, |
|
99 | - EE_Ticket $ticket, |
|
100 | - EE_Line_Item $ticket_line_item |
|
101 | - ) { |
|
102 | - $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | - $transaction->total_line_item(), |
|
104 | - $ticket_line_item |
|
105 | - ); |
|
106 | - $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | - return (float) $final_price; |
|
108 | - } |
|
89 | + /** |
|
90 | + * @param EE_Transaction $transaction |
|
91 | + * @param EE_Ticket $ticket |
|
92 | + * @param EE_Line_Item $ticket_line_item |
|
93 | + * @return float |
|
94 | + * @throws EE_Error |
|
95 | + * @throws OutOfRangeException |
|
96 | + */ |
|
97 | + protected function resolveFinalPrice( |
|
98 | + EE_Transaction $transaction, |
|
99 | + EE_Ticket $ticket, |
|
100 | + EE_Line_Item $ticket_line_item |
|
101 | + ) { |
|
102 | + $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | + $transaction->total_line_item(), |
|
104 | + $ticket_line_item |
|
105 | + ); |
|
106 | + $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | + return (float) $final_price; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * @param EE_Registration[] $registrations |
|
113 | - * @param boolean $update_existing_registrations |
|
114 | - * @return int |
|
115 | - * @throws EE_Error |
|
116 | - */ |
|
117 | - protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
118 | - { |
|
119 | - $new_reg_count = count($registrations) + 1; |
|
120 | - if ($update_existing_registrations) { |
|
121 | - foreach ($registrations as $registration) { |
|
122 | - if ($registration instanceof EE_Registration) { |
|
123 | - $registration->set_count($new_reg_count); |
|
124 | - $registration->save(); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $new_reg_count; |
|
129 | - } |
|
111 | + /** |
|
112 | + * @param EE_Registration[] $registrations |
|
113 | + * @param boolean $update_existing_registrations |
|
114 | + * @return int |
|
115 | + * @throws EE_Error |
|
116 | + */ |
|
117 | + protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
118 | + { |
|
119 | + $new_reg_count = count($registrations) + 1; |
|
120 | + if ($update_existing_registrations) { |
|
121 | + foreach ($registrations as $registration) { |
|
122 | + if ($registration instanceof EE_Registration) { |
|
123 | + $registration->set_count($new_reg_count); |
|
124 | + $registration->save(); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $new_reg_count; |
|
129 | + } |
|
130 | 130 | } |
@@ -70,14 +70,14 @@ |
||
70 | 70 | 'REG_code' => $reg_code, |
71 | 71 | ) |
72 | 72 | ); |
73 | - if (! $registration instanceof EE_Registration) { |
|
73 | + if ( ! $registration instanceof EE_Registration) { |
|
74 | 74 | throw new UnexpectedEntityException($registration, 'EE_Registration'); |
75 | 75 | } |
76 | 76 | // save registration so that we have an ID |
77 | 77 | $registration->save(); |
78 | 78 | // track reservation on reg but don't adjust ticket and datetime reserved counts |
79 | 79 | // because that is done as soon as the tickets are added/removed from the cart |
80 | - $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
80 | + $registration->reserve_ticket(false, 'CreateRegistrationService:'.__LINE__); |
|
81 | 81 | $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
82 | 82 | $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
83 | 83 | $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
@@ -42,7 +42,6 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * Return the schema for a given model from a given model. |
44 | 44 | * |
45 | - * @param \EEM_Base $model |
|
46 | 45 | * @return array |
47 | 46 | */ |
48 | 47 | public function getModelSchema() |
@@ -120,7 +119,6 @@ discard block |
||
120 | 119 | /** |
121 | 120 | * Outputs the schema header for a model. |
122 | 121 | * |
123 | - * @param \EEM_Base $model |
|
124 | 122 | * @return array |
125 | 123 | */ |
126 | 124 | public function getInitialSchemaStructure() |
@@ -24,126 +24,126 @@ |
||
24 | 24 | class JsonModelSchema |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var \EEM_Base |
|
29 | - */ |
|
30 | - protected $model; |
|
31 | - |
|
32 | - /** |
|
33 | - * JsonModelSchema constructor. |
|
34 | - * |
|
35 | - * @param \EEM_Base $model |
|
36 | - */ |
|
37 | - public function __construct(EEM_Base $model) |
|
38 | - { |
|
39 | - $this->model = $model; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Return the schema for a given model from a given model. |
|
44 | - * |
|
45 | - * @param \EEM_Base $model |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getModelSchema() |
|
49 | - { |
|
50 | - return $this->getModelSchemaForRelations( |
|
51 | - $this->model->relation_settings(), |
|
52 | - $this->getModelSchemaForFields( |
|
53 | - $this->model->field_settings(), |
|
54 | - $this->getInitialSchemaStructure() |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the schema for a given set of model fields. |
|
62 | - * |
|
63 | - * @param \EE_Model_Field_Base[] $model_fields |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
67 | - { |
|
68 | - foreach ($model_fields as $field => $model_field) { |
|
69 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
70 | - continue; |
|
71 | - } |
|
72 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
73 | - |
|
74 | - // if this is a primary key field add the primary key item |
|
75 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
76 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
77 | - if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
78 | - $schema['properties'][ $field ]['readonly'] = true; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - // if this is a foreign key field add the foreign key item |
|
83 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
84 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
85 | - 'description' => esc_html__( |
|
86 | - 'This is a foreign key the points to the given models.', |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - 'type' => 'array', |
|
90 | - 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
91 | - ); |
|
92 | - } |
|
93 | - } |
|
94 | - return $schema; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Get the schema for a given set of model relations |
|
100 | - * |
|
101 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
105 | - { |
|
106 | - foreach ($relations_on_model as $model_name => $relation) { |
|
107 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
108 | - continue; |
|
109 | - } |
|
110 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
111 | - ? strtolower($model_name) |
|
112 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
113 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
114 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
115 | - } |
|
116 | - return $schema; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Outputs the schema header for a model. |
|
122 | - * |
|
123 | - * @param \EEM_Base $model |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function getInitialSchemaStructure() |
|
127 | - { |
|
128 | - return array( |
|
129 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
130 | - 'title' => $this->model->get_this_model_name(), |
|
131 | - 'type' => 'object', |
|
132 | - 'properties' => array(), |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Allows one to just use the object as a string to get the json. |
|
139 | - * eg. |
|
140 | - * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
141 | - * echo $json_schema; //outputs the schema as a json formatted string. |
|
142 | - * |
|
143 | - * @return bool|false|mixed|string |
|
144 | - */ |
|
145 | - public function __toString() |
|
146 | - { |
|
147 | - return wp_json_encode($this->getModelSchema()); |
|
148 | - } |
|
27 | + /** |
|
28 | + * @var \EEM_Base |
|
29 | + */ |
|
30 | + protected $model; |
|
31 | + |
|
32 | + /** |
|
33 | + * JsonModelSchema constructor. |
|
34 | + * |
|
35 | + * @param \EEM_Base $model |
|
36 | + */ |
|
37 | + public function __construct(EEM_Base $model) |
|
38 | + { |
|
39 | + $this->model = $model; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Return the schema for a given model from a given model. |
|
44 | + * |
|
45 | + * @param \EEM_Base $model |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getModelSchema() |
|
49 | + { |
|
50 | + return $this->getModelSchemaForRelations( |
|
51 | + $this->model->relation_settings(), |
|
52 | + $this->getModelSchemaForFields( |
|
53 | + $this->model->field_settings(), |
|
54 | + $this->getInitialSchemaStructure() |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the schema for a given set of model fields. |
|
62 | + * |
|
63 | + * @param \EE_Model_Field_Base[] $model_fields |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
67 | + { |
|
68 | + foreach ($model_fields as $field => $model_field) { |
|
69 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + $schema['properties'][ $field ] = $model_field->getSchema(); |
|
73 | + |
|
74 | + // if this is a primary key field add the primary key item |
|
75 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
76 | + $schema['properties'][ $field ]['primary_key'] = true; |
|
77 | + if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
78 | + $schema['properties'][ $field ]['readonly'] = true; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + // if this is a foreign key field add the foreign key item |
|
83 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
84 | + $schema['properties'][ $field ]['foreign_key'] = array( |
|
85 | + 'description' => esc_html__( |
|
86 | + 'This is a foreign key the points to the given models.', |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + 'type' => 'array', |
|
90 | + 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
91 | + ); |
|
92 | + } |
|
93 | + } |
|
94 | + return $schema; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Get the schema for a given set of model relations |
|
100 | + * |
|
101 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
105 | + { |
|
106 | + foreach ($relations_on_model as $model_name => $relation) { |
|
107 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
108 | + continue; |
|
109 | + } |
|
110 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
111 | + ? strtolower($model_name) |
|
112 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
113 | + $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
114 | + $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
115 | + } |
|
116 | + return $schema; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Outputs the schema header for a model. |
|
122 | + * |
|
123 | + * @param \EEM_Base $model |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function getInitialSchemaStructure() |
|
127 | + { |
|
128 | + return array( |
|
129 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
130 | + 'title' => $this->model->get_this_model_name(), |
|
131 | + 'type' => 'object', |
|
132 | + 'properties' => array(), |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Allows one to just use the object as a string to get the json. |
|
139 | + * eg. |
|
140 | + * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
141 | + * echo $json_schema; //outputs the schema as a json formatted string. |
|
142 | + * |
|
143 | + * @return bool|false|mixed|string |
|
144 | + */ |
|
145 | + public function __toString() |
|
146 | + { |
|
147 | + return wp_json_encode($this->getModelSchema()); |
|
148 | + } |
|
149 | 149 | } |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | public function getModelSchemaForFields(array $model_fields, array $schema) |
67 | 67 | { |
68 | 68 | foreach ($model_fields as $field => $model_field) { |
69 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
69 | + if ( ! $model_field instanceof EE_Model_Field_Base) { |
|
70 | 70 | continue; |
71 | 71 | } |
72 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
72 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
73 | 73 | |
74 | 74 | // if this is a primary key field add the primary key item |
75 | 75 | if ($model_field instanceof EE_Primary_Key_Field_Base) { |
76 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
76 | + $schema['properties'][$field]['primary_key'] = true; |
|
77 | 77 | if ($model_field instanceof EE_Primary_Key_Int_Field) { |
78 | - $schema['properties'][ $field ]['readonly'] = true; |
|
78 | + $schema['properties'][$field]['readonly'] = true; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | // if this is a foreign key field add the foreign key item |
83 | 83 | if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
84 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
84 | + $schema['properties'][$field]['foreign_key'] = array( |
|
85 | 85 | 'description' => esc_html__( |
86 | 86 | 'This is a foreign key the points to the given models.', |
87 | 87 | 'event_espresso' |
@@ -104,14 +104,14 @@ discard block |
||
104 | 104 | public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
105 | 105 | { |
106 | 106 | foreach ($relations_on_model as $model_name => $relation) { |
107 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
107 | + if ( ! $relation instanceof EE_Model_Relation_Base) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
111 | 111 | ? strtolower($model_name) |
112 | 112 | : EEH_Inflector::pluralize_and_lower($model_name); |
113 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
114 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
113 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
114 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
115 | 115 | } |
116 | 116 | return $schema; |
117 | 117 | } |
@@ -90,6 +90,10 @@ |
||
90 | 90 | return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @param integer $offset |
|
95 | + * @param integer $limit |
|
96 | + */ |
|
93 | 97 | public function get_csv_data($offset, $limit) |
94 | 98 | { |
95 | 99 | $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
@@ -19,106 +19,106 @@ |
||
19 | 19 | class AttendeesReport extends JobHandlerFile |
20 | 20 | { |
21 | 21 | |
22 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | - public function create_job(JobParameters $job_parameters) |
|
24 | - { |
|
25 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | - throw new BatchRequestException( |
|
27 | - __('You do not have permission to view contacts', 'event_espresso') |
|
28 | - ); |
|
29 | - } |
|
30 | - $filepath = $this->create_file_from_job_with_name( |
|
31 | - $job_parameters->job_id(), |
|
32 | - __('contact-list-report.csv', 'event_espresso') |
|
33 | - ); |
|
34 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
35 | - $job_parameters->set_job_size($this->count_units_to_process()); |
|
36 | - // we should also set the header columns |
|
37 | - $csv_data_for_row = $this->get_csv_data(0, 1); |
|
38 | - \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
39 | - // if we actually processed a row there, record it |
|
40 | - if ($job_parameters->job_size()) { |
|
41 | - $job_parameters->mark_processed(1); |
|
42 | - } |
|
43 | - return new JobStepResponse( |
|
44 | - $job_parameters, |
|
45 | - __('Contacts report started successfully...', 'event_espresso') |
|
46 | - ); |
|
47 | - } |
|
22 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | + public function create_job(JobParameters $job_parameters) |
|
24 | + { |
|
25 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | + throw new BatchRequestException( |
|
27 | + __('You do not have permission to view contacts', 'event_espresso') |
|
28 | + ); |
|
29 | + } |
|
30 | + $filepath = $this->create_file_from_job_with_name( |
|
31 | + $job_parameters->job_id(), |
|
32 | + __('contact-list-report.csv', 'event_espresso') |
|
33 | + ); |
|
34 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
35 | + $job_parameters->set_job_size($this->count_units_to_process()); |
|
36 | + // we should also set the header columns |
|
37 | + $csv_data_for_row = $this->get_csv_data(0, 1); |
|
38 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
39 | + // if we actually processed a row there, record it |
|
40 | + if ($job_parameters->job_size()) { |
|
41 | + $job_parameters->mark_processed(1); |
|
42 | + } |
|
43 | + return new JobStepResponse( |
|
44 | + $job_parameters, |
|
45 | + __('Contacts report started successfully...', 'event_espresso') |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
51 | - { |
|
52 | - $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size); |
|
53 | - \EEH_Export::write_data_array_to_csv( |
|
54 | - $job_parameters->extra_datum('filepath'), |
|
55 | - $csv_data, |
|
56 | - false |
|
57 | - ); |
|
58 | - $units_processed = count($csv_data); |
|
59 | - $job_parameters->mark_processed($units_processed); |
|
60 | - $extra_response_data = array( |
|
61 | - 'file_url' => '', |
|
62 | - ); |
|
63 | - if ($units_processed < $batch_size) { |
|
64 | - $job_parameters->set_status(JobParameters::status_complete); |
|
65 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
66 | - } |
|
67 | - return new JobStepResponse( |
|
68 | - $job_parameters, |
|
69 | - sprintf( |
|
70 | - __('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
71 | - count($csv_data) |
|
72 | - ), |
|
73 | - $extra_response_data |
|
74 | - ); |
|
75 | - } |
|
50 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
51 | + { |
|
52 | + $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size); |
|
53 | + \EEH_Export::write_data_array_to_csv( |
|
54 | + $job_parameters->extra_datum('filepath'), |
|
55 | + $csv_data, |
|
56 | + false |
|
57 | + ); |
|
58 | + $units_processed = count($csv_data); |
|
59 | + $job_parameters->mark_processed($units_processed); |
|
60 | + $extra_response_data = array( |
|
61 | + 'file_url' => '', |
|
62 | + ); |
|
63 | + if ($units_processed < $batch_size) { |
|
64 | + $job_parameters->set_status(JobParameters::status_complete); |
|
65 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
66 | + } |
|
67 | + return new JobStepResponse( |
|
68 | + $job_parameters, |
|
69 | + sprintf( |
|
70 | + __('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
71 | + count($csv_data) |
|
72 | + ), |
|
73 | + $extra_response_data |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - public function cleanup_job(JobParameters $job_parameters) |
|
79 | - { |
|
80 | - $this->_file_helper->delete( |
|
81 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
82 | - true, |
|
83 | - 'd' |
|
84 | - ); |
|
85 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
86 | - } |
|
78 | + public function cleanup_job(JobParameters $job_parameters) |
|
79 | + { |
|
80 | + $this->_file_helper->delete( |
|
81 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
82 | + true, |
|
83 | + 'd' |
|
84 | + ); |
|
85 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
86 | + } |
|
87 | 87 | |
88 | - public function count_units_to_process() |
|
89 | - { |
|
90 | - return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
|
91 | - } |
|
88 | + public function count_units_to_process() |
|
89 | + { |
|
90 | + return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
|
91 | + } |
|
92 | 92 | |
93 | - public function get_csv_data($offset, $limit) |
|
94 | - { |
|
95 | - $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
|
96 | - array( |
|
97 | - 'limit' => array($offset, $limit), |
|
98 | - 'force_join' => array('State', 'Country'), |
|
99 | - 'caps' => \EEM_Base::caps_read_admin, |
|
100 | - ) |
|
101 | - ); |
|
102 | - $csv_data = array(); |
|
103 | - foreach ($attendee_rows as $attendee_row) { |
|
104 | - $csv_row = array(); |
|
105 | - foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
106 | - if ($field_name == 'STA_ID') { |
|
107 | - $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
|
108 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
109 | - } elseif ($field_name == 'CNT_ISO') { |
|
110 | - $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
|
111 | - $csv_row[ __('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
112 | - } else { |
|
113 | - $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
114 | - } |
|
115 | - } |
|
116 | - $csv_data[] = apply_filters( |
|
117 | - 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
118 | - $csv_row, |
|
119 | - $attendee_row |
|
120 | - ); |
|
121 | - } |
|
122 | - return $csv_data; |
|
123 | - } |
|
93 | + public function get_csv_data($offset, $limit) |
|
94 | + { |
|
95 | + $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
|
96 | + array( |
|
97 | + 'limit' => array($offset, $limit), |
|
98 | + 'force_join' => array('State', 'Country'), |
|
99 | + 'caps' => \EEM_Base::caps_read_admin, |
|
100 | + ) |
|
101 | + ); |
|
102 | + $csv_data = array(); |
|
103 | + foreach ($attendee_rows as $attendee_row) { |
|
104 | + $csv_row = array(); |
|
105 | + foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
106 | + if ($field_name == 'STA_ID') { |
|
107 | + $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
|
108 | + $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
109 | + } elseif ($field_name == 'CNT_ISO') { |
|
110 | + $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
|
111 | + $csv_row[ __('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
112 | + } else { |
|
113 | + $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
114 | + } |
|
115 | + } |
|
116 | + $csv_data[] = apply_filters( |
|
117 | + 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
118 | + $csv_row, |
|
119 | + $attendee_row |
|
120 | + ); |
|
121 | + } |
|
122 | + return $csv_data; |
|
123 | + } |
|
124 | 124 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
23 | 23 | public function create_job(JobParameters $job_parameters) |
24 | 24 | { |
25 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
25 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
26 | 26 | throw new BatchRequestException( |
27 | 27 | __('You do not have permission to view contacts', 'event_espresso') |
28 | 28 | ); |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
106 | 106 | if ($field_name == 'STA_ID') { |
107 | 107 | $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
108 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
108 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; |
|
109 | 109 | } elseif ($field_name == 'CNT_ISO') { |
110 | 110 | $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
111 | - $csv_row[ __('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
111 | + $csv_row[__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
112 | 112 | } else { |
113 | - $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
113 | + $csv_row[wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES)] = $attendee_row[$field_obj->get_qualified_column()]; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | $csv_data[] = apply_filters( |