@@ -22,1064 +22,1064 @@ |
||
22 | 22 | class EE_Dependency_Map |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | - */ |
|
33 | - const load_new_object = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | - */ |
|
39 | - const load_from_cache = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * When registering a dependency, |
|
43 | - * this indicates to keep any existing dependencies that already exist, |
|
44 | - * and simply discard any new dependencies declared in the incoming data |
|
45 | - */ |
|
46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * When registering a dependency, |
|
50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | - */ |
|
52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
53 | - |
|
54 | - /** |
|
55 | - * @type EE_Dependency_Map $_instance |
|
56 | - */ |
|
57 | - protected static $_instance; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var ClassInterfaceCache $class_cache |
|
61 | - */ |
|
62 | - private $class_cache; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type RequestInterface $request |
|
66 | - */ |
|
67 | - protected $request; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type LegacyRequestInterface $legacy_request |
|
71 | - */ |
|
72 | - protected $legacy_request; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type ResponseInterface $response |
|
76 | - */ |
|
77 | - protected $response; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type LoaderInterface $loader |
|
81 | - */ |
|
82 | - protected $loader; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type array $_dependency_map |
|
86 | - */ |
|
87 | - protected $_dependency_map = []; |
|
88 | - |
|
89 | - /** |
|
90 | - * @type array $_class_loaders |
|
91 | - */ |
|
92 | - protected $_class_loaders = []; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * EE_Dependency_Map constructor. |
|
97 | - * |
|
98 | - * @param ClassInterfaceCache $class_cache |
|
99 | - */ |
|
100 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
101 | - { |
|
102 | - $this->class_cache = $class_cache; |
|
103 | - do_action('EE_Dependency_Map____construct', $this); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return void |
|
109 | - * @throws InvalidAliasException |
|
110 | - */ |
|
111 | - public function initialize() |
|
112 | - { |
|
113 | - $this->_register_core_dependencies(); |
|
114 | - $this->_register_core_class_loaders(); |
|
115 | - $this->_register_core_aliases(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @singleton method used to instantiate class object |
|
121 | - * @param ClassInterfaceCache|null $class_cache |
|
122 | - * @return EE_Dependency_Map |
|
123 | - */ |
|
124 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
125 | - { |
|
126 | - // check if class object is instantiated, and instantiated properly |
|
127 | - if ( |
|
128 | - ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
129 | - && $class_cache instanceof ClassInterfaceCache |
|
130 | - ) { |
|
131 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
132 | - } |
|
133 | - return EE_Dependency_Map::$_instance; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param RequestInterface $request |
|
139 | - */ |
|
140 | - public function setRequest(RequestInterface $request) |
|
141 | - { |
|
142 | - $this->request = $request; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param LegacyRequestInterface $legacy_request |
|
148 | - */ |
|
149 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
150 | - { |
|
151 | - $this->legacy_request = $legacy_request; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param ResponseInterface $response |
|
157 | - */ |
|
158 | - public function setResponse(ResponseInterface $response) |
|
159 | - { |
|
160 | - $this->response = $response; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param LoaderInterface $loader |
|
166 | - */ |
|
167 | - public function setLoader(LoaderInterface $loader) |
|
168 | - { |
|
169 | - $this->loader = $loader; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $class |
|
175 | - * @param array $dependencies |
|
176 | - * @param int $overwrite |
|
177 | - * @return bool |
|
178 | - */ |
|
179 | - public static function register_dependencies( |
|
180 | - $class, |
|
181 | - array $dependencies, |
|
182 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
183 | - ) { |
|
184 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
190 | - * to the class specified by the first parameter. |
|
191 | - * IMPORTANT !!! |
|
192 | - * The order of elements in the incoming $dependencies array MUST match |
|
193 | - * the order of the constructor parameters for the class in question. |
|
194 | - * This is especially important when overriding any existing dependencies that are registered. |
|
195 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
196 | - * |
|
197 | - * @param string $class |
|
198 | - * @param array $dependencies |
|
199 | - * @param int $overwrite |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function registerDependencies( |
|
203 | - $class, |
|
204 | - array $dependencies, |
|
205 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
206 | - ) { |
|
207 | - $class = trim($class, '\\'); |
|
208 | - $registered = false; |
|
209 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
210 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
211 | - } |
|
212 | - // we need to make sure that any aliases used when registering a dependency |
|
213 | - // get resolved to the correct class name |
|
214 | - foreach ($dependencies as $dependency => $load_source) { |
|
215 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
216 | - if ( |
|
217 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
218 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
219 | - ) { |
|
220 | - unset($dependencies[ $dependency ]); |
|
221 | - $dependencies[ $alias ] = $load_source; |
|
222 | - $registered = true; |
|
223 | - } |
|
224 | - } |
|
225 | - // now add our two lists of dependencies together. |
|
226 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
227 | - // so $dependencies is NOT overwritten because it is listed first |
|
228 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
229 | - // Union is way faster than array_merge() but should be used with caution... |
|
230 | - // especially with numerically indexed arrays |
|
231 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
232 | - // now we need to ensure that the resulting dependencies |
|
233 | - // array only has the entries that are required for the class |
|
234 | - // so first count how many dependencies were originally registered for the class |
|
235 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
236 | - // if that count is non-zero (meaning dependencies were already registered) |
|
237 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
238 | - // then truncate the final array to match that count |
|
239 | - ? array_slice($dependencies, 0, $dependency_count) |
|
240 | - // otherwise just take the incoming array because nothing previously existed |
|
241 | - : $dependencies; |
|
242 | - return $registered; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param string $class_name |
|
248 | - * @param string $loader |
|
249 | - * @return bool |
|
250 | - * @throws DomainException |
|
251 | - */ |
|
252 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
253 | - { |
|
254 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @param string $class_name |
|
260 | - * @param string $loader |
|
261 | - * @return bool |
|
262 | - * @throws DomainException |
|
263 | - */ |
|
264 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
265 | - { |
|
266 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
267 | - throw new DomainException( |
|
268 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
269 | - ); |
|
270 | - } |
|
271 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
272 | - if ( |
|
273 | - ! is_callable($loader) |
|
274 | - && ( |
|
275 | - strpos($loader, 'load_') !== 0 |
|
276 | - || ! method_exists('EE_Registry', $loader) |
|
277 | - ) |
|
278 | - ) { |
|
279 | - throw new DomainException( |
|
280 | - sprintf( |
|
281 | - esc_html__( |
|
282 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
283 | - 'event_espresso' |
|
284 | - ), |
|
285 | - $loader |
|
286 | - ) |
|
287 | - ); |
|
288 | - } |
|
289 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
290 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
291 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
292 | - return true; |
|
293 | - } |
|
294 | - return false; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function dependency_map() |
|
302 | - { |
|
303 | - return $this->_dependency_map; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
309 | - * |
|
310 | - * @param string $class_name |
|
311 | - * @return boolean |
|
312 | - */ |
|
313 | - public function has($class_name = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - return isset($this->_dependency_map[ $class_name ]); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
325 | - * |
|
326 | - * @param string $class_name |
|
327 | - * @param string $dependency |
|
328 | - * @return bool |
|
329 | - */ |
|
330 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
331 | - { |
|
332 | - // all legacy models have the same dependencies |
|
333 | - if (strpos($class_name, 'EEM_') === 0) { |
|
334 | - $class_name = 'LEGACY_MODELS'; |
|
335 | - } |
|
336 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
337 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
343 | - * |
|
344 | - * @param string $class_name |
|
345 | - * @param string $dependency |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
349 | - { |
|
350 | - // all legacy models have the same dependencies |
|
351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
352 | - $class_name = 'LEGACY_MODELS'; |
|
353 | - } |
|
354 | - $dependency = $this->getFqnForAlias($dependency); |
|
355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
356 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
357 | - : EE_Dependency_Map::not_registered; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @param string $class_name |
|
363 | - * @return string | Closure |
|
364 | - */ |
|
365 | - public function class_loader($class_name) |
|
366 | - { |
|
367 | - // all legacy models use load_model() |
|
368 | - if (strpos($class_name, 'EEM_') === 0) { |
|
369 | - return 'load_model'; |
|
370 | - } |
|
371 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
372 | - // perform strpos() first to avoid loading regex every time we load a class |
|
373 | - if ( |
|
374 | - strpos($class_name, 'EE_CPT_') === 0 |
|
375 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
376 | - ) { |
|
377 | - return 'load_core'; |
|
378 | - } |
|
379 | - $class_name = $this->getFqnForAlias($class_name); |
|
380 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @return array |
|
386 | - */ |
|
387 | - public function class_loaders() |
|
388 | - { |
|
389 | - return $this->_class_loaders; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * adds an alias for a classname |
|
395 | - * |
|
396 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
397 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
398 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
399 | - * @throws InvalidAliasException |
|
400 | - */ |
|
401 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
402 | - { |
|
403 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
409 | - * WHY? |
|
410 | - * Because if a class is type hinting for a concretion, |
|
411 | - * then why would we need to find another class to supply it? |
|
412 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
413 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
414 | - * Don't go looking for some substitute. |
|
415 | - * Whereas if a class is type hinting for an interface... |
|
416 | - * then we need to find an actual class to use. |
|
417 | - * So the interface IS the alias for some other FQN, |
|
418 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
419 | - * represents some other class. |
|
420 | - * |
|
421 | - * @param string $fqn |
|
422 | - * @param string $for_class |
|
423 | - * @return bool |
|
424 | - */ |
|
425 | - public function isAlias($fqn = '', $for_class = '') |
|
426 | - { |
|
427 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
433 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
434 | - * for example: |
|
435 | - * if the following two entries were added to the _aliases array: |
|
436 | - * array( |
|
437 | - * 'interface_alias' => 'some\namespace\interface' |
|
438 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
439 | - * ) |
|
440 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
441 | - * to load an instance of 'some\namespace\classname' |
|
442 | - * |
|
443 | - * @param string $alias |
|
444 | - * @param string $for_class |
|
445 | - * @return string |
|
446 | - */ |
|
447 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
448 | - { |
|
449 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
455 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
456 | - * This is done by using the following class constants: |
|
457 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
458 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
459 | - */ |
|
460 | - protected function _register_core_dependencies() |
|
461 | - { |
|
462 | - $this->_dependency_map = [ |
|
463 | - 'EE_Request_Handler' => [ |
|
464 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
465 | - ], |
|
466 | - 'EE_System' => [ |
|
467 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
472 | - ], |
|
473 | - 'EE_Admin' => [ |
|
474 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
476 | - ], |
|
477 | - 'EE_Cart' => [ |
|
478 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | - ], |
|
480 | - 'EE_Messenger_Collection_Loader' => [ |
|
481 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | - ], |
|
483 | - 'EE_Message_Type_Collection_Loader' => [ |
|
484 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
485 | - ], |
|
486 | - 'EE_Message_Resource_Manager' => [ |
|
487 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
488 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
490 | - ], |
|
491 | - 'EE_Message_Factory' => [ |
|
492 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
493 | - ], |
|
494 | - 'EE_messages' => [ |
|
495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | - ], |
|
497 | - 'EE_Messages_Generator' => [ |
|
498 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
499 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
500 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
501 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
502 | - ], |
|
503 | - 'EE_Messages_Processor' => [ |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - ], |
|
506 | - 'EE_Messages_Queue' => [ |
|
507 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
508 | - ], |
|
509 | - 'EE_Messages_Template_Defaults' => [ |
|
510 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
511 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
512 | - ], |
|
513 | - 'EE_Message_To_Generate_From_Request' => [ |
|
514 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
515 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
516 | - ], |
|
517 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
518 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
519 | - ], |
|
520 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
521 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
522 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
523 | - ], |
|
524 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
525 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
526 | - ], |
|
527 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
528 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
529 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
530 | - ], |
|
531 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
532 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
533 | - ], |
|
534 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
535 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
536 | - ], |
|
537 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
538 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
539 | - ], |
|
540 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
541 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
542 | - ], |
|
543 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
544 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
545 | - ], |
|
546 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
547 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
548 | - ], |
|
549 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
550 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
551 | - ], |
|
552 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
553 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
554 | - ], |
|
555 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
556 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
557 | - ], |
|
558 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
559 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
560 | - ], |
|
561 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
562 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
563 | - ], |
|
564 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
565 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
566 | - ], |
|
567 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
568 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
569 | - ], |
|
570 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - ], |
|
573 | - 'EE_Data_Migration_Class_Base' => [ |
|
574 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | - ], |
|
577 | - 'EE_DMS_Core_4_1_0' => [ |
|
578 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
579 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
580 | - ], |
|
581 | - 'EE_DMS_Core_4_2_0' => [ |
|
582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
583 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
584 | - ], |
|
585 | - 'EE_DMS_Core_4_3_0' => [ |
|
586 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
587 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
588 | - ], |
|
589 | - 'EE_DMS_Core_4_4_0' => [ |
|
590 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
591 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
592 | - ], |
|
593 | - 'EE_DMS_Core_4_5_0' => [ |
|
594 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
595 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
596 | - ], |
|
597 | - 'EE_DMS_Core_4_6_0' => [ |
|
598 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
599 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
600 | - ], |
|
601 | - 'EE_DMS_Core_4_7_0' => [ |
|
602 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
603 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
604 | - ], |
|
605 | - 'EE_DMS_Core_4_8_0' => [ |
|
606 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
607 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
608 | - ], |
|
609 | - 'EE_DMS_Core_4_9_0' => [ |
|
610 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
611 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
612 | - ], |
|
613 | - 'EE_DMS_Core_4_10_0' => [ |
|
614 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
615 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
616 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
617 | - ], |
|
618 | - 'EE_DMS_Core_4_11_0' => [ |
|
619 | - 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
620 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
621 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
622 | - ], |
|
623 | - 'EE_DMS_Core_4_12_0' => [ |
|
624 | - 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
625 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
626 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ], |
|
628 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
629 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
630 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
631 | - ], |
|
632 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
633 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
634 | - ], |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
636 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
637 | - ], |
|
638 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
639 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
640 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
641 | - ], |
|
642 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
643 | - null, |
|
644 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
645 | - ], |
|
646 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
647 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
648 | - ], |
|
649 | - 'LEGACY_MODELS' => [ |
|
650 | - null, |
|
651 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
652 | - ], |
|
653 | - 'EE_Module_Request_Router' => [ |
|
654 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | - ], |
|
656 | - 'EE_Registration_Processor' => [ |
|
657 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
658 | - ], |
|
659 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
660 | - null, |
|
661 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
662 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ], |
|
664 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
665 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
666 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
667 | - ], |
|
668 | - 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
669 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
670 | - ], |
|
671 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
672 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
673 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
674 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
675 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
676 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
677 | - ], |
|
678 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
679 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
680 | - ], |
|
681 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
682 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
683 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
684 | - ], |
|
685 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
686 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
687 | - ], |
|
688 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
689 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
690 | - ], |
|
691 | - 'EE_CPT_Strategy' => [ |
|
692 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
694 | - ], |
|
695 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
696 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
697 | - ], |
|
698 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
699 | - null, |
|
700 | - null, |
|
701 | - null, |
|
702 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
704 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
705 | - ], |
|
706 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
707 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
708 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
709 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
710 | - ], |
|
711 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
712 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
713 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
714 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
715 | - ], |
|
716 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
717 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
718 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
719 | - ], |
|
720 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
721 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
722 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
723 | - ], |
|
724 | - 'EE_URL_Validation_Strategy' => [ |
|
725 | - null, |
|
726 | - null, |
|
727 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
728 | - ], |
|
729 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
730 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
731 | - ], |
|
732 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
733 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
734 | - ], |
|
735 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
736 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
737 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
739 | - null, |
|
740 | - ], |
|
741 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
742 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
743 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
744 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
745 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
746 | - ], |
|
747 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
748 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
749 | - ], |
|
750 | - 'EventEspresso\core\services\routing\Router' => [ |
|
751 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
752 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
753 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
754 | - ], |
|
755 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
756 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
757 | - ], |
|
758 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
759 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
760 | - ], |
|
761 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
762 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
763 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
764 | - ], |
|
765 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
766 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
767 | - ], |
|
768 | - 'EventEspresso\core\services\addon\AddonManager' => [ |
|
769 | - 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
770 | - 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
771 | - 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
772 | - 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
773 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
774 | - ], |
|
775 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
776 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
777 | - ], |
|
778 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
779 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
780 | - ], |
|
781 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
782 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
783 | - ], |
|
784 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
785 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
786 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
787 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
788 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
789 | - ], |
|
790 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
791 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
792 | - ], |
|
793 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
794 | - 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
795 | - ], |
|
796 | - 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
797 | - 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
798 | - 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
799 | - 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
800 | - 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
801 | - 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
802 | - 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
803 | - 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
804 | - 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
805 | - ], |
|
806 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
807 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
808 | - ], |
|
809 | - 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
810 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
811 | - ], |
|
812 | - ]; |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * Registers how core classes are loaded. |
|
818 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
819 | - * 'EE_Request_Handler' => 'load_core' |
|
820 | - * 'EE_Messages_Queue' => 'load_lib' |
|
821 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
822 | - * or, if greater control is required, by providing a custom closure. For example: |
|
823 | - * 'Some_Class' => function () { |
|
824 | - * return new Some_Class(); |
|
825 | - * }, |
|
826 | - * This is required for instantiating dependencies |
|
827 | - * where an interface has been type hinted in a class constructor. For example: |
|
828 | - * 'Required_Interface' => function () { |
|
829 | - * return new A_Class_That_Implements_Required_Interface(); |
|
830 | - * }, |
|
831 | - */ |
|
832 | - protected function _register_core_class_loaders() |
|
833 | - { |
|
834 | - $this->_class_loaders = [ |
|
835 | - // load_core |
|
836 | - 'EE_Dependency_Map' => function () { |
|
837 | - return $this; |
|
838 | - }, |
|
839 | - 'EE_Capabilities' => 'load_core', |
|
840 | - 'EE_Encryption' => 'load_core', |
|
841 | - 'EE_Front_Controller' => 'load_core', |
|
842 | - 'EE_Module_Request_Router' => 'load_core', |
|
843 | - 'EE_Registry' => 'load_core', |
|
844 | - 'EE_Request' => function () { |
|
845 | - return $this->legacy_request; |
|
846 | - }, |
|
847 | - 'EventEspresso\core\services\request\Request' => function () { |
|
848 | - return $this->request; |
|
849 | - }, |
|
850 | - 'EventEspresso\core\services\request\Response' => function () { |
|
851 | - return $this->response; |
|
852 | - }, |
|
853 | - 'EE_Base' => 'load_core', |
|
854 | - 'EE_Request_Handler' => 'load_core', |
|
855 | - 'EE_Session' => 'load_core', |
|
856 | - 'EE_Cron_Tasks' => 'load_core', |
|
857 | - 'EE_System' => 'load_core', |
|
858 | - 'EE_Maintenance_Mode' => 'load_core', |
|
859 | - 'EE_Register_CPTs' => 'load_core', |
|
860 | - 'EE_Admin' => 'load_core', |
|
861 | - 'EE_CPT_Strategy' => 'load_core', |
|
862 | - // load_class |
|
863 | - 'EE_Registration_Processor' => 'load_class', |
|
864 | - // load_lib |
|
865 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
866 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
867 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
868 | - 'EE_Messenger_Collection' => 'load_lib', |
|
869 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
870 | - 'EE_Messages_Processor' => 'load_lib', |
|
871 | - 'EE_Message_Repository' => 'load_lib', |
|
872 | - 'EE_Messages_Queue' => 'load_lib', |
|
873 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
874 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
875 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
876 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
877 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
878 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
879 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
880 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
881 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
882 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
883 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
884 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
885 | - 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
886 | - 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
887 | - 'EE_Messages_Generator' => static function () { |
|
888 | - return EE_Registry::instance()->load_lib( |
|
889 | - 'Messages_Generator', |
|
890 | - [], |
|
891 | - false, |
|
892 | - false |
|
893 | - ); |
|
894 | - }, |
|
895 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
896 | - return EE_Registry::instance()->load_lib( |
|
897 | - 'Messages_Template_Defaults', |
|
898 | - $arguments, |
|
899 | - false, |
|
900 | - false |
|
901 | - ); |
|
902 | - }, |
|
903 | - // load_helper |
|
904 | - 'EEH_Parse_Shortcodes' => static function () { |
|
905 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
906 | - return new EEH_Parse_Shortcodes(); |
|
907 | - } |
|
908 | - return null; |
|
909 | - }, |
|
910 | - 'EE_Template_Config' => static function () { |
|
911 | - return EE_Config::instance()->template_settings; |
|
912 | - }, |
|
913 | - 'EE_Currency_Config' => static function () { |
|
914 | - return EE_Config::instance()->currency; |
|
915 | - }, |
|
916 | - 'EE_Registration_Config' => static function () { |
|
917 | - return EE_Config::instance()->registration; |
|
918 | - }, |
|
919 | - 'EE_Core_Config' => static function () { |
|
920 | - return EE_Config::instance()->core; |
|
921 | - }, |
|
922 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
923 | - return LoaderFactory::getLoader(); |
|
924 | - }, |
|
925 | - 'EE_Network_Config' => static function () { |
|
926 | - return EE_Network_Config::instance(); |
|
927 | - }, |
|
928 | - 'EE_Config' => static function () { |
|
929 | - return EE_Config::instance(); |
|
930 | - }, |
|
931 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
932 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
933 | - }, |
|
934 | - 'EE_Admin_Config' => static function () { |
|
935 | - return EE_Config::instance()->admin; |
|
936 | - }, |
|
937 | - 'EE_Organization_Config' => static function () { |
|
938 | - return EE_Config::instance()->organization; |
|
939 | - }, |
|
940 | - 'EE_Network_Core_Config' => static function () { |
|
941 | - return EE_Network_Config::instance()->core; |
|
942 | - }, |
|
943 | - 'EE_Environment_Config' => static function () { |
|
944 | - return EE_Config::instance()->environment; |
|
945 | - }, |
|
946 | - 'EED_Core_Rest_Api' => static function () { |
|
947 | - return EED_Core_Rest_Api::instance(); |
|
948 | - }, |
|
949 | - 'WP_REST_Server' => static function () { |
|
950 | - return rest_get_server(); |
|
951 | - }, |
|
952 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
953 | - return EE_Psr4AutoloaderInit::psr4_loader(); |
|
954 | - }, |
|
955 | - ]; |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * can be used for supplying alternate names for classes, |
|
961 | - * or for connecting interface names to instantiable classes |
|
962 | - * |
|
963 | - * @throws InvalidAliasException |
|
964 | - */ |
|
965 | - protected function _register_core_aliases() |
|
966 | - { |
|
967 | - $aliases = [ |
|
968 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
969 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
970 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
971 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
972 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
973 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
974 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
975 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
976 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
977 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
978 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
979 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
980 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
981 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
982 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
983 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
984 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
985 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
986 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
987 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
988 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
989 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
990 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
991 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
992 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
993 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
994 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
995 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
996 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
997 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
998 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
999 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1000 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1001 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1002 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1003 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1004 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1005 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
1006 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
1007 | - ]; |
|
1008 | - foreach ($aliases as $alias => $fqn) { |
|
1009 | - if (is_array($fqn)) { |
|
1010 | - foreach ($fqn as $class => $for_class) { |
|
1011 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
1012 | - } |
|
1013 | - continue; |
|
1014 | - } |
|
1015 | - $this->class_cache->addAlias($fqn, $alias); |
|
1016 | - } |
|
1017 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1018 | - $this->class_cache->addAlias( |
|
1019 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1020 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1021 | - ); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1028 | - * request Primarily used by unit tests. |
|
1029 | - */ |
|
1030 | - public function reset() |
|
1031 | - { |
|
1032 | - $this->_register_core_class_loaders(); |
|
1033 | - $this->_register_core_dependencies(); |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1039 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1040 | - * WHY? |
|
1041 | - * Because if a class is type hinting for a concretion, |
|
1042 | - * then why would we need to find another class to supply it? |
|
1043 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1044 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1045 | - * Don't go looking for some substitute. |
|
1046 | - * Whereas if a class is type hinting for an interface... |
|
1047 | - * then we need to find an actual class to use. |
|
1048 | - * So the interface IS the alias for some other FQN, |
|
1049 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1050 | - * represents some other class. |
|
1051 | - * |
|
1052 | - * @param string $fqn |
|
1053 | - * @param string $for_class |
|
1054 | - * @return bool |
|
1055 | - * @deprecated 4.9.62.p |
|
1056 | - */ |
|
1057 | - public function has_alias($fqn = '', $for_class = '') |
|
1058 | - { |
|
1059 | - return $this->isAlias($fqn, $for_class); |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1065 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1066 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1067 | - * for example: |
|
1068 | - * if the following two entries were added to the _aliases array: |
|
1069 | - * array( |
|
1070 | - * 'interface_alias' => 'some\namespace\interface' |
|
1071 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1072 | - * ) |
|
1073 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1074 | - * to load an instance of 'some\namespace\classname' |
|
1075 | - * |
|
1076 | - * @param string $alias |
|
1077 | - * @param string $for_class |
|
1078 | - * @return string |
|
1079 | - * @deprecated 4.9.62.p |
|
1080 | - */ |
|
1081 | - public function get_alias($alias = '', $for_class = '') |
|
1082 | - { |
|
1083 | - return $this->getFqnForAlias($alias, $for_class); |
|
1084 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | + */ |
|
33 | + const load_new_object = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | + */ |
|
39 | + const load_from_cache = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * When registering a dependency, |
|
43 | + * this indicates to keep any existing dependencies that already exist, |
|
44 | + * and simply discard any new dependencies declared in the incoming data |
|
45 | + */ |
|
46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * When registering a dependency, |
|
50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | + */ |
|
52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
53 | + |
|
54 | + /** |
|
55 | + * @type EE_Dependency_Map $_instance |
|
56 | + */ |
|
57 | + protected static $_instance; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var ClassInterfaceCache $class_cache |
|
61 | + */ |
|
62 | + private $class_cache; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type RequestInterface $request |
|
66 | + */ |
|
67 | + protected $request; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type LegacyRequestInterface $legacy_request |
|
71 | + */ |
|
72 | + protected $legacy_request; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type ResponseInterface $response |
|
76 | + */ |
|
77 | + protected $response; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type LoaderInterface $loader |
|
81 | + */ |
|
82 | + protected $loader; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type array $_dependency_map |
|
86 | + */ |
|
87 | + protected $_dependency_map = []; |
|
88 | + |
|
89 | + /** |
|
90 | + * @type array $_class_loaders |
|
91 | + */ |
|
92 | + protected $_class_loaders = []; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * EE_Dependency_Map constructor. |
|
97 | + * |
|
98 | + * @param ClassInterfaceCache $class_cache |
|
99 | + */ |
|
100 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
101 | + { |
|
102 | + $this->class_cache = $class_cache; |
|
103 | + do_action('EE_Dependency_Map____construct', $this); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + * @throws InvalidAliasException |
|
110 | + */ |
|
111 | + public function initialize() |
|
112 | + { |
|
113 | + $this->_register_core_dependencies(); |
|
114 | + $this->_register_core_class_loaders(); |
|
115 | + $this->_register_core_aliases(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @singleton method used to instantiate class object |
|
121 | + * @param ClassInterfaceCache|null $class_cache |
|
122 | + * @return EE_Dependency_Map |
|
123 | + */ |
|
124 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
125 | + { |
|
126 | + // check if class object is instantiated, and instantiated properly |
|
127 | + if ( |
|
128 | + ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
129 | + && $class_cache instanceof ClassInterfaceCache |
|
130 | + ) { |
|
131 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
132 | + } |
|
133 | + return EE_Dependency_Map::$_instance; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param RequestInterface $request |
|
139 | + */ |
|
140 | + public function setRequest(RequestInterface $request) |
|
141 | + { |
|
142 | + $this->request = $request; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param LegacyRequestInterface $legacy_request |
|
148 | + */ |
|
149 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
150 | + { |
|
151 | + $this->legacy_request = $legacy_request; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param ResponseInterface $response |
|
157 | + */ |
|
158 | + public function setResponse(ResponseInterface $response) |
|
159 | + { |
|
160 | + $this->response = $response; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param LoaderInterface $loader |
|
166 | + */ |
|
167 | + public function setLoader(LoaderInterface $loader) |
|
168 | + { |
|
169 | + $this->loader = $loader; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $class |
|
175 | + * @param array $dependencies |
|
176 | + * @param int $overwrite |
|
177 | + * @return bool |
|
178 | + */ |
|
179 | + public static function register_dependencies( |
|
180 | + $class, |
|
181 | + array $dependencies, |
|
182 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
183 | + ) { |
|
184 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
190 | + * to the class specified by the first parameter. |
|
191 | + * IMPORTANT !!! |
|
192 | + * The order of elements in the incoming $dependencies array MUST match |
|
193 | + * the order of the constructor parameters for the class in question. |
|
194 | + * This is especially important when overriding any existing dependencies that are registered. |
|
195 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
196 | + * |
|
197 | + * @param string $class |
|
198 | + * @param array $dependencies |
|
199 | + * @param int $overwrite |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function registerDependencies( |
|
203 | + $class, |
|
204 | + array $dependencies, |
|
205 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
206 | + ) { |
|
207 | + $class = trim($class, '\\'); |
|
208 | + $registered = false; |
|
209 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
210 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
211 | + } |
|
212 | + // we need to make sure that any aliases used when registering a dependency |
|
213 | + // get resolved to the correct class name |
|
214 | + foreach ($dependencies as $dependency => $load_source) { |
|
215 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
216 | + if ( |
|
217 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
218 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
219 | + ) { |
|
220 | + unset($dependencies[ $dependency ]); |
|
221 | + $dependencies[ $alias ] = $load_source; |
|
222 | + $registered = true; |
|
223 | + } |
|
224 | + } |
|
225 | + // now add our two lists of dependencies together. |
|
226 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
227 | + // so $dependencies is NOT overwritten because it is listed first |
|
228 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
229 | + // Union is way faster than array_merge() but should be used with caution... |
|
230 | + // especially with numerically indexed arrays |
|
231 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
232 | + // now we need to ensure that the resulting dependencies |
|
233 | + // array only has the entries that are required for the class |
|
234 | + // so first count how many dependencies were originally registered for the class |
|
235 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
236 | + // if that count is non-zero (meaning dependencies were already registered) |
|
237 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
238 | + // then truncate the final array to match that count |
|
239 | + ? array_slice($dependencies, 0, $dependency_count) |
|
240 | + // otherwise just take the incoming array because nothing previously existed |
|
241 | + : $dependencies; |
|
242 | + return $registered; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param string $class_name |
|
248 | + * @param string $loader |
|
249 | + * @return bool |
|
250 | + * @throws DomainException |
|
251 | + */ |
|
252 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
253 | + { |
|
254 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @param string $class_name |
|
260 | + * @param string $loader |
|
261 | + * @return bool |
|
262 | + * @throws DomainException |
|
263 | + */ |
|
264 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
265 | + { |
|
266 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
267 | + throw new DomainException( |
|
268 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
269 | + ); |
|
270 | + } |
|
271 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
272 | + if ( |
|
273 | + ! is_callable($loader) |
|
274 | + && ( |
|
275 | + strpos($loader, 'load_') !== 0 |
|
276 | + || ! method_exists('EE_Registry', $loader) |
|
277 | + ) |
|
278 | + ) { |
|
279 | + throw new DomainException( |
|
280 | + sprintf( |
|
281 | + esc_html__( |
|
282 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
283 | + 'event_espresso' |
|
284 | + ), |
|
285 | + $loader |
|
286 | + ) |
|
287 | + ); |
|
288 | + } |
|
289 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
290 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
291 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
292 | + return true; |
|
293 | + } |
|
294 | + return false; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function dependency_map() |
|
302 | + { |
|
303 | + return $this->_dependency_map; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
309 | + * |
|
310 | + * @param string $class_name |
|
311 | + * @return boolean |
|
312 | + */ |
|
313 | + public function has($class_name = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + return isset($this->_dependency_map[ $class_name ]); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
325 | + * |
|
326 | + * @param string $class_name |
|
327 | + * @param string $dependency |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
331 | + { |
|
332 | + // all legacy models have the same dependencies |
|
333 | + if (strpos($class_name, 'EEM_') === 0) { |
|
334 | + $class_name = 'LEGACY_MODELS'; |
|
335 | + } |
|
336 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
337 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
343 | + * |
|
344 | + * @param string $class_name |
|
345 | + * @param string $dependency |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
349 | + { |
|
350 | + // all legacy models have the same dependencies |
|
351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
352 | + $class_name = 'LEGACY_MODELS'; |
|
353 | + } |
|
354 | + $dependency = $this->getFqnForAlias($dependency); |
|
355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
356 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
357 | + : EE_Dependency_Map::not_registered; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @param string $class_name |
|
363 | + * @return string | Closure |
|
364 | + */ |
|
365 | + public function class_loader($class_name) |
|
366 | + { |
|
367 | + // all legacy models use load_model() |
|
368 | + if (strpos($class_name, 'EEM_') === 0) { |
|
369 | + return 'load_model'; |
|
370 | + } |
|
371 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
372 | + // perform strpos() first to avoid loading regex every time we load a class |
|
373 | + if ( |
|
374 | + strpos($class_name, 'EE_CPT_') === 0 |
|
375 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
376 | + ) { |
|
377 | + return 'load_core'; |
|
378 | + } |
|
379 | + $class_name = $this->getFqnForAlias($class_name); |
|
380 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @return array |
|
386 | + */ |
|
387 | + public function class_loaders() |
|
388 | + { |
|
389 | + return $this->_class_loaders; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * adds an alias for a classname |
|
395 | + * |
|
396 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
397 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
398 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
399 | + * @throws InvalidAliasException |
|
400 | + */ |
|
401 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
402 | + { |
|
403 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
409 | + * WHY? |
|
410 | + * Because if a class is type hinting for a concretion, |
|
411 | + * then why would we need to find another class to supply it? |
|
412 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
413 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
414 | + * Don't go looking for some substitute. |
|
415 | + * Whereas if a class is type hinting for an interface... |
|
416 | + * then we need to find an actual class to use. |
|
417 | + * So the interface IS the alias for some other FQN, |
|
418 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
419 | + * represents some other class. |
|
420 | + * |
|
421 | + * @param string $fqn |
|
422 | + * @param string $for_class |
|
423 | + * @return bool |
|
424 | + */ |
|
425 | + public function isAlias($fqn = '', $for_class = '') |
|
426 | + { |
|
427 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
433 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
434 | + * for example: |
|
435 | + * if the following two entries were added to the _aliases array: |
|
436 | + * array( |
|
437 | + * 'interface_alias' => 'some\namespace\interface' |
|
438 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
439 | + * ) |
|
440 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
441 | + * to load an instance of 'some\namespace\classname' |
|
442 | + * |
|
443 | + * @param string $alias |
|
444 | + * @param string $for_class |
|
445 | + * @return string |
|
446 | + */ |
|
447 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
448 | + { |
|
449 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
455 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
456 | + * This is done by using the following class constants: |
|
457 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
458 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
459 | + */ |
|
460 | + protected function _register_core_dependencies() |
|
461 | + { |
|
462 | + $this->_dependency_map = [ |
|
463 | + 'EE_Request_Handler' => [ |
|
464 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
465 | + ], |
|
466 | + 'EE_System' => [ |
|
467 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
472 | + ], |
|
473 | + 'EE_Admin' => [ |
|
474 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
476 | + ], |
|
477 | + 'EE_Cart' => [ |
|
478 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | + ], |
|
480 | + 'EE_Messenger_Collection_Loader' => [ |
|
481 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | + ], |
|
483 | + 'EE_Message_Type_Collection_Loader' => [ |
|
484 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
485 | + ], |
|
486 | + 'EE_Message_Resource_Manager' => [ |
|
487 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
488 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
490 | + ], |
|
491 | + 'EE_Message_Factory' => [ |
|
492 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
493 | + ], |
|
494 | + 'EE_messages' => [ |
|
495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | + ], |
|
497 | + 'EE_Messages_Generator' => [ |
|
498 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
499 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
500 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
501 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
502 | + ], |
|
503 | + 'EE_Messages_Processor' => [ |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + ], |
|
506 | + 'EE_Messages_Queue' => [ |
|
507 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
508 | + ], |
|
509 | + 'EE_Messages_Template_Defaults' => [ |
|
510 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
511 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
512 | + ], |
|
513 | + 'EE_Message_To_Generate_From_Request' => [ |
|
514 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
515 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
516 | + ], |
|
517 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
518 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
519 | + ], |
|
520 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
521 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
522 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
523 | + ], |
|
524 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
525 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
526 | + ], |
|
527 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
528 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
529 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
530 | + ], |
|
531 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
532 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
533 | + ], |
|
534 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
535 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
536 | + ], |
|
537 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
538 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
539 | + ], |
|
540 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
541 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
542 | + ], |
|
543 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
544 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
545 | + ], |
|
546 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
547 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
548 | + ], |
|
549 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
550 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
551 | + ], |
|
552 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
553 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
554 | + ], |
|
555 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
556 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
557 | + ], |
|
558 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
559 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
560 | + ], |
|
561 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
562 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
563 | + ], |
|
564 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
565 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
566 | + ], |
|
567 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
568 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
569 | + ], |
|
570 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + ], |
|
573 | + 'EE_Data_Migration_Class_Base' => [ |
|
574 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | + ], |
|
577 | + 'EE_DMS_Core_4_1_0' => [ |
|
578 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
579 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
580 | + ], |
|
581 | + 'EE_DMS_Core_4_2_0' => [ |
|
582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
583 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
584 | + ], |
|
585 | + 'EE_DMS_Core_4_3_0' => [ |
|
586 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
587 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
588 | + ], |
|
589 | + 'EE_DMS_Core_4_4_0' => [ |
|
590 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
591 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
592 | + ], |
|
593 | + 'EE_DMS_Core_4_5_0' => [ |
|
594 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
595 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
596 | + ], |
|
597 | + 'EE_DMS_Core_4_6_0' => [ |
|
598 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
599 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
600 | + ], |
|
601 | + 'EE_DMS_Core_4_7_0' => [ |
|
602 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
603 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
604 | + ], |
|
605 | + 'EE_DMS_Core_4_8_0' => [ |
|
606 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
607 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
608 | + ], |
|
609 | + 'EE_DMS_Core_4_9_0' => [ |
|
610 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
611 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
612 | + ], |
|
613 | + 'EE_DMS_Core_4_10_0' => [ |
|
614 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
615 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
616 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
617 | + ], |
|
618 | + 'EE_DMS_Core_4_11_0' => [ |
|
619 | + 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
620 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
621 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
622 | + ], |
|
623 | + 'EE_DMS_Core_4_12_0' => [ |
|
624 | + 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
625 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
626 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ], |
|
628 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
629 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
630 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
631 | + ], |
|
632 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
633 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
634 | + ], |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
636 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
637 | + ], |
|
638 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
639 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
640 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
641 | + ], |
|
642 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
643 | + null, |
|
644 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
645 | + ], |
|
646 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
647 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
648 | + ], |
|
649 | + 'LEGACY_MODELS' => [ |
|
650 | + null, |
|
651 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
652 | + ], |
|
653 | + 'EE_Module_Request_Router' => [ |
|
654 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | + ], |
|
656 | + 'EE_Registration_Processor' => [ |
|
657 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
658 | + ], |
|
659 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
660 | + null, |
|
661 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
662 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ], |
|
664 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
665 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
666 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
667 | + ], |
|
668 | + 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
669 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
670 | + ], |
|
671 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
672 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
673 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
674 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
675 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
676 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
677 | + ], |
|
678 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
679 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
680 | + ], |
|
681 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
682 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
683 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
684 | + ], |
|
685 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
686 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
687 | + ], |
|
688 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
689 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
690 | + ], |
|
691 | + 'EE_CPT_Strategy' => [ |
|
692 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
694 | + ], |
|
695 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
696 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
697 | + ], |
|
698 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
699 | + null, |
|
700 | + null, |
|
701 | + null, |
|
702 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
704 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
705 | + ], |
|
706 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
707 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
708 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
709 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
710 | + ], |
|
711 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
712 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
713 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
714 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
715 | + ], |
|
716 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
717 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
718 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
719 | + ], |
|
720 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
721 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
722 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
723 | + ], |
|
724 | + 'EE_URL_Validation_Strategy' => [ |
|
725 | + null, |
|
726 | + null, |
|
727 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
728 | + ], |
|
729 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
730 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
731 | + ], |
|
732 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
733 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
734 | + ], |
|
735 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
736 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
737 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
739 | + null, |
|
740 | + ], |
|
741 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
742 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
743 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
744 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
745 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
746 | + ], |
|
747 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
748 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
749 | + ], |
|
750 | + 'EventEspresso\core\services\routing\Router' => [ |
|
751 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
752 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
753 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
754 | + ], |
|
755 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
756 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
757 | + ], |
|
758 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
759 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
760 | + ], |
|
761 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
762 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
763 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
764 | + ], |
|
765 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
766 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
767 | + ], |
|
768 | + 'EventEspresso\core\services\addon\AddonManager' => [ |
|
769 | + 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
770 | + 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
771 | + 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
772 | + 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
773 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
774 | + ], |
|
775 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
776 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
777 | + ], |
|
778 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
779 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
780 | + ], |
|
781 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
782 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
783 | + ], |
|
784 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
785 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
786 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
787 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
788 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
789 | + ], |
|
790 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
791 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
792 | + ], |
|
793 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
794 | + 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
795 | + ], |
|
796 | + 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
797 | + 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
798 | + 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
799 | + 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
800 | + 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
801 | + 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
802 | + 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
803 | + 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
804 | + 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
805 | + ], |
|
806 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
807 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
808 | + ], |
|
809 | + 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
810 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
811 | + ], |
|
812 | + ]; |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * Registers how core classes are loaded. |
|
818 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
819 | + * 'EE_Request_Handler' => 'load_core' |
|
820 | + * 'EE_Messages_Queue' => 'load_lib' |
|
821 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
822 | + * or, if greater control is required, by providing a custom closure. For example: |
|
823 | + * 'Some_Class' => function () { |
|
824 | + * return new Some_Class(); |
|
825 | + * }, |
|
826 | + * This is required for instantiating dependencies |
|
827 | + * where an interface has been type hinted in a class constructor. For example: |
|
828 | + * 'Required_Interface' => function () { |
|
829 | + * return new A_Class_That_Implements_Required_Interface(); |
|
830 | + * }, |
|
831 | + */ |
|
832 | + protected function _register_core_class_loaders() |
|
833 | + { |
|
834 | + $this->_class_loaders = [ |
|
835 | + // load_core |
|
836 | + 'EE_Dependency_Map' => function () { |
|
837 | + return $this; |
|
838 | + }, |
|
839 | + 'EE_Capabilities' => 'load_core', |
|
840 | + 'EE_Encryption' => 'load_core', |
|
841 | + 'EE_Front_Controller' => 'load_core', |
|
842 | + 'EE_Module_Request_Router' => 'load_core', |
|
843 | + 'EE_Registry' => 'load_core', |
|
844 | + 'EE_Request' => function () { |
|
845 | + return $this->legacy_request; |
|
846 | + }, |
|
847 | + 'EventEspresso\core\services\request\Request' => function () { |
|
848 | + return $this->request; |
|
849 | + }, |
|
850 | + 'EventEspresso\core\services\request\Response' => function () { |
|
851 | + return $this->response; |
|
852 | + }, |
|
853 | + 'EE_Base' => 'load_core', |
|
854 | + 'EE_Request_Handler' => 'load_core', |
|
855 | + 'EE_Session' => 'load_core', |
|
856 | + 'EE_Cron_Tasks' => 'load_core', |
|
857 | + 'EE_System' => 'load_core', |
|
858 | + 'EE_Maintenance_Mode' => 'load_core', |
|
859 | + 'EE_Register_CPTs' => 'load_core', |
|
860 | + 'EE_Admin' => 'load_core', |
|
861 | + 'EE_CPT_Strategy' => 'load_core', |
|
862 | + // load_class |
|
863 | + 'EE_Registration_Processor' => 'load_class', |
|
864 | + // load_lib |
|
865 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
866 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
867 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
868 | + 'EE_Messenger_Collection' => 'load_lib', |
|
869 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
870 | + 'EE_Messages_Processor' => 'load_lib', |
|
871 | + 'EE_Message_Repository' => 'load_lib', |
|
872 | + 'EE_Messages_Queue' => 'load_lib', |
|
873 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
874 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
875 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
876 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
877 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
878 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
879 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
880 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
881 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
882 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
883 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
884 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
885 | + 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
886 | + 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
887 | + 'EE_Messages_Generator' => static function () { |
|
888 | + return EE_Registry::instance()->load_lib( |
|
889 | + 'Messages_Generator', |
|
890 | + [], |
|
891 | + false, |
|
892 | + false |
|
893 | + ); |
|
894 | + }, |
|
895 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
896 | + return EE_Registry::instance()->load_lib( |
|
897 | + 'Messages_Template_Defaults', |
|
898 | + $arguments, |
|
899 | + false, |
|
900 | + false |
|
901 | + ); |
|
902 | + }, |
|
903 | + // load_helper |
|
904 | + 'EEH_Parse_Shortcodes' => static function () { |
|
905 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
906 | + return new EEH_Parse_Shortcodes(); |
|
907 | + } |
|
908 | + return null; |
|
909 | + }, |
|
910 | + 'EE_Template_Config' => static function () { |
|
911 | + return EE_Config::instance()->template_settings; |
|
912 | + }, |
|
913 | + 'EE_Currency_Config' => static function () { |
|
914 | + return EE_Config::instance()->currency; |
|
915 | + }, |
|
916 | + 'EE_Registration_Config' => static function () { |
|
917 | + return EE_Config::instance()->registration; |
|
918 | + }, |
|
919 | + 'EE_Core_Config' => static function () { |
|
920 | + return EE_Config::instance()->core; |
|
921 | + }, |
|
922 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
923 | + return LoaderFactory::getLoader(); |
|
924 | + }, |
|
925 | + 'EE_Network_Config' => static function () { |
|
926 | + return EE_Network_Config::instance(); |
|
927 | + }, |
|
928 | + 'EE_Config' => static function () { |
|
929 | + return EE_Config::instance(); |
|
930 | + }, |
|
931 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
932 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
933 | + }, |
|
934 | + 'EE_Admin_Config' => static function () { |
|
935 | + return EE_Config::instance()->admin; |
|
936 | + }, |
|
937 | + 'EE_Organization_Config' => static function () { |
|
938 | + return EE_Config::instance()->organization; |
|
939 | + }, |
|
940 | + 'EE_Network_Core_Config' => static function () { |
|
941 | + return EE_Network_Config::instance()->core; |
|
942 | + }, |
|
943 | + 'EE_Environment_Config' => static function () { |
|
944 | + return EE_Config::instance()->environment; |
|
945 | + }, |
|
946 | + 'EED_Core_Rest_Api' => static function () { |
|
947 | + return EED_Core_Rest_Api::instance(); |
|
948 | + }, |
|
949 | + 'WP_REST_Server' => static function () { |
|
950 | + return rest_get_server(); |
|
951 | + }, |
|
952 | + 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
953 | + return EE_Psr4AutoloaderInit::psr4_loader(); |
|
954 | + }, |
|
955 | + ]; |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * can be used for supplying alternate names for classes, |
|
961 | + * or for connecting interface names to instantiable classes |
|
962 | + * |
|
963 | + * @throws InvalidAliasException |
|
964 | + */ |
|
965 | + protected function _register_core_aliases() |
|
966 | + { |
|
967 | + $aliases = [ |
|
968 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
969 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
970 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
971 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
972 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
973 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
974 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
975 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
976 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
977 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
978 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
979 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
980 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
981 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
982 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
983 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
984 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
985 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
986 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
987 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
988 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
989 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
990 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
991 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
992 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
993 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
994 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
995 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
996 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
997 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
998 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
999 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1000 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1001 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1002 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1003 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1004 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1005 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
1006 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
1007 | + ]; |
|
1008 | + foreach ($aliases as $alias => $fqn) { |
|
1009 | + if (is_array($fqn)) { |
|
1010 | + foreach ($fqn as $class => $for_class) { |
|
1011 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
1012 | + } |
|
1013 | + continue; |
|
1014 | + } |
|
1015 | + $this->class_cache->addAlias($fqn, $alias); |
|
1016 | + } |
|
1017 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1018 | + $this->class_cache->addAlias( |
|
1019 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1020 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1021 | + ); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1028 | + * request Primarily used by unit tests. |
|
1029 | + */ |
|
1030 | + public function reset() |
|
1031 | + { |
|
1032 | + $this->_register_core_class_loaders(); |
|
1033 | + $this->_register_core_dependencies(); |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1039 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1040 | + * WHY? |
|
1041 | + * Because if a class is type hinting for a concretion, |
|
1042 | + * then why would we need to find another class to supply it? |
|
1043 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1044 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1045 | + * Don't go looking for some substitute. |
|
1046 | + * Whereas if a class is type hinting for an interface... |
|
1047 | + * then we need to find an actual class to use. |
|
1048 | + * So the interface IS the alias for some other FQN, |
|
1049 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1050 | + * represents some other class. |
|
1051 | + * |
|
1052 | + * @param string $fqn |
|
1053 | + * @param string $for_class |
|
1054 | + * @return bool |
|
1055 | + * @deprecated 4.9.62.p |
|
1056 | + */ |
|
1057 | + public function has_alias($fqn = '', $for_class = '') |
|
1058 | + { |
|
1059 | + return $this->isAlias($fqn, $for_class); |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1065 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1066 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1067 | + * for example: |
|
1068 | + * if the following two entries were added to the _aliases array: |
|
1069 | + * array( |
|
1070 | + * 'interface_alias' => 'some\namespace\interface' |
|
1071 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1072 | + * ) |
|
1073 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1074 | + * to load an instance of 'some\namespace\classname' |
|
1075 | + * |
|
1076 | + * @param string $alias |
|
1077 | + * @param string $for_class |
|
1078 | + * @return string |
|
1079 | + * @deprecated 4.9.62.p |
|
1080 | + */ |
|
1081 | + public function get_alias($alias = '', $for_class = '') |
|
1082 | + { |
|
1083 | + return $this->getFqnForAlias($alias, $for_class); |
|
1084 | + } |
|
1085 | 1085 | } |
@@ -13,369 +13,369 @@ |
||
13 | 13 | class EEM_Price extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - // private instance of the EEM_Price object |
|
17 | - protected static $_instance; |
|
16 | + // private instance of the EEM_Price object |
|
17 | + protected static $_instance; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * private constructor to prevent direct creation |
|
22 | - * |
|
23 | - * @Constructor |
|
24 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | - * (and any incoming timezone data that gets saved). |
|
26 | - * Note this just sends the timezone info to the date time model field objects. |
|
27 | - * Default is NULL |
|
28 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | - */ |
|
30 | - protected function __construct($timezone) |
|
31 | - { |
|
32 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | - $this->singular_item = __('Price', 'event_espresso'); |
|
34 | - $this->plural_item = __('Prices', 'event_espresso'); |
|
20 | + /** |
|
21 | + * private constructor to prevent direct creation |
|
22 | + * |
|
23 | + * @Constructor |
|
24 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | + * (and any incoming timezone data that gets saved). |
|
26 | + * Note this just sends the timezone info to the date time model field objects. |
|
27 | + * Default is NULL |
|
28 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | + */ |
|
30 | + protected function __construct($timezone) |
|
31 | + { |
|
32 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | + $this->singular_item = __('Price', 'event_espresso'); |
|
34 | + $this->plural_item = __('Prices', 'event_espresso'); |
|
35 | 35 | |
36 | - $this->_tables = [ |
|
37 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | - ]; |
|
39 | - $this->_fields = [ |
|
40 | - 'Price' => [ |
|
41 | - 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | - 'PRC_ID', |
|
43 | - 'Price ID' |
|
44 | - ), |
|
45 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'PRT_ID', |
|
47 | - esc_html__('Price type Id', 'event_espresso'), |
|
48 | - false, |
|
49 | - null, |
|
50 | - 'Price_Type' |
|
51 | - ), |
|
52 | - 'PRC_amount' => new EE_Money_Field( |
|
53 | - 'PRC_amount', |
|
54 | - esc_html__('Price Amount', 'event_espresso'), |
|
55 | - false, |
|
56 | - 0 |
|
57 | - ), |
|
58 | - 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | - 'PRC_name', |
|
60 | - esc_html__('Name of Price', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | - 'PRC_desc', |
|
66 | - esc_html__('Price Description', 'event_espresso'), |
|
67 | - false, |
|
68 | - '' |
|
69 | - ), |
|
70 | - 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | - 'PRC_is_default', |
|
72 | - esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | - false, |
|
74 | - false |
|
75 | - ), |
|
76 | - 'PRC_overrides' => new EE_Integer_Field( |
|
77 | - 'PRC_overrides', |
|
78 | - esc_html__( |
|
79 | - 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - true, |
|
83 | - 0 |
|
84 | - ), |
|
85 | - 'PRC_order' => new EE_Integer_Field( |
|
86 | - 'PRC_order', |
|
87 | - esc_html__( |
|
88 | - 'Order of Application of Price (lower numbers apply first?)', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - false, |
|
92 | - 1 |
|
93 | - ), |
|
94 | - 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | - 'PRC_deleted', |
|
96 | - esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | - false, |
|
98 | - false |
|
99 | - ), |
|
100 | - 'PRC_parent' => new EE_Integer_Field( |
|
101 | - 'PRC_parent', |
|
102 | - esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | - true, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | - 'PRC_wp_user', |
|
108 | - esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | - false |
|
110 | - ), |
|
111 | - ], |
|
112 | - ]; |
|
113 | - $this->_model_relations = [ |
|
114 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | - ]; |
|
118 | - // this model is generally available for reading |
|
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | - new EE_Restriction_Generator_Default_Public( |
|
121 | - 'PRC_is_default', |
|
122 | - 'Ticket.Datetime.Event' |
|
123 | - ); |
|
124 | - // account for default tickets in the caps |
|
125 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | - new EE_Restriction_Generator_Default_Protected( |
|
127 | - 'PRC_is_default', |
|
128 | - 'Ticket.Datetime.Event' |
|
129 | - ); |
|
130 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | - new EE_Restriction_Generator_Default_Protected( |
|
132 | - 'PRC_is_default', |
|
133 | - 'Ticket.Datetime.Event' |
|
134 | - ); |
|
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | - new EE_Restriction_Generator_Default_Protected( |
|
137 | - 'PRC_is_default', |
|
138 | - 'Ticket.Datetime.Event' |
|
139 | - ); |
|
140 | - parent::__construct($timezone); |
|
141 | - } |
|
36 | + $this->_tables = [ |
|
37 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | + ]; |
|
39 | + $this->_fields = [ |
|
40 | + 'Price' => [ |
|
41 | + 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | + 'PRC_ID', |
|
43 | + 'Price ID' |
|
44 | + ), |
|
45 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'PRT_ID', |
|
47 | + esc_html__('Price type Id', 'event_espresso'), |
|
48 | + false, |
|
49 | + null, |
|
50 | + 'Price_Type' |
|
51 | + ), |
|
52 | + 'PRC_amount' => new EE_Money_Field( |
|
53 | + 'PRC_amount', |
|
54 | + esc_html__('Price Amount', 'event_espresso'), |
|
55 | + false, |
|
56 | + 0 |
|
57 | + ), |
|
58 | + 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | + 'PRC_name', |
|
60 | + esc_html__('Name of Price', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | + 'PRC_desc', |
|
66 | + esc_html__('Price Description', 'event_espresso'), |
|
67 | + false, |
|
68 | + '' |
|
69 | + ), |
|
70 | + 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | + 'PRC_is_default', |
|
72 | + esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | + false, |
|
74 | + false |
|
75 | + ), |
|
76 | + 'PRC_overrides' => new EE_Integer_Field( |
|
77 | + 'PRC_overrides', |
|
78 | + esc_html__( |
|
79 | + 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + true, |
|
83 | + 0 |
|
84 | + ), |
|
85 | + 'PRC_order' => new EE_Integer_Field( |
|
86 | + 'PRC_order', |
|
87 | + esc_html__( |
|
88 | + 'Order of Application of Price (lower numbers apply first?)', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + false, |
|
92 | + 1 |
|
93 | + ), |
|
94 | + 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | + 'PRC_deleted', |
|
96 | + esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | + false, |
|
98 | + false |
|
99 | + ), |
|
100 | + 'PRC_parent' => new EE_Integer_Field( |
|
101 | + 'PRC_parent', |
|
102 | + esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | + true, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | + 'PRC_wp_user', |
|
108 | + esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | + false |
|
110 | + ), |
|
111 | + ], |
|
112 | + ]; |
|
113 | + $this->_model_relations = [ |
|
114 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | + ]; |
|
118 | + // this model is generally available for reading |
|
119 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | + new EE_Restriction_Generator_Default_Public( |
|
121 | + 'PRC_is_default', |
|
122 | + 'Ticket.Datetime.Event' |
|
123 | + ); |
|
124 | + // account for default tickets in the caps |
|
125 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | + new EE_Restriction_Generator_Default_Protected( |
|
127 | + 'PRC_is_default', |
|
128 | + 'Ticket.Datetime.Event' |
|
129 | + ); |
|
130 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | + new EE_Restriction_Generator_Default_Protected( |
|
132 | + 'PRC_is_default', |
|
133 | + 'Ticket.Datetime.Event' |
|
134 | + ); |
|
135 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | + new EE_Restriction_Generator_Default_Protected( |
|
137 | + 'PRC_is_default', |
|
138 | + 'Ticket.Datetime.Event' |
|
139 | + ); |
|
140 | + parent::__construct($timezone); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * instantiate a new price object with blank/empty properties |
|
146 | - * |
|
147 | - * @return mixed array on success, FALSE on fail |
|
148 | - */ |
|
149 | - public function get_new_price() |
|
150 | - { |
|
151 | - return $this->create_default_object(); |
|
152 | - } |
|
144 | + /** |
|
145 | + * instantiate a new price object with blank/empty properties |
|
146 | + * |
|
147 | + * @return mixed array on success, FALSE on fail |
|
148 | + */ |
|
149 | + public function get_new_price() |
|
150 | + { |
|
151 | + return $this->create_default_object(); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * retrieve ALL prices from db |
|
157 | - * |
|
158 | - * @return EE_Base_Class[]|EE_PRice[] |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public function get_all_prices() |
|
162 | - { |
|
163 | - // retrieve all prices |
|
164 | - return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
165 | - } |
|
155 | + /** |
|
156 | + * retrieve ALL prices from db |
|
157 | + * |
|
158 | + * @return EE_Base_Class[]|EE_PRice[] |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public function get_all_prices() |
|
162 | + { |
|
163 | + // retrieve all prices |
|
164 | + return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * retrieve all active prices for a particular event |
|
170 | - * |
|
171 | - * @param int $EVT_ID |
|
172 | - * @return array on success |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public function get_all_event_prices($EVT_ID = 0) |
|
176 | - { |
|
177 | - return $this->get_all( |
|
178 | - [ |
|
179 | - [ |
|
180 | - 'EVT_ID' => $EVT_ID, |
|
181 | - 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
182 | - ], |
|
183 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
184 | - ] |
|
185 | - ); |
|
186 | - } |
|
168 | + /** |
|
169 | + * retrieve all active prices for a particular event |
|
170 | + * |
|
171 | + * @param int $EVT_ID |
|
172 | + * @return array on success |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public function get_all_event_prices($EVT_ID = 0) |
|
176 | + { |
|
177 | + return $this->get_all( |
|
178 | + [ |
|
179 | + [ |
|
180 | + 'EVT_ID' => $EVT_ID, |
|
181 | + 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
182 | + ], |
|
183 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
184 | + ] |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
191 | - * |
|
192 | - * @param boolean $count return count |
|
193 | - * @param bool $include_taxes |
|
194 | - * @return bool|EE_Base_Class[]|EE_PRice[] |
|
195 | - * @throws EE_Error |
|
196 | - */ |
|
197 | - public function get_all_default_prices($count = false, $include_taxes = false) |
|
198 | - { |
|
199 | - $_where = [ |
|
200 | - 'PRC_deleted' => 0, |
|
201 | - 'PRC_is_default' => 1, |
|
202 | - ]; |
|
203 | - if (! $include_taxes) { |
|
204 | - $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
205 | - } |
|
206 | - $_query_params = [ |
|
207 | - $_where, |
|
208 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
209 | - ]; |
|
210 | - return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
211 | - } |
|
189 | + /** |
|
190 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
191 | + * |
|
192 | + * @param boolean $count return count |
|
193 | + * @param bool $include_taxes |
|
194 | + * @return bool|EE_Base_Class[]|EE_PRice[] |
|
195 | + * @throws EE_Error |
|
196 | + */ |
|
197 | + public function get_all_default_prices($count = false, $include_taxes = false) |
|
198 | + { |
|
199 | + $_where = [ |
|
200 | + 'PRC_deleted' => 0, |
|
201 | + 'PRC_is_default' => 1, |
|
202 | + ]; |
|
203 | + if (! $include_taxes) { |
|
204 | + $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
205 | + } |
|
206 | + $_query_params = [ |
|
207 | + $_where, |
|
208 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
209 | + ]; |
|
210 | + return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
211 | + } |
|
212 | 212 | |
213 | 213 | |
214 | - /** |
|
215 | - * retrieve all active global prices that are taxes |
|
216 | - * |
|
217 | - * @return bool|EE_Base_Class[]|EE_PRice[] |
|
218 | - * @throws EE_Error |
|
219 | - * @since $VID:$ |
|
220 | - */ |
|
221 | - public function getAllDefaultTaxes() |
|
222 | - { |
|
223 | - return $this->get_all( |
|
224 | - [ |
|
225 | - [ |
|
226 | - 'PRC_deleted' => 0, |
|
227 | - 'PRC_is_default' => 1, |
|
228 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax |
|
229 | - ], |
|
230 | - 'order_by' => [ |
|
231 | - 'Price_Type.PRT_order' => 'ASC', |
|
232 | - 'PRC_order' => 'ASC' |
|
233 | - ], |
|
234 | - ] |
|
235 | - ); |
|
236 | - } |
|
214 | + /** |
|
215 | + * retrieve all active global prices that are taxes |
|
216 | + * |
|
217 | + * @return bool|EE_Base_Class[]|EE_PRice[] |
|
218 | + * @throws EE_Error |
|
219 | + * @since $VID:$ |
|
220 | + */ |
|
221 | + public function getAllDefaultTaxes() |
|
222 | + { |
|
223 | + return $this->get_all( |
|
224 | + [ |
|
225 | + [ |
|
226 | + 'PRC_deleted' => 0, |
|
227 | + 'PRC_is_default' => 1, |
|
228 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax |
|
229 | + ], |
|
230 | + 'order_by' => [ |
|
231 | + 'Price_Type.PRT_order' => 'ASC', |
|
232 | + 'PRC_order' => 'ASC' |
|
233 | + ], |
|
234 | + ] |
|
235 | + ); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * retrieve all prices that are taxes |
|
241 | - * |
|
242 | - * @return EE_Base_Class[]|EE_PRice[] |
|
243 | - * @throws EE_Error |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws ReflectionException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function get_all_prices_that_are_taxes() |
|
250 | - { |
|
251 | - $taxes = []; |
|
252 | - $all_taxes = $this->get_all( |
|
253 | - [ |
|
254 | - ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => 1], |
|
255 | - 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
256 | - ] |
|
257 | - ); |
|
258 | - foreach ($all_taxes as $tax) { |
|
259 | - if ($tax instanceof EE_Price) { |
|
260 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
261 | - } |
|
262 | - } |
|
263 | - return $taxes; |
|
264 | - } |
|
239 | + /** |
|
240 | + * retrieve all prices that are taxes |
|
241 | + * |
|
242 | + * @return EE_Base_Class[]|EE_PRice[] |
|
243 | + * @throws EE_Error |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws ReflectionException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function get_all_prices_that_are_taxes() |
|
250 | + { |
|
251 | + $taxes = []; |
|
252 | + $all_taxes = $this->get_all( |
|
253 | + [ |
|
254 | + ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => 1], |
|
255 | + 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
256 | + ] |
|
257 | + ); |
|
258 | + foreach ($all_taxes as $tax) { |
|
259 | + if ($tax instanceof EE_Price) { |
|
260 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
261 | + } |
|
262 | + } |
|
263 | + return $taxes; |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | - /** |
|
268 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
269 | - * |
|
270 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
271 | - * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
272 | - * @throws EE_Error |
|
273 | - */ |
|
274 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
275 | - { |
|
276 | - $array_of_price_objects = []; |
|
277 | - if (empty($TKT_ID)) { |
|
278 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
279 | - // return that list |
|
280 | - $default_prices = $this->get_all_default_prices(); |
|
267 | + /** |
|
268 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
269 | + * |
|
270 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
271 | + * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
272 | + * @throws EE_Error |
|
273 | + */ |
|
274 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
275 | + { |
|
276 | + $array_of_price_objects = []; |
|
277 | + if (empty($TKT_ID)) { |
|
278 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
279 | + // return that list |
|
280 | + $default_prices = $this->get_all_default_prices(); |
|
281 | 281 | |
282 | - if ($default_prices) { |
|
283 | - foreach ($default_prices as $price) { |
|
284 | - if ($price instanceof EE_Price) { |
|
285 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
286 | - } |
|
287 | - } |
|
288 | - return $array_of_price_objects; |
|
289 | - } |
|
290 | - return []; |
|
291 | - } |
|
292 | - $ticket_prices = $this->get_all( |
|
293 | - [ |
|
294 | - [ |
|
295 | - 'TKT_ID' => $TKT_ID, |
|
296 | - 'PRC_deleted' => 0, |
|
297 | - ], |
|
298 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
299 | - ] |
|
300 | - ); |
|
282 | + if ($default_prices) { |
|
283 | + foreach ($default_prices as $price) { |
|
284 | + if ($price instanceof EE_Price) { |
|
285 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
286 | + } |
|
287 | + } |
|
288 | + return $array_of_price_objects; |
|
289 | + } |
|
290 | + return []; |
|
291 | + } |
|
292 | + $ticket_prices = $this->get_all( |
|
293 | + [ |
|
294 | + [ |
|
295 | + 'TKT_ID' => $TKT_ID, |
|
296 | + 'PRC_deleted' => 0, |
|
297 | + ], |
|
298 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
299 | + ] |
|
300 | + ); |
|
301 | 301 | |
302 | - if (! empty($ticket_prices)) { |
|
303 | - foreach ($ticket_prices as $price) { |
|
304 | - if ($price instanceof EE_Price) { |
|
305 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
306 | - } |
|
307 | - } |
|
308 | - return $array_of_price_objects; |
|
309 | - } |
|
310 | - return false; |
|
311 | - } |
|
302 | + if (! empty($ticket_prices)) { |
|
303 | + foreach ($ticket_prices as $price) { |
|
304 | + if ($price instanceof EE_Price) { |
|
305 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
306 | + } |
|
307 | + } |
|
308 | + return $array_of_price_objects; |
|
309 | + } |
|
310 | + return false; |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * _sort_event_prices_by_type |
|
316 | - * |
|
317 | - * @param EE_Price $price_a |
|
318 | - * @param EE_Price $price_b |
|
319 | - * @return bool false on fail |
|
320 | - */ |
|
321 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
322 | - { |
|
323 | - if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
324 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
325 | - } |
|
326 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
327 | - } |
|
314 | + /** |
|
315 | + * _sort_event_prices_by_type |
|
316 | + * |
|
317 | + * @param EE_Price $price_a |
|
318 | + * @param EE_Price $price_b |
|
319 | + * @return bool false on fail |
|
320 | + */ |
|
321 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
322 | + { |
|
323 | + if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
324 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
325 | + } |
|
326 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
327 | + } |
|
328 | 328 | |
329 | 329 | |
330 | - /** |
|
331 | - * _sort_event_prices_by_order |
|
332 | - * |
|
333 | - * @param EE_Price $price_a |
|
334 | - * @param EE_Price $price_b |
|
335 | - * @return bool false on fail |
|
336 | - */ |
|
337 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
338 | - { |
|
339 | - if ($price_a->order() === $price_b->order()) { |
|
340 | - return 0; |
|
341 | - } |
|
342 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
343 | - } |
|
330 | + /** |
|
331 | + * _sort_event_prices_by_order |
|
332 | + * |
|
333 | + * @param EE_Price $price_a |
|
334 | + * @param EE_Price $price_b |
|
335 | + * @return bool false on fail |
|
336 | + */ |
|
337 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
338 | + { |
|
339 | + if ($price_a->order() === $price_b->order()) { |
|
340 | + return 0; |
|
341 | + } |
|
342 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
343 | + } |
|
344 | 344 | |
345 | 345 | |
346 | - /** |
|
347 | - * get all prices of a specific type |
|
348 | - * |
|
349 | - * @param int $type - PRT_ID |
|
350 | - * @return EE_Base_Class[]|EE_PRice[] |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function get_all_prices_that_are_type($type = 0) |
|
354 | - { |
|
355 | - return $this->get_all( |
|
356 | - [ |
|
357 | - [ |
|
358 | - 'PRT_ID' => $type, |
|
359 | - ], |
|
360 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
361 | - ] |
|
362 | - ); |
|
363 | - } |
|
346 | + /** |
|
347 | + * get all prices of a specific type |
|
348 | + * |
|
349 | + * @param int $type - PRT_ID |
|
350 | + * @return EE_Base_Class[]|EE_PRice[] |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function get_all_prices_that_are_type($type = 0) |
|
354 | + { |
|
355 | + return $this->get_all( |
|
356 | + [ |
|
357 | + [ |
|
358 | + 'PRT_ID' => $type, |
|
359 | + ], |
|
360 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
361 | + ] |
|
362 | + ); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | - /** |
|
367 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
368 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
369 | - * |
|
370 | - * @return array which can be used like so: $this->get_all(array(array(...where |
|
371 | - * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
372 | - */ |
|
373 | - public function _order_by_array_for_get_all_method() |
|
374 | - { |
|
375 | - return [ |
|
376 | - 'PRC_order' => 'ASC', |
|
377 | - 'Price_Type.PRT_order' => 'ASC', |
|
378 | - 'PRC_ID' => 'ASC', |
|
379 | - ]; |
|
380 | - } |
|
366 | + /** |
|
367 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
368 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
369 | + * |
|
370 | + * @return array which can be used like so: $this->get_all(array(array(...where |
|
371 | + * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
372 | + */ |
|
373 | + public function _order_by_array_for_get_all_method() |
|
374 | + { |
|
375 | + return [ |
|
376 | + 'PRC_order' => 'ASC', |
|
377 | + 'Price_Type.PRT_order' => 'ASC', |
|
378 | + 'PRC_ID' => 'ASC', |
|
379 | + ]; |
|
380 | + } |
|
381 | 381 | } |
@@ -28,616 +28,616 @@ |
||
28 | 28 | class EEM_Line_Item extends EEM_Base |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | - */ |
|
36 | - const type_tax_sub_total = 'tax-sub-total'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | - */ |
|
43 | - const type_tax = 'tax'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Indicating individual items purchased, or discounts or surcharges. |
|
47 | - * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | - * Possible children are sub-line-items and cancellations. |
|
49 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | - * LIN_totals. Its LIN_percent = 0. |
|
51 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | - */ |
|
54 | - const type_line_item = 'line-item'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Line item indicating all the factors that make a single line item. |
|
58 | - * Sub-line items should have NO children line items. |
|
59 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | - */ |
|
65 | - const type_sub_line_item = 'sub-item'; |
|
66 | - |
|
67 | - /** |
|
68 | - * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
69 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
70 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
71 | - */ |
|
72 | - const type_sub_tax = 'sub-tax'; |
|
73 | - |
|
74 | - /** |
|
75 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
76 | - * Direct children should be event subtotals. |
|
77 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
78 | - */ |
|
79 | - const type_sub_total = 'sub-total'; |
|
80 | - |
|
81 | - /** |
|
82 | - * Line item for the grand total of an order. |
|
83 | - * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
84 | - * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
85 | - * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
86 | - */ |
|
87 | - const type_total = 'total'; |
|
88 | - |
|
89 | - /** |
|
90 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
91 | - * should be created, indicating the quantity that were cancelled |
|
92 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
93 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
94 | - * cancelled, and only one remains). |
|
95 | - * When items are refunded, a cancellation line item should be made, which points |
|
96 | - * to teh payment model object which actually refunded the payment. |
|
97 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
98 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
99 | - * Their LIN_percent should be 0. |
|
100 | - */ |
|
101 | - const type_cancellation = 'cancellation'; |
|
102 | - |
|
103 | - // various line item object types |
|
104 | - const OBJ_TYPE_EVENT = 'Event'; |
|
105 | - |
|
106 | - const OBJ_TYPE_PRICE = 'Price'; |
|
107 | - |
|
108 | - const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
109 | - |
|
110 | - const OBJ_TYPE_TICKET = 'Ticket'; |
|
111 | - |
|
112 | - const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
113 | - |
|
114 | - /** |
|
115 | - * @var EEM_Line_Item $_instance |
|
116 | - */ |
|
117 | - protected static $_instance; |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * private constructor to prevent direct creation |
|
122 | - * |
|
123 | - * @Constructor |
|
124 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
125 | - * (and any incoming timezone data that gets saved). |
|
126 | - * Note this just sends the timezone info to the date time model field objects. |
|
127 | - * Default is NULL |
|
128 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
129 | - * @throws EE_Error |
|
130 | - * @throws InvalidArgumentException |
|
131 | - */ |
|
132 | - protected function __construct($timezone) |
|
133 | - { |
|
134 | - $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
135 | - $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
136 | - |
|
137 | - $this->_tables = array( |
|
138 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
139 | - ); |
|
140 | - $line_items_can_be_for = apply_filters( |
|
141 | - 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
142 | - array('Ticket', 'Price', 'Event') |
|
143 | - ); |
|
144 | - $this->_fields = array( |
|
145 | - 'Line_Item' => array( |
|
146 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
147 | - 'LIN_ID', |
|
148 | - esc_html__('ID', 'event_espresso') |
|
149 | - ), |
|
150 | - 'LIN_code' => new EE_Slug_Field( |
|
151 | - 'LIN_code', |
|
152 | - esc_html__('Code for index into Cart', 'event_espresso'), |
|
153 | - true |
|
154 | - ), |
|
155 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
156 | - 'TXN_ID', |
|
157 | - esc_html__('Transaction ID', 'event_espresso'), |
|
158 | - true, |
|
159 | - null, |
|
160 | - 'Transaction' |
|
161 | - ), |
|
162 | - 'LIN_name' => new EE_Full_HTML_Field( |
|
163 | - 'LIN_name', |
|
164 | - esc_html__('Line Item Name', 'event_espresso'), |
|
165 | - false, |
|
166 | - '' |
|
167 | - ), |
|
168 | - 'LIN_desc' => new EE_Full_HTML_Field( |
|
169 | - 'LIN_desc', |
|
170 | - esc_html__('Line Item Description', 'event_espresso'), |
|
171 | - true |
|
172 | - ), |
|
173 | - 'LIN_unit_price' => new EE_Money_Field( |
|
174 | - 'LIN_unit_price', |
|
175 | - esc_html__('Unit Price', 'event_espresso'), |
|
176 | - false, |
|
177 | - 0 |
|
178 | - ), |
|
179 | - 'LIN_percent' => new EE_Float_Field( |
|
180 | - 'LIN_percent', |
|
181 | - esc_html__('Percent', 'event_espresso'), |
|
182 | - false, |
|
183 | - 0 |
|
184 | - ), |
|
185 | - 'LIN_is_taxable' => new EE_Boolean_Field( |
|
186 | - 'LIN_is_taxable', |
|
187 | - esc_html__('Taxable', 'event_espresso'), |
|
188 | - false, |
|
189 | - false |
|
190 | - ), |
|
191 | - 'LIN_order' => new EE_Integer_Field( |
|
192 | - 'LIN_order', |
|
193 | - esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
194 | - false, |
|
195 | - 1 |
|
196 | - ), |
|
197 | - 'LIN_total' => new EE_Money_Field( |
|
198 | - 'LIN_total', |
|
199 | - esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
200 | - false, |
|
201 | - 0 |
|
202 | - ), |
|
203 | - 'LIN_pretax' => new EE_Money_Field( |
|
204 | - 'LIN_pretax', |
|
205 | - esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
206 | - false, |
|
207 | - 0 |
|
208 | - ), |
|
209 | - 'LIN_quantity' => new EE_Integer_Field( |
|
210 | - 'LIN_quantity', |
|
211 | - esc_html__('Quantity', 'event_espresso'), |
|
212 | - true, |
|
213 | - 1 |
|
214 | - ), |
|
215 | - 'LIN_parent' => new EE_Integer_Field( |
|
216 | - 'LIN_parent', |
|
217 | - esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
218 | - true, |
|
219 | - null |
|
220 | - ), |
|
221 | - 'LIN_type' => new EE_Enum_Text_Field( |
|
222 | - 'LIN_type', |
|
223 | - esc_html__('Type', 'event_espresso'), |
|
224 | - false, |
|
225 | - 'line-item', |
|
226 | - array( |
|
227 | - self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
228 | - self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
229 | - self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
230 | - self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
231 | - self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
232 | - self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
233 | - self::type_total => esc_html__('Total', 'event_espresso'), |
|
234 | - self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
235 | - ) |
|
236 | - ), |
|
237 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
238 | - 'OBJ_ID', |
|
239 | - esc_html__('ID of Item purchased.', 'event_espresso'), |
|
240 | - true, |
|
241 | - null, |
|
242 | - $line_items_can_be_for |
|
243 | - ), |
|
244 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
245 | - 'OBJ_type', |
|
246 | - esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
247 | - true, |
|
248 | - null, |
|
249 | - $line_items_can_be_for |
|
250 | - ), |
|
251 | - 'LIN_timestamp' => new EE_Datetime_Field( |
|
252 | - 'LIN_timestamp', |
|
253 | - esc_html__('When the line item was created', 'event_espresso'), |
|
254 | - false, |
|
255 | - EE_Datetime_Field::now, |
|
256 | - $timezone |
|
257 | - ), |
|
258 | - ), |
|
259 | - ); |
|
260 | - $this->_model_relations = array( |
|
261 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
262 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
263 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
264 | - 'Event' => new EE_Belongs_To_Any_Relation(), |
|
265 | - ); |
|
266 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
267 | - $this->_caps_slug = 'transactions'; |
|
268 | - parent::__construct($timezone); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Gets all the line items for this transaction of the given type |
|
274 | - * |
|
275 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
276 | - * @param EE_Transaction|int $transaction |
|
277 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws InvalidInterfaceException |
|
282 | - */ |
|
283 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
284 | - { |
|
285 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
286 | - return $this->get_all(array( |
|
287 | - array( |
|
288 | - 'LIN_type' => $line_item_type, |
|
289 | - 'TXN_ID' => $transaction, |
|
290 | - ), |
|
291 | - )); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Gets all line items unrelated to tickets that are normal line items |
|
297 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
298 | - * |
|
299 | - * @param EE_Transaction|int $transaction |
|
300 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
301 | - * @throws EE_Error |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - */ |
|
306 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
307 | - { |
|
308 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
309 | - return $this->get_all(array( |
|
310 | - array( |
|
311 | - 'LIN_type' => self::type_line_item, |
|
312 | - 'TXN_ID' => $transaction, |
|
313 | - 'OR' => array( |
|
314 | - 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
315 | - 'OBJ_type*null' => array('IS_NULL'), |
|
316 | - ), |
|
317 | - ), |
|
318 | - )); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
324 | - * This needs to be very efficient |
|
325 | - * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
326 | - * deleting and joining tables like this. |
|
327 | - * |
|
328 | - * @return int count of how many deleted |
|
329 | - * @throws EE_Error |
|
330 | - * @throws InvalidArgumentException |
|
331 | - * @throws InvalidDataTypeException |
|
332 | - * @throws InvalidInterfaceException |
|
333 | - */ |
|
334 | - public function delete_line_items_with_no_transaction() |
|
335 | - { |
|
336 | - /** @type WPDB $wpdb */ |
|
337 | - global $wpdb; |
|
338 | - $time_to_leave_alone = apply_filters( |
|
339 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
340 | - WEEK_IN_SECONDS |
|
341 | - ); |
|
342 | - $query = $wpdb->prepare( |
|
343 | - 'DELETE li |
|
31 | + /** |
|
32 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | + */ |
|
36 | + const type_tax_sub_total = 'tax-sub-total'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | + */ |
|
43 | + const type_tax = 'tax'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Indicating individual items purchased, or discounts or surcharges. |
|
47 | + * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | + * Possible children are sub-line-items and cancellations. |
|
49 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | + * LIN_totals. Its LIN_percent = 0. |
|
51 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | + */ |
|
54 | + const type_line_item = 'line-item'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Line item indicating all the factors that make a single line item. |
|
58 | + * Sub-line items should have NO children line items. |
|
59 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | + */ |
|
65 | + const type_sub_line_item = 'sub-item'; |
|
66 | + |
|
67 | + /** |
|
68 | + * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
69 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
70 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
71 | + */ |
|
72 | + const type_sub_tax = 'sub-tax'; |
|
73 | + |
|
74 | + /** |
|
75 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
76 | + * Direct children should be event subtotals. |
|
77 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
78 | + */ |
|
79 | + const type_sub_total = 'sub-total'; |
|
80 | + |
|
81 | + /** |
|
82 | + * Line item for the grand total of an order. |
|
83 | + * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
84 | + * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
85 | + * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
86 | + */ |
|
87 | + const type_total = 'total'; |
|
88 | + |
|
89 | + /** |
|
90 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
91 | + * should be created, indicating the quantity that were cancelled |
|
92 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
93 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
94 | + * cancelled, and only one remains). |
|
95 | + * When items are refunded, a cancellation line item should be made, which points |
|
96 | + * to teh payment model object which actually refunded the payment. |
|
97 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
98 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
99 | + * Their LIN_percent should be 0. |
|
100 | + */ |
|
101 | + const type_cancellation = 'cancellation'; |
|
102 | + |
|
103 | + // various line item object types |
|
104 | + const OBJ_TYPE_EVENT = 'Event'; |
|
105 | + |
|
106 | + const OBJ_TYPE_PRICE = 'Price'; |
|
107 | + |
|
108 | + const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
109 | + |
|
110 | + const OBJ_TYPE_TICKET = 'Ticket'; |
|
111 | + |
|
112 | + const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
113 | + |
|
114 | + /** |
|
115 | + * @var EEM_Line_Item $_instance |
|
116 | + */ |
|
117 | + protected static $_instance; |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * private constructor to prevent direct creation |
|
122 | + * |
|
123 | + * @Constructor |
|
124 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
125 | + * (and any incoming timezone data that gets saved). |
|
126 | + * Note this just sends the timezone info to the date time model field objects. |
|
127 | + * Default is NULL |
|
128 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
129 | + * @throws EE_Error |
|
130 | + * @throws InvalidArgumentException |
|
131 | + */ |
|
132 | + protected function __construct($timezone) |
|
133 | + { |
|
134 | + $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
135 | + $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
136 | + |
|
137 | + $this->_tables = array( |
|
138 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
139 | + ); |
|
140 | + $line_items_can_be_for = apply_filters( |
|
141 | + 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
142 | + array('Ticket', 'Price', 'Event') |
|
143 | + ); |
|
144 | + $this->_fields = array( |
|
145 | + 'Line_Item' => array( |
|
146 | + 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
147 | + 'LIN_ID', |
|
148 | + esc_html__('ID', 'event_espresso') |
|
149 | + ), |
|
150 | + 'LIN_code' => new EE_Slug_Field( |
|
151 | + 'LIN_code', |
|
152 | + esc_html__('Code for index into Cart', 'event_espresso'), |
|
153 | + true |
|
154 | + ), |
|
155 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
156 | + 'TXN_ID', |
|
157 | + esc_html__('Transaction ID', 'event_espresso'), |
|
158 | + true, |
|
159 | + null, |
|
160 | + 'Transaction' |
|
161 | + ), |
|
162 | + 'LIN_name' => new EE_Full_HTML_Field( |
|
163 | + 'LIN_name', |
|
164 | + esc_html__('Line Item Name', 'event_espresso'), |
|
165 | + false, |
|
166 | + '' |
|
167 | + ), |
|
168 | + 'LIN_desc' => new EE_Full_HTML_Field( |
|
169 | + 'LIN_desc', |
|
170 | + esc_html__('Line Item Description', 'event_espresso'), |
|
171 | + true |
|
172 | + ), |
|
173 | + 'LIN_unit_price' => new EE_Money_Field( |
|
174 | + 'LIN_unit_price', |
|
175 | + esc_html__('Unit Price', 'event_espresso'), |
|
176 | + false, |
|
177 | + 0 |
|
178 | + ), |
|
179 | + 'LIN_percent' => new EE_Float_Field( |
|
180 | + 'LIN_percent', |
|
181 | + esc_html__('Percent', 'event_espresso'), |
|
182 | + false, |
|
183 | + 0 |
|
184 | + ), |
|
185 | + 'LIN_is_taxable' => new EE_Boolean_Field( |
|
186 | + 'LIN_is_taxable', |
|
187 | + esc_html__('Taxable', 'event_espresso'), |
|
188 | + false, |
|
189 | + false |
|
190 | + ), |
|
191 | + 'LIN_order' => new EE_Integer_Field( |
|
192 | + 'LIN_order', |
|
193 | + esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
194 | + false, |
|
195 | + 1 |
|
196 | + ), |
|
197 | + 'LIN_total' => new EE_Money_Field( |
|
198 | + 'LIN_total', |
|
199 | + esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
200 | + false, |
|
201 | + 0 |
|
202 | + ), |
|
203 | + 'LIN_pretax' => new EE_Money_Field( |
|
204 | + 'LIN_pretax', |
|
205 | + esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
206 | + false, |
|
207 | + 0 |
|
208 | + ), |
|
209 | + 'LIN_quantity' => new EE_Integer_Field( |
|
210 | + 'LIN_quantity', |
|
211 | + esc_html__('Quantity', 'event_espresso'), |
|
212 | + true, |
|
213 | + 1 |
|
214 | + ), |
|
215 | + 'LIN_parent' => new EE_Integer_Field( |
|
216 | + 'LIN_parent', |
|
217 | + esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
218 | + true, |
|
219 | + null |
|
220 | + ), |
|
221 | + 'LIN_type' => new EE_Enum_Text_Field( |
|
222 | + 'LIN_type', |
|
223 | + esc_html__('Type', 'event_espresso'), |
|
224 | + false, |
|
225 | + 'line-item', |
|
226 | + array( |
|
227 | + self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
228 | + self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
229 | + self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
230 | + self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
231 | + self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
232 | + self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
233 | + self::type_total => esc_html__('Total', 'event_espresso'), |
|
234 | + self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
235 | + ) |
|
236 | + ), |
|
237 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
238 | + 'OBJ_ID', |
|
239 | + esc_html__('ID of Item purchased.', 'event_espresso'), |
|
240 | + true, |
|
241 | + null, |
|
242 | + $line_items_can_be_for |
|
243 | + ), |
|
244 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
245 | + 'OBJ_type', |
|
246 | + esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
247 | + true, |
|
248 | + null, |
|
249 | + $line_items_can_be_for |
|
250 | + ), |
|
251 | + 'LIN_timestamp' => new EE_Datetime_Field( |
|
252 | + 'LIN_timestamp', |
|
253 | + esc_html__('When the line item was created', 'event_espresso'), |
|
254 | + false, |
|
255 | + EE_Datetime_Field::now, |
|
256 | + $timezone |
|
257 | + ), |
|
258 | + ), |
|
259 | + ); |
|
260 | + $this->_model_relations = array( |
|
261 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
262 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
263 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
264 | + 'Event' => new EE_Belongs_To_Any_Relation(), |
|
265 | + ); |
|
266 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
267 | + $this->_caps_slug = 'transactions'; |
|
268 | + parent::__construct($timezone); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Gets all the line items for this transaction of the given type |
|
274 | + * |
|
275 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
276 | + * @param EE_Transaction|int $transaction |
|
277 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws InvalidInterfaceException |
|
282 | + */ |
|
283 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
284 | + { |
|
285 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
286 | + return $this->get_all(array( |
|
287 | + array( |
|
288 | + 'LIN_type' => $line_item_type, |
|
289 | + 'TXN_ID' => $transaction, |
|
290 | + ), |
|
291 | + )); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Gets all line items unrelated to tickets that are normal line items |
|
297 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
298 | + * |
|
299 | + * @param EE_Transaction|int $transaction |
|
300 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
301 | + * @throws EE_Error |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + */ |
|
306 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
307 | + { |
|
308 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
309 | + return $this->get_all(array( |
|
310 | + array( |
|
311 | + 'LIN_type' => self::type_line_item, |
|
312 | + 'TXN_ID' => $transaction, |
|
313 | + 'OR' => array( |
|
314 | + 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
315 | + 'OBJ_type*null' => array('IS_NULL'), |
|
316 | + ), |
|
317 | + ), |
|
318 | + )); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
324 | + * This needs to be very efficient |
|
325 | + * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
326 | + * deleting and joining tables like this. |
|
327 | + * |
|
328 | + * @return int count of how many deleted |
|
329 | + * @throws EE_Error |
|
330 | + * @throws InvalidArgumentException |
|
331 | + * @throws InvalidDataTypeException |
|
332 | + * @throws InvalidInterfaceException |
|
333 | + */ |
|
334 | + public function delete_line_items_with_no_transaction() |
|
335 | + { |
|
336 | + /** @type WPDB $wpdb */ |
|
337 | + global $wpdb; |
|
338 | + $time_to_leave_alone = apply_filters( |
|
339 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
340 | + WEEK_IN_SECONDS |
|
341 | + ); |
|
342 | + $query = $wpdb->prepare( |
|
343 | + 'DELETE li |
|
344 | 344 | FROM ' . $this->table() . ' li |
345 | 345 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
346 | 346 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
347 | - // use GMT time because that's what TXN_timestamps are in |
|
348 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
349 | - ); |
|
350 | - return $wpdb->query($query); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * get_line_item_for_transaction_object |
|
356 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
357 | - * |
|
358 | - * @param int $TXN_ID |
|
359 | - * @param EE_Base_Class $object |
|
360 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
361 | - * @throws EE_Error |
|
362 | - * @throws InvalidArgumentException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidInterfaceException |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
368 | - { |
|
369 | - return $this->get_all(array( |
|
370 | - array( |
|
371 | - 'TXN_ID' => $TXN_ID, |
|
372 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
373 | - 'OBJ_ID' => $object->ID(), |
|
374 | - ), |
|
375 | - )); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * get_object_line_items_for_transaction |
|
381 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
382 | - * |
|
383 | - * @param int $TXN_ID |
|
384 | - * @param string $OBJ_type |
|
385 | - * @param array $OBJ_IDs |
|
386 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function get_object_line_items_for_transaction( |
|
390 | - $TXN_ID, |
|
391 | - $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
392 | - $OBJ_IDs = array() |
|
393 | - ) { |
|
394 | - $query_params = array( |
|
395 | - 'OBJ_type' => $OBJ_type, |
|
396 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
397 | - 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
398 | - ); |
|
399 | - if ($TXN_ID) { |
|
400 | - $query_params['TXN_ID'] = $TXN_ID; |
|
401 | - } |
|
402 | - return $this->get_all(array($query_params)); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * get_all_ticket_line_items_for_transaction |
|
408 | - * |
|
409 | - * @param EE_Transaction $transaction |
|
410 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
411 | - * @throws EE_Error |
|
412 | - * @throws InvalidArgumentException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws InvalidInterfaceException |
|
415 | - * @throws ReflectionException |
|
416 | - */ |
|
417 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
418 | - { |
|
419 | - return $this->get_all(array( |
|
420 | - array( |
|
421 | - 'TXN_ID' => $transaction->ID(), |
|
422 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
423 | - ), |
|
424 | - )); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * get_ticket_line_item_for_transaction |
|
430 | - * |
|
431 | - * @param int $TXN_ID |
|
432 | - * @param int $TKT_ID |
|
433 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
434 | - * @throws EE_Error |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws InvalidInterfaceException |
|
438 | - */ |
|
439 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
440 | - { |
|
441 | - return $this->get_one(array( |
|
442 | - array( |
|
443 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
444 | - 'OBJ_ID' => $TKT_ID, |
|
445 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
446 | - ), |
|
447 | - )); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * get_existing_promotion_line_item |
|
453 | - * searches the cart for existing line items for the specified promotion |
|
454 | - * |
|
455 | - * @since 1.0.0 |
|
456 | - * @param EE_Line_Item $parent_line_item |
|
457 | - * @param EE_Promotion $promotion |
|
458 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
459 | - * @throws EE_Error |
|
460 | - * @throws InvalidArgumentException |
|
461 | - * @throws InvalidDataTypeException |
|
462 | - * @throws InvalidInterfaceException |
|
463 | - * @throws ReflectionException |
|
464 | - */ |
|
465 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
466 | - { |
|
467 | - return $this->get_one(array( |
|
468 | - array( |
|
469 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
470 | - 'LIN_parent' => $parent_line_item->ID(), |
|
471 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
472 | - 'OBJ_ID' => $promotion->ID(), |
|
473 | - ), |
|
474 | - )); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * get_all_promotion_line_items |
|
480 | - * searches the cart for any and all existing promotion line items |
|
481 | - * |
|
482 | - * @since 1.0.0 |
|
483 | - * @param EE_Line_Item $parent_line_item |
|
484 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
492 | - { |
|
493 | - return $this->get_all(array( |
|
494 | - array( |
|
495 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
496 | - 'LIN_parent' => $parent_line_item->ID(), |
|
497 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
498 | - ), |
|
499 | - )); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Gets the registration's corresponding line item. |
|
505 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
506 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
507 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
508 | - * |
|
509 | - * @param EE_Registration $registration |
|
510 | - * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
511 | - * @throws EE_Error |
|
512 | - */ |
|
513 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
514 | - { |
|
515 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
521 | - * |
|
522 | - * @param EE_Registration $registration |
|
523 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
524 | - * @return array @see |
|
525 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
526 | - * @throws EE_Error |
|
527 | - */ |
|
528 | - public function line_item_for_registration_query_params( |
|
529 | - EE_Registration $registration, |
|
530 | - $original_query_params = array() |
|
531 | - ) { |
|
532 | - return array_replace_recursive($original_query_params, array( |
|
533 | - array( |
|
534 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
535 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
536 | - 'TXN_ID' => $registration->transaction_ID(), |
|
537 | - ), |
|
538 | - )); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
544 | - * @throws InvalidInterfaceException |
|
545 | - * @throws InvalidDataTypeException |
|
546 | - * @throws EE_Error |
|
547 | - * @throws InvalidArgumentException |
|
548 | - */ |
|
549 | - public function get_total_line_items_with_no_transaction() |
|
550 | - { |
|
551 | - return $this->get_total_line_items_for_carts(); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
557 | - * @throws InvalidInterfaceException |
|
558 | - * @throws InvalidDataTypeException |
|
559 | - * @throws EE_Error |
|
560 | - * @throws InvalidArgumentException |
|
561 | - */ |
|
562 | - public function get_total_line_items_for_active_carts() |
|
563 | - { |
|
564 | - return $this->get_total_line_items_for_carts(false); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
570 | - * @throws InvalidInterfaceException |
|
571 | - * @throws InvalidDataTypeException |
|
572 | - * @throws EE_Error |
|
573 | - * @throws InvalidArgumentException |
|
574 | - */ |
|
575 | - public function get_total_line_items_for_expired_carts() |
|
576 | - { |
|
577 | - return $this->get_total_line_items_for_carts(true); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
583 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
584 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
585 | - * |
|
586 | - * @param null $expired |
|
587 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
588 | - * @throws EE_Error |
|
589 | - * @throws InvalidArgumentException |
|
590 | - * @throws InvalidDataTypeException |
|
591 | - * @throws InvalidInterfaceException |
|
592 | - */ |
|
593 | - private function get_total_line_items_for_carts($expired = null) |
|
594 | - { |
|
595 | - $where_params = array( |
|
596 | - 'TXN_ID' => 0, |
|
597 | - 'LIN_type' => 'total', |
|
598 | - ); |
|
599 | - if ($expired !== null) { |
|
600 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
601 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
602 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
603 | - ); |
|
604 | - $where_params['LIN_timestamp'] = array( |
|
605 | - $expired ? '<=' : '>', |
|
606 | - $session_lifespan->expiration(), |
|
607 | - ); |
|
608 | - } |
|
609 | - return $this->get_all(array($where_params)); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
615 | - * AND the timestamp is older than the session lifespan. |
|
616 | - * |
|
617 | - * @param int $timestamp |
|
618 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
619 | - * @throws EE_Error |
|
620 | - * @throws InvalidArgumentException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws InvalidInterfaceException |
|
623 | - */ |
|
624 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
625 | - { |
|
626 | - if (! absint($timestamp)) { |
|
627 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
628 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
629 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
630 | - ); |
|
631 | - $timestamp = $session_lifespan->expiration(); |
|
632 | - } |
|
633 | - return $this->get_all( |
|
634 | - array( |
|
635 | - array( |
|
636 | - 'TXN_ID' => 0, |
|
637 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
638 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
639 | - ), |
|
640 | - ) |
|
641 | - ); |
|
642 | - } |
|
347 | + // use GMT time because that's what TXN_timestamps are in |
|
348 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
349 | + ); |
|
350 | + return $wpdb->query($query); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * get_line_item_for_transaction_object |
|
356 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
357 | + * |
|
358 | + * @param int $TXN_ID |
|
359 | + * @param EE_Base_Class $object |
|
360 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
361 | + * @throws EE_Error |
|
362 | + * @throws InvalidArgumentException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidInterfaceException |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
368 | + { |
|
369 | + return $this->get_all(array( |
|
370 | + array( |
|
371 | + 'TXN_ID' => $TXN_ID, |
|
372 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
373 | + 'OBJ_ID' => $object->ID(), |
|
374 | + ), |
|
375 | + )); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * get_object_line_items_for_transaction |
|
381 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
382 | + * |
|
383 | + * @param int $TXN_ID |
|
384 | + * @param string $OBJ_type |
|
385 | + * @param array $OBJ_IDs |
|
386 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function get_object_line_items_for_transaction( |
|
390 | + $TXN_ID, |
|
391 | + $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
392 | + $OBJ_IDs = array() |
|
393 | + ) { |
|
394 | + $query_params = array( |
|
395 | + 'OBJ_type' => $OBJ_type, |
|
396 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
397 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
398 | + ); |
|
399 | + if ($TXN_ID) { |
|
400 | + $query_params['TXN_ID'] = $TXN_ID; |
|
401 | + } |
|
402 | + return $this->get_all(array($query_params)); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * get_all_ticket_line_items_for_transaction |
|
408 | + * |
|
409 | + * @param EE_Transaction $transaction |
|
410 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
411 | + * @throws EE_Error |
|
412 | + * @throws InvalidArgumentException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws InvalidInterfaceException |
|
415 | + * @throws ReflectionException |
|
416 | + */ |
|
417 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
418 | + { |
|
419 | + return $this->get_all(array( |
|
420 | + array( |
|
421 | + 'TXN_ID' => $transaction->ID(), |
|
422 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
423 | + ), |
|
424 | + )); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * get_ticket_line_item_for_transaction |
|
430 | + * |
|
431 | + * @param int $TXN_ID |
|
432 | + * @param int $TKT_ID |
|
433 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
434 | + * @throws EE_Error |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws InvalidInterfaceException |
|
438 | + */ |
|
439 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
440 | + { |
|
441 | + return $this->get_one(array( |
|
442 | + array( |
|
443 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
444 | + 'OBJ_ID' => $TKT_ID, |
|
445 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
446 | + ), |
|
447 | + )); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * get_existing_promotion_line_item |
|
453 | + * searches the cart for existing line items for the specified promotion |
|
454 | + * |
|
455 | + * @since 1.0.0 |
|
456 | + * @param EE_Line_Item $parent_line_item |
|
457 | + * @param EE_Promotion $promotion |
|
458 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
459 | + * @throws EE_Error |
|
460 | + * @throws InvalidArgumentException |
|
461 | + * @throws InvalidDataTypeException |
|
462 | + * @throws InvalidInterfaceException |
|
463 | + * @throws ReflectionException |
|
464 | + */ |
|
465 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
466 | + { |
|
467 | + return $this->get_one(array( |
|
468 | + array( |
|
469 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
470 | + 'LIN_parent' => $parent_line_item->ID(), |
|
471 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
472 | + 'OBJ_ID' => $promotion->ID(), |
|
473 | + ), |
|
474 | + )); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * get_all_promotion_line_items |
|
480 | + * searches the cart for any and all existing promotion line items |
|
481 | + * |
|
482 | + * @since 1.0.0 |
|
483 | + * @param EE_Line_Item $parent_line_item |
|
484 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
492 | + { |
|
493 | + return $this->get_all(array( |
|
494 | + array( |
|
495 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
496 | + 'LIN_parent' => $parent_line_item->ID(), |
|
497 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
498 | + ), |
|
499 | + )); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Gets the registration's corresponding line item. |
|
505 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
506 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
507 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
508 | + * |
|
509 | + * @param EE_Registration $registration |
|
510 | + * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
511 | + * @throws EE_Error |
|
512 | + */ |
|
513 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
514 | + { |
|
515 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
521 | + * |
|
522 | + * @param EE_Registration $registration |
|
523 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
524 | + * @return array @see |
|
525 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
526 | + * @throws EE_Error |
|
527 | + */ |
|
528 | + public function line_item_for_registration_query_params( |
|
529 | + EE_Registration $registration, |
|
530 | + $original_query_params = array() |
|
531 | + ) { |
|
532 | + return array_replace_recursive($original_query_params, array( |
|
533 | + array( |
|
534 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
535 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
536 | + 'TXN_ID' => $registration->transaction_ID(), |
|
537 | + ), |
|
538 | + )); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
544 | + * @throws InvalidInterfaceException |
|
545 | + * @throws InvalidDataTypeException |
|
546 | + * @throws EE_Error |
|
547 | + * @throws InvalidArgumentException |
|
548 | + */ |
|
549 | + public function get_total_line_items_with_no_transaction() |
|
550 | + { |
|
551 | + return $this->get_total_line_items_for_carts(); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
557 | + * @throws InvalidInterfaceException |
|
558 | + * @throws InvalidDataTypeException |
|
559 | + * @throws EE_Error |
|
560 | + * @throws InvalidArgumentException |
|
561 | + */ |
|
562 | + public function get_total_line_items_for_active_carts() |
|
563 | + { |
|
564 | + return $this->get_total_line_items_for_carts(false); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
570 | + * @throws InvalidInterfaceException |
|
571 | + * @throws InvalidDataTypeException |
|
572 | + * @throws EE_Error |
|
573 | + * @throws InvalidArgumentException |
|
574 | + */ |
|
575 | + public function get_total_line_items_for_expired_carts() |
|
576 | + { |
|
577 | + return $this->get_total_line_items_for_carts(true); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
583 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
584 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
585 | + * |
|
586 | + * @param null $expired |
|
587 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
588 | + * @throws EE_Error |
|
589 | + * @throws InvalidArgumentException |
|
590 | + * @throws InvalidDataTypeException |
|
591 | + * @throws InvalidInterfaceException |
|
592 | + */ |
|
593 | + private function get_total_line_items_for_carts($expired = null) |
|
594 | + { |
|
595 | + $where_params = array( |
|
596 | + 'TXN_ID' => 0, |
|
597 | + 'LIN_type' => 'total', |
|
598 | + ); |
|
599 | + if ($expired !== null) { |
|
600 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
601 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
602 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
603 | + ); |
|
604 | + $where_params['LIN_timestamp'] = array( |
|
605 | + $expired ? '<=' : '>', |
|
606 | + $session_lifespan->expiration(), |
|
607 | + ); |
|
608 | + } |
|
609 | + return $this->get_all(array($where_params)); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
615 | + * AND the timestamp is older than the session lifespan. |
|
616 | + * |
|
617 | + * @param int $timestamp |
|
618 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
619 | + * @throws EE_Error |
|
620 | + * @throws InvalidArgumentException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws InvalidInterfaceException |
|
623 | + */ |
|
624 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
625 | + { |
|
626 | + if (! absint($timestamp)) { |
|
627 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
628 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
629 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
630 | + ); |
|
631 | + $timestamp = $session_lifespan->expiration(); |
|
632 | + } |
|
633 | + return $this->get_all( |
|
634 | + array( |
|
635 | + array( |
|
636 | + 'TXN_ID' => 0, |
|
637 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
638 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
639 | + ), |
|
640 | + ) |
|
641 | + ); |
|
642 | + } |
|
643 | 643 | } |
@@ -8,128 +8,128 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * number of decimal places to round numbers to when performing calculations |
|
13 | - * |
|
14 | - * @var integer |
|
15 | - */ |
|
16 | - protected $decimal_precision = 6; |
|
17 | - |
|
18 | - /** |
|
19 | - * number of decimal places to round numbers to for display |
|
20 | - * |
|
21 | - * @var integer |
|
22 | - */ |
|
23 | - protected $locale_precision = 6; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string $table_column |
|
28 | - * @param string $nicename |
|
29 | - * @param bool $nullable |
|
30 | - * @param null $default_value |
|
31 | - */ |
|
32 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
33 | - { |
|
34 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
35 | - $this->setSchemaType('object'); |
|
36 | - $this->locale_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Schemas: |
|
42 | - * 'localized_float': "3,023.00" |
|
43 | - * 'no_currency_code': "$3,023.00" |
|
44 | - * null: "$3,023.00<span>USD</span>" |
|
45 | - * |
|
46 | - * @param string $value_on_field_to_be_outputted |
|
47 | - * @param string $schema |
|
48 | - * @return string |
|
49 | - * @throws EE_Error |
|
50 | - */ |
|
51 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null): string |
|
52 | - { |
|
53 | - if ($schema == 'localized_float') { |
|
54 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
55 | - } |
|
56 | - $display_code = $schema !== 'no_currency_code'; |
|
57 | - // we don't use the $pretty_float because format_currency will take care of it. |
|
58 | - return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
64 | - * Rounds the float to the correct number of decimal places for this country's currency. |
|
65 | - * Also, interprets periods and commas according to the country's currency settings. |
|
66 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
67 | - * |
|
68 | - * @param string $value_inputted_for_field_on_model_object |
|
69 | - * @return float |
|
70 | - */ |
|
71 | - public function prepare_for_set($value_inputted_for_field_on_model_object): float |
|
72 | - { |
|
73 | - // now it's a float-style string or number |
|
74 | - $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
75 | - // round to the correctly number of decimal places for this currency |
|
76 | - return $this->roundNumericValue($float_val); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return array[] |
|
82 | - */ |
|
83 | - public function getSchemaProperties(): array |
|
84 | - { |
|
85 | - return [ |
|
86 | - 'raw' => [ |
|
87 | - 'description' => sprintf( |
|
88 | - __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
89 | - $this->get_nicename() |
|
90 | - ), |
|
91 | - 'type' => 'number', |
|
92 | - ], |
|
93 | - 'pretty' => [ |
|
94 | - 'description' => sprintf( |
|
95 | - __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
96 | - $this->get_nicename() |
|
97 | - ), |
|
98 | - 'type' => 'string', |
|
99 | - 'format' => 'money', |
|
100 | - ], |
|
101 | - ]; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * strips formatting, rounds the provided number, and returns a float |
|
107 | - * if $round is set to true, then the decimal precision for the site locale will be used, |
|
108 | - * otherwise the default decimal precision of 6 will be used |
|
109 | - * |
|
110 | - * @param float|int|string $number unformatted number value, ex: 1234.5678956789 |
|
111 | - * @param bool $round whether to round the price off according to the locale settings |
|
112 | - * @return float rounded value, ex: 1,234.567896 |
|
113 | - */ |
|
114 | - private function roundNumericValue($number, bool $round = false): float |
|
115 | - { |
|
116 | - $precision = $round ? $this->locale_precision : $this->decimal_precision; |
|
117 | - return round( |
|
118 | - $this->filterNumericValue($number), |
|
119 | - $precision ?? $this->decimal_precision, |
|
120 | - PHP_ROUND_HALF_UP |
|
121 | - ); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Removes all characters except digits, +- and . |
|
127 | - * |
|
128 | - * @param float|int|string $number |
|
129 | - * @return float |
|
130 | - */ |
|
131 | - private function filterNumericValue($number): float |
|
132 | - { |
|
133 | - return (float) filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
134 | - } |
|
11 | + /** |
|
12 | + * number of decimal places to round numbers to when performing calculations |
|
13 | + * |
|
14 | + * @var integer |
|
15 | + */ |
|
16 | + protected $decimal_precision = 6; |
|
17 | + |
|
18 | + /** |
|
19 | + * number of decimal places to round numbers to for display |
|
20 | + * |
|
21 | + * @var integer |
|
22 | + */ |
|
23 | + protected $locale_precision = 6; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string $table_column |
|
28 | + * @param string $nicename |
|
29 | + * @param bool $nullable |
|
30 | + * @param null $default_value |
|
31 | + */ |
|
32 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
33 | + { |
|
34 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
35 | + $this->setSchemaType('object'); |
|
36 | + $this->locale_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Schemas: |
|
42 | + * 'localized_float': "3,023.00" |
|
43 | + * 'no_currency_code': "$3,023.00" |
|
44 | + * null: "$3,023.00<span>USD</span>" |
|
45 | + * |
|
46 | + * @param string $value_on_field_to_be_outputted |
|
47 | + * @param string $schema |
|
48 | + * @return string |
|
49 | + * @throws EE_Error |
|
50 | + */ |
|
51 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null): string |
|
52 | + { |
|
53 | + if ($schema == 'localized_float') { |
|
54 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
55 | + } |
|
56 | + $display_code = $schema !== 'no_currency_code'; |
|
57 | + // we don't use the $pretty_float because format_currency will take care of it. |
|
58 | + return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
64 | + * Rounds the float to the correct number of decimal places for this country's currency. |
|
65 | + * Also, interprets periods and commas according to the country's currency settings. |
|
66 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
67 | + * |
|
68 | + * @param string $value_inputted_for_field_on_model_object |
|
69 | + * @return float |
|
70 | + */ |
|
71 | + public function prepare_for_set($value_inputted_for_field_on_model_object): float |
|
72 | + { |
|
73 | + // now it's a float-style string or number |
|
74 | + $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
75 | + // round to the correctly number of decimal places for this currency |
|
76 | + return $this->roundNumericValue($float_val); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return array[] |
|
82 | + */ |
|
83 | + public function getSchemaProperties(): array |
|
84 | + { |
|
85 | + return [ |
|
86 | + 'raw' => [ |
|
87 | + 'description' => sprintf( |
|
88 | + __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
89 | + $this->get_nicename() |
|
90 | + ), |
|
91 | + 'type' => 'number', |
|
92 | + ], |
|
93 | + 'pretty' => [ |
|
94 | + 'description' => sprintf( |
|
95 | + __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
96 | + $this->get_nicename() |
|
97 | + ), |
|
98 | + 'type' => 'string', |
|
99 | + 'format' => 'money', |
|
100 | + ], |
|
101 | + ]; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * strips formatting, rounds the provided number, and returns a float |
|
107 | + * if $round is set to true, then the decimal precision for the site locale will be used, |
|
108 | + * otherwise the default decimal precision of 6 will be used |
|
109 | + * |
|
110 | + * @param float|int|string $number unformatted number value, ex: 1234.5678956789 |
|
111 | + * @param bool $round whether to round the price off according to the locale settings |
|
112 | + * @return float rounded value, ex: 1,234.567896 |
|
113 | + */ |
|
114 | + private function roundNumericValue($number, bool $round = false): float |
|
115 | + { |
|
116 | + $precision = $round ? $this->locale_precision : $this->decimal_precision; |
|
117 | + return round( |
|
118 | + $this->filterNumericValue($number), |
|
119 | + $precision ?? $this->decimal_precision, |
|
120 | + PHP_ROUND_HALF_UP |
|
121 | + ); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Removes all characters except digits, +- and . |
|
127 | + * |
|
128 | + * @param float|int|string $number |
|
129 | + * @return float |
|
130 | + */ |
|
131 | + private function filterNumericValue($number): float |
|
132 | + { |
|
133 | + return (float) filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
134 | + } |
|
135 | 135 | } |
@@ -7,77 +7,77 @@ |
||
7 | 7 | class EE_Float_Field extends EE_Model_Field_Base |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @param string $table_column |
|
12 | - * @param string $nicename |
|
13 | - * @param bool $nullable |
|
14 | - * @param null $default_value |
|
15 | - */ |
|
16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | - { |
|
18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | - $this->setSchemaType('number'); |
|
20 | - } |
|
10 | + /** |
|
11 | + * @param string $table_column |
|
12 | + * @param string $nicename |
|
13 | + * @param bool $nullable |
|
14 | + * @param null $default_value |
|
15 | + */ |
|
16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | + { |
|
18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | + $this->setSchemaType('number'); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | - * Returns a float |
|
28 | - * |
|
29 | - * @param float|string $value_inputted_for_field_on_model_object |
|
30 | - * @return float |
|
31 | - */ |
|
32 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | - { |
|
23 | + /** |
|
24 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | + * Returns a float |
|
28 | + * |
|
29 | + * @param float|string $value_inputted_for_field_on_model_object |
|
30 | + * @return float |
|
31 | + */ |
|
32 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | + { |
|
34 | 34 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
35 | - // remove whitespaces and thousands separators |
|
36 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | - $value_inputted_for_field_on_model_object = str_replace( |
|
38 | - array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | - "", |
|
40 | - $value_inputted_for_field_on_model_object |
|
41 | - ); |
|
35 | + // remove whitespaces and thousands separators |
|
36 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | + $value_inputted_for_field_on_model_object = str_replace( |
|
38 | + array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | + "", |
|
40 | + $value_inputted_for_field_on_model_object |
|
41 | + ); |
|
42 | 42 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
43 | 43 | // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
44 | - $value_inputted_for_field_on_model_object = str_replace( |
|
45 | - EE_Config::instance()->currency->dec_mrk, |
|
46 | - ".", |
|
47 | - $value_inputted_for_field_on_model_object |
|
48 | - ); |
|
44 | + $value_inputted_for_field_on_model_object = str_replace( |
|
45 | + EE_Config::instance()->currency->dec_mrk, |
|
46 | + ".", |
|
47 | + $value_inputted_for_field_on_model_object |
|
48 | + ); |
|
49 | 49 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
50 | 50 | // double-check there's absolutely nothing left on this string besides numbers |
51 | - $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | - "/[^0-9,.]/", |
|
53 | - "", |
|
54 | - $value_inputted_for_field_on_model_object |
|
55 | - ); |
|
56 | - } |
|
51 | + $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | + "/[^0-9,.]/", |
|
53 | + "", |
|
54 | + $value_inputted_for_field_on_model_object |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
58 | - return floatval($value_inputted_for_field_on_model_object); |
|
59 | - } |
|
58 | + return floatval($value_inputted_for_field_on_model_object); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | - * |
|
64 | - * @param float $value_on_field_to_be_outputted |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | - { |
|
69 | - $EE = EE_Registry::instance(); |
|
70 | - return number_format( |
|
71 | - $value_on_field_to_be_outputted, |
|
72 | - $EE->CFG->currency->dec_plc, |
|
73 | - $EE->CFG->currency->dec_mrk, |
|
74 | - $EE->CFG->currency->thsnds |
|
75 | - ); |
|
76 | - } |
|
61 | + /** |
|
62 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | + * |
|
64 | + * @param float $value_on_field_to_be_outputted |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | + { |
|
69 | + $EE = EE_Registry::instance(); |
|
70 | + return number_format( |
|
71 | + $value_on_field_to_be_outputted, |
|
72 | + $EE->CFG->currency->dec_plc, |
|
73 | + $EE->CFG->currency->dec_mrk, |
|
74 | + $EE->CFG->currency->thsnds |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | - { |
|
78 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | + { |
|
80 | 80 | // echo "prepare for set from db of ";d($value_found_in_db_for_model_object); |
81 | - return floatval($value_found_in_db_for_model_object); |
|
82 | - } |
|
81 | + return floatval($value_found_in_db_for_model_object); |
|
82 | + } |
|
83 | 83 | } |
@@ -20,234 +20,234 @@ |
||
20 | 20 | */ |
21 | 21 | class TicketPriceModifiers |
22 | 22 | { |
23 | - /** |
|
24 | - * @var EE_Ticket |
|
25 | - */ |
|
26 | - private $ticket; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Price[] |
|
31 | - */ |
|
32 | - private $ticket_prices; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param EE_Ticket $ticket |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public function __construct(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $this->ticket = $ticket; |
|
43 | - // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | - $this->ticket_prices = $this->ticket->prices(); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param callable $filter |
|
50 | - * @return array |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - private function filterModifiersForTicket(callable $filter): array |
|
55 | - { |
|
56 | - $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | - if (empty($ticket_modifiers)) { |
|
58 | - $ticket_modifiers = $this->ticket_prices; |
|
59 | - } |
|
60 | - return array_filter($ticket_modifiers, $filter); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * retrieve all price modifiers for the this ticket |
|
66 | - * |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function getAllModifiersForTicket(): array |
|
72 | - { |
|
73 | - return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | - * |
|
80 | - * @param EE_Price $price_modifier |
|
81 | - * @return bool |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | - { |
|
87 | - return ! $price_modifier->is_base_price(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * retrieve all discounts for the this ticket |
|
93 | - * |
|
94 | - * @return array |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getAllDiscountModifiersForTicket(): array |
|
99 | - { |
|
100 | - return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | - * |
|
107 | - * @param EE_Price $price_modifier |
|
108 | - * @return bool |
|
109 | - * @throws EE_Error |
|
110 | - * @throws ReflectionException |
|
111 | - */ |
|
112 | - public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | - { |
|
114 | - return $price_modifier->is_discount(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * retrieve all surcharges for the this ticket |
|
120 | - * |
|
121 | - * @return array |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function getAllSurchargeModifiersForTicket(): array |
|
126 | - { |
|
127 | - return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | - * |
|
134 | - * @param EE_Price $price_modifier |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws ReflectionException |
|
138 | - */ |
|
139 | - public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | - { |
|
141 | - return $price_modifier->is_surcharge(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * retrieve all discounts AND surcharges for the this ticket |
|
147 | - * |
|
148 | - * @return array |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | - { |
|
154 | - return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | - * |
|
161 | - * @param EE_Price $price_modifier |
|
162 | - * @return bool |
|
163 | - * @throws EE_Error |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | - { |
|
168 | - return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * retrieve all taxes for the this ticket |
|
174 | - * |
|
175 | - * @return array |
|
176 | - * @throws EE_Error |
|
177 | - * @throws ReflectionException |
|
178 | - */ |
|
179 | - public function getAllTaxesForTicket(): array |
|
180 | - { |
|
181 | - return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | - * |
|
188 | - * @param EE_Price $price_modifier |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | - { |
|
195 | - return $price_modifier->is_tax(); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | - * |
|
202 | - * @return array |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function getAllNonTaxPricesForTicket(): array |
|
207 | - { |
|
208 | - return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * pass to filterModifiersForTicket() with a ticket |
|
214 | - * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | - * |
|
216 | - * @param EE_Price $price_modifier |
|
217 | - * @return bool |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | - { |
|
223 | - return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * retrieve the base price for the this ticket |
|
229 | - * |
|
230 | - * @return array |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - public function getBasePrice(): array |
|
235 | - { |
|
236 | - return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * pass to filterModifiersForTicket() |
|
242 | - * to retrieve the base price for the this ticket |
|
243 | - * |
|
244 | - * @param EE_Price $price_modifier |
|
245 | - * @return bool |
|
246 | - * @throws EE_Error |
|
247 | - * @throws ReflectionException |
|
248 | - */ |
|
249 | - public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | - { |
|
251 | - return $price_modifier->is_base_price(); |
|
252 | - } |
|
23 | + /** |
|
24 | + * @var EE_Ticket |
|
25 | + */ |
|
26 | + private $ticket; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Price[] |
|
31 | + */ |
|
32 | + private $ticket_prices; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param EE_Ticket $ticket |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public function __construct(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $this->ticket = $ticket; |
|
43 | + // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | + $this->ticket_prices = $this->ticket->prices(); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param callable $filter |
|
50 | + * @return array |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + private function filterModifiersForTicket(callable $filter): array |
|
55 | + { |
|
56 | + $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | + if (empty($ticket_modifiers)) { |
|
58 | + $ticket_modifiers = $this->ticket_prices; |
|
59 | + } |
|
60 | + return array_filter($ticket_modifiers, $filter); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * retrieve all price modifiers for the this ticket |
|
66 | + * |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function getAllModifiersForTicket(): array |
|
72 | + { |
|
73 | + return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | + * |
|
80 | + * @param EE_Price $price_modifier |
|
81 | + * @return bool |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | + { |
|
87 | + return ! $price_modifier->is_base_price(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * retrieve all discounts for the this ticket |
|
93 | + * |
|
94 | + * @return array |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getAllDiscountModifiersForTicket(): array |
|
99 | + { |
|
100 | + return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | + * |
|
107 | + * @param EE_Price $price_modifier |
|
108 | + * @return bool |
|
109 | + * @throws EE_Error |
|
110 | + * @throws ReflectionException |
|
111 | + */ |
|
112 | + public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | + { |
|
114 | + return $price_modifier->is_discount(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * retrieve all surcharges for the this ticket |
|
120 | + * |
|
121 | + * @return array |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function getAllSurchargeModifiersForTicket(): array |
|
126 | + { |
|
127 | + return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | + * |
|
134 | + * @param EE_Price $price_modifier |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws ReflectionException |
|
138 | + */ |
|
139 | + public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | + { |
|
141 | + return $price_modifier->is_surcharge(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * retrieve all discounts AND surcharges for the this ticket |
|
147 | + * |
|
148 | + * @return array |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | + { |
|
154 | + return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | + * |
|
161 | + * @param EE_Price $price_modifier |
|
162 | + * @return bool |
|
163 | + * @throws EE_Error |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | + { |
|
168 | + return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * retrieve all taxes for the this ticket |
|
174 | + * |
|
175 | + * @return array |
|
176 | + * @throws EE_Error |
|
177 | + * @throws ReflectionException |
|
178 | + */ |
|
179 | + public function getAllTaxesForTicket(): array |
|
180 | + { |
|
181 | + return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | + * |
|
188 | + * @param EE_Price $price_modifier |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | + { |
|
195 | + return $price_modifier->is_tax(); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | + * |
|
202 | + * @return array |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function getAllNonTaxPricesForTicket(): array |
|
207 | + { |
|
208 | + return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * pass to filterModifiersForTicket() with a ticket |
|
214 | + * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | + * |
|
216 | + * @param EE_Price $price_modifier |
|
217 | + * @return bool |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | + { |
|
223 | + return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * retrieve the base price for the this ticket |
|
229 | + * |
|
230 | + * @return array |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + public function getBasePrice(): array |
|
235 | + { |
|
236 | + return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * pass to filterModifiersForTicket() |
|
242 | + * to retrieve the base price for the this ticket |
|
243 | + * |
|
244 | + * @param EE_Price $price_modifier |
|
245 | + * @return bool |
|
246 | + * @throws EE_Error |
|
247 | + * @throws ReflectionException |
|
248 | + */ |
|
249 | + public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | + { |
|
251 | + return $price_modifier->is_base_price(); |
|
252 | + } |
|
253 | 253 | } |
@@ -23,495 +23,495 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class EE_Gateway |
25 | 25 | { |
26 | - /** |
|
27 | - * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | - * that ALL currencies are supported by this gateway |
|
29 | - */ |
|
30 | - const all_currencies_supported = 'all_currencies_supported'; |
|
31 | - /** |
|
32 | - * Where values are 3-letter currency codes |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $_currencies_supported = array(); |
|
37 | - /** |
|
38 | - * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | - * admin in EE's wp-admin page) |
|
40 | - * |
|
41 | - * @var boolean |
|
42 | - */ |
|
43 | - protected $_supports_sending_refunds = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | - * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | - * |
|
49 | - * @var boolean |
|
50 | - */ |
|
51 | - protected $_supports_receiving_refunds = false; |
|
52 | - /** |
|
53 | - * Model for querying for existing payments |
|
54 | - * |
|
55 | - * @var EEMI_Payment |
|
56 | - */ |
|
57 | - protected $_pay_model; |
|
58 | - |
|
59 | - /** |
|
60 | - * Model used for adding to the payments log |
|
61 | - * |
|
62 | - * @var EEMI_Payment_Log |
|
63 | - */ |
|
64 | - protected $_pay_log; |
|
65 | - |
|
66 | - /** |
|
67 | - * Used for formatting some input to gateways |
|
68 | - * |
|
69 | - * @var EEHI_Template |
|
70 | - */ |
|
71 | - protected $_template; |
|
72 | - |
|
73 | - /** |
|
74 | - * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | - * |
|
76 | - * @var EEHI_Money |
|
77 | - */ |
|
78 | - protected $_money; |
|
79 | - |
|
80 | - /** |
|
81 | - * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | - * |
|
83 | - * @var EEHI_Line_Item |
|
84 | - */ |
|
85 | - protected $_line_item; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var GatewayDataFormatterInterface |
|
89 | - */ |
|
90 | - protected $_gateway_data_formatter; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var FormatterInterface |
|
94 | - */ |
|
95 | - protected $_unsupported_character_remover; |
|
96 | - |
|
97 | - /** |
|
98 | - * The ID of the payment method using this gateway |
|
99 | - * |
|
100 | - * @var int |
|
101 | - */ |
|
102 | - protected $_ID; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | - */ |
|
107 | - protected $_debug_mode; |
|
108 | - /** |
|
109 | - * |
|
110 | - * @var string $_name name to show for this payment method |
|
111 | - */ |
|
112 | - protected $_name; |
|
113 | - /** |
|
114 | - * |
|
115 | - * @var string name to show fir this payment method to admin-type users |
|
116 | - */ |
|
117 | - protected $_admin_name; |
|
118 | - |
|
119 | - /** |
|
120 | - * @return EE_Gateway |
|
121 | - */ |
|
122 | - public function __construct() |
|
123 | - { |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * We don't want to serialize models as they often have circular structures |
|
128 | - * (eg a payment model has a reference to each payment model object; and most |
|
129 | - * payments have a transaction, most transactions have a payment method; |
|
130 | - * most payment methods have a payment method type; most payment method types |
|
131 | - * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | - * beginning again) |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function __sleep() |
|
137 | - { |
|
138 | - $properties = get_object_vars($this); |
|
139 | - unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | - return array_keys($properties); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns whether or not this gateway should support SENDING refunds |
|
145 | - * see $_supports_sending_refunds |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public function supports_sending_refunds() |
|
150 | - { |
|
151 | - return $this->_supports_sending_refunds; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | - * see $_supports_receiving_refunds |
|
157 | - * |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - public function supports_receiving_refunds() |
|
161 | - { |
|
162 | - return $this->_supports_receiving_refunds; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Tries to refund the payment specified, taking into account the extra |
|
168 | - * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | - * this should just throw an exception. |
|
170 | - * |
|
171 | - * @param EE_Payment $payment |
|
172 | - * @param array $refund_info |
|
173 | - * @return EE_Payment for the refund |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | - { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | - * etc |
|
185 | - * |
|
186 | - * @param array $settings_array |
|
187 | - */ |
|
188 | - public function set_settings($settings_array) |
|
189 | - { |
|
190 | - foreach ($settings_array as $name => $value) { |
|
191 | - $property_name = "_" . $name; |
|
192 | - $this->{$property_name} = $value; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * See this class description |
|
198 | - * |
|
199 | - * @param EEMI_Payment $payment_model |
|
200 | - */ |
|
201 | - public function set_payment_model($payment_model) |
|
202 | - { |
|
203 | - $this->_pay_model = $payment_model; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * See this class description |
|
208 | - * |
|
209 | - * @param EEMI_Payment_Log $payment_log_model |
|
210 | - */ |
|
211 | - public function set_payment_log($payment_log_model) |
|
212 | - { |
|
213 | - $this->_pay_log = $payment_log_model; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * See this class description |
|
218 | - * |
|
219 | - * @param EEHI_Template $template_helper |
|
220 | - */ |
|
221 | - public function set_template_helper($template_helper) |
|
222 | - { |
|
223 | - $this->_template = $template_helper; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * See this class description |
|
228 | - * |
|
229 | - * @param EEHI_Line_Item $line_item_helper |
|
230 | - */ |
|
231 | - public function set_line_item_helper($line_item_helper) |
|
232 | - { |
|
233 | - $this->_line_item = $line_item_helper; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * See this class description |
|
238 | - * |
|
239 | - * @param EEHI_Money $money_helper |
|
240 | - */ |
|
241 | - public function set_money_helper($money_helper) |
|
242 | - { |
|
243 | - $this->_money = $money_helper; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the gateway data formatter helper |
|
249 | - * |
|
250 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | - * @throws InvalidEntityException if it's not set properly |
|
252 | - */ |
|
253 | - public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | - { |
|
255 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | - throw new InvalidEntityException( |
|
257 | - is_object($gateway_data_formatter) |
|
258 | - ? get_class($gateway_data_formatter) |
|
259 | - : esc_html__('Not an object', 'event_espresso'), |
|
260 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | - ); |
|
262 | - } |
|
263 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Gets the gateway data formatter |
|
268 | - * |
|
269 | - * @return GatewayDataFormatterInterface |
|
270 | - * @throws InvalidEntityException if it's not set properly |
|
271 | - */ |
|
272 | - protected function _get_gateway_formatter() |
|
273 | - { |
|
274 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | - throw new InvalidEntityException( |
|
276 | - is_object($this->_gateway_data_formatter) |
|
277 | - ? get_class($this->_gateway_data_formatter) |
|
278 | - : esc_html__('Not an object', 'event_espresso'), |
|
279 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | - ); |
|
281 | - } |
|
282 | - return $this->_gateway_data_formatter; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Sets the helper which will remove unsupported characters for most gateways |
|
288 | - * |
|
289 | - * @param FormatterInterface $formatter |
|
290 | - * @return FormatterInterface |
|
291 | - * @throws InvalidEntityException |
|
292 | - */ |
|
293 | - public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | - { |
|
295 | - if (! $formatter instanceof FormatterInterface) { |
|
296 | - throw new InvalidEntityException( |
|
297 | - is_object($formatter) |
|
298 | - ? get_class($formatter) |
|
299 | - : esc_html__('Not an object', 'event_espresso'), |
|
300 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | - ); |
|
302 | - } |
|
303 | - $this->_unsupported_character_remover = $formatter; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | - * |
|
309 | - * @return FormatterInterface |
|
310 | - * @throws InvalidEntityException |
|
311 | - */ |
|
312 | - protected function _get_unsupported_character_remover() |
|
313 | - { |
|
314 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | - throw new InvalidEntityException( |
|
316 | - is_object($this->_unsupported_character_remover) |
|
317 | - ? get_class($this->_unsupported_character_remover) |
|
318 | - : esc_html__('Not an object', 'event_espresso'), |
|
319 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | - ); |
|
321 | - } |
|
322 | - return $this->_unsupported_character_remover; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param $message |
|
328 | - * @param $payment |
|
329 | - */ |
|
330 | - public function log($message, $object_logged) |
|
331 | - { |
|
332 | - if ($object_logged instanceof EEI_Payment) { |
|
333 | - $type = 'Payment'; |
|
334 | - $id = $object_logged->ID(); |
|
335 | - } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | - $type = 'Transaction'; |
|
337 | - $id = $object_logged->ID(); |
|
338 | - } else { |
|
339 | - $type = 'Payment_Method'; |
|
340 | - $id = $this->_ID; |
|
341 | - } |
|
342 | - // only log if we're going to store it for longer than the minimum time |
|
343 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | - if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | - $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Formats the amount so it can generally be sent to gateways |
|
351 | - * |
|
352 | - * @param float $amount |
|
353 | - * @return string |
|
354 | - * @deprecated since 4.9.31 insetad use |
|
355 | - * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | - */ |
|
357 | - public function format_currency($amount) |
|
358 | - { |
|
359 | - return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Returns either an array of all the currency codes supported, |
|
364 | - * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | - * |
|
366 | - * @return mixed array or string |
|
367 | - */ |
|
368 | - public function currencies_supported() |
|
369 | - { |
|
370 | - return $this->_currencies_supported; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | - * can be used to determine if some more complex line items, like promotions, |
|
376 | - * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | - * about creating an itemized list of purchases and instead only send the total due) |
|
378 | - * |
|
379 | - * @param EE_Transaction $transaction |
|
380 | - * @return float |
|
381 | - */ |
|
382 | - protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | - { |
|
384 | - $total_line_item = $transaction->total_line_item(); |
|
385 | - $total = 0; |
|
386 | - foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | - $total += max($item_line_item->total(), 0); |
|
388 | - } |
|
389 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | - $total += max($tax_line_item->total(), 0); |
|
391 | - } |
|
392 | - return $total; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Determines whether or not we can easily itemize the transaction using only |
|
397 | - * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | - * |
|
399 | - * @param EEI_Payment $payment |
|
400 | - * @return boolean |
|
401 | - */ |
|
402 | - protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | - { |
|
404 | - return $this->_money->compare_floats( |
|
405 | - $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | - $payment->transaction()->total() |
|
407 | - ) |
|
408 | - && $this->_money->compare_floats( |
|
409 | - $payment->amount(), |
|
410 | - $payment->transaction()->total() |
|
411 | - ); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Handles updating the transaction and any other related data based on the payment. |
|
416 | - * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | - * but doing so on those functions might be too early. It's possible that the changes |
|
418 | - * you make to teh transaction or registration or line items may just get overwritten |
|
419 | - * at that point. Instead, you should store any info you need on the payment during those |
|
420 | - * functions, and use that information at this step, which client code will decide |
|
421 | - * for you when it should be called. |
|
422 | - * |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @return void |
|
425 | - */ |
|
426 | - public function update_txn_based_on_payment($payment) |
|
427 | - { |
|
428 | - // maybe update the transaction or line items or registrations |
|
429 | - // but most gateways don't need to do this, because they only update the payment |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | - * |
|
435 | - * @param EEI_Payment $payment |
|
436 | - * @return EEI_Event|null |
|
437 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | - */ |
|
439 | - protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | - { |
|
441 | - return $payment->get_first_event(); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the name of the first event for which is being paid |
|
446 | - * |
|
447 | - * @param EEI_Payment $payment |
|
448 | - * @return string |
|
449 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | - */ |
|
451 | - protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | - { |
|
453 | - return $payment->get_first_event_name(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | - * |
|
459 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | - * @param EE_Payment $payment |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | - { |
|
465 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | - * |
|
471 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | - * @param EEI_Payment $payment |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | - { |
|
477 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Gets the name to use for a line item when sending line items to the gateway |
|
482 | - * |
|
483 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | - * @param EE_Line_Item $line_item |
|
485 | - * @param EEI_Payment $payment |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - protected function _format_line_item_name(EE_Line_Item $line_item, EEI_Payment $payment) |
|
489 | - { |
|
490 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets the description to use for a line item when sending line items to the gateway |
|
495 | - * |
|
496 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | - * @param EE_Line_Item $line_item |
|
498 | - * @param EEI_Payment $payment |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected function _format_line_item_desc(EE_Line_Item $line_item, EEI_Payment $payment) |
|
502 | - { |
|
503 | - return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Gets the order description that should generlly be sent to gateways |
|
508 | - * |
|
509 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | - * @param EEI_Payment $payment |
|
511 | - * @return type |
|
512 | - */ |
|
513 | - protected function _format_order_description(EEI_Payment $payment) |
|
514 | - { |
|
515 | - return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | - } |
|
26 | + /** |
|
27 | + * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | + * that ALL currencies are supported by this gateway |
|
29 | + */ |
|
30 | + const all_currencies_supported = 'all_currencies_supported'; |
|
31 | + /** |
|
32 | + * Where values are 3-letter currency codes |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $_currencies_supported = array(); |
|
37 | + /** |
|
38 | + * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | + * admin in EE's wp-admin page) |
|
40 | + * |
|
41 | + * @var boolean |
|
42 | + */ |
|
43 | + protected $_supports_sending_refunds = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | + * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | + * |
|
49 | + * @var boolean |
|
50 | + */ |
|
51 | + protected $_supports_receiving_refunds = false; |
|
52 | + /** |
|
53 | + * Model for querying for existing payments |
|
54 | + * |
|
55 | + * @var EEMI_Payment |
|
56 | + */ |
|
57 | + protected $_pay_model; |
|
58 | + |
|
59 | + /** |
|
60 | + * Model used for adding to the payments log |
|
61 | + * |
|
62 | + * @var EEMI_Payment_Log |
|
63 | + */ |
|
64 | + protected $_pay_log; |
|
65 | + |
|
66 | + /** |
|
67 | + * Used for formatting some input to gateways |
|
68 | + * |
|
69 | + * @var EEHI_Template |
|
70 | + */ |
|
71 | + protected $_template; |
|
72 | + |
|
73 | + /** |
|
74 | + * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | + * |
|
76 | + * @var EEHI_Money |
|
77 | + */ |
|
78 | + protected $_money; |
|
79 | + |
|
80 | + /** |
|
81 | + * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | + * |
|
83 | + * @var EEHI_Line_Item |
|
84 | + */ |
|
85 | + protected $_line_item; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var GatewayDataFormatterInterface |
|
89 | + */ |
|
90 | + protected $_gateway_data_formatter; |
|
91 | + |
|
92 | + /** |
|
93 | + * @var FormatterInterface |
|
94 | + */ |
|
95 | + protected $_unsupported_character_remover; |
|
96 | + |
|
97 | + /** |
|
98 | + * The ID of the payment method using this gateway |
|
99 | + * |
|
100 | + * @var int |
|
101 | + */ |
|
102 | + protected $_ID; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | + */ |
|
107 | + protected $_debug_mode; |
|
108 | + /** |
|
109 | + * |
|
110 | + * @var string $_name name to show for this payment method |
|
111 | + */ |
|
112 | + protected $_name; |
|
113 | + /** |
|
114 | + * |
|
115 | + * @var string name to show fir this payment method to admin-type users |
|
116 | + */ |
|
117 | + protected $_admin_name; |
|
118 | + |
|
119 | + /** |
|
120 | + * @return EE_Gateway |
|
121 | + */ |
|
122 | + public function __construct() |
|
123 | + { |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * We don't want to serialize models as they often have circular structures |
|
128 | + * (eg a payment model has a reference to each payment model object; and most |
|
129 | + * payments have a transaction, most transactions have a payment method; |
|
130 | + * most payment methods have a payment method type; most payment method types |
|
131 | + * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | + * beginning again) |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function __sleep() |
|
137 | + { |
|
138 | + $properties = get_object_vars($this); |
|
139 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | + return array_keys($properties); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns whether or not this gateway should support SENDING refunds |
|
145 | + * see $_supports_sending_refunds |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public function supports_sending_refunds() |
|
150 | + { |
|
151 | + return $this->_supports_sending_refunds; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | + * see $_supports_receiving_refunds |
|
157 | + * |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + public function supports_receiving_refunds() |
|
161 | + { |
|
162 | + return $this->_supports_receiving_refunds; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Tries to refund the payment specified, taking into account the extra |
|
168 | + * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | + * this should just throw an exception. |
|
170 | + * |
|
171 | + * @param EE_Payment $payment |
|
172 | + * @param array $refund_info |
|
173 | + * @return EE_Payment for the refund |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | + { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | + * etc |
|
185 | + * |
|
186 | + * @param array $settings_array |
|
187 | + */ |
|
188 | + public function set_settings($settings_array) |
|
189 | + { |
|
190 | + foreach ($settings_array as $name => $value) { |
|
191 | + $property_name = "_" . $name; |
|
192 | + $this->{$property_name} = $value; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * See this class description |
|
198 | + * |
|
199 | + * @param EEMI_Payment $payment_model |
|
200 | + */ |
|
201 | + public function set_payment_model($payment_model) |
|
202 | + { |
|
203 | + $this->_pay_model = $payment_model; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * See this class description |
|
208 | + * |
|
209 | + * @param EEMI_Payment_Log $payment_log_model |
|
210 | + */ |
|
211 | + public function set_payment_log($payment_log_model) |
|
212 | + { |
|
213 | + $this->_pay_log = $payment_log_model; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * See this class description |
|
218 | + * |
|
219 | + * @param EEHI_Template $template_helper |
|
220 | + */ |
|
221 | + public function set_template_helper($template_helper) |
|
222 | + { |
|
223 | + $this->_template = $template_helper; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * See this class description |
|
228 | + * |
|
229 | + * @param EEHI_Line_Item $line_item_helper |
|
230 | + */ |
|
231 | + public function set_line_item_helper($line_item_helper) |
|
232 | + { |
|
233 | + $this->_line_item = $line_item_helper; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * See this class description |
|
238 | + * |
|
239 | + * @param EEHI_Money $money_helper |
|
240 | + */ |
|
241 | + public function set_money_helper($money_helper) |
|
242 | + { |
|
243 | + $this->_money = $money_helper; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the gateway data formatter helper |
|
249 | + * |
|
250 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | + * @throws InvalidEntityException if it's not set properly |
|
252 | + */ |
|
253 | + public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | + { |
|
255 | + if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | + throw new InvalidEntityException( |
|
257 | + is_object($gateway_data_formatter) |
|
258 | + ? get_class($gateway_data_formatter) |
|
259 | + : esc_html__('Not an object', 'event_espresso'), |
|
260 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | + ); |
|
262 | + } |
|
263 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Gets the gateway data formatter |
|
268 | + * |
|
269 | + * @return GatewayDataFormatterInterface |
|
270 | + * @throws InvalidEntityException if it's not set properly |
|
271 | + */ |
|
272 | + protected function _get_gateway_formatter() |
|
273 | + { |
|
274 | + if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | + throw new InvalidEntityException( |
|
276 | + is_object($this->_gateway_data_formatter) |
|
277 | + ? get_class($this->_gateway_data_formatter) |
|
278 | + : esc_html__('Not an object', 'event_espresso'), |
|
279 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | + ); |
|
281 | + } |
|
282 | + return $this->_gateway_data_formatter; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Sets the helper which will remove unsupported characters for most gateways |
|
288 | + * |
|
289 | + * @param FormatterInterface $formatter |
|
290 | + * @return FormatterInterface |
|
291 | + * @throws InvalidEntityException |
|
292 | + */ |
|
293 | + public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | + { |
|
295 | + if (! $formatter instanceof FormatterInterface) { |
|
296 | + throw new InvalidEntityException( |
|
297 | + is_object($formatter) |
|
298 | + ? get_class($formatter) |
|
299 | + : esc_html__('Not an object', 'event_espresso'), |
|
300 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | + ); |
|
302 | + } |
|
303 | + $this->_unsupported_character_remover = $formatter; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | + * |
|
309 | + * @return FormatterInterface |
|
310 | + * @throws InvalidEntityException |
|
311 | + */ |
|
312 | + protected function _get_unsupported_character_remover() |
|
313 | + { |
|
314 | + if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | + throw new InvalidEntityException( |
|
316 | + is_object($this->_unsupported_character_remover) |
|
317 | + ? get_class($this->_unsupported_character_remover) |
|
318 | + : esc_html__('Not an object', 'event_espresso'), |
|
319 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | + ); |
|
321 | + } |
|
322 | + return $this->_unsupported_character_remover; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param $message |
|
328 | + * @param $payment |
|
329 | + */ |
|
330 | + public function log($message, $object_logged) |
|
331 | + { |
|
332 | + if ($object_logged instanceof EEI_Payment) { |
|
333 | + $type = 'Payment'; |
|
334 | + $id = $object_logged->ID(); |
|
335 | + } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | + $type = 'Transaction'; |
|
337 | + $id = $object_logged->ID(); |
|
338 | + } else { |
|
339 | + $type = 'Payment_Method'; |
|
340 | + $id = $this->_ID; |
|
341 | + } |
|
342 | + // only log if we're going to store it for longer than the minimum time |
|
343 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | + if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Formats the amount so it can generally be sent to gateways |
|
351 | + * |
|
352 | + * @param float $amount |
|
353 | + * @return string |
|
354 | + * @deprecated since 4.9.31 insetad use |
|
355 | + * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | + */ |
|
357 | + public function format_currency($amount) |
|
358 | + { |
|
359 | + return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Returns either an array of all the currency codes supported, |
|
364 | + * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | + * |
|
366 | + * @return mixed array or string |
|
367 | + */ |
|
368 | + public function currencies_supported() |
|
369 | + { |
|
370 | + return $this->_currencies_supported; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | + * can be used to determine if some more complex line items, like promotions, |
|
376 | + * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | + * about creating an itemized list of purchases and instead only send the total due) |
|
378 | + * |
|
379 | + * @param EE_Transaction $transaction |
|
380 | + * @return float |
|
381 | + */ |
|
382 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | + { |
|
384 | + $total_line_item = $transaction->total_line_item(); |
|
385 | + $total = 0; |
|
386 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | + $total += max($item_line_item->total(), 0); |
|
388 | + } |
|
389 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | + $total += max($tax_line_item->total(), 0); |
|
391 | + } |
|
392 | + return $total; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Determines whether or not we can easily itemize the transaction using only |
|
397 | + * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | + * |
|
399 | + * @param EEI_Payment $payment |
|
400 | + * @return boolean |
|
401 | + */ |
|
402 | + protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | + { |
|
404 | + return $this->_money->compare_floats( |
|
405 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | + $payment->transaction()->total() |
|
407 | + ) |
|
408 | + && $this->_money->compare_floats( |
|
409 | + $payment->amount(), |
|
410 | + $payment->transaction()->total() |
|
411 | + ); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Handles updating the transaction and any other related data based on the payment. |
|
416 | + * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | + * but doing so on those functions might be too early. It's possible that the changes |
|
418 | + * you make to teh transaction or registration or line items may just get overwritten |
|
419 | + * at that point. Instead, you should store any info you need on the payment during those |
|
420 | + * functions, and use that information at this step, which client code will decide |
|
421 | + * for you when it should be called. |
|
422 | + * |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @return void |
|
425 | + */ |
|
426 | + public function update_txn_based_on_payment($payment) |
|
427 | + { |
|
428 | + // maybe update the transaction or line items or registrations |
|
429 | + // but most gateways don't need to do this, because they only update the payment |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | + * |
|
435 | + * @param EEI_Payment $payment |
|
436 | + * @return EEI_Event|null |
|
437 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | + */ |
|
439 | + protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | + { |
|
441 | + return $payment->get_first_event(); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the name of the first event for which is being paid |
|
446 | + * |
|
447 | + * @param EEI_Payment $payment |
|
448 | + * @return string |
|
449 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | + */ |
|
451 | + protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | + { |
|
453 | + return $payment->get_first_event_name(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | + * |
|
459 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | + * @param EE_Payment $payment |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | + { |
|
465 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | + * |
|
471 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | + * @param EEI_Payment $payment |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | + { |
|
477 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Gets the name to use for a line item when sending line items to the gateway |
|
482 | + * |
|
483 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | + * @param EE_Line_Item $line_item |
|
485 | + * @param EEI_Payment $payment |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + protected function _format_line_item_name(EE_Line_Item $line_item, EEI_Payment $payment) |
|
489 | + { |
|
490 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets the description to use for a line item when sending line items to the gateway |
|
495 | + * |
|
496 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | + * @param EE_Line_Item $line_item |
|
498 | + * @param EEI_Payment $payment |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected function _format_line_item_desc(EE_Line_Item $line_item, EEI_Payment $payment) |
|
502 | + { |
|
503 | + return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Gets the order description that should generlly be sent to gateways |
|
508 | + * |
|
509 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | + * @param EEI_Payment $payment |
|
511 | + * @return type |
|
512 | + */ |
|
513 | + protected function _format_order_description(EEI_Payment $payment) |
|
514 | + { |
|
515 | + return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | + } |
|
517 | 517 | } |
@@ -16,14 +16,14 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * process |
|
21 | - * |
|
22 | - * @param EE_Line_Item $line_item |
|
23 | - * @return EE_Line_Item |
|
24 | - */ |
|
25 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
26 | - { |
|
27 | - return $line_item; |
|
28 | - } |
|
19 | + /** |
|
20 | + * process |
|
21 | + * |
|
22 | + * @param EE_Line_Item $line_item |
|
23 | + * @return EE_Line_Item |
|
24 | + */ |
|
25 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
26 | + { |
|
27 | + return $line_item; |
|
28 | + } |
|
29 | 29 | } |
@@ -36,95 +36,95 @@ |
||
36 | 36 | class EE_Line_Item_Filter_Processor |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | - */ |
|
42 | - protected $line_item_filters; |
|
39 | + /** |
|
40 | + * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | + */ |
|
42 | + protected $line_item_filters; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @type EE_Line_Item $grand_total_line_item |
|
46 | - */ |
|
47 | - protected $grand_total_line_item; |
|
44 | + /** |
|
45 | + * @type EE_Line_Item $grand_total_line_item |
|
46 | + */ |
|
47 | + protected $grand_total_line_item; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * EE_Line_Item_Filter_Processor constructor. |
|
52 | - * |
|
53 | - * @param EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | - * @param EE_Line_Item $grand_total_line_item |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EE_Line_Item $grand_total_line_item) |
|
59 | - { |
|
60 | - $this->line_item_filters = $line_item_filters; |
|
61 | - if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
62 | - throw new EE_Error(__('A Line Item of the type total is required', 'event_espresso')); |
|
63 | - } |
|
64 | - $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
65 | - } |
|
50 | + /** |
|
51 | + * EE_Line_Item_Filter_Processor constructor. |
|
52 | + * |
|
53 | + * @param EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | + * @param EE_Line_Item $grand_total_line_item |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EE_Line_Item $grand_total_line_item) |
|
59 | + { |
|
60 | + $this->line_item_filters = $line_item_filters; |
|
61 | + if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
62 | + throw new EE_Error(__('A Line Item of the type total is required', 'event_espresso')); |
|
63 | + } |
|
64 | + $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * clone_and_reset_line_item_tree |
|
70 | - * |
|
71 | - * @param EE_Line_Item $line_item |
|
72 | - * @return EE_Line_Item |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - protected function clone_and_reset_line_item_tree(EE_Line_Item $line_item): EE_Line_Item |
|
77 | - { |
|
78 | - $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
79 | - foreach ($line_item->children() as $child_line_item) { |
|
80 | - $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
81 | - } |
|
82 | - return $cloned_line_item; |
|
83 | - } |
|
68 | + /** |
|
69 | + * clone_and_reset_line_item_tree |
|
70 | + * |
|
71 | + * @param EE_Line_Item $line_item |
|
72 | + * @return EE_Line_Item |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + protected function clone_and_reset_line_item_tree(EE_Line_Item $line_item): EE_Line_Item |
|
77 | + { |
|
78 | + $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
79 | + foreach ($line_item->children() as $child_line_item) { |
|
80 | + $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
81 | + } |
|
82 | + return $cloned_line_item; |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * clone_and_reset_line_item |
|
88 | - * |
|
89 | - * clones the incoming object |
|
90 | - * resets any fields that represent database primary keys |
|
91 | - * resets total |
|
92 | - * |
|
93 | - * @param EE_Line_Item $line_item |
|
94 | - * @return EE_Line_Item |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - protected function clone_and_reset_line_item(EE_Line_Item $line_item): EE_Line_Item |
|
99 | - { |
|
100 | - // we don't actually want to work with the original line item, so clone it |
|
101 | - $cloned_line_item = clone $line_item; |
|
102 | - $cloned_line_item->set('LIN_ID', null); |
|
103 | - $cloned_line_item->set('LIN_parent', null); |
|
104 | - $cloned_line_item->clear_related_line_item_cache(); |
|
105 | - foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
106 | - $cloned_line_item->clear_cache($relation_name, null, true); |
|
107 | - } |
|
108 | - $cloned_line_item->set_allow_persist(false); |
|
109 | - return $cloned_line_item; |
|
110 | - } |
|
86 | + /** |
|
87 | + * clone_and_reset_line_item |
|
88 | + * |
|
89 | + * clones the incoming object |
|
90 | + * resets any fields that represent database primary keys |
|
91 | + * resets total |
|
92 | + * |
|
93 | + * @param EE_Line_Item $line_item |
|
94 | + * @return EE_Line_Item |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + protected function clone_and_reset_line_item(EE_Line_Item $line_item): EE_Line_Item |
|
99 | + { |
|
100 | + // we don't actually want to work with the original line item, so clone it |
|
101 | + $cloned_line_item = clone $line_item; |
|
102 | + $cloned_line_item->set('LIN_ID', null); |
|
103 | + $cloned_line_item->set('LIN_parent', null); |
|
104 | + $cloned_line_item->clear_related_line_item_cache(); |
|
105 | + foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
106 | + $cloned_line_item->clear_cache($relation_name, null, true); |
|
107 | + } |
|
108 | + $cloned_line_item->set_allow_persist(false); |
|
109 | + return $cloned_line_item; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * process |
|
115 | - * |
|
116 | - * @return EE_Line_Item |
|
117 | - * @throws EE_Error |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function process(): ?EE_Line_Item |
|
121 | - { |
|
122 | - $this->line_item_filters->rewind(); |
|
123 | - while ($this->line_item_filters->valid()) { |
|
124 | - $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
125 | - $this->line_item_filters->next(); |
|
126 | - } |
|
127 | - $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
128 | - return $this->grand_total_line_item; |
|
129 | - } |
|
113 | + /** |
|
114 | + * process |
|
115 | + * |
|
116 | + * @return EE_Line_Item |
|
117 | + * @throws EE_Error |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function process(): ?EE_Line_Item |
|
121 | + { |
|
122 | + $this->line_item_filters->rewind(); |
|
123 | + while ($this->line_item_filters->valid()) { |
|
124 | + $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
125 | + $this->line_item_filters->next(); |
|
126 | + } |
|
127 | + $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
128 | + return $this->grand_total_line_item; |
|
129 | + } |
|
130 | 130 | } |