@@ -14,43 +14,43 @@ |
||
14 | 14 | */ |
15 | 15 | class InternationalDNS extends International |
16 | 16 | { |
17 | - /** |
|
18 | - * Validates the email in teh same way as the parent, but also |
|
19 | - * verifies the domain exists. |
|
20 | - * |
|
21 | - * @param string $email_address |
|
22 | - * @return bool |
|
23 | - * @throws EmailValidationException |
|
24 | - */ |
|
25 | - public function validate(string $email_address): bool |
|
26 | - { |
|
27 | - parent::validate($email_address); |
|
28 | - $domain = $this->getDomainPartOfEmail( |
|
29 | - $email_address, |
|
30 | - $this->getAtIndex($email_address) |
|
31 | - ); |
|
32 | - if (! checkdnsrr($domain)) { |
|
33 | - // domain not found in MX records |
|
34 | - throw new EmailValidationException( |
|
35 | - esc_html__( |
|
36 | - // @codingStandardsIgnoreStart |
|
37 | - 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
38 | - // @codingStandardsIgnoreEnd |
|
39 | - 'event_espresso' |
|
40 | - ) |
|
41 | - ); |
|
42 | - } |
|
43 | - if (! checkdnsrr($domain, 'A')) { |
|
44 | - // domain not found in A records |
|
45 | - throw new EmailValidationException( |
|
46 | - esc_html__( |
|
47 | - // @codingStandardsIgnoreStart |
|
48 | - 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
49 | - // @codingStandardsIgnoreEnd |
|
50 | - 'event_espresso' |
|
51 | - ) |
|
52 | - ); |
|
53 | - } |
|
54 | - return true; |
|
55 | - } |
|
17 | + /** |
|
18 | + * Validates the email in teh same way as the parent, but also |
|
19 | + * verifies the domain exists. |
|
20 | + * |
|
21 | + * @param string $email_address |
|
22 | + * @return bool |
|
23 | + * @throws EmailValidationException |
|
24 | + */ |
|
25 | + public function validate(string $email_address): bool |
|
26 | + { |
|
27 | + parent::validate($email_address); |
|
28 | + $domain = $this->getDomainPartOfEmail( |
|
29 | + $email_address, |
|
30 | + $this->getAtIndex($email_address) |
|
31 | + ); |
|
32 | + if (! checkdnsrr($domain)) { |
|
33 | + // domain not found in MX records |
|
34 | + throw new EmailValidationException( |
|
35 | + esc_html__( |
|
36 | + // @codingStandardsIgnoreStart |
|
37 | + 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
38 | + // @codingStandardsIgnoreEnd |
|
39 | + 'event_espresso' |
|
40 | + ) |
|
41 | + ); |
|
42 | + } |
|
43 | + if (! checkdnsrr($domain, 'A')) { |
|
44 | + // domain not found in A records |
|
45 | + throw new EmailValidationException( |
|
46 | + esc_html__( |
|
47 | + // @codingStandardsIgnoreStart |
|
48 | + 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
49 | + // @codingStandardsIgnoreEnd |
|
50 | + 'event_espresso' |
|
51 | + ) |
|
52 | + ); |
|
53 | + } |
|
54 | + return true; |
|
55 | + } |
|
56 | 56 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $email_address, |
30 | 30 | $this->getAtIndex($email_address) |
31 | 31 | ); |
32 | - if (! checkdnsrr($domain)) { |
|
32 | + if ( ! checkdnsrr($domain)) { |
|
33 | 33 | // domain not found in MX records |
34 | 34 | throw new EmailValidationException( |
35 | 35 | esc_html__( |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | ) |
41 | 41 | ); |
42 | 42 | } |
43 | - if (! checkdnsrr($domain, 'A')) { |
|
43 | + if ( ! checkdnsrr($domain, 'A')) { |
|
44 | 44 | // domain not found in A records |
45 | 45 | throw new EmailValidationException( |
46 | 46 | esc_html__( |
@@ -13,12 +13,12 @@ |
||
13 | 13 | */ |
14 | 14 | interface EmailValidatorInterface |
15 | 15 | { |
16 | - /** |
|
17 | - * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
18 | - * |
|
19 | - * @param string $email_address |
|
20 | - * @return boolean |
|
21 | - * @throws EmailValidationException |
|
22 | - */ |
|
23 | - public function validate(string $email_address): bool; |
|
16 | + /** |
|
17 | + * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
18 | + * |
|
19 | + * @param string $email_address |
|
20 | + * @return boolean |
|
21 | + * @throws EmailValidationException |
|
22 | + */ |
|
23 | + public function validate(string $email_address): bool; |
|
24 | 24 | } |
@@ -15,59 +15,59 @@ |
||
15 | 15 | */ |
16 | 16 | class EmailValidationService implements EmailValidatorInterface |
17 | 17 | { |
18 | - protected EE_Registration_Config $registration_config; |
|
18 | + protected EE_Registration_Config $registration_config; |
|
19 | 19 | |
20 | - protected LoaderInterface $loader; |
|
20 | + protected LoaderInterface $loader; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * EmailValidationService constructor. |
|
25 | - * Accepts an \EE_Config as an argument. |
|
26 | - * |
|
27 | - * @param EE_Registration_Config $config |
|
28 | - * @param LoaderInterface $loader |
|
29 | - */ |
|
30 | - public function __construct(EE_Registration_Config $config, LoaderInterface $loader) |
|
31 | - { |
|
32 | - $this->registration_config = $config; |
|
33 | - $this->loader = $loader; |
|
34 | - } |
|
23 | + /** |
|
24 | + * EmailValidationService constructor. |
|
25 | + * Accepts an \EE_Config as an argument. |
|
26 | + * |
|
27 | + * @param EE_Registration_Config $config |
|
28 | + * @param LoaderInterface $loader |
|
29 | + */ |
|
30 | + public function __construct(EE_Registration_Config $config, LoaderInterface $loader) |
|
31 | + { |
|
32 | + $this->registration_config = $config; |
|
33 | + $this->loader = $loader; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Validates the email address. If it's invalid, an EmailValidationException |
|
39 | - * is thrown that describes why its invalid. |
|
40 | - * |
|
41 | - * @param string $email_address |
|
42 | - * @return boolean |
|
43 | - * @throws EmailValidationException |
|
44 | - */ |
|
45 | - public function validate(string $email_address): bool |
|
46 | - { |
|
47 | - // pick the correct validator according to the config |
|
48 | - switch ($this->registration_config->email_validation_level) { |
|
49 | - case 'basic': |
|
50 | - $validator = $this->loader->getShared( |
|
51 | - 'EventEspresso\core\domain\services\validation\email\strategies\Basic' |
|
52 | - ); |
|
53 | - break; |
|
54 | - case 'i18n': |
|
55 | - $validator = $this->loader->getShared( |
|
56 | - 'EventEspresso\core\domain\services\validation\email\strategies\International' |
|
57 | - ); |
|
58 | - break; |
|
59 | - case 'i18n_dns': |
|
60 | - $validator = $this->loader->getShared( |
|
61 | - 'EventEspresso\core\domain\services\validation\email\strategies\InternationalDNS' |
|
62 | - ); |
|
63 | - break; |
|
64 | - case 'wp_default': |
|
65 | - default: |
|
66 | - $validator = $this->loader->getShared( |
|
67 | - 'EventEspresso\core\domain\services\validation\email\strategies\WordPress' |
|
68 | - ); |
|
69 | - break; |
|
70 | - } |
|
71 | - return $validator->validate($email_address); |
|
72 | - } |
|
37 | + /** |
|
38 | + * Validates the email address. If it's invalid, an EmailValidationException |
|
39 | + * is thrown that describes why its invalid. |
|
40 | + * |
|
41 | + * @param string $email_address |
|
42 | + * @return boolean |
|
43 | + * @throws EmailValidationException |
|
44 | + */ |
|
45 | + public function validate(string $email_address): bool |
|
46 | + { |
|
47 | + // pick the correct validator according to the config |
|
48 | + switch ($this->registration_config->email_validation_level) { |
|
49 | + case 'basic': |
|
50 | + $validator = $this->loader->getShared( |
|
51 | + 'EventEspresso\core\domain\services\validation\email\strategies\Basic' |
|
52 | + ); |
|
53 | + break; |
|
54 | + case 'i18n': |
|
55 | + $validator = $this->loader->getShared( |
|
56 | + 'EventEspresso\core\domain\services\validation\email\strategies\International' |
|
57 | + ); |
|
58 | + break; |
|
59 | + case 'i18n_dns': |
|
60 | + $validator = $this->loader->getShared( |
|
61 | + 'EventEspresso\core\domain\services\validation\email\strategies\InternationalDNS' |
|
62 | + ); |
|
63 | + break; |
|
64 | + case 'wp_default': |
|
65 | + default: |
|
66 | + $validator = $this->loader->getShared( |
|
67 | + 'EventEspresso\core\domain\services\validation\email\strategies\WordPress' |
|
68 | + ); |
|
69 | + break; |
|
70 | + } |
|
71 | + return $validator->validate($email_address); |
|
72 | + } |
|
73 | 73 | } |
@@ -15,185 +15,185 @@ |
||
15 | 15 | */ |
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | - /** |
|
19 | - * indicates that the current request involves some form of activation |
|
20 | - */ |
|
21 | - const ACTIVATION = 'activation-request'; |
|
22 | - |
|
23 | - /** |
|
24 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
25 | - */ |
|
26 | - const ADMIN = 'non-ajax-admin-request'; |
|
27 | - |
|
28 | - /** |
|
29 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
30 | - */ |
|
31 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
32 | - |
|
33 | - /** |
|
34 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
35 | - */ |
|
36 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
37 | - |
|
38 | - /** |
|
39 | - * indicates that the current request is for the WP Heartbeat |
|
40 | - */ |
|
41 | - const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
42 | - |
|
43 | - /** |
|
44 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
45 | - */ |
|
46 | - const AJAX_OTHER = 'other-ajax-request'; |
|
47 | - |
|
48 | - /** |
|
49 | - * indicates that the current request is for the EE REST API |
|
50 | - */ |
|
51 | - const API = 'rest-api'; |
|
52 | - |
|
53 | - /** |
|
54 | - * indicates that the current request is from the command line |
|
55 | - */ |
|
56 | - const CLI = 'command-line'; |
|
57 | - |
|
58 | - /** |
|
59 | - * indicates that the current request is for a WP_Cron |
|
60 | - */ |
|
61 | - const CRON = 'wp-cron'; |
|
62 | - |
|
63 | - /** |
|
64 | - * indicates that the current request is for a feed (ie: RSS) |
|
65 | - */ |
|
66 | - const FEED = 'feed-request'; |
|
67 | - |
|
68 | - /** |
|
69 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
70 | - */ |
|
71 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
72 | - |
|
73 | - /** |
|
74 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
75 | - */ |
|
76 | - const IFRAME = 'iframe-request'; |
|
77 | - |
|
78 | - /** |
|
79 | - * indicates that the current request is for the EE GraphQL manager |
|
80 | - */ |
|
81 | - const GQL = 'graphql'; |
|
82 | - |
|
83 | - /** |
|
84 | - * indicates that the current request is for the WP REST API |
|
85 | - */ |
|
86 | - const WP_API = 'wp-rest-api'; |
|
87 | - |
|
88 | - /** |
|
89 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
90 | - */ |
|
91 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
92 | - |
|
93 | - /** |
|
94 | - * @var boolean $is_activation |
|
95 | - */ |
|
96 | - private bool $is_activation = false; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var boolean $is_unit_testing |
|
100 | - */ |
|
101 | - private bool $is_unit_testing = false; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var array $valid_request_types |
|
105 | - */ |
|
106 | - private array $valid_request_types = array(); |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * RequestTypeContext constructor. |
|
111 | - * |
|
112 | - * @param string $slug |
|
113 | - * @param string $description |
|
114 | - * @throws InvalidArgumentException |
|
115 | - */ |
|
116 | - public function __construct($slug, $description) |
|
117 | - { |
|
118 | - parent::__construct($slug, $description); |
|
119 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
120 | - throw new InvalidArgumentException( |
|
121 | - sprintf( |
|
122 | - esc_html__( |
|
123 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
124 | - 'event_espresso' |
|
125 | - ), |
|
126 | - '<br />', |
|
127 | - var_export($this->validRequestTypes(), true) |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function validRequestTypes(): array |
|
138 | - { |
|
139 | - if (empty($this->valid_request_types)) { |
|
140 | - $this->valid_request_types = apply_filters( |
|
141 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
142 | - array( |
|
143 | - RequestTypeContext::ACTIVATION, |
|
144 | - RequestTypeContext::ADMIN, |
|
145 | - RequestTypeContext::AJAX_ADMIN, |
|
146 | - RequestTypeContext::AJAX_FRONT, |
|
147 | - RequestTypeContext::AJAX_HEARTBEAT, |
|
148 | - RequestTypeContext::AJAX_OTHER, |
|
149 | - RequestTypeContext::API, |
|
150 | - RequestTypeContext::CLI, |
|
151 | - RequestTypeContext::CRON, |
|
152 | - RequestTypeContext::FEED, |
|
153 | - RequestTypeContext::FRONTEND, |
|
154 | - RequestTypeContext::GQL, |
|
155 | - RequestTypeContext::IFRAME, |
|
156 | - RequestTypeContext::WP_API, |
|
157 | - RequestTypeContext::WP_SCRAPE, |
|
158 | - ) |
|
159 | - ); |
|
160 | - } |
|
161 | - return $this->valid_request_types; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function isActivation(): bool |
|
169 | - { |
|
170 | - return $this->is_activation; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param bool $is_activation |
|
176 | - */ |
|
177 | - public function setIsActivation(bool $is_activation = false) |
|
178 | - { |
|
179 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function isUnitTesting(): bool |
|
187 | - { |
|
188 | - return $this->is_unit_testing; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param bool $is_unit_testing |
|
194 | - */ |
|
195 | - public function setIsUnitTesting(bool $is_unit_testing = false) |
|
196 | - { |
|
197 | - $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN); |
|
198 | - } |
|
18 | + /** |
|
19 | + * indicates that the current request involves some form of activation |
|
20 | + */ |
|
21 | + const ACTIVATION = 'activation-request'; |
|
22 | + |
|
23 | + /** |
|
24 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
25 | + */ |
|
26 | + const ADMIN = 'non-ajax-admin-request'; |
|
27 | + |
|
28 | + /** |
|
29 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
30 | + */ |
|
31 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
32 | + |
|
33 | + /** |
|
34 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
35 | + */ |
|
36 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
37 | + |
|
38 | + /** |
|
39 | + * indicates that the current request is for the WP Heartbeat |
|
40 | + */ |
|
41 | + const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
42 | + |
|
43 | + /** |
|
44 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
45 | + */ |
|
46 | + const AJAX_OTHER = 'other-ajax-request'; |
|
47 | + |
|
48 | + /** |
|
49 | + * indicates that the current request is for the EE REST API |
|
50 | + */ |
|
51 | + const API = 'rest-api'; |
|
52 | + |
|
53 | + /** |
|
54 | + * indicates that the current request is from the command line |
|
55 | + */ |
|
56 | + const CLI = 'command-line'; |
|
57 | + |
|
58 | + /** |
|
59 | + * indicates that the current request is for a WP_Cron |
|
60 | + */ |
|
61 | + const CRON = 'wp-cron'; |
|
62 | + |
|
63 | + /** |
|
64 | + * indicates that the current request is for a feed (ie: RSS) |
|
65 | + */ |
|
66 | + const FEED = 'feed-request'; |
|
67 | + |
|
68 | + /** |
|
69 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
70 | + */ |
|
71 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
72 | + |
|
73 | + /** |
|
74 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
75 | + */ |
|
76 | + const IFRAME = 'iframe-request'; |
|
77 | + |
|
78 | + /** |
|
79 | + * indicates that the current request is for the EE GraphQL manager |
|
80 | + */ |
|
81 | + const GQL = 'graphql'; |
|
82 | + |
|
83 | + /** |
|
84 | + * indicates that the current request is for the WP REST API |
|
85 | + */ |
|
86 | + const WP_API = 'wp-rest-api'; |
|
87 | + |
|
88 | + /** |
|
89 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
90 | + */ |
|
91 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
92 | + |
|
93 | + /** |
|
94 | + * @var boolean $is_activation |
|
95 | + */ |
|
96 | + private bool $is_activation = false; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var boolean $is_unit_testing |
|
100 | + */ |
|
101 | + private bool $is_unit_testing = false; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var array $valid_request_types |
|
105 | + */ |
|
106 | + private array $valid_request_types = array(); |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * RequestTypeContext constructor. |
|
111 | + * |
|
112 | + * @param string $slug |
|
113 | + * @param string $description |
|
114 | + * @throws InvalidArgumentException |
|
115 | + */ |
|
116 | + public function __construct($slug, $description) |
|
117 | + { |
|
118 | + parent::__construct($slug, $description); |
|
119 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
120 | + throw new InvalidArgumentException( |
|
121 | + sprintf( |
|
122 | + esc_html__( |
|
123 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
124 | + 'event_espresso' |
|
125 | + ), |
|
126 | + '<br />', |
|
127 | + var_export($this->validRequestTypes(), true) |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function validRequestTypes(): array |
|
138 | + { |
|
139 | + if (empty($this->valid_request_types)) { |
|
140 | + $this->valid_request_types = apply_filters( |
|
141 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
142 | + array( |
|
143 | + RequestTypeContext::ACTIVATION, |
|
144 | + RequestTypeContext::ADMIN, |
|
145 | + RequestTypeContext::AJAX_ADMIN, |
|
146 | + RequestTypeContext::AJAX_FRONT, |
|
147 | + RequestTypeContext::AJAX_HEARTBEAT, |
|
148 | + RequestTypeContext::AJAX_OTHER, |
|
149 | + RequestTypeContext::API, |
|
150 | + RequestTypeContext::CLI, |
|
151 | + RequestTypeContext::CRON, |
|
152 | + RequestTypeContext::FEED, |
|
153 | + RequestTypeContext::FRONTEND, |
|
154 | + RequestTypeContext::GQL, |
|
155 | + RequestTypeContext::IFRAME, |
|
156 | + RequestTypeContext::WP_API, |
|
157 | + RequestTypeContext::WP_SCRAPE, |
|
158 | + ) |
|
159 | + ); |
|
160 | + } |
|
161 | + return $this->valid_request_types; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function isActivation(): bool |
|
169 | + { |
|
170 | + return $this->is_activation; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param bool $is_activation |
|
176 | + */ |
|
177 | + public function setIsActivation(bool $is_activation = false) |
|
178 | + { |
|
179 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function isUnitTesting(): bool |
|
187 | + { |
|
188 | + return $this->is_unit_testing; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param bool $is_unit_testing |
|
194 | + */ |
|
195 | + public function setIsUnitTesting(bool $is_unit_testing = false) |
|
196 | + { |
|
197 | + $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN); |
|
198 | + } |
|
199 | 199 | } |
@@ -27,97 +27,97 @@ |
||
27 | 27 | */ |
28 | 28 | class AdminRoute extends Route |
29 | 29 | { |
30 | - protected EE_Admin_Config $admin_config; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array $default_dependencies |
|
34 | - */ |
|
35 | - protected static $default_dependencies = [ |
|
36 | - 'EE_Admin_Config' => EE_Dependency_Map::load_from_cache, |
|
37 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
38 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
39 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
40 | - ]; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Route constructor. |
|
45 | - * |
|
46 | - * @param EE_Admin_Config $admin_config |
|
47 | - * @param EE_Dependency_Map $dependency_map |
|
48 | - * @param LoaderInterface $loader |
|
49 | - * @param RequestInterface $request |
|
50 | - * @param JsonDataNode|null $data_node |
|
51 | - * @param RouteMatchSpecificationInterface|null $specification |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - EE_Admin_Config $admin_config, |
|
55 | - EE_Dependency_Map $dependency_map, |
|
56 | - LoaderInterface $loader, |
|
57 | - RequestInterface $request, |
|
58 | - JsonDataNode $data_node = null, |
|
59 | - RouteMatchSpecificationInterface $specification = null |
|
60 | - ) { |
|
61 | - $this->admin_config = $admin_config; |
|
62 | - parent::__construct($dependency_map, $loader, $request, $data_node, $specification); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return CapCheckInterface |
|
68 | - */ |
|
69 | - public function getCapCheck() |
|
70 | - { |
|
71 | - return new CapCheck('ee_read_events', 'access Event Espresso admin route'); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public static function getDefaultDependencies(): array |
|
79 | - { |
|
80 | - return self::$default_dependencies; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * returns true if the current request matches this route |
|
86 | - * |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function matchesCurrentRequest(): bool |
|
90 | - { |
|
91 | - return $this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation(); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function registerDependencies() |
|
99 | - { |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * implements logic required to run during request |
|
105 | - * |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - protected function requestHandler(): bool |
|
109 | - { |
|
110 | - // don't handle request more than once!!! |
|
111 | - if (did_action('AHEE__EE_System__load_controllers__load_admin_controllers')) { |
|
112 | - return true; |
|
113 | - } |
|
114 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
115 | - $this->loader->getShared('EE_Admin'); |
|
116 | - do_action( |
|
117 | - 'AHEE__EventEspresso_core_domain_entities_routing_handlers_admin_AdminRoute__requestHandler__admin_loaded' |
|
118 | - ); |
|
119 | - |
|
120 | - AdminFontSize::setAdminFontSizeBodyClass(); |
|
121 | - return true; |
|
122 | - } |
|
30 | + protected EE_Admin_Config $admin_config; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array $default_dependencies |
|
34 | + */ |
|
35 | + protected static $default_dependencies = [ |
|
36 | + 'EE_Admin_Config' => EE_Dependency_Map::load_from_cache, |
|
37 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
38 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
39 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
40 | + ]; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Route constructor. |
|
45 | + * |
|
46 | + * @param EE_Admin_Config $admin_config |
|
47 | + * @param EE_Dependency_Map $dependency_map |
|
48 | + * @param LoaderInterface $loader |
|
49 | + * @param RequestInterface $request |
|
50 | + * @param JsonDataNode|null $data_node |
|
51 | + * @param RouteMatchSpecificationInterface|null $specification |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + EE_Admin_Config $admin_config, |
|
55 | + EE_Dependency_Map $dependency_map, |
|
56 | + LoaderInterface $loader, |
|
57 | + RequestInterface $request, |
|
58 | + JsonDataNode $data_node = null, |
|
59 | + RouteMatchSpecificationInterface $specification = null |
|
60 | + ) { |
|
61 | + $this->admin_config = $admin_config; |
|
62 | + parent::__construct($dependency_map, $loader, $request, $data_node, $specification); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return CapCheckInterface |
|
68 | + */ |
|
69 | + public function getCapCheck() |
|
70 | + { |
|
71 | + return new CapCheck('ee_read_events', 'access Event Espresso admin route'); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public static function getDefaultDependencies(): array |
|
79 | + { |
|
80 | + return self::$default_dependencies; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * returns true if the current request matches this route |
|
86 | + * |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function matchesCurrentRequest(): bool |
|
90 | + { |
|
91 | + return $this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation(); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function registerDependencies() |
|
99 | + { |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * implements logic required to run during request |
|
105 | + * |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + protected function requestHandler(): bool |
|
109 | + { |
|
110 | + // don't handle request more than once!!! |
|
111 | + if (did_action('AHEE__EE_System__load_controllers__load_admin_controllers')) { |
|
112 | + return true; |
|
113 | + } |
|
114 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
115 | + $this->loader->getShared('EE_Admin'); |
|
116 | + do_action( |
|
117 | + 'AHEE__EventEspresso_core_domain_entities_routing_handlers_admin_AdminRoute__requestHandler__admin_loaded' |
|
118 | + ); |
|
119 | + |
|
120 | + AdminFontSize::setAdminFontSizeBodyClass(); |
|
121 | + return true; |
|
122 | + } |
|
123 | 123 | } |
@@ -19,227 +19,227 @@ |
||
19 | 19 | */ |
20 | 20 | class GQLRequests extends Route |
21 | 21 | { |
22 | - /** |
|
23 | - * @var AssetManifestFactory |
|
24 | - */ |
|
25 | - private $manifest_factory; |
|
22 | + /** |
|
23 | + * @var AssetManifestFactory |
|
24 | + */ |
|
25 | + private $manifest_factory; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * AssetRequests constructor. |
|
30 | - * |
|
31 | - * @param EE_Dependency_Map $dependency_map |
|
32 | - * @param LoaderInterface $loader |
|
33 | - * @param RequestInterface $request |
|
34 | - * @param AssetManifestFactory $manifest_factory |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - EE_Dependency_Map $dependency_map, |
|
38 | - LoaderInterface $loader, |
|
39 | - RequestInterface $request, |
|
40 | - AssetManifestFactory $manifest_factory |
|
41 | - ) { |
|
42 | - $this->manifest_factory = $manifest_factory; |
|
43 | - parent::__construct($dependency_map, $loader, $request); |
|
44 | - } |
|
28 | + /** |
|
29 | + * AssetRequests constructor. |
|
30 | + * |
|
31 | + * @param EE_Dependency_Map $dependency_map |
|
32 | + * @param LoaderInterface $loader |
|
33 | + * @param RequestInterface $request |
|
34 | + * @param AssetManifestFactory $manifest_factory |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + EE_Dependency_Map $dependency_map, |
|
38 | + LoaderInterface $loader, |
|
39 | + RequestInterface $request, |
|
40 | + AssetManifestFactory $manifest_factory |
|
41 | + ) { |
|
42 | + $this->manifest_factory = $manifest_factory; |
|
43 | + parent::__construct($dependency_map, $loader, $request); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * returns true if the current request matches this route |
|
49 | - * |
|
50 | - * @return bool |
|
51 | - * @since 5.0.0.p |
|
52 | - */ |
|
53 | - public function matchesCurrentRequest(): bool |
|
54 | - { |
|
55 | - global $pagenow; |
|
56 | - return ( |
|
57 | - $this->request->isGQL() |
|
58 | - || $this->request->isUnitTesting() |
|
59 | - || ( |
|
60 | - $this->request->isAdmin() |
|
61 | - && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | - && ( |
|
63 | - $this->request->getRequestParam('action') === 'create_new' |
|
64 | - || $this->request->getRequestParam('action') === 'edit' |
|
65 | - ) |
|
66 | - ) || ( |
|
67 | - $pagenow |
|
68 | - && ( |
|
69 | - $pagenow === 'post-new.php' |
|
70 | - || ( |
|
71 | - $pagenow === 'post.php' |
|
72 | - && $this->request->getRequestParam('action') === 'edit' |
|
73 | - ) |
|
74 | - ) |
|
75 | - ) |
|
76 | - ); |
|
77 | - } |
|
47 | + /** |
|
48 | + * returns true if the current request matches this route |
|
49 | + * |
|
50 | + * @return bool |
|
51 | + * @since 5.0.0.p |
|
52 | + */ |
|
53 | + public function matchesCurrentRequest(): bool |
|
54 | + { |
|
55 | + global $pagenow; |
|
56 | + return ( |
|
57 | + $this->request->isGQL() |
|
58 | + || $this->request->isUnitTesting() |
|
59 | + || ( |
|
60 | + $this->request->isAdmin() |
|
61 | + && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | + && ( |
|
63 | + $this->request->getRequestParam('action') === 'create_new' |
|
64 | + || $this->request->getRequestParam('action') === 'edit' |
|
65 | + ) |
|
66 | + ) || ( |
|
67 | + $pagenow |
|
68 | + && ( |
|
69 | + $pagenow === 'post-new.php' |
|
70 | + || ( |
|
71 | + $pagenow === 'post.php' |
|
72 | + && $this->request->getRequestParam('action') === 'edit' |
|
73 | + ) |
|
74 | + ) |
|
75 | + ) |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @since 5.0.0.p |
|
82 | - */ |
|
83 | - protected function registerDependencies() |
|
84 | - { |
|
85 | - $this->dependency_map->registerDependencies( |
|
86 | - 'EventEspresso\core\services\graphql\GraphQLManager', |
|
87 | - [ |
|
88 | - 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
89 | - 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
90 | - 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
91 | - 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | - 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
93 | - ] |
|
94 | - ); |
|
95 | - $this->dependency_map->registerDependencies( |
|
96 | - 'EventEspresso\core\services\graphql\TypesManager', |
|
97 | - [ |
|
98 | - 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
99 | - ] |
|
100 | - ); |
|
101 | - $this->dependency_map->registerDependencies( |
|
102 | - 'EventEspresso\core\services\graphql\InputsManager', |
|
103 | - [ |
|
104 | - 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
105 | - ] |
|
106 | - ); |
|
107 | - $this->dependency_map->registerDependencies( |
|
108 | - 'EventEspresso\core\services\graphql\EnumsManager', |
|
109 | - [ |
|
110 | - 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
111 | - ] |
|
112 | - ); |
|
113 | - $this->dependency_map->registerDependencies( |
|
114 | - 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
115 | - [ |
|
116 | - 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
117 | - ] |
|
118 | - ); |
|
119 | - $this->dependency_map->registerDependencies( |
|
120 | - 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
121 | - [ |
|
122 | - 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
123 | - ] |
|
124 | - ); |
|
125 | - $this->dependency_map->registerDependencies( |
|
126 | - 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
127 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
128 | - ); |
|
129 | - $this->dependency_map->registerDependencies( |
|
130 | - 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
131 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
132 | - ); |
|
133 | - $this->dependency_map->registerDependencies( |
|
134 | - 'EventEspresso\core\domain\services\graphql\types\Event', |
|
135 | - ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
136 | - ); |
|
137 | - $this->dependency_map->registerDependencies( |
|
138 | - 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
139 | - ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
140 | - ); |
|
141 | - $this->dependency_map->registerDependencies( |
|
142 | - 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
143 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
144 | - ); |
|
145 | - $this->dependency_map->registerDependencies( |
|
146 | - 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
147 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
148 | - ); |
|
149 | - $this->dependency_map->registerDependencies( |
|
150 | - 'EventEspresso\core\domain\services\graphql\types\Price', |
|
151 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
152 | - ); |
|
153 | - $this->dependency_map->registerDependencies( |
|
154 | - 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
155 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
156 | - ); |
|
157 | - $this->dependency_map->registerDependencies( |
|
158 | - 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
159 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
160 | - ); |
|
161 | - $this->dependency_map->registerDependencies( |
|
162 | - 'EventEspresso\core\domain\services\graphql\types\State', |
|
163 | - ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
164 | - ); |
|
165 | - $this->dependency_map->registerDependencies( |
|
166 | - 'EventEspresso\core\domain\services\graphql\types\Country', |
|
167 | - ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
168 | - ); |
|
169 | - $this->dependency_map->registerDependencies( |
|
170 | - 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
171 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
172 | - ); |
|
173 | - $this->dependency_map->registerDependencies( |
|
174 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
175 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
176 | - ); |
|
177 | - $this->dependency_map->registerDependencies( |
|
178 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
179 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
180 | - ); |
|
181 | - $this->dependency_map->registerDependencies( |
|
182 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryCountriesConnection', |
|
183 | - ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
184 | - ); |
|
185 | - $this->dependency_map->registerDependencies( |
|
186 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
187 | - ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
188 | - ); |
|
189 | - $this->dependency_map->registerDependencies( |
|
190 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
191 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
192 | - ); |
|
193 | - $this->dependency_map->registerDependencies( |
|
194 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryStatesConnection', |
|
195 | - ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
196 | - ); |
|
197 | - $this->dependency_map->registerDependencies( |
|
198 | - 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
199 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
200 | - ); |
|
201 | - $this->dependency_map->registerDependencies( |
|
202 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
203 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
204 | - ); |
|
205 | - $this->dependency_map->registerDependencies( |
|
206 | - 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
207 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
208 | - ); |
|
209 | - $this->dependency_map->registerDependencies( |
|
210 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
211 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
212 | - ); |
|
213 | - $this->dependency_map->registerDependencies( |
|
214 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
215 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
216 | - ); |
|
217 | - $this->dependency_map->registerDependencies( |
|
218 | - 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
219 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
220 | - ); |
|
221 | - $this->dependency_map->registerDependencies( |
|
222 | - 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
223 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
224 | - ); |
|
225 | - } |
|
80 | + /** |
|
81 | + * @since 5.0.0.p |
|
82 | + */ |
|
83 | + protected function registerDependencies() |
|
84 | + { |
|
85 | + $this->dependency_map->registerDependencies( |
|
86 | + 'EventEspresso\core\services\graphql\GraphQLManager', |
|
87 | + [ |
|
88 | + 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
89 | + 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
90 | + 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
91 | + 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | + 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
93 | + ] |
|
94 | + ); |
|
95 | + $this->dependency_map->registerDependencies( |
|
96 | + 'EventEspresso\core\services\graphql\TypesManager', |
|
97 | + [ |
|
98 | + 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
99 | + ] |
|
100 | + ); |
|
101 | + $this->dependency_map->registerDependencies( |
|
102 | + 'EventEspresso\core\services\graphql\InputsManager', |
|
103 | + [ |
|
104 | + 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
105 | + ] |
|
106 | + ); |
|
107 | + $this->dependency_map->registerDependencies( |
|
108 | + 'EventEspresso\core\services\graphql\EnumsManager', |
|
109 | + [ |
|
110 | + 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
111 | + ] |
|
112 | + ); |
|
113 | + $this->dependency_map->registerDependencies( |
|
114 | + 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
115 | + [ |
|
116 | + 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
117 | + ] |
|
118 | + ); |
|
119 | + $this->dependency_map->registerDependencies( |
|
120 | + 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
121 | + [ |
|
122 | + 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
123 | + ] |
|
124 | + ); |
|
125 | + $this->dependency_map->registerDependencies( |
|
126 | + 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
127 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
128 | + ); |
|
129 | + $this->dependency_map->registerDependencies( |
|
130 | + 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
131 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
132 | + ); |
|
133 | + $this->dependency_map->registerDependencies( |
|
134 | + 'EventEspresso\core\domain\services\graphql\types\Event', |
|
135 | + ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
136 | + ); |
|
137 | + $this->dependency_map->registerDependencies( |
|
138 | + 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
139 | + ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
140 | + ); |
|
141 | + $this->dependency_map->registerDependencies( |
|
142 | + 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
143 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
144 | + ); |
|
145 | + $this->dependency_map->registerDependencies( |
|
146 | + 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
147 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
148 | + ); |
|
149 | + $this->dependency_map->registerDependencies( |
|
150 | + 'EventEspresso\core\domain\services\graphql\types\Price', |
|
151 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
152 | + ); |
|
153 | + $this->dependency_map->registerDependencies( |
|
154 | + 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
155 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
156 | + ); |
|
157 | + $this->dependency_map->registerDependencies( |
|
158 | + 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
159 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
160 | + ); |
|
161 | + $this->dependency_map->registerDependencies( |
|
162 | + 'EventEspresso\core\domain\services\graphql\types\State', |
|
163 | + ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
164 | + ); |
|
165 | + $this->dependency_map->registerDependencies( |
|
166 | + 'EventEspresso\core\domain\services\graphql\types\Country', |
|
167 | + ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
168 | + ); |
|
169 | + $this->dependency_map->registerDependencies( |
|
170 | + 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
171 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
172 | + ); |
|
173 | + $this->dependency_map->registerDependencies( |
|
174 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
175 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
176 | + ); |
|
177 | + $this->dependency_map->registerDependencies( |
|
178 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
179 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
180 | + ); |
|
181 | + $this->dependency_map->registerDependencies( |
|
182 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryCountriesConnection', |
|
183 | + ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
184 | + ); |
|
185 | + $this->dependency_map->registerDependencies( |
|
186 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
187 | + ['EEM_Form_Element' => EE_Dependency_Map::load_from_cache] |
|
188 | + ); |
|
189 | + $this->dependency_map->registerDependencies( |
|
190 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
191 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
192 | + ); |
|
193 | + $this->dependency_map->registerDependencies( |
|
194 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryStatesConnection', |
|
195 | + ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
196 | + ); |
|
197 | + $this->dependency_map->registerDependencies( |
|
198 | + 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
199 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
200 | + ); |
|
201 | + $this->dependency_map->registerDependencies( |
|
202 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
203 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
204 | + ); |
|
205 | + $this->dependency_map->registerDependencies( |
|
206 | + 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
207 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
208 | + ); |
|
209 | + $this->dependency_map->registerDependencies( |
|
210 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
211 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
212 | + ); |
|
213 | + $this->dependency_map->registerDependencies( |
|
214 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
215 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
216 | + ); |
|
217 | + $this->dependency_map->registerDependencies( |
|
218 | + 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
219 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
220 | + ); |
|
221 | + $this->dependency_map->registerDependencies( |
|
222 | + 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
223 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
224 | + ); |
|
225 | + } |
|
226 | 226 | |
227 | 227 | |
228 | - /** |
|
229 | - * implements logic required to run during request |
|
230 | - * |
|
231 | - * @return bool |
|
232 | - * @since 5.0.0.p |
|
233 | - */ |
|
234 | - protected function requestHandler(): bool |
|
235 | - { |
|
236 | - // load handler for EE GraphQL requests |
|
237 | - $graphQL_manager = $this->loader->getShared( |
|
238 | - 'EventEspresso\core\services\graphql\GraphQLManager' |
|
239 | - ); |
|
240 | - $graphQL_manager->init(); |
|
241 | - $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
242 | - $manifest->initialize(); |
|
243 | - return true; |
|
244 | - } |
|
228 | + /** |
|
229 | + * implements logic required to run during request |
|
230 | + * |
|
231 | + * @return bool |
|
232 | + * @since 5.0.0.p |
|
233 | + */ |
|
234 | + protected function requestHandler(): bool |
|
235 | + { |
|
236 | + // load handler for EE GraphQL requests |
|
237 | + $graphQL_manager = $this->loader->getShared( |
|
238 | + 'EventEspresso\core\services\graphql\GraphQLManager' |
|
239 | + ); |
|
240 | + $graphQL_manager->init(); |
|
241 | + $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
242 | + $manifest->initialize(); |
|
243 | + return true; |
|
244 | + } |
|
245 | 245 | } |
@@ -15,54 +15,54 @@ |
||
15 | 15 | */ |
16 | 16 | class SessionRequests extends Route |
17 | 17 | { |
18 | - /** |
|
19 | - * returns true if the current request matches this route |
|
20 | - * |
|
21 | - * @return bool |
|
22 | - * @since 5.0.0.p |
|
23 | - */ |
|
24 | - public function matchesCurrentRequest(): bool |
|
25 | - { |
|
26 | - return $this->request->isAdmin() |
|
27 | - || $this->request->isEeAjax() |
|
28 | - || $this->request->isFrontend() |
|
29 | - || $this->request->isIframe() |
|
30 | - || $this->request->isApi() |
|
31 | - || $this->request->isWordPressApi(); |
|
32 | - } |
|
18 | + /** |
|
19 | + * returns true if the current request matches this route |
|
20 | + * |
|
21 | + * @return bool |
|
22 | + * @since 5.0.0.p |
|
23 | + */ |
|
24 | + public function matchesCurrentRequest(): bool |
|
25 | + { |
|
26 | + return $this->request->isAdmin() |
|
27 | + || $this->request->isEeAjax() |
|
28 | + || $this->request->isFrontend() |
|
29 | + || $this->request->isIframe() |
|
30 | + || $this->request->isApi() |
|
31 | + || $this->request->isWordPressApi(); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @since 5.0.0.p |
|
37 | - */ |
|
38 | - protected function registerDependencies() |
|
39 | - { |
|
40 | - $this->dependency_map->registerDependencies( |
|
41 | - 'EE_Session', |
|
42 | - [ |
|
43 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
44 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
45 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
46 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
47 | - 'EventEspresso\core\services\encryption\Base64Encoder' => EE_Dependency_Map::load_from_cache, |
|
48 | - ] |
|
49 | - ); |
|
50 | - $this->dependency_map->registerDependencies( |
|
51 | - 'EventEspresso\core\services\session\SessionStartHandler', |
|
52 | - ['EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache] |
|
53 | - ); |
|
54 | - } |
|
35 | + /** |
|
36 | + * @since 5.0.0.p |
|
37 | + */ |
|
38 | + protected function registerDependencies() |
|
39 | + { |
|
40 | + $this->dependency_map->registerDependencies( |
|
41 | + 'EE_Session', |
|
42 | + [ |
|
43 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
44 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
45 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
46 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
47 | + 'EventEspresso\core\services\encryption\Base64Encoder' => EE_Dependency_Map::load_from_cache, |
|
48 | + ] |
|
49 | + ); |
|
50 | + $this->dependency_map->registerDependencies( |
|
51 | + 'EventEspresso\core\services\session\SessionStartHandler', |
|
52 | + ['EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache] |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * implements logic required to run during request |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - * @since 5.0.0.p |
|
62 | - */ |
|
63 | - protected function requestHandler(): bool |
|
64 | - { |
|
65 | - $this->loader->getShared('EE_Session'); |
|
66 | - return true; |
|
67 | - } |
|
57 | + /** |
|
58 | + * implements logic required to run during request |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + * @since 5.0.0.p |
|
62 | + */ |
|
63 | + protected function requestHandler(): bool |
|
64 | + { |
|
65 | + $this->loader->getShared('EE_Session'); |
|
66 | + return true; |
|
67 | + } |
|
68 | 68 | } |
@@ -19,195 +19,195 @@ |
||
19 | 19 | */ |
20 | 20 | class DbSafeDateTime extends DateTime |
21 | 21 | { |
22 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
23 | - /** |
|
24 | - * @type string db_safe_timestamp_format |
|
25 | - */ |
|
26 | - const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
27 | - |
|
28 | - // phpcs:enable |
|
29 | - |
|
30 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
31 | - /** |
|
32 | - * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
33 | - * |
|
34 | - * @type string $_datetime_string |
|
35 | - */ |
|
36 | - protected $_datetime_string = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * where to write the error log to |
|
40 | - * |
|
41 | - * @type string $_error_log_dir |
|
42 | - */ |
|
43 | - protected $_error_log_dir = ''; |
|
44 | - |
|
45 | - // phpcs:enable |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param string $error_log_dir |
|
50 | - */ |
|
51 | - public function setErrorLogDir(string $error_log_dir): void |
|
52 | - { |
|
53 | - // if the folder path is writable, then except the path + filename, else keep empty |
|
54 | - $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
55 | - ? $error_log_dir |
|
56 | - : ''; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function __toString(): string |
|
64 | - { |
|
65 | - return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function __sleep(): array |
|
73 | - { |
|
74 | - $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
75 | - $date = DateTime::createFromFormat( |
|
76 | - DbSafeDateTime::db_safe_timestamp_format, |
|
77 | - $this->_datetime_string |
|
78 | - ); |
|
79 | - if (! $date instanceof DateTime) { |
|
80 | - try { |
|
81 | - // we want a stack trace to determine where the malformed date came from, so... |
|
82 | - throw new DomainException(''); |
|
83 | - } catch (DomainException $e) { |
|
84 | - $stack_trace = $e->getTraceAsString(); |
|
85 | - } |
|
86 | - $this->writeToErrorLog( |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - $this->_datetime_string, |
|
93 | - '<br />', |
|
94 | - print_r(DateTime::getLastErrors(), true), |
|
95 | - PHP_VERSION, |
|
96 | - $stack_trace |
|
97 | - ) |
|
98 | - ); |
|
99 | - } |
|
100 | - return ['_datetime_string']; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * if an empty or null value got saved to the db for a datetime, |
|
106 | - * then some servers and/or PHP itself will incorrectly convert that date string |
|
107 | - * resulting in "-0001-11-30" for the year-month-day. |
|
108 | - * see the Notes section |
|
109 | - * |
|
110 | - * @link http://php.net/manual/en/datetime.formats.date.php |
|
111 | - * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
112 | - * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
113 | - * so we're no better off, but at least things won't go fatal on us. |
|
114 | - * @throws Exception |
|
115 | - */ |
|
116 | - public function __wakeup(): void |
|
117 | - { |
|
118 | - $date = self::createFromFormat( |
|
119 | - DbSafeDateTime::db_safe_timestamp_format, |
|
120 | - $this->_datetime_string |
|
121 | - ); |
|
122 | - if (! $date instanceof DateTime) { |
|
123 | - $this->writeToErrorLog( |
|
124 | - sprintf( |
|
125 | - esc_html__( |
|
126 | - 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
127 | - 'event_espresso' |
|
128 | - ), |
|
129 | - $this->_datetime_string, |
|
130 | - '<br />', |
|
131 | - print_r(DateTime::getLastErrors(), true), |
|
132 | - PHP_VERSION |
|
133 | - ) |
|
134 | - ); |
|
135 | - } else { |
|
136 | - $this->__construct( |
|
137 | - $date->format(EE_Datetime_Field::mysql_timestamp_format), |
|
138 | - new DateTimeZone($date->format('e')) |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Normalizes incoming date string so that it is a bit more stable for use. |
|
146 | - * |
|
147 | - * @param string $date_string |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public static function normalizeInvalidDate(string $date_string): string |
|
151 | - { |
|
152 | - return str_replace( |
|
153 | - ['-0001-11-29', '-0001-11-30', '0000-00-00'], |
|
154 | - '0000-01-03', |
|
155 | - $date_string |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Creates a DbSafeDateTime from ye old DateTime |
|
162 | - * |
|
163 | - * @param DateTime $datetime |
|
164 | - * @return DbSafeDateTime |
|
165 | - * @throws Exception |
|
166 | - */ |
|
167 | - public static function createFromDateTime(DateTime $datetime): DbSafeDateTime |
|
168 | - { |
|
169 | - return new DbSafeDateTime( |
|
170 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format), |
|
171 | - new DateTimeZone($datetime->format('e')) |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Parse a string into a new DateTime object according to the specified format |
|
178 | - * |
|
179 | - * @param string $format Format accepted by date(). |
|
180 | - * @param string $time String representing the time. |
|
181 | - * @param DateTimeZone|null $timezone A DateTimeZone object representing the desired time zone. |
|
182 | - * @return DbSafeDateTime|boolean |
|
183 | - * @throws Exception |
|
184 | - * @link https://php.net/manual/en/datetime.createfromformat.php |
|
185 | - */ |
|
186 | - #[\ReturnTypeWillChange] |
|
187 | - public static function createFromFormat($format, $time, ?DateTimeZone $timezone = null) |
|
188 | - { |
|
189 | - $time = self::normalizeInvalidDate($time); |
|
190 | - // Various php versions handle the third argument differently. This conditional accounts for that. |
|
191 | - $DateTime = $timezone instanceof DateTimeZone |
|
192 | - ? parent::createFromFormat($format, $time, $timezone) |
|
193 | - : parent::createFromFormat($format, $time); |
|
194 | - return $DateTime instanceof DateTime |
|
195 | - ? self::createFromDateTime($DateTime) |
|
196 | - : $DateTime; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $message |
|
202 | - */ |
|
203 | - private function writeToErrorLog(string $message) |
|
204 | - { |
|
205 | - if (! empty($this->_error_log_dir)) { |
|
206 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
207 | - error_log($message, 3, $this->_error_log_dir); |
|
208 | - } else { |
|
209 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
210 | - error_log($message); |
|
211 | - } |
|
212 | - } |
|
22 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
23 | + /** |
|
24 | + * @type string db_safe_timestamp_format |
|
25 | + */ |
|
26 | + const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
27 | + |
|
28 | + // phpcs:enable |
|
29 | + |
|
30 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
31 | + /** |
|
32 | + * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
33 | + * |
|
34 | + * @type string $_datetime_string |
|
35 | + */ |
|
36 | + protected $_datetime_string = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * where to write the error log to |
|
40 | + * |
|
41 | + * @type string $_error_log_dir |
|
42 | + */ |
|
43 | + protected $_error_log_dir = ''; |
|
44 | + |
|
45 | + // phpcs:enable |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param string $error_log_dir |
|
50 | + */ |
|
51 | + public function setErrorLogDir(string $error_log_dir): void |
|
52 | + { |
|
53 | + // if the folder path is writable, then except the path + filename, else keep empty |
|
54 | + $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
55 | + ? $error_log_dir |
|
56 | + : ''; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function __toString(): string |
|
64 | + { |
|
65 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function __sleep(): array |
|
73 | + { |
|
74 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
75 | + $date = DateTime::createFromFormat( |
|
76 | + DbSafeDateTime::db_safe_timestamp_format, |
|
77 | + $this->_datetime_string |
|
78 | + ); |
|
79 | + if (! $date instanceof DateTime) { |
|
80 | + try { |
|
81 | + // we want a stack trace to determine where the malformed date came from, so... |
|
82 | + throw new DomainException(''); |
|
83 | + } catch (DomainException $e) { |
|
84 | + $stack_trace = $e->getTraceAsString(); |
|
85 | + } |
|
86 | + $this->writeToErrorLog( |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + $this->_datetime_string, |
|
93 | + '<br />', |
|
94 | + print_r(DateTime::getLastErrors(), true), |
|
95 | + PHP_VERSION, |
|
96 | + $stack_trace |
|
97 | + ) |
|
98 | + ); |
|
99 | + } |
|
100 | + return ['_datetime_string']; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * if an empty or null value got saved to the db for a datetime, |
|
106 | + * then some servers and/or PHP itself will incorrectly convert that date string |
|
107 | + * resulting in "-0001-11-30" for the year-month-day. |
|
108 | + * see the Notes section |
|
109 | + * |
|
110 | + * @link http://php.net/manual/en/datetime.formats.date.php |
|
111 | + * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
112 | + * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
113 | + * so we're no better off, but at least things won't go fatal on us. |
|
114 | + * @throws Exception |
|
115 | + */ |
|
116 | + public function __wakeup(): void |
|
117 | + { |
|
118 | + $date = self::createFromFormat( |
|
119 | + DbSafeDateTime::db_safe_timestamp_format, |
|
120 | + $this->_datetime_string |
|
121 | + ); |
|
122 | + if (! $date instanceof DateTime) { |
|
123 | + $this->writeToErrorLog( |
|
124 | + sprintf( |
|
125 | + esc_html__( |
|
126 | + 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
127 | + 'event_espresso' |
|
128 | + ), |
|
129 | + $this->_datetime_string, |
|
130 | + '<br />', |
|
131 | + print_r(DateTime::getLastErrors(), true), |
|
132 | + PHP_VERSION |
|
133 | + ) |
|
134 | + ); |
|
135 | + } else { |
|
136 | + $this->__construct( |
|
137 | + $date->format(EE_Datetime_Field::mysql_timestamp_format), |
|
138 | + new DateTimeZone($date->format('e')) |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Normalizes incoming date string so that it is a bit more stable for use. |
|
146 | + * |
|
147 | + * @param string $date_string |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public static function normalizeInvalidDate(string $date_string): string |
|
151 | + { |
|
152 | + return str_replace( |
|
153 | + ['-0001-11-29', '-0001-11-30', '0000-00-00'], |
|
154 | + '0000-01-03', |
|
155 | + $date_string |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Creates a DbSafeDateTime from ye old DateTime |
|
162 | + * |
|
163 | + * @param DateTime $datetime |
|
164 | + * @return DbSafeDateTime |
|
165 | + * @throws Exception |
|
166 | + */ |
|
167 | + public static function createFromDateTime(DateTime $datetime): DbSafeDateTime |
|
168 | + { |
|
169 | + return new DbSafeDateTime( |
|
170 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format), |
|
171 | + new DateTimeZone($datetime->format('e')) |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Parse a string into a new DateTime object according to the specified format |
|
178 | + * |
|
179 | + * @param string $format Format accepted by date(). |
|
180 | + * @param string $time String representing the time. |
|
181 | + * @param DateTimeZone|null $timezone A DateTimeZone object representing the desired time zone. |
|
182 | + * @return DbSafeDateTime|boolean |
|
183 | + * @throws Exception |
|
184 | + * @link https://php.net/manual/en/datetime.createfromformat.php |
|
185 | + */ |
|
186 | + #[\ReturnTypeWillChange] |
|
187 | + public static function createFromFormat($format, $time, ?DateTimeZone $timezone = null) |
|
188 | + { |
|
189 | + $time = self::normalizeInvalidDate($time); |
|
190 | + // Various php versions handle the third argument differently. This conditional accounts for that. |
|
191 | + $DateTime = $timezone instanceof DateTimeZone |
|
192 | + ? parent::createFromFormat($format, $time, $timezone) |
|
193 | + : parent::createFromFormat($format, $time); |
|
194 | + return $DateTime instanceof DateTime |
|
195 | + ? self::createFromDateTime($DateTime) |
|
196 | + : $DateTime; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $message |
|
202 | + */ |
|
203 | + private function writeToErrorLog(string $message) |
|
204 | + { |
|
205 | + if (! empty($this->_error_log_dir)) { |
|
206 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
207 | + error_log($message, 3, $this->_error_log_dir); |
|
208 | + } else { |
|
209 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
210 | + error_log($message); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -13,75 +13,75 @@ |
||
13 | 13 | */ |
14 | 14 | class CurrentUser |
15 | 15 | { |
16 | - private EventManagers $event_managers; |
|
17 | - |
|
18 | - private ?WP_User $current_user = null; |
|
19 | - |
|
20 | - private bool $is_event_manager = false; |
|
21 | - |
|
22 | - private bool $is_logged_in = false; |
|
23 | - |
|
24 | - private bool $is_super_admin = false; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * CurrentUser constructor. |
|
29 | - * |
|
30 | - * @param EventManagers $event_managers |
|
31 | - */ |
|
32 | - public function __construct(EventManagers $event_managers) |
|
33 | - { |
|
34 | - $this->event_managers = $event_managers; |
|
35 | - $this->setCurrentUser(); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - public function setCurrentUser(): void |
|
40 | - { |
|
41 | - if (! $this->current_user instanceof WP_User) { |
|
42 | - $this->current_user = wp_get_current_user(); |
|
43 | - $event_manager_roles = array_keys($this->event_managers->roles()); |
|
44 | - $current_user_roles = $this->current_user->roles; |
|
45 | - $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
46 | - $this->is_super_admin = is_super_admin($this->current_user->ID); |
|
47 | - $this->is_logged_in = $this->current_user->exists(); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return WP_User |
|
54 | - */ |
|
55 | - public function currentUser(): ?WP_User |
|
56 | - { |
|
57 | - return $this->current_user; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function isEventManager(): bool |
|
65 | - { |
|
66 | - return $this->is_event_manager; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - public function isLoggedIn(): bool |
|
74 | - { |
|
75 | - return $this->is_logged_in; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return bool |
|
81 | - * @since 5.0.8.p |
|
82 | - */ |
|
83 | - public function isSuperAdmin(): bool |
|
84 | - { |
|
85 | - return $this->is_super_admin; |
|
86 | - } |
|
16 | + private EventManagers $event_managers; |
|
17 | + |
|
18 | + private ?WP_User $current_user = null; |
|
19 | + |
|
20 | + private bool $is_event_manager = false; |
|
21 | + |
|
22 | + private bool $is_logged_in = false; |
|
23 | + |
|
24 | + private bool $is_super_admin = false; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * CurrentUser constructor. |
|
29 | + * |
|
30 | + * @param EventManagers $event_managers |
|
31 | + */ |
|
32 | + public function __construct(EventManagers $event_managers) |
|
33 | + { |
|
34 | + $this->event_managers = $event_managers; |
|
35 | + $this->setCurrentUser(); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + public function setCurrentUser(): void |
|
40 | + { |
|
41 | + if (! $this->current_user instanceof WP_User) { |
|
42 | + $this->current_user = wp_get_current_user(); |
|
43 | + $event_manager_roles = array_keys($this->event_managers->roles()); |
|
44 | + $current_user_roles = $this->current_user->roles; |
|
45 | + $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
46 | + $this->is_super_admin = is_super_admin($this->current_user->ID); |
|
47 | + $this->is_logged_in = $this->current_user->exists(); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return WP_User |
|
54 | + */ |
|
55 | + public function currentUser(): ?WP_User |
|
56 | + { |
|
57 | + return $this->current_user; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function isEventManager(): bool |
|
65 | + { |
|
66 | + return $this->is_event_manager; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + public function isLoggedIn(): bool |
|
74 | + { |
|
75 | + return $this->is_logged_in; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + * @since 5.0.8.p |
|
82 | + */ |
|
83 | + public function isSuperAdmin(): bool |
|
84 | + { |
|
85 | + return $this->is_super_admin; |
|
86 | + } |
|
87 | 87 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | |
39 | 39 | public function setCurrentUser(): void |
40 | 40 | { |
41 | - if (! $this->current_user instanceof WP_User) { |
|
41 | + if ( ! $this->current_user instanceof WP_User) { |
|
42 | 42 | $this->current_user = wp_get_current_user(); |
43 | 43 | $event_manager_roles = array_keys($this->event_managers->roles()); |
44 | 44 | $current_user_roles = $this->current_user->roles; |