@@ -13,35 +13,35 @@ |
||
13 | 13 | class RewriteRules |
14 | 14 | { |
15 | 15 | |
16 | - const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
16 | + const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function flush() |
|
25 | - { |
|
26 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
27 | - } |
|
19 | + /** |
|
20 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function flush() |
|
25 | + { |
|
26 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function flushRewriteRules() |
|
36 | - { |
|
37 | - if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
38 | - add_action( |
|
39 | - 'shutdown', |
|
40 | - static function () { |
|
41 | - flush_rewrite_rules(); |
|
42 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
43 | - } |
|
44 | - ); |
|
45 | - } |
|
46 | - } |
|
30 | + /** |
|
31 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function flushRewriteRules() |
|
36 | + { |
|
37 | + if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
38 | + add_action( |
|
39 | + 'shutdown', |
|
40 | + static function () { |
|
41 | + flush_rewrite_rules(); |
|
42 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
43 | + } |
|
44 | + ); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
38 | 38 | add_action( |
39 | 39 | 'shutdown', |
40 | - static function () { |
|
40 | + static function() { |
|
41 | 41 | flush_rewrite_rules(); |
42 | 42 | update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
43 | 43 | } |
@@ -16,254 +16,254 @@ |
||
16 | 16 | final class EE_Module_Request_Router implements InterminableInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var RequestInterface $request |
|
21 | - */ |
|
22 | - private $request; |
|
19 | + /** |
|
20 | + * @var RequestInterface $request |
|
21 | + */ |
|
22 | + private $request; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var array $_previous_routes |
|
26 | - */ |
|
27 | - private static $_previous_routes = array(); |
|
24 | + /** |
|
25 | + * @var array $_previous_routes |
|
26 | + */ |
|
27 | + private static $_previous_routes = array(); |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var WP_Query $WP_Query |
|
31 | - */ |
|
32 | - public $WP_Query; |
|
29 | + /** |
|
30 | + * @var WP_Query $WP_Query |
|
31 | + */ |
|
32 | + public $WP_Query; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * EE_Module_Request_Router constructor. |
|
37 | - * |
|
38 | - * @param RequestInterface $request |
|
39 | - */ |
|
40 | - public function __construct(RequestInterface $request) |
|
41 | - { |
|
42 | - $this->request = $request; |
|
43 | - } |
|
35 | + /** |
|
36 | + * EE_Module_Request_Router constructor. |
|
37 | + * |
|
38 | + * @param RequestInterface $request |
|
39 | + */ |
|
40 | + public function __construct(RequestInterface $request) |
|
41 | + { |
|
42 | + $this->request = $request; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
48 | - * on subsequent calls to this method, |
|
49 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
50 | - * and checks if the last called route has any forwarding routes registered for it |
|
51 | - * |
|
52 | - * @param WP_Query $WP_Query |
|
53 | - * @return NULL|string |
|
54 | - * @throws EE_Error |
|
55 | - * @throws ReflectionException |
|
56 | - */ |
|
57 | - public function get_route(WP_Query $WP_Query) |
|
58 | - { |
|
59 | - $this->WP_Query = $WP_Query; |
|
60 | - // assume this if first route being called |
|
61 | - $previous_route = false; |
|
62 | - // but is it really ??? |
|
63 | - if (! empty(self::$_previous_routes)) { |
|
64 | - // get last run route |
|
65 | - $previous_routes = array_values(self::$_previous_routes); |
|
66 | - $previous_route = array_pop($previous_routes); |
|
67 | - } |
|
68 | - // has another route already been run ? |
|
69 | - if ($previous_route) { |
|
70 | - // check if forwarding has been set |
|
71 | - $current_route = $this->get_forward($previous_route); |
|
72 | - try { |
|
73 | - // check for recursive forwarding |
|
74 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
75 | - throw new EE_Error( |
|
76 | - sprintf( |
|
77 | - __( |
|
78 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - $current_route |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
85 | - } catch (EE_Error $e) { |
|
86 | - $e->get_error(); |
|
87 | - return null; |
|
88 | - } |
|
89 | - } else { |
|
90 | - // first route called |
|
91 | - $current_route = null; |
|
92 | - // grab all routes |
|
93 | - $routes = EE_Config::get_routes(); |
|
94 | - foreach ($routes as $key => $route) { |
|
95 | - // first determine if route key uses w?ldc*rds |
|
96 | - $uses_wildcards = strpos($key, '?') !== false |
|
97 | - || strpos($key, '*') !== false; |
|
98 | - // check request for module route |
|
99 | - $route_found = $uses_wildcards |
|
100 | - ? $this->request->matches($key) |
|
101 | - : $this->request->requestParamIsSet($key); |
|
102 | - if ($route_found) { |
|
103 | - $current_route = $uses_wildcards |
|
104 | - ? $this->request->getMatch($key) |
|
105 | - : $this->request->getRequestParam($key); |
|
106 | - $current_route = sanitize_text_field($current_route); |
|
107 | - if ($current_route) { |
|
108 | - $current_route = array($key, $current_route); |
|
109 | - break; |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - // sorry, but I can't read what you route ! |
|
115 | - if (empty($current_route)) { |
|
116 | - return null; |
|
117 | - } |
|
118 | - // add route to previous routes array |
|
119 | - self::$_previous_routes[] = $current_route; |
|
120 | - return $current_route; |
|
121 | - } |
|
46 | + /** |
|
47 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
48 | + * on subsequent calls to this method, |
|
49 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
50 | + * and checks if the last called route has any forwarding routes registered for it |
|
51 | + * |
|
52 | + * @param WP_Query $WP_Query |
|
53 | + * @return NULL|string |
|
54 | + * @throws EE_Error |
|
55 | + * @throws ReflectionException |
|
56 | + */ |
|
57 | + public function get_route(WP_Query $WP_Query) |
|
58 | + { |
|
59 | + $this->WP_Query = $WP_Query; |
|
60 | + // assume this if first route being called |
|
61 | + $previous_route = false; |
|
62 | + // but is it really ??? |
|
63 | + if (! empty(self::$_previous_routes)) { |
|
64 | + // get last run route |
|
65 | + $previous_routes = array_values(self::$_previous_routes); |
|
66 | + $previous_route = array_pop($previous_routes); |
|
67 | + } |
|
68 | + // has another route already been run ? |
|
69 | + if ($previous_route) { |
|
70 | + // check if forwarding has been set |
|
71 | + $current_route = $this->get_forward($previous_route); |
|
72 | + try { |
|
73 | + // check for recursive forwarding |
|
74 | + if (isset(self::$_previous_routes[ $current_route ])) { |
|
75 | + throw new EE_Error( |
|
76 | + sprintf( |
|
77 | + __( |
|
78 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + $current_route |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | + } catch (EE_Error $e) { |
|
86 | + $e->get_error(); |
|
87 | + return null; |
|
88 | + } |
|
89 | + } else { |
|
90 | + // first route called |
|
91 | + $current_route = null; |
|
92 | + // grab all routes |
|
93 | + $routes = EE_Config::get_routes(); |
|
94 | + foreach ($routes as $key => $route) { |
|
95 | + // first determine if route key uses w?ldc*rds |
|
96 | + $uses_wildcards = strpos($key, '?') !== false |
|
97 | + || strpos($key, '*') !== false; |
|
98 | + // check request for module route |
|
99 | + $route_found = $uses_wildcards |
|
100 | + ? $this->request->matches($key) |
|
101 | + : $this->request->requestParamIsSet($key); |
|
102 | + if ($route_found) { |
|
103 | + $current_route = $uses_wildcards |
|
104 | + ? $this->request->getMatch($key) |
|
105 | + : $this->request->getRequestParam($key); |
|
106 | + $current_route = sanitize_text_field($current_route); |
|
107 | + if ($current_route) { |
|
108 | + $current_route = array($key, $current_route); |
|
109 | + break; |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + // sorry, but I can't read what you route ! |
|
115 | + if (empty($current_route)) { |
|
116 | + return null; |
|
117 | + } |
|
118 | + // add route to previous routes array |
|
119 | + self::$_previous_routes[] = $current_route; |
|
120 | + return $current_route; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
126 | - * |
|
127 | - * @param string $key |
|
128 | - * @param string $current_route |
|
129 | - * @return EED_Module|object|boolean|null |
|
130 | - * @throws EE_Error |
|
131 | - * @throws ReflectionException |
|
132 | - */ |
|
133 | - public function resolve_route($key, $current_route) |
|
134 | - { |
|
135 | - // get module method that route has been mapped to |
|
136 | - $module_method = EE_Config::get_route($current_route, $key); |
|
137 | - // verify result was returned |
|
138 | - if (empty($module_method)) { |
|
139 | - $msg = sprintf( |
|
140 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
141 | - $current_route |
|
142 | - ); |
|
143 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | - return false; |
|
145 | - } |
|
146 | - // verify that result is an array |
|
147 | - if (! is_array($module_method)) { |
|
148 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | - return false; |
|
151 | - } |
|
152 | - // grab module name |
|
153 | - $module_name = $module_method[0]; |
|
154 | - // verify that a class method was registered properly |
|
155 | - if (! isset($module_method[1])) { |
|
156 | - $msg = sprintf( |
|
157 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
158 | - $current_route |
|
159 | - ); |
|
160 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
161 | - return false; |
|
162 | - } |
|
163 | - // grab method |
|
164 | - $method = $module_method[1]; |
|
165 | - // verify that class exists |
|
166 | - if (! class_exists($module_name)) { |
|
167 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
168 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
169 | - return false; |
|
170 | - } |
|
171 | - // verify that method exists |
|
172 | - if (! method_exists($module_name, $method)) { |
|
173 | - $msg = sprintf( |
|
174 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
175 | - $method, |
|
176 | - $current_route |
|
177 | - ); |
|
178 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
179 | - return false; |
|
180 | - } |
|
181 | - // instantiate module and call route method |
|
182 | - return $this->_module_router($module_name, $method); |
|
183 | - } |
|
124 | + /** |
|
125 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
126 | + * |
|
127 | + * @param string $key |
|
128 | + * @param string $current_route |
|
129 | + * @return EED_Module|object|boolean|null |
|
130 | + * @throws EE_Error |
|
131 | + * @throws ReflectionException |
|
132 | + */ |
|
133 | + public function resolve_route($key, $current_route) |
|
134 | + { |
|
135 | + // get module method that route has been mapped to |
|
136 | + $module_method = EE_Config::get_route($current_route, $key); |
|
137 | + // verify result was returned |
|
138 | + if (empty($module_method)) { |
|
139 | + $msg = sprintf( |
|
140 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
141 | + $current_route |
|
142 | + ); |
|
143 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | + return false; |
|
145 | + } |
|
146 | + // verify that result is an array |
|
147 | + if (! is_array($module_method)) { |
|
148 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
149 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | + return false; |
|
151 | + } |
|
152 | + // grab module name |
|
153 | + $module_name = $module_method[0]; |
|
154 | + // verify that a class method was registered properly |
|
155 | + if (! isset($module_method[1])) { |
|
156 | + $msg = sprintf( |
|
157 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
158 | + $current_route |
|
159 | + ); |
|
160 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
161 | + return false; |
|
162 | + } |
|
163 | + // grab method |
|
164 | + $method = $module_method[1]; |
|
165 | + // verify that class exists |
|
166 | + if (! class_exists($module_name)) { |
|
167 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
168 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
169 | + return false; |
|
170 | + } |
|
171 | + // verify that method exists |
|
172 | + if (! method_exists($module_name, $method)) { |
|
173 | + $msg = sprintf( |
|
174 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
175 | + $method, |
|
176 | + $current_route |
|
177 | + ); |
|
178 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
179 | + return false; |
|
180 | + } |
|
181 | + // instantiate module and call route method |
|
182 | + return $this->_module_router($module_name, $method); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
188 | - * |
|
189 | - * @param string $module_name |
|
190 | - * @return EED_Module|object|null |
|
191 | - */ |
|
192 | - public static function module_factory($module_name) |
|
193 | - { |
|
194 | - if ($module_name === 'EED_Module') { |
|
195 | - EE_Error::add_error( |
|
196 | - sprintf( |
|
197 | - __( |
|
198 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $module_name |
|
202 | - ), |
|
203 | - __FILE__, |
|
204 | - __FUNCTION__, |
|
205 | - __LINE__ |
|
206 | - ); |
|
207 | - return null; |
|
208 | - } |
|
209 | - // instantiate module class |
|
210 | - $module = new $module_name(); |
|
211 | - // ensure that class is actually a module |
|
212 | - if (! $module instanceof EED_Module) { |
|
213 | - EE_Error::add_error( |
|
214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | - __FILE__, |
|
216 | - __FUNCTION__, |
|
217 | - __LINE__ |
|
218 | - ); |
|
219 | - return null; |
|
220 | - } |
|
221 | - return $module; |
|
222 | - } |
|
186 | + /** |
|
187 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
188 | + * |
|
189 | + * @param string $module_name |
|
190 | + * @return EED_Module|object|null |
|
191 | + */ |
|
192 | + public static function module_factory($module_name) |
|
193 | + { |
|
194 | + if ($module_name === 'EED_Module') { |
|
195 | + EE_Error::add_error( |
|
196 | + sprintf( |
|
197 | + __( |
|
198 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $module_name |
|
202 | + ), |
|
203 | + __FILE__, |
|
204 | + __FUNCTION__, |
|
205 | + __LINE__ |
|
206 | + ); |
|
207 | + return null; |
|
208 | + } |
|
209 | + // instantiate module class |
|
210 | + $module = new $module_name(); |
|
211 | + // ensure that class is actually a module |
|
212 | + if (! $module instanceof EED_Module) { |
|
213 | + EE_Error::add_error( |
|
214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | + __FILE__, |
|
216 | + __FUNCTION__, |
|
217 | + __LINE__ |
|
218 | + ); |
|
219 | + return null; |
|
220 | + } |
|
221 | + return $module; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | - /** |
|
226 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | - * |
|
228 | - * @param string $module_name |
|
229 | - * @param string $method |
|
230 | - * @return EED_Module|null |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - private function _module_router($module_name, $method) |
|
235 | - { |
|
236 | - // instantiate module class |
|
237 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | - if ($module instanceof EED_Module) { |
|
239 | - // and call whatever action the route was for |
|
240 | - try { |
|
241 | - $module->{$method}($this->WP_Query); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - $e->get_error(); |
|
244 | - return null; |
|
245 | - } |
|
246 | - } |
|
247 | - return $module; |
|
248 | - } |
|
225 | + /** |
|
226 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | + * |
|
228 | + * @param string $module_name |
|
229 | + * @param string $method |
|
230 | + * @return EED_Module|null |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + private function _module_router($module_name, $method) |
|
235 | + { |
|
236 | + // instantiate module class |
|
237 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | + if ($module instanceof EED_Module) { |
|
239 | + // and call whatever action the route was for |
|
240 | + try { |
|
241 | + $module->{$method}($this->WP_Query); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + $e->get_error(); |
|
244 | + return null; |
|
245 | + } |
|
246 | + } |
|
247 | + return $module; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param $current_route |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_forward($current_route) |
|
256 | - { |
|
257 | - return EE_Config::get_forward($current_route); |
|
258 | - } |
|
251 | + /** |
|
252 | + * @param $current_route |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_forward($current_route) |
|
256 | + { |
|
257 | + return EE_Config::get_forward($current_route); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * @param $current_route |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_view($current_route) |
|
266 | - { |
|
267 | - return EE_Config::get_view($current_route); |
|
268 | - } |
|
261 | + /** |
|
262 | + * @param $current_route |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_view($current_route) |
|
266 | + { |
|
267 | + return EE_Config::get_view($current_route); |
|
268 | + } |
|
269 | 269 | } |
@@ -21,270 +21,270 @@ |
||
21 | 21 | class Mirror |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var ReflectionClass[] $classes |
|
26 | - */ |
|
27 | - private $classes = []; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ReflectionMethod[] $constructors |
|
31 | - */ |
|
32 | - private $constructors = []; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var ReflectionParameter[][] $parameters |
|
36 | - */ |
|
37 | - private $parameters = []; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var ReflectionParameter[][] $parameters |
|
41 | - */ |
|
42 | - private $parameter_classes = []; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var ReflectionProperty[][] $properties |
|
46 | - */ |
|
47 | - private $properties = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var ReflectionMethod[][] $methods |
|
51 | - */ |
|
52 | - private $methods = []; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $class_name |
|
57 | - * @return ReflectionClass |
|
58 | - * @throws ReflectionException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
61 | - public function getReflectionClass($class_name) |
|
62 | - { |
|
63 | - if (! is_string($class_name)) { |
|
64 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | - } |
|
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | - } |
|
69 | - return $this->classes[ $class_name ]; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $class_name |
|
75 | - * @return ReflectionMethod |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function getConstructor($class_name) |
|
80 | - { |
|
81 | - if (! is_string($class_name)) { |
|
82 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | - } |
|
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
85 | - $reflection_class = $this->getReflectionClass($class_name); |
|
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | - } |
|
88 | - return $this->constructors[ $class_name ]; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param ReflectionClass $reflection_class |
|
94 | - * @return ReflectionMethod |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | - { |
|
100 | - return $this->getConstructor($reflection_class->getName()); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $class_name |
|
106 | - * @return ReflectionParameter[] |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public function getParameters($class_name) |
|
111 | - { |
|
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
113 | - $constructor = $this->getConstructor($class_name); |
|
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | - } |
|
116 | - return $this->parameters[ $class_name ]; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param ReflectionClass $reflection_class |
|
122 | - * @return ReflectionParameter[] |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - * @throws ReflectionException |
|
125 | - */ |
|
126 | - public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | - { |
|
128 | - return $this->getParameters($reflection_class->getName()); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param ReflectionMethod $constructor |
|
134 | - * @return ReflectionParameter[] |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | - { |
|
140 | - return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param ReflectionParameter $param |
|
146 | - * @param string $class_name |
|
147 | - * @param string $index |
|
148 | - * @return string|null |
|
149 | - */ |
|
150 | - public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
151 | - { |
|
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
154 | - } |
|
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = []; |
|
157 | - } |
|
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
160 | - } |
|
161 | - // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
162 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | - ? $this->getParameterClassNameLegacy($param) |
|
164 | - : $this->getParameterClassNamePhp8($param); |
|
165 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param ReflectionParameter $param |
|
171 | - * @return string|null |
|
172 | - * @since 4.10.13.p |
|
173 | - */ |
|
174 | - private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
175 | - { |
|
176 | - $reflection_class = $param->getClass(); |
|
177 | - return $reflection_class instanceof ReflectionClass |
|
178 | - ? $param->getClass()->getName() |
|
179 | - : null; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
185 | - * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
186 | - * which can either be a ReflectionNamedType or ReflectionUnionType |
|
187 | - * |
|
188 | - * @param ReflectionParameter $param |
|
189 | - * @return null |
|
190 | - * @since 4.10.13.p |
|
191 | - */ |
|
192 | - private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
193 | - { |
|
194 | - $reflection_type = $param->getType(); |
|
195 | - |
|
196 | - if ($reflection_type instanceof \ReflectionNamedType) { |
|
197 | - return $reflection_type->getName(); |
|
198 | - } |
|
199 | - |
|
200 | - if ($reflection_type instanceof \ReflectionUnionType) { |
|
201 | - $reflection_types = $reflection_type->getTypes(); |
|
202 | - if (is_array($reflection_types)) { |
|
203 | - $first = reset($reflection_types); |
|
204 | - return $first->getName(); |
|
205 | - } |
|
206 | - } |
|
207 | - return null; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param ReflectionParameter $param |
|
213 | - * @param string $class_name |
|
214 | - * @param string $index |
|
215 | - * @return string|null |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
219 | - { |
|
220 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
222 | - } |
|
223 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | - $this->parameter_classes[ $class_name ] = []; |
|
225 | - } |
|
226 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
228 | - } |
|
229 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | - ? $param->getDefaultValue() |
|
231 | - : null; |
|
232 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param string $class_name |
|
238 | - * @return ReflectionProperty[] |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws ReflectionException |
|
241 | - */ |
|
242 | - public function getProperties($class_name) |
|
243 | - { |
|
244 | - if (! isset($this->properties[ $class_name ])) { |
|
245 | - $reflection_class = $this->getReflectionClass($class_name); |
|
246 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
247 | - } |
|
248 | - return $this->properties[ $class_name ]; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param ReflectionClass $reflection_class |
|
254 | - * @return ReflectionProperty[] |
|
255 | - * @throws InvalidDataTypeException |
|
256 | - * @throws ReflectionException |
|
257 | - */ |
|
258 | - public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
259 | - { |
|
260 | - return $this->getProperties($reflection_class->getName()); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $class_name |
|
266 | - * @return ReflectionMethod[] |
|
267 | - * @throws InvalidDataTypeException |
|
268 | - * @throws ReflectionException |
|
269 | - */ |
|
270 | - public function getMethods($class_name) |
|
271 | - { |
|
272 | - if (! isset($this->methods[ $class_name ])) { |
|
273 | - $reflection_class = $this->getReflectionClass($class_name); |
|
274 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
275 | - } |
|
276 | - return $this->methods[ $class_name ]; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * @param ReflectionClass $reflection_class ) |
|
282 | - * @return ReflectionMethod[] |
|
283 | - * @throws InvalidDataTypeException |
|
284 | - * @throws ReflectionException |
|
285 | - */ |
|
286 | - public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
287 | - { |
|
288 | - return $this->getMethods($reflection_class->getName()); |
|
289 | - } |
|
24 | + /** |
|
25 | + * @var ReflectionClass[] $classes |
|
26 | + */ |
|
27 | + private $classes = []; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ReflectionMethod[] $constructors |
|
31 | + */ |
|
32 | + private $constructors = []; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var ReflectionParameter[][] $parameters |
|
36 | + */ |
|
37 | + private $parameters = []; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var ReflectionParameter[][] $parameters |
|
41 | + */ |
|
42 | + private $parameter_classes = []; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var ReflectionProperty[][] $properties |
|
46 | + */ |
|
47 | + private $properties = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var ReflectionMethod[][] $methods |
|
51 | + */ |
|
52 | + private $methods = []; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $class_name |
|
57 | + * @return ReflectionClass |
|
58 | + * @throws ReflectionException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | + public function getReflectionClass($class_name) |
|
62 | + { |
|
63 | + if (! is_string($class_name)) { |
|
64 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | + } |
|
66 | + if (! isset($this->classes[ $class_name ])) { |
|
67 | + $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | + } |
|
69 | + return $this->classes[ $class_name ]; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $class_name |
|
75 | + * @return ReflectionMethod |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function getConstructor($class_name) |
|
80 | + { |
|
81 | + if (! is_string($class_name)) { |
|
82 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | + } |
|
84 | + if (! isset($this->constructors[ $class_name ])) { |
|
85 | + $reflection_class = $this->getReflectionClass($class_name); |
|
86 | + $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | + } |
|
88 | + return $this->constructors[ $class_name ]; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param ReflectionClass $reflection_class |
|
94 | + * @return ReflectionMethod |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | + { |
|
100 | + return $this->getConstructor($reflection_class->getName()); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $class_name |
|
106 | + * @return ReflectionParameter[] |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public function getParameters($class_name) |
|
111 | + { |
|
112 | + if (! isset($this->parameters[ $class_name ])) { |
|
113 | + $constructor = $this->getConstructor($class_name); |
|
114 | + $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | + } |
|
116 | + return $this->parameters[ $class_name ]; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param ReflectionClass $reflection_class |
|
122 | + * @return ReflectionParameter[] |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + * @throws ReflectionException |
|
125 | + */ |
|
126 | + public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | + { |
|
128 | + return $this->getParameters($reflection_class->getName()); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param ReflectionMethod $constructor |
|
134 | + * @return ReflectionParameter[] |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | + { |
|
140 | + return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param ReflectionParameter $param |
|
146 | + * @param string $class_name |
|
147 | + * @param string $index |
|
148 | + * @return string|null |
|
149 | + */ |
|
150 | + public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
151 | + { |
|
152 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
154 | + } |
|
155 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | + $this->parameter_classes[ $class_name ] = []; |
|
157 | + } |
|
158 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
160 | + } |
|
161 | + // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
162 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | + ? $this->getParameterClassNameLegacy($param) |
|
164 | + : $this->getParameterClassNamePhp8($param); |
|
165 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param ReflectionParameter $param |
|
171 | + * @return string|null |
|
172 | + * @since 4.10.13.p |
|
173 | + */ |
|
174 | + private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
175 | + { |
|
176 | + $reflection_class = $param->getClass(); |
|
177 | + return $reflection_class instanceof ReflectionClass |
|
178 | + ? $param->getClass()->getName() |
|
179 | + : null; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
185 | + * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
186 | + * which can either be a ReflectionNamedType or ReflectionUnionType |
|
187 | + * |
|
188 | + * @param ReflectionParameter $param |
|
189 | + * @return null |
|
190 | + * @since 4.10.13.p |
|
191 | + */ |
|
192 | + private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
193 | + { |
|
194 | + $reflection_type = $param->getType(); |
|
195 | + |
|
196 | + if ($reflection_type instanceof \ReflectionNamedType) { |
|
197 | + return $reflection_type->getName(); |
|
198 | + } |
|
199 | + |
|
200 | + if ($reflection_type instanceof \ReflectionUnionType) { |
|
201 | + $reflection_types = $reflection_type->getTypes(); |
|
202 | + if (is_array($reflection_types)) { |
|
203 | + $first = reset($reflection_types); |
|
204 | + return $first->getName(); |
|
205 | + } |
|
206 | + } |
|
207 | + return null; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param ReflectionParameter $param |
|
213 | + * @param string $class_name |
|
214 | + * @param string $index |
|
215 | + * @return string|null |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
219 | + { |
|
220 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
222 | + } |
|
223 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | + $this->parameter_classes[ $class_name ] = []; |
|
225 | + } |
|
226 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
228 | + } |
|
229 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | + ? $param->getDefaultValue() |
|
231 | + : null; |
|
232 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param string $class_name |
|
238 | + * @return ReflectionProperty[] |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws ReflectionException |
|
241 | + */ |
|
242 | + public function getProperties($class_name) |
|
243 | + { |
|
244 | + if (! isset($this->properties[ $class_name ])) { |
|
245 | + $reflection_class = $this->getReflectionClass($class_name); |
|
246 | + $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
247 | + } |
|
248 | + return $this->properties[ $class_name ]; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param ReflectionClass $reflection_class |
|
254 | + * @return ReflectionProperty[] |
|
255 | + * @throws InvalidDataTypeException |
|
256 | + * @throws ReflectionException |
|
257 | + */ |
|
258 | + public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
259 | + { |
|
260 | + return $this->getProperties($reflection_class->getName()); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $class_name |
|
266 | + * @return ReflectionMethod[] |
|
267 | + * @throws InvalidDataTypeException |
|
268 | + * @throws ReflectionException |
|
269 | + */ |
|
270 | + public function getMethods($class_name) |
|
271 | + { |
|
272 | + if (! isset($this->methods[ $class_name ])) { |
|
273 | + $reflection_class = $this->getReflectionClass($class_name); |
|
274 | + $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
275 | + } |
|
276 | + return $this->methods[ $class_name ]; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * @param ReflectionClass $reflection_class ) |
|
282 | + * @return ReflectionMethod[] |
|
283 | + * @throws InvalidDataTypeException |
|
284 | + * @throws ReflectionException |
|
285 | + */ |
|
286 | + public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
287 | + { |
|
288 | + return $this->getMethods($reflection_class->getName()); |
|
289 | + } |
|
290 | 290 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getReflectionClass($class_name) |
62 | 62 | { |
63 | - if (! is_string($class_name)) { |
|
63 | + if ( ! is_string($class_name)) { |
|
64 | 64 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
65 | 65 | } |
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
66 | + if ( ! isset($this->classes[$class_name])) { |
|
67 | + $this->classes[$class_name] = new ReflectionClass($class_name); |
|
68 | 68 | } |
69 | - return $this->classes[ $class_name ]; |
|
69 | + return $this->classes[$class_name]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getConstructor($class_name) |
80 | 80 | { |
81 | - if (! is_string($class_name)) { |
|
81 | + if ( ! is_string($class_name)) { |
|
82 | 82 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
83 | 83 | } |
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
84 | + if ( ! isset($this->constructors[$class_name])) { |
|
85 | 85 | $reflection_class = $this->getReflectionClass($class_name); |
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | + $this->constructors[$class_name] = $reflection_class->getConstructor(); |
|
87 | 87 | } |
88 | - return $this->constructors[ $class_name ]; |
|
88 | + return $this->constructors[$class_name]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getParameters($class_name) |
111 | 111 | { |
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
112 | + if ( ! isset($this->parameters[$class_name])) { |
|
113 | 113 | $constructor = $this->getConstructor($class_name); |
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | + $this->parameters[$class_name] = $constructor->getParameters(); |
|
115 | 115 | } |
116 | - return $this->parameters[ $class_name ]; |
|
116 | + return $this->parameters[$class_name]; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
151 | 151 | { |
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
152 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
154 | 154 | } |
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = []; |
|
155 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
156 | + $this->parameter_classes[$class_name] = []; |
|
157 | 157 | } |
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
158 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
159 | + $this->parameter_classes[$class_name][$index] = []; |
|
160 | 160 | } |
161 | 161 | // ReflectionParameter::getClass() is deprecated in PHP 8+ |
162 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
162 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = PHP_VERSION_ID < 80000 |
|
163 | 163 | ? $this->getParameterClassNameLegacy($param) |
164 | 164 | : $this->getParameterClassNamePhp8($param); |
165 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
165 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -217,19 +217,19 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
219 | 219 | { |
220 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
221 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
220 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) { |
|
221 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
222 | 222 | } |
223 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
224 | - $this->parameter_classes[ $class_name ] = []; |
|
223 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
224 | + $this->parameter_classes[$class_name] = []; |
|
225 | 225 | } |
226 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
227 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
226 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
227 | + $this->parameter_classes[$class_name][$index] = []; |
|
228 | 228 | } |
229 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
229 | + $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable() |
|
230 | 230 | ? $param->getDefaultValue() |
231 | 231 | : null; |
232 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
232 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function getProperties($class_name) |
243 | 243 | { |
244 | - if (! isset($this->properties[ $class_name ])) { |
|
244 | + if ( ! isset($this->properties[$class_name])) { |
|
245 | 245 | $reflection_class = $this->getReflectionClass($class_name); |
246 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
246 | + $this->properties[$class_name] = $reflection_class->getProperties(); |
|
247 | 247 | } |
248 | - return $this->properties[ $class_name ]; |
|
248 | + return $this->properties[$class_name]; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function getMethods($class_name) |
271 | 271 | { |
272 | - if (! isset($this->methods[ $class_name ])) { |
|
272 | + if ( ! isset($this->methods[$class_name])) { |
|
273 | 273 | $reflection_class = $this->getReflectionClass($class_name); |
274 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
274 | + $this->methods[$class_name] = $reflection_class->getMethods(); |
|
275 | 275 | } |
276 | - return $this->methods[ $class_name ]; |
|
276 | + return $this->methods[$class_name]; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 |
@@ -27,225 +27,225 @@ |
||
27 | 27 | class ProgressStepManager |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var ProgressStepInterface[] |
|
32 | - */ |
|
33 | - private $collection; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $default_step; |
|
39 | - |
|
40 | - /** |
|
41 | - * the key used for the URL param that denotes the current form step |
|
42 | - * defaults to 'ee-form-step' |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private $form_step_url_key = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var ProgressStepsDisplayInterface |
|
50 | - */ |
|
51 | - private $display_strategy; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var RequestInterface |
|
55 | - */ |
|
56 | - private $request; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * ProgressStepManager constructor |
|
61 | - * |
|
62 | - * @param string $display_strategy_name |
|
63 | - * @param string $default_step |
|
64 | - * @param string $form_step_url_key |
|
65 | - * @param CollectionInterface $collection |
|
66 | - * @param RequestInterface $request |
|
67 | - */ |
|
68 | - public function __construct( |
|
69 | - $display_strategy_name = 'number_bubbles', |
|
70 | - $default_step = '', |
|
71 | - $form_step_url_key = '', |
|
72 | - CollectionInterface $collection = null, |
|
73 | - RequestInterface $request = null |
|
74 | - ) { |
|
75 | - $this->setDisplayStrategy($display_strategy_name); |
|
76 | - $this->setDefaultStep($default_step); |
|
77 | - $this->setFormStepUrlKey($form_step_url_key); |
|
78 | - if (! $collection instanceof CollectionInterface) { |
|
79 | - $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
|
80 | - } |
|
81 | - $this->collection = $collection; |
|
82 | - if (! $request instanceof RequestInterface) { |
|
83 | - /** @var RequestInterface $request */ |
|
84 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
85 | - } |
|
86 | - $this->request = $request; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $display_strategy_name |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidClassException |
|
94 | - */ |
|
95 | - protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
|
96 | - { |
|
97 | - if (! is_string($display_strategy_name)) { |
|
98 | - throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
|
99 | - } |
|
100 | - // build up FQCN from incoming display strategy folder name |
|
101 | - $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
|
102 | - $display_strategy_class .= $display_strategy_name . '\\'; |
|
103 | - $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
|
104 | - $display_strategy_class .= 'ProgressStepsDisplay'; |
|
105 | - $display_strategy_class = apply_filters( |
|
106 | - 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
|
107 | - $display_strategy_class |
|
108 | - ); |
|
109 | - if (! class_exists($display_strategy_class)) { |
|
110 | - throw new InvalidClassException($display_strategy_class); |
|
111 | - } |
|
112 | - $display_strategy = new $display_strategy_class(); |
|
113 | - if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
114 | - throw new InvalidClassException( |
|
115 | - $display_strategy_class, |
|
116 | - sprintf( |
|
117 | - __('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'), |
|
118 | - $display_strategy_class, |
|
119 | - '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
|
120 | - ) |
|
121 | - ); |
|
122 | - } |
|
123 | - $this->display_strategy = $display_strategy; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $default_step |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - public function setDefaultStep($default_step) |
|
132 | - { |
|
133 | - if (! is_string($default_step)) { |
|
134 | - throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
|
135 | - } |
|
136 | - $this->default_step = $default_step; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $form_step_url_key |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - */ |
|
144 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
145 | - { |
|
146 | - if (! is_string($form_step_url_key)) { |
|
147 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
148 | - } |
|
149 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param string $step |
|
155 | - * @throws InvalidIdentifierException |
|
156 | - */ |
|
157 | - public function setCurrentStep($step = '') |
|
158 | - { |
|
159 | - // use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
|
160 | - $step = ! empty($step) |
|
161 | - ? $step |
|
162 | - : $this->request->getRequestParam($this->form_step_url_key, $this->default_step); |
|
163 | - // grab the step previously known as current, in case we need to revert |
|
164 | - $current_current_step = $this->collection->current(); |
|
165 | - // verify that requested step exists |
|
166 | - if (! $this->collection->has($step)) { |
|
167 | - throw new InvalidIdentifierException($step, $this->default_step); |
|
168 | - } |
|
169 | - if ($this->collection->setCurrent($step)) { |
|
170 | - // if the old boss is the same as the new boss, then nothing changes |
|
171 | - if ($this->collection->current() !== $current_current_step) { |
|
172 | - $current_current_step->setIsCurrent(false); |
|
173 | - } |
|
174 | - $this->collection->current()->setIsCurrent(); |
|
175 | - } else { |
|
176 | - $this->collection->setCurrent($current_current_step->id()); |
|
177 | - $current_current_step->setIsCurrent(true); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * setPreviousStepsCompleted |
|
184 | - */ |
|
185 | - public function setPreviousStepsCompleted() |
|
186 | - { |
|
187 | - $current_current_step = $this->collection->current(); |
|
188 | - $this->collection->rewind(); |
|
189 | - while ($this->collection->valid()) { |
|
190 | - if ($this->collection->current() === $current_current_step) { |
|
191 | - break; |
|
192 | - } |
|
193 | - $this->setCurrentStepCompleted(); |
|
194 | - $this->collection->next(); |
|
195 | - } |
|
196 | - $this->collection->setCurrentUsingObject($current_current_step); |
|
197 | - return false; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @return ProgressStepInterface |
|
203 | - */ |
|
204 | - public function currentStep() |
|
205 | - { |
|
206 | - return $this->collection->current(); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @return ProgressStepInterface |
|
212 | - */ |
|
213 | - public function nextStep() |
|
214 | - { |
|
215 | - return $this->collection->next(); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - public function enqueueStylesAndScripts() |
|
223 | - { |
|
224 | - $this->display_strategy->enqueueStylesAndScripts(); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * echos out HTML |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function displaySteps() |
|
234 | - { |
|
235 | - return EEH_Template::display_template( |
|
236 | - $this->display_strategy->getTemplate(), |
|
237 | - array('progress_steps' => $this->collection), |
|
238 | - true |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param bool $completed |
|
245 | - * @return ProgressStepInterface |
|
246 | - */ |
|
247 | - public function setCurrentStepCompleted($completed = true) |
|
248 | - { |
|
249 | - return $this->collection->current()->setIsCompleted($completed); |
|
250 | - } |
|
30 | + /** |
|
31 | + * @var ProgressStepInterface[] |
|
32 | + */ |
|
33 | + private $collection; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $default_step; |
|
39 | + |
|
40 | + /** |
|
41 | + * the key used for the URL param that denotes the current form step |
|
42 | + * defaults to 'ee-form-step' |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private $form_step_url_key = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var ProgressStepsDisplayInterface |
|
50 | + */ |
|
51 | + private $display_strategy; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var RequestInterface |
|
55 | + */ |
|
56 | + private $request; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * ProgressStepManager constructor |
|
61 | + * |
|
62 | + * @param string $display_strategy_name |
|
63 | + * @param string $default_step |
|
64 | + * @param string $form_step_url_key |
|
65 | + * @param CollectionInterface $collection |
|
66 | + * @param RequestInterface $request |
|
67 | + */ |
|
68 | + public function __construct( |
|
69 | + $display_strategy_name = 'number_bubbles', |
|
70 | + $default_step = '', |
|
71 | + $form_step_url_key = '', |
|
72 | + CollectionInterface $collection = null, |
|
73 | + RequestInterface $request = null |
|
74 | + ) { |
|
75 | + $this->setDisplayStrategy($display_strategy_name); |
|
76 | + $this->setDefaultStep($default_step); |
|
77 | + $this->setFormStepUrlKey($form_step_url_key); |
|
78 | + if (! $collection instanceof CollectionInterface) { |
|
79 | + $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
|
80 | + } |
|
81 | + $this->collection = $collection; |
|
82 | + if (! $request instanceof RequestInterface) { |
|
83 | + /** @var RequestInterface $request */ |
|
84 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
85 | + } |
|
86 | + $this->request = $request; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $display_strategy_name |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidClassException |
|
94 | + */ |
|
95 | + protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
|
96 | + { |
|
97 | + if (! is_string($display_strategy_name)) { |
|
98 | + throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
|
99 | + } |
|
100 | + // build up FQCN from incoming display strategy folder name |
|
101 | + $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
|
102 | + $display_strategy_class .= $display_strategy_name . '\\'; |
|
103 | + $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
|
104 | + $display_strategy_class .= 'ProgressStepsDisplay'; |
|
105 | + $display_strategy_class = apply_filters( |
|
106 | + 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
|
107 | + $display_strategy_class |
|
108 | + ); |
|
109 | + if (! class_exists($display_strategy_class)) { |
|
110 | + throw new InvalidClassException($display_strategy_class); |
|
111 | + } |
|
112 | + $display_strategy = new $display_strategy_class(); |
|
113 | + if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
114 | + throw new InvalidClassException( |
|
115 | + $display_strategy_class, |
|
116 | + sprintf( |
|
117 | + __('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'), |
|
118 | + $display_strategy_class, |
|
119 | + '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
|
120 | + ) |
|
121 | + ); |
|
122 | + } |
|
123 | + $this->display_strategy = $display_strategy; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $default_step |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + public function setDefaultStep($default_step) |
|
132 | + { |
|
133 | + if (! is_string($default_step)) { |
|
134 | + throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
|
135 | + } |
|
136 | + $this->default_step = $default_step; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $form_step_url_key |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + */ |
|
144 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
145 | + { |
|
146 | + if (! is_string($form_step_url_key)) { |
|
147 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
148 | + } |
|
149 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param string $step |
|
155 | + * @throws InvalidIdentifierException |
|
156 | + */ |
|
157 | + public function setCurrentStep($step = '') |
|
158 | + { |
|
159 | + // use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
|
160 | + $step = ! empty($step) |
|
161 | + ? $step |
|
162 | + : $this->request->getRequestParam($this->form_step_url_key, $this->default_step); |
|
163 | + // grab the step previously known as current, in case we need to revert |
|
164 | + $current_current_step = $this->collection->current(); |
|
165 | + // verify that requested step exists |
|
166 | + if (! $this->collection->has($step)) { |
|
167 | + throw new InvalidIdentifierException($step, $this->default_step); |
|
168 | + } |
|
169 | + if ($this->collection->setCurrent($step)) { |
|
170 | + // if the old boss is the same as the new boss, then nothing changes |
|
171 | + if ($this->collection->current() !== $current_current_step) { |
|
172 | + $current_current_step->setIsCurrent(false); |
|
173 | + } |
|
174 | + $this->collection->current()->setIsCurrent(); |
|
175 | + } else { |
|
176 | + $this->collection->setCurrent($current_current_step->id()); |
|
177 | + $current_current_step->setIsCurrent(true); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * setPreviousStepsCompleted |
|
184 | + */ |
|
185 | + public function setPreviousStepsCompleted() |
|
186 | + { |
|
187 | + $current_current_step = $this->collection->current(); |
|
188 | + $this->collection->rewind(); |
|
189 | + while ($this->collection->valid()) { |
|
190 | + if ($this->collection->current() === $current_current_step) { |
|
191 | + break; |
|
192 | + } |
|
193 | + $this->setCurrentStepCompleted(); |
|
194 | + $this->collection->next(); |
|
195 | + } |
|
196 | + $this->collection->setCurrentUsingObject($current_current_step); |
|
197 | + return false; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @return ProgressStepInterface |
|
203 | + */ |
|
204 | + public function currentStep() |
|
205 | + { |
|
206 | + return $this->collection->current(); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @return ProgressStepInterface |
|
212 | + */ |
|
213 | + public function nextStep() |
|
214 | + { |
|
215 | + return $this->collection->next(); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + public function enqueueStylesAndScripts() |
|
223 | + { |
|
224 | + $this->display_strategy->enqueueStylesAndScripts(); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * echos out HTML |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function displaySteps() |
|
234 | + { |
|
235 | + return EEH_Template::display_template( |
|
236 | + $this->display_strategy->getTemplate(), |
|
237 | + array('progress_steps' => $this->collection), |
|
238 | + true |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param bool $completed |
|
245 | + * @return ProgressStepInterface |
|
246 | + */ |
|
247 | + public function setCurrentStepCompleted($completed = true) |
|
248 | + { |
|
249 | + return $this->collection->current()->setIsCompleted($completed); |
|
250 | + } |
|
251 | 251 | } |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | $this->setDisplayStrategy($display_strategy_name); |
76 | 76 | $this->setDefaultStep($default_step); |
77 | 77 | $this->setFormStepUrlKey($form_step_url_key); |
78 | - if (! $collection instanceof CollectionInterface) { |
|
78 | + if ( ! $collection instanceof CollectionInterface) { |
|
79 | 79 | $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
80 | 80 | } |
81 | 81 | $this->collection = $collection; |
82 | - if (! $request instanceof RequestInterface) { |
|
82 | + if ( ! $request instanceof RequestInterface) { |
|
83 | 83 | /** @var RequestInterface $request */ |
84 | 84 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
85 | 85 | } |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
96 | 96 | { |
97 | - if (! is_string($display_strategy_name)) { |
|
97 | + if ( ! is_string($display_strategy_name)) { |
|
98 | 98 | throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
99 | 99 | } |
100 | 100 | // build up FQCN from incoming display strategy folder name |
101 | 101 | $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
102 | - $display_strategy_class .= $display_strategy_name . '\\'; |
|
102 | + $display_strategy_class .= $display_strategy_name.'\\'; |
|
103 | 103 | $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
104 | 104 | $display_strategy_class .= 'ProgressStepsDisplay'; |
105 | 105 | $display_strategy_class = apply_filters( |
106 | 106 | 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
107 | 107 | $display_strategy_class |
108 | 108 | ); |
109 | - if (! class_exists($display_strategy_class)) { |
|
109 | + if ( ! class_exists($display_strategy_class)) { |
|
110 | 110 | throw new InvalidClassException($display_strategy_class); |
111 | 111 | } |
112 | 112 | $display_strategy = new $display_strategy_class(); |
113 | - if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
113 | + if ( ! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
114 | 114 | throw new InvalidClassException( |
115 | 115 | $display_strategy_class, |
116 | 116 | sprintf( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function setDefaultStep($default_step) |
132 | 132 | { |
133 | - if (! is_string($default_step)) { |
|
133 | + if ( ! is_string($default_step)) { |
|
134 | 134 | throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
135 | 135 | } |
136 | 136 | $this->default_step = $default_step; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
145 | 145 | { |
146 | - if (! is_string($form_step_url_key)) { |
|
146 | + if ( ! is_string($form_step_url_key)) { |
|
147 | 147 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
148 | 148 | } |
149 | 149 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | // grab the step previously known as current, in case we need to revert |
164 | 164 | $current_current_step = $this->collection->current(); |
165 | 165 | // verify that requested step exists |
166 | - if (! $this->collection->has($step)) { |
|
166 | + if ( ! $this->collection->has($step)) { |
|
167 | 167 | throw new InvalidIdentifierException($step, $this->default_step); |
168 | 168 | } |
169 | 169 | if ($this->collection->setCurrent($step)) { |
@@ -26,771 +26,771 @@ |
||
26 | 26 | class EE_Registration_Processor extends EE_Processor_Base |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Registration_Processor $_instance |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - private static $_instance; |
|
34 | - |
|
35 | - /** |
|
36 | - * initial reg status at the beginning of this request. |
|
37 | - * indexed by registration ID |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $_old_reg_status = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * reg status at the end of the request after all processing. |
|
45 | - * indexed by registration ID |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $_new_reg_status = []; |
|
50 | - |
|
51 | - /** |
|
52 | - * amounts paid at the end of the request after all processing. |
|
53 | - * indexed by registration ID |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - protected static $_amount_paid = []; |
|
58 | - |
|
59 | - /** |
|
60 | - * Cache of the reg final price for registrations corresponding to a ticket line item |
|
61 | - * |
|
62 | - * @deprecated |
|
63 | - * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
64 | - */ |
|
65 | - protected $_reg_final_price_per_tkt_line_item; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var RequestInterface $request |
|
69 | - */ |
|
70 | - protected $request; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @singleton method used to instantiate class object |
|
75 | - * @param RequestInterface|null $request |
|
76 | - * @return EE_Registration_Processor instance |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws InvalidInterfaceException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - */ |
|
81 | - public static function instance(RequestInterface $request = null) |
|
82 | - { |
|
83 | - // check if class object is instantiated |
|
84 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
85 | - if (! $request instanceof RequestInterface) { |
|
86 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
87 | - } |
|
88 | - self::$_instance = new self($request); |
|
89 | - } |
|
90 | - return self::$_instance; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Registration_Processor constructor. |
|
96 | - * |
|
97 | - * @param RequestInterface $request |
|
98 | - */ |
|
99 | - public function __construct(RequestInterface $request) |
|
100 | - { |
|
101 | - $this->request = $request; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param int $REG_ID |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function old_reg_status($REG_ID) |
|
110 | - { |
|
111 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param int $REG_ID |
|
117 | - * @param string $old_reg_status |
|
118 | - */ |
|
119 | - public function set_old_reg_status($REG_ID, $old_reg_status) |
|
120 | - { |
|
121 | - // only set the first time |
|
122 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
123 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param int $REG_ID |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function new_reg_status($REG_ID) |
|
133 | - { |
|
134 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param int $REG_ID |
|
140 | - * @param string $new_reg_status |
|
141 | - */ |
|
142 | - public function set_new_reg_status($REG_ID, $new_reg_status) |
|
143 | - { |
|
144 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * reg_status_updated |
|
150 | - * |
|
151 | - * @param int $REG_ID |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function reg_status_updated($REG_ID) |
|
155 | - { |
|
156 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param EE_Registration $registration |
|
162 | - * @throws EE_Error |
|
163 | - * @throws EntityNotFoundException |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws InvalidDataTypeException |
|
166 | - * @throws InvalidInterfaceException |
|
167 | - * @throws ReflectionException |
|
168 | - * @throws RuntimeException |
|
169 | - */ |
|
170 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
171 | - { |
|
172 | - $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
173 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
174 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
175 | - $registration->save(); |
|
176 | - // trigger notifications |
|
177 | - $this->trigger_registration_update_notifications($registration); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * manually_update_registration_status |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * @param EE_Registration $registration |
|
186 | - * @param string $new_reg_status |
|
187 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
188 | - * to client code |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws EntityNotFoundException |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws ReflectionException |
|
196 | - * @throws RuntimeException |
|
197 | - */ |
|
198 | - public function manually_update_registration_status( |
|
199 | - EE_Registration $registration, |
|
200 | - $new_reg_status = '', |
|
201 | - $save = true |
|
202 | - ) { |
|
203 | - // set initial REG_Status |
|
204 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
205 | - // set incoming REG_Status |
|
206 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
207 | - // toggle reg status but only if it has changed and the user can do so |
|
208 | - if ($this->reg_status_updated($registration->ID()) |
|
209 | - && ( |
|
210 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
211 | - || EE_Registry::instance()->CAP->current_user_can( |
|
212 | - 'ee_edit_registration', |
|
213 | - 'toggle_registration_status', |
|
214 | - $registration->ID() |
|
215 | - ) |
|
216 | - ) |
|
217 | - ) { |
|
218 | - // change status to new value |
|
219 | - $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
220 | - if ($updated && $save) { |
|
221 | - $registration->save(); |
|
222 | - } |
|
223 | - return true; |
|
224 | - } |
|
225 | - return false; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * toggle_incomplete_registration_status_to_default |
|
231 | - * changes any incomplete registrations to either the event or global default registration status |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param EE_Registration $registration |
|
235 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
236 | - * that up to client code |
|
237 | - * @param ContextInterface|null $context |
|
238 | - * @return void |
|
239 | - * @throws EE_Error |
|
240 | - * @throws InvalidArgumentException |
|
241 | - * @throws ReflectionException |
|
242 | - * @throws RuntimeException |
|
243 | - * @throws EntityNotFoundException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - */ |
|
247 | - public function toggle_incomplete_registration_status_to_default( |
|
248 | - EE_Registration $registration, |
|
249 | - $save = true, |
|
250 | - ContextInterface $context = null |
|
251 | - ) { |
|
252 | - $existing_reg_status = $registration->status_ID(); |
|
253 | - // set initial REG_Status |
|
254 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
255 | - // is the registration currently incomplete ? |
|
256 | - if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
257 | - // grab default reg status for the event, if set |
|
258 | - $event_default_registration_status = $registration->event()->default_registration_status(); |
|
259 | - // if no default reg status is set for the event, then use the global value |
|
260 | - $STS_ID = ! empty($event_default_registration_status) |
|
261 | - ? $event_default_registration_status |
|
262 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
263 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
264 | - $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
265 | - : $STS_ID; |
|
266 | - // set incoming REG_Status |
|
267 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
268 | - $registration->set_status($STS_ID, false, $context); |
|
269 | - if ($save) { |
|
270 | - $registration->save(); |
|
271 | - } |
|
272 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
273 | - if (! EE_Processor_Base::$IPN) { |
|
274 | - // otherwise, send out notifications |
|
275 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
276 | - } |
|
277 | - // DEBUG LOG |
|
278 | - // $this->log( |
|
279 | - // __CLASS__, |
|
280 | - // __FUNCTION__, |
|
281 | - // __LINE__, |
|
282 | - // $registration->transaction(), |
|
283 | - // array( |
|
284 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
285 | - // 'deliver_notifications' => has_filter( |
|
286 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
287 | - // ), |
|
288 | - // ) |
|
289 | - // ); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * toggle_registration_status_for_default_approved_events |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @param EE_Registration $registration |
|
299 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
300 | - * to client code |
|
301 | - * @return bool |
|
302 | - * @throws EE_Error |
|
303 | - * @throws EntityNotFoundException |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws InvalidInterfaceException |
|
307 | - * @throws ReflectionException |
|
308 | - * @throws RuntimeException |
|
309 | - */ |
|
310 | - public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
311 | - { |
|
312 | - $reg_status = $registration->status_ID(); |
|
313 | - // set initial REG_Status |
|
314 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
315 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
316 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
317 | - if ($reg_status !== EEM_Registration::status_id_cancelled |
|
318 | - && $reg_status |
|
319 | - !== EEM_Registration::status_id_declined |
|
320 | - && $reg_status !== EEM_Registration::status_id_approved |
|
321 | - && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
322 | - ) { |
|
323 | - // set incoming REG_Status |
|
324 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
325 | - // toggle status to approved |
|
326 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
327 | - if ($save) { |
|
328 | - $registration->save(); |
|
329 | - } |
|
330 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
331 | - if (! EE_Processor_Base::$IPN) { |
|
332 | - // otherwise, send out notifications |
|
333 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
334 | - } |
|
335 | - // DEBUG LOG |
|
336 | - // $this->log( |
|
337 | - // __CLASS__, |
|
338 | - // __FUNCTION__, |
|
339 | - // __LINE__, |
|
340 | - // $registration->transaction(), |
|
341 | - // array( |
|
342 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
343 | - // 'deliver_notifications' => has_filter( |
|
344 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
345 | - // ), |
|
346 | - // ) |
|
347 | - // ); |
|
348 | - return true; |
|
349 | - } |
|
350 | - return false; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * toggle_registration_statuses_if_no_monies_owing |
|
356 | - * |
|
357 | - * @access public |
|
358 | - * @param EE_Registration $registration |
|
359 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
360 | - * to client code |
|
361 | - * @param array $additional_details |
|
362 | - * @return bool |
|
363 | - * @throws EE_Error |
|
364 | - * @throws EntityNotFoundException |
|
365 | - * @throws InvalidArgumentException |
|
366 | - * @throws InvalidDataTypeException |
|
367 | - * @throws InvalidInterfaceException |
|
368 | - * @throws ReflectionException |
|
369 | - * @throws RuntimeException |
|
370 | - */ |
|
371 | - public function toggle_registration_status_if_no_monies_owing( |
|
372 | - EE_Registration $registration, |
|
373 | - $save = true, |
|
374 | - array $additional_details = [] |
|
375 | - ) { |
|
376 | - // set initial REG_Status |
|
377 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
378 | - // was a payment just made ? |
|
379 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
380 | - && $additional_details['payment_updates'] |
|
381 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
382 | - ? $additional_details['last_payment'] |
|
383 | - : null; |
|
384 | - $total_paid = array_sum(self::$_amount_paid); |
|
385 | - // toggle reg status to approved IF |
|
386 | - if (// REG status is pending payment |
|
387 | - $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
388 | - // AND no monies are owing |
|
389 | - && ( |
|
390 | - ( |
|
391 | - $registration->transaction()->is_completed() |
|
392 | - || $registration->transaction()->is_overpaid() |
|
393 | - || $registration->transaction()->is_free() |
|
394 | - || apply_filters( |
|
395 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
396 | - false, |
|
397 | - $registration |
|
398 | - ) |
|
399 | - ) |
|
400 | - || ( |
|
401 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
402 | - && // this specific registration has not yet been paid for |
|
403 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
404 | - && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
405 | - $payment->amount() - $total_paid >= $registration->final_price() |
|
406 | - ) |
|
407 | - ) |
|
408 | - ) { |
|
409 | - // mark as paid |
|
410 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
411 | - // track new REG_Status |
|
412 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
413 | - // toggle status to approved |
|
414 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
415 | - if ($save) { |
|
416 | - $registration->save(); |
|
417 | - } |
|
418 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
419 | - if (! EE_Processor_Base::$IPN) { |
|
420 | - // otherwise, send out notifications |
|
421 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
422 | - } |
|
423 | - // DEBUG LOG |
|
424 | - // $this->log( |
|
425 | - // __CLASS__, |
|
426 | - // __FUNCTION__, |
|
427 | - // __LINE__, |
|
428 | - // $registration->transaction(), |
|
429 | - // array( |
|
430 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
431 | - // 'deliver_notifications' => has_filter( |
|
432 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
433 | - // ), |
|
434 | - // ) |
|
435 | - // ); |
|
436 | - return true; |
|
437 | - } |
|
438 | - return false; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * registration_status_changed |
|
444 | - * |
|
445 | - * @access public |
|
446 | - * @param EE_Registration $registration |
|
447 | - * @param array $additional_details |
|
448 | - * @return void |
|
449 | - */ |
|
450 | - public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
451 | - { |
|
452 | - try { |
|
453 | - if (! $registration instanceof EE_Registration) { |
|
454 | - throw new EE_Error( |
|
455 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
456 | - ); |
|
457 | - } |
|
458 | - // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
459 | - // EEH_Debug_Tools::log( |
|
460 | - // __CLASS__, |
|
461 | - // __FUNCTION__, |
|
462 | - // __LINE__, |
|
463 | - // array($registration->transaction(), $additional_details), |
|
464 | - // false, |
|
465 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
466 | - // ); |
|
467 | - if (! $registration->is_primary_registrant()) { |
|
468 | - return; |
|
469 | - } |
|
470 | - do_action( |
|
471 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
472 | - $registration, |
|
473 | - $additional_details |
|
474 | - ); |
|
475 | - } catch (Exception $e) { |
|
476 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
483 | - * |
|
484 | - * @param EE_Registration $registration |
|
485 | - * @param array $additional_details |
|
486 | - * @return bool |
|
487 | - * @throws EE_Error |
|
488 | - * @throws EntityNotFoundException |
|
489 | - * @throws InvalidArgumentException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws InvalidInterfaceException |
|
492 | - * @throws ReflectionException |
|
493 | - * @throws RuntimeException |
|
494 | - */ |
|
495 | - public function update_registration_after_checkout_or_payment( |
|
496 | - EE_Registration $registration, |
|
497 | - array $additional_details = [] |
|
498 | - ) { |
|
499 | - // set initial REG_Status |
|
500 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
501 | - // if the registration status gets updated, then save the registration |
|
502 | - if ($this->toggle_registration_status_for_default_approved_events($registration, false) |
|
503 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
504 | - $registration, |
|
505 | - false, |
|
506 | - $additional_details |
|
507 | - ) |
|
508 | - ) { |
|
509 | - $registration->save(); |
|
510 | - } |
|
511 | - // set new REG_Status |
|
512 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
513 | - return $this->reg_status_updated($registration->ID()) |
|
514 | - && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
520 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
521 | - * |
|
522 | - * @param EE_Transaction $transaction |
|
523 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
524 | - * @return void |
|
525 | - * @throws EE_Error |
|
526 | - * @throws InvalidArgumentException |
|
527 | - * @throws InvalidDataTypeException |
|
528 | - * @throws InvalidInterfaceException |
|
529 | - * @throws RuntimeException |
|
530 | - * @throws ReflectionException |
|
531 | - */ |
|
532 | - public function update_registration_final_prices($transaction, $save_regs = true) |
|
533 | - { |
|
534 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
535 | - $transaction->total_line_item() |
|
536 | - ); |
|
537 | - foreach ($transaction->registrations() as $registration) { |
|
538 | - /** @var EE_Line_Item $line_item */ |
|
539 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
540 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
541 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
542 | - if ($save_regs) { |
|
543 | - $registration->save(); |
|
544 | - } |
|
545 | - } |
|
546 | - } |
|
547 | - // and make sure there's no rounding problem |
|
548 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
554 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
555 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
556 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
557 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
558 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
559 | - * we just grab one registrant at random and make them responsible for it. |
|
560 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
561 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
562 | - * |
|
563 | - * @param EE_Transaction $transaction |
|
564 | - * @return bool success verifying that there is NO difference after this method is done |
|
565 | - * @throws EE_Error |
|
566 | - * @throws InvalidArgumentException |
|
567 | - * @throws InvalidDataTypeException |
|
568 | - * @throws InvalidInterfaceException |
|
569 | - * @throws ReflectionException |
|
570 | - */ |
|
571 | - public function fix_reg_final_price_rounding_issue($transaction) |
|
572 | - { |
|
573 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
574 | - [ |
|
575 | - [ |
|
576 | - 'TXN_ID' => $transaction->ID(), |
|
577 | - ], |
|
578 | - ], |
|
579 | - 'REG_final_price' |
|
580 | - ); |
|
581 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
582 | - // ok then, just grab one of the registrations |
|
583 | - if ($diff !== (float) 0) { |
|
584 | - $a_reg = EEM_Registration::instance()->get_one( |
|
585 | - [ |
|
586 | - [ |
|
587 | - 'TXN_ID' => $transaction->ID(), |
|
588 | - ], |
|
589 | - ] |
|
590 | - ); |
|
591 | - return $a_reg instanceof EE_Registration |
|
592 | - && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
593 | - } |
|
594 | - return true; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * update_registration_after_being_canceled_or_declined |
|
600 | - * |
|
601 | - * @param EE_Registration $registration |
|
602 | - * @param array $closed_reg_statuses |
|
603 | - * @param bool $update_reg |
|
604 | - * @return bool |
|
605 | - * @throws EE_Error |
|
606 | - * @throws RuntimeException |
|
607 | - * @throws ReflectionException |
|
608 | - */ |
|
609 | - public function update_registration_after_being_canceled_or_declined( |
|
610 | - EE_Registration $registration, |
|
611 | - array $closed_reg_statuses = [], |
|
612 | - $update_reg = true |
|
613 | - ) { |
|
614 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
615 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
616 | - ? $closed_reg_statuses |
|
617 | - : EEM_Registration::closed_reg_statuses(); |
|
618 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
619 | - return false; |
|
620 | - } |
|
621 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
622 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
623 | - $registration->set_final_price(0); |
|
624 | - if ($update_reg) { |
|
625 | - $registration->save(); |
|
626 | - } |
|
627 | - return true; |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * update_canceled_or_declined_registration_after_being_reinstated |
|
633 | - * |
|
634 | - * @param EE_Registration $registration |
|
635 | - * @param array $closed_reg_statuses |
|
636 | - * @param bool $update_reg |
|
637 | - * @return bool |
|
638 | - * @throws EE_Error |
|
639 | - * @throws RuntimeException |
|
640 | - * @throws ReflectionException |
|
641 | - */ |
|
642 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
643 | - EE_Registration $registration, |
|
644 | - array $closed_reg_statuses = [], |
|
645 | - $update_reg = true |
|
646 | - ) { |
|
647 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
648 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
649 | - : EEM_Registration::closed_reg_statuses(); |
|
650 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
651 | - return false; |
|
652 | - } |
|
653 | - $ticket = $registration->ticket(); |
|
654 | - if (! $ticket instanceof EE_Ticket) { |
|
655 | - throw new EE_Error( |
|
656 | - sprintf( |
|
657 | - esc_html__( |
|
658 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
659 | - 'event_espresso' |
|
660 | - ), |
|
661 | - $registration->ticket_ID() |
|
662 | - ) |
|
663 | - ); |
|
664 | - } |
|
665 | - $registration->set_final_price($ticket->price()); |
|
666 | - if ($update_reg) { |
|
667 | - $registration->save(); |
|
668 | - } |
|
669 | - return true; |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * generate_ONE_registration_from_line_item |
|
675 | - * Although a ticket line item may have a quantity greater than 1, |
|
676 | - * this method will ONLY CREATE ONE REGISTRATION !!! |
|
677 | - * Regardless of the ticket line item quantity. |
|
678 | - * This means that any code calling this method is responsible for ensuring |
|
679 | - * that the final registration count matches the ticket line item quantity. |
|
680 | - * This was done to make it easier to match the number of registrations |
|
681 | - * to the number of tickets in the cart, when the cart has been edited |
|
682 | - * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
683 | - * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
684 | - * |
|
685 | - * @param EE_Line_Item $line_item |
|
686 | - * @param EE_Transaction $transaction |
|
687 | - * @param int $att_nmbr |
|
688 | - * @param int $total_ticket_count |
|
689 | - * @return EE_Registration | null |
|
690 | - * @throws OutOfRangeException |
|
691 | - * @throws UnexpectedEntityException |
|
692 | - * @throws EE_Error |
|
693 | - * @throws ReflectionException |
|
694 | - * @deprecated |
|
695 | - * @since 4.9.1 |
|
696 | - */ |
|
697 | - public function generate_ONE_registration_from_line_item( |
|
698 | - EE_Line_Item $line_item, |
|
699 | - EE_Transaction $transaction, |
|
700 | - $att_nmbr = 1, |
|
701 | - $total_ticket_count = 1 |
|
702 | - ) { |
|
703 | - EE_Error::doing_it_wrong( |
|
704 | - __CLASS__ . '::' . __FUNCTION__, |
|
705 | - sprintf( |
|
706 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
707 | - '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
708 | - ), |
|
709 | - '4.9.1', |
|
710 | - '5.0.0' |
|
711 | - ); |
|
712 | - // grab the related ticket object for this line_item |
|
713 | - $ticket = $line_item->ticket(); |
|
714 | - if (! $ticket instanceof EE_Ticket) { |
|
715 | - EE_Error::add_error( |
|
716 | - sprintf( |
|
717 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
718 | - $line_item->ID() |
|
719 | - ), |
|
720 | - __FILE__, |
|
721 | - __FUNCTION__, |
|
722 | - __LINE__ |
|
723 | - ); |
|
724 | - return null; |
|
725 | - } |
|
726 | - $registration_service = new CreateRegistrationService(); |
|
727 | - // then generate a new registration from that |
|
728 | - return $registration_service->create( |
|
729 | - $ticket->get_related_event(), |
|
730 | - $transaction, |
|
731 | - $ticket, |
|
732 | - $line_item, |
|
733 | - $att_nmbr, |
|
734 | - $total_ticket_count |
|
735 | - ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * generates reg_url_link |
|
741 | - * |
|
742 | - * @param int $att_nmbr |
|
743 | - * @param EE_Line_Item | string $item |
|
744 | - * @return RegUrlLink |
|
745 | - * @throws InvalidArgumentException |
|
746 | - * @deprecated |
|
747 | - * @since 4.9.1 |
|
748 | - */ |
|
749 | - public function generate_reg_url_link($att_nmbr, $item) |
|
750 | - { |
|
751 | - EE_Error::doing_it_wrong( |
|
752 | - __CLASS__ . '::' . __FUNCTION__, |
|
753 | - sprintf( |
|
754 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
755 | - 'EventEspresso\core\domain\entities\RegUrlLink' |
|
756 | - ), |
|
757 | - '4.9.1', |
|
758 | - '5.0.0' |
|
759 | - ); |
|
760 | - return new RegUrlLink($att_nmbr, $item); |
|
761 | - } |
|
762 | - |
|
763 | - |
|
764 | - /** |
|
765 | - * generates reg code |
|
766 | - * |
|
767 | - * @param EE_Registration $registration |
|
768 | - * @return RegCode |
|
769 | - * @throws EE_Error |
|
770 | - * @throws EntityNotFoundException |
|
771 | - * @throws InvalidArgumentException |
|
772 | - * @since 4.9.1 |
|
773 | - * @deprecated |
|
774 | - */ |
|
775 | - public function generate_reg_code(EE_Registration $registration) |
|
776 | - { |
|
777 | - EE_Error::doing_it_wrong( |
|
778 | - __CLASS__ . '::' . __FUNCTION__, |
|
779 | - sprintf( |
|
780 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
781 | - 'EventEspresso\core\domain\entities\RegCode' |
|
782 | - ), |
|
783 | - '4.9.1', |
|
784 | - '5.0.0' |
|
785 | - ); |
|
786 | - return apply_filters( |
|
787 | - 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
788 | - new RegCode( |
|
789 | - RegUrlLink::fromRegistration($registration), |
|
790 | - $registration->transaction(), |
|
791 | - $registration->ticket() |
|
792 | - ), |
|
793 | - $registration |
|
794 | - ); |
|
795 | - } |
|
29 | + /** |
|
30 | + * @var EE_Registration_Processor $_instance |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + private static $_instance; |
|
34 | + |
|
35 | + /** |
|
36 | + * initial reg status at the beginning of this request. |
|
37 | + * indexed by registration ID |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $_old_reg_status = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * reg status at the end of the request after all processing. |
|
45 | + * indexed by registration ID |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $_new_reg_status = []; |
|
50 | + |
|
51 | + /** |
|
52 | + * amounts paid at the end of the request after all processing. |
|
53 | + * indexed by registration ID |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + protected static $_amount_paid = []; |
|
58 | + |
|
59 | + /** |
|
60 | + * Cache of the reg final price for registrations corresponding to a ticket line item |
|
61 | + * |
|
62 | + * @deprecated |
|
63 | + * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
64 | + */ |
|
65 | + protected $_reg_final_price_per_tkt_line_item; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var RequestInterface $request |
|
69 | + */ |
|
70 | + protected $request; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @singleton method used to instantiate class object |
|
75 | + * @param RequestInterface|null $request |
|
76 | + * @return EE_Registration_Processor instance |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws InvalidInterfaceException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + */ |
|
81 | + public static function instance(RequestInterface $request = null) |
|
82 | + { |
|
83 | + // check if class object is instantiated |
|
84 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
85 | + if (! $request instanceof RequestInterface) { |
|
86 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
87 | + } |
|
88 | + self::$_instance = new self($request); |
|
89 | + } |
|
90 | + return self::$_instance; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Registration_Processor constructor. |
|
96 | + * |
|
97 | + * @param RequestInterface $request |
|
98 | + */ |
|
99 | + public function __construct(RequestInterface $request) |
|
100 | + { |
|
101 | + $this->request = $request; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param int $REG_ID |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function old_reg_status($REG_ID) |
|
110 | + { |
|
111 | + return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param int $REG_ID |
|
117 | + * @param string $old_reg_status |
|
118 | + */ |
|
119 | + public function set_old_reg_status($REG_ID, $old_reg_status) |
|
120 | + { |
|
121 | + // only set the first time |
|
122 | + if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
123 | + $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param int $REG_ID |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function new_reg_status($REG_ID) |
|
133 | + { |
|
134 | + return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param int $REG_ID |
|
140 | + * @param string $new_reg_status |
|
141 | + */ |
|
142 | + public function set_new_reg_status($REG_ID, $new_reg_status) |
|
143 | + { |
|
144 | + $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * reg_status_updated |
|
150 | + * |
|
151 | + * @param int $REG_ID |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function reg_status_updated($REG_ID) |
|
155 | + { |
|
156 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param EE_Registration $registration |
|
162 | + * @throws EE_Error |
|
163 | + * @throws EntityNotFoundException |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws InvalidDataTypeException |
|
166 | + * @throws InvalidInterfaceException |
|
167 | + * @throws ReflectionException |
|
168 | + * @throws RuntimeException |
|
169 | + */ |
|
170 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
171 | + { |
|
172 | + $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
173 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
174 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
175 | + $registration->save(); |
|
176 | + // trigger notifications |
|
177 | + $this->trigger_registration_update_notifications($registration); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * manually_update_registration_status |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * @param EE_Registration $registration |
|
186 | + * @param string $new_reg_status |
|
187 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
188 | + * to client code |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws EntityNotFoundException |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws ReflectionException |
|
196 | + * @throws RuntimeException |
|
197 | + */ |
|
198 | + public function manually_update_registration_status( |
|
199 | + EE_Registration $registration, |
|
200 | + $new_reg_status = '', |
|
201 | + $save = true |
|
202 | + ) { |
|
203 | + // set initial REG_Status |
|
204 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
205 | + // set incoming REG_Status |
|
206 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
207 | + // toggle reg status but only if it has changed and the user can do so |
|
208 | + if ($this->reg_status_updated($registration->ID()) |
|
209 | + && ( |
|
210 | + (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
211 | + || EE_Registry::instance()->CAP->current_user_can( |
|
212 | + 'ee_edit_registration', |
|
213 | + 'toggle_registration_status', |
|
214 | + $registration->ID() |
|
215 | + ) |
|
216 | + ) |
|
217 | + ) { |
|
218 | + // change status to new value |
|
219 | + $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
220 | + if ($updated && $save) { |
|
221 | + $registration->save(); |
|
222 | + } |
|
223 | + return true; |
|
224 | + } |
|
225 | + return false; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * toggle_incomplete_registration_status_to_default |
|
231 | + * changes any incomplete registrations to either the event or global default registration status |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param EE_Registration $registration |
|
235 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
236 | + * that up to client code |
|
237 | + * @param ContextInterface|null $context |
|
238 | + * @return void |
|
239 | + * @throws EE_Error |
|
240 | + * @throws InvalidArgumentException |
|
241 | + * @throws ReflectionException |
|
242 | + * @throws RuntimeException |
|
243 | + * @throws EntityNotFoundException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + */ |
|
247 | + public function toggle_incomplete_registration_status_to_default( |
|
248 | + EE_Registration $registration, |
|
249 | + $save = true, |
|
250 | + ContextInterface $context = null |
|
251 | + ) { |
|
252 | + $existing_reg_status = $registration->status_ID(); |
|
253 | + // set initial REG_Status |
|
254 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
255 | + // is the registration currently incomplete ? |
|
256 | + if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
257 | + // grab default reg status for the event, if set |
|
258 | + $event_default_registration_status = $registration->event()->default_registration_status(); |
|
259 | + // if no default reg status is set for the event, then use the global value |
|
260 | + $STS_ID = ! empty($event_default_registration_status) |
|
261 | + ? $event_default_registration_status |
|
262 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
263 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
264 | + $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
265 | + : $STS_ID; |
|
266 | + // set incoming REG_Status |
|
267 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
268 | + $registration->set_status($STS_ID, false, $context); |
|
269 | + if ($save) { |
|
270 | + $registration->save(); |
|
271 | + } |
|
272 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
273 | + if (! EE_Processor_Base::$IPN) { |
|
274 | + // otherwise, send out notifications |
|
275 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
276 | + } |
|
277 | + // DEBUG LOG |
|
278 | + // $this->log( |
|
279 | + // __CLASS__, |
|
280 | + // __FUNCTION__, |
|
281 | + // __LINE__, |
|
282 | + // $registration->transaction(), |
|
283 | + // array( |
|
284 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
285 | + // 'deliver_notifications' => has_filter( |
|
286 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
287 | + // ), |
|
288 | + // ) |
|
289 | + // ); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * toggle_registration_status_for_default_approved_events |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @param EE_Registration $registration |
|
299 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
300 | + * to client code |
|
301 | + * @return bool |
|
302 | + * @throws EE_Error |
|
303 | + * @throws EntityNotFoundException |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws InvalidInterfaceException |
|
307 | + * @throws ReflectionException |
|
308 | + * @throws RuntimeException |
|
309 | + */ |
|
310 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
311 | + { |
|
312 | + $reg_status = $registration->status_ID(); |
|
313 | + // set initial REG_Status |
|
314 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
315 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
316 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
317 | + if ($reg_status !== EEM_Registration::status_id_cancelled |
|
318 | + && $reg_status |
|
319 | + !== EEM_Registration::status_id_declined |
|
320 | + && $reg_status !== EEM_Registration::status_id_approved |
|
321 | + && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
322 | + ) { |
|
323 | + // set incoming REG_Status |
|
324 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
325 | + // toggle status to approved |
|
326 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
327 | + if ($save) { |
|
328 | + $registration->save(); |
|
329 | + } |
|
330 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
331 | + if (! EE_Processor_Base::$IPN) { |
|
332 | + // otherwise, send out notifications |
|
333 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
334 | + } |
|
335 | + // DEBUG LOG |
|
336 | + // $this->log( |
|
337 | + // __CLASS__, |
|
338 | + // __FUNCTION__, |
|
339 | + // __LINE__, |
|
340 | + // $registration->transaction(), |
|
341 | + // array( |
|
342 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
343 | + // 'deliver_notifications' => has_filter( |
|
344 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
345 | + // ), |
|
346 | + // ) |
|
347 | + // ); |
|
348 | + return true; |
|
349 | + } |
|
350 | + return false; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * toggle_registration_statuses_if_no_monies_owing |
|
356 | + * |
|
357 | + * @access public |
|
358 | + * @param EE_Registration $registration |
|
359 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
360 | + * to client code |
|
361 | + * @param array $additional_details |
|
362 | + * @return bool |
|
363 | + * @throws EE_Error |
|
364 | + * @throws EntityNotFoundException |
|
365 | + * @throws InvalidArgumentException |
|
366 | + * @throws InvalidDataTypeException |
|
367 | + * @throws InvalidInterfaceException |
|
368 | + * @throws ReflectionException |
|
369 | + * @throws RuntimeException |
|
370 | + */ |
|
371 | + public function toggle_registration_status_if_no_monies_owing( |
|
372 | + EE_Registration $registration, |
|
373 | + $save = true, |
|
374 | + array $additional_details = [] |
|
375 | + ) { |
|
376 | + // set initial REG_Status |
|
377 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
378 | + // was a payment just made ? |
|
379 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
380 | + && $additional_details['payment_updates'] |
|
381 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
382 | + ? $additional_details['last_payment'] |
|
383 | + : null; |
|
384 | + $total_paid = array_sum(self::$_amount_paid); |
|
385 | + // toggle reg status to approved IF |
|
386 | + if (// REG status is pending payment |
|
387 | + $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
388 | + // AND no monies are owing |
|
389 | + && ( |
|
390 | + ( |
|
391 | + $registration->transaction()->is_completed() |
|
392 | + || $registration->transaction()->is_overpaid() |
|
393 | + || $registration->transaction()->is_free() |
|
394 | + || apply_filters( |
|
395 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
396 | + false, |
|
397 | + $registration |
|
398 | + ) |
|
399 | + ) |
|
400 | + || ( |
|
401 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
402 | + && // this specific registration has not yet been paid for |
|
403 | + ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
404 | + && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
405 | + $payment->amount() - $total_paid >= $registration->final_price() |
|
406 | + ) |
|
407 | + ) |
|
408 | + ) { |
|
409 | + // mark as paid |
|
410 | + self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
411 | + // track new REG_Status |
|
412 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
413 | + // toggle status to approved |
|
414 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
415 | + if ($save) { |
|
416 | + $registration->save(); |
|
417 | + } |
|
418 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
419 | + if (! EE_Processor_Base::$IPN) { |
|
420 | + // otherwise, send out notifications |
|
421 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
422 | + } |
|
423 | + // DEBUG LOG |
|
424 | + // $this->log( |
|
425 | + // __CLASS__, |
|
426 | + // __FUNCTION__, |
|
427 | + // __LINE__, |
|
428 | + // $registration->transaction(), |
|
429 | + // array( |
|
430 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
431 | + // 'deliver_notifications' => has_filter( |
|
432 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
433 | + // ), |
|
434 | + // ) |
|
435 | + // ); |
|
436 | + return true; |
|
437 | + } |
|
438 | + return false; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * registration_status_changed |
|
444 | + * |
|
445 | + * @access public |
|
446 | + * @param EE_Registration $registration |
|
447 | + * @param array $additional_details |
|
448 | + * @return void |
|
449 | + */ |
|
450 | + public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
451 | + { |
|
452 | + try { |
|
453 | + if (! $registration instanceof EE_Registration) { |
|
454 | + throw new EE_Error( |
|
455 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
456 | + ); |
|
457 | + } |
|
458 | + // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
459 | + // EEH_Debug_Tools::log( |
|
460 | + // __CLASS__, |
|
461 | + // __FUNCTION__, |
|
462 | + // __LINE__, |
|
463 | + // array($registration->transaction(), $additional_details), |
|
464 | + // false, |
|
465 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
466 | + // ); |
|
467 | + if (! $registration->is_primary_registrant()) { |
|
468 | + return; |
|
469 | + } |
|
470 | + do_action( |
|
471 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
472 | + $registration, |
|
473 | + $additional_details |
|
474 | + ); |
|
475 | + } catch (Exception $e) { |
|
476 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
483 | + * |
|
484 | + * @param EE_Registration $registration |
|
485 | + * @param array $additional_details |
|
486 | + * @return bool |
|
487 | + * @throws EE_Error |
|
488 | + * @throws EntityNotFoundException |
|
489 | + * @throws InvalidArgumentException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws InvalidInterfaceException |
|
492 | + * @throws ReflectionException |
|
493 | + * @throws RuntimeException |
|
494 | + */ |
|
495 | + public function update_registration_after_checkout_or_payment( |
|
496 | + EE_Registration $registration, |
|
497 | + array $additional_details = [] |
|
498 | + ) { |
|
499 | + // set initial REG_Status |
|
500 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
501 | + // if the registration status gets updated, then save the registration |
|
502 | + if ($this->toggle_registration_status_for_default_approved_events($registration, false) |
|
503 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
504 | + $registration, |
|
505 | + false, |
|
506 | + $additional_details |
|
507 | + ) |
|
508 | + ) { |
|
509 | + $registration->save(); |
|
510 | + } |
|
511 | + // set new REG_Status |
|
512 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
513 | + return $this->reg_status_updated($registration->ID()) |
|
514 | + && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
520 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
521 | + * |
|
522 | + * @param EE_Transaction $transaction |
|
523 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
524 | + * @return void |
|
525 | + * @throws EE_Error |
|
526 | + * @throws InvalidArgumentException |
|
527 | + * @throws InvalidDataTypeException |
|
528 | + * @throws InvalidInterfaceException |
|
529 | + * @throws RuntimeException |
|
530 | + * @throws ReflectionException |
|
531 | + */ |
|
532 | + public function update_registration_final_prices($transaction, $save_regs = true) |
|
533 | + { |
|
534 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
535 | + $transaction->total_line_item() |
|
536 | + ); |
|
537 | + foreach ($transaction->registrations() as $registration) { |
|
538 | + /** @var EE_Line_Item $line_item */ |
|
539 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
540 | + if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
541 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
542 | + if ($save_regs) { |
|
543 | + $registration->save(); |
|
544 | + } |
|
545 | + } |
|
546 | + } |
|
547 | + // and make sure there's no rounding problem |
|
548 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
554 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
555 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
556 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
557 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
558 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
559 | + * we just grab one registrant at random and make them responsible for it. |
|
560 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
561 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
562 | + * |
|
563 | + * @param EE_Transaction $transaction |
|
564 | + * @return bool success verifying that there is NO difference after this method is done |
|
565 | + * @throws EE_Error |
|
566 | + * @throws InvalidArgumentException |
|
567 | + * @throws InvalidDataTypeException |
|
568 | + * @throws InvalidInterfaceException |
|
569 | + * @throws ReflectionException |
|
570 | + */ |
|
571 | + public function fix_reg_final_price_rounding_issue($transaction) |
|
572 | + { |
|
573 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
574 | + [ |
|
575 | + [ |
|
576 | + 'TXN_ID' => $transaction->ID(), |
|
577 | + ], |
|
578 | + ], |
|
579 | + 'REG_final_price' |
|
580 | + ); |
|
581 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
582 | + // ok then, just grab one of the registrations |
|
583 | + if ($diff !== (float) 0) { |
|
584 | + $a_reg = EEM_Registration::instance()->get_one( |
|
585 | + [ |
|
586 | + [ |
|
587 | + 'TXN_ID' => $transaction->ID(), |
|
588 | + ], |
|
589 | + ] |
|
590 | + ); |
|
591 | + return $a_reg instanceof EE_Registration |
|
592 | + && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
593 | + } |
|
594 | + return true; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * update_registration_after_being_canceled_or_declined |
|
600 | + * |
|
601 | + * @param EE_Registration $registration |
|
602 | + * @param array $closed_reg_statuses |
|
603 | + * @param bool $update_reg |
|
604 | + * @return bool |
|
605 | + * @throws EE_Error |
|
606 | + * @throws RuntimeException |
|
607 | + * @throws ReflectionException |
|
608 | + */ |
|
609 | + public function update_registration_after_being_canceled_or_declined( |
|
610 | + EE_Registration $registration, |
|
611 | + array $closed_reg_statuses = [], |
|
612 | + $update_reg = true |
|
613 | + ) { |
|
614 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
615 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
616 | + ? $closed_reg_statuses |
|
617 | + : EEM_Registration::closed_reg_statuses(); |
|
618 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
619 | + return false; |
|
620 | + } |
|
621 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
622 | + $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
623 | + $registration->set_final_price(0); |
|
624 | + if ($update_reg) { |
|
625 | + $registration->save(); |
|
626 | + } |
|
627 | + return true; |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * update_canceled_or_declined_registration_after_being_reinstated |
|
633 | + * |
|
634 | + * @param EE_Registration $registration |
|
635 | + * @param array $closed_reg_statuses |
|
636 | + * @param bool $update_reg |
|
637 | + * @return bool |
|
638 | + * @throws EE_Error |
|
639 | + * @throws RuntimeException |
|
640 | + * @throws ReflectionException |
|
641 | + */ |
|
642 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
643 | + EE_Registration $registration, |
|
644 | + array $closed_reg_statuses = [], |
|
645 | + $update_reg = true |
|
646 | + ) { |
|
647 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
648 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
649 | + : EEM_Registration::closed_reg_statuses(); |
|
650 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
651 | + return false; |
|
652 | + } |
|
653 | + $ticket = $registration->ticket(); |
|
654 | + if (! $ticket instanceof EE_Ticket) { |
|
655 | + throw new EE_Error( |
|
656 | + sprintf( |
|
657 | + esc_html__( |
|
658 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
659 | + 'event_espresso' |
|
660 | + ), |
|
661 | + $registration->ticket_ID() |
|
662 | + ) |
|
663 | + ); |
|
664 | + } |
|
665 | + $registration->set_final_price($ticket->price()); |
|
666 | + if ($update_reg) { |
|
667 | + $registration->save(); |
|
668 | + } |
|
669 | + return true; |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * generate_ONE_registration_from_line_item |
|
675 | + * Although a ticket line item may have a quantity greater than 1, |
|
676 | + * this method will ONLY CREATE ONE REGISTRATION !!! |
|
677 | + * Regardless of the ticket line item quantity. |
|
678 | + * This means that any code calling this method is responsible for ensuring |
|
679 | + * that the final registration count matches the ticket line item quantity. |
|
680 | + * This was done to make it easier to match the number of registrations |
|
681 | + * to the number of tickets in the cart, when the cart has been edited |
|
682 | + * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
683 | + * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
684 | + * |
|
685 | + * @param EE_Line_Item $line_item |
|
686 | + * @param EE_Transaction $transaction |
|
687 | + * @param int $att_nmbr |
|
688 | + * @param int $total_ticket_count |
|
689 | + * @return EE_Registration | null |
|
690 | + * @throws OutOfRangeException |
|
691 | + * @throws UnexpectedEntityException |
|
692 | + * @throws EE_Error |
|
693 | + * @throws ReflectionException |
|
694 | + * @deprecated |
|
695 | + * @since 4.9.1 |
|
696 | + */ |
|
697 | + public function generate_ONE_registration_from_line_item( |
|
698 | + EE_Line_Item $line_item, |
|
699 | + EE_Transaction $transaction, |
|
700 | + $att_nmbr = 1, |
|
701 | + $total_ticket_count = 1 |
|
702 | + ) { |
|
703 | + EE_Error::doing_it_wrong( |
|
704 | + __CLASS__ . '::' . __FUNCTION__, |
|
705 | + sprintf( |
|
706 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
707 | + '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
708 | + ), |
|
709 | + '4.9.1', |
|
710 | + '5.0.0' |
|
711 | + ); |
|
712 | + // grab the related ticket object for this line_item |
|
713 | + $ticket = $line_item->ticket(); |
|
714 | + if (! $ticket instanceof EE_Ticket) { |
|
715 | + EE_Error::add_error( |
|
716 | + sprintf( |
|
717 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
718 | + $line_item->ID() |
|
719 | + ), |
|
720 | + __FILE__, |
|
721 | + __FUNCTION__, |
|
722 | + __LINE__ |
|
723 | + ); |
|
724 | + return null; |
|
725 | + } |
|
726 | + $registration_service = new CreateRegistrationService(); |
|
727 | + // then generate a new registration from that |
|
728 | + return $registration_service->create( |
|
729 | + $ticket->get_related_event(), |
|
730 | + $transaction, |
|
731 | + $ticket, |
|
732 | + $line_item, |
|
733 | + $att_nmbr, |
|
734 | + $total_ticket_count |
|
735 | + ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * generates reg_url_link |
|
741 | + * |
|
742 | + * @param int $att_nmbr |
|
743 | + * @param EE_Line_Item | string $item |
|
744 | + * @return RegUrlLink |
|
745 | + * @throws InvalidArgumentException |
|
746 | + * @deprecated |
|
747 | + * @since 4.9.1 |
|
748 | + */ |
|
749 | + public function generate_reg_url_link($att_nmbr, $item) |
|
750 | + { |
|
751 | + EE_Error::doing_it_wrong( |
|
752 | + __CLASS__ . '::' . __FUNCTION__, |
|
753 | + sprintf( |
|
754 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
755 | + 'EventEspresso\core\domain\entities\RegUrlLink' |
|
756 | + ), |
|
757 | + '4.9.1', |
|
758 | + '5.0.0' |
|
759 | + ); |
|
760 | + return new RegUrlLink($att_nmbr, $item); |
|
761 | + } |
|
762 | + |
|
763 | + |
|
764 | + /** |
|
765 | + * generates reg code |
|
766 | + * |
|
767 | + * @param EE_Registration $registration |
|
768 | + * @return RegCode |
|
769 | + * @throws EE_Error |
|
770 | + * @throws EntityNotFoundException |
|
771 | + * @throws InvalidArgumentException |
|
772 | + * @since 4.9.1 |
|
773 | + * @deprecated |
|
774 | + */ |
|
775 | + public function generate_reg_code(EE_Registration $registration) |
|
776 | + { |
|
777 | + EE_Error::doing_it_wrong( |
|
778 | + __CLASS__ . '::' . __FUNCTION__, |
|
779 | + sprintf( |
|
780 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
781 | + 'EventEspresso\core\domain\entities\RegCode' |
|
782 | + ), |
|
783 | + '4.9.1', |
|
784 | + '5.0.0' |
|
785 | + ); |
|
786 | + return apply_filters( |
|
787 | + 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
788 | + new RegCode( |
|
789 | + RegUrlLink::fromRegistration($registration), |
|
790 | + $registration->transaction(), |
|
791 | + $registration->ticket() |
|
792 | + ), |
|
793 | + $registration |
|
794 | + ); |
|
795 | + } |
|
796 | 796 | } |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | public static function instance(RequestInterface $request = null) |
82 | 82 | { |
83 | 83 | // check if class object is instantiated |
84 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
85 | - if (! $request instanceof RequestInterface) { |
|
84 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
85 | + if ( ! $request instanceof RequestInterface) { |
|
86 | 86 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
87 | 87 | } |
88 | 88 | self::$_instance = new self($request); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function old_reg_status($REG_ID) |
110 | 110 | { |
111 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
111 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | public function set_old_reg_status($REG_ID, $old_reg_status) |
120 | 120 | { |
121 | 121 | // only set the first time |
122 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
123 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
122 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
123 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function new_reg_status($REG_ID) |
133 | 133 | { |
134 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
134 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function set_new_reg_status($REG_ID, $new_reg_status) |
143 | 143 | { |
144 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
144 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | // toggle reg status but only if it has changed and the user can do so |
208 | 208 | if ($this->reg_status_updated($registration->ID()) |
209 | 209 | && ( |
210 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
210 | + ( ! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
211 | 211 | || EE_Registry::instance()->CAP->current_user_can( |
212 | 212 | 'ee_edit_registration', |
213 | 213 | 'toggle_registration_status', |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $registration->save(); |
271 | 271 | } |
272 | 272 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
273 | - if (! EE_Processor_Base::$IPN) { |
|
273 | + if ( ! EE_Processor_Base::$IPN) { |
|
274 | 274 | // otherwise, send out notifications |
275 | 275 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
276 | 276 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $registration->save(); |
329 | 329 | } |
330 | 330 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
331 | - if (! EE_Processor_Base::$IPN) { |
|
331 | + if ( ! EE_Processor_Base::$IPN) { |
|
332 | 332 | // otherwise, send out notifications |
333 | 333 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
334 | 334 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | // set initial REG_Status |
377 | 377 | $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
378 | 378 | // was a payment just made ? |
379 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
379 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
380 | 380 | && $additional_details['payment_updates'] |
381 | 381 | && $additional_details['last_payment'] instanceof EE_Payment |
382 | 382 | ? $additional_details['last_payment'] |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | || ( |
401 | 401 | $payment instanceof EE_Payment && $payment->is_approved() |
402 | 402 | && // this specific registration has not yet been paid for |
403 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
403 | + ! isset(self::$_amount_paid[$registration->ID()]) |
|
404 | 404 | && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
405 | 405 | $payment->amount() - $total_paid >= $registration->final_price() |
406 | 406 | ) |
407 | 407 | ) |
408 | 408 | ) { |
409 | 409 | // mark as paid |
410 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
410 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
411 | 411 | // track new REG_Status |
412 | 412 | $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
413 | 413 | // toggle status to approved |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $registration->save(); |
417 | 417 | } |
418 | 418 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
419 | - if (! EE_Processor_Base::$IPN) { |
|
419 | + if ( ! EE_Processor_Base::$IPN) { |
|
420 | 420 | // otherwise, send out notifications |
421 | 421 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
422 | 422 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | public function trigger_registration_update_notifications($registration, array $additional_details = []) |
451 | 451 | { |
452 | 452 | try { |
453 | - if (! $registration instanceof EE_Registration) { |
|
453 | + if ( ! $registration instanceof EE_Registration) { |
|
454 | 454 | throw new EE_Error( |
455 | 455 | esc_html__('An invalid registration was received.', 'event_espresso') |
456 | 456 | ); |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | // false, |
465 | 465 | // 'EE_Transaction: ' . $registration->transaction()->ID() |
466 | 466 | // ); |
467 | - if (! $registration->is_primary_registrant()) { |
|
467 | + if ( ! $registration->is_primary_registrant()) { |
|
468 | 468 | return; |
469 | 469 | } |
470 | 470 | do_action( |
@@ -537,8 +537,8 @@ discard block |
||
537 | 537 | foreach ($transaction->registrations() as $registration) { |
538 | 538 | /** @var EE_Line_Item $line_item */ |
539 | 539 | $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
540 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
541 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
540 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
541 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
542 | 542 | if ($save_regs) { |
543 | 543 | $registration->save(); |
544 | 544 | } |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | ], |
579 | 579 | 'REG_final_price' |
580 | 580 | ); |
581 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
581 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
582 | 582 | // ok then, just grab one of the registrations |
583 | 583 | if ($diff !== (float) 0) { |
584 | 584 | $a_reg = EEM_Registration::instance()->get_one( |
@@ -615,11 +615,11 @@ discard block |
||
615 | 615 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
616 | 616 | ? $closed_reg_statuses |
617 | 617 | : EEM_Registration::closed_reg_statuses(); |
618 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
618 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
619 | 619 | return false; |
620 | 620 | } |
621 | 621 | // release a reserved ticket by decrementing ticket and datetime reserved values |
622 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
622 | + $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__); |
|
623 | 623 | $registration->set_final_price(0); |
624 | 624 | if ($update_reg) { |
625 | 625 | $registration->save(); |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | return false; |
652 | 652 | } |
653 | 653 | $ticket = $registration->ticket(); |
654 | - if (! $ticket instanceof EE_Ticket) { |
|
654 | + if ( ! $ticket instanceof EE_Ticket) { |
|
655 | 655 | throw new EE_Error( |
656 | 656 | sprintf( |
657 | 657 | esc_html__( |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | $total_ticket_count = 1 |
702 | 702 | ) { |
703 | 703 | EE_Error::doing_it_wrong( |
704 | - __CLASS__ . '::' . __FUNCTION__, |
|
704 | + __CLASS__.'::'.__FUNCTION__, |
|
705 | 705 | sprintf( |
706 | 706 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
707 | 707 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | ); |
712 | 712 | // grab the related ticket object for this line_item |
713 | 713 | $ticket = $line_item->ticket(); |
714 | - if (! $ticket instanceof EE_Ticket) { |
|
714 | + if ( ! $ticket instanceof EE_Ticket) { |
|
715 | 715 | EE_Error::add_error( |
716 | 716 | sprintf( |
717 | 717 | esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | public function generate_reg_url_link($att_nmbr, $item) |
750 | 750 | { |
751 | 751 | EE_Error::doing_it_wrong( |
752 | - __CLASS__ . '::' . __FUNCTION__, |
|
752 | + __CLASS__.'::'.__FUNCTION__, |
|
753 | 753 | sprintf( |
754 | 754 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
755 | 755 | 'EventEspresso\core\domain\entities\RegUrlLink' |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | public function generate_reg_code(EE_Registration $registration) |
776 | 776 | { |
777 | 777 | EE_Error::doing_it_wrong( |
778 | - __CLASS__ . '::' . __FUNCTION__, |
|
778 | + __CLASS__.'::'.__FUNCTION__, |
|
779 | 779 | sprintf( |
780 | 780 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
781 | 781 | 'EventEspresso\core\domain\entities\RegCode' |
@@ -20,1143 +20,1143 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | - ) { |
|
361 | - return 'load_core'; |
|
362 | - } |
|
363 | - $class_name = $this->getFqnForAlias($class_name); |
|
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function class_loaders() |
|
372 | - { |
|
373 | - return $this->_class_loaders; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * adds an alias for a classname |
|
379 | - * |
|
380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | - */ |
|
384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | - { |
|
386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | - * WHY? |
|
393 | - * Because if a class is type hinting for a concretion, |
|
394 | - * then why would we need to find another class to supply it? |
|
395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | - * Don't go looking for some substitute. |
|
398 | - * Whereas if a class is type hinting for an interface... |
|
399 | - * then we need to find an actual class to use. |
|
400 | - * So the interface IS the alias for some other FQN, |
|
401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | - * represents some other class. |
|
403 | - * |
|
404 | - * @param string $fqn |
|
405 | - * @param string $for_class |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isAlias($fqn = '', $for_class = '') |
|
409 | - { |
|
410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | - * for example: |
|
418 | - * if the following two entries were added to the _aliases array: |
|
419 | - * array( |
|
420 | - * 'interface_alias' => 'some\namespace\interface' |
|
421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | - * ) |
|
423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | - * to load an instance of 'some\namespace\classname' |
|
425 | - * |
|
426 | - * @param string $alias |
|
427 | - * @param string $for_class |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | - { |
|
432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | - * This is done by using the following class constants: |
|
440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | - */ |
|
443 | - protected function _register_core_dependencies() |
|
444 | - { |
|
445 | - $this->_dependency_map = array( |
|
446 | - 'EE_Request_Handler' => array( |
|
447 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_System' => array( |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Session' => array( |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Cart' => array( |
|
463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_Front_Controller' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messenger_Collection_Loader' => array( |
|
471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | - ), |
|
473 | - 'EE_Message_Type_Collection_Loader' => array( |
|
474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Message_Resource_Manager' => array( |
|
477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_Message_Factory' => array( |
|
482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_messages' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Generator' => array( |
|
488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_Messages_Processor' => array( |
|
494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Messages_Queue' => array( |
|
497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | - ), |
|
499 | - 'EE_Messages_Template_Defaults' => array( |
|
500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EE_Message_To_Generate_From_Request' => array( |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_Data_Migration_Class_Base' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_1_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_2_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_3_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_4_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_5_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_6_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_7_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EE_DMS_Core_4_8_0' => array( |
|
596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EE_DMS_Core_4_9_0' => array( |
|
600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EE_DMS_Core_4_10_0' => array( |
|
604 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | - array(), |
|
610 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | - ), |
|
612 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | - ), |
|
654 | - 'LEGACY_MODELS' => array( |
|
655 | - null, |
|
656 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | - ), |
|
658 | - 'EE_Module_Request_Router' => array( |
|
659 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - 'EE_Registration_Processor' => array( |
|
662 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | - null, |
|
666 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | - ), |
|
669 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EE_Admin_Transactions_List_Table' => array( |
|
674 | - null, |
|
675 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | - ), |
|
677 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | - ), |
|
682 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | - ), |
|
686 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | - ), |
|
695 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | - ), |
|
698 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | - ), |
|
701 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | - ), |
|
705 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | - ), |
|
708 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | - ), |
|
715 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | - ), |
|
718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | - ), |
|
722 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | - ), |
|
725 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | - ), |
|
728 | - 'EE_CPT_Strategy' => array( |
|
729 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | - ), |
|
732 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | - ), |
|
735 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | - ), |
|
742 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | - ), |
|
746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | - ), |
|
749 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | - ), |
|
753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | - ), |
|
756 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | - ), |
|
759 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | - ), |
|
762 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | - ), |
|
765 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | - ), |
|
769 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | - null, |
|
771 | - null, |
|
772 | - null, |
|
773 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | - ), |
|
777 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | - ), |
|
781 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | - ), |
|
787 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | - ), |
|
792 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | - ), |
|
796 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | - ), |
|
801 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | - ), |
|
806 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | - ), |
|
810 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | - ), |
|
814 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | - ), |
|
817 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | - ), |
|
820 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | - ), |
|
823 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | - ), |
|
827 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | - ), |
|
831 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | - ), |
|
834 | - 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | - ), |
|
837 | - 'EE_URL_Validation_Strategy' => array( |
|
838 | - null, |
|
839 | - null, |
|
840 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | - ), |
|
842 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | - ), |
|
849 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | - 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | - ), |
|
853 | - 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | - ), |
|
857 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | - 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | - ), |
|
861 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | - ), |
|
864 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | - ], |
|
867 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | - null, |
|
869 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | - ], |
|
872 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | - ], |
|
876 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | - ], |
|
880 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | - ], |
|
884 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | - ], |
|
888 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
889 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
890 | - ], |
|
891 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
892 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
893 | - ], |
|
894 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
895 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
896 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
897 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
898 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
899 | - ], |
|
900 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
901 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
902 | - ] |
|
903 | - ); |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * Registers how core classes are loaded. |
|
909 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
910 | - * 'EE_Request_Handler' => 'load_core' |
|
911 | - * 'EE_Messages_Queue' => 'load_lib' |
|
912 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
913 | - * or, if greater control is required, by providing a custom closure. For example: |
|
914 | - * 'Some_Class' => function () { |
|
915 | - * return new Some_Class(); |
|
916 | - * }, |
|
917 | - * This is required for instantiating dependencies |
|
918 | - * where an interface has been type hinted in a class constructor. For example: |
|
919 | - * 'Required_Interface' => function () { |
|
920 | - * return new A_Class_That_Implements_Required_Interface(); |
|
921 | - * }, |
|
922 | - */ |
|
923 | - protected function _register_core_class_loaders() |
|
924 | - { |
|
925 | - $this->_class_loaders = array( |
|
926 | - // load_core |
|
927 | - 'EE_Dependency_Map' => function () { |
|
928 | - return $this; |
|
929 | - }, |
|
930 | - 'EE_Capabilities' => 'load_core', |
|
931 | - 'EE_Encryption' => 'load_core', |
|
932 | - 'EE_Front_Controller' => 'load_core', |
|
933 | - 'EE_Module_Request_Router' => 'load_core', |
|
934 | - 'EE_Registry' => 'load_core', |
|
935 | - 'EE_Request' => function () { |
|
936 | - return $this->legacy_request; |
|
937 | - }, |
|
938 | - 'EventEspresso\core\services\request\Request' => function () { |
|
939 | - return $this->request; |
|
940 | - }, |
|
941 | - 'EventEspresso\core\services\request\Response' => function () { |
|
942 | - return $this->response; |
|
943 | - }, |
|
944 | - 'EE_Base' => 'load_core', |
|
945 | - 'EE_Request_Handler' => 'load_core', |
|
946 | - 'EE_Session' => 'load_core', |
|
947 | - 'EE_Cron_Tasks' => 'load_core', |
|
948 | - 'EE_System' => 'load_core', |
|
949 | - 'EE_Maintenance_Mode' => 'load_core', |
|
950 | - 'EE_Register_CPTs' => 'load_core', |
|
951 | - 'EE_Admin' => 'load_core', |
|
952 | - 'EE_CPT_Strategy' => 'load_core', |
|
953 | - // load_class |
|
954 | - 'EE_Registration_Processor' => 'load_class', |
|
955 | - // load_lib |
|
956 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
957 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
958 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
959 | - 'EE_Messenger_Collection' => 'load_lib', |
|
960 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
961 | - 'EE_Messages_Processor' => 'load_lib', |
|
962 | - 'EE_Message_Repository' => 'load_lib', |
|
963 | - 'EE_Messages_Queue' => 'load_lib', |
|
964 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
965 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
966 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
967 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
968 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
969 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
970 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
971 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
972 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
973 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
974 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
975 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
976 | - 'EE_Messages_Generator' => function () { |
|
977 | - return EE_Registry::instance()->load_lib( |
|
978 | - 'Messages_Generator', |
|
979 | - array(), |
|
980 | - false, |
|
981 | - false |
|
982 | - ); |
|
983 | - }, |
|
984 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
985 | - return EE_Registry::instance()->load_lib( |
|
986 | - 'Messages_Template_Defaults', |
|
987 | - $arguments, |
|
988 | - false, |
|
989 | - false |
|
990 | - ); |
|
991 | - }, |
|
992 | - // load_helper |
|
993 | - 'EEH_Parse_Shortcodes' => function () { |
|
994 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
995 | - return new EEH_Parse_Shortcodes(); |
|
996 | - } |
|
997 | - return null; |
|
998 | - }, |
|
999 | - 'EE_Template_Config' => function () { |
|
1000 | - return EE_Config::instance()->template_settings; |
|
1001 | - }, |
|
1002 | - 'EE_Currency_Config' => function () { |
|
1003 | - return EE_Config::instance()->currency; |
|
1004 | - }, |
|
1005 | - 'EE_Registration_Config' => function () { |
|
1006 | - return EE_Config::instance()->registration; |
|
1007 | - }, |
|
1008 | - 'EE_Core_Config' => function () { |
|
1009 | - return EE_Config::instance()->core; |
|
1010 | - }, |
|
1011 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
1012 | - return LoaderFactory::getLoader(); |
|
1013 | - }, |
|
1014 | - 'EE_Network_Config' => function () { |
|
1015 | - return EE_Network_Config::instance(); |
|
1016 | - }, |
|
1017 | - 'EE_Config' => function () { |
|
1018 | - return EE_Config::instance(); |
|
1019 | - }, |
|
1020 | - 'EventEspresso\core\domain\Domain' => function () { |
|
1021 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
1022 | - }, |
|
1023 | - 'EE_Admin_Config' => function () { |
|
1024 | - return EE_Config::instance()->admin; |
|
1025 | - }, |
|
1026 | - 'EE_Organization_Config' => function () { |
|
1027 | - return EE_Config::instance()->organization; |
|
1028 | - }, |
|
1029 | - 'EE_Network_Core_Config' => function () { |
|
1030 | - return EE_Network_Config::instance()->core; |
|
1031 | - }, |
|
1032 | - 'EE_Environment_Config' => function () { |
|
1033 | - return EE_Config::instance()->environment; |
|
1034 | - }, |
|
1035 | - ); |
|
1036 | - } |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * can be used for supplying alternate names for classes, |
|
1041 | - * or for connecting interface names to instantiable classes |
|
1042 | - */ |
|
1043 | - protected function _register_core_aliases() |
|
1044 | - { |
|
1045 | - $aliases = array( |
|
1046 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1047 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1048 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1049 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1050 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1051 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1052 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1053 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1054 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1055 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1056 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1057 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1058 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1059 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1060 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1061 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1062 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1063 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1064 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1065 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1066 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1067 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1068 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1069 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1070 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1071 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1072 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1073 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1074 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1075 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1076 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1077 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1078 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1079 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1080 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1081 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1082 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1083 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
1084 | - ); |
|
1085 | - foreach ($aliases as $alias => $fqn) { |
|
1086 | - if (is_array($fqn)) { |
|
1087 | - foreach ($fqn as $class => $for_class) { |
|
1088 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
1089 | - } |
|
1090 | - continue; |
|
1091 | - } |
|
1092 | - $this->class_cache->addAlias($fqn, $alias); |
|
1093 | - } |
|
1094 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1095 | - $this->class_cache->addAlias( |
|
1096 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1097 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1098 | - ); |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1105 | - * request Primarily used by unit tests. |
|
1106 | - */ |
|
1107 | - public function reset() |
|
1108 | - { |
|
1109 | - $this->_register_core_class_loaders(); |
|
1110 | - $this->_register_core_dependencies(); |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1116 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1117 | - * WHY? |
|
1118 | - * Because if a class is type hinting for a concretion, |
|
1119 | - * then why would we need to find another class to supply it? |
|
1120 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1121 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1122 | - * Don't go looking for some substitute. |
|
1123 | - * Whereas if a class is type hinting for an interface... |
|
1124 | - * then we need to find an actual class to use. |
|
1125 | - * So the interface IS the alias for some other FQN, |
|
1126 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1127 | - * represents some other class. |
|
1128 | - * |
|
1129 | - * @deprecated 4.9.62.p |
|
1130 | - * @param string $fqn |
|
1131 | - * @param string $for_class |
|
1132 | - * @return bool |
|
1133 | - */ |
|
1134 | - public function has_alias($fqn = '', $for_class = '') |
|
1135 | - { |
|
1136 | - return $this->isAlias($fqn, $for_class); |
|
1137 | - } |
|
1138 | - |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1142 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1143 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1144 | - * for example: |
|
1145 | - * if the following two entries were added to the _aliases array: |
|
1146 | - * array( |
|
1147 | - * 'interface_alias' => 'some\namespace\interface' |
|
1148 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1149 | - * ) |
|
1150 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1151 | - * to load an instance of 'some\namespace\classname' |
|
1152 | - * |
|
1153 | - * @deprecated 4.9.62.p |
|
1154 | - * @param string $alias |
|
1155 | - * @param string $for_class |
|
1156 | - * @return string |
|
1157 | - */ |
|
1158 | - public function get_alias($alias = '', $for_class = '') |
|
1159 | - { |
|
1160 | - return $this->getFqnForAlias($alias, $for_class); |
|
1161 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | + ) { |
|
361 | + return 'load_core'; |
|
362 | + } |
|
363 | + $class_name = $this->getFqnForAlias($class_name); |
|
364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function class_loaders() |
|
372 | + { |
|
373 | + return $this->_class_loaders; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * adds an alias for a classname |
|
379 | + * |
|
380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | + */ |
|
384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | + { |
|
386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | + * WHY? |
|
393 | + * Because if a class is type hinting for a concretion, |
|
394 | + * then why would we need to find another class to supply it? |
|
395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | + * Don't go looking for some substitute. |
|
398 | + * Whereas if a class is type hinting for an interface... |
|
399 | + * then we need to find an actual class to use. |
|
400 | + * So the interface IS the alias for some other FQN, |
|
401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | + * represents some other class. |
|
403 | + * |
|
404 | + * @param string $fqn |
|
405 | + * @param string $for_class |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isAlias($fqn = '', $for_class = '') |
|
409 | + { |
|
410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | + * for example: |
|
418 | + * if the following two entries were added to the _aliases array: |
|
419 | + * array( |
|
420 | + * 'interface_alias' => 'some\namespace\interface' |
|
421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | + * ) |
|
423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | + * to load an instance of 'some\namespace\classname' |
|
425 | + * |
|
426 | + * @param string $alias |
|
427 | + * @param string $for_class |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | + { |
|
432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | + * This is done by using the following class constants: |
|
440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | + */ |
|
443 | + protected function _register_core_dependencies() |
|
444 | + { |
|
445 | + $this->_dependency_map = array( |
|
446 | + 'EE_Request_Handler' => array( |
|
447 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_System' => array( |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Session' => array( |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Cart' => array( |
|
463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_Front_Controller' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messenger_Collection_Loader' => array( |
|
471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | + ), |
|
473 | + 'EE_Message_Type_Collection_Loader' => array( |
|
474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Message_Resource_Manager' => array( |
|
477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_Message_Factory' => array( |
|
482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_messages' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Generator' => array( |
|
488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_Messages_Processor' => array( |
|
494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Messages_Queue' => array( |
|
497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | + ), |
|
499 | + 'EE_Messages_Template_Defaults' => array( |
|
500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EE_Message_To_Generate_From_Request' => array( |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_Data_Migration_Class_Base' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_1_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_2_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_3_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_4_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_5_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_6_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_7_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EE_DMS_Core_4_8_0' => array( |
|
596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EE_DMS_Core_4_9_0' => array( |
|
600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EE_DMS_Core_4_10_0' => array( |
|
604 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | + array(), |
|
610 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | + ), |
|
612 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | + ), |
|
654 | + 'LEGACY_MODELS' => array( |
|
655 | + null, |
|
656 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | + ), |
|
658 | + 'EE_Module_Request_Router' => array( |
|
659 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + 'EE_Registration_Processor' => array( |
|
662 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | + null, |
|
666 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | + ), |
|
669 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EE_Admin_Transactions_List_Table' => array( |
|
674 | + null, |
|
675 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | + ), |
|
677 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | + ), |
|
682 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | + ), |
|
686 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | + ), |
|
695 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | + ), |
|
698 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | + ), |
|
701 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | + ), |
|
705 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | + ), |
|
708 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | + ), |
|
715 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | + ), |
|
718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | + ), |
|
722 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | + ), |
|
725 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | + ), |
|
728 | + 'EE_CPT_Strategy' => array( |
|
729 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | + ), |
|
732 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | + ), |
|
735 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | + ), |
|
742 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | + ), |
|
746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | + ), |
|
749 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | + ), |
|
753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | + ), |
|
756 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | + ), |
|
759 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | + ), |
|
762 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | + ), |
|
765 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | + ), |
|
769 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | + null, |
|
771 | + null, |
|
772 | + null, |
|
773 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | + ), |
|
777 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | + ), |
|
781 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | + ), |
|
787 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | + ), |
|
792 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | + ), |
|
796 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | + ), |
|
801 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | + ), |
|
806 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | + ), |
|
810 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | + ), |
|
814 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | + ), |
|
817 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | + ), |
|
820 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | + ), |
|
823 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | + ), |
|
827 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | + ), |
|
831 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | + ), |
|
834 | + 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | + ), |
|
837 | + 'EE_URL_Validation_Strategy' => array( |
|
838 | + null, |
|
839 | + null, |
|
840 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | + ), |
|
842 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | + ), |
|
849 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | + 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | + ), |
|
853 | + 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | + ), |
|
857 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | + 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | + ), |
|
861 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | + ), |
|
864 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | + ], |
|
867 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | + null, |
|
869 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | + ], |
|
872 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | + ], |
|
876 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | + ], |
|
880 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | + ], |
|
884 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | + ], |
|
888 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
889 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
890 | + ], |
|
891 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
892 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
893 | + ], |
|
894 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
895 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
896 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
897 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
898 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
899 | + ], |
|
900 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
901 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
902 | + ] |
|
903 | + ); |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * Registers how core classes are loaded. |
|
909 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
910 | + * 'EE_Request_Handler' => 'load_core' |
|
911 | + * 'EE_Messages_Queue' => 'load_lib' |
|
912 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
913 | + * or, if greater control is required, by providing a custom closure. For example: |
|
914 | + * 'Some_Class' => function () { |
|
915 | + * return new Some_Class(); |
|
916 | + * }, |
|
917 | + * This is required for instantiating dependencies |
|
918 | + * where an interface has been type hinted in a class constructor. For example: |
|
919 | + * 'Required_Interface' => function () { |
|
920 | + * return new A_Class_That_Implements_Required_Interface(); |
|
921 | + * }, |
|
922 | + */ |
|
923 | + protected function _register_core_class_loaders() |
|
924 | + { |
|
925 | + $this->_class_loaders = array( |
|
926 | + // load_core |
|
927 | + 'EE_Dependency_Map' => function () { |
|
928 | + return $this; |
|
929 | + }, |
|
930 | + 'EE_Capabilities' => 'load_core', |
|
931 | + 'EE_Encryption' => 'load_core', |
|
932 | + 'EE_Front_Controller' => 'load_core', |
|
933 | + 'EE_Module_Request_Router' => 'load_core', |
|
934 | + 'EE_Registry' => 'load_core', |
|
935 | + 'EE_Request' => function () { |
|
936 | + return $this->legacy_request; |
|
937 | + }, |
|
938 | + 'EventEspresso\core\services\request\Request' => function () { |
|
939 | + return $this->request; |
|
940 | + }, |
|
941 | + 'EventEspresso\core\services\request\Response' => function () { |
|
942 | + return $this->response; |
|
943 | + }, |
|
944 | + 'EE_Base' => 'load_core', |
|
945 | + 'EE_Request_Handler' => 'load_core', |
|
946 | + 'EE_Session' => 'load_core', |
|
947 | + 'EE_Cron_Tasks' => 'load_core', |
|
948 | + 'EE_System' => 'load_core', |
|
949 | + 'EE_Maintenance_Mode' => 'load_core', |
|
950 | + 'EE_Register_CPTs' => 'load_core', |
|
951 | + 'EE_Admin' => 'load_core', |
|
952 | + 'EE_CPT_Strategy' => 'load_core', |
|
953 | + // load_class |
|
954 | + 'EE_Registration_Processor' => 'load_class', |
|
955 | + // load_lib |
|
956 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
957 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
958 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
959 | + 'EE_Messenger_Collection' => 'load_lib', |
|
960 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
961 | + 'EE_Messages_Processor' => 'load_lib', |
|
962 | + 'EE_Message_Repository' => 'load_lib', |
|
963 | + 'EE_Messages_Queue' => 'load_lib', |
|
964 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
965 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
966 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
967 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
968 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
969 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
970 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
971 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
972 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
973 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
974 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
975 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
976 | + 'EE_Messages_Generator' => function () { |
|
977 | + return EE_Registry::instance()->load_lib( |
|
978 | + 'Messages_Generator', |
|
979 | + array(), |
|
980 | + false, |
|
981 | + false |
|
982 | + ); |
|
983 | + }, |
|
984 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
985 | + return EE_Registry::instance()->load_lib( |
|
986 | + 'Messages_Template_Defaults', |
|
987 | + $arguments, |
|
988 | + false, |
|
989 | + false |
|
990 | + ); |
|
991 | + }, |
|
992 | + // load_helper |
|
993 | + 'EEH_Parse_Shortcodes' => function () { |
|
994 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
995 | + return new EEH_Parse_Shortcodes(); |
|
996 | + } |
|
997 | + return null; |
|
998 | + }, |
|
999 | + 'EE_Template_Config' => function () { |
|
1000 | + return EE_Config::instance()->template_settings; |
|
1001 | + }, |
|
1002 | + 'EE_Currency_Config' => function () { |
|
1003 | + return EE_Config::instance()->currency; |
|
1004 | + }, |
|
1005 | + 'EE_Registration_Config' => function () { |
|
1006 | + return EE_Config::instance()->registration; |
|
1007 | + }, |
|
1008 | + 'EE_Core_Config' => function () { |
|
1009 | + return EE_Config::instance()->core; |
|
1010 | + }, |
|
1011 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
1012 | + return LoaderFactory::getLoader(); |
|
1013 | + }, |
|
1014 | + 'EE_Network_Config' => function () { |
|
1015 | + return EE_Network_Config::instance(); |
|
1016 | + }, |
|
1017 | + 'EE_Config' => function () { |
|
1018 | + return EE_Config::instance(); |
|
1019 | + }, |
|
1020 | + 'EventEspresso\core\domain\Domain' => function () { |
|
1021 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
1022 | + }, |
|
1023 | + 'EE_Admin_Config' => function () { |
|
1024 | + return EE_Config::instance()->admin; |
|
1025 | + }, |
|
1026 | + 'EE_Organization_Config' => function () { |
|
1027 | + return EE_Config::instance()->organization; |
|
1028 | + }, |
|
1029 | + 'EE_Network_Core_Config' => function () { |
|
1030 | + return EE_Network_Config::instance()->core; |
|
1031 | + }, |
|
1032 | + 'EE_Environment_Config' => function () { |
|
1033 | + return EE_Config::instance()->environment; |
|
1034 | + }, |
|
1035 | + ); |
|
1036 | + } |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * can be used for supplying alternate names for classes, |
|
1041 | + * or for connecting interface names to instantiable classes |
|
1042 | + */ |
|
1043 | + protected function _register_core_aliases() |
|
1044 | + { |
|
1045 | + $aliases = array( |
|
1046 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1047 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1048 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1049 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1050 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1051 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1052 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1053 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1054 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1055 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1056 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1057 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1058 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1059 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1060 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1061 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1062 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1063 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1064 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1065 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1066 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1067 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1068 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1069 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1070 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1071 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1072 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1073 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1074 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1075 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1076 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1077 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1078 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1079 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1080 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1081 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1082 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1083 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
1084 | + ); |
|
1085 | + foreach ($aliases as $alias => $fqn) { |
|
1086 | + if (is_array($fqn)) { |
|
1087 | + foreach ($fqn as $class => $for_class) { |
|
1088 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
1089 | + } |
|
1090 | + continue; |
|
1091 | + } |
|
1092 | + $this->class_cache->addAlias($fqn, $alias); |
|
1093 | + } |
|
1094 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1095 | + $this->class_cache->addAlias( |
|
1096 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1097 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1098 | + ); |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1105 | + * request Primarily used by unit tests. |
|
1106 | + */ |
|
1107 | + public function reset() |
|
1108 | + { |
|
1109 | + $this->_register_core_class_loaders(); |
|
1110 | + $this->_register_core_dependencies(); |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1116 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1117 | + * WHY? |
|
1118 | + * Because if a class is type hinting for a concretion, |
|
1119 | + * then why would we need to find another class to supply it? |
|
1120 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1121 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1122 | + * Don't go looking for some substitute. |
|
1123 | + * Whereas if a class is type hinting for an interface... |
|
1124 | + * then we need to find an actual class to use. |
|
1125 | + * So the interface IS the alias for some other FQN, |
|
1126 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1127 | + * represents some other class. |
|
1128 | + * |
|
1129 | + * @deprecated 4.9.62.p |
|
1130 | + * @param string $fqn |
|
1131 | + * @param string $for_class |
|
1132 | + * @return bool |
|
1133 | + */ |
|
1134 | + public function has_alias($fqn = '', $for_class = '') |
|
1135 | + { |
|
1136 | + return $this->isAlias($fqn, $for_class); |
|
1137 | + } |
|
1138 | + |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1142 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1143 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1144 | + * for example: |
|
1145 | + * if the following two entries were added to the _aliases array: |
|
1146 | + * array( |
|
1147 | + * 'interface_alias' => 'some\namespace\interface' |
|
1148 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1149 | + * ) |
|
1150 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1151 | + * to load an instance of 'some\namespace\classname' |
|
1152 | + * |
|
1153 | + * @deprecated 4.9.62.p |
|
1154 | + * @param string $alias |
|
1155 | + * @param string $for_class |
|
1156 | + * @return string |
|
1157 | + */ |
|
1158 | + public function get_alias($alias = '', $for_class = '') |
|
1159 | + { |
|
1160 | + return $this->getFqnForAlias($alias, $for_class); |
|
1161 | + } |
|
1162 | 1162 | } |
@@ -28,580 +28,580 @@ |
||
28 | 28 | abstract class SequentialStepFormManager |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * a simplified URL with no form related parameters |
|
33 | - * that will be used to build the form's redirect URLs |
|
34 | - * |
|
35 | - * @var string $base_url |
|
36 | - */ |
|
37 | - private $base_url = ''; |
|
38 | - |
|
39 | - /** |
|
40 | - * the key used for the URL param that denotes the current form step |
|
41 | - * defaults to 'ee-form-step' |
|
42 | - * |
|
43 | - * @var string $form_step_url_key |
|
44 | - */ |
|
45 | - private $form_step_url_key = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $default_form_step |
|
49 | - */ |
|
50 | - private $default_form_step = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $form_action |
|
54 | - */ |
|
55 | - private $form_action; |
|
56 | - |
|
57 | - /** |
|
58 | - * value of one of the string constant above |
|
59 | - * |
|
60 | - * @var string $form_config |
|
61 | - */ |
|
62 | - private $form_config; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string $progress_step_style |
|
66 | - */ |
|
67 | - private $progress_step_style = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var RequestInterface $request |
|
71 | - */ |
|
72 | - private $request; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var Collection $form_steps |
|
76 | - */ |
|
77 | - protected $form_steps; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var ProgressStepManager $progress_step_manager |
|
81 | - */ |
|
82 | - protected $progress_step_manager; |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return Collection|null |
|
87 | - */ |
|
88 | - abstract protected function getFormStepsCollection(); |
|
89 | - |
|
90 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
91 | - /** |
|
92 | - * StepsManager constructor |
|
93 | - * |
|
94 | - * @param string $base_url |
|
95 | - * @param string $default_form_step |
|
96 | - * @param string $form_action |
|
97 | - * @param string $form_config |
|
98 | - * @param RequestInterface $request |
|
99 | - * @param string $progress_step_style |
|
100 | - * @throws InvalidDataTypeException |
|
101 | - * @throws InvalidArgumentException |
|
102 | - */ |
|
103 | - public function __construct( |
|
104 | - $base_url, |
|
105 | - $default_form_step, |
|
106 | - $form_action = '', |
|
107 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
108 | - $progress_step_style = 'number_bubbles', |
|
109 | - RequestInterface $request = null |
|
110 | - ) { |
|
111 | - $this->setBaseUrl($base_url); |
|
112 | - $this->setDefaultFormStep($default_form_step); |
|
113 | - $this->setFormAction($form_action); |
|
114 | - $this->setFormConfig($form_config); |
|
115 | - $this->setProgressStepStyle($progress_step_style); |
|
116 | - $this->request = $request; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - * @throws InvalidFormHandlerException |
|
123 | - */ |
|
124 | - public function baseUrl() |
|
125 | - { |
|
126 | - if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
127 | - add_query_arg( |
|
128 | - array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
129 | - $this->base_url |
|
130 | - ); |
|
131 | - } |
|
132 | - return $this->base_url; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $base_url |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidArgumentException |
|
140 | - */ |
|
141 | - protected function setBaseUrl($base_url) |
|
142 | - { |
|
143 | - if (! is_string($base_url)) { |
|
144 | - throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
145 | - } |
|
146 | - if (empty($base_url)) { |
|
147 | - throw new InvalidArgumentException( |
|
148 | - esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
149 | - ); |
|
150 | - } |
|
151 | - $this->base_url = $base_url; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return string |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - */ |
|
159 | - public function formStepUrlKey() |
|
160 | - { |
|
161 | - if (empty($this->form_step_url_key)) { |
|
162 | - $this->setFormStepUrlKey(); |
|
163 | - } |
|
164 | - return $this->form_step_url_key; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param string $form_step_url_key |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
173 | - { |
|
174 | - if (! is_string($form_step_url_key)) { |
|
175 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
176 | - } |
|
177 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function defaultFormStep() |
|
185 | - { |
|
186 | - return $this->default_form_step; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @param $default_form_step |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - */ |
|
194 | - protected function setDefaultFormStep($default_form_step) |
|
195 | - { |
|
196 | - if (! is_string($default_form_step)) { |
|
197 | - throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
198 | - } |
|
199 | - $this->default_form_step = $default_form_step; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return void |
|
205 | - * @throws InvalidIdentifierException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - */ |
|
208 | - protected function setCurrentStepFromRequest() |
|
209 | - { |
|
210 | - $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
211 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
212 | - throw new InvalidIdentifierException( |
|
213 | - $current_step_slug, |
|
214 | - $this->defaultFormStep(), |
|
215 | - sprintf( |
|
216 | - esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
217 | - $current_step_slug |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @return SequentialStepFormInterface|object |
|
226 | - * @throws InvalidFormHandlerException |
|
227 | - */ |
|
228 | - public function getCurrentStep() |
|
229 | - { |
|
230 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
231 | - throw new InvalidFormHandlerException($this->form_steps->current()); |
|
232 | - } |
|
233 | - return $this->form_steps->current(); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return string |
|
239 | - * @throws InvalidFormHandlerException |
|
240 | - */ |
|
241 | - public function formAction() |
|
242 | - { |
|
243 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
244 | - $this->form_action = $this->baseUrl(); |
|
245 | - } |
|
246 | - return $this->form_action; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $form_action |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - */ |
|
254 | - public function setFormAction($form_action) |
|
255 | - { |
|
256 | - if (! is_string($form_action)) { |
|
257 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
258 | - } |
|
259 | - $this->form_action = $form_action; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @param array $form_action_args |
|
265 | - * @throws InvalidDataTypeException |
|
266 | - * @throws InvalidFormHandlerException |
|
267 | - */ |
|
268 | - public function addFormActionArgs($form_action_args = array()) |
|
269 | - { |
|
270 | - if (! is_array($form_action_args)) { |
|
271 | - throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
272 | - } |
|
273 | - $form_action_args = ! empty($form_action_args) |
|
274 | - ? $form_action_args |
|
275 | - : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
276 | - $this->getCurrentStep()->setFormAction( |
|
277 | - add_query_arg($form_action_args, $this->formAction()) |
|
278 | - ); |
|
279 | - $this->form_action = $this->getCurrentStep()->formAction(); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function formConfig() |
|
287 | - { |
|
288 | - return $this->form_config; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $form_config |
|
294 | - */ |
|
295 | - public function setFormConfig($form_config) |
|
296 | - { |
|
297 | - $this->form_config = $form_config; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function progressStepStyle() |
|
305 | - { |
|
306 | - return $this->progress_step_style; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param string $progress_step_style |
|
312 | - */ |
|
313 | - public function setProgressStepStyle($progress_step_style) |
|
314 | - { |
|
315 | - $this->progress_step_style = $progress_step_style; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * @return RequestInterface |
|
321 | - */ |
|
322 | - public function request() |
|
323 | - { |
|
324 | - return $this->request; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @return Collection|null |
|
330 | - * @throws InvalidInterfaceException |
|
331 | - */ |
|
332 | - protected function getProgressStepsCollection() |
|
333 | - { |
|
334 | - static $collection = null; |
|
335 | - if (! $collection instanceof ProgressStepCollection) { |
|
336 | - $collection = new ProgressStepCollection(); |
|
337 | - } |
|
338 | - return $collection; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @param Collection $progress_steps_collection |
|
344 | - * @return ProgressStepManager |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - * @throws InvalidClassException |
|
347 | - * @throws InvalidDataTypeException |
|
348 | - * @throws InvalidEntityException |
|
349 | - * @throws InvalidFormHandlerException |
|
350 | - */ |
|
351 | - protected function generateProgressSteps(Collection $progress_steps_collection) |
|
352 | - { |
|
353 | - $current_step = $this->getCurrentStep(); |
|
354 | - /** @var SequentialStepForm $form_step */ |
|
355 | - foreach ($this->form_steps as $form_step) { |
|
356 | - // is this step active ? |
|
357 | - if (! $form_step->initialize()) { |
|
358 | - continue; |
|
359 | - } |
|
360 | - $progress_steps_collection->add( |
|
361 | - new ProgressStep( |
|
362 | - $form_step->order(), |
|
363 | - $form_step->slug(), |
|
364 | - $form_step->slug(), |
|
365 | - $form_step->formName() |
|
366 | - ), |
|
367 | - $form_step->slug() |
|
368 | - ); |
|
369 | - } |
|
370 | - // set collection pointer back to current step |
|
371 | - $this->form_steps->setCurrentUsingObject($current_step); |
|
372 | - return new ProgressStepManager( |
|
373 | - $this->progressStepStyle(), |
|
374 | - $this->defaultFormStep(), |
|
375 | - $this->formStepUrlKey(), |
|
376 | - $progress_steps_collection |
|
377 | - ); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @throws InvalidClassException |
|
383 | - * @throws InvalidDataTypeException |
|
384 | - * @throws InvalidEntityException |
|
385 | - * @throws InvalidIdentifierException |
|
386 | - * @throws InvalidInterfaceException |
|
387 | - * @throws InvalidArgumentException |
|
388 | - * @throws InvalidFormHandlerException |
|
389 | - */ |
|
390 | - public function buildForm() |
|
391 | - { |
|
392 | - $this->buildCurrentStepFormForDisplay(); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @param array $form_data |
|
398 | - * @throws InvalidArgumentException |
|
399 | - * @throws InvalidClassException |
|
400 | - * @throws InvalidDataTypeException |
|
401 | - * @throws InvalidEntityException |
|
402 | - * @throws InvalidFormHandlerException |
|
403 | - * @throws InvalidIdentifierException |
|
404 | - * @throws InvalidInterfaceException |
|
405 | - */ |
|
406 | - public function processForm($form_data = array()) |
|
407 | - { |
|
408 | - $this->buildCurrentStepFormForProcessing(); |
|
409 | - $this->processCurrentStepForm($form_data); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * @throws InvalidClassException |
|
415 | - * @throws InvalidDataTypeException |
|
416 | - * @throws InvalidEntityException |
|
417 | - * @throws InvalidInterfaceException |
|
418 | - * @throws InvalidIdentifierException |
|
419 | - * @throws InvalidArgumentException |
|
420 | - * @throws InvalidFormHandlerException |
|
421 | - */ |
|
422 | - public function buildCurrentStepFormForDisplay() |
|
423 | - { |
|
424 | - $form_step = $this->buildCurrentStepForm(); |
|
425 | - // no displayable content ? then skip straight to processing |
|
426 | - if (! $form_step->displayable()) { |
|
427 | - $this->addFormActionArgs(); |
|
428 | - $form_step->setFormAction($this->formAction()); |
|
429 | - wp_safe_redirect($form_step->formAction()); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @throws InvalidClassException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws InvalidEntityException |
|
438 | - * @throws InvalidInterfaceException |
|
439 | - * @throws InvalidIdentifierException |
|
440 | - * @throws InvalidArgumentException |
|
441 | - * @throws InvalidFormHandlerException |
|
442 | - */ |
|
443 | - public function buildCurrentStepFormForProcessing() |
|
444 | - { |
|
445 | - $this->buildCurrentStepForm(false); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @param bool $for_display |
|
451 | - * @return SequentialStepFormInterface |
|
452 | - * @throws InvalidArgumentException |
|
453 | - * @throws InvalidClassException |
|
454 | - * @throws InvalidDataTypeException |
|
455 | - * @throws InvalidEntityException |
|
456 | - * @throws InvalidFormHandlerException |
|
457 | - * @throws InvalidIdentifierException |
|
458 | - * @throws InvalidInterfaceException |
|
459 | - */ |
|
460 | - private function buildCurrentStepForm($for_display = true) |
|
461 | - { |
|
462 | - $this->form_steps = $this->getFormStepsCollection(); |
|
463 | - $this->setCurrentStepFromRequest(); |
|
464 | - $form_step = $this->getCurrentStep(); |
|
465 | - if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
466 | - $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
467 | - } |
|
468 | - if ($for_display && $form_step->displayable()) { |
|
469 | - $this->progress_step_manager = $this->generateProgressSteps( |
|
470 | - $this->getProgressStepsCollection() |
|
471 | - ); |
|
472 | - $this->progress_step_manager->setCurrentStep( |
|
473 | - $form_step->slug() |
|
474 | - ); |
|
475 | - // mark all previous progress steps as completed |
|
476 | - $this->progress_step_manager->setPreviousStepsCompleted(); |
|
477 | - $this->progress_step_manager->enqueueStylesAndScripts(); |
|
478 | - $this->addFormActionArgs(); |
|
479 | - $form_step->setFormAction($this->formAction()); |
|
480 | - } else { |
|
481 | - $form_step->setRedirectUrl($this->baseUrl()); |
|
482 | - $form_step->addRedirectArgs( |
|
483 | - array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
484 | - ); |
|
485 | - } |
|
486 | - $form_step->generate(); |
|
487 | - if ($for_display) { |
|
488 | - $form_step->enqueueStylesAndScripts(); |
|
489 | - } |
|
490 | - return $form_step; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * @param bool $return_as_string |
|
496 | - * @return string |
|
497 | - * @throws InvalidFormHandlerException |
|
498 | - */ |
|
499 | - public function displayProgressSteps($return_as_string = true) |
|
500 | - { |
|
501 | - $form_step = $this->getCurrentStep(); |
|
502 | - if (! $form_step->displayable()) { |
|
503 | - return ''; |
|
504 | - } |
|
505 | - $progress_steps = apply_filters( |
|
506 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
507 | - '' |
|
508 | - ); |
|
509 | - $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
510 | - $progress_steps .= apply_filters( |
|
511 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
512 | - '' |
|
513 | - ); |
|
514 | - if ($return_as_string) { |
|
515 | - return $progress_steps; |
|
516 | - } |
|
517 | - echo $progress_steps; |
|
518 | - return ''; |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @param bool $return_as_string |
|
524 | - * @return string |
|
525 | - * @throws InvalidFormHandlerException |
|
526 | - */ |
|
527 | - public function displayCurrentStepForm($return_as_string = true) |
|
528 | - { |
|
529 | - if ($return_as_string) { |
|
530 | - return $this->getCurrentStep()->display(); |
|
531 | - } |
|
532 | - echo $this->getCurrentStep()->display(); |
|
533 | - return ''; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @param array $form_data |
|
539 | - * @return void |
|
540 | - * @throws InvalidArgumentException |
|
541 | - * @throws InvalidDataTypeException |
|
542 | - * @throws InvalidFormHandlerException |
|
543 | - */ |
|
544 | - public function processCurrentStepForm($form_data = array()) |
|
545 | - { |
|
546 | - // grab instance of current step because after calling next() below, |
|
547 | - // any calls to getCurrentStep() will return the "next" step because we advanced |
|
548 | - $current_step = $this->getCurrentStep(); |
|
549 | - try { |
|
550 | - // form processing should either throw exceptions or return true |
|
551 | - $current_step->process($form_data); |
|
552 | - } catch (Exception $e) { |
|
553 | - // something went wrong, convert the Exception to an EE_Error |
|
554 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
555 | - // prevent redirect to next step or other if exception was thrown |
|
556 | - if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
557 | - || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
558 | - ) { |
|
559 | - $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
560 | - } |
|
561 | - } |
|
562 | - // save notices to a transient so that when we redirect back |
|
563 | - // to the display portion for this step |
|
564 | - // those notices can be displayed |
|
565 | - EE_Error::get_notices(false, true); |
|
566 | - $this->redirectForm($current_step); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * handles where to go to next |
|
572 | - * |
|
573 | - * @param SequentialStepFormInterface $current_step |
|
574 | - * @throws InvalidArgumentException |
|
575 | - * @throws InvalidDataTypeException |
|
576 | - * @throws InvalidFormHandlerException |
|
577 | - */ |
|
578 | - public function redirectForm(SequentialStepFormInterface $current_step) |
|
579 | - { |
|
580 | - $redirect_step = $current_step; |
|
581 | - switch ($current_step->redirectTo()) { |
|
582 | - case SequentialStepForm::REDIRECT_TO_OTHER: |
|
583 | - // going somewhere else, so just check out now |
|
584 | - wp_safe_redirect($redirect_step->redirectUrl()); |
|
585 | - exit(); |
|
586 | - case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
587 | - $redirect_step = $this->form_steps->previous(); |
|
588 | - break; |
|
589 | - case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
590 | - $this->form_steps->next(); |
|
591 | - if ($this->form_steps->valid()) { |
|
592 | - $redirect_step = $this->form_steps->current(); |
|
593 | - } |
|
594 | - break; |
|
595 | - case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
596 | - default: |
|
597 | - // $redirect_step is already set |
|
598 | - } |
|
599 | - $current_step->setRedirectUrl($this->baseUrl()); |
|
600 | - $current_step->addRedirectArgs( |
|
601 | - // use the slug for whatever step we are redirecting too |
|
602 | - array($this->formStepUrlKey() => $redirect_step->slug()) |
|
603 | - ); |
|
604 | - wp_safe_redirect($current_step->redirectUrl()); |
|
605 | - exit(); |
|
606 | - } |
|
31 | + /** |
|
32 | + * a simplified URL with no form related parameters |
|
33 | + * that will be used to build the form's redirect URLs |
|
34 | + * |
|
35 | + * @var string $base_url |
|
36 | + */ |
|
37 | + private $base_url = ''; |
|
38 | + |
|
39 | + /** |
|
40 | + * the key used for the URL param that denotes the current form step |
|
41 | + * defaults to 'ee-form-step' |
|
42 | + * |
|
43 | + * @var string $form_step_url_key |
|
44 | + */ |
|
45 | + private $form_step_url_key = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $default_form_step |
|
49 | + */ |
|
50 | + private $default_form_step = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $form_action |
|
54 | + */ |
|
55 | + private $form_action; |
|
56 | + |
|
57 | + /** |
|
58 | + * value of one of the string constant above |
|
59 | + * |
|
60 | + * @var string $form_config |
|
61 | + */ |
|
62 | + private $form_config; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string $progress_step_style |
|
66 | + */ |
|
67 | + private $progress_step_style = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var RequestInterface $request |
|
71 | + */ |
|
72 | + private $request; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var Collection $form_steps |
|
76 | + */ |
|
77 | + protected $form_steps; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var ProgressStepManager $progress_step_manager |
|
81 | + */ |
|
82 | + protected $progress_step_manager; |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return Collection|null |
|
87 | + */ |
|
88 | + abstract protected function getFormStepsCollection(); |
|
89 | + |
|
90 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
91 | + /** |
|
92 | + * StepsManager constructor |
|
93 | + * |
|
94 | + * @param string $base_url |
|
95 | + * @param string $default_form_step |
|
96 | + * @param string $form_action |
|
97 | + * @param string $form_config |
|
98 | + * @param RequestInterface $request |
|
99 | + * @param string $progress_step_style |
|
100 | + * @throws InvalidDataTypeException |
|
101 | + * @throws InvalidArgumentException |
|
102 | + */ |
|
103 | + public function __construct( |
|
104 | + $base_url, |
|
105 | + $default_form_step, |
|
106 | + $form_action = '', |
|
107 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
108 | + $progress_step_style = 'number_bubbles', |
|
109 | + RequestInterface $request = null |
|
110 | + ) { |
|
111 | + $this->setBaseUrl($base_url); |
|
112 | + $this->setDefaultFormStep($default_form_step); |
|
113 | + $this->setFormAction($form_action); |
|
114 | + $this->setFormConfig($form_config); |
|
115 | + $this->setProgressStepStyle($progress_step_style); |
|
116 | + $this->request = $request; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + * @throws InvalidFormHandlerException |
|
123 | + */ |
|
124 | + public function baseUrl() |
|
125 | + { |
|
126 | + if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
127 | + add_query_arg( |
|
128 | + array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
129 | + $this->base_url |
|
130 | + ); |
|
131 | + } |
|
132 | + return $this->base_url; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $base_url |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidArgumentException |
|
140 | + */ |
|
141 | + protected function setBaseUrl($base_url) |
|
142 | + { |
|
143 | + if (! is_string($base_url)) { |
|
144 | + throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
145 | + } |
|
146 | + if (empty($base_url)) { |
|
147 | + throw new InvalidArgumentException( |
|
148 | + esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
149 | + ); |
|
150 | + } |
|
151 | + $this->base_url = $base_url; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + */ |
|
159 | + public function formStepUrlKey() |
|
160 | + { |
|
161 | + if (empty($this->form_step_url_key)) { |
|
162 | + $this->setFormStepUrlKey(); |
|
163 | + } |
|
164 | + return $this->form_step_url_key; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param string $form_step_url_key |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
173 | + { |
|
174 | + if (! is_string($form_step_url_key)) { |
|
175 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
176 | + } |
|
177 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function defaultFormStep() |
|
185 | + { |
|
186 | + return $this->default_form_step; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @param $default_form_step |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + */ |
|
194 | + protected function setDefaultFormStep($default_form_step) |
|
195 | + { |
|
196 | + if (! is_string($default_form_step)) { |
|
197 | + throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
198 | + } |
|
199 | + $this->default_form_step = $default_form_step; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + * @throws InvalidIdentifierException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + */ |
|
208 | + protected function setCurrentStepFromRequest() |
|
209 | + { |
|
210 | + $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
211 | + if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
212 | + throw new InvalidIdentifierException( |
|
213 | + $current_step_slug, |
|
214 | + $this->defaultFormStep(), |
|
215 | + sprintf( |
|
216 | + esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
217 | + $current_step_slug |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @return SequentialStepFormInterface|object |
|
226 | + * @throws InvalidFormHandlerException |
|
227 | + */ |
|
228 | + public function getCurrentStep() |
|
229 | + { |
|
230 | + if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
231 | + throw new InvalidFormHandlerException($this->form_steps->current()); |
|
232 | + } |
|
233 | + return $this->form_steps->current(); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return string |
|
239 | + * @throws InvalidFormHandlerException |
|
240 | + */ |
|
241 | + public function formAction() |
|
242 | + { |
|
243 | + if (! is_string($this->form_action) || empty($this->form_action)) { |
|
244 | + $this->form_action = $this->baseUrl(); |
|
245 | + } |
|
246 | + return $this->form_action; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $form_action |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + */ |
|
254 | + public function setFormAction($form_action) |
|
255 | + { |
|
256 | + if (! is_string($form_action)) { |
|
257 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
258 | + } |
|
259 | + $this->form_action = $form_action; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @param array $form_action_args |
|
265 | + * @throws InvalidDataTypeException |
|
266 | + * @throws InvalidFormHandlerException |
|
267 | + */ |
|
268 | + public function addFormActionArgs($form_action_args = array()) |
|
269 | + { |
|
270 | + if (! is_array($form_action_args)) { |
|
271 | + throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
272 | + } |
|
273 | + $form_action_args = ! empty($form_action_args) |
|
274 | + ? $form_action_args |
|
275 | + : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
276 | + $this->getCurrentStep()->setFormAction( |
|
277 | + add_query_arg($form_action_args, $this->formAction()) |
|
278 | + ); |
|
279 | + $this->form_action = $this->getCurrentStep()->formAction(); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function formConfig() |
|
287 | + { |
|
288 | + return $this->form_config; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $form_config |
|
294 | + */ |
|
295 | + public function setFormConfig($form_config) |
|
296 | + { |
|
297 | + $this->form_config = $form_config; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function progressStepStyle() |
|
305 | + { |
|
306 | + return $this->progress_step_style; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param string $progress_step_style |
|
312 | + */ |
|
313 | + public function setProgressStepStyle($progress_step_style) |
|
314 | + { |
|
315 | + $this->progress_step_style = $progress_step_style; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * @return RequestInterface |
|
321 | + */ |
|
322 | + public function request() |
|
323 | + { |
|
324 | + return $this->request; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @return Collection|null |
|
330 | + * @throws InvalidInterfaceException |
|
331 | + */ |
|
332 | + protected function getProgressStepsCollection() |
|
333 | + { |
|
334 | + static $collection = null; |
|
335 | + if (! $collection instanceof ProgressStepCollection) { |
|
336 | + $collection = new ProgressStepCollection(); |
|
337 | + } |
|
338 | + return $collection; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @param Collection $progress_steps_collection |
|
344 | + * @return ProgressStepManager |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + * @throws InvalidClassException |
|
347 | + * @throws InvalidDataTypeException |
|
348 | + * @throws InvalidEntityException |
|
349 | + * @throws InvalidFormHandlerException |
|
350 | + */ |
|
351 | + protected function generateProgressSteps(Collection $progress_steps_collection) |
|
352 | + { |
|
353 | + $current_step = $this->getCurrentStep(); |
|
354 | + /** @var SequentialStepForm $form_step */ |
|
355 | + foreach ($this->form_steps as $form_step) { |
|
356 | + // is this step active ? |
|
357 | + if (! $form_step->initialize()) { |
|
358 | + continue; |
|
359 | + } |
|
360 | + $progress_steps_collection->add( |
|
361 | + new ProgressStep( |
|
362 | + $form_step->order(), |
|
363 | + $form_step->slug(), |
|
364 | + $form_step->slug(), |
|
365 | + $form_step->formName() |
|
366 | + ), |
|
367 | + $form_step->slug() |
|
368 | + ); |
|
369 | + } |
|
370 | + // set collection pointer back to current step |
|
371 | + $this->form_steps->setCurrentUsingObject($current_step); |
|
372 | + return new ProgressStepManager( |
|
373 | + $this->progressStepStyle(), |
|
374 | + $this->defaultFormStep(), |
|
375 | + $this->formStepUrlKey(), |
|
376 | + $progress_steps_collection |
|
377 | + ); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @throws InvalidClassException |
|
383 | + * @throws InvalidDataTypeException |
|
384 | + * @throws InvalidEntityException |
|
385 | + * @throws InvalidIdentifierException |
|
386 | + * @throws InvalidInterfaceException |
|
387 | + * @throws InvalidArgumentException |
|
388 | + * @throws InvalidFormHandlerException |
|
389 | + */ |
|
390 | + public function buildForm() |
|
391 | + { |
|
392 | + $this->buildCurrentStepFormForDisplay(); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @param array $form_data |
|
398 | + * @throws InvalidArgumentException |
|
399 | + * @throws InvalidClassException |
|
400 | + * @throws InvalidDataTypeException |
|
401 | + * @throws InvalidEntityException |
|
402 | + * @throws InvalidFormHandlerException |
|
403 | + * @throws InvalidIdentifierException |
|
404 | + * @throws InvalidInterfaceException |
|
405 | + */ |
|
406 | + public function processForm($form_data = array()) |
|
407 | + { |
|
408 | + $this->buildCurrentStepFormForProcessing(); |
|
409 | + $this->processCurrentStepForm($form_data); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * @throws InvalidClassException |
|
415 | + * @throws InvalidDataTypeException |
|
416 | + * @throws InvalidEntityException |
|
417 | + * @throws InvalidInterfaceException |
|
418 | + * @throws InvalidIdentifierException |
|
419 | + * @throws InvalidArgumentException |
|
420 | + * @throws InvalidFormHandlerException |
|
421 | + */ |
|
422 | + public function buildCurrentStepFormForDisplay() |
|
423 | + { |
|
424 | + $form_step = $this->buildCurrentStepForm(); |
|
425 | + // no displayable content ? then skip straight to processing |
|
426 | + if (! $form_step->displayable()) { |
|
427 | + $this->addFormActionArgs(); |
|
428 | + $form_step->setFormAction($this->formAction()); |
|
429 | + wp_safe_redirect($form_step->formAction()); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @throws InvalidClassException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws InvalidEntityException |
|
438 | + * @throws InvalidInterfaceException |
|
439 | + * @throws InvalidIdentifierException |
|
440 | + * @throws InvalidArgumentException |
|
441 | + * @throws InvalidFormHandlerException |
|
442 | + */ |
|
443 | + public function buildCurrentStepFormForProcessing() |
|
444 | + { |
|
445 | + $this->buildCurrentStepForm(false); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @param bool $for_display |
|
451 | + * @return SequentialStepFormInterface |
|
452 | + * @throws InvalidArgumentException |
|
453 | + * @throws InvalidClassException |
|
454 | + * @throws InvalidDataTypeException |
|
455 | + * @throws InvalidEntityException |
|
456 | + * @throws InvalidFormHandlerException |
|
457 | + * @throws InvalidIdentifierException |
|
458 | + * @throws InvalidInterfaceException |
|
459 | + */ |
|
460 | + private function buildCurrentStepForm($for_display = true) |
|
461 | + { |
|
462 | + $this->form_steps = $this->getFormStepsCollection(); |
|
463 | + $this->setCurrentStepFromRequest(); |
|
464 | + $form_step = $this->getCurrentStep(); |
|
465 | + if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
466 | + $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
467 | + } |
|
468 | + if ($for_display && $form_step->displayable()) { |
|
469 | + $this->progress_step_manager = $this->generateProgressSteps( |
|
470 | + $this->getProgressStepsCollection() |
|
471 | + ); |
|
472 | + $this->progress_step_manager->setCurrentStep( |
|
473 | + $form_step->slug() |
|
474 | + ); |
|
475 | + // mark all previous progress steps as completed |
|
476 | + $this->progress_step_manager->setPreviousStepsCompleted(); |
|
477 | + $this->progress_step_manager->enqueueStylesAndScripts(); |
|
478 | + $this->addFormActionArgs(); |
|
479 | + $form_step->setFormAction($this->formAction()); |
|
480 | + } else { |
|
481 | + $form_step->setRedirectUrl($this->baseUrl()); |
|
482 | + $form_step->addRedirectArgs( |
|
483 | + array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
484 | + ); |
|
485 | + } |
|
486 | + $form_step->generate(); |
|
487 | + if ($for_display) { |
|
488 | + $form_step->enqueueStylesAndScripts(); |
|
489 | + } |
|
490 | + return $form_step; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * @param bool $return_as_string |
|
496 | + * @return string |
|
497 | + * @throws InvalidFormHandlerException |
|
498 | + */ |
|
499 | + public function displayProgressSteps($return_as_string = true) |
|
500 | + { |
|
501 | + $form_step = $this->getCurrentStep(); |
|
502 | + if (! $form_step->displayable()) { |
|
503 | + return ''; |
|
504 | + } |
|
505 | + $progress_steps = apply_filters( |
|
506 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
507 | + '' |
|
508 | + ); |
|
509 | + $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
510 | + $progress_steps .= apply_filters( |
|
511 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
512 | + '' |
|
513 | + ); |
|
514 | + if ($return_as_string) { |
|
515 | + return $progress_steps; |
|
516 | + } |
|
517 | + echo $progress_steps; |
|
518 | + return ''; |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @param bool $return_as_string |
|
524 | + * @return string |
|
525 | + * @throws InvalidFormHandlerException |
|
526 | + */ |
|
527 | + public function displayCurrentStepForm($return_as_string = true) |
|
528 | + { |
|
529 | + if ($return_as_string) { |
|
530 | + return $this->getCurrentStep()->display(); |
|
531 | + } |
|
532 | + echo $this->getCurrentStep()->display(); |
|
533 | + return ''; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @param array $form_data |
|
539 | + * @return void |
|
540 | + * @throws InvalidArgumentException |
|
541 | + * @throws InvalidDataTypeException |
|
542 | + * @throws InvalidFormHandlerException |
|
543 | + */ |
|
544 | + public function processCurrentStepForm($form_data = array()) |
|
545 | + { |
|
546 | + // grab instance of current step because after calling next() below, |
|
547 | + // any calls to getCurrentStep() will return the "next" step because we advanced |
|
548 | + $current_step = $this->getCurrentStep(); |
|
549 | + try { |
|
550 | + // form processing should either throw exceptions or return true |
|
551 | + $current_step->process($form_data); |
|
552 | + } catch (Exception $e) { |
|
553 | + // something went wrong, convert the Exception to an EE_Error |
|
554 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
555 | + // prevent redirect to next step or other if exception was thrown |
|
556 | + if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
557 | + || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
558 | + ) { |
|
559 | + $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
560 | + } |
|
561 | + } |
|
562 | + // save notices to a transient so that when we redirect back |
|
563 | + // to the display portion for this step |
|
564 | + // those notices can be displayed |
|
565 | + EE_Error::get_notices(false, true); |
|
566 | + $this->redirectForm($current_step); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * handles where to go to next |
|
572 | + * |
|
573 | + * @param SequentialStepFormInterface $current_step |
|
574 | + * @throws InvalidArgumentException |
|
575 | + * @throws InvalidDataTypeException |
|
576 | + * @throws InvalidFormHandlerException |
|
577 | + */ |
|
578 | + public function redirectForm(SequentialStepFormInterface $current_step) |
|
579 | + { |
|
580 | + $redirect_step = $current_step; |
|
581 | + switch ($current_step->redirectTo()) { |
|
582 | + case SequentialStepForm::REDIRECT_TO_OTHER: |
|
583 | + // going somewhere else, so just check out now |
|
584 | + wp_safe_redirect($redirect_step->redirectUrl()); |
|
585 | + exit(); |
|
586 | + case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
587 | + $redirect_step = $this->form_steps->previous(); |
|
588 | + break; |
|
589 | + case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
590 | + $this->form_steps->next(); |
|
591 | + if ($this->form_steps->valid()) { |
|
592 | + $redirect_step = $this->form_steps->current(); |
|
593 | + } |
|
594 | + break; |
|
595 | + case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
596 | + default: |
|
597 | + // $redirect_step is already set |
|
598 | + } |
|
599 | + $current_step->setRedirectUrl($this->baseUrl()); |
|
600 | + $current_step->addRedirectArgs( |
|
601 | + // use the slug for whatever step we are redirecting too |
|
602 | + array($this->formStepUrlKey() => $redirect_step->slug()) |
|
603 | + ); |
|
604 | + wp_safe_redirect($current_step->redirectUrl()); |
|
605 | + exit(); |
|
606 | + } |
|
607 | 607 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function setBaseUrl($base_url) |
142 | 142 | { |
143 | - if (! is_string($base_url)) { |
|
143 | + if ( ! is_string($base_url)) { |
|
144 | 144 | throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
145 | 145 | } |
146 | 146 | if (empty($base_url)) { |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
173 | 173 | { |
174 | - if (! is_string($form_step_url_key)) { |
|
174 | + if ( ! is_string($form_step_url_key)) { |
|
175 | 175 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
176 | 176 | } |
177 | 177 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function setDefaultFormStep($default_form_step) |
195 | 195 | { |
196 | - if (! is_string($default_form_step)) { |
|
196 | + if ( ! is_string($default_form_step)) { |
|
197 | 197 | throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
198 | 198 | } |
199 | 199 | $this->default_form_step = $default_form_step; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | protected function setCurrentStepFromRequest() |
209 | 209 | { |
210 | 210 | $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
211 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
211 | + if ( ! $this->form_steps->setCurrent($current_step_slug)) { |
|
212 | 212 | throw new InvalidIdentifierException( |
213 | 213 | $current_step_slug, |
214 | 214 | $this->defaultFormStep(), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function getCurrentStep() |
229 | 229 | { |
230 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
230 | + if ( ! $this->form_steps->current() instanceof SequentialStepForm) { |
|
231 | 231 | throw new InvalidFormHandlerException($this->form_steps->current()); |
232 | 232 | } |
233 | 233 | return $this->form_steps->current(); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function formAction() |
242 | 242 | { |
243 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
243 | + if ( ! is_string($this->form_action) || empty($this->form_action)) { |
|
244 | 244 | $this->form_action = $this->baseUrl(); |
245 | 245 | } |
246 | 246 | return $this->form_action; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function setFormAction($form_action) |
255 | 255 | { |
256 | - if (! is_string($form_action)) { |
|
256 | + if ( ! is_string($form_action)) { |
|
257 | 257 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
258 | 258 | } |
259 | 259 | $this->form_action = $form_action; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function addFormActionArgs($form_action_args = array()) |
269 | 269 | { |
270 | - if (! is_array($form_action_args)) { |
|
270 | + if ( ! is_array($form_action_args)) { |
|
271 | 271 | throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
272 | 272 | } |
273 | 273 | $form_action_args = ! empty($form_action_args) |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | protected function getProgressStepsCollection() |
333 | 333 | { |
334 | 334 | static $collection = null; |
335 | - if (! $collection instanceof ProgressStepCollection) { |
|
335 | + if ( ! $collection instanceof ProgressStepCollection) { |
|
336 | 336 | $collection = new ProgressStepCollection(); |
337 | 337 | } |
338 | 338 | return $collection; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | /** @var SequentialStepForm $form_step */ |
355 | 355 | foreach ($this->form_steps as $form_step) { |
356 | 356 | // is this step active ? |
357 | - if (! $form_step->initialize()) { |
|
357 | + if ( ! $form_step->initialize()) { |
|
358 | 358 | continue; |
359 | 359 | } |
360 | 360 | $progress_steps_collection->add( |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | { |
424 | 424 | $form_step = $this->buildCurrentStepForm(); |
425 | 425 | // no displayable content ? then skip straight to processing |
426 | - if (! $form_step->displayable()) { |
|
426 | + if ( ! $form_step->displayable()) { |
|
427 | 427 | $this->addFormActionArgs(); |
428 | 428 | $form_step->setFormAction($this->formAction()); |
429 | 429 | wp_safe_redirect($form_step->formAction()); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | public function displayProgressSteps($return_as_string = true) |
500 | 500 | { |
501 | 501 | $form_step = $this->getCurrentStep(); |
502 | - if (! $form_step->displayable()) { |
|
502 | + if ( ! $form_step->displayable()) { |
|
503 | 503 | return ''; |
504 | 504 | } |
505 | 505 | $progress_steps = apply_filters( |
@@ -22,1237 +22,1237 @@ |
||
22 | 22 | class EE_Register_Addon implements EEI_Plugin_API |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * possibly truncated version of the EE core version string |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected static $_core_version = ''; |
|
31 | - |
|
32 | - /** |
|
33 | - * Holds values for registered addons |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected static $_settings = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | - * EE core with knowledge of ALL the addons out there. |
|
45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | - * minimum plugin version. |
|
49 | - * @access protected |
|
50 | - */ |
|
51 | - protected static $_incompatible_addons = array( |
|
52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | - 'Promotions' => '1.0.0.rc.084', |
|
54 | - ); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | - * not just '4.3.0'. |
|
60 | - * So if the addon developer doesn't provide that full version string, |
|
61 | - * fill in the blanks for them |
|
62 | - * |
|
63 | - * @param string $min_core_version |
|
64 | - * @return string always like '4.3.0.rc.000' |
|
65 | - */ |
|
66 | - protected static function _effective_version($min_core_version) |
|
67 | - { |
|
68 | - // versions: 4 . 3 . 1 . p . 123 |
|
69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | - $version_parts = explode('.', $min_core_version); |
|
71 | - // check they specified the micro version (after 2nd period) |
|
72 | - if (! isset($version_parts[2])) { |
|
73 | - $version_parts[2] = '0'; |
|
74 | - } |
|
75 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | - if (! isset($version_parts[3])) { |
|
78 | - $version_parts[3] = 'dev'; |
|
79 | - } |
|
80 | - if (! isset($version_parts[4])) { |
|
81 | - $version_parts[4] = '000'; |
|
82 | - } |
|
83 | - return implode('.', $version_parts); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns whether or not the min core version requirement of the addon is met |
|
89 | - * |
|
90 | - * @param string $min_core_version the minimum core version required by the addon |
|
91 | - * @param string $actual_core_version the actual core version, optional |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public static function _meets_min_core_version_requirement( |
|
95 | - $min_core_version, |
|
96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | - ) { |
|
98 | - return version_compare( |
|
99 | - self::_effective_version($actual_core_version), |
|
100 | - self::_effective_version($min_core_version), |
|
101 | - '>=' |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Method for registering new EE_Addons. |
|
108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | - * |
|
117 | - * @since 4.3.0 |
|
118 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | - * @param array $setup_args { |
|
120 | - * An array of arguments provided for registering |
|
121 | - * the message type. |
|
122 | - * @type string $class_name the addon's main file name. |
|
123 | - * If left blank, generated from the addon name, |
|
124 | - * changes something like "calendar" to |
|
125 | - * "EE_Calendar" |
|
126 | - * @type string $min_core_version the minimum version of EE Core that the |
|
127 | - * addon will work with. eg "4.8.1.rc.084" |
|
128 | - * @type string $version the "software" version for the addon. eg |
|
129 | - * "1.0.0.p" for a first stable release, or |
|
130 | - * "1.0.0.rc.043" for a version in progress |
|
131 | - * @type string $main_file_path the full server path to the main file |
|
132 | - * loaded directly by WP |
|
133 | - * @type DomainInterface $domain child class of |
|
134 | - * EventEspresso\core\domain\DomainBase |
|
135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | - * for the addon's Domain class |
|
137 | - * (see EventEspresso\core\domain\Domain) |
|
138 | - * @type string $admin_path full server path to the folder where the |
|
139 | - * addon\'s admin files reside |
|
140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | - * first invoked, can be used for hooking into |
|
142 | - * any admin page |
|
143 | - * @type string $config_section the section name for this addon's |
|
144 | - * configuration settings section |
|
145 | - * (defaults to "addons") |
|
146 | - * @type string $config_class the class name for this addon's |
|
147 | - * configuration settings object |
|
148 | - * @type string $config_name the class name for this addon's |
|
149 | - * configuration settings object |
|
150 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | - * server paths to those files. |
|
152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | - * folders containing classes that might be |
|
154 | - * invoked by the addon |
|
155 | - * @type string $dms_paths [Required] an array of full server paths to |
|
156 | - * folders that contain data migration scripts. |
|
157 | - * The key should be the EE_Addon class name that |
|
158 | - * this set of data migration scripts belongs to. |
|
159 | - * If the EE_Addon class is namespaced, then this |
|
160 | - * needs to be the Fully Qualified Class Name |
|
161 | - * @type string $module_paths an array of full server paths to any |
|
162 | - * EED_Modules used by the addon |
|
163 | - * @type string $shortcode_paths an array of full server paths to folders |
|
164 | - * that contain EES_Shortcodes |
|
165 | - * @type string $widget_paths an array of full server paths to folders |
|
166 | - * that contain WP_Widgets |
|
167 | - * @type string $pue_options |
|
168 | - * @type array $capabilities an array indexed by role name |
|
169 | - * (i.e administrator,author ) and the values |
|
170 | - * are an array of caps to add to the role. |
|
171 | - * 'administrator' => array( |
|
172 | - * 'read_addon', |
|
173 | - * 'edit_addon', |
|
174 | - * etc. |
|
175 | - * ). |
|
176 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | - * for any addons that need to register any |
|
178 | - * special meta mapped capabilities. Should |
|
179 | - * be indexed where the key is the |
|
180 | - * EE_Meta_Capability_Map class name and the |
|
181 | - * values are the arguments sent to the class. |
|
182 | - * @type array $model_paths array of folders containing DB models |
|
183 | - * @see EE_Register_Model |
|
184 | - * @type array $class_paths array of folders containing DB classes |
|
185 | - * @see EE_Register_Model |
|
186 | - * @type array $model_extension_paths array of folders containing DB model |
|
187 | - * extensions |
|
188 | - * @see EE_Register_Model_Extension |
|
189 | - * @type array $class_extension_paths array of folders containing DB class |
|
190 | - * extensions |
|
191 | - * @see EE_Register_Model_Extension |
|
192 | - * @type array message_types { |
|
193 | - * An array of message types with the key as |
|
194 | - * the message type name and the values as |
|
195 | - * below: |
|
196 | - * @type string $mtfilename [Required] The filename of the message type |
|
197 | - * being registered. This will be the main |
|
198 | - * EE_{Message Type Name}_message_type class. |
|
199 | - * for example: |
|
200 | - * EE_Declined_Registration_message_type.class.php |
|
201 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | - * messages autoloader for the new message type. |
|
203 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | - * type should activate with. Each value in |
|
205 | - * the |
|
206 | - * array |
|
207 | - * should match the name property of a |
|
208 | - * EE_messenger. Optional. |
|
209 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | - * type should validate with. Each value in |
|
211 | - * the |
|
212 | - * array |
|
213 | - * should match the name property of an |
|
214 | - * EE_messenger. |
|
215 | - * Optional. |
|
216 | - * } |
|
217 | - * @type array $custom_post_types |
|
218 | - * @type array $custom_taxonomies |
|
219 | - * @type array $payment_method_paths each element is the folder containing the |
|
220 | - * EE_PMT_Base child class |
|
221 | - * (eg, |
|
222 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | - * which contains the files |
|
224 | - * EE_PMT_Payomatic.pm.php) |
|
225 | - * @type array $default_terms |
|
226 | - * @type array $namespace { |
|
227 | - * An array with two items for registering the |
|
228 | - * addon's namespace. (If, for some reason, you |
|
229 | - * require additional namespaces, |
|
230 | - * use |
|
231 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | - * directly) |
|
233 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | - * @type string $FQNS the namespace prefix |
|
235 | - * @type string $DIR a base directory for class files in the |
|
236 | - * namespace. |
|
237 | - * } |
|
238 | - * } |
|
239 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | - * privacy policy classes) or FQCNs (specific |
|
241 | - * classnames of privacy policy classes) |
|
242 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | - * privacy policy classes) or FQCNs (specific |
|
244 | - * classnames of privacy policy classes) |
|
245 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | - * privacy policy classes) or FQCNs (specific |
|
247 | - * classnames of privacy policy classes) |
|
248 | - * @return void |
|
249 | - * @throws DomainException |
|
250 | - * @throws EE_Error |
|
251 | - * @throws InvalidArgumentException |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws InvalidInterfaceException |
|
254 | - */ |
|
255 | - public static function register($addon_name = '', array $setup_args = array()) |
|
256 | - { |
|
257 | - // required fields MUST be present, so let's make sure they are. |
|
258 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
259 | - // get class name for addon |
|
260 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
261 | - // setup $_settings array from incoming values. |
|
262 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
263 | - // setup PUE |
|
264 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
265 | - // does this addon work with this version of core or WordPress ? |
|
266 | - // does this addon work with this version of core or WordPress ? |
|
267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | - return; |
|
269 | - } |
|
270 | - // register namespaces |
|
271 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | - // check if this is an activation request |
|
273 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | - // dont bother setting up the rest of the addon atm |
|
275 | - return; |
|
276 | - } |
|
277 | - // we need cars |
|
278 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | - // register new models and extensions |
|
280 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | - // setup DMS |
|
282 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | - // if config_class is present let's register config. |
|
284 | - EE_Register_Addon::_register_config($addon_name); |
|
285 | - // register admin pages |
|
286 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | - // add to list of modules to be registered |
|
288 | - EE_Register_Addon::_register_modules($addon_name); |
|
289 | - // add to list of shortcodes to be registered |
|
290 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | - // add to list of widgets to be registered |
|
292 | - EE_Register_Addon::_register_widgets($addon_name); |
|
293 | - // register capability related stuff. |
|
294 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | - // any message type to register? |
|
296 | - EE_Register_Addon::_register_message_types($addon_name); |
|
297 | - // any custom post type/ custom capabilities or default terms to register |
|
298 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | - // and any payment methods |
|
300 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | - // and privacy policy generators |
|
302 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | - // and privacy policy generators |
|
304 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | - // and privacy policy generators |
|
306 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | - // load and instantiate main addon class |
|
308 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $addon_name |
|
316 | - * @param array $setup_args |
|
317 | - * @return void |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - // required fields MUST be present, so let's make sure they are. |
|
323 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | - throw new EE_Error( |
|
325 | - __( |
|
326 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | - 'event_espresso' |
|
328 | - ) |
|
329 | - ); |
|
330 | - } |
|
331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | - throw new EE_Error( |
|
333 | - sprintf( |
|
334 | - __( |
|
335 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - implode(',', array_keys($setup_args)) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - // check that addon has not already been registered with that name |
|
343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | - throw new EE_Error( |
|
345 | - sprintf( |
|
346 | - __( |
|
347 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - $addon_name |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $addon_name |
|
359 | - * @param array $setup_args |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | - { |
|
364 | - if (empty($setup_args['class_name'])) { |
|
365 | - // generate one by first separating name with spaces |
|
366 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | - // capitalize, then replace spaces with underscores |
|
368 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | - } else { |
|
370 | - $class_name = $setup_args['class_name']; |
|
371 | - } |
|
372 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | - ? $class_name |
|
375 | - : 'EE_' . $class_name; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @param string $class_name |
|
381 | - * @param array $setup_args |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | - { |
|
386 | - // setup $_settings array from incoming values. |
|
387 | - $addon_settings = array( |
|
388 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | - 'class_name' => $class_name, |
|
390 | - // the addon slug for use in URLs, etc |
|
391 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | - ? (string) $setup_args['plugin_slug'] |
|
393 | - : '', |
|
394 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | - ? (string) $setup_args['plugin_action_slug'] |
|
397 | - : '', |
|
398 | - // the "software" version for the addon |
|
399 | - 'version' => isset($setup_args['version']) |
|
400 | - ? (string) $setup_args['version'] |
|
401 | - : '', |
|
402 | - // the minimum version of EE Core that the addon will work with |
|
403 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | - ? (string) $setup_args['min_core_version'] |
|
405 | - : '', |
|
406 | - // the minimum version of WordPress that the addon will work with |
|
407 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | - ? (string) $setup_args['min_wp_version'] |
|
409 | - : EE_MIN_WP_VER_REQUIRED, |
|
410 | - // full server path to main file (file loaded directly by WP) |
|
411 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | - ? (string) $setup_args['main_file_path'] |
|
413 | - : '', |
|
414 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | - ? $setup_args['domain'] |
|
417 | - : null, |
|
418 | - // Fully Qualified Class Name for the addon's Domain class |
|
419 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | - ? (string) $setup_args['domain_fqcn'] |
|
421 | - : '', |
|
422 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | - 'admin_path' => isset($setup_args['admin_path']) |
|
424 | - ? (string) $setup_args['admin_path'] : '', |
|
425 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | - ? (string) $setup_args['admin_callback'] |
|
428 | - : '', |
|
429 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | - 'config_section' => isset($setup_args['config_section']) |
|
431 | - ? (string) $setup_args['config_section'] |
|
432 | - : 'addons', |
|
433 | - // the class name for this addon's configuration settings object |
|
434 | - 'config_class' => isset($setup_args['config_class']) |
|
435 | - ? (string) $setup_args['config_class'] : '', |
|
436 | - // the name given to the config for this addons' configuration settings object (optional) |
|
437 | - 'config_name' => isset($setup_args['config_name']) |
|
438 | - ? (string) $setup_args['config_name'] : '', |
|
439 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | - ? (array) $setup_args['autoloader_paths'] |
|
442 | - : array(), |
|
443 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | - ? (array) $setup_args['autoloader_folders'] |
|
446 | - : array(), |
|
447 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | - ? (array) $setup_args['dms_paths'] |
|
452 | - : array(), |
|
453 | - // array of full server paths to any EED_Modules used by the addon |
|
454 | - 'module_paths' => isset($setup_args['module_paths']) |
|
455 | - ? (array) $setup_args['module_paths'] |
|
456 | - : array(), |
|
457 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | - ? (array) $setup_args['shortcode_paths'] |
|
460 | - : array(), |
|
461 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | - ? (array) $setup_args['shortcode_fqcns'] |
|
463 | - : array(), |
|
464 | - // array of full server paths to any WP_Widgets used by the addon |
|
465 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | - ? (array) $setup_args['widget_paths'] |
|
467 | - : array(), |
|
468 | - // array of PUE options used by the addon |
|
469 | - 'pue_options' => isset($setup_args['pue_options']) |
|
470 | - ? (array) $setup_args['pue_options'] |
|
471 | - : array(), |
|
472 | - 'message_types' => isset($setup_args['message_types']) |
|
473 | - ? (array) $setup_args['message_types'] |
|
474 | - : array(), |
|
475 | - 'capabilities' => isset($setup_args['capabilities']) |
|
476 | - ? (array) $setup_args['capabilities'] |
|
477 | - : array(), |
|
478 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | - ? (array) $setup_args['capability_maps'] |
|
480 | - : array(), |
|
481 | - 'model_paths' => isset($setup_args['model_paths']) |
|
482 | - ? (array) $setup_args['model_paths'] |
|
483 | - : array(), |
|
484 | - 'class_paths' => isset($setup_args['class_paths']) |
|
485 | - ? (array) $setup_args['class_paths'] |
|
486 | - : array(), |
|
487 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | - ? (array) $setup_args['model_extension_paths'] |
|
489 | - : array(), |
|
490 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | - ? (array) $setup_args['class_extension_paths'] |
|
492 | - : array(), |
|
493 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | - ? (array) $setup_args['custom_post_types'] |
|
495 | - : array(), |
|
496 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | - ? (array) $setup_args['custom_taxonomies'] |
|
498 | - : array(), |
|
499 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | - ? (array) $setup_args['payment_method_paths'] |
|
501 | - : array(), |
|
502 | - 'default_terms' => isset($setup_args['default_terms']) |
|
503 | - ? (array) $setup_args['default_terms'] |
|
504 | - : array(), |
|
505 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | - // that can be used for adding upgrading/marketing info |
|
507 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
508 | - 'namespace' => isset( |
|
509 | - $setup_args['namespace']['FQNS'], |
|
510 | - $setup_args['namespace']['DIR'] |
|
511 | - ) |
|
512 | - ? (array) $setup_args['namespace'] |
|
513 | - : array(), |
|
514 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
515 | - ? (array) $setup_args['privacy_policies'] |
|
516 | - : '', |
|
517 | - ); |
|
518 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
519 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
520 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
521 | - && ! empty($addon_settings['admin_path']) |
|
522 | - ? $addon_settings['plugin_slug'] |
|
523 | - : $addon_settings['plugin_action_slug']; |
|
524 | - // full server path to main file (file loaded directly by WP) |
|
525 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
526 | - return $addon_settings; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param string $addon_name |
|
532 | - * @param array $addon_settings |
|
533 | - * @return boolean |
|
534 | - */ |
|
535 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
536 | - { |
|
537 | - global $wp_version; |
|
538 | - $incompatibility_message = ''; |
|
539 | - // check whether this addon version is compatible with EE core |
|
540 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
541 | - && ! self::_meets_min_core_version_requirement( |
|
542 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
543 | - $addon_settings['version'] |
|
544 | - ) |
|
545 | - ) { |
|
546 | - $incompatibility_message = sprintf( |
|
547 | - __( |
|
548 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
549 | - 'event_espresso' |
|
550 | - ), |
|
551 | - $addon_name, |
|
552 | - '<br />', |
|
553 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
554 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
555 | - '</span><br />' |
|
556 | - ); |
|
557 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
558 | - ) { |
|
559 | - $incompatibility_message = sprintf( |
|
560 | - __( |
|
561 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
562 | - 'event_espresso' |
|
563 | - ), |
|
564 | - $addon_name, |
|
565 | - self::_effective_version($addon_settings['min_core_version']), |
|
566 | - self::_effective_version(espresso_version()), |
|
567 | - '<br />', |
|
568 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
569 | - '</span><br />' |
|
570 | - ); |
|
571 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
572 | - $incompatibility_message = sprintf( |
|
573 | - __( |
|
574 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
575 | - 'event_espresso' |
|
576 | - ), |
|
577 | - $addon_name, |
|
578 | - $addon_settings['min_wp_version'], |
|
579 | - '<br />', |
|
580 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
581 | - '</span><br />' |
|
582 | - ); |
|
583 | - } |
|
584 | - if (! empty($incompatibility_message)) { |
|
585 | - // remove 'activate' from the REQUEST |
|
586 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
587 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
588 | - if (current_user_can('activate_plugins')) { |
|
589 | - // show an error message indicating the plugin didn't activate properly |
|
590 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
591 | - } |
|
592 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
593 | - return false; |
|
594 | - } |
|
595 | - // addon IS compatible |
|
596 | - return true; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * if plugin update engine is being used for auto-updates, |
|
602 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
603 | - * (not needed if PUE is not being used) |
|
604 | - * |
|
605 | - * @param string $addon_name |
|
606 | - * @param string $class_name |
|
607 | - * @param array $setup_args |
|
608 | - * @return void |
|
609 | - */ |
|
610 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
611 | - { |
|
612 | - if (! empty($setup_args['pue_options'])) { |
|
613 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
614 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
615 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
616 | - : 'espresso_' . strtolower($class_name), |
|
617 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
618 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
619 | - : plugin_basename($setup_args['main_file_path']), |
|
620 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
621 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
622 | - : '24', |
|
623 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
624 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
625 | - : false, |
|
626 | - ); |
|
627 | - add_action( |
|
628 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
629 | - array('EE_Register_Addon', 'load_pue_update') |
|
630 | - ); |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
637 | - * |
|
638 | - * @param array $addon_settings |
|
639 | - * @return void |
|
640 | - */ |
|
641 | - private static function _setup_namespaces(array $addon_settings) |
|
642 | - { |
|
643 | - // |
|
644 | - if (isset( |
|
645 | - $addon_settings['namespace']['FQNS'], |
|
646 | - $addon_settings['namespace']['DIR'] |
|
647 | - )) { |
|
648 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
649 | - $addon_settings['namespace']['FQNS'], |
|
650 | - $addon_settings['namespace']['DIR'] |
|
651 | - ); |
|
652 | - } |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @param string $addon_name |
|
658 | - * @param array $addon_settings |
|
659 | - * @return bool |
|
660 | - * @throws InvalidArgumentException |
|
661 | - * @throws InvalidDataTypeException |
|
662 | - * @throws InvalidInterfaceException |
|
663 | - */ |
|
664 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
665 | - { |
|
666 | - // this is an activation request |
|
667 | - if (did_action('activate_plugin')) { |
|
668 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
669 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
670 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
671 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
672 | - if (! isset(self::$_settings[ $addon_name ]) |
|
673 | - || (isset(self::$_settings[ $addon_name ]) |
|
674 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
675 | - ) |
|
676 | - ) { |
|
677 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
678 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
679 | - $addon->set_activation_indicator_option(); |
|
680 | - // dont bother setting up the rest of the addon. |
|
681 | - // we know it was just activated and the request will end soon |
|
682 | - } |
|
683 | - return true; |
|
684 | - } |
|
685 | - // make sure this was called in the right place! |
|
686 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
687 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
688 | - ) { |
|
689 | - EE_Error::doing_it_wrong( |
|
690 | - __METHOD__, |
|
691 | - sprintf( |
|
692 | - __( |
|
693 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
694 | - 'event_espresso' |
|
695 | - ), |
|
696 | - $addon_name |
|
697 | - ), |
|
698 | - '4.3.0' |
|
699 | - ); |
|
700 | - } |
|
701 | - // make sure addon settings are set correctly without overwriting anything existing |
|
702 | - if (isset(self::$_settings[ $addon_name ])) { |
|
703 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | - } else { |
|
705 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | - } |
|
707 | - return false; |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * @param string $addon_name |
|
713 | - * @return void |
|
714 | - * @throws EE_Error |
|
715 | - */ |
|
716 | - private static function _setup_autoloaders($addon_name) |
|
717 | - { |
|
718 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | - // setup autoloader for single file |
|
720 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | - } |
|
722 | - // setup autoloaders for folders |
|
723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | - } |
|
727 | - } |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * register new models and extensions |
|
733 | - * |
|
734 | - * @param string $addon_name |
|
735 | - * @return void |
|
736 | - * @throws EE_Error |
|
737 | - */ |
|
738 | - private static function _register_models_and_extensions($addon_name) |
|
739 | - { |
|
740 | - // register new models |
|
741 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
742 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
743 | - ) { |
|
744 | - EE_Register_Model::register( |
|
745 | - $addon_name, |
|
746 | - array( |
|
747 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
748 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
749 | - ) |
|
750 | - ); |
|
751 | - } |
|
752 | - // register model extensions |
|
753 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
754 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
755 | - ) { |
|
756 | - EE_Register_Model_Extensions::register( |
|
757 | - $addon_name, |
|
758 | - array( |
|
759 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
760 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
761 | - ) |
|
762 | - ); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * @param string $addon_name |
|
769 | - * @return void |
|
770 | - * @throws EE_Error |
|
771 | - */ |
|
772 | - private static function _register_data_migration_scripts($addon_name) |
|
773 | - { |
|
774 | - // setup DMS |
|
775 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
776 | - EE_Register_Data_Migration_Scripts::register( |
|
777 | - $addon_name, |
|
778 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
779 | - ); |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - |
|
784 | - /** |
|
785 | - * @param string $addon_name |
|
786 | - * @return void |
|
787 | - * @throws EE_Error |
|
788 | - */ |
|
789 | - private static function _register_config($addon_name) |
|
790 | - { |
|
791 | - // if config_class is present let's register config. |
|
792 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
793 | - EE_Register_Config::register( |
|
794 | - self::$_settings[ $addon_name ]['config_class'], |
|
795 | - array( |
|
796 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
797 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
798 | - ) |
|
799 | - ); |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * @param string $addon_name |
|
806 | - * @return void |
|
807 | - * @throws EE_Error |
|
808 | - */ |
|
809 | - private static function _register_admin_pages($addon_name) |
|
810 | - { |
|
811 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
812 | - EE_Register_Admin_Page::register( |
|
813 | - $addon_name, |
|
814 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
815 | - ); |
|
816 | - } |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * @param string $addon_name |
|
822 | - * @return void |
|
823 | - * @throws EE_Error |
|
824 | - */ |
|
825 | - private static function _register_modules($addon_name) |
|
826 | - { |
|
827 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
828 | - EE_Register_Module::register( |
|
829 | - $addon_name, |
|
830 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
831 | - ); |
|
832 | - } |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * @param string $addon_name |
|
838 | - * @return void |
|
839 | - * @throws EE_Error |
|
840 | - */ |
|
841 | - private static function _register_shortcodes($addon_name) |
|
842 | - { |
|
843 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
844 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
845 | - ) { |
|
846 | - EE_Register_Shortcode::register( |
|
847 | - $addon_name, |
|
848 | - array( |
|
849 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
850 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
851 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
852 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
853 | - ) |
|
854 | - ); |
|
855 | - } |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * @param string $addon_name |
|
861 | - * @return void |
|
862 | - * @throws EE_Error |
|
863 | - */ |
|
864 | - private static function _register_widgets($addon_name) |
|
865 | - { |
|
866 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
867 | - EE_Register_Widget::register( |
|
868 | - $addon_name, |
|
869 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
870 | - ); |
|
871 | - } |
|
872 | - } |
|
873 | - |
|
874 | - |
|
875 | - /** |
|
876 | - * @param string $addon_name |
|
877 | - * @return void |
|
878 | - * @throws EE_Error |
|
879 | - */ |
|
880 | - private static function _register_capabilities($addon_name) |
|
881 | - { |
|
882 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
883 | - EE_Register_Capabilities::register( |
|
884 | - $addon_name, |
|
885 | - array( |
|
886 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
887 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
888 | - ) |
|
889 | - ); |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * @param string $addon_name |
|
896 | - * @return void |
|
897 | - */ |
|
898 | - private static function _register_message_types($addon_name) |
|
899 | - { |
|
900 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
901 | - add_action( |
|
902 | - 'EE_Brewing_Regular___messages_caf', |
|
903 | - array('EE_Register_Addon', 'register_message_types') |
|
904 | - ); |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param string $addon_name |
|
911 | - * @return void |
|
912 | - * @throws EE_Error |
|
913 | - */ |
|
914 | - private static function _register_custom_post_types($addon_name) |
|
915 | - { |
|
916 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
917 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
918 | - ) { |
|
919 | - EE_Register_CPT::register( |
|
920 | - $addon_name, |
|
921 | - array( |
|
922 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
923 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
924 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
925 | - ) |
|
926 | - ); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * @param string $addon_name |
|
933 | - * @return void |
|
934 | - * @throws InvalidArgumentException |
|
935 | - * @throws InvalidInterfaceException |
|
936 | - * @throws InvalidDataTypeException |
|
937 | - * @throws DomainException |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - private static function _register_payment_methods($addon_name) |
|
941 | - { |
|
942 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
943 | - EE_Register_Payment_Method::register( |
|
944 | - $addon_name, |
|
945 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
946 | - ); |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * @param string $addon_name |
|
953 | - * @return void |
|
954 | - * @throws InvalidArgumentException |
|
955 | - * @throws InvalidInterfaceException |
|
956 | - * @throws InvalidDataTypeException |
|
957 | - * @throws DomainException |
|
958 | - */ |
|
959 | - private static function registerPrivacyPolicies($addon_name) |
|
960 | - { |
|
961 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
962 | - EE_Register_Privacy_Policy::register( |
|
963 | - $addon_name, |
|
964 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
965 | - ); |
|
966 | - } |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * @param string $addon_name |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - private static function registerPersonalDataExporters($addon_name) |
|
975 | - { |
|
976 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
977 | - EE_Register_Personal_Data_Eraser::register( |
|
978 | - $addon_name, |
|
979 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
980 | - ); |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @param string $addon_name |
|
987 | - * @return void |
|
988 | - */ |
|
989 | - private static function registerPersonalDataErasers($addon_name) |
|
990 | - { |
|
991 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
992 | - EE_Register_Personal_Data_Eraser::register( |
|
993 | - $addon_name, |
|
994 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
995 | - ); |
|
996 | - } |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - /** |
|
1001 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1002 | - * |
|
1003 | - * @param string $addon_name |
|
1004 | - * @return EE_Addon |
|
1005 | - * @throws InvalidArgumentException |
|
1006 | - * @throws InvalidInterfaceException |
|
1007 | - * @throws InvalidDataTypeException |
|
1008 | - */ |
|
1009 | - private static function _load_and_init_addon_class($addon_name) |
|
1010 | - { |
|
1011 | - $addon = LoaderFactory::getLoader()->getShared( |
|
1012 | - self::$_settings[ $addon_name ]['class_name'], |
|
1013 | - array('EE_Registry::create(addon)' => true) |
|
1014 | - ); |
|
1015 | - if (! $addon instanceof EE_Addon) { |
|
1016 | - throw new DomainException( |
|
1017 | - sprintf( |
|
1018 | - esc_html__( |
|
1019 | - 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
1020 | - 'event_espresso' |
|
1021 | - ), |
|
1022 | - $addon_name |
|
1023 | - ) |
|
1024 | - ); |
|
1025 | - } |
|
1026 | - // setter inject dep map if required |
|
1027 | - if ($addon->dependencyMap() === null) { |
|
1028 | - $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
1029 | - } |
|
1030 | - // setter inject domain if required |
|
1031 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1032 | - |
|
1033 | - $addon->set_name($addon_name); |
|
1034 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1035 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1036 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1037 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1038 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1039 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1040 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1041 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1042 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1043 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1044 | - // setup the add-on's pue_slug if we have one. |
|
1045 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1046 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1047 | - } |
|
1048 | - // unfortunately this can't be hooked in upon construction, |
|
1049 | - // because we don't have the plugin's mainfile path upon construction. |
|
1050 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1051 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1052 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1053 | - add_action( |
|
1054 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1055 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - return $addon; |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * @param string $addon_name |
|
1064 | - * @param EE_Addon $addon |
|
1065 | - * @since 4.10.13.p |
|
1066 | - */ |
|
1067 | - private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
1068 | - { |
|
1069 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1070 | - // using supplied Domain object |
|
1071 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1072 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1073 | - : null; |
|
1074 | - // or construct one using Domain FQCN |
|
1075 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1076 | - $domain = LoaderFactory::getLoader()->getShared( |
|
1077 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1078 | - [ |
|
1079 | - new EventEspresso\core\domain\values\FilePath( |
|
1080 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1081 | - ), |
|
1082 | - EventEspresso\core\domain\values\Version::fromString( |
|
1083 | - self::$_settings[ $addon_name ]['version'] |
|
1084 | - ), |
|
1085 | - ] |
|
1086 | - ); |
|
1087 | - } |
|
1088 | - if ($domain instanceof DomainInterface) { |
|
1089 | - $addon->setDomain($domain); |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * load_pue_update - Update notifications |
|
1097 | - * |
|
1098 | - * @return void |
|
1099 | - * @throws InvalidArgumentException |
|
1100 | - * @throws InvalidDataTypeException |
|
1101 | - * @throws InvalidInterfaceException |
|
1102 | - */ |
|
1103 | - public static function load_pue_update() |
|
1104 | - { |
|
1105 | - // load PUE client |
|
1106 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1107 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1108 | - // cycle thru settings |
|
1109 | - foreach (self::$_settings as $settings) { |
|
1110 | - if (! empty($settings['pue_options'])) { |
|
1111 | - // initiate the class and start the plugin update engine! |
|
1112 | - new PluginUpdateEngineChecker( |
|
1113 | - // host file URL |
|
1114 | - $license_server, |
|
1115 | - // plugin slug(s) |
|
1116 | - array( |
|
1117 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1118 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1119 | - ), |
|
1120 | - // options |
|
1121 | - array( |
|
1122 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1123 | - 'lang_domain' => 'event_espresso', |
|
1124 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1125 | - 'option_key' => 'ee_site_license_key', |
|
1126 | - 'options_page_slug' => 'event_espresso', |
|
1127 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1128 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1129 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1130 | - ) |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - } |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1139 | - * |
|
1140 | - * @since 4.4.0 |
|
1141 | - * @return void |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public static function register_message_types() |
|
1145 | - { |
|
1146 | - foreach (self::$_settings as $settings) { |
|
1147 | - if (! empty($settings['message_types'])) { |
|
1148 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1149 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1150 | - } |
|
1151 | - } |
|
1152 | - } |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1158 | - * |
|
1159 | - * @param string $addon_name the name for the addon that was previously registered |
|
1160 | - * @throws DomainException |
|
1161 | - * @throws InvalidArgumentException |
|
1162 | - * @throws InvalidDataTypeException |
|
1163 | - * @throws InvalidInterfaceException |
|
1164 | - *@since 4.3.0 |
|
1165 | - */ |
|
1166 | - public static function deregister($addon_name = '') |
|
1167 | - { |
|
1168 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1169 | - try { |
|
1170 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1171 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1172 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1173 | - // setup DMS |
|
1174 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1175 | - } |
|
1176 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1177 | - // register admin page |
|
1178 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1179 | - } |
|
1180 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1181 | - // add to list of modules to be registered |
|
1182 | - EE_Register_Module::deregister($addon_name); |
|
1183 | - } |
|
1184 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1185 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1186 | - ) { |
|
1187 | - // add to list of shortcodes to be registered |
|
1188 | - EE_Register_Shortcode::deregister($addon_name); |
|
1189 | - } |
|
1190 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1191 | - // if config_class present let's register config. |
|
1192 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1193 | - } |
|
1194 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1195 | - // add to list of widgets to be registered |
|
1196 | - EE_Register_Widget::deregister($addon_name); |
|
1197 | - } |
|
1198 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1199 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1200 | - ) { |
|
1201 | - // add to list of shortcodes to be registered |
|
1202 | - EE_Register_Model::deregister($addon_name); |
|
1203 | - } |
|
1204 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1205 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1206 | - ) { |
|
1207 | - // add to list of shortcodes to be registered |
|
1208 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1209 | - } |
|
1210 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1211 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1212 | - EE_Register_Message_Type::deregister($message_type); |
|
1213 | - } |
|
1214 | - } |
|
1215 | - // deregister capabilities for addon |
|
1216 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1217 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1218 | - ) { |
|
1219 | - EE_Register_Capabilities::deregister($addon_name); |
|
1220 | - } |
|
1221 | - // deregister custom_post_types for addon |
|
1222 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1223 | - EE_Register_CPT::deregister($addon_name); |
|
1224 | - } |
|
1225 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1226 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1227 | - } |
|
1228 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1229 | - if ($addon instanceof EE_Addon) { |
|
1230 | - remove_action( |
|
1231 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1232 | - array($addon, 'deactivation') |
|
1233 | - ); |
|
1234 | - remove_action( |
|
1235 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1236 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1237 | - ); |
|
1238 | - // remove `after_registration` call |
|
1239 | - remove_action( |
|
1240 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1241 | - array($addon, 'after_registration'), |
|
1242 | - 999 |
|
1243 | - ); |
|
1244 | - } |
|
1245 | - EE_Registry::instance()->removeAddon($class_name); |
|
1246 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1247 | - // the add-on was not yet registered in the registry, |
|
1248 | - // so RegistryContainer::__get() throws this exception. |
|
1249 | - // also no need to worry about this or log it, |
|
1250 | - // it's ok to deregister an add-on before its registered in the registry |
|
1251 | - } catch (Exception $e) { |
|
1252 | - new ExceptionLogger($e); |
|
1253 | - } |
|
1254 | - unset(self::$_settings[ $addon_name ]); |
|
1255 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1256 | - } |
|
1257 | - } |
|
25 | + /** |
|
26 | + * possibly truncated version of the EE core version string |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected static $_core_version = ''; |
|
31 | + |
|
32 | + /** |
|
33 | + * Holds values for registered addons |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected static $_settings = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | + * EE core with knowledge of ALL the addons out there. |
|
45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | + * minimum plugin version. |
|
49 | + * @access protected |
|
50 | + */ |
|
51 | + protected static $_incompatible_addons = array( |
|
52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | + 'Promotions' => '1.0.0.rc.084', |
|
54 | + ); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | + * not just '4.3.0'. |
|
60 | + * So if the addon developer doesn't provide that full version string, |
|
61 | + * fill in the blanks for them |
|
62 | + * |
|
63 | + * @param string $min_core_version |
|
64 | + * @return string always like '4.3.0.rc.000' |
|
65 | + */ |
|
66 | + protected static function _effective_version($min_core_version) |
|
67 | + { |
|
68 | + // versions: 4 . 3 . 1 . p . 123 |
|
69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | + $version_parts = explode('.', $min_core_version); |
|
71 | + // check they specified the micro version (after 2nd period) |
|
72 | + if (! isset($version_parts[2])) { |
|
73 | + $version_parts[2] = '0'; |
|
74 | + } |
|
75 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | + if (! isset($version_parts[3])) { |
|
78 | + $version_parts[3] = 'dev'; |
|
79 | + } |
|
80 | + if (! isset($version_parts[4])) { |
|
81 | + $version_parts[4] = '000'; |
|
82 | + } |
|
83 | + return implode('.', $version_parts); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns whether or not the min core version requirement of the addon is met |
|
89 | + * |
|
90 | + * @param string $min_core_version the minimum core version required by the addon |
|
91 | + * @param string $actual_core_version the actual core version, optional |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public static function _meets_min_core_version_requirement( |
|
95 | + $min_core_version, |
|
96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | + ) { |
|
98 | + return version_compare( |
|
99 | + self::_effective_version($actual_core_version), |
|
100 | + self::_effective_version($min_core_version), |
|
101 | + '>=' |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Method for registering new EE_Addons. |
|
108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | + * |
|
117 | + * @since 4.3.0 |
|
118 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | + * @param array $setup_args { |
|
120 | + * An array of arguments provided for registering |
|
121 | + * the message type. |
|
122 | + * @type string $class_name the addon's main file name. |
|
123 | + * If left blank, generated from the addon name, |
|
124 | + * changes something like "calendar" to |
|
125 | + * "EE_Calendar" |
|
126 | + * @type string $min_core_version the minimum version of EE Core that the |
|
127 | + * addon will work with. eg "4.8.1.rc.084" |
|
128 | + * @type string $version the "software" version for the addon. eg |
|
129 | + * "1.0.0.p" for a first stable release, or |
|
130 | + * "1.0.0.rc.043" for a version in progress |
|
131 | + * @type string $main_file_path the full server path to the main file |
|
132 | + * loaded directly by WP |
|
133 | + * @type DomainInterface $domain child class of |
|
134 | + * EventEspresso\core\domain\DomainBase |
|
135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | + * for the addon's Domain class |
|
137 | + * (see EventEspresso\core\domain\Domain) |
|
138 | + * @type string $admin_path full server path to the folder where the |
|
139 | + * addon\'s admin files reside |
|
140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | + * first invoked, can be used for hooking into |
|
142 | + * any admin page |
|
143 | + * @type string $config_section the section name for this addon's |
|
144 | + * configuration settings section |
|
145 | + * (defaults to "addons") |
|
146 | + * @type string $config_class the class name for this addon's |
|
147 | + * configuration settings object |
|
148 | + * @type string $config_name the class name for this addon's |
|
149 | + * configuration settings object |
|
150 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | + * server paths to those files. |
|
152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | + * folders containing classes that might be |
|
154 | + * invoked by the addon |
|
155 | + * @type string $dms_paths [Required] an array of full server paths to |
|
156 | + * folders that contain data migration scripts. |
|
157 | + * The key should be the EE_Addon class name that |
|
158 | + * this set of data migration scripts belongs to. |
|
159 | + * If the EE_Addon class is namespaced, then this |
|
160 | + * needs to be the Fully Qualified Class Name |
|
161 | + * @type string $module_paths an array of full server paths to any |
|
162 | + * EED_Modules used by the addon |
|
163 | + * @type string $shortcode_paths an array of full server paths to folders |
|
164 | + * that contain EES_Shortcodes |
|
165 | + * @type string $widget_paths an array of full server paths to folders |
|
166 | + * that contain WP_Widgets |
|
167 | + * @type string $pue_options |
|
168 | + * @type array $capabilities an array indexed by role name |
|
169 | + * (i.e administrator,author ) and the values |
|
170 | + * are an array of caps to add to the role. |
|
171 | + * 'administrator' => array( |
|
172 | + * 'read_addon', |
|
173 | + * 'edit_addon', |
|
174 | + * etc. |
|
175 | + * ). |
|
176 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | + * for any addons that need to register any |
|
178 | + * special meta mapped capabilities. Should |
|
179 | + * be indexed where the key is the |
|
180 | + * EE_Meta_Capability_Map class name and the |
|
181 | + * values are the arguments sent to the class. |
|
182 | + * @type array $model_paths array of folders containing DB models |
|
183 | + * @see EE_Register_Model |
|
184 | + * @type array $class_paths array of folders containing DB classes |
|
185 | + * @see EE_Register_Model |
|
186 | + * @type array $model_extension_paths array of folders containing DB model |
|
187 | + * extensions |
|
188 | + * @see EE_Register_Model_Extension |
|
189 | + * @type array $class_extension_paths array of folders containing DB class |
|
190 | + * extensions |
|
191 | + * @see EE_Register_Model_Extension |
|
192 | + * @type array message_types { |
|
193 | + * An array of message types with the key as |
|
194 | + * the message type name and the values as |
|
195 | + * below: |
|
196 | + * @type string $mtfilename [Required] The filename of the message type |
|
197 | + * being registered. This will be the main |
|
198 | + * EE_{Message Type Name}_message_type class. |
|
199 | + * for example: |
|
200 | + * EE_Declined_Registration_message_type.class.php |
|
201 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | + * messages autoloader for the new message type. |
|
203 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | + * type should activate with. Each value in |
|
205 | + * the |
|
206 | + * array |
|
207 | + * should match the name property of a |
|
208 | + * EE_messenger. Optional. |
|
209 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | + * type should validate with. Each value in |
|
211 | + * the |
|
212 | + * array |
|
213 | + * should match the name property of an |
|
214 | + * EE_messenger. |
|
215 | + * Optional. |
|
216 | + * } |
|
217 | + * @type array $custom_post_types |
|
218 | + * @type array $custom_taxonomies |
|
219 | + * @type array $payment_method_paths each element is the folder containing the |
|
220 | + * EE_PMT_Base child class |
|
221 | + * (eg, |
|
222 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | + * which contains the files |
|
224 | + * EE_PMT_Payomatic.pm.php) |
|
225 | + * @type array $default_terms |
|
226 | + * @type array $namespace { |
|
227 | + * An array with two items for registering the |
|
228 | + * addon's namespace. (If, for some reason, you |
|
229 | + * require additional namespaces, |
|
230 | + * use |
|
231 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | + * directly) |
|
233 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | + * @type string $FQNS the namespace prefix |
|
235 | + * @type string $DIR a base directory for class files in the |
|
236 | + * namespace. |
|
237 | + * } |
|
238 | + * } |
|
239 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | + * privacy policy classes) or FQCNs (specific |
|
241 | + * classnames of privacy policy classes) |
|
242 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | + * privacy policy classes) or FQCNs (specific |
|
244 | + * classnames of privacy policy classes) |
|
245 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | + * privacy policy classes) or FQCNs (specific |
|
247 | + * classnames of privacy policy classes) |
|
248 | + * @return void |
|
249 | + * @throws DomainException |
|
250 | + * @throws EE_Error |
|
251 | + * @throws InvalidArgumentException |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws InvalidInterfaceException |
|
254 | + */ |
|
255 | + public static function register($addon_name = '', array $setup_args = array()) |
|
256 | + { |
|
257 | + // required fields MUST be present, so let's make sure they are. |
|
258 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
259 | + // get class name for addon |
|
260 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
261 | + // setup $_settings array from incoming values. |
|
262 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
263 | + // setup PUE |
|
264 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
265 | + // does this addon work with this version of core or WordPress ? |
|
266 | + // does this addon work with this version of core or WordPress ? |
|
267 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | + return; |
|
269 | + } |
|
270 | + // register namespaces |
|
271 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | + // check if this is an activation request |
|
273 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | + // dont bother setting up the rest of the addon atm |
|
275 | + return; |
|
276 | + } |
|
277 | + // we need cars |
|
278 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | + // register new models and extensions |
|
280 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | + // setup DMS |
|
282 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | + // if config_class is present let's register config. |
|
284 | + EE_Register_Addon::_register_config($addon_name); |
|
285 | + // register admin pages |
|
286 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | + // add to list of modules to be registered |
|
288 | + EE_Register_Addon::_register_modules($addon_name); |
|
289 | + // add to list of shortcodes to be registered |
|
290 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | + // add to list of widgets to be registered |
|
292 | + EE_Register_Addon::_register_widgets($addon_name); |
|
293 | + // register capability related stuff. |
|
294 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | + // any message type to register? |
|
296 | + EE_Register_Addon::_register_message_types($addon_name); |
|
297 | + // any custom post type/ custom capabilities or default terms to register |
|
298 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | + // and any payment methods |
|
300 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | + // and privacy policy generators |
|
302 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | + // and privacy policy generators |
|
304 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | + // and privacy policy generators |
|
306 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | + // load and instantiate main addon class |
|
308 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $addon_name |
|
316 | + * @param array $setup_args |
|
317 | + * @return void |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + // required fields MUST be present, so let's make sure they are. |
|
323 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | + throw new EE_Error( |
|
325 | + __( |
|
326 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | + 'event_espresso' |
|
328 | + ) |
|
329 | + ); |
|
330 | + } |
|
331 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | + throw new EE_Error( |
|
333 | + sprintf( |
|
334 | + __( |
|
335 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + implode(',', array_keys($setup_args)) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + // check that addon has not already been registered with that name |
|
343 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | + throw new EE_Error( |
|
345 | + sprintf( |
|
346 | + __( |
|
347 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + $addon_name |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $addon_name |
|
359 | + * @param array $setup_args |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | + { |
|
364 | + if (empty($setup_args['class_name'])) { |
|
365 | + // generate one by first separating name with spaces |
|
366 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | + // capitalize, then replace spaces with underscores |
|
368 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | + } else { |
|
370 | + $class_name = $setup_args['class_name']; |
|
371 | + } |
|
372 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | + ? $class_name |
|
375 | + : 'EE_' . $class_name; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @param string $class_name |
|
381 | + * @param array $setup_args |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | + { |
|
386 | + // setup $_settings array from incoming values. |
|
387 | + $addon_settings = array( |
|
388 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | + 'class_name' => $class_name, |
|
390 | + // the addon slug for use in URLs, etc |
|
391 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | + ? (string) $setup_args['plugin_slug'] |
|
393 | + : '', |
|
394 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | + ? (string) $setup_args['plugin_action_slug'] |
|
397 | + : '', |
|
398 | + // the "software" version for the addon |
|
399 | + 'version' => isset($setup_args['version']) |
|
400 | + ? (string) $setup_args['version'] |
|
401 | + : '', |
|
402 | + // the minimum version of EE Core that the addon will work with |
|
403 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | + ? (string) $setup_args['min_core_version'] |
|
405 | + : '', |
|
406 | + // the minimum version of WordPress that the addon will work with |
|
407 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | + ? (string) $setup_args['min_wp_version'] |
|
409 | + : EE_MIN_WP_VER_REQUIRED, |
|
410 | + // full server path to main file (file loaded directly by WP) |
|
411 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | + ? (string) $setup_args['main_file_path'] |
|
413 | + : '', |
|
414 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | + ? $setup_args['domain'] |
|
417 | + : null, |
|
418 | + // Fully Qualified Class Name for the addon's Domain class |
|
419 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | + ? (string) $setup_args['domain_fqcn'] |
|
421 | + : '', |
|
422 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | + 'admin_path' => isset($setup_args['admin_path']) |
|
424 | + ? (string) $setup_args['admin_path'] : '', |
|
425 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | + ? (string) $setup_args['admin_callback'] |
|
428 | + : '', |
|
429 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | + 'config_section' => isset($setup_args['config_section']) |
|
431 | + ? (string) $setup_args['config_section'] |
|
432 | + : 'addons', |
|
433 | + // the class name for this addon's configuration settings object |
|
434 | + 'config_class' => isset($setup_args['config_class']) |
|
435 | + ? (string) $setup_args['config_class'] : '', |
|
436 | + // the name given to the config for this addons' configuration settings object (optional) |
|
437 | + 'config_name' => isset($setup_args['config_name']) |
|
438 | + ? (string) $setup_args['config_name'] : '', |
|
439 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | + ? (array) $setup_args['autoloader_paths'] |
|
442 | + : array(), |
|
443 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | + ? (array) $setup_args['autoloader_folders'] |
|
446 | + : array(), |
|
447 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | + ? (array) $setup_args['dms_paths'] |
|
452 | + : array(), |
|
453 | + // array of full server paths to any EED_Modules used by the addon |
|
454 | + 'module_paths' => isset($setup_args['module_paths']) |
|
455 | + ? (array) $setup_args['module_paths'] |
|
456 | + : array(), |
|
457 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | + ? (array) $setup_args['shortcode_paths'] |
|
460 | + : array(), |
|
461 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | + ? (array) $setup_args['shortcode_fqcns'] |
|
463 | + : array(), |
|
464 | + // array of full server paths to any WP_Widgets used by the addon |
|
465 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | + ? (array) $setup_args['widget_paths'] |
|
467 | + : array(), |
|
468 | + // array of PUE options used by the addon |
|
469 | + 'pue_options' => isset($setup_args['pue_options']) |
|
470 | + ? (array) $setup_args['pue_options'] |
|
471 | + : array(), |
|
472 | + 'message_types' => isset($setup_args['message_types']) |
|
473 | + ? (array) $setup_args['message_types'] |
|
474 | + : array(), |
|
475 | + 'capabilities' => isset($setup_args['capabilities']) |
|
476 | + ? (array) $setup_args['capabilities'] |
|
477 | + : array(), |
|
478 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | + ? (array) $setup_args['capability_maps'] |
|
480 | + : array(), |
|
481 | + 'model_paths' => isset($setup_args['model_paths']) |
|
482 | + ? (array) $setup_args['model_paths'] |
|
483 | + : array(), |
|
484 | + 'class_paths' => isset($setup_args['class_paths']) |
|
485 | + ? (array) $setup_args['class_paths'] |
|
486 | + : array(), |
|
487 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | + ? (array) $setup_args['model_extension_paths'] |
|
489 | + : array(), |
|
490 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | + ? (array) $setup_args['class_extension_paths'] |
|
492 | + : array(), |
|
493 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | + ? (array) $setup_args['custom_post_types'] |
|
495 | + : array(), |
|
496 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | + ? (array) $setup_args['custom_taxonomies'] |
|
498 | + : array(), |
|
499 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | + ? (array) $setup_args['payment_method_paths'] |
|
501 | + : array(), |
|
502 | + 'default_terms' => isset($setup_args['default_terms']) |
|
503 | + ? (array) $setup_args['default_terms'] |
|
504 | + : array(), |
|
505 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | + // that can be used for adding upgrading/marketing info |
|
507 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
508 | + 'namespace' => isset( |
|
509 | + $setup_args['namespace']['FQNS'], |
|
510 | + $setup_args['namespace']['DIR'] |
|
511 | + ) |
|
512 | + ? (array) $setup_args['namespace'] |
|
513 | + : array(), |
|
514 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
515 | + ? (array) $setup_args['privacy_policies'] |
|
516 | + : '', |
|
517 | + ); |
|
518 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
519 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
520 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
521 | + && ! empty($addon_settings['admin_path']) |
|
522 | + ? $addon_settings['plugin_slug'] |
|
523 | + : $addon_settings['plugin_action_slug']; |
|
524 | + // full server path to main file (file loaded directly by WP) |
|
525 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
526 | + return $addon_settings; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param string $addon_name |
|
532 | + * @param array $addon_settings |
|
533 | + * @return boolean |
|
534 | + */ |
|
535 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
536 | + { |
|
537 | + global $wp_version; |
|
538 | + $incompatibility_message = ''; |
|
539 | + // check whether this addon version is compatible with EE core |
|
540 | + if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
541 | + && ! self::_meets_min_core_version_requirement( |
|
542 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
543 | + $addon_settings['version'] |
|
544 | + ) |
|
545 | + ) { |
|
546 | + $incompatibility_message = sprintf( |
|
547 | + __( |
|
548 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
549 | + 'event_espresso' |
|
550 | + ), |
|
551 | + $addon_name, |
|
552 | + '<br />', |
|
553 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
554 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
555 | + '</span><br />' |
|
556 | + ); |
|
557 | + } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
558 | + ) { |
|
559 | + $incompatibility_message = sprintf( |
|
560 | + __( |
|
561 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
562 | + 'event_espresso' |
|
563 | + ), |
|
564 | + $addon_name, |
|
565 | + self::_effective_version($addon_settings['min_core_version']), |
|
566 | + self::_effective_version(espresso_version()), |
|
567 | + '<br />', |
|
568 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
569 | + '</span><br />' |
|
570 | + ); |
|
571 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
572 | + $incompatibility_message = sprintf( |
|
573 | + __( |
|
574 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
575 | + 'event_espresso' |
|
576 | + ), |
|
577 | + $addon_name, |
|
578 | + $addon_settings['min_wp_version'], |
|
579 | + '<br />', |
|
580 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
581 | + '</span><br />' |
|
582 | + ); |
|
583 | + } |
|
584 | + if (! empty($incompatibility_message)) { |
|
585 | + // remove 'activate' from the REQUEST |
|
586 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
587 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
588 | + if (current_user_can('activate_plugins')) { |
|
589 | + // show an error message indicating the plugin didn't activate properly |
|
590 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
591 | + } |
|
592 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
593 | + return false; |
|
594 | + } |
|
595 | + // addon IS compatible |
|
596 | + return true; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * if plugin update engine is being used for auto-updates, |
|
602 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
603 | + * (not needed if PUE is not being used) |
|
604 | + * |
|
605 | + * @param string $addon_name |
|
606 | + * @param string $class_name |
|
607 | + * @param array $setup_args |
|
608 | + * @return void |
|
609 | + */ |
|
610 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
611 | + { |
|
612 | + if (! empty($setup_args['pue_options'])) { |
|
613 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
614 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
615 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
616 | + : 'espresso_' . strtolower($class_name), |
|
617 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
618 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
619 | + : plugin_basename($setup_args['main_file_path']), |
|
620 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
621 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
622 | + : '24', |
|
623 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
624 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
625 | + : false, |
|
626 | + ); |
|
627 | + add_action( |
|
628 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
629 | + array('EE_Register_Addon', 'load_pue_update') |
|
630 | + ); |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
637 | + * |
|
638 | + * @param array $addon_settings |
|
639 | + * @return void |
|
640 | + */ |
|
641 | + private static function _setup_namespaces(array $addon_settings) |
|
642 | + { |
|
643 | + // |
|
644 | + if (isset( |
|
645 | + $addon_settings['namespace']['FQNS'], |
|
646 | + $addon_settings['namespace']['DIR'] |
|
647 | + )) { |
|
648 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
649 | + $addon_settings['namespace']['FQNS'], |
|
650 | + $addon_settings['namespace']['DIR'] |
|
651 | + ); |
|
652 | + } |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @param string $addon_name |
|
658 | + * @param array $addon_settings |
|
659 | + * @return bool |
|
660 | + * @throws InvalidArgumentException |
|
661 | + * @throws InvalidDataTypeException |
|
662 | + * @throws InvalidInterfaceException |
|
663 | + */ |
|
664 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
665 | + { |
|
666 | + // this is an activation request |
|
667 | + if (did_action('activate_plugin')) { |
|
668 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
669 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
670 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
671 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
672 | + if (! isset(self::$_settings[ $addon_name ]) |
|
673 | + || (isset(self::$_settings[ $addon_name ]) |
|
674 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
675 | + ) |
|
676 | + ) { |
|
677 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
678 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
679 | + $addon->set_activation_indicator_option(); |
|
680 | + // dont bother setting up the rest of the addon. |
|
681 | + // we know it was just activated and the request will end soon |
|
682 | + } |
|
683 | + return true; |
|
684 | + } |
|
685 | + // make sure this was called in the right place! |
|
686 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
687 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
688 | + ) { |
|
689 | + EE_Error::doing_it_wrong( |
|
690 | + __METHOD__, |
|
691 | + sprintf( |
|
692 | + __( |
|
693 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
694 | + 'event_espresso' |
|
695 | + ), |
|
696 | + $addon_name |
|
697 | + ), |
|
698 | + '4.3.0' |
|
699 | + ); |
|
700 | + } |
|
701 | + // make sure addon settings are set correctly without overwriting anything existing |
|
702 | + if (isset(self::$_settings[ $addon_name ])) { |
|
703 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | + } else { |
|
705 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | + } |
|
707 | + return false; |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * @param string $addon_name |
|
713 | + * @return void |
|
714 | + * @throws EE_Error |
|
715 | + */ |
|
716 | + private static function _setup_autoloaders($addon_name) |
|
717 | + { |
|
718 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | + // setup autoloader for single file |
|
720 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | + } |
|
722 | + // setup autoloaders for folders |
|
723 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | + } |
|
727 | + } |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * register new models and extensions |
|
733 | + * |
|
734 | + * @param string $addon_name |
|
735 | + * @return void |
|
736 | + * @throws EE_Error |
|
737 | + */ |
|
738 | + private static function _register_models_and_extensions($addon_name) |
|
739 | + { |
|
740 | + // register new models |
|
741 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
742 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
743 | + ) { |
|
744 | + EE_Register_Model::register( |
|
745 | + $addon_name, |
|
746 | + array( |
|
747 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
748 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
749 | + ) |
|
750 | + ); |
|
751 | + } |
|
752 | + // register model extensions |
|
753 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
754 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
755 | + ) { |
|
756 | + EE_Register_Model_Extensions::register( |
|
757 | + $addon_name, |
|
758 | + array( |
|
759 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
760 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
761 | + ) |
|
762 | + ); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * @param string $addon_name |
|
769 | + * @return void |
|
770 | + * @throws EE_Error |
|
771 | + */ |
|
772 | + private static function _register_data_migration_scripts($addon_name) |
|
773 | + { |
|
774 | + // setup DMS |
|
775 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
776 | + EE_Register_Data_Migration_Scripts::register( |
|
777 | + $addon_name, |
|
778 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
779 | + ); |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + |
|
784 | + /** |
|
785 | + * @param string $addon_name |
|
786 | + * @return void |
|
787 | + * @throws EE_Error |
|
788 | + */ |
|
789 | + private static function _register_config($addon_name) |
|
790 | + { |
|
791 | + // if config_class is present let's register config. |
|
792 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
793 | + EE_Register_Config::register( |
|
794 | + self::$_settings[ $addon_name ]['config_class'], |
|
795 | + array( |
|
796 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
797 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
798 | + ) |
|
799 | + ); |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * @param string $addon_name |
|
806 | + * @return void |
|
807 | + * @throws EE_Error |
|
808 | + */ |
|
809 | + private static function _register_admin_pages($addon_name) |
|
810 | + { |
|
811 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
812 | + EE_Register_Admin_Page::register( |
|
813 | + $addon_name, |
|
814 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
815 | + ); |
|
816 | + } |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * @param string $addon_name |
|
822 | + * @return void |
|
823 | + * @throws EE_Error |
|
824 | + */ |
|
825 | + private static function _register_modules($addon_name) |
|
826 | + { |
|
827 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
828 | + EE_Register_Module::register( |
|
829 | + $addon_name, |
|
830 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
831 | + ); |
|
832 | + } |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * @param string $addon_name |
|
838 | + * @return void |
|
839 | + * @throws EE_Error |
|
840 | + */ |
|
841 | + private static function _register_shortcodes($addon_name) |
|
842 | + { |
|
843 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
844 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
845 | + ) { |
|
846 | + EE_Register_Shortcode::register( |
|
847 | + $addon_name, |
|
848 | + array( |
|
849 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
850 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
851 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
852 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
853 | + ) |
|
854 | + ); |
|
855 | + } |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * @param string $addon_name |
|
861 | + * @return void |
|
862 | + * @throws EE_Error |
|
863 | + */ |
|
864 | + private static function _register_widgets($addon_name) |
|
865 | + { |
|
866 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
867 | + EE_Register_Widget::register( |
|
868 | + $addon_name, |
|
869 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
870 | + ); |
|
871 | + } |
|
872 | + } |
|
873 | + |
|
874 | + |
|
875 | + /** |
|
876 | + * @param string $addon_name |
|
877 | + * @return void |
|
878 | + * @throws EE_Error |
|
879 | + */ |
|
880 | + private static function _register_capabilities($addon_name) |
|
881 | + { |
|
882 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
883 | + EE_Register_Capabilities::register( |
|
884 | + $addon_name, |
|
885 | + array( |
|
886 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
887 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
888 | + ) |
|
889 | + ); |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * @param string $addon_name |
|
896 | + * @return void |
|
897 | + */ |
|
898 | + private static function _register_message_types($addon_name) |
|
899 | + { |
|
900 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
901 | + add_action( |
|
902 | + 'EE_Brewing_Regular___messages_caf', |
|
903 | + array('EE_Register_Addon', 'register_message_types') |
|
904 | + ); |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param string $addon_name |
|
911 | + * @return void |
|
912 | + * @throws EE_Error |
|
913 | + */ |
|
914 | + private static function _register_custom_post_types($addon_name) |
|
915 | + { |
|
916 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
917 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
918 | + ) { |
|
919 | + EE_Register_CPT::register( |
|
920 | + $addon_name, |
|
921 | + array( |
|
922 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
923 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
924 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
925 | + ) |
|
926 | + ); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * @param string $addon_name |
|
933 | + * @return void |
|
934 | + * @throws InvalidArgumentException |
|
935 | + * @throws InvalidInterfaceException |
|
936 | + * @throws InvalidDataTypeException |
|
937 | + * @throws DomainException |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + private static function _register_payment_methods($addon_name) |
|
941 | + { |
|
942 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
943 | + EE_Register_Payment_Method::register( |
|
944 | + $addon_name, |
|
945 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
946 | + ); |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * @param string $addon_name |
|
953 | + * @return void |
|
954 | + * @throws InvalidArgumentException |
|
955 | + * @throws InvalidInterfaceException |
|
956 | + * @throws InvalidDataTypeException |
|
957 | + * @throws DomainException |
|
958 | + */ |
|
959 | + private static function registerPrivacyPolicies($addon_name) |
|
960 | + { |
|
961 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
962 | + EE_Register_Privacy_Policy::register( |
|
963 | + $addon_name, |
|
964 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
965 | + ); |
|
966 | + } |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * @param string $addon_name |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + private static function registerPersonalDataExporters($addon_name) |
|
975 | + { |
|
976 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
977 | + EE_Register_Personal_Data_Eraser::register( |
|
978 | + $addon_name, |
|
979 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
980 | + ); |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @param string $addon_name |
|
987 | + * @return void |
|
988 | + */ |
|
989 | + private static function registerPersonalDataErasers($addon_name) |
|
990 | + { |
|
991 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
992 | + EE_Register_Personal_Data_Eraser::register( |
|
993 | + $addon_name, |
|
994 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
995 | + ); |
|
996 | + } |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + /** |
|
1001 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1002 | + * |
|
1003 | + * @param string $addon_name |
|
1004 | + * @return EE_Addon |
|
1005 | + * @throws InvalidArgumentException |
|
1006 | + * @throws InvalidInterfaceException |
|
1007 | + * @throws InvalidDataTypeException |
|
1008 | + */ |
|
1009 | + private static function _load_and_init_addon_class($addon_name) |
|
1010 | + { |
|
1011 | + $addon = LoaderFactory::getLoader()->getShared( |
|
1012 | + self::$_settings[ $addon_name ]['class_name'], |
|
1013 | + array('EE_Registry::create(addon)' => true) |
|
1014 | + ); |
|
1015 | + if (! $addon instanceof EE_Addon) { |
|
1016 | + throw new DomainException( |
|
1017 | + sprintf( |
|
1018 | + esc_html__( |
|
1019 | + 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
1020 | + 'event_espresso' |
|
1021 | + ), |
|
1022 | + $addon_name |
|
1023 | + ) |
|
1024 | + ); |
|
1025 | + } |
|
1026 | + // setter inject dep map if required |
|
1027 | + if ($addon->dependencyMap() === null) { |
|
1028 | + $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
1029 | + } |
|
1030 | + // setter inject domain if required |
|
1031 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1032 | + |
|
1033 | + $addon->set_name($addon_name); |
|
1034 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1035 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1036 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1037 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1038 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1039 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1040 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1041 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1042 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1043 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1044 | + // setup the add-on's pue_slug if we have one. |
|
1045 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1046 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1047 | + } |
|
1048 | + // unfortunately this can't be hooked in upon construction, |
|
1049 | + // because we don't have the plugin's mainfile path upon construction. |
|
1050 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1051 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1052 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1053 | + add_action( |
|
1054 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1055 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + return $addon; |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * @param string $addon_name |
|
1064 | + * @param EE_Addon $addon |
|
1065 | + * @since 4.10.13.p |
|
1066 | + */ |
|
1067 | + private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
1068 | + { |
|
1069 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1070 | + // using supplied Domain object |
|
1071 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1072 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1073 | + : null; |
|
1074 | + // or construct one using Domain FQCN |
|
1075 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1076 | + $domain = LoaderFactory::getLoader()->getShared( |
|
1077 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1078 | + [ |
|
1079 | + new EventEspresso\core\domain\values\FilePath( |
|
1080 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1081 | + ), |
|
1082 | + EventEspresso\core\domain\values\Version::fromString( |
|
1083 | + self::$_settings[ $addon_name ]['version'] |
|
1084 | + ), |
|
1085 | + ] |
|
1086 | + ); |
|
1087 | + } |
|
1088 | + if ($domain instanceof DomainInterface) { |
|
1089 | + $addon->setDomain($domain); |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * load_pue_update - Update notifications |
|
1097 | + * |
|
1098 | + * @return void |
|
1099 | + * @throws InvalidArgumentException |
|
1100 | + * @throws InvalidDataTypeException |
|
1101 | + * @throws InvalidInterfaceException |
|
1102 | + */ |
|
1103 | + public static function load_pue_update() |
|
1104 | + { |
|
1105 | + // load PUE client |
|
1106 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1107 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1108 | + // cycle thru settings |
|
1109 | + foreach (self::$_settings as $settings) { |
|
1110 | + if (! empty($settings['pue_options'])) { |
|
1111 | + // initiate the class and start the plugin update engine! |
|
1112 | + new PluginUpdateEngineChecker( |
|
1113 | + // host file URL |
|
1114 | + $license_server, |
|
1115 | + // plugin slug(s) |
|
1116 | + array( |
|
1117 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1118 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1119 | + ), |
|
1120 | + // options |
|
1121 | + array( |
|
1122 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1123 | + 'lang_domain' => 'event_espresso', |
|
1124 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1125 | + 'option_key' => 'ee_site_license_key', |
|
1126 | + 'options_page_slug' => 'event_espresso', |
|
1127 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1128 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1129 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1130 | + ) |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + } |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1139 | + * |
|
1140 | + * @since 4.4.0 |
|
1141 | + * @return void |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public static function register_message_types() |
|
1145 | + { |
|
1146 | + foreach (self::$_settings as $settings) { |
|
1147 | + if (! empty($settings['message_types'])) { |
|
1148 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1149 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1150 | + } |
|
1151 | + } |
|
1152 | + } |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1158 | + * |
|
1159 | + * @param string $addon_name the name for the addon that was previously registered |
|
1160 | + * @throws DomainException |
|
1161 | + * @throws InvalidArgumentException |
|
1162 | + * @throws InvalidDataTypeException |
|
1163 | + * @throws InvalidInterfaceException |
|
1164 | + *@since 4.3.0 |
|
1165 | + */ |
|
1166 | + public static function deregister($addon_name = '') |
|
1167 | + { |
|
1168 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1169 | + try { |
|
1170 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1171 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1172 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1173 | + // setup DMS |
|
1174 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1175 | + } |
|
1176 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1177 | + // register admin page |
|
1178 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1179 | + } |
|
1180 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1181 | + // add to list of modules to be registered |
|
1182 | + EE_Register_Module::deregister($addon_name); |
|
1183 | + } |
|
1184 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1185 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1186 | + ) { |
|
1187 | + // add to list of shortcodes to be registered |
|
1188 | + EE_Register_Shortcode::deregister($addon_name); |
|
1189 | + } |
|
1190 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1191 | + // if config_class present let's register config. |
|
1192 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1193 | + } |
|
1194 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1195 | + // add to list of widgets to be registered |
|
1196 | + EE_Register_Widget::deregister($addon_name); |
|
1197 | + } |
|
1198 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1199 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1200 | + ) { |
|
1201 | + // add to list of shortcodes to be registered |
|
1202 | + EE_Register_Model::deregister($addon_name); |
|
1203 | + } |
|
1204 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1205 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1206 | + ) { |
|
1207 | + // add to list of shortcodes to be registered |
|
1208 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1209 | + } |
|
1210 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1211 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1212 | + EE_Register_Message_Type::deregister($message_type); |
|
1213 | + } |
|
1214 | + } |
|
1215 | + // deregister capabilities for addon |
|
1216 | + if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1217 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1218 | + ) { |
|
1219 | + EE_Register_Capabilities::deregister($addon_name); |
|
1220 | + } |
|
1221 | + // deregister custom_post_types for addon |
|
1222 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1223 | + EE_Register_CPT::deregister($addon_name); |
|
1224 | + } |
|
1225 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1226 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1227 | + } |
|
1228 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1229 | + if ($addon instanceof EE_Addon) { |
|
1230 | + remove_action( |
|
1231 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1232 | + array($addon, 'deactivation') |
|
1233 | + ); |
|
1234 | + remove_action( |
|
1235 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1236 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1237 | + ); |
|
1238 | + // remove `after_registration` call |
|
1239 | + remove_action( |
|
1240 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1241 | + array($addon, 'after_registration'), |
|
1242 | + 999 |
|
1243 | + ); |
|
1244 | + } |
|
1245 | + EE_Registry::instance()->removeAddon($class_name); |
|
1246 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1247 | + // the add-on was not yet registered in the registry, |
|
1248 | + // so RegistryContainer::__get() throws this exception. |
|
1249 | + // also no need to worry about this or log it, |
|
1250 | + // it's ok to deregister an add-on before its registered in the registry |
|
1251 | + } catch (Exception $e) { |
|
1252 | + new ExceptionLogger($e); |
|
1253 | + } |
|
1254 | + unset(self::$_settings[ $addon_name ]); |
|
1255 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1256 | + } |
|
1257 | + } |
|
1258 | 1258 | } |
@@ -13,368 +13,368 @@ |
||
13 | 13 | final class EE_Request_Handler implements InterminableInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var RequestInterface $request |
|
18 | - */ |
|
19 | - private $request; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var array $_notice |
|
23 | - */ |
|
24 | - private $_notice = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * rendered output to be returned to WP |
|
28 | - * |
|
29 | - * @var string $_output |
|
30 | - */ |
|
31 | - private $_output = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * whether current request is via AJAX |
|
35 | - * |
|
36 | - * @var boolean $ajax |
|
37 | - */ |
|
38 | - public $ajax = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * whether current request is via AJAX from the frontend of the site |
|
42 | - * |
|
43 | - * @var boolean $front_ajax |
|
44 | - */ |
|
45 | - public $front_ajax = false; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param RequestInterface $request |
|
50 | - */ |
|
51 | - public function __construct(RequestInterface $request) |
|
52 | - { |
|
53 | - $this->request = $request; |
|
54 | - $this->ajax = $this->request->isAjax(); |
|
55 | - $this->front_ajax = $this->request->isFrontAjax(); |
|
56 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param WP $wp |
|
62 | - * @return void |
|
63 | - * @throws EE_Error |
|
64 | - * @throws ReflectionException |
|
65 | - */ |
|
66 | - public function parse_request($wp = null) |
|
67 | - { |
|
68 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
69 | - if (! $wp instanceof WP) { |
|
70 | - global $wp; |
|
71 | - } |
|
72 | - $this->set_request_vars($wp); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param WP $wp |
|
78 | - * @return void |
|
79 | - * @throws EE_Error |
|
80 | - * @throws ReflectionException |
|
81 | - */ |
|
82 | - public function set_request_vars($wp = null) |
|
83 | - { |
|
84 | - if (! is_admin()) { |
|
85 | - // set request post_id |
|
86 | - $this->request->setRequestParam('post_id', $this->get_post_id_from_request($wp)); |
|
87 | - // set request post name |
|
88 | - $this->request->setRequestParam('post_name', $this->get_post_name_from_request($wp)); |
|
89 | - // set request post_type |
|
90 | - $this->request->setRequestParam('post_type', $this->get_post_type_from_request($wp)); |
|
91 | - // true or false ? is this page being used by EE ? |
|
92 | - $this->set_espresso_page(); |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param WP $wp |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - public function get_post_id_from_request($wp = null) |
|
102 | - { |
|
103 | - if (! $wp instanceof WP) { |
|
104 | - global $wp; |
|
105 | - } |
|
106 | - $post_id = null; |
|
107 | - if (isset($wp->query_vars['p'])) { |
|
108 | - $post_id = $wp->query_vars['p']; |
|
109 | - } |
|
110 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
111 | - $post_id = $wp->query_vars['page_id']; |
|
112 | - } |
|
113 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
114 | - $post_id = basename($wp->request); |
|
115 | - } |
|
116 | - return $post_id; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param WP $wp |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function get_post_name_from_request($wp = null) |
|
125 | - { |
|
126 | - global $wpdb; |
|
127 | - if (! $wp instanceof WP) { |
|
128 | - global $wp; |
|
129 | - } |
|
130 | - $post_name = null; |
|
131 | - if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
132 | - $post_name = $wp->query_vars['name']; |
|
133 | - } |
|
134 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
135 | - $post_name = $wp->query_vars['pagename']; |
|
136 | - } |
|
137 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
138 | - $possible_post_name = basename($wp->request); |
|
139 | - if (! is_numeric($possible_post_name)) { |
|
140 | - $SQL = "SELECT ID from {$wpdb->posts}"; |
|
141 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
142 | - $SQL .= " AND post_name=%s"; |
|
143 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
144 | - if ($possible_post_name) { |
|
145 | - $post_name = $possible_post_name; |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - if (! $post_name && $this->get('post_id')) { |
|
150 | - $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
151 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
152 | - $SQL .= " AND ID=%d"; |
|
153 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
154 | - if ($possible_post_name) { |
|
155 | - $post_name = $possible_post_name; |
|
156 | - } |
|
157 | - } |
|
158 | - return $post_name; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param WP $wp |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - public function get_post_type_from_request($wp = null) |
|
167 | - { |
|
168 | - if (! $wp instanceof WP) { |
|
169 | - global $wp; |
|
170 | - } |
|
171 | - return isset($wp->query_vars['post_type']) |
|
172 | - ? $wp->query_vars['post_type'] |
|
173 | - : null; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Just a helper method for getting the url for the displayed page. |
|
179 | - * |
|
180 | - * @param WP $wp |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function get_current_page_permalink($wp = null) |
|
184 | - { |
|
185 | - $post_id = $this->get_post_id_from_request($wp); |
|
186 | - if ($post_id) { |
|
187 | - $current_page_permalink = get_permalink($post_id); |
|
188 | - } else { |
|
189 | - if (! $wp instanceof WP) { |
|
190 | - global $wp; |
|
191 | - } |
|
192 | - if ($wp->request) { |
|
193 | - $current_page_permalink = site_url($wp->request); |
|
194 | - } else { |
|
195 | - $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
196 | - } |
|
197 | - } |
|
198 | - return $current_page_permalink; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return bool |
|
204 | - * @throws EE_Error |
|
205 | - * @throws ReflectionException |
|
206 | - */ |
|
207 | - public function test_for_espresso_page() |
|
208 | - { |
|
209 | - global $wp; |
|
210 | - /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
211 | - $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
212 | - $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
213 | - if (is_array($espresso_CPT_taxonomies)) { |
|
214 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
216 | - return true; |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
220 | - // load espresso CPT endpoints |
|
221 | - $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
222 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
223 | - $post_types = (array) $this->get('post_type'); |
|
224 | - foreach ($post_types as $post_type) { |
|
225 | - // was a post name passed ? |
|
226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
227 | - // kk we know this is an espresso page, but is it a specific post ? |
|
228 | - if (! $this->get('post_name')) { |
|
229 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
232 | - : ''; |
|
233 | - // if the post type matches on of our then set the endpoint |
|
234 | - if ($post_name) { |
|
235 | - $this->set('post_name', $post_name); |
|
236 | - } |
|
237 | - } |
|
238 | - return true; |
|
239 | - } |
|
240 | - } |
|
241 | - return false; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @param $key |
|
246 | - * @param $value |
|
247 | - * @return void |
|
248 | - */ |
|
249 | - public function set_notice($key, $value) |
|
250 | - { |
|
251 | - $this->_notice[ $key ] = $value; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param $key |
|
257 | - * @return mixed |
|
258 | - */ |
|
259 | - public function get_notice($key) |
|
260 | - { |
|
261 | - return isset($this->_notice[ $key ]) |
|
262 | - ? $this->_notice[ $key ] |
|
263 | - : null; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @param $string |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function add_output($string) |
|
272 | - { |
|
273 | - $this->_output .= $string; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function get_output() |
|
281 | - { |
|
282 | - return $this->_output; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $item |
|
288 | - * @param $key |
|
289 | - */ |
|
290 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
291 | - { |
|
292 | - $item = strpos($item, 'email') !== false |
|
293 | - ? sanitize_email($item) |
|
294 | - : sanitize_text_field($item); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @param null|bool $value |
|
300 | - * @return void |
|
301 | - * @throws EE_Error |
|
302 | - * @throws ReflectionException |
|
303 | - */ |
|
304 | - public function set_espresso_page($value = null) |
|
305 | - { |
|
306 | - $this->request->setRequestParam( |
|
307 | - 'is_espresso_page', |
|
308 | - ! empty($value) |
|
309 | - ? $value |
|
310 | - : $this->test_for_espresso_page() |
|
311 | - ); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @return bool |
|
317 | - */ |
|
318 | - public function is_espresso_page() |
|
319 | - { |
|
320 | - return $this->request->requestParamIsSet('is_espresso_page'); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * returns contents of $_REQUEST |
|
326 | - * |
|
327 | - * @return array |
|
328 | - */ |
|
329 | - public function params() |
|
330 | - { |
|
331 | - return $this->request->requestParams(); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param $key |
|
337 | - * @param $value |
|
338 | - * @param bool $override_ee |
|
339 | - * @return void |
|
340 | - */ |
|
341 | - public function set($key, $value, $override_ee = false) |
|
342 | - { |
|
343 | - $this->request->setRequestParam($key, $value, $override_ee); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @param $key |
|
349 | - * @param null $default |
|
350 | - * @return mixed |
|
351 | - */ |
|
352 | - public function get($key, $default = null) |
|
353 | - { |
|
354 | - return $this->request->getRequestParam($key, $default); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * check if param exists |
|
360 | - * |
|
361 | - * @param $key |
|
362 | - * @return boolean |
|
363 | - */ |
|
364 | - public function is_set($key) |
|
365 | - { |
|
366 | - return $this->request->requestParamIsSet($key); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * remove param |
|
372 | - * |
|
373 | - * @param $key |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function un_set($key) |
|
377 | - { |
|
378 | - $this->request->unSetRequestParam($key); |
|
379 | - } |
|
16 | + /** |
|
17 | + * @var RequestInterface $request |
|
18 | + */ |
|
19 | + private $request; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var array $_notice |
|
23 | + */ |
|
24 | + private $_notice = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * rendered output to be returned to WP |
|
28 | + * |
|
29 | + * @var string $_output |
|
30 | + */ |
|
31 | + private $_output = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * whether current request is via AJAX |
|
35 | + * |
|
36 | + * @var boolean $ajax |
|
37 | + */ |
|
38 | + public $ajax = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * whether current request is via AJAX from the frontend of the site |
|
42 | + * |
|
43 | + * @var boolean $front_ajax |
|
44 | + */ |
|
45 | + public $front_ajax = false; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param RequestInterface $request |
|
50 | + */ |
|
51 | + public function __construct(RequestInterface $request) |
|
52 | + { |
|
53 | + $this->request = $request; |
|
54 | + $this->ajax = $this->request->isAjax(); |
|
55 | + $this->front_ajax = $this->request->isFrontAjax(); |
|
56 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param WP $wp |
|
62 | + * @return void |
|
63 | + * @throws EE_Error |
|
64 | + * @throws ReflectionException |
|
65 | + */ |
|
66 | + public function parse_request($wp = null) |
|
67 | + { |
|
68 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
69 | + if (! $wp instanceof WP) { |
|
70 | + global $wp; |
|
71 | + } |
|
72 | + $this->set_request_vars($wp); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param WP $wp |
|
78 | + * @return void |
|
79 | + * @throws EE_Error |
|
80 | + * @throws ReflectionException |
|
81 | + */ |
|
82 | + public function set_request_vars($wp = null) |
|
83 | + { |
|
84 | + if (! is_admin()) { |
|
85 | + // set request post_id |
|
86 | + $this->request->setRequestParam('post_id', $this->get_post_id_from_request($wp)); |
|
87 | + // set request post name |
|
88 | + $this->request->setRequestParam('post_name', $this->get_post_name_from_request($wp)); |
|
89 | + // set request post_type |
|
90 | + $this->request->setRequestParam('post_type', $this->get_post_type_from_request($wp)); |
|
91 | + // true or false ? is this page being used by EE ? |
|
92 | + $this->set_espresso_page(); |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param WP $wp |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + public function get_post_id_from_request($wp = null) |
|
102 | + { |
|
103 | + if (! $wp instanceof WP) { |
|
104 | + global $wp; |
|
105 | + } |
|
106 | + $post_id = null; |
|
107 | + if (isset($wp->query_vars['p'])) { |
|
108 | + $post_id = $wp->query_vars['p']; |
|
109 | + } |
|
110 | + if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
111 | + $post_id = $wp->query_vars['page_id']; |
|
112 | + } |
|
113 | + if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
114 | + $post_id = basename($wp->request); |
|
115 | + } |
|
116 | + return $post_id; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param WP $wp |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function get_post_name_from_request($wp = null) |
|
125 | + { |
|
126 | + global $wpdb; |
|
127 | + if (! $wp instanceof WP) { |
|
128 | + global $wp; |
|
129 | + } |
|
130 | + $post_name = null; |
|
131 | + if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
132 | + $post_name = $wp->query_vars['name']; |
|
133 | + } |
|
134 | + if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
135 | + $post_name = $wp->query_vars['pagename']; |
|
136 | + } |
|
137 | + if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
138 | + $possible_post_name = basename($wp->request); |
|
139 | + if (! is_numeric($possible_post_name)) { |
|
140 | + $SQL = "SELECT ID from {$wpdb->posts}"; |
|
141 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
142 | + $SQL .= " AND post_name=%s"; |
|
143 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
144 | + if ($possible_post_name) { |
|
145 | + $post_name = $possible_post_name; |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + if (! $post_name && $this->get('post_id')) { |
|
150 | + $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
151 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
152 | + $SQL .= " AND ID=%d"; |
|
153 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
154 | + if ($possible_post_name) { |
|
155 | + $post_name = $possible_post_name; |
|
156 | + } |
|
157 | + } |
|
158 | + return $post_name; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param WP $wp |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + public function get_post_type_from_request($wp = null) |
|
167 | + { |
|
168 | + if (! $wp instanceof WP) { |
|
169 | + global $wp; |
|
170 | + } |
|
171 | + return isset($wp->query_vars['post_type']) |
|
172 | + ? $wp->query_vars['post_type'] |
|
173 | + : null; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Just a helper method for getting the url for the displayed page. |
|
179 | + * |
|
180 | + * @param WP $wp |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function get_current_page_permalink($wp = null) |
|
184 | + { |
|
185 | + $post_id = $this->get_post_id_from_request($wp); |
|
186 | + if ($post_id) { |
|
187 | + $current_page_permalink = get_permalink($post_id); |
|
188 | + } else { |
|
189 | + if (! $wp instanceof WP) { |
|
190 | + global $wp; |
|
191 | + } |
|
192 | + if ($wp->request) { |
|
193 | + $current_page_permalink = site_url($wp->request); |
|
194 | + } else { |
|
195 | + $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
196 | + } |
|
197 | + } |
|
198 | + return $current_page_permalink; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return bool |
|
204 | + * @throws EE_Error |
|
205 | + * @throws ReflectionException |
|
206 | + */ |
|
207 | + public function test_for_espresso_page() |
|
208 | + { |
|
209 | + global $wp; |
|
210 | + /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
211 | + $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
212 | + $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
213 | + if (is_array($espresso_CPT_taxonomies)) { |
|
214 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
215 | + if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
216 | + return true; |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | + // load espresso CPT endpoints |
|
221 | + $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
222 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
223 | + $post_types = (array) $this->get('post_type'); |
|
224 | + foreach ($post_types as $post_type) { |
|
225 | + // was a post name passed ? |
|
226 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
227 | + // kk we know this is an espresso page, but is it a specific post ? |
|
228 | + if (! $this->get('post_name')) { |
|
229 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
230 | + $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | + ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
232 | + : ''; |
|
233 | + // if the post type matches on of our then set the endpoint |
|
234 | + if ($post_name) { |
|
235 | + $this->set('post_name', $post_name); |
|
236 | + } |
|
237 | + } |
|
238 | + return true; |
|
239 | + } |
|
240 | + } |
|
241 | + return false; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param $key |
|
246 | + * @param $value |
|
247 | + * @return void |
|
248 | + */ |
|
249 | + public function set_notice($key, $value) |
|
250 | + { |
|
251 | + $this->_notice[ $key ] = $value; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param $key |
|
257 | + * @return mixed |
|
258 | + */ |
|
259 | + public function get_notice($key) |
|
260 | + { |
|
261 | + return isset($this->_notice[ $key ]) |
|
262 | + ? $this->_notice[ $key ] |
|
263 | + : null; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @param $string |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function add_output($string) |
|
272 | + { |
|
273 | + $this->_output .= $string; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function get_output() |
|
281 | + { |
|
282 | + return $this->_output; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $item |
|
288 | + * @param $key |
|
289 | + */ |
|
290 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
291 | + { |
|
292 | + $item = strpos($item, 'email') !== false |
|
293 | + ? sanitize_email($item) |
|
294 | + : sanitize_text_field($item); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @param null|bool $value |
|
300 | + * @return void |
|
301 | + * @throws EE_Error |
|
302 | + * @throws ReflectionException |
|
303 | + */ |
|
304 | + public function set_espresso_page($value = null) |
|
305 | + { |
|
306 | + $this->request->setRequestParam( |
|
307 | + 'is_espresso_page', |
|
308 | + ! empty($value) |
|
309 | + ? $value |
|
310 | + : $this->test_for_espresso_page() |
|
311 | + ); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @return bool |
|
317 | + */ |
|
318 | + public function is_espresso_page() |
|
319 | + { |
|
320 | + return $this->request->requestParamIsSet('is_espresso_page'); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * returns contents of $_REQUEST |
|
326 | + * |
|
327 | + * @return array |
|
328 | + */ |
|
329 | + public function params() |
|
330 | + { |
|
331 | + return $this->request->requestParams(); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param $key |
|
337 | + * @param $value |
|
338 | + * @param bool $override_ee |
|
339 | + * @return void |
|
340 | + */ |
|
341 | + public function set($key, $value, $override_ee = false) |
|
342 | + { |
|
343 | + $this->request->setRequestParam($key, $value, $override_ee); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @param $key |
|
349 | + * @param null $default |
|
350 | + * @return mixed |
|
351 | + */ |
|
352 | + public function get($key, $default = null) |
|
353 | + { |
|
354 | + return $this->request->getRequestParam($key, $default); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * check if param exists |
|
360 | + * |
|
361 | + * @param $key |
|
362 | + * @return boolean |
|
363 | + */ |
|
364 | + public function is_set($key) |
|
365 | + { |
|
366 | + return $this->request->requestParamIsSet($key); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * remove param |
|
372 | + * |
|
373 | + * @param $key |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function un_set($key) |
|
377 | + { |
|
378 | + $this->request->unSetRequestParam($key); |
|
379 | + } |
|
380 | 380 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function parse_request($wp = null) |
67 | 67 | { |
68 | 68 | // if somebody forgot to provide us with WP, that's ok because its global |
69 | - if (! $wp instanceof WP) { |
|
69 | + if ( ! $wp instanceof WP) { |
|
70 | 70 | global $wp; |
71 | 71 | } |
72 | 72 | $this->set_request_vars($wp); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function set_request_vars($wp = null) |
83 | 83 | { |
84 | - if (! is_admin()) { |
|
84 | + if ( ! is_admin()) { |
|
85 | 85 | // set request post_id |
86 | 86 | $this->request->setRequestParam('post_id', $this->get_post_id_from_request($wp)); |
87 | 87 | // set request post name |
@@ -100,17 +100,17 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function get_post_id_from_request($wp = null) |
102 | 102 | { |
103 | - if (! $wp instanceof WP) { |
|
103 | + if ( ! $wp instanceof WP) { |
|
104 | 104 | global $wp; |
105 | 105 | } |
106 | 106 | $post_id = null; |
107 | 107 | if (isset($wp->query_vars['p'])) { |
108 | 108 | $post_id = $wp->query_vars['p']; |
109 | 109 | } |
110 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
110 | + if ( ! $post_id && isset($wp->query_vars['page_id'])) { |
|
111 | 111 | $post_id = $wp->query_vars['page_id']; |
112 | 112 | } |
113 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
113 | + if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
114 | 114 | $post_id = basename($wp->request); |
115 | 115 | } |
116 | 116 | return $post_id; |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | public function get_post_name_from_request($wp = null) |
125 | 125 | { |
126 | 126 | global $wpdb; |
127 | - if (! $wp instanceof WP) { |
|
127 | + if ( ! $wp instanceof WP) { |
|
128 | 128 | global $wp; |
129 | 129 | } |
130 | 130 | $post_name = null; |
131 | 131 | if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
132 | 132 | $post_name = $wp->query_vars['name']; |
133 | 133 | } |
134 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
134 | + if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
135 | 135 | $post_name = $wp->query_vars['pagename']; |
136 | 136 | } |
137 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
137 | + if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
138 | 138 | $possible_post_name = basename($wp->request); |
139 | - if (! is_numeric($possible_post_name)) { |
|
139 | + if ( ! is_numeric($possible_post_name)) { |
|
140 | 140 | $SQL = "SELECT ID from {$wpdb->posts}"; |
141 | 141 | $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
142 | 142 | $SQL .= " AND post_name=%s"; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
149 | - if (! $post_name && $this->get('post_id')) { |
|
149 | + if ( ! $post_name && $this->get('post_id')) { |
|
150 | 150 | $SQL = "SELECT post_name from {$wpdb->posts}"; |
151 | 151 | $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
152 | 152 | $SQL .= " AND ID=%d"; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function get_post_type_from_request($wp = null) |
167 | 167 | { |
168 | - if (! $wp instanceof WP) { |
|
168 | + if ( ! $wp instanceof WP) { |
|
169 | 169 | global $wp; |
170 | 170 | } |
171 | 171 | return isset($wp->query_vars['post_type']) |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if ($post_id) { |
187 | 187 | $current_page_permalink = get_permalink($post_id); |
188 | 188 | } else { |
189 | - if (! $wp instanceof WP) { |
|
189 | + if ( ! $wp instanceof WP) { |
|
190 | 190 | global $wp; |
191 | 191 | } |
192 | 192 | if ($wp->request) { |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
213 | 213 | if (is_array($espresso_CPT_taxonomies)) { |
214 | 214 | foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
215 | + if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) { |
|
216 | 216 | return true; |
217 | 217 | } |
218 | 218 | } |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | $post_types = (array) $this->get('post_type'); |
224 | 224 | foreach ($post_types as $post_type) { |
225 | 225 | // was a post name passed ? |
226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
226 | + if (isset($post_type_CPT_endpoints[$post_type])) { |
|
227 | 227 | // kk we know this is an espresso page, but is it a specific post ? |
228 | - if (! $this->get('post_name')) { |
|
228 | + if ( ! $this->get('post_name')) { |
|
229 | 229 | // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
230 | + $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
|
231 | + ? $post_type_CPT_endpoints[$this->get('post_type')] |
|
232 | 232 | : ''; |
233 | 233 | // if the post type matches on of our then set the endpoint |
234 | 234 | if ($post_name) { |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function set_notice($key, $value) |
250 | 250 | { |
251 | - $this->_notice[ $key ] = $value; |
|
251 | + $this->_notice[$key] = $value; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function get_notice($key) |
260 | 260 | { |
261 | - return isset($this->_notice[ $key ]) |
|
262 | - ? $this->_notice[ $key ] |
|
261 | + return isset($this->_notice[$key]) |
|
262 | + ? $this->_notice[$key] |
|
263 | 263 | : null; |
264 | 264 | } |
265 | 265 |