@@ -17,665 +17,665 @@ |
||
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 | - * $_FILES parameters |
|
50 | - * |
|
51 | - * @var array $files |
|
52 | - */ |
|
53 | - private $files; |
|
54 | - |
|
55 | - /** |
|
56 | - * $_REQUEST parameters |
|
57 | - * |
|
58 | - * @var array $request |
|
59 | - */ |
|
60 | - private $request; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var RequestTypeContextCheckerInterface |
|
64 | - */ |
|
65 | - private $request_type; |
|
66 | - |
|
67 | - /** |
|
68 | - * IP address for request |
|
69 | - * |
|
70 | - * @var string $ip_address |
|
71 | - */ |
|
72 | - private $ip_address; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var string $user_agent |
|
76 | - */ |
|
77 | - private $user_agent; |
|
78 | - |
|
79 | - /** |
|
80 | - * true if current user appears to be some kind of bot |
|
81 | - * |
|
82 | - * @var bool $is_bot |
|
83 | - */ |
|
84 | - private $is_bot; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $get |
|
89 | - * @param array $post |
|
90 | - * @param array $cookie |
|
91 | - * @param array $server |
|
92 | - * @param array $files |
|
93 | - */ |
|
94 | - public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
95 | - { |
|
96 | - // grab request vars |
|
97 | - $this->get = $get; |
|
98 | - $this->post = $post; |
|
99 | - $this->cookie = $cookie; |
|
100 | - $this->server = $server; |
|
101 | - $this->files = $files; |
|
102 | - $this->request = array_merge($this->get, $this->post); |
|
103 | - $this->ip_address = $this->visitorIp(); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param RequestTypeContextCheckerInterface $type |
|
109 | - */ |
|
110 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
111 | - { |
|
112 | - $this->request_type = $type; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function getParams() |
|
120 | - { |
|
121 | - return $this->get; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function postParams() |
|
129 | - { |
|
130 | - return $this->post; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function cookieParams() |
|
138 | - { |
|
139 | - return $this->cookie; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - public function serverParams() |
|
147 | - { |
|
148 | - return $this->server; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public function filesParams() |
|
156 | - { |
|
157 | - return $this->files; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * returns contents of $_REQUEST |
|
163 | - * |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public function requestParams() |
|
167 | - { |
|
168 | - return $this->request; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $key |
|
174 | - * @param $value |
|
175 | - * @param bool $override_ee |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - public function setRequestParam($key, $value, $override_ee = false) |
|
179 | - { |
|
180 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
181 | - if ($key !== 'ee' |
|
182 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
183 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
184 | - ) { |
|
185 | - $this->request[ $key ] = $value; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * returns the value for a request param if the given key exists |
|
192 | - * |
|
193 | - * @param $key |
|
194 | - * @param null $default |
|
195 | - * @return mixed |
|
196 | - */ |
|
197 | - public function getRequestParam($key, $default = null) |
|
198 | - { |
|
199 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * check if param exists |
|
205 | - * |
|
206 | - * @param $key |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function requestParamIsSet($key) |
|
210 | - { |
|
211 | - return $this->requestParameterDrillDown($key); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
217 | - * and return the value for the first match found |
|
218 | - * wildcards can be either of the following: |
|
219 | - * ? to represent a single character of any type |
|
220 | - * * to represent one or more characters of any type |
|
221 | - * |
|
222 | - * @param string $pattern |
|
223 | - * @param null|mixed $default |
|
224 | - * @return mixed |
|
225 | - */ |
|
226 | - public function getMatch($pattern, $default = null) |
|
227 | - { |
|
228 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
234 | - * wildcards can be either of the following: |
|
235 | - * ? to represent a single character of any type |
|
236 | - * * to represent one or more characters of any type |
|
237 | - * returns true if a match is found or false if not |
|
238 | - * |
|
239 | - * @param string $pattern |
|
240 | - * @return bool |
|
241 | - */ |
|
242 | - public function matches($pattern) |
|
243 | - { |
|
244 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
250 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
251 | - * and used to search through the current request's parameter keys |
|
252 | - * @param array $request_params The array of request parameters to search through |
|
253 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
254 | - * Default is null |
|
255 | - * @param string $return [optional] Controls what kind of value is returned. |
|
256 | - * Options are: |
|
257 | - * 'bool' will return true or false if match is found or not |
|
258 | - * 'key' will return the first key found that matches the supplied pattern |
|
259 | - * 'value' will return the value for the first request parameter |
|
260 | - * whose key matches the supplied pattern |
|
261 | - * Default is 'value' |
|
262 | - * @return boolean|string |
|
263 | - */ |
|
264 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
265 | - { |
|
266 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
267 | - ? $return |
|
268 | - : 'is_set'; |
|
269 | - // replace wildcard chars with regex chars |
|
270 | - $pattern = str_replace( |
|
271 | - array("\*", "\?"), |
|
272 | - array('.*', '.'), |
|
273 | - preg_quote($pattern, '/') |
|
274 | - ); |
|
275 | - foreach ($request_params as $key => $request_param) { |
|
276 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
277 | - // return value for request param |
|
278 | - if ($return === 'value') { |
|
279 | - return $request_params[ $key ]; |
|
280 | - } |
|
281 | - // or actual key or true just to indicate it was found |
|
282 | - return $return === 'key' ? $key : true; |
|
283 | - } |
|
284 | - } |
|
285 | - // match not found so return default value or false |
|
286 | - return $return === 'value' ? $default : false; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
292 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
293 | - * by using square brackets to surround keys for deeper array elements. |
|
294 | - * For example : |
|
295 | - * if the supplied $key was: "first[second][third]" |
|
296 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
297 | - * Given the following request parameters: |
|
298 | - * array( |
|
299 | - * 'first' => array( |
|
300 | - * 'second' => array( |
|
301 | - * 'third' => 'has a value' |
|
302 | - * ) |
|
303 | - * ) |
|
304 | - * ) |
|
305 | - * would return true if default parameters were set |
|
306 | - * |
|
307 | - * @param string $callback |
|
308 | - * @param $key |
|
309 | - * @param null $default |
|
310 | - * @param array $request_params |
|
311 | - * @return bool|mixed|null |
|
312 | - */ |
|
313 | - private function requestParameterDrillDown( |
|
314 | - $key, |
|
315 | - $default = null, |
|
316 | - $callback = 'is_set', |
|
317 | - array $request_params = array() |
|
318 | - ) { |
|
319 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
320 | - ? $callback |
|
321 | - : 'is_set'; |
|
322 | - $request_params = ! empty($request_params) |
|
323 | - ? $request_params |
|
324 | - : $this->request; |
|
325 | - // does incoming key represent an array like 'first[second][third]' ? |
|
326 | - if (strpos($key, '[') !== false) { |
|
327 | - // turn it into an actual array |
|
328 | - $key = str_replace(']', '', $key); |
|
329 | - $keys = explode('[', $key); |
|
330 | - $key = array_shift($keys); |
|
331 | - if ($callback === 'match') { |
|
332 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
333 | - $key = $real_key ? $real_key : $key; |
|
334 | - } |
|
335 | - // check if top level key exists |
|
336 | - if (isset($request_params[ $key ])) { |
|
337 | - // build a new key to pass along like: 'second[third]' |
|
338 | - // or just 'second' depending on depth of keys |
|
339 | - $key_string = array_shift($keys); |
|
340 | - if (! empty($keys)) { |
|
341 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
342 | - } |
|
343 | - return $this->requestParameterDrillDown( |
|
344 | - $key_string, |
|
345 | - $default, |
|
346 | - $callback, |
|
347 | - $request_params[ $key ] |
|
348 | - ); |
|
349 | - } |
|
350 | - } |
|
351 | - if ($callback === 'is_set') { |
|
352 | - return isset($request_params[ $key ]); |
|
353 | - } |
|
354 | - if ($callback === 'match') { |
|
355 | - return $this->match($key, $request_params, $default); |
|
356 | - } |
|
357 | - return isset($request_params[ $key ]) |
|
358 | - ? $request_params[ $key ] |
|
359 | - : $default; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * remove param |
|
365 | - * |
|
366 | - * @param $key |
|
367 | - * @param bool $unset_from_global_too |
|
368 | - */ |
|
369 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
370 | - { |
|
371 | - // because unset may not actually remove var |
|
372 | - $this->request[ $key ] = null; |
|
373 | - unset($this->request[ $key ]); |
|
374 | - if ($unset_from_global_too) { |
|
375 | - unset($_REQUEST[ $key ]); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * remove params |
|
382 | - * |
|
383 | - * @param array $keys |
|
384 | - * @param bool $unset_from_global_too |
|
385 | - */ |
|
386 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
387 | - { |
|
388 | - foreach ($keys as $key) { |
|
389 | - $this->unSetRequestParam($key, $unset_from_global_too); |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function ipAddress() |
|
398 | - { |
|
399 | - return $this->ip_address; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * attempt to get IP address of current visitor from server |
|
405 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
406 | - * |
|
407 | - * @access public |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - private function visitorIp() |
|
411 | - { |
|
412 | - $visitor_ip = '0.0.0.0'; |
|
413 | - $server_keys = array( |
|
414 | - 'HTTP_CLIENT_IP', |
|
415 | - 'HTTP_X_FORWARDED_FOR', |
|
416 | - 'HTTP_X_FORWARDED', |
|
417 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
418 | - 'HTTP_FORWARDED_FOR', |
|
419 | - 'HTTP_FORWARDED', |
|
420 | - 'REMOTE_ADDR', |
|
421 | - ); |
|
422 | - foreach ($server_keys as $key) { |
|
423 | - if (isset($this->server[ $key ])) { |
|
424 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
425 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
426 | - $visitor_ip = $ip; |
|
427 | - } |
|
428 | - } |
|
429 | - } |
|
430 | - } |
|
431 | - return $visitor_ip; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
437 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
438 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
439 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function requestUri($relativeToWpRoot = false) |
|
443 | - { |
|
444 | - $request_uri = filter_input( |
|
445 | - INPUT_SERVER, |
|
446 | - 'REQUEST_URI', |
|
447 | - FILTER_SANITIZE_URL, |
|
448 | - FILTER_NULL_ON_FAILURE |
|
449 | - ); |
|
450 | - if (empty($request_uri)) { |
|
451 | - // fallback sanitization if the above fails |
|
452 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
453 | - } |
|
454 | - if ($relativeToWpRoot) { |
|
455 | - $home_path = untrailingslashit( |
|
456 | - parse_url( |
|
457 | - home_url(), |
|
458 | - PHP_URL_PATH |
|
459 | - ) |
|
460 | - ); |
|
461 | - $request_uri = str_replace( |
|
462 | - $home_path, |
|
463 | - '', |
|
464 | - $request_uri |
|
465 | - ); |
|
466 | - } |
|
467 | - return $request_uri; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public function userAgent() |
|
474 | - { |
|
475 | - return $this->user_agent; |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * @param string $user_agent |
|
481 | - */ |
|
482 | - public function setUserAgent($user_agent = '') |
|
483 | - { |
|
484 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
485 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
486 | - } |
|
487 | - $this->user_agent = $user_agent; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * @return bool |
|
493 | - */ |
|
494 | - public function isBot() |
|
495 | - { |
|
496 | - return $this->is_bot; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param bool $is_bot |
|
502 | - */ |
|
503 | - public function setIsBot($is_bot) |
|
504 | - { |
|
505 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @return bool |
|
511 | - */ |
|
512 | - public function isActivation() |
|
513 | - { |
|
514 | - return $this->request_type->isActivation(); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * @param $is_activation |
|
520 | - * @return bool |
|
521 | - */ |
|
522 | - public function setIsActivation($is_activation) |
|
523 | - { |
|
524 | - return $this->request_type->setIsActivation($is_activation); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @return bool |
|
530 | - */ |
|
531 | - public function isAdmin() |
|
532 | - { |
|
533 | - return $this->request_type->isAdmin(); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @return bool |
|
539 | - */ |
|
540 | - public function isAdminAjax() |
|
541 | - { |
|
542 | - return $this->request_type->isAdminAjax(); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * @return bool |
|
548 | - */ |
|
549 | - public function isAjax() |
|
550 | - { |
|
551 | - return $this->request_type->isAjax(); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @return bool |
|
557 | - */ |
|
558 | - public function isEeAjax() |
|
559 | - { |
|
560 | - return $this->request_type->isEeAjax(); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * @return bool |
|
566 | - */ |
|
567 | - public function isOtherAjax() |
|
568 | - { |
|
569 | - return $this->request_type->isOtherAjax(); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * @return bool |
|
575 | - */ |
|
576 | - public function isApi() |
|
577 | - { |
|
578 | - return $this->request_type->isApi(); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @return bool |
|
584 | - */ |
|
585 | - public function isCli() |
|
586 | - { |
|
587 | - return $this->request_type->isCli(); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * @return bool |
|
593 | - */ |
|
594 | - public function isCron() |
|
595 | - { |
|
596 | - return $this->request_type->isCron(); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @return bool |
|
602 | - */ |
|
603 | - public function isFeed() |
|
604 | - { |
|
605 | - return $this->request_type->isFeed(); |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @return bool |
|
611 | - */ |
|
612 | - public function isFrontend() |
|
613 | - { |
|
614 | - return $this->request_type->isFrontend(); |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * @return bool |
|
620 | - */ |
|
621 | - public function isFrontAjax() |
|
622 | - { |
|
623 | - return $this->request_type->isFrontAjax(); |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * @return bool |
|
629 | - */ |
|
630 | - public function isGQL() |
|
631 | - { |
|
632 | - return $this->request_type->isGQL(); |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * @return bool |
|
638 | - */ |
|
639 | - public function isIframe() |
|
640 | - { |
|
641 | - return $this->request_type->isIframe(); |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - /** |
|
646 | - * @return bool |
|
647 | - */ |
|
648 | - public function isWordPressApi() |
|
649 | - { |
|
650 | - return $this->request_type->isWordPressApi(); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * @return bool |
|
657 | - */ |
|
658 | - public function isWordPressHeartbeat() |
|
659 | - { |
|
660 | - return $this->request_type->isWordPressHeartbeat(); |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * @return bool |
|
667 | - */ |
|
668 | - public function isWordPressScrape() |
|
669 | - { |
|
670 | - return $this->request_type->isWordPressScrape(); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * @return string |
|
676 | - */ |
|
677 | - public function slug() |
|
678 | - { |
|
679 | - return $this->request_type->slug(); |
|
680 | - } |
|
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 | + * $_FILES parameters |
|
50 | + * |
|
51 | + * @var array $files |
|
52 | + */ |
|
53 | + private $files; |
|
54 | + |
|
55 | + /** |
|
56 | + * $_REQUEST parameters |
|
57 | + * |
|
58 | + * @var array $request |
|
59 | + */ |
|
60 | + private $request; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var RequestTypeContextCheckerInterface |
|
64 | + */ |
|
65 | + private $request_type; |
|
66 | + |
|
67 | + /** |
|
68 | + * IP address for request |
|
69 | + * |
|
70 | + * @var string $ip_address |
|
71 | + */ |
|
72 | + private $ip_address; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var string $user_agent |
|
76 | + */ |
|
77 | + private $user_agent; |
|
78 | + |
|
79 | + /** |
|
80 | + * true if current user appears to be some kind of bot |
|
81 | + * |
|
82 | + * @var bool $is_bot |
|
83 | + */ |
|
84 | + private $is_bot; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $get |
|
89 | + * @param array $post |
|
90 | + * @param array $cookie |
|
91 | + * @param array $server |
|
92 | + * @param array $files |
|
93 | + */ |
|
94 | + public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
95 | + { |
|
96 | + // grab request vars |
|
97 | + $this->get = $get; |
|
98 | + $this->post = $post; |
|
99 | + $this->cookie = $cookie; |
|
100 | + $this->server = $server; |
|
101 | + $this->files = $files; |
|
102 | + $this->request = array_merge($this->get, $this->post); |
|
103 | + $this->ip_address = $this->visitorIp(); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param RequestTypeContextCheckerInterface $type |
|
109 | + */ |
|
110 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
111 | + { |
|
112 | + $this->request_type = $type; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function getParams() |
|
120 | + { |
|
121 | + return $this->get; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function postParams() |
|
129 | + { |
|
130 | + return $this->post; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function cookieParams() |
|
138 | + { |
|
139 | + return $this->cookie; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + public function serverParams() |
|
147 | + { |
|
148 | + return $this->server; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public function filesParams() |
|
156 | + { |
|
157 | + return $this->files; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * returns contents of $_REQUEST |
|
163 | + * |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public function requestParams() |
|
167 | + { |
|
168 | + return $this->request; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $key |
|
174 | + * @param $value |
|
175 | + * @param bool $override_ee |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + public function setRequestParam($key, $value, $override_ee = false) |
|
179 | + { |
|
180 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
181 | + if ($key !== 'ee' |
|
182 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
183 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
184 | + ) { |
|
185 | + $this->request[ $key ] = $value; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * returns the value for a request param if the given key exists |
|
192 | + * |
|
193 | + * @param $key |
|
194 | + * @param null $default |
|
195 | + * @return mixed |
|
196 | + */ |
|
197 | + public function getRequestParam($key, $default = null) |
|
198 | + { |
|
199 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * check if param exists |
|
205 | + * |
|
206 | + * @param $key |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function requestParamIsSet($key) |
|
210 | + { |
|
211 | + return $this->requestParameterDrillDown($key); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
217 | + * and return the value for the first match found |
|
218 | + * wildcards can be either of the following: |
|
219 | + * ? to represent a single character of any type |
|
220 | + * * to represent one or more characters of any type |
|
221 | + * |
|
222 | + * @param string $pattern |
|
223 | + * @param null|mixed $default |
|
224 | + * @return mixed |
|
225 | + */ |
|
226 | + public function getMatch($pattern, $default = null) |
|
227 | + { |
|
228 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
234 | + * wildcards can be either of the following: |
|
235 | + * ? to represent a single character of any type |
|
236 | + * * to represent one or more characters of any type |
|
237 | + * returns true if a match is found or false if not |
|
238 | + * |
|
239 | + * @param string $pattern |
|
240 | + * @return bool |
|
241 | + */ |
|
242 | + public function matches($pattern) |
|
243 | + { |
|
244 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
250 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
251 | + * and used to search through the current request's parameter keys |
|
252 | + * @param array $request_params The array of request parameters to search through |
|
253 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
254 | + * Default is null |
|
255 | + * @param string $return [optional] Controls what kind of value is returned. |
|
256 | + * Options are: |
|
257 | + * 'bool' will return true or false if match is found or not |
|
258 | + * 'key' will return the first key found that matches the supplied pattern |
|
259 | + * 'value' will return the value for the first request parameter |
|
260 | + * whose key matches the supplied pattern |
|
261 | + * Default is 'value' |
|
262 | + * @return boolean|string |
|
263 | + */ |
|
264 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
265 | + { |
|
266 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
267 | + ? $return |
|
268 | + : 'is_set'; |
|
269 | + // replace wildcard chars with regex chars |
|
270 | + $pattern = str_replace( |
|
271 | + array("\*", "\?"), |
|
272 | + array('.*', '.'), |
|
273 | + preg_quote($pattern, '/') |
|
274 | + ); |
|
275 | + foreach ($request_params as $key => $request_param) { |
|
276 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
277 | + // return value for request param |
|
278 | + if ($return === 'value') { |
|
279 | + return $request_params[ $key ]; |
|
280 | + } |
|
281 | + // or actual key or true just to indicate it was found |
|
282 | + return $return === 'key' ? $key : true; |
|
283 | + } |
|
284 | + } |
|
285 | + // match not found so return default value or false |
|
286 | + return $return === 'value' ? $default : false; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
292 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
293 | + * by using square brackets to surround keys for deeper array elements. |
|
294 | + * For example : |
|
295 | + * if the supplied $key was: "first[second][third]" |
|
296 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
297 | + * Given the following request parameters: |
|
298 | + * array( |
|
299 | + * 'first' => array( |
|
300 | + * 'second' => array( |
|
301 | + * 'third' => 'has a value' |
|
302 | + * ) |
|
303 | + * ) |
|
304 | + * ) |
|
305 | + * would return true if default parameters were set |
|
306 | + * |
|
307 | + * @param string $callback |
|
308 | + * @param $key |
|
309 | + * @param null $default |
|
310 | + * @param array $request_params |
|
311 | + * @return bool|mixed|null |
|
312 | + */ |
|
313 | + private function requestParameterDrillDown( |
|
314 | + $key, |
|
315 | + $default = null, |
|
316 | + $callback = 'is_set', |
|
317 | + array $request_params = array() |
|
318 | + ) { |
|
319 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
320 | + ? $callback |
|
321 | + : 'is_set'; |
|
322 | + $request_params = ! empty($request_params) |
|
323 | + ? $request_params |
|
324 | + : $this->request; |
|
325 | + // does incoming key represent an array like 'first[second][third]' ? |
|
326 | + if (strpos($key, '[') !== false) { |
|
327 | + // turn it into an actual array |
|
328 | + $key = str_replace(']', '', $key); |
|
329 | + $keys = explode('[', $key); |
|
330 | + $key = array_shift($keys); |
|
331 | + if ($callback === 'match') { |
|
332 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
333 | + $key = $real_key ? $real_key : $key; |
|
334 | + } |
|
335 | + // check if top level key exists |
|
336 | + if (isset($request_params[ $key ])) { |
|
337 | + // build a new key to pass along like: 'second[third]' |
|
338 | + // or just 'second' depending on depth of keys |
|
339 | + $key_string = array_shift($keys); |
|
340 | + if (! empty($keys)) { |
|
341 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
342 | + } |
|
343 | + return $this->requestParameterDrillDown( |
|
344 | + $key_string, |
|
345 | + $default, |
|
346 | + $callback, |
|
347 | + $request_params[ $key ] |
|
348 | + ); |
|
349 | + } |
|
350 | + } |
|
351 | + if ($callback === 'is_set') { |
|
352 | + return isset($request_params[ $key ]); |
|
353 | + } |
|
354 | + if ($callback === 'match') { |
|
355 | + return $this->match($key, $request_params, $default); |
|
356 | + } |
|
357 | + return isset($request_params[ $key ]) |
|
358 | + ? $request_params[ $key ] |
|
359 | + : $default; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * remove param |
|
365 | + * |
|
366 | + * @param $key |
|
367 | + * @param bool $unset_from_global_too |
|
368 | + */ |
|
369 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
370 | + { |
|
371 | + // because unset may not actually remove var |
|
372 | + $this->request[ $key ] = null; |
|
373 | + unset($this->request[ $key ]); |
|
374 | + if ($unset_from_global_too) { |
|
375 | + unset($_REQUEST[ $key ]); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * remove params |
|
382 | + * |
|
383 | + * @param array $keys |
|
384 | + * @param bool $unset_from_global_too |
|
385 | + */ |
|
386 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
387 | + { |
|
388 | + foreach ($keys as $key) { |
|
389 | + $this->unSetRequestParam($key, $unset_from_global_too); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function ipAddress() |
|
398 | + { |
|
399 | + return $this->ip_address; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * attempt to get IP address of current visitor from server |
|
405 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
406 | + * |
|
407 | + * @access public |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + private function visitorIp() |
|
411 | + { |
|
412 | + $visitor_ip = '0.0.0.0'; |
|
413 | + $server_keys = array( |
|
414 | + 'HTTP_CLIENT_IP', |
|
415 | + 'HTTP_X_FORWARDED_FOR', |
|
416 | + 'HTTP_X_FORWARDED', |
|
417 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
418 | + 'HTTP_FORWARDED_FOR', |
|
419 | + 'HTTP_FORWARDED', |
|
420 | + 'REMOTE_ADDR', |
|
421 | + ); |
|
422 | + foreach ($server_keys as $key) { |
|
423 | + if (isset($this->server[ $key ])) { |
|
424 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
425 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
426 | + $visitor_ip = $ip; |
|
427 | + } |
|
428 | + } |
|
429 | + } |
|
430 | + } |
|
431 | + return $visitor_ip; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
437 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
438 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
439 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function requestUri($relativeToWpRoot = false) |
|
443 | + { |
|
444 | + $request_uri = filter_input( |
|
445 | + INPUT_SERVER, |
|
446 | + 'REQUEST_URI', |
|
447 | + FILTER_SANITIZE_URL, |
|
448 | + FILTER_NULL_ON_FAILURE |
|
449 | + ); |
|
450 | + if (empty($request_uri)) { |
|
451 | + // fallback sanitization if the above fails |
|
452 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
453 | + } |
|
454 | + if ($relativeToWpRoot) { |
|
455 | + $home_path = untrailingslashit( |
|
456 | + parse_url( |
|
457 | + home_url(), |
|
458 | + PHP_URL_PATH |
|
459 | + ) |
|
460 | + ); |
|
461 | + $request_uri = str_replace( |
|
462 | + $home_path, |
|
463 | + '', |
|
464 | + $request_uri |
|
465 | + ); |
|
466 | + } |
|
467 | + return $request_uri; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public function userAgent() |
|
474 | + { |
|
475 | + return $this->user_agent; |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * @param string $user_agent |
|
481 | + */ |
|
482 | + public function setUserAgent($user_agent = '') |
|
483 | + { |
|
484 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
485 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
486 | + } |
|
487 | + $this->user_agent = $user_agent; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * @return bool |
|
493 | + */ |
|
494 | + public function isBot() |
|
495 | + { |
|
496 | + return $this->is_bot; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param bool $is_bot |
|
502 | + */ |
|
503 | + public function setIsBot($is_bot) |
|
504 | + { |
|
505 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @return bool |
|
511 | + */ |
|
512 | + public function isActivation() |
|
513 | + { |
|
514 | + return $this->request_type->isActivation(); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * @param $is_activation |
|
520 | + * @return bool |
|
521 | + */ |
|
522 | + public function setIsActivation($is_activation) |
|
523 | + { |
|
524 | + return $this->request_type->setIsActivation($is_activation); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @return bool |
|
530 | + */ |
|
531 | + public function isAdmin() |
|
532 | + { |
|
533 | + return $this->request_type->isAdmin(); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @return bool |
|
539 | + */ |
|
540 | + public function isAdminAjax() |
|
541 | + { |
|
542 | + return $this->request_type->isAdminAjax(); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * @return bool |
|
548 | + */ |
|
549 | + public function isAjax() |
|
550 | + { |
|
551 | + return $this->request_type->isAjax(); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @return bool |
|
557 | + */ |
|
558 | + public function isEeAjax() |
|
559 | + { |
|
560 | + return $this->request_type->isEeAjax(); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * @return bool |
|
566 | + */ |
|
567 | + public function isOtherAjax() |
|
568 | + { |
|
569 | + return $this->request_type->isOtherAjax(); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * @return bool |
|
575 | + */ |
|
576 | + public function isApi() |
|
577 | + { |
|
578 | + return $this->request_type->isApi(); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @return bool |
|
584 | + */ |
|
585 | + public function isCli() |
|
586 | + { |
|
587 | + return $this->request_type->isCli(); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * @return bool |
|
593 | + */ |
|
594 | + public function isCron() |
|
595 | + { |
|
596 | + return $this->request_type->isCron(); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @return bool |
|
602 | + */ |
|
603 | + public function isFeed() |
|
604 | + { |
|
605 | + return $this->request_type->isFeed(); |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @return bool |
|
611 | + */ |
|
612 | + public function isFrontend() |
|
613 | + { |
|
614 | + return $this->request_type->isFrontend(); |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * @return bool |
|
620 | + */ |
|
621 | + public function isFrontAjax() |
|
622 | + { |
|
623 | + return $this->request_type->isFrontAjax(); |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * @return bool |
|
629 | + */ |
|
630 | + public function isGQL() |
|
631 | + { |
|
632 | + return $this->request_type->isGQL(); |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * @return bool |
|
638 | + */ |
|
639 | + public function isIframe() |
|
640 | + { |
|
641 | + return $this->request_type->isIframe(); |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + /** |
|
646 | + * @return bool |
|
647 | + */ |
|
648 | + public function isWordPressApi() |
|
649 | + { |
|
650 | + return $this->request_type->isWordPressApi(); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * @return bool |
|
657 | + */ |
|
658 | + public function isWordPressHeartbeat() |
|
659 | + { |
|
660 | + return $this->request_type->isWordPressHeartbeat(); |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * @return bool |
|
667 | + */ |
|
668 | + public function isWordPressScrape() |
|
669 | + { |
|
670 | + return $this->request_type->isWordPressScrape(); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * @return string |
|
676 | + */ |
|
677 | + public function slug() |
|
678 | + { |
|
679 | + return $this->request_type->slug(); |
|
680 | + } |
|
681 | 681 | } |
@@ -17,293 +17,293 @@ |
||
17 | 17 | class CustomPostTypeDefinitions |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Core_Config |
|
22 | - */ |
|
23 | - public $core_config; |
|
20 | + /** |
|
21 | + * @var EE_Core_Config |
|
22 | + */ |
|
23 | + public $core_config; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array $custom_post_types |
|
27 | - */ |
|
28 | - private $custom_post_types; |
|
25 | + /** |
|
26 | + * @var array $custom_post_types |
|
27 | + */ |
|
28 | + private $custom_post_types; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var LoaderInterface $loader |
|
32 | - */ |
|
33 | - private $loader; |
|
30 | + /** |
|
31 | + * @var LoaderInterface $loader |
|
32 | + */ |
|
33 | + private $loader; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * EspressoCustomPostTypeDefinitions constructor. |
|
38 | - * |
|
39 | - * @param EE_Core_Config $core_config |
|
40 | - * @param LoaderInterface $loader |
|
41 | - */ |
|
42 | - public function __construct(EE_Core_Config $core_config, LoaderInterface $loader) |
|
43 | - { |
|
44 | - $this->core_config = $core_config; |
|
45 | - $this->loader = $loader; |
|
46 | - $this->setDefinitions(); |
|
47 | - } |
|
36 | + /** |
|
37 | + * EspressoCustomPostTypeDefinitions constructor. |
|
38 | + * |
|
39 | + * @param EE_Core_Config $core_config |
|
40 | + * @param LoaderInterface $loader |
|
41 | + */ |
|
42 | + public function __construct(EE_Core_Config $core_config, LoaderInterface $loader) |
|
43 | + { |
|
44 | + $this->core_config = $core_config; |
|
45 | + $this->loader = $loader; |
|
46 | + $this->setDefinitions(); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * defines Espresso Custom Post Types |
|
52 | - * NOTE the ['args']['page_templates'] array index is something specific to our CPTs |
|
53 | - * and not part of the WP custom post type api. |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - private function setDefinitions() |
|
58 | - { |
|
59 | - $this->custom_post_types = array( |
|
60 | - 'espresso_events' => array( |
|
61 | - 'singular_name' => esc_html__('Event', 'event_espresso'), |
|
62 | - 'plural_name' => esc_html__('Events', 'event_espresso'), |
|
63 | - 'singular_slug' => esc_html__('event', 'event_espresso'), |
|
64 | - 'plural_slug' => $this->core_config->event_cpt_slug, |
|
65 | - 'class_name' => 'EE_Event', |
|
66 | - 'model_name' => 'EEM_Event', |
|
67 | - 'args' => array( |
|
68 | - 'public' => true, |
|
69 | - 'show_in_nav_menus' => true, |
|
70 | - 'show_in_graphql' => true, |
|
71 | - 'graphql_single_name' => __( 'Event', 'event_espresso' ), |
|
72 | - 'graphql_plural_name' => __( 'Events', 'event_espresso' ), |
|
73 | - 'capability_type' => 'event', |
|
74 | - 'capabilities' => array( |
|
75 | - 'edit_post' => 'ee_edit_event', |
|
76 | - 'read_post' => 'ee_read_event', |
|
77 | - 'delete_post' => 'ee_delete_event', |
|
78 | - 'edit_posts' => 'ee_edit_events', |
|
79 | - 'edit_others_posts' => 'ee_edit_others_events', |
|
80 | - 'publish_posts' => 'ee_publish_events', |
|
81 | - 'read_private_posts' => 'ee_read_private_events', |
|
82 | - 'delete_posts' => 'ee_delete_events', |
|
83 | - 'delete_private_posts' => 'ee_delete_private_events', |
|
84 | - 'delete_published_posts' => 'ee_delete_published_events', |
|
85 | - 'delete_others_posts' => 'ee_delete_others_events', |
|
86 | - 'edit_private_posts' => 'ee_edit_private_events', |
|
87 | - 'edit_published_posts' => 'ee_edit_published_events', |
|
88 | - ), |
|
89 | - 'taxonomies' => array( |
|
90 | - 'espresso_event_categories', |
|
91 | - 'espresso_event_type', |
|
92 | - 'post_tag', |
|
93 | - ), |
|
94 | - 'page_templates' => true, |
|
95 | - ), |
|
96 | - ), |
|
97 | - 'espresso_venues' => array( |
|
98 | - 'singular_name' => esc_html__('Venue', 'event_espresso'), |
|
99 | - 'plural_name' => esc_html__('Venues', 'event_espresso'), |
|
100 | - 'singular_slug' => esc_html__('venue', 'event_espresso'), |
|
101 | - 'plural_slug' => esc_html__('venues', 'event_espresso'), |
|
102 | - 'class_name' => 'EE_Venue', |
|
103 | - 'model_name' => 'EEM_Venue', |
|
104 | - 'args' => array( |
|
105 | - 'public' => true, |
|
106 | - 'show_in_nav_menus' => false, // by default this doesn't show for decaf, |
|
107 | - 'show_in_graphql' => true, |
|
108 | - 'graphql_single_name' => __( 'Venue', 'event_espresso' ), |
|
109 | - 'graphql_plural_name' => __( 'Venues', 'event_espresso' ), |
|
110 | - 'capability_type' => 'venue', |
|
111 | - 'capabilities' => array( |
|
112 | - 'edit_post' => 'ee_edit_venue', |
|
113 | - 'read_post' => 'ee_read_venue', |
|
114 | - 'delete_post' => 'ee_delete_venue', |
|
115 | - 'edit_posts' => 'ee_edit_venues', |
|
116 | - 'edit_others_posts' => 'ee_edit_others_venues', |
|
117 | - 'publish_posts' => 'ee_publish_venues', |
|
118 | - 'read_private_posts' => 'ee_read_private_venues', |
|
119 | - 'delete_posts' => 'ee_delete_venues', |
|
120 | - 'delete_private_posts' => 'ee_delete_private_venues', |
|
121 | - 'delete_published_posts' => 'ee_delete_published_venues', |
|
122 | - 'delete_others_posts' => 'ee_edit_others_venues', |
|
123 | - 'edit_private_posts' => 'ee_edit_private_venues', |
|
124 | - 'edit_published_posts' => 'ee_edit_published_venues', |
|
125 | - ), |
|
126 | - 'taxonomies' => array( |
|
127 | - 'espresso_venue_categories', |
|
128 | - 'post_tag', |
|
129 | - ), |
|
130 | - 'page_templates' => true, |
|
131 | - ), |
|
132 | - ), |
|
133 | - 'espresso_attendees' => array( |
|
134 | - 'singular_name' => esc_html__('Contact', 'event_espresso'), |
|
135 | - 'plural_name' => esc_html__('Contacts', 'event_espresso'), |
|
136 | - 'singular_slug' => esc_html__('contact', 'event_espresso'), |
|
137 | - 'plural_slug' => esc_html__('contacts', 'event_espresso'), |
|
138 | - 'class_name' => 'EE_Attendee', |
|
139 | - 'model_name' => 'EEM_Attendee', |
|
140 | - 'args' => array( |
|
141 | - 'public' => false, |
|
142 | - 'publicly_queryable' => false, |
|
143 | - 'hierarchical' => false, |
|
144 | - 'has_archive' => false, |
|
145 | - 'supports' => array( |
|
146 | - 'editor', |
|
147 | - 'thumbnail', |
|
148 | - 'excerpt', |
|
149 | - 'custom-fields', |
|
150 | - 'comments', |
|
151 | - ), |
|
152 | - 'taxonomies' => array('post_tag'), |
|
153 | - 'capability_type' => 'contact', |
|
154 | - 'capabilities' => array( |
|
155 | - 'edit_post' => 'ee_edit_contact', |
|
156 | - 'read_post' => 'ee_read_contact', |
|
157 | - 'delete_post' => 'ee_delete_contact', |
|
158 | - 'edit_posts' => 'ee_edit_contacts', |
|
159 | - 'edit_others_posts' => 'ee_edit_contacts', |
|
160 | - 'publish_posts' => 'ee_edit_contacts', |
|
161 | - 'read_private_posts' => 'ee_edit_contacts', |
|
162 | - 'delete_posts' => 'ee_delete_contacts', |
|
163 | - 'delete_private_posts' => 'ee_delete_contacts', |
|
164 | - 'delete_published_posts' => 'ee_delete_contacts', |
|
165 | - 'delete_others_posts' => 'ee_delete_contacts', |
|
166 | - 'edit_private_posts' => 'ee_edit_contacts', |
|
167 | - 'edit_published_posts' => 'ee_edit_contacts', |
|
168 | - ), |
|
169 | - ), |
|
170 | - ), |
|
171 | - ); |
|
172 | - } |
|
50 | + /** |
|
51 | + * defines Espresso Custom Post Types |
|
52 | + * NOTE the ['args']['page_templates'] array index is something specific to our CPTs |
|
53 | + * and not part of the WP custom post type api. |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + private function setDefinitions() |
|
58 | + { |
|
59 | + $this->custom_post_types = array( |
|
60 | + 'espresso_events' => array( |
|
61 | + 'singular_name' => esc_html__('Event', 'event_espresso'), |
|
62 | + 'plural_name' => esc_html__('Events', 'event_espresso'), |
|
63 | + 'singular_slug' => esc_html__('event', 'event_espresso'), |
|
64 | + 'plural_slug' => $this->core_config->event_cpt_slug, |
|
65 | + 'class_name' => 'EE_Event', |
|
66 | + 'model_name' => 'EEM_Event', |
|
67 | + 'args' => array( |
|
68 | + 'public' => true, |
|
69 | + 'show_in_nav_menus' => true, |
|
70 | + 'show_in_graphql' => true, |
|
71 | + 'graphql_single_name' => __( 'Event', 'event_espresso' ), |
|
72 | + 'graphql_plural_name' => __( 'Events', 'event_espresso' ), |
|
73 | + 'capability_type' => 'event', |
|
74 | + 'capabilities' => array( |
|
75 | + 'edit_post' => 'ee_edit_event', |
|
76 | + 'read_post' => 'ee_read_event', |
|
77 | + 'delete_post' => 'ee_delete_event', |
|
78 | + 'edit_posts' => 'ee_edit_events', |
|
79 | + 'edit_others_posts' => 'ee_edit_others_events', |
|
80 | + 'publish_posts' => 'ee_publish_events', |
|
81 | + 'read_private_posts' => 'ee_read_private_events', |
|
82 | + 'delete_posts' => 'ee_delete_events', |
|
83 | + 'delete_private_posts' => 'ee_delete_private_events', |
|
84 | + 'delete_published_posts' => 'ee_delete_published_events', |
|
85 | + 'delete_others_posts' => 'ee_delete_others_events', |
|
86 | + 'edit_private_posts' => 'ee_edit_private_events', |
|
87 | + 'edit_published_posts' => 'ee_edit_published_events', |
|
88 | + ), |
|
89 | + 'taxonomies' => array( |
|
90 | + 'espresso_event_categories', |
|
91 | + 'espresso_event_type', |
|
92 | + 'post_tag', |
|
93 | + ), |
|
94 | + 'page_templates' => true, |
|
95 | + ), |
|
96 | + ), |
|
97 | + 'espresso_venues' => array( |
|
98 | + 'singular_name' => esc_html__('Venue', 'event_espresso'), |
|
99 | + 'plural_name' => esc_html__('Venues', 'event_espresso'), |
|
100 | + 'singular_slug' => esc_html__('venue', 'event_espresso'), |
|
101 | + 'plural_slug' => esc_html__('venues', 'event_espresso'), |
|
102 | + 'class_name' => 'EE_Venue', |
|
103 | + 'model_name' => 'EEM_Venue', |
|
104 | + 'args' => array( |
|
105 | + 'public' => true, |
|
106 | + 'show_in_nav_menus' => false, // by default this doesn't show for decaf, |
|
107 | + 'show_in_graphql' => true, |
|
108 | + 'graphql_single_name' => __( 'Venue', 'event_espresso' ), |
|
109 | + 'graphql_plural_name' => __( 'Venues', 'event_espresso' ), |
|
110 | + 'capability_type' => 'venue', |
|
111 | + 'capabilities' => array( |
|
112 | + 'edit_post' => 'ee_edit_venue', |
|
113 | + 'read_post' => 'ee_read_venue', |
|
114 | + 'delete_post' => 'ee_delete_venue', |
|
115 | + 'edit_posts' => 'ee_edit_venues', |
|
116 | + 'edit_others_posts' => 'ee_edit_others_venues', |
|
117 | + 'publish_posts' => 'ee_publish_venues', |
|
118 | + 'read_private_posts' => 'ee_read_private_venues', |
|
119 | + 'delete_posts' => 'ee_delete_venues', |
|
120 | + 'delete_private_posts' => 'ee_delete_private_venues', |
|
121 | + 'delete_published_posts' => 'ee_delete_published_venues', |
|
122 | + 'delete_others_posts' => 'ee_edit_others_venues', |
|
123 | + 'edit_private_posts' => 'ee_edit_private_venues', |
|
124 | + 'edit_published_posts' => 'ee_edit_published_venues', |
|
125 | + ), |
|
126 | + 'taxonomies' => array( |
|
127 | + 'espresso_venue_categories', |
|
128 | + 'post_tag', |
|
129 | + ), |
|
130 | + 'page_templates' => true, |
|
131 | + ), |
|
132 | + ), |
|
133 | + 'espresso_attendees' => array( |
|
134 | + 'singular_name' => esc_html__('Contact', 'event_espresso'), |
|
135 | + 'plural_name' => esc_html__('Contacts', 'event_espresso'), |
|
136 | + 'singular_slug' => esc_html__('contact', 'event_espresso'), |
|
137 | + 'plural_slug' => esc_html__('contacts', 'event_espresso'), |
|
138 | + 'class_name' => 'EE_Attendee', |
|
139 | + 'model_name' => 'EEM_Attendee', |
|
140 | + 'args' => array( |
|
141 | + 'public' => false, |
|
142 | + 'publicly_queryable' => false, |
|
143 | + 'hierarchical' => false, |
|
144 | + 'has_archive' => false, |
|
145 | + 'supports' => array( |
|
146 | + 'editor', |
|
147 | + 'thumbnail', |
|
148 | + 'excerpt', |
|
149 | + 'custom-fields', |
|
150 | + 'comments', |
|
151 | + ), |
|
152 | + 'taxonomies' => array('post_tag'), |
|
153 | + 'capability_type' => 'contact', |
|
154 | + 'capabilities' => array( |
|
155 | + 'edit_post' => 'ee_edit_contact', |
|
156 | + 'read_post' => 'ee_read_contact', |
|
157 | + 'delete_post' => 'ee_delete_contact', |
|
158 | + 'edit_posts' => 'ee_edit_contacts', |
|
159 | + 'edit_others_posts' => 'ee_edit_contacts', |
|
160 | + 'publish_posts' => 'ee_edit_contacts', |
|
161 | + 'read_private_posts' => 'ee_edit_contacts', |
|
162 | + 'delete_posts' => 'ee_delete_contacts', |
|
163 | + 'delete_private_posts' => 'ee_delete_contacts', |
|
164 | + 'delete_published_posts' => 'ee_delete_contacts', |
|
165 | + 'delete_others_posts' => 'ee_delete_contacts', |
|
166 | + 'edit_private_posts' => 'ee_edit_contacts', |
|
167 | + 'edit_published_posts' => 'ee_edit_contacts', |
|
168 | + ), |
|
169 | + ), |
|
170 | + ), |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function getDefinitions() |
|
179 | - { |
|
180 | - return (array) apply_filters( |
|
181 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
182 | - // legacy filter applied for now, |
|
183 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
184 | - apply_filters( |
|
185 | - 'FHEE__EE_Register_CPTs__get_CPTs__cpts', |
|
186 | - $this->custom_post_types |
|
187 | - ) |
|
188 | - ); |
|
189 | - } |
|
175 | + /** |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function getDefinitions() |
|
179 | + { |
|
180 | + return (array) apply_filters( |
|
181 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
182 | + // legacy filter applied for now, |
|
183 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
184 | + apply_filters( |
|
185 | + 'FHEE__EE_Register_CPTs__get_CPTs__cpts', |
|
186 | + $this->custom_post_types |
|
187 | + ) |
|
188 | + ); |
|
189 | + } |
|
190 | 190 | |
191 | 191 | |
192 | - /** |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - public function getCustomPostTypeSlugs() |
|
196 | - { |
|
197 | - return array_keys($this->getDefinitions()); |
|
198 | - } |
|
192 | + /** |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + public function getCustomPostTypeSlugs() |
|
196 | + { |
|
197 | + return array_keys($this->getDefinitions()); |
|
198 | + } |
|
199 | 199 | |
200 | 200 | |
201 | - /** |
|
202 | - * This basically goes through the CPT array and returns only CPT's |
|
203 | - * that have the ['args']['public'] option set as false |
|
204 | - * |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function getPrivateCustomPostTypes() |
|
208 | - { |
|
209 | - $private_CPTs = array(); |
|
210 | - foreach ($this->getDefinitions() as $CPT => $details) { |
|
211 | - if (empty($details['args']['public'])) { |
|
212 | - $private_CPTs[ $CPT ] = $details; |
|
213 | - } |
|
214 | - } |
|
215 | - return $private_CPTs; |
|
216 | - } |
|
201 | + /** |
|
202 | + * This basically goes through the CPT array and returns only CPT's |
|
203 | + * that have the ['args']['public'] option set as false |
|
204 | + * |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function getPrivateCustomPostTypes() |
|
208 | + { |
|
209 | + $private_CPTs = array(); |
|
210 | + foreach ($this->getDefinitions() as $CPT => $details) { |
|
211 | + if (empty($details['args']['public'])) { |
|
212 | + $private_CPTs[ $CPT ] = $details; |
|
213 | + } |
|
214 | + } |
|
215 | + return $private_CPTs; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * This returns the corresponding model name for cpts registered by EE. |
|
221 | - * |
|
222 | - * @param string $post_type_slug If a slug is included, then attempt to retrieve |
|
223 | - * the model name for the given cpt slug. |
|
224 | - * Otherwise if empty, then we'll return |
|
225 | - * all cpt model names for cpts registered in EE. |
|
226 | - * @return array Empty array if no matching model names for the given slug |
|
227 | - * or an array of model names indexed by post type slug. |
|
228 | - */ |
|
229 | - public function getCustomPostTypeModelNames($post_type_slug = '') |
|
230 | - { |
|
231 | - $cpts = $this->getDefinitions(); |
|
232 | - // first if slug passed in... |
|
233 | - if (! empty($post_type_slug)) { |
|
234 | - // check that slug and cpt match |
|
235 | - if (! isset($cpts[ $post_type_slug ])) { |
|
236 | - return array(); |
|
237 | - } |
|
238 | - if (empty($cpts[ $post_type_slug ]['class_name']) |
|
239 | - && empty($cpts[ $post_type_slug ]['model_name']) |
|
240 | - ) { |
|
241 | - return array(); |
|
242 | - } |
|
243 | - // k let's get the model name for this cpt. |
|
244 | - return $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
245 | - } |
|
246 | - // if we made it here then we're returning an array of cpt model names indexed by post_type_slug. |
|
247 | - $cpt_models = array(); |
|
248 | - foreach ($cpts as $slug => $args) { |
|
249 | - $model = $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
250 | - if (! empty($model)) { |
|
251 | - $cpt_models[ $slug ] = $model; |
|
252 | - } |
|
253 | - } |
|
254 | - return $cpt_models; |
|
255 | - } |
|
219 | + /** |
|
220 | + * This returns the corresponding model name for cpts registered by EE. |
|
221 | + * |
|
222 | + * @param string $post_type_slug If a slug is included, then attempt to retrieve |
|
223 | + * the model name for the given cpt slug. |
|
224 | + * Otherwise if empty, then we'll return |
|
225 | + * all cpt model names for cpts registered in EE. |
|
226 | + * @return array Empty array if no matching model names for the given slug |
|
227 | + * or an array of model names indexed by post type slug. |
|
228 | + */ |
|
229 | + public function getCustomPostTypeModelNames($post_type_slug = '') |
|
230 | + { |
|
231 | + $cpts = $this->getDefinitions(); |
|
232 | + // first if slug passed in... |
|
233 | + if (! empty($post_type_slug)) { |
|
234 | + // check that slug and cpt match |
|
235 | + if (! isset($cpts[ $post_type_slug ])) { |
|
236 | + return array(); |
|
237 | + } |
|
238 | + if (empty($cpts[ $post_type_slug ]['class_name']) |
|
239 | + && empty($cpts[ $post_type_slug ]['model_name']) |
|
240 | + ) { |
|
241 | + return array(); |
|
242 | + } |
|
243 | + // k let's get the model name for this cpt. |
|
244 | + return $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
245 | + } |
|
246 | + // if we made it here then we're returning an array of cpt model names indexed by post_type_slug. |
|
247 | + $cpt_models = array(); |
|
248 | + foreach ($cpts as $slug => $args) { |
|
249 | + $model = $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
250 | + if (! empty($model)) { |
|
251 | + $cpt_models[ $slug ] = $model; |
|
252 | + } |
|
253 | + } |
|
254 | + return $cpt_models; |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * @param $post_type_slug |
|
260 | - * @param array $cpt |
|
261 | - * @return array |
|
262 | - */ |
|
263 | - private function getCustomPostTypeModelName($post_type_slug, array $cpt) |
|
264 | - { |
|
265 | - if (! empty($cpt['model_name'])) { |
|
266 | - return array($post_type_slug => $cpt['model_name']); |
|
267 | - } |
|
268 | - if (! empty($cpt['class_name'])) { |
|
269 | - return array( |
|
270 | - $post_type_slug => $this->deriveCptModelNameFromClassName($cpt['class_name']), |
|
271 | - ); |
|
272 | - } |
|
273 | - return array(); |
|
274 | - } |
|
258 | + /** |
|
259 | + * @param $post_type_slug |
|
260 | + * @param array $cpt |
|
261 | + * @return array |
|
262 | + */ |
|
263 | + private function getCustomPostTypeModelName($post_type_slug, array $cpt) |
|
264 | + { |
|
265 | + if (! empty($cpt['model_name'])) { |
|
266 | + return array($post_type_slug => $cpt['model_name']); |
|
267 | + } |
|
268 | + if (! empty($cpt['class_name'])) { |
|
269 | + return array( |
|
270 | + $post_type_slug => $this->deriveCptModelNameFromClassName($cpt['class_name']), |
|
271 | + ); |
|
272 | + } |
|
273 | + return array(); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | |
277 | - /** |
|
278 | - * @param string $class_name |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - private function deriveCptModelNameFromClassName($class_name) |
|
282 | - { |
|
283 | - return str_replace('EE', 'EEM', $class_name); |
|
284 | - } |
|
277 | + /** |
|
278 | + * @param string $class_name |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + private function deriveCptModelNameFromClassName($class_name) |
|
282 | + { |
|
283 | + return str_replace('EE', 'EEM', $class_name); |
|
284 | + } |
|
285 | 285 | |
286 | 286 | |
287 | - /** |
|
288 | - * This instantiates cpt models related to the cpts registered via EE. |
|
289 | - * |
|
290 | - * @since 4.6.16.rc.000 |
|
291 | - * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
292 | - * the cpt matching the given slug. Otherwise all cpt models will be |
|
293 | - * instantiated (if possible). |
|
294 | - * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
295 | - * EEM models indexed by post slug. |
|
296 | - */ |
|
297 | - public function getCustomPostTypeModels($post_type_slug = '') |
|
298 | - { |
|
299 | - $cpt_model_names = $this->getCustomPostTypeModelNames($post_type_slug); |
|
300 | - $instantiated = array(); |
|
301 | - foreach ($cpt_model_names as $slug => $model_name) { |
|
302 | - $model = $this->loader->getShared($model_name); |
|
303 | - if ($model instanceof EEM_CPT_Base) { |
|
304 | - $instantiated[ $slug ] = $model; |
|
305 | - } |
|
306 | - } |
|
307 | - return $instantiated; |
|
308 | - } |
|
287 | + /** |
|
288 | + * This instantiates cpt models related to the cpts registered via EE. |
|
289 | + * |
|
290 | + * @since 4.6.16.rc.000 |
|
291 | + * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
292 | + * the cpt matching the given slug. Otherwise all cpt models will be |
|
293 | + * instantiated (if possible). |
|
294 | + * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
295 | + * EEM models indexed by post slug. |
|
296 | + */ |
|
297 | + public function getCustomPostTypeModels($post_type_slug = '') |
|
298 | + { |
|
299 | + $cpt_model_names = $this->getCustomPostTypeModelNames($post_type_slug); |
|
300 | + $instantiated = array(); |
|
301 | + foreach ($cpt_model_names as $slug => $model_name) { |
|
302 | + $model = $this->loader->getShared($model_name); |
|
303 | + if ($model instanceof EEM_CPT_Base) { |
|
304 | + $instantiated[ $slug ] = $model; |
|
305 | + } |
|
306 | + } |
|
307 | + return $instantiated; |
|
308 | + } |
|
309 | 309 | } |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | 'public' => true, |
69 | 69 | 'show_in_nav_menus' => true, |
70 | 70 | 'show_in_graphql' => true, |
71 | - 'graphql_single_name' => __( 'Event', 'event_espresso' ), |
|
72 | - 'graphql_plural_name' => __( 'Events', 'event_espresso' ), |
|
71 | + 'graphql_single_name' => __('Event', 'event_espresso'), |
|
72 | + 'graphql_plural_name' => __('Events', 'event_espresso'), |
|
73 | 73 | 'capability_type' => 'event', |
74 | 74 | 'capabilities' => array( |
75 | 75 | 'edit_post' => 'ee_edit_event', |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | 'public' => true, |
106 | 106 | 'show_in_nav_menus' => false, // by default this doesn't show for decaf, |
107 | 107 | 'show_in_graphql' => true, |
108 | - 'graphql_single_name' => __( 'Venue', 'event_espresso' ), |
|
109 | - 'graphql_plural_name' => __( 'Venues', 'event_espresso' ), |
|
108 | + 'graphql_single_name' => __('Venue', 'event_espresso'), |
|
109 | + 'graphql_plural_name' => __('Venues', 'event_espresso'), |
|
110 | 110 | 'capability_type' => 'venue', |
111 | 111 | 'capabilities' => array( |
112 | 112 | 'edit_post' => 'ee_edit_venue', |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $private_CPTs = array(); |
210 | 210 | foreach ($this->getDefinitions() as $CPT => $details) { |
211 | 211 | if (empty($details['args']['public'])) { |
212 | - $private_CPTs[ $CPT ] = $details; |
|
212 | + $private_CPTs[$CPT] = $details; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | return $private_CPTs; |
@@ -230,25 +230,25 @@ discard block |
||
230 | 230 | { |
231 | 231 | $cpts = $this->getDefinitions(); |
232 | 232 | // first if slug passed in... |
233 | - if (! empty($post_type_slug)) { |
|
233 | + if ( ! empty($post_type_slug)) { |
|
234 | 234 | // check that slug and cpt match |
235 | - if (! isset($cpts[ $post_type_slug ])) { |
|
235 | + if ( ! isset($cpts[$post_type_slug])) { |
|
236 | 236 | return array(); |
237 | 237 | } |
238 | - if (empty($cpts[ $post_type_slug ]['class_name']) |
|
239 | - && empty($cpts[ $post_type_slug ]['model_name']) |
|
238 | + if (empty($cpts[$post_type_slug]['class_name']) |
|
239 | + && empty($cpts[$post_type_slug]['model_name']) |
|
240 | 240 | ) { |
241 | 241 | return array(); |
242 | 242 | } |
243 | 243 | // k let's get the model name for this cpt. |
244 | - return $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
244 | + return $this->getCustomPostTypeModelName($post_type_slug, $cpts[$post_type_slug]); |
|
245 | 245 | } |
246 | 246 | // if we made it here then we're returning an array of cpt model names indexed by post_type_slug. |
247 | 247 | $cpt_models = array(); |
248 | 248 | foreach ($cpts as $slug => $args) { |
249 | - $model = $this->getCustomPostTypeModelName($post_type_slug, $cpts[ $post_type_slug ]); |
|
250 | - if (! empty($model)) { |
|
251 | - $cpt_models[ $slug ] = $model; |
|
249 | + $model = $this->getCustomPostTypeModelName($post_type_slug, $cpts[$post_type_slug]); |
|
250 | + if ( ! empty($model)) { |
|
251 | + $cpt_models[$slug] = $model; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | return $cpt_models; |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | */ |
263 | 263 | private function getCustomPostTypeModelName($post_type_slug, array $cpt) |
264 | 264 | { |
265 | - if (! empty($cpt['model_name'])) { |
|
265 | + if ( ! empty($cpt['model_name'])) { |
|
266 | 266 | return array($post_type_slug => $cpt['model_name']); |
267 | 267 | } |
268 | - if (! empty($cpt['class_name'])) { |
|
268 | + if ( ! empty($cpt['class_name'])) { |
|
269 | 269 | return array( |
270 | 270 | $post_type_slug => $this->deriveCptModelNameFromClassName($cpt['class_name']), |
271 | 271 | ); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | foreach ($cpt_model_names as $slug => $model_name) { |
302 | 302 | $model = $this->loader->getShared($model_name); |
303 | 303 | if ($model instanceof EEM_CPT_Base) { |
304 | - $instantiated[ $slug ] = $model; |
|
304 | + $instantiated[$slug] = $model; |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | return $instantiated; |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | */ |
57 | 57 | class DatetimeConnectionResolver extends AbstractConnectionResolver { |
58 | 58 | |
59 | - /** |
|
60 | - * @return EEM_Datetime |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - */ |
|
59 | + /** |
|
60 | + * @return EEM_Datetime |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + */ |
|
66 | 66 | public function get_query() { |
67 | 67 | return EEM_Datetime::instance(); |
68 | 68 | } |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
119 | 119 | */ |
120 | 120 | $query_args['limit'] = min( |
121 | - max( absint( $first ), absint( $last ), 10 ), |
|
122 | - $this->query_amount |
|
123 | - ) + 1; |
|
121 | + max( absint( $first ), absint( $last ), 10 ), |
|
122 | + $this->query_amount |
|
123 | + ) + 1; |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | |
172 | - /** |
|
173 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
174 | - * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
175 | - * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
176 | - * now this gets the job done. |
|
177 | - * |
|
178 | - * @param array $query_args |
|
179 | - * @return array |
|
180 | - */ |
|
172 | + /** |
|
173 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
174 | + * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
175 | + * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
176 | + * now this gets the job done. |
|
177 | + * |
|
178 | + * @param array $query_args |
|
179 | + * @return array |
|
180 | + */ |
|
181 | 181 | public function sanitize_input_fields(array $query_args) { |
182 | 182 | |
183 | 183 | $arg_mapping = [ |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function get_items() { |
76 | 76 | |
77 | - $results = $this->query->get_col( $this->query_args ); |
|
77 | + $results = $this->query->get_col($this->query_args); |
|
78 | 78 | |
79 | - return ! empty( $results ) ? $results : []; |
|
79 | + return ! empty($results) ? $results : []; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function should_execute() { |
92 | 92 | |
93 | - if ( false === $this->should_execute ) { |
|
93 | + if (false === $this->should_execute) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * Prepare for later use |
113 | 113 | */ |
114 | - $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; |
|
115 | - $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; |
|
114 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
115 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
116 | 116 | |
117 | 117 | /** |
118 | 118 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
119 | 119 | */ |
120 | 120 | $query_args['limit'] = min( |
121 | - max( absint( $first ), absint( $last ), 10 ), |
|
121 | + max(absint($first), absint($last), 10), |
|
122 | 122 | $this->query_amount |
123 | 123 | ) + 1; |
124 | 124 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
127 | 127 | */ |
128 | 128 | $input_fields = []; |
129 | - if ( ! empty( $this->args['where'] ) ) { |
|
130 | - $input_fields = $this->sanitize_input_fields( $this->args['where'] ); |
|
129 | + if ( ! empty($this->args['where'])) { |
|
130 | + $input_fields = $this->sanitize_input_fields($this->args['where']); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * set the query to pull datetimes that belong to that event. |
138 | 138 | * We can set more cases for other source types. |
139 | 139 | */ |
140 | - if (is_object( $this->source )) { |
|
140 | + if (is_object($this->source)) { |
|
141 | 141 | switch (true) { |
142 | 142 | // It's surely an event |
143 | 143 | case $this->source instanceof Post: |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * Merge the input_fields with the default query_args |
160 | 160 | */ |
161 | - if ( ! empty( $input_fields ) ) { |
|
162 | - $query_args = array_merge( $query_args, $input_fields ); |
|
161 | + if ( ! empty($input_fields)) { |
|
162 | + $query_args = array_merge($query_args, $input_fields); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * Return the Query Args |
190 | 190 | */ |
191 | - return ! empty( $query_args ) && is_array( $query_args ) ? $query_args : []; |
|
191 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
192 | 192 | |
193 | 193 | } |
194 | 194 |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | class TicketConnectionResolver extends AbstractConnectionResolver { |
56 | 56 | |
57 | - /** |
|
58 | - * @return EEM_Ticket |
|
59 | - * @throws EE_Error |
|
60 | - * @throws InvalidArgumentException |
|
61 | - * @throws InvalidDataTypeException |
|
62 | - * @throws InvalidInterfaceException |
|
63 | - */ |
|
57 | + /** |
|
58 | + * @return EEM_Ticket |
|
59 | + * @throws EE_Error |
|
60 | + * @throws InvalidArgumentException |
|
61 | + * @throws InvalidDataTypeException |
|
62 | + * @throws InvalidInterfaceException |
|
63 | + */ |
|
64 | 64 | public function get_query() { |
65 | 65 | return EEM_Ticket::instance(); |
66 | 66 | } |
@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
101 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
102 | - * handle batch resolution of the posts. |
|
103 | - * |
|
104 | - * @return array |
|
105 | - * @throws EE_Error |
|
106 | - * @throws InvalidArgumentException |
|
107 | - * @throws ReflectionException |
|
108 | - * @throws InvalidDataTypeException |
|
109 | - * @throws InvalidInterfaceException |
|
110 | - */ |
|
99 | + /** |
|
100 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
101 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
102 | + * handle batch resolution of the posts. |
|
103 | + * |
|
104 | + * @return array |
|
105 | + * @throws EE_Error |
|
106 | + * @throws InvalidArgumentException |
|
107 | + * @throws ReflectionException |
|
108 | + * @throws InvalidDataTypeException |
|
109 | + * @throws InvalidInterfaceException |
|
110 | + */ |
|
111 | 111 | public function get_query_args() { |
112 | 112 | |
113 | 113 | $query_args = []; |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
123 | 123 | */ |
124 | 124 | $query_args['limit'] = min( |
125 | - max( absint( $first ), absint( $last ), 10 ), |
|
126 | - $this->query_amount |
|
127 | - ) + 1; |
|
125 | + max( absint( $first ), absint( $last ), 10 ), |
|
126 | + $this->query_amount |
|
127 | + ) + 1; |
|
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
164 | - * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
165 | - * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
166 | - * now this gets the job done. |
|
167 | - * |
|
168 | - * @param array $query_args |
|
169 | - * @return array |
|
170 | - */ |
|
162 | + /** |
|
163 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
164 | + * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
165 | + * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
166 | + * now this gets the job done. |
|
167 | + * |
|
168 | + * @param array $query_args |
|
169 | + * @return array |
|
170 | + */ |
|
171 | 171 | public function sanitize_input_fields(array $query_args) { |
172 | 172 | |
173 | 173 | $arg_mapping = [ |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function get_items() { |
74 | 74 | |
75 | - $results = $this->query->get_col( $this->query_args ); |
|
75 | + $results = $this->query->get_col($this->query_args); |
|
76 | 76 | |
77 | - return ! empty( $results ) ? $results : []; |
|
77 | + return ! empty($results) ? $results : []; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function should_execute() { |
90 | 90 | |
91 | - if ( false === $this->should_execute ) { |
|
91 | + if (false === $this->should_execute) { |
|
92 | 92 | return false; |
93 | 93 | } |
94 | 94 | |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | /** |
116 | 116 | * Prepare for later use |
117 | 117 | */ |
118 | - $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; |
|
119 | - $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; |
|
118 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
119 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
123 | 123 | */ |
124 | 124 | $query_args['limit'] = min( |
125 | - max( absint( $first ), absint( $last ), 10 ), |
|
125 | + max(absint($first), absint($last), 10), |
|
126 | 126 | $this->query_amount |
127 | 127 | ) + 1; |
128 | 128 | |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
131 | 131 | */ |
132 | 132 | $input_fields = []; |
133 | - if ( ! empty( $this->args['where'] ) ) { |
|
134 | - $input_fields = $this->sanitize_input_fields( $this->args['where'] ); |
|
133 | + if ( ! empty($this->args['where'])) { |
|
134 | + $input_fields = $this->sanitize_input_fields($this->args['where']); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
138 | 138 | * Determine where we're at in the Graph and adjust the query context appropriately. |
139 | 139 | */ |
140 | - if (is_object( $this->source )) { |
|
140 | + if (is_object($this->source)) { |
|
141 | 141 | switch (true) { |
142 | 142 | case $this->source instanceof EE_Datetime: |
143 | - $query_args[] = [ 'Datetime.DTT_ID' => $this->source->ID() ]; |
|
143 | + $query_args[] = ['Datetime.DTT_ID' => $this->source->ID()]; |
|
144 | 144 | break; |
145 | 145 | } |
146 | 146 | } |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | /** |
149 | 149 | * Merge the input_fields with the default query_args |
150 | 150 | */ |
151 | - if ( ! empty( $input_fields ) ) { |
|
152 | - $query_args = array_merge( $query_args, $input_fields ); |
|
151 | + if ( ! empty($input_fields)) { |
|
152 | + $query_args = array_merge($query_args, $input_fields); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | /** |
179 | 179 | * Return the Query Args |
180 | 180 | */ |
181 | - return ! empty( $query_args ) && is_array( $query_args ) ? $query_args : []; |
|
181 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
182 | 182 | |
183 | 183 | } |
184 | 184 |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | class VenueConnectionResolver extends AbstractConnectionResolver { |
56 | 56 | |
57 | - /** |
|
58 | - * @return EEM_Venue |
|
59 | - * @throws EE_Error |
|
60 | - * @throws InvalidArgumentException |
|
61 | - * @throws InvalidDataTypeException |
|
62 | - * @throws InvalidInterfaceException |
|
63 | - */ |
|
57 | + /** |
|
58 | + * @return EEM_Venue |
|
59 | + * @throws EE_Error |
|
60 | + * @throws InvalidArgumentException |
|
61 | + * @throws InvalidDataTypeException |
|
62 | + * @throws InvalidInterfaceException |
|
63 | + */ |
|
64 | 64 | public function get_query() { |
65 | 65 | return EEM_Venue::instance(); |
66 | 66 | } |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
117 | 117 | */ |
118 | 118 | $query_args['limit'] = min( |
119 | - max( absint( $first ), absint( $last ), 10 ), |
|
120 | - $this->query_amount |
|
121 | - ) + 1; |
|
119 | + max( absint( $first ), absint( $last ), 10 ), |
|
120 | + $this->query_amount |
|
121 | + ) + 1; |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * this was quick. I'd be down to explore more dynamic ways to map this, but for |
167 | 167 | * now this gets the job done. |
168 | 168 | * |
169 | - * @param array $query_args |
|
169 | + * @param array $query_args |
|
170 | 170 | * @return array |
171 | 171 | */ |
172 | 172 | public function sanitize_input_fields(array $query_args) { |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function get_items() { |
74 | 74 | |
75 | - $results = $this->query->get_col( $this->query_args ); |
|
75 | + $results = $this->query->get_col($this->query_args); |
|
76 | 76 | |
77 | - return ! empty( $results ) ? $results : []; |
|
77 | + return ! empty($results) ? $results : []; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function should_execute() { |
90 | 90 | |
91 | - if ( false === $this->should_execute ) { |
|
91 | + if (false === $this->should_execute) { |
|
92 | 92 | return false; |
93 | 93 | } |
94 | 94 | |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Prepare for later use |
111 | 111 | */ |
112 | - $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; |
|
113 | - $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; |
|
112 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
113 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
117 | 117 | */ |
118 | 118 | $query_args['limit'] = min( |
119 | - max( absint( $first ), absint( $last ), 10 ), |
|
119 | + max(absint($first), absint($last), 10), |
|
120 | 120 | $this->query_amount |
121 | 121 | ) + 1; |
122 | 122 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
125 | 125 | */ |
126 | 126 | $input_fields = []; |
127 | - if ( ! empty( $this->args['where'] ) ) { |
|
128 | - $input_fields = $this->sanitize_input_fields( $this->args['where'] ); |
|
127 | + if ( ! empty($this->args['where'])) { |
|
128 | + $input_fields = $this->sanitize_input_fields($this->args['where']); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * set the query to pull datetimes that belong to that event. |
136 | 136 | * We can set more cases for other source types. |
137 | 137 | */ |
138 | - if (is_object( $this->source )) { |
|
138 | + if (is_object($this->source)) { |
|
139 | 139 | switch (true) { |
140 | 140 | // Assumed to be an event |
141 | 141 | case $this->source instanceof Post: |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * Merge the input_fields with the default query_args |
152 | 152 | */ |
153 | - if ( ! empty( $input_fields ) ) { |
|
154 | - $query_args = array_merge( $query_args, $input_fields ); |
|
153 | + if ( ! empty($input_fields)) { |
|
154 | + $query_args = array_merge($query_args, $input_fields); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * Return the Query Args |
181 | 181 | */ |
182 | - return ! empty( $query_args ) && is_array( $query_args ) ? $query_args : []; |
|
182 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
183 | 183 | |
184 | 184 | } |
185 | 185 |
@@ -37,66 +37,66 @@ |
||
37 | 37 | class EventDatetimesConnection implements ConnectionInterface |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * @var EEM_Datetime $model |
|
42 | - */ |
|
43 | - protected $model; |
|
40 | + /** |
|
41 | + * @var EEM_Datetime $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * DatetimeConnection constructor. |
|
48 | - * |
|
49 | - * @param EEM_Datetime $model |
|
50 | - */ |
|
51 | - public function __construct(EEM_Datetime $model) |
|
52 | - { |
|
53 | - $this->model = $model; |
|
54 | - } |
|
46 | + /** |
|
47 | + * DatetimeConnection constructor. |
|
48 | + * |
|
49 | + * @param EEM_Datetime $model |
|
50 | + */ |
|
51 | + public function __construct(EEM_Datetime $model) |
|
52 | + { |
|
53 | + $this->model = $model; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public function config() |
|
62 | - { |
|
63 | - return [ |
|
64 | - 'fromType' => 'Event', |
|
65 | - 'toType' => 'Datetime', |
|
66 | - 'fromFieldName' => 'datetimes', |
|
67 | - 'connectionTypeName' => 'EventDatetimesConnection', |
|
68 | - 'resolve' => [$this, 'resolveConnection'], |
|
69 | - 'resolveNode' => [$this, 'resolveNode'] |
|
70 | - ]; |
|
71 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public function config() |
|
62 | + { |
|
63 | + return [ |
|
64 | + 'fromType' => 'Event', |
|
65 | + 'toType' => 'Datetime', |
|
66 | + 'fromFieldName' => 'datetimes', |
|
67 | + 'connectionTypeName' => 'EventDatetimesConnection', |
|
68 | + 'resolve' => [$this, 'resolveConnection'], |
|
69 | + 'resolveNode' => [$this, 'resolveNode'] |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param $entity |
|
76 | - * @param $args |
|
77 | - * @param $context |
|
78 | - * @param $info |
|
79 | - * @return array |
|
80 | - * @throws Exception |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveConnection($entity, $args, $context, $info) |
|
84 | - { |
|
85 | - $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
86 | - return $resolver->get_connection(); |
|
87 | - } |
|
74 | + /** |
|
75 | + * @param $entity |
|
76 | + * @param $args |
|
77 | + * @param $context |
|
78 | + * @param $info |
|
79 | + * @return array |
|
80 | + * @throws Exception |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveConnection($entity, $args, $context, $info) |
|
84 | + { |
|
85 | + $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
86 | + return $resolver->get_connection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param $id |
|
92 | - * @param $args |
|
93 | - * @param $context |
|
94 | - * @param $info |
|
95 | - * @return EE_Base_Class |
|
96 | - * @since $VID:$ |
|
97 | - */ |
|
98 | - public function resolveNode($id, $args, $context, $info) |
|
99 | - { |
|
100 | - return $this->model->get_one_by_ID($id); |
|
101 | - } |
|
90 | + /** |
|
91 | + * @param $id |
|
92 | + * @param $args |
|
93 | + * @param $context |
|
94 | + * @param $info |
|
95 | + * @return EE_Base_Class |
|
96 | + * @since $VID:$ |
|
97 | + */ |
|
98 | + public function resolveNode($id, $args, $context, $info) |
|
99 | + { |
|
100 | + return $this->model->get_one_by_ID($id); |
|
101 | + } |
|
102 | 102 | } |
@@ -37,66 +37,66 @@ |
||
37 | 37 | class EventVenuesConnection implements ConnectionInterface |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * @var EEM_Venue $model |
|
42 | - */ |
|
43 | - protected $model; |
|
40 | + /** |
|
41 | + * @var EEM_Venue $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * DatetimeConnection constructor. |
|
48 | - * |
|
49 | - * @param EEM_Venue $model |
|
50 | - */ |
|
51 | - public function __construct(EEM_Venue $model) |
|
52 | - { |
|
53 | - $this->model = $model; |
|
54 | - } |
|
46 | + /** |
|
47 | + * DatetimeConnection constructor. |
|
48 | + * |
|
49 | + * @param EEM_Venue $model |
|
50 | + */ |
|
51 | + public function __construct(EEM_Venue $model) |
|
52 | + { |
|
53 | + $this->model = $model; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public function config() |
|
62 | - { |
|
63 | - return [ |
|
64 | - 'fromType' => 'Event', |
|
65 | - 'toType' => 'Venue', |
|
66 | - 'fromFieldName' => 'venues', |
|
67 | - 'connectionTypeName' => 'EventVenuesConnection', |
|
68 | - 'resolve' => [$this, 'resolveConnection'], |
|
69 | - 'resolveNode' => [$this, 'resolveNode'] |
|
70 | - ]; |
|
71 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public function config() |
|
62 | + { |
|
63 | + return [ |
|
64 | + 'fromType' => 'Event', |
|
65 | + 'toType' => 'Venue', |
|
66 | + 'fromFieldName' => 'venues', |
|
67 | + 'connectionTypeName' => 'EventVenuesConnection', |
|
68 | + 'resolve' => [$this, 'resolveConnection'], |
|
69 | + 'resolveNode' => [$this, 'resolveNode'] |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param $entity |
|
76 | - * @param $args |
|
77 | - * @param $context |
|
78 | - * @param $info |
|
79 | - * @return array |
|
80 | - * @throws Exception |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveConnection($entity, $args, $context, $info) |
|
84 | - { |
|
85 | - $resolver = new VenueConnectionResolver($entity, $args, $context, $info); |
|
86 | - return $resolver->get_connection(); |
|
87 | - } |
|
74 | + /** |
|
75 | + * @param $entity |
|
76 | + * @param $args |
|
77 | + * @param $context |
|
78 | + * @param $info |
|
79 | + * @return array |
|
80 | + * @throws Exception |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveConnection($entity, $args, $context, $info) |
|
84 | + { |
|
85 | + $resolver = new VenueConnectionResolver($entity, $args, $context, $info); |
|
86 | + return $resolver->get_connection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param $id |
|
92 | - * @param $args |
|
93 | - * @param $context |
|
94 | - * @param $info |
|
95 | - * @return EE_Base_Class |
|
96 | - * @since $VID:$ |
|
97 | - */ |
|
98 | - public function resolveNode($id, $args, $context, $info) |
|
99 | - { |
|
100 | - return $this->model->get_one_by_ID($id); |
|
101 | - } |
|
90 | + /** |
|
91 | + * @param $id |
|
92 | + * @param $args |
|
93 | + * @param $context |
|
94 | + * @param $info |
|
95 | + * @return EE_Base_Class |
|
96 | + * @since $VID:$ |
|
97 | + */ |
|
98 | + public function resolveNode($id, $args, $context, $info) |
|
99 | + { |
|
100 | + return $this->model->get_one_by_ID($id); |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | \ No newline at end of file |
@@ -37,66 +37,66 @@ |
||
37 | 37 | class TicketDatetimesConnection implements ConnectionInterface |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * @var EEM_Datetime $model |
|
42 | - */ |
|
43 | - protected $model; |
|
40 | + /** |
|
41 | + * @var EEM_Datetime $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * DatetimeConnection constructor. |
|
48 | - * |
|
49 | - * @param EEM_Datetime $model |
|
50 | - */ |
|
51 | - public function __construct(EEM_Datetime $model) |
|
52 | - { |
|
53 | - $this->model = $model; |
|
54 | - } |
|
46 | + /** |
|
47 | + * DatetimeConnection constructor. |
|
48 | + * |
|
49 | + * @param EEM_Datetime $model |
|
50 | + */ |
|
51 | + public function __construct(EEM_Datetime $model) |
|
52 | + { |
|
53 | + $this->model = $model; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public function config() |
|
62 | - { |
|
63 | - return [ |
|
64 | - 'fromType' => 'Ticket', |
|
65 | - 'toType' => 'Datetime', |
|
66 | - 'fromFieldName' => 'datetimes', |
|
67 | - 'connectionTypeName' => 'TicketDatetimesConnection', |
|
68 | - 'resolve' => [$this, 'resolveConnection'], |
|
69 | - 'resolveNode' => [$this, 'resolveNode'] |
|
70 | - ]; |
|
71 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public function config() |
|
62 | + { |
|
63 | + return [ |
|
64 | + 'fromType' => 'Ticket', |
|
65 | + 'toType' => 'Datetime', |
|
66 | + 'fromFieldName' => 'datetimes', |
|
67 | + 'connectionTypeName' => 'TicketDatetimesConnection', |
|
68 | + 'resolve' => [$this, 'resolveConnection'], |
|
69 | + 'resolveNode' => [$this, 'resolveNode'] |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param $entity |
|
76 | - * @param $args |
|
77 | - * @param $context |
|
78 | - * @param $info |
|
79 | - * @return array |
|
80 | - * @throws Exception |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveConnection($entity, $args, $context, $info) |
|
84 | - { |
|
85 | - $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
86 | - return $resolver->get_connection(); |
|
87 | - } |
|
74 | + /** |
|
75 | + * @param $entity |
|
76 | + * @param $args |
|
77 | + * @param $context |
|
78 | + * @param $info |
|
79 | + * @return array |
|
80 | + * @throws Exception |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveConnection($entity, $args, $context, $info) |
|
84 | + { |
|
85 | + $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
86 | + return $resolver->get_connection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param $id |
|
92 | - * @param $args |
|
93 | - * @param $context |
|
94 | - * @param $info |
|
95 | - * @return EE_Base_Class |
|
96 | - * @since $VID:$ |
|
97 | - */ |
|
98 | - public function resolveNode($id, $args, $context, $info) |
|
99 | - { |
|
100 | - return $this->model->get_one_by_ID($id); |
|
101 | - } |
|
90 | + /** |
|
91 | + * @param $id |
|
92 | + * @param $args |
|
93 | + * @param $context |
|
94 | + * @param $info |
|
95 | + * @return EE_Base_Class |
|
96 | + * @since $VID:$ |
|
97 | + */ |
|
98 | + public function resolveNode($id, $args, $context, $info) |
|
99 | + { |
|
100 | + return $this->model->get_one_by_ID($id); |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | \ No newline at end of file |
@@ -37,66 +37,66 @@ |
||
37 | 37 | class DatetimeTicketsConnection implements ConnectionInterface |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * @var EEM_Ticket $model |
|
42 | - */ |
|
43 | - protected $model; |
|
40 | + /** |
|
41 | + * @var EEM_Ticket $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * DatetimeConnection constructor. |
|
48 | - * |
|
49 | - * @param EEM_Ticket $model |
|
50 | - */ |
|
51 | - public function __construct(EEM_Ticket $model) |
|
52 | - { |
|
53 | - $this->model = $model; |
|
54 | - } |
|
46 | + /** |
|
47 | + * DatetimeConnection constructor. |
|
48 | + * |
|
49 | + * @param EEM_Ticket $model |
|
50 | + */ |
|
51 | + public function __construct(EEM_Ticket $model) |
|
52 | + { |
|
53 | + $this->model = $model; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public function config() |
|
62 | - { |
|
63 | - return [ |
|
64 | - 'fromType' => 'Datetime', |
|
65 | - 'toType' => 'Ticket', |
|
66 | - 'fromFieldName' => 'tickets', |
|
67 | - 'connectionTypeName' => 'DatetimeTicketsConnection', |
|
68 | - 'resolve' => [$this, 'resolveConnection'], |
|
69 | - 'resolveNode' => [$this, 'resolveNode'] |
|
70 | - ]; |
|
71 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public function config() |
|
62 | + { |
|
63 | + return [ |
|
64 | + 'fromType' => 'Datetime', |
|
65 | + 'toType' => 'Ticket', |
|
66 | + 'fromFieldName' => 'tickets', |
|
67 | + 'connectionTypeName' => 'DatetimeTicketsConnection', |
|
68 | + 'resolve' => [$this, 'resolveConnection'], |
|
69 | + 'resolveNode' => [$this, 'resolveNode'] |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param $entity |
|
76 | - * @param $args |
|
77 | - * @param $context |
|
78 | - * @param $info |
|
79 | - * @return array |
|
80 | - * @throws Exception |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveConnection($entity, $args, $context, $info) |
|
84 | - { |
|
85 | - $resolver = new TicketConnectionResolver($entity, $args, $context, $info); |
|
86 | - return $resolver->get_connection(); |
|
87 | - } |
|
74 | + /** |
|
75 | + * @param $entity |
|
76 | + * @param $args |
|
77 | + * @param $context |
|
78 | + * @param $info |
|
79 | + * @return array |
|
80 | + * @throws Exception |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveConnection($entity, $args, $context, $info) |
|
84 | + { |
|
85 | + $resolver = new TicketConnectionResolver($entity, $args, $context, $info); |
|
86 | + return $resolver->get_connection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param $id |
|
92 | - * @param $args |
|
93 | - * @param $context |
|
94 | - * @param $info |
|
95 | - * @return EE_Base_Class |
|
96 | - * @since $VID:$ |
|
97 | - */ |
|
98 | - public function resolveNode($id, $args, $context, $info) |
|
99 | - { |
|
100 | - return $this->model->get_one_by_ID($id); |
|
101 | - } |
|
90 | + /** |
|
91 | + * @param $id |
|
92 | + * @param $args |
|
93 | + * @param $context |
|
94 | + * @param $info |
|
95 | + * @return EE_Base_Class |
|
96 | + * @since $VID:$ |
|
97 | + */ |
|
98 | + public function resolveNode($id, $args, $context, $info) |
|
99 | + { |
|
100 | + return $this->model->get_one_by_ID($id); |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | \ No newline at end of file |