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