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