@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * Adds instructions on how to brew objects |
362 | 362 | * |
363 | 363 | * @param RecipeInterface $recipe |
364 | - * @return mixed |
|
364 | + * @return boolean |
|
365 | 365 | * @throws InvalidIdentifierException |
366 | 366 | */ |
367 | 367 | public function addRecipe(RecipeInterface $recipe) |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | /** |
462 | 462 | * Adds a service to one of the internal collections |
463 | 463 | * |
464 | - * @param $identifier |
|
464 | + * @param string $identifier |
|
465 | 465 | * @param array $arguments |
466 | 466 | * @param string $type |
467 | 467 | * @return mixed |
@@ -33,594 +33,594 @@ |
||
33 | 33 | { |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * This was the best coffee related name I could think of to represent class name "aliases" |
|
38 | - * So classes can be found via an alias identifier, |
|
39 | - * that is revealed when it is run through... the filters... eh? get it? |
|
40 | - * |
|
41 | - * @var array $filters |
|
42 | - */ |
|
43 | - private $filters; |
|
44 | - |
|
45 | - /** |
|
46 | - * These are the classes that will actually build the objects (to order of course) |
|
47 | - * |
|
48 | - * @var array $coffee_makers |
|
49 | - */ |
|
50 | - private $coffee_makers; |
|
51 | - |
|
52 | - /** |
|
53 | - * where the instantiated "singleton" objects are stored |
|
54 | - * |
|
55 | - * @var CollectionInterface $carafe |
|
56 | - */ |
|
57 | - private $carafe; |
|
58 | - |
|
59 | - /** |
|
60 | - * collection of Recipes that instruct us how to brew objects |
|
61 | - * |
|
62 | - * @var CollectionInterface $recipes |
|
63 | - */ |
|
64 | - private $recipes; |
|
65 | - |
|
66 | - /** |
|
67 | - * collection of closures for brewing objects |
|
68 | - * |
|
69 | - * @var CollectionInterface $reservoir |
|
70 | - */ |
|
71 | - private $reservoir; |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * CoffeeShop constructor |
|
77 | - * |
|
78 | - * @throws InvalidInterfaceException |
|
79 | - */ |
|
80 | - public function __construct() |
|
81 | - { |
|
82 | - // array for storing class aliases |
|
83 | - $this->filters = array(); |
|
84 | - // create collection for storing shared services |
|
85 | - $this->carafe = new LooseCollection( '' ); |
|
86 | - // create collection for storing recipes that tell us how to build services and entities |
|
87 | - $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
88 | - // create collection for storing closures for constructing new entities |
|
89 | - $this->reservoir = new Collection('Closure'); |
|
90 | - // create collection for storing the generators that build our services and entity closures |
|
91 | - $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Returns true if the container can return an entry for the given identifier. |
|
98 | - * Returns false otherwise. |
|
99 | - * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
100 | - * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
101 | - * |
|
102 | - * @param string $identifier Identifier of the entry to look for. |
|
103 | - * Typically a Fully Qualified Class Name |
|
104 | - * @return boolean |
|
105 | - * @throws InvalidIdentifierException |
|
106 | - */ |
|
107 | - public function has($identifier) |
|
108 | - { |
|
109 | - $identifier = $this->filterIdentifier($identifier); |
|
110 | - return $this->carafe->has($identifier); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * finds a previously brewed (SHARED) service and returns it |
|
117 | - * |
|
118 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
119 | - * Typically a Fully Qualified Class Name |
|
120 | - * @return mixed |
|
121 | - * @throws InvalidIdentifierException |
|
122 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
123 | - */ |
|
124 | - public function get($identifier) |
|
125 | - { |
|
126 | - $identifier = $this->filterIdentifier($identifier); |
|
127 | - if ($this->carafe->has($identifier)) { |
|
128 | - return $this->carafe->get($identifier); |
|
129 | - } |
|
130 | - throw new ServiceNotFoundException($identifier); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * returns an instance of the requested entity type using the supplied arguments. |
|
137 | - * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
138 | - * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
139 | - * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
140 | - * then a new entity will be instantiated from the closure and returned. |
|
141 | - * If a closure does not exist, then one will be built and added to the reservoir |
|
142 | - * before instantiating the requested entity. |
|
143 | - * |
|
144 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
145 | - * Typically a Fully Qualified Class Name |
|
146 | - * @param array $arguments an array of arguments to be passed to the entity constructor |
|
147 | - * @param string $type |
|
148 | - * @return mixed |
|
149 | - * @throws OutOfBoundsException |
|
150 | - * @throws InstantiationException |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - * @throws InvalidClassException |
|
153 | - * @throws InvalidIdentifierException |
|
154 | - * @throws ServiceExistsException |
|
155 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
156 | - */ |
|
157 | - public function brew($identifier, $arguments = array(), $type = '') |
|
158 | - { |
|
159 | - // resolve any class aliases that may exist |
|
160 | - $identifier = $this->filterIdentifier($identifier); |
|
161 | - // is a shared service being requested and already exists in the carafe? |
|
162 | - $brewed = $this->getShared($identifier, $type); |
|
163 | - // then return whatever was found |
|
164 | - if($brewed !== false) { |
|
165 | - return $brewed; |
|
166 | - } |
|
167 | - // if the reservoir doesn't have a closure already for the requested identifier, |
|
168 | - // then neither a shared service nor a closure for making entities has been built yet |
|
169 | - if (! $this->reservoir->has($identifier)) { |
|
170 | - // so let's brew something up and add it to the proper collection |
|
171 | - $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
172 | - } |
|
173 | - // did the requested class only require loading, and if so, was that successful? |
|
174 | - if($this->brewedLoadOnly($brewed, $identifier, $type) === true) { |
|
175 | - return true; |
|
176 | - } |
|
177 | - // was the brewed item a callable factory function ? |
|
178 | - if (is_callable($brewed)) { |
|
179 | - // then instantiate a new entity from the cached closure |
|
180 | - return $brewed($arguments); |
|
181 | - } |
|
182 | - if ($brewed) { |
|
183 | - // requested object was a shared entity, so attempt to get it from the carafe again |
|
184 | - // because if it wasn't there before, then it should have just been brewed and added, |
|
185 | - // but if it still isn't there, then this time the thrown ServiceNotFoundException will not be caught |
|
186 | - return $this->get($identifier); |
|
187 | - } |
|
188 | - // if identifier is for a non-shared entity, |
|
189 | - // then either a cached closure already existed, or was just brewed |
|
190 | - return $this->brewedClosure($identifier, $arguments); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $identifier |
|
197 | - * @param string $type |
|
198 | - * @return bool|mixed |
|
199 | - * @throws InvalidIdentifierException |
|
200 | - */ |
|
201 | - protected function getShared($identifier, $type) |
|
202 | - { |
|
203 | - try { |
|
204 | - if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
205 | - // if a shared service was requested and an instance is in the carafe, then return it |
|
206 | - return $this->get($identifier); |
|
207 | - } |
|
208 | - } catch (ServiceNotFoundException $e) { |
|
209 | - // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
210 | - // and instead, attempt to build whatever was requested |
|
211 | - } |
|
212 | - return false; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @param mixed $brewed |
|
219 | - * @param string $identifier |
|
220 | - * @param string $type |
|
221 | - * @return bool |
|
222 | - * @throws InvalidClassException |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - * @throws InvalidIdentifierException |
|
225 | - * @throws OutOfBoundsException |
|
226 | - * @throws ServiceExistsException |
|
227 | - * @throws ServiceNotFoundException |
|
228 | - */ |
|
229 | - protected function brewedLoadOnly($brewed, $identifier, $type) |
|
230 | - { |
|
231 | - if ($type === CoffeeMaker::BREW_LOAD_ONLY) { |
|
232 | - if ($brewed !== true) { |
|
233 | - throw new ServiceNotFoundException( |
|
234 | - sprintf( |
|
235 | - esc_html__( |
|
236 | - 'The "%1$s" class could not be loaded.', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - $identifier |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - return true; |
|
244 | - } |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $identifier |
|
252 | - * @param array $arguments |
|
253 | - * @return mixed |
|
254 | - * @throws InstantiationException |
|
255 | - */ |
|
256 | - protected function brewedClosure($identifier, array $arguments) |
|
257 | - { |
|
258 | - $closure = $this->reservoir->get($identifier); |
|
259 | - if (empty($closure)) { |
|
260 | - throw new InstantiationException( |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - 'Could not brew an instance of "%1$s".', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - $identifier |
|
267 | - ) |
|
268 | - ); |
|
269 | - } |
|
270 | - return $closure($arguments); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @param CoffeeMakerInterface $coffee_maker |
|
277 | - * @param string $type |
|
278 | - * @return bool |
|
279 | - * @throws InvalidIdentifierException |
|
280 | - * @throws InvalidEntityException |
|
281 | - */ |
|
282 | - public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
283 | - { |
|
284 | - $type = CoffeeMaker::validateType($type); |
|
285 | - return $this->coffee_makers->add($coffee_maker, $type); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @param string $identifier |
|
292 | - * @param callable $closure |
|
293 | - * @return callable|null |
|
294 | - * @throws InvalidIdentifierException |
|
295 | - * @throws InvalidDataTypeException |
|
296 | - */ |
|
297 | - public function addClosure($identifier, $closure) |
|
298 | - { |
|
299 | - if ( ! is_callable($closure)) { |
|
300 | - throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
301 | - } |
|
302 | - $identifier = $this->processIdentifier($identifier); |
|
303 | - if ($this->reservoir->add($closure, $identifier)) { |
|
304 | - return $closure; |
|
305 | - } |
|
306 | - return null; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @param string $identifier |
|
313 | - * @return boolean |
|
314 | - * @throws InvalidIdentifierException |
|
315 | - */ |
|
316 | - public function removeClosure($identifier) |
|
317 | - { |
|
318 | - $identifier = $this->processIdentifier($identifier); |
|
319 | - if ($this->reservoir->has($identifier)) { |
|
320 | - return $this->reservoir->remove($this->reservoir->get($identifier)); |
|
321 | - } |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
329 | - * Typically a Fully Qualified Class Name |
|
330 | - * @param mixed $service |
|
331 | - * @return bool |
|
332 | - * @throws \EventEspresso\core\services\container\exceptions\InvalidServiceException |
|
333 | - * @throws InvalidIdentifierException |
|
334 | - */ |
|
335 | - public function addService($identifier, $service) |
|
336 | - { |
|
337 | - $identifier = $this->processIdentifier($identifier); |
|
338 | - $service = $this->validateService($identifier, $service); |
|
339 | - return $this->carafe->add($service, $identifier); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @param string $identifier |
|
346 | - * @return boolean |
|
347 | - * @throws InvalidIdentifierException |
|
348 | - */ |
|
349 | - public function removeService($identifier) |
|
350 | - { |
|
351 | - $identifier = $this->processIdentifier($identifier); |
|
352 | - if ($this->carafe->has($identifier)) { |
|
353 | - return $this->carafe->remove($this->carafe->get($identifier)); |
|
354 | - } |
|
355 | - return false; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Adds instructions on how to brew objects |
|
362 | - * |
|
363 | - * @param RecipeInterface $recipe |
|
364 | - * @return mixed |
|
365 | - * @throws InvalidIdentifierException |
|
366 | - */ |
|
367 | - public function addRecipe(RecipeInterface $recipe) |
|
368 | - { |
|
369 | - $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
370 | - $identifier = $this->processIdentifier($recipe->identifier()); |
|
371 | - return $this->recipes->add($recipe, $identifier); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @param string $identifier The Recipe's identifier |
|
378 | - * @return boolean |
|
379 | - * @throws InvalidIdentifierException |
|
380 | - */ |
|
381 | - public function removeRecipe($identifier) |
|
382 | - { |
|
383 | - $identifier = $this->processIdentifier($identifier); |
|
384 | - if ($this->recipes->has($identifier)) { |
|
385 | - return $this->recipes->remove($this->recipes->get($identifier)); |
|
386 | - } |
|
387 | - return false; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Get instructions on how to brew objects |
|
394 | - * |
|
395 | - * @param string $identifier Identifier for the entity class that the recipe applies to |
|
396 | - * Typically a Fully Qualified Class Name |
|
397 | - * @param string $type |
|
398 | - * @return RecipeInterface |
|
399 | - * @throws OutOfBoundsException |
|
400 | - * @throws InvalidIdentifierException |
|
401 | - */ |
|
402 | - public function getRecipe($identifier, $type = '') |
|
403 | - { |
|
404 | - $identifier = $this->processIdentifier($identifier); |
|
405 | - if ($this->recipes->has($identifier)) { |
|
406 | - return $this->recipes->get($identifier); |
|
407 | - } |
|
408 | - $default_recipes = $this->getDefaultRecipes(); |
|
409 | - $matches = array(); |
|
410 | - foreach ($default_recipes as $wildcard => $default_recipe) { |
|
411 | - // is the wildcard recipe prefix in the identifier ? |
|
412 | - if (strpos($identifier, $wildcard) !== false) { |
|
413 | - // track matches and use the number of wildcard characters matched for the key |
|
414 | - $matches[strlen($wildcard)] = $default_recipe; |
|
415 | - } |
|
416 | - } |
|
417 | - if (count($matches) > 0) { |
|
418 | - // sort our recipes by the number of wildcard characters matched |
|
419 | - ksort($matches); |
|
420 | - // then grab the last recipe form the list, since it had the most matching characters |
|
421 | - $match = array_pop($matches); |
|
422 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
423 | - return $this->copyDefaultRecipe($match, $identifier, $type); |
|
424 | - } |
|
425 | - if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
426 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
427 | - return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
428 | - } |
|
429 | - throw new OutOfBoundsException( |
|
430 | - sprintf( |
|
431 | - __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
432 | - $identifier |
|
433 | - ) |
|
434 | - ); |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * adds class name aliases to list of filters |
|
441 | - * |
|
442 | - * @param string $identifier Identifier for the entity class that the alias applies to |
|
443 | - * Typically a Fully Qualified Class Name |
|
444 | - * @param array $aliases |
|
445 | - * @return void |
|
446 | - * @throws InvalidIdentifierException |
|
447 | - */ |
|
448 | - public function addAliases($identifier, $aliases) |
|
449 | - { |
|
450 | - if (empty($aliases)) { |
|
451 | - return; |
|
452 | - } |
|
453 | - $identifier = $this->processIdentifier($identifier); |
|
454 | - foreach ((array)$aliases as $alias) { |
|
455 | - $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * Adds a service to one of the internal collections |
|
463 | - * |
|
464 | - * @param $identifier |
|
465 | - * @param array $arguments |
|
466 | - * @param string $type |
|
467 | - * @return mixed |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidClassException |
|
470 | - * @throws OutOfBoundsException |
|
471 | - * @throws InvalidIdentifierException |
|
472 | - * @throws ServiceExistsException |
|
473 | - */ |
|
474 | - private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
475 | - { |
|
476 | - if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
477 | - throw new ServiceExistsException($identifier); |
|
478 | - } |
|
479 | - $identifier = $this->filterIdentifier($identifier); |
|
480 | - $recipe = $this->getRecipe($identifier, $type); |
|
481 | - $type = ! empty($type) ? $type : $recipe->type(); |
|
482 | - $coffee_maker = $this->getCoffeeMaker($type); |
|
483 | - return $coffee_maker->brew($recipe, $arguments); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * filters alias identifiers to find the real class name |
|
490 | - * |
|
491 | - * @param string $identifier Identifier for the entity class that the filter applies to |
|
492 | - * Typically a Fully Qualified Class Name |
|
493 | - * @return string |
|
494 | - * @throws InvalidIdentifierException |
|
495 | - */ |
|
496 | - private function filterIdentifier($identifier) |
|
497 | - { |
|
498 | - $identifier = $this->processIdentifier($identifier); |
|
499 | - return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
500 | - ? $this->filters[$identifier] |
|
501 | - : $identifier; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * verifies and standardizes identifiers |
|
508 | - * |
|
509 | - * @param string $identifier Identifier for the entity class |
|
510 | - * Typically a Fully Qualified Class Name |
|
511 | - * @return string |
|
512 | - * @throws InvalidIdentifierException |
|
513 | - */ |
|
514 | - private function processIdentifier($identifier) |
|
515 | - { |
|
516 | - if ( ! is_string($identifier)) { |
|
517 | - throw new InvalidIdentifierException( |
|
518 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
519 | - '\Fully\Qualified\ClassName' |
|
520 | - ); |
|
521 | - } |
|
522 | - return ltrim($identifier, '\\'); |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * @param string $type |
|
529 | - * @return CoffeeMakerInterface |
|
530 | - * @throws OutOfBoundsException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws InvalidClassException |
|
533 | - */ |
|
534 | - private function getCoffeeMaker($type) |
|
535 | - { |
|
536 | - if ( ! $this->coffee_makers->has($type)) { |
|
537 | - throw new OutOfBoundsException( |
|
538 | - __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
539 | - ); |
|
540 | - } |
|
541 | - return $this->coffee_makers->get($type); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Retrieves all recipes that use a wildcard "*" in their identifier |
|
548 | - * This allows recipes to be set up for handling |
|
549 | - * legacy classes that do not support PSR-4 autoloading. |
|
550 | - * for example: |
|
551 | - * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
552 | - * |
|
553 | - * @return array |
|
554 | - */ |
|
555 | - private function getDefaultRecipes() |
|
556 | - { |
|
557 | - $default_recipes = array(); |
|
558 | - $this->recipes->rewind(); |
|
559 | - while ($this->recipes->valid()) { |
|
560 | - $identifier = $this->recipes->getInfo(); |
|
561 | - // does this recipe use a wildcard ? (but is NOT the global default) |
|
562 | - if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
563 | - // strip the wildcard and use identifier as key |
|
564 | - $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
565 | - } |
|
566 | - $this->recipes->next(); |
|
567 | - } |
|
568 | - return $default_recipes; |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * clones a default recipe and then copies details |
|
575 | - * from the incoming request to it so that it can be used |
|
576 | - * |
|
577 | - * @param RecipeInterface $default_recipe |
|
578 | - * @param string $identifier |
|
579 | - * @param string $type |
|
580 | - * @return RecipeInterface |
|
581 | - */ |
|
582 | - private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
583 | - { |
|
584 | - $recipe = clone $default_recipe; |
|
585 | - if ( ! empty($type)) { |
|
586 | - $recipe->setType($type); |
|
587 | - } |
|
588 | - // is this the base default recipe ? |
|
589 | - if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
590 | - $recipe->setIdentifier($identifier); |
|
591 | - $recipe->setFqcn($identifier); |
|
592 | - return $recipe; |
|
593 | - } |
|
594 | - $recipe->setIdentifier($identifier); |
|
595 | - foreach ($default_recipe->paths() as $path) { |
|
596 | - $path = str_replace('*', $identifier, $path); |
|
597 | - if (is_readable($path)) { |
|
598 | - $recipe->setPaths($path); |
|
599 | - } |
|
600 | - } |
|
601 | - $recipe->setFqcn($identifier); |
|
602 | - return $recipe; |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
609 | - * Typically a Fully Qualified Class Name |
|
610 | - * @param mixed $service |
|
611 | - * @return mixed |
|
612 | - * @throws InvalidServiceException |
|
613 | - */ |
|
614 | - private function validateService($identifier, $service) |
|
615 | - { |
|
616 | - if ( ! is_object($service)) { |
|
617 | - throw new InvalidServiceException( |
|
618 | - $identifier, |
|
619 | - $service |
|
620 | - ); |
|
621 | - } |
|
622 | - return $service; |
|
623 | - } |
|
36 | + /** |
|
37 | + * This was the best coffee related name I could think of to represent class name "aliases" |
|
38 | + * So classes can be found via an alias identifier, |
|
39 | + * that is revealed when it is run through... the filters... eh? get it? |
|
40 | + * |
|
41 | + * @var array $filters |
|
42 | + */ |
|
43 | + private $filters; |
|
44 | + |
|
45 | + /** |
|
46 | + * These are the classes that will actually build the objects (to order of course) |
|
47 | + * |
|
48 | + * @var array $coffee_makers |
|
49 | + */ |
|
50 | + private $coffee_makers; |
|
51 | + |
|
52 | + /** |
|
53 | + * where the instantiated "singleton" objects are stored |
|
54 | + * |
|
55 | + * @var CollectionInterface $carafe |
|
56 | + */ |
|
57 | + private $carafe; |
|
58 | + |
|
59 | + /** |
|
60 | + * collection of Recipes that instruct us how to brew objects |
|
61 | + * |
|
62 | + * @var CollectionInterface $recipes |
|
63 | + */ |
|
64 | + private $recipes; |
|
65 | + |
|
66 | + /** |
|
67 | + * collection of closures for brewing objects |
|
68 | + * |
|
69 | + * @var CollectionInterface $reservoir |
|
70 | + */ |
|
71 | + private $reservoir; |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * CoffeeShop constructor |
|
77 | + * |
|
78 | + * @throws InvalidInterfaceException |
|
79 | + */ |
|
80 | + public function __construct() |
|
81 | + { |
|
82 | + // array for storing class aliases |
|
83 | + $this->filters = array(); |
|
84 | + // create collection for storing shared services |
|
85 | + $this->carafe = new LooseCollection( '' ); |
|
86 | + // create collection for storing recipes that tell us how to build services and entities |
|
87 | + $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
88 | + // create collection for storing closures for constructing new entities |
|
89 | + $this->reservoir = new Collection('Closure'); |
|
90 | + // create collection for storing the generators that build our services and entity closures |
|
91 | + $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Returns true if the container can return an entry for the given identifier. |
|
98 | + * Returns false otherwise. |
|
99 | + * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
100 | + * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
101 | + * |
|
102 | + * @param string $identifier Identifier of the entry to look for. |
|
103 | + * Typically a Fully Qualified Class Name |
|
104 | + * @return boolean |
|
105 | + * @throws InvalidIdentifierException |
|
106 | + */ |
|
107 | + public function has($identifier) |
|
108 | + { |
|
109 | + $identifier = $this->filterIdentifier($identifier); |
|
110 | + return $this->carafe->has($identifier); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * finds a previously brewed (SHARED) service and returns it |
|
117 | + * |
|
118 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
119 | + * Typically a Fully Qualified Class Name |
|
120 | + * @return mixed |
|
121 | + * @throws InvalidIdentifierException |
|
122 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
123 | + */ |
|
124 | + public function get($identifier) |
|
125 | + { |
|
126 | + $identifier = $this->filterIdentifier($identifier); |
|
127 | + if ($this->carafe->has($identifier)) { |
|
128 | + return $this->carafe->get($identifier); |
|
129 | + } |
|
130 | + throw new ServiceNotFoundException($identifier); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * returns an instance of the requested entity type using the supplied arguments. |
|
137 | + * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
138 | + * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
139 | + * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
140 | + * then a new entity will be instantiated from the closure and returned. |
|
141 | + * If a closure does not exist, then one will be built and added to the reservoir |
|
142 | + * before instantiating the requested entity. |
|
143 | + * |
|
144 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
145 | + * Typically a Fully Qualified Class Name |
|
146 | + * @param array $arguments an array of arguments to be passed to the entity constructor |
|
147 | + * @param string $type |
|
148 | + * @return mixed |
|
149 | + * @throws OutOfBoundsException |
|
150 | + * @throws InstantiationException |
|
151 | + * @throws InvalidDataTypeException |
|
152 | + * @throws InvalidClassException |
|
153 | + * @throws InvalidIdentifierException |
|
154 | + * @throws ServiceExistsException |
|
155 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
156 | + */ |
|
157 | + public function brew($identifier, $arguments = array(), $type = '') |
|
158 | + { |
|
159 | + // resolve any class aliases that may exist |
|
160 | + $identifier = $this->filterIdentifier($identifier); |
|
161 | + // is a shared service being requested and already exists in the carafe? |
|
162 | + $brewed = $this->getShared($identifier, $type); |
|
163 | + // then return whatever was found |
|
164 | + if($brewed !== false) { |
|
165 | + return $brewed; |
|
166 | + } |
|
167 | + // if the reservoir doesn't have a closure already for the requested identifier, |
|
168 | + // then neither a shared service nor a closure for making entities has been built yet |
|
169 | + if (! $this->reservoir->has($identifier)) { |
|
170 | + // so let's brew something up and add it to the proper collection |
|
171 | + $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
172 | + } |
|
173 | + // did the requested class only require loading, and if so, was that successful? |
|
174 | + if($this->brewedLoadOnly($brewed, $identifier, $type) === true) { |
|
175 | + return true; |
|
176 | + } |
|
177 | + // was the brewed item a callable factory function ? |
|
178 | + if (is_callable($brewed)) { |
|
179 | + // then instantiate a new entity from the cached closure |
|
180 | + return $brewed($arguments); |
|
181 | + } |
|
182 | + if ($brewed) { |
|
183 | + // requested object was a shared entity, so attempt to get it from the carafe again |
|
184 | + // because if it wasn't there before, then it should have just been brewed and added, |
|
185 | + // but if it still isn't there, then this time the thrown ServiceNotFoundException will not be caught |
|
186 | + return $this->get($identifier); |
|
187 | + } |
|
188 | + // if identifier is for a non-shared entity, |
|
189 | + // then either a cached closure already existed, or was just brewed |
|
190 | + return $this->brewedClosure($identifier, $arguments); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $identifier |
|
197 | + * @param string $type |
|
198 | + * @return bool|mixed |
|
199 | + * @throws InvalidIdentifierException |
|
200 | + */ |
|
201 | + protected function getShared($identifier, $type) |
|
202 | + { |
|
203 | + try { |
|
204 | + if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
205 | + // if a shared service was requested and an instance is in the carafe, then return it |
|
206 | + return $this->get($identifier); |
|
207 | + } |
|
208 | + } catch (ServiceNotFoundException $e) { |
|
209 | + // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
210 | + // and instead, attempt to build whatever was requested |
|
211 | + } |
|
212 | + return false; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @param mixed $brewed |
|
219 | + * @param string $identifier |
|
220 | + * @param string $type |
|
221 | + * @return bool |
|
222 | + * @throws InvalidClassException |
|
223 | + * @throws InvalidDataTypeException |
|
224 | + * @throws InvalidIdentifierException |
|
225 | + * @throws OutOfBoundsException |
|
226 | + * @throws ServiceExistsException |
|
227 | + * @throws ServiceNotFoundException |
|
228 | + */ |
|
229 | + protected function brewedLoadOnly($brewed, $identifier, $type) |
|
230 | + { |
|
231 | + if ($type === CoffeeMaker::BREW_LOAD_ONLY) { |
|
232 | + if ($brewed !== true) { |
|
233 | + throw new ServiceNotFoundException( |
|
234 | + sprintf( |
|
235 | + esc_html__( |
|
236 | + 'The "%1$s" class could not be loaded.', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + $identifier |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + return true; |
|
244 | + } |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $identifier |
|
252 | + * @param array $arguments |
|
253 | + * @return mixed |
|
254 | + * @throws InstantiationException |
|
255 | + */ |
|
256 | + protected function brewedClosure($identifier, array $arguments) |
|
257 | + { |
|
258 | + $closure = $this->reservoir->get($identifier); |
|
259 | + if (empty($closure)) { |
|
260 | + throw new InstantiationException( |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + 'Could not brew an instance of "%1$s".', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + $identifier |
|
267 | + ) |
|
268 | + ); |
|
269 | + } |
|
270 | + return $closure($arguments); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @param CoffeeMakerInterface $coffee_maker |
|
277 | + * @param string $type |
|
278 | + * @return bool |
|
279 | + * @throws InvalidIdentifierException |
|
280 | + * @throws InvalidEntityException |
|
281 | + */ |
|
282 | + public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
283 | + { |
|
284 | + $type = CoffeeMaker::validateType($type); |
|
285 | + return $this->coffee_makers->add($coffee_maker, $type); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @param string $identifier |
|
292 | + * @param callable $closure |
|
293 | + * @return callable|null |
|
294 | + * @throws InvalidIdentifierException |
|
295 | + * @throws InvalidDataTypeException |
|
296 | + */ |
|
297 | + public function addClosure($identifier, $closure) |
|
298 | + { |
|
299 | + if ( ! is_callable($closure)) { |
|
300 | + throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
301 | + } |
|
302 | + $identifier = $this->processIdentifier($identifier); |
|
303 | + if ($this->reservoir->add($closure, $identifier)) { |
|
304 | + return $closure; |
|
305 | + } |
|
306 | + return null; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @param string $identifier |
|
313 | + * @return boolean |
|
314 | + * @throws InvalidIdentifierException |
|
315 | + */ |
|
316 | + public function removeClosure($identifier) |
|
317 | + { |
|
318 | + $identifier = $this->processIdentifier($identifier); |
|
319 | + if ($this->reservoir->has($identifier)) { |
|
320 | + return $this->reservoir->remove($this->reservoir->get($identifier)); |
|
321 | + } |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
329 | + * Typically a Fully Qualified Class Name |
|
330 | + * @param mixed $service |
|
331 | + * @return bool |
|
332 | + * @throws \EventEspresso\core\services\container\exceptions\InvalidServiceException |
|
333 | + * @throws InvalidIdentifierException |
|
334 | + */ |
|
335 | + public function addService($identifier, $service) |
|
336 | + { |
|
337 | + $identifier = $this->processIdentifier($identifier); |
|
338 | + $service = $this->validateService($identifier, $service); |
|
339 | + return $this->carafe->add($service, $identifier); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @param string $identifier |
|
346 | + * @return boolean |
|
347 | + * @throws InvalidIdentifierException |
|
348 | + */ |
|
349 | + public function removeService($identifier) |
|
350 | + { |
|
351 | + $identifier = $this->processIdentifier($identifier); |
|
352 | + if ($this->carafe->has($identifier)) { |
|
353 | + return $this->carafe->remove($this->carafe->get($identifier)); |
|
354 | + } |
|
355 | + return false; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Adds instructions on how to brew objects |
|
362 | + * |
|
363 | + * @param RecipeInterface $recipe |
|
364 | + * @return mixed |
|
365 | + * @throws InvalidIdentifierException |
|
366 | + */ |
|
367 | + public function addRecipe(RecipeInterface $recipe) |
|
368 | + { |
|
369 | + $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
370 | + $identifier = $this->processIdentifier($recipe->identifier()); |
|
371 | + return $this->recipes->add($recipe, $identifier); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @param string $identifier The Recipe's identifier |
|
378 | + * @return boolean |
|
379 | + * @throws InvalidIdentifierException |
|
380 | + */ |
|
381 | + public function removeRecipe($identifier) |
|
382 | + { |
|
383 | + $identifier = $this->processIdentifier($identifier); |
|
384 | + if ($this->recipes->has($identifier)) { |
|
385 | + return $this->recipes->remove($this->recipes->get($identifier)); |
|
386 | + } |
|
387 | + return false; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Get instructions on how to brew objects |
|
394 | + * |
|
395 | + * @param string $identifier Identifier for the entity class that the recipe applies to |
|
396 | + * Typically a Fully Qualified Class Name |
|
397 | + * @param string $type |
|
398 | + * @return RecipeInterface |
|
399 | + * @throws OutOfBoundsException |
|
400 | + * @throws InvalidIdentifierException |
|
401 | + */ |
|
402 | + public function getRecipe($identifier, $type = '') |
|
403 | + { |
|
404 | + $identifier = $this->processIdentifier($identifier); |
|
405 | + if ($this->recipes->has($identifier)) { |
|
406 | + return $this->recipes->get($identifier); |
|
407 | + } |
|
408 | + $default_recipes = $this->getDefaultRecipes(); |
|
409 | + $matches = array(); |
|
410 | + foreach ($default_recipes as $wildcard => $default_recipe) { |
|
411 | + // is the wildcard recipe prefix in the identifier ? |
|
412 | + if (strpos($identifier, $wildcard) !== false) { |
|
413 | + // track matches and use the number of wildcard characters matched for the key |
|
414 | + $matches[strlen($wildcard)] = $default_recipe; |
|
415 | + } |
|
416 | + } |
|
417 | + if (count($matches) > 0) { |
|
418 | + // sort our recipes by the number of wildcard characters matched |
|
419 | + ksort($matches); |
|
420 | + // then grab the last recipe form the list, since it had the most matching characters |
|
421 | + $match = array_pop($matches); |
|
422 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
423 | + return $this->copyDefaultRecipe($match, $identifier, $type); |
|
424 | + } |
|
425 | + if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
426 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
427 | + return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
428 | + } |
|
429 | + throw new OutOfBoundsException( |
|
430 | + sprintf( |
|
431 | + __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
432 | + $identifier |
|
433 | + ) |
|
434 | + ); |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * adds class name aliases to list of filters |
|
441 | + * |
|
442 | + * @param string $identifier Identifier for the entity class that the alias applies to |
|
443 | + * Typically a Fully Qualified Class Name |
|
444 | + * @param array $aliases |
|
445 | + * @return void |
|
446 | + * @throws InvalidIdentifierException |
|
447 | + */ |
|
448 | + public function addAliases($identifier, $aliases) |
|
449 | + { |
|
450 | + if (empty($aliases)) { |
|
451 | + return; |
|
452 | + } |
|
453 | + $identifier = $this->processIdentifier($identifier); |
|
454 | + foreach ((array)$aliases as $alias) { |
|
455 | + $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * Adds a service to one of the internal collections |
|
463 | + * |
|
464 | + * @param $identifier |
|
465 | + * @param array $arguments |
|
466 | + * @param string $type |
|
467 | + * @return mixed |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidClassException |
|
470 | + * @throws OutOfBoundsException |
|
471 | + * @throws InvalidIdentifierException |
|
472 | + * @throws ServiceExistsException |
|
473 | + */ |
|
474 | + private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
475 | + { |
|
476 | + if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
477 | + throw new ServiceExistsException($identifier); |
|
478 | + } |
|
479 | + $identifier = $this->filterIdentifier($identifier); |
|
480 | + $recipe = $this->getRecipe($identifier, $type); |
|
481 | + $type = ! empty($type) ? $type : $recipe->type(); |
|
482 | + $coffee_maker = $this->getCoffeeMaker($type); |
|
483 | + return $coffee_maker->brew($recipe, $arguments); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * filters alias identifiers to find the real class name |
|
490 | + * |
|
491 | + * @param string $identifier Identifier for the entity class that the filter applies to |
|
492 | + * Typically a Fully Qualified Class Name |
|
493 | + * @return string |
|
494 | + * @throws InvalidIdentifierException |
|
495 | + */ |
|
496 | + private function filterIdentifier($identifier) |
|
497 | + { |
|
498 | + $identifier = $this->processIdentifier($identifier); |
|
499 | + return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
500 | + ? $this->filters[$identifier] |
|
501 | + : $identifier; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * verifies and standardizes identifiers |
|
508 | + * |
|
509 | + * @param string $identifier Identifier for the entity class |
|
510 | + * Typically a Fully Qualified Class Name |
|
511 | + * @return string |
|
512 | + * @throws InvalidIdentifierException |
|
513 | + */ |
|
514 | + private function processIdentifier($identifier) |
|
515 | + { |
|
516 | + if ( ! is_string($identifier)) { |
|
517 | + throw new InvalidIdentifierException( |
|
518 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
519 | + '\Fully\Qualified\ClassName' |
|
520 | + ); |
|
521 | + } |
|
522 | + return ltrim($identifier, '\\'); |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * @param string $type |
|
529 | + * @return CoffeeMakerInterface |
|
530 | + * @throws OutOfBoundsException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws InvalidClassException |
|
533 | + */ |
|
534 | + private function getCoffeeMaker($type) |
|
535 | + { |
|
536 | + if ( ! $this->coffee_makers->has($type)) { |
|
537 | + throw new OutOfBoundsException( |
|
538 | + __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
539 | + ); |
|
540 | + } |
|
541 | + return $this->coffee_makers->get($type); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Retrieves all recipes that use a wildcard "*" in their identifier |
|
548 | + * This allows recipes to be set up for handling |
|
549 | + * legacy classes that do not support PSR-4 autoloading. |
|
550 | + * for example: |
|
551 | + * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
552 | + * |
|
553 | + * @return array |
|
554 | + */ |
|
555 | + private function getDefaultRecipes() |
|
556 | + { |
|
557 | + $default_recipes = array(); |
|
558 | + $this->recipes->rewind(); |
|
559 | + while ($this->recipes->valid()) { |
|
560 | + $identifier = $this->recipes->getInfo(); |
|
561 | + // does this recipe use a wildcard ? (but is NOT the global default) |
|
562 | + if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
563 | + // strip the wildcard and use identifier as key |
|
564 | + $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
565 | + } |
|
566 | + $this->recipes->next(); |
|
567 | + } |
|
568 | + return $default_recipes; |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * clones a default recipe and then copies details |
|
575 | + * from the incoming request to it so that it can be used |
|
576 | + * |
|
577 | + * @param RecipeInterface $default_recipe |
|
578 | + * @param string $identifier |
|
579 | + * @param string $type |
|
580 | + * @return RecipeInterface |
|
581 | + */ |
|
582 | + private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
583 | + { |
|
584 | + $recipe = clone $default_recipe; |
|
585 | + if ( ! empty($type)) { |
|
586 | + $recipe->setType($type); |
|
587 | + } |
|
588 | + // is this the base default recipe ? |
|
589 | + if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
590 | + $recipe->setIdentifier($identifier); |
|
591 | + $recipe->setFqcn($identifier); |
|
592 | + return $recipe; |
|
593 | + } |
|
594 | + $recipe->setIdentifier($identifier); |
|
595 | + foreach ($default_recipe->paths() as $path) { |
|
596 | + $path = str_replace('*', $identifier, $path); |
|
597 | + if (is_readable($path)) { |
|
598 | + $recipe->setPaths($path); |
|
599 | + } |
|
600 | + } |
|
601 | + $recipe->setFqcn($identifier); |
|
602 | + return $recipe; |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
609 | + * Typically a Fully Qualified Class Name |
|
610 | + * @param mixed $service |
|
611 | + * @return mixed |
|
612 | + * @throws InvalidServiceException |
|
613 | + */ |
|
614 | + private function validateService($identifier, $service) |
|
615 | + { |
|
616 | + if ( ! is_object($service)) { |
|
617 | + throw new InvalidServiceException( |
|
618 | + $identifier, |
|
619 | + $service |
|
620 | + ); |
|
621 | + } |
|
622 | + return $service; |
|
623 | + } |
|
624 | 624 | |
625 | 625 | } |
626 | 626 | // End of file CoffeeShop.php |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | // array for storing class aliases |
83 | 83 | $this->filters = array(); |
84 | 84 | // create collection for storing shared services |
85 | - $this->carafe = new LooseCollection( '' ); |
|
85 | + $this->carafe = new LooseCollection(''); |
|
86 | 86 | // create collection for storing recipes that tell us how to build services and entities |
87 | 87 | $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
88 | 88 | // create collection for storing closures for constructing new entities |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | // is a shared service being requested and already exists in the carafe? |
162 | 162 | $brewed = $this->getShared($identifier, $type); |
163 | 163 | // then return whatever was found |
164 | - if($brewed !== false) { |
|
164 | + if ($brewed !== false) { |
|
165 | 165 | return $brewed; |
166 | 166 | } |
167 | 167 | // if the reservoir doesn't have a closure already for the requested identifier, |
168 | 168 | // then neither a shared service nor a closure for making entities has been built yet |
169 | - if (! $this->reservoir->has($identifier)) { |
|
169 | + if ( ! $this->reservoir->has($identifier)) { |
|
170 | 170 | // so let's brew something up and add it to the proper collection |
171 | 171 | $brewed = $this->makeCoffee($identifier, $arguments, $type); |
172 | 172 | } |
173 | 173 | // did the requested class only require loading, and if so, was that successful? |
174 | - if($this->brewedLoadOnly($brewed, $identifier, $type) === true) { |
|
174 | + if ($this->brewedLoadOnly($brewed, $identifier, $type) === true) { |
|
175 | 175 | return true; |
176 | 176 | } |
177 | 177 | // was the brewed item a callable factory function ? |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | return; |
452 | 452 | } |
453 | 453 | $identifier = $this->processIdentifier($identifier); |
454 | - foreach ((array)$aliases as $alias) { |
|
454 | + foreach ((array) $aliases as $alias) { |
|
455 | 455 | $this->filters[$this->processIdentifier($alias)] = $identifier; |
456 | 456 | } |
457 | 457 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\exceptions\InvalidClassException; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -26,26 +26,26 @@ discard block |
||
26 | 26 | class LoadOnlyCoffeeMaker extends CoffeeMaker |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function type() |
|
33 | - { |
|
34 | - return CoffeeMaker::BREW_LOAD_ONLY; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param RecipeInterface $recipe |
|
41 | - * @param array $arguments |
|
42 | - * @return mixed |
|
43 | - * @throws InvalidClassException |
|
44 | - */ |
|
45 | - public function brew(RecipeInterface $recipe, $arguments = array()) |
|
46 | - { |
|
47 | - return $this->resolveClassAndFilepath($recipe); |
|
48 | - } |
|
29 | + /** |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function type() |
|
33 | + { |
|
34 | + return CoffeeMaker::BREW_LOAD_ONLY; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param RecipeInterface $recipe |
|
41 | + * @param array $arguments |
|
42 | + * @return mixed |
|
43 | + * @throws InvalidClassException |
|
44 | + */ |
|
45 | + public function brew(RecipeInterface $recipe, $arguments = array()) |
|
46 | + { |
|
47 | + return $this->resolveClassAndFilepath($recipe); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use RuntimeException; |
9 | 9 | |
10 | 10 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
11 | - exit('No direct script access allowed'); |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -24,316 +24,316 @@ discard block |
||
24 | 24 | class Recipe implements RecipeInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * A default Recipe to use if none is specified for a class |
|
29 | - */ |
|
30 | - const DEFAULT_ID = '*'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Identifier for the entity class to be constructed. |
|
34 | - * Typically a Fully Qualified Class Name |
|
35 | - * |
|
36 | - * @var string $identifier |
|
37 | - */ |
|
38 | - private $identifier; |
|
39 | - |
|
40 | - /** |
|
41 | - * Fully Qualified Class Name |
|
42 | - * |
|
43 | - * @var string $fqcn |
|
44 | - */ |
|
45 | - private $fqcn; |
|
46 | - |
|
47 | - /** |
|
48 | - * a dependency class map array |
|
49 | - * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments), |
|
50 | - * and that class type hints for an interface, then this property allows you to configure what dependencies |
|
51 | - * get used when instantiating the class. |
|
52 | - * For example: |
|
53 | - * There's a class called Coffee, and one of its constructor arguments is BeanInterface |
|
54 | - * There are two implementations of BeanInterface: HonduranBean, and KenyanBean |
|
55 | - * We want one Coffee object to use HonduranBean for its BeanInterface, |
|
56 | - * and the 2nd Coffee object to use KenyanBean for its BeanInterface. |
|
57 | - * To do this, we need to create two Recipes: |
|
58 | - * one with an identifier of 'HonduranCoffee' using the following ingredients : |
|
59 | - * array('BeanInterface' => 'HonduranBean') |
|
60 | - * and the other with an identifier of 'KenyanCoffee' using the following ingredients : |
|
61 | - * array('BeanInterface' => 'KenyanBean') |
|
62 | - * Then, whenever the CoffeeShop brews an instance of HonduranCoffee, |
|
63 | - * an instance of HonduranBean will get injected for the BeanInterface dependency, |
|
64 | - * and whenever the CoffeeShop brews an instance of KenyanCoffee, |
|
65 | - * an instance of KenyanBean will get injected for the BeanInterface dependency |
|
66 | - * |
|
67 | - * @var array $ingredients |
|
68 | - */ |
|
69 | - private $ingredients = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * one of the class constants from CoffeeShop: |
|
73 | - * CoffeeMaker::BREW_NEW - creates a new instance |
|
74 | - * CoffeeMaker::BREW_SHARED - creates a shared instance |
|
75 | - * CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate |
|
76 | - * |
|
77 | - * @var string $type |
|
78 | - */ |
|
79 | - private $type; |
|
80 | - |
|
81 | - /** |
|
82 | - * class name aliases - typically a Fully Qualified Interface that the class implements |
|
83 | - * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name |
|
84 | - * |
|
85 | - * @var array $filters |
|
86 | - */ |
|
87 | - private $filters = array(); |
|
88 | - |
|
89 | - /** |
|
90 | - * array of full server filepaths to files that may contain the class |
|
91 | - * |
|
92 | - * @var array $paths |
|
93 | - */ |
|
94 | - private $paths = array(); |
|
95 | - |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Recipe constructor. |
|
100 | - * |
|
101 | - * @param string $identifier class identifier, can be an alias, or FQCN, or whatever |
|
102 | - * @param string $fqcn \Fully\Qualified\ClassName, optional if $identifier is FQCN |
|
103 | - * @param array $ingredients array of dependencies that can not be resolved automatically, |
|
104 | - * used for resolving concrete classes for type hinted interfaces |
|
105 | - * for the dependencies of THIS class |
|
106 | - * @param string $type recipe type: one of the class constants on |
|
107 | - * \EventEspresso\core\services\container\CoffeeMaker |
|
108 | - * @param array $filters array of class aliases, or class interfaces |
|
109 | - * this works somewhat opposite to the $ingredients array above, |
|
110 | - * in that this array specifies interfaces or aliases |
|
111 | - * that this Recipe can be used for when resolving OTHER class's dependencies |
|
112 | - * @param array $paths if class can not be loaded via PSR-4 autoloading, |
|
113 | - * then supply a filepath, or array of filepaths, so that it can be included |
|
114 | - */ |
|
115 | - public function __construct( |
|
116 | - $identifier, |
|
117 | - $fqcn = '', |
|
118 | - $filters = array(), |
|
119 | - $ingredients = array(), |
|
120 | - $type = CoffeeMaker::BREW_NEW, |
|
121 | - $paths = array() |
|
122 | - ) |
|
123 | - { |
|
124 | - $this->setIdentifier($identifier); |
|
125 | - $this->setFilters((array)$filters); |
|
126 | - $this->setIngredients((array)$ingredients); |
|
127 | - $this->setType($type); |
|
128 | - $this->setPaths($paths); |
|
129 | - $this->setFqcn($fqcn); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function identifier() |
|
138 | - { |
|
139 | - return $this->identifier; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public function fqcn() |
|
148 | - { |
|
149 | - return $this->fqcn; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - public function filters() |
|
158 | - { |
|
159 | - return (array)$this->filters; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - public function ingredients() |
|
168 | - { |
|
169 | - return $this->ingredients; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function type() |
|
178 | - { |
|
179 | - return $this->type; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return array |
|
186 | - */ |
|
187 | - public function paths() |
|
188 | - { |
|
189 | - return (array)$this->paths; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
196 | - * Typically a Fully Qualified Class Name |
|
197 | - */ |
|
198 | - public function setIdentifier($identifier) |
|
199 | - { |
|
200 | - if ( ! is_string($identifier) || empty($identifier)) { |
|
201 | - throw new InvalidIdentifierException( |
|
202 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
203 | - __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
204 | - ); |
|
205 | - } |
|
206 | - $this->identifier = $identifier; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Ensures incoming string is a valid Fully Qualified Class Name, |
|
213 | - * except if this is the default wildcard Recipe ( * ), |
|
214 | - * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
215 | - * for classes that are not PSR-4 compatible |
|
216 | - * PLZ NOTE: |
|
217 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
218 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
219 | - * |
|
220 | - * @param string $fqcn |
|
221 | - * @throws InvalidDataTypeException |
|
222 | - * @throws InvalidClassException |
|
223 | - * @throws InvalidInterfaceException |
|
224 | - */ |
|
225 | - public function setFqcn($fqcn) |
|
226 | - { |
|
227 | - $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
228 | - if ( ! is_string($fqcn)) { |
|
229 | - throw new InvalidDataTypeException( |
|
230 | - '$fqcn', |
|
231 | - is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
232 | - __('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
233 | - ); |
|
234 | - } |
|
235 | - $fqcn = ltrim($fqcn, '\\'); |
|
236 | - if ( |
|
237 | - $fqcn !== Recipe::DEFAULT_ID |
|
238 | - && ! empty($fqcn) |
|
239 | - && empty($this->paths) |
|
240 | - && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
241 | - ) { |
|
242 | - throw new InvalidClassException($fqcn); |
|
243 | - } |
|
244 | - $this->fqcn = $fqcn; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
251 | - * example: |
|
252 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
253 | - */ |
|
254 | - public function setIngredients(array $ingredients) |
|
255 | - { |
|
256 | - if (empty($ingredients)) { |
|
257 | - return; |
|
258 | - } |
|
259 | - if ( ! is_array($ingredients)) { |
|
260 | - throw new InvalidDataTypeException( |
|
261 | - '$ingredients', |
|
262 | - is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
263 | - __('array of class dependencies', 'event_espresso') |
|
264 | - ); |
|
265 | - } |
|
266 | - $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
272 | - */ |
|
273 | - public function setType($type = CoffeeMaker::BREW_NEW) |
|
274 | - { |
|
275 | - $this->type = CoffeeMaker::validateType($type); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
282 | - * example: |
|
283 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
284 | - */ |
|
285 | - public function setFilters(array $filters) |
|
286 | - { |
|
287 | - if (empty($filters)) { |
|
288 | - return; |
|
289 | - } |
|
290 | - if ( ! is_array($filters)) { |
|
291 | - throw new InvalidDataTypeException( |
|
292 | - '$filters', |
|
293 | - is_object($filters) ? get_class($filters) : gettype($filters), |
|
294 | - __('array of class aliases', 'event_espresso') |
|
295 | - ); |
|
296 | - } |
|
297 | - $this->filters = array_merge($this->filters, $filters); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
304 | - * and merges them in with any existing filepaths |
|
305 | - * |
|
306 | - * PLZ NOTE: |
|
307 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
308 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
309 | - * |
|
310 | - * @param string|array $paths |
|
311 | - */ |
|
312 | - public function setPaths($paths = array()) |
|
313 | - { |
|
314 | - if (empty($paths)) { |
|
315 | - return; |
|
316 | - } |
|
317 | - if ( ! (is_string($paths) || is_array($paths))) { |
|
318 | - throw new InvalidDataTypeException( |
|
319 | - '$path', |
|
320 | - is_object($paths) ? get_class($paths) : gettype($paths), |
|
321 | - __('string or array of strings (full server filepath(s))', 'event_espresso') |
|
322 | - ); |
|
323 | - } |
|
324 | - $paths = (array)$paths; |
|
325 | - foreach ($paths as $path) { |
|
326 | - if (strpos($path, '*') === false && ! is_readable($path)) { |
|
327 | - throw new RuntimeException( |
|
328 | - sprintf( |
|
329 | - __('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
330 | - $path |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - $this->paths = array_merge($this->paths, $paths); |
|
336 | - } |
|
27 | + /** |
|
28 | + * A default Recipe to use if none is specified for a class |
|
29 | + */ |
|
30 | + const DEFAULT_ID = '*'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Identifier for the entity class to be constructed. |
|
34 | + * Typically a Fully Qualified Class Name |
|
35 | + * |
|
36 | + * @var string $identifier |
|
37 | + */ |
|
38 | + private $identifier; |
|
39 | + |
|
40 | + /** |
|
41 | + * Fully Qualified Class Name |
|
42 | + * |
|
43 | + * @var string $fqcn |
|
44 | + */ |
|
45 | + private $fqcn; |
|
46 | + |
|
47 | + /** |
|
48 | + * a dependency class map array |
|
49 | + * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments), |
|
50 | + * and that class type hints for an interface, then this property allows you to configure what dependencies |
|
51 | + * get used when instantiating the class. |
|
52 | + * For example: |
|
53 | + * There's a class called Coffee, and one of its constructor arguments is BeanInterface |
|
54 | + * There are two implementations of BeanInterface: HonduranBean, and KenyanBean |
|
55 | + * We want one Coffee object to use HonduranBean for its BeanInterface, |
|
56 | + * and the 2nd Coffee object to use KenyanBean for its BeanInterface. |
|
57 | + * To do this, we need to create two Recipes: |
|
58 | + * one with an identifier of 'HonduranCoffee' using the following ingredients : |
|
59 | + * array('BeanInterface' => 'HonduranBean') |
|
60 | + * and the other with an identifier of 'KenyanCoffee' using the following ingredients : |
|
61 | + * array('BeanInterface' => 'KenyanBean') |
|
62 | + * Then, whenever the CoffeeShop brews an instance of HonduranCoffee, |
|
63 | + * an instance of HonduranBean will get injected for the BeanInterface dependency, |
|
64 | + * and whenever the CoffeeShop brews an instance of KenyanCoffee, |
|
65 | + * an instance of KenyanBean will get injected for the BeanInterface dependency |
|
66 | + * |
|
67 | + * @var array $ingredients |
|
68 | + */ |
|
69 | + private $ingredients = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * one of the class constants from CoffeeShop: |
|
73 | + * CoffeeMaker::BREW_NEW - creates a new instance |
|
74 | + * CoffeeMaker::BREW_SHARED - creates a shared instance |
|
75 | + * CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate |
|
76 | + * |
|
77 | + * @var string $type |
|
78 | + */ |
|
79 | + private $type; |
|
80 | + |
|
81 | + /** |
|
82 | + * class name aliases - typically a Fully Qualified Interface that the class implements |
|
83 | + * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name |
|
84 | + * |
|
85 | + * @var array $filters |
|
86 | + */ |
|
87 | + private $filters = array(); |
|
88 | + |
|
89 | + /** |
|
90 | + * array of full server filepaths to files that may contain the class |
|
91 | + * |
|
92 | + * @var array $paths |
|
93 | + */ |
|
94 | + private $paths = array(); |
|
95 | + |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Recipe constructor. |
|
100 | + * |
|
101 | + * @param string $identifier class identifier, can be an alias, or FQCN, or whatever |
|
102 | + * @param string $fqcn \Fully\Qualified\ClassName, optional if $identifier is FQCN |
|
103 | + * @param array $ingredients array of dependencies that can not be resolved automatically, |
|
104 | + * used for resolving concrete classes for type hinted interfaces |
|
105 | + * for the dependencies of THIS class |
|
106 | + * @param string $type recipe type: one of the class constants on |
|
107 | + * \EventEspresso\core\services\container\CoffeeMaker |
|
108 | + * @param array $filters array of class aliases, or class interfaces |
|
109 | + * this works somewhat opposite to the $ingredients array above, |
|
110 | + * in that this array specifies interfaces or aliases |
|
111 | + * that this Recipe can be used for when resolving OTHER class's dependencies |
|
112 | + * @param array $paths if class can not be loaded via PSR-4 autoloading, |
|
113 | + * then supply a filepath, or array of filepaths, so that it can be included |
|
114 | + */ |
|
115 | + public function __construct( |
|
116 | + $identifier, |
|
117 | + $fqcn = '', |
|
118 | + $filters = array(), |
|
119 | + $ingredients = array(), |
|
120 | + $type = CoffeeMaker::BREW_NEW, |
|
121 | + $paths = array() |
|
122 | + ) |
|
123 | + { |
|
124 | + $this->setIdentifier($identifier); |
|
125 | + $this->setFilters((array)$filters); |
|
126 | + $this->setIngredients((array)$ingredients); |
|
127 | + $this->setType($type); |
|
128 | + $this->setPaths($paths); |
|
129 | + $this->setFqcn($fqcn); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function identifier() |
|
138 | + { |
|
139 | + return $this->identifier; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public function fqcn() |
|
148 | + { |
|
149 | + return $this->fqcn; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + public function filters() |
|
158 | + { |
|
159 | + return (array)$this->filters; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + public function ingredients() |
|
168 | + { |
|
169 | + return $this->ingredients; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function type() |
|
178 | + { |
|
179 | + return $this->type; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return array |
|
186 | + */ |
|
187 | + public function paths() |
|
188 | + { |
|
189 | + return (array)$this->paths; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
196 | + * Typically a Fully Qualified Class Name |
|
197 | + */ |
|
198 | + public function setIdentifier($identifier) |
|
199 | + { |
|
200 | + if ( ! is_string($identifier) || empty($identifier)) { |
|
201 | + throw new InvalidIdentifierException( |
|
202 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
203 | + __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
204 | + ); |
|
205 | + } |
|
206 | + $this->identifier = $identifier; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Ensures incoming string is a valid Fully Qualified Class Name, |
|
213 | + * except if this is the default wildcard Recipe ( * ), |
|
214 | + * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
215 | + * for classes that are not PSR-4 compatible |
|
216 | + * PLZ NOTE: |
|
217 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
218 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
219 | + * |
|
220 | + * @param string $fqcn |
|
221 | + * @throws InvalidDataTypeException |
|
222 | + * @throws InvalidClassException |
|
223 | + * @throws InvalidInterfaceException |
|
224 | + */ |
|
225 | + public function setFqcn($fqcn) |
|
226 | + { |
|
227 | + $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
228 | + if ( ! is_string($fqcn)) { |
|
229 | + throw new InvalidDataTypeException( |
|
230 | + '$fqcn', |
|
231 | + is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
232 | + __('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
233 | + ); |
|
234 | + } |
|
235 | + $fqcn = ltrim($fqcn, '\\'); |
|
236 | + if ( |
|
237 | + $fqcn !== Recipe::DEFAULT_ID |
|
238 | + && ! empty($fqcn) |
|
239 | + && empty($this->paths) |
|
240 | + && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
241 | + ) { |
|
242 | + throw new InvalidClassException($fqcn); |
|
243 | + } |
|
244 | + $this->fqcn = $fqcn; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
251 | + * example: |
|
252 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
253 | + */ |
|
254 | + public function setIngredients(array $ingredients) |
|
255 | + { |
|
256 | + if (empty($ingredients)) { |
|
257 | + return; |
|
258 | + } |
|
259 | + if ( ! is_array($ingredients)) { |
|
260 | + throw new InvalidDataTypeException( |
|
261 | + '$ingredients', |
|
262 | + is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
263 | + __('array of class dependencies', 'event_espresso') |
|
264 | + ); |
|
265 | + } |
|
266 | + $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
272 | + */ |
|
273 | + public function setType($type = CoffeeMaker::BREW_NEW) |
|
274 | + { |
|
275 | + $this->type = CoffeeMaker::validateType($type); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
282 | + * example: |
|
283 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
284 | + */ |
|
285 | + public function setFilters(array $filters) |
|
286 | + { |
|
287 | + if (empty($filters)) { |
|
288 | + return; |
|
289 | + } |
|
290 | + if ( ! is_array($filters)) { |
|
291 | + throw new InvalidDataTypeException( |
|
292 | + '$filters', |
|
293 | + is_object($filters) ? get_class($filters) : gettype($filters), |
|
294 | + __('array of class aliases', 'event_espresso') |
|
295 | + ); |
|
296 | + } |
|
297 | + $this->filters = array_merge($this->filters, $filters); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
304 | + * and merges them in with any existing filepaths |
|
305 | + * |
|
306 | + * PLZ NOTE: |
|
307 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
308 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
309 | + * |
|
310 | + * @param string|array $paths |
|
311 | + */ |
|
312 | + public function setPaths($paths = array()) |
|
313 | + { |
|
314 | + if (empty($paths)) { |
|
315 | + return; |
|
316 | + } |
|
317 | + if ( ! (is_string($paths) || is_array($paths))) { |
|
318 | + throw new InvalidDataTypeException( |
|
319 | + '$path', |
|
320 | + is_object($paths) ? get_class($paths) : gettype($paths), |
|
321 | + __('string or array of strings (full server filepath(s))', 'event_espresso') |
|
322 | + ); |
|
323 | + } |
|
324 | + $paths = (array)$paths; |
|
325 | + foreach ($paths as $path) { |
|
326 | + if (strpos($path, '*') === false && ! is_readable($path)) { |
|
327 | + throw new RuntimeException( |
|
328 | + sprintf( |
|
329 | + __('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
330 | + $path |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + $this->paths = array_merge($this->paths, $paths); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * OpenCoffeeShop constructor |
|
35 | - * |
|
36 | - * @throws InvalidInterfaceException |
|
37 | - */ |
|
33 | + /** |
|
34 | + * OpenCoffeeShop constructor |
|
35 | + * |
|
36 | + * @throws InvalidInterfaceException |
|
37 | + */ |
|
38 | 38 | public function __construct() |
39 | - { |
|
40 | - // instantiate the DI container |
|
39 | + { |
|
40 | + // instantiate the DI container |
|
41 | 41 | $this->CoffeeShop = new CoffeeShop(); |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
@@ -52,60 +52,60 @@ discard block |
||
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * configure coffee makers which control the different kinds of brews |
|
57 | - * ( shared services, new factory objects, etc ) |
|
58 | - * |
|
59 | - * @throws InvalidEntityException |
|
60 | - */ |
|
55 | + /** |
|
56 | + * configure coffee makers which control the different kinds of brews |
|
57 | + * ( shared services, new factory objects, etc ) |
|
58 | + * |
|
59 | + * @throws InvalidEntityException |
|
60 | + */ |
|
61 | 61 | public function setupCoffeeMakers() { |
62 | - // create a dependency injector class for resolving class constructor arguments |
|
63 | - $DependencyInjector = new DependencyInjector( |
|
64 | - $this->CoffeeShop, |
|
65 | - new \EEH_Array() |
|
66 | - ); |
|
67 | - // and some coffeemakers, one for creating new instances |
|
68 | - $this->CoffeeShop->addCoffeeMaker( |
|
69 | - new NewCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
70 | - CoffeeMaker::BREW_NEW |
|
71 | - ); |
|
72 | - // one for shared services |
|
73 | - $this->CoffeeShop->addCoffeeMaker( |
|
74 | - new SharedCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
75 | - CoffeeMaker::BREW_SHARED |
|
76 | - ); |
|
77 | - // and one for classes that only get loaded |
|
78 | - $this->CoffeeShop->addCoffeeMaker( |
|
79 | - new LoadOnlyCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
80 | - CoffeeMaker::BREW_LOAD_ONLY |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Recipes define how to load legacy classes |
|
88 | - * |
|
89 | - * @throws InvalidIdentifierException |
|
90 | - */ |
|
91 | - public function addRecipes() { |
|
92 | - // add default recipe, which should handle loading for most PSR-4 compatible classes |
|
93 | - // as long as they are not type hinting for interfaces |
|
94 | - $this->CoffeeShop->addRecipe( |
|
95 | - new Recipe( |
|
96 | - Recipe::DEFAULT_ID |
|
97 | - ) |
|
98 | - ); |
|
99 | - // PSR-4 compatible class with aliases |
|
62 | + // create a dependency injector class for resolving class constructor arguments |
|
63 | + $DependencyInjector = new DependencyInjector( |
|
64 | + $this->CoffeeShop, |
|
65 | + new \EEH_Array() |
|
66 | + ); |
|
67 | + // and some coffeemakers, one for creating new instances |
|
68 | + $this->CoffeeShop->addCoffeeMaker( |
|
69 | + new NewCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
70 | + CoffeeMaker::BREW_NEW |
|
71 | + ); |
|
72 | + // one for shared services |
|
73 | + $this->CoffeeShop->addCoffeeMaker( |
|
74 | + new SharedCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
75 | + CoffeeMaker::BREW_SHARED |
|
76 | + ); |
|
77 | + // and one for classes that only get loaded |
|
78 | + $this->CoffeeShop->addCoffeeMaker( |
|
79 | + new LoadOnlyCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
80 | + CoffeeMaker::BREW_LOAD_ONLY |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Recipes define how to load legacy classes |
|
88 | + * |
|
89 | + * @throws InvalidIdentifierException |
|
90 | + */ |
|
91 | + public function addRecipes() { |
|
92 | + // add default recipe, which should handle loading for most PSR-4 compatible classes |
|
93 | + // as long as they are not type hinting for interfaces |
|
94 | + $this->CoffeeShop->addRecipe( |
|
95 | + new Recipe( |
|
96 | + Recipe::DEFAULT_ID |
|
97 | + ) |
|
98 | + ); |
|
99 | + // PSR-4 compatible class with aliases |
|
100 | 100 | $this->CoffeeShop->addRecipe( |
101 | 101 | new Recipe( |
102 | 102 | 'CommandHandlerManager', |
103 | 103 | 'EventEspresso\core\services\commands\CommandHandlerManager', |
104 | - array( |
|
105 | - 'CommandHandlerManagerInterface', |
|
106 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
107 | - ), |
|
108 | - array(), |
|
104 | + array( |
|
105 | + 'CommandHandlerManagerInterface', |
|
106 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
107 | + ), |
|
108 | + array(), |
|
109 | 109 | CoffeeMaker::BREW_SHARED |
110 | 110 | ) |
111 | 111 | ); |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | new Recipe( |
115 | 115 | 'CommandBus', |
116 | 116 | 'EventEspresso\core\services\commands\CommandBus', |
117 | - array( |
|
118 | - 'CommandBusInterface', |
|
119 | - 'EventEspresso\core\services\commands\CommandBusInterface', |
|
120 | - ), |
|
121 | - array(), |
|
117 | + array( |
|
118 | + 'CommandBusInterface', |
|
119 | + 'EventEspresso\core\services\commands\CommandBusInterface', |
|
120 | + ), |
|
121 | + array(), |
|
122 | 122 | CoffeeMaker::BREW_SHARED |
123 | 123 | ) |
124 | 124 | ); |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | new Recipe( |
129 | 129 | 'EEI_*', |
130 | 130 | '', |
131 | - array(), |
|
132 | - array(), |
|
131 | + array(), |
|
132 | + array(), |
|
133 | 133 | CoffeeMaker::BREW_LOAD_ONLY, |
134 | - array( |
|
135 | - EE_INTERFACES . '*.php', |
|
136 | - EE_INTERFACES . '*.interfaces.php', |
|
137 | - ) |
|
134 | + array( |
|
135 | + EE_INTERFACES . '*.php', |
|
136 | + EE_INTERFACES . '*.interfaces.php', |
|
137 | + ) |
|
138 | 138 | ) |
139 | 139 | ); |
140 | 140 | // add a wildcard recipe for loading models |
141 | 141 | $this->CoffeeShop->addRecipe( |
142 | 142 | new Recipe( |
143 | 143 | 'EEM_*', |
144 | - '', |
|
145 | - array(), |
|
146 | - array(), |
|
144 | + '', |
|
145 | + array(), |
|
146 | + array(), |
|
147 | 147 | CoffeeMaker::BREW_SHARED, |
148 | 148 | EE_MODELS . '*.model.php' |
149 | 149 | ) |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | $this->CoffeeShop->addRecipe( |
153 | 153 | new Recipe( |
154 | 154 | 'EE_*', |
155 | - '', |
|
156 | - array(), |
|
157 | - array(), |
|
158 | - CoffeeMaker::BREW_SHARED, |
|
155 | + '', |
|
156 | + array(), |
|
157 | + array(), |
|
158 | + CoffeeMaker::BREW_SHARED, |
|
159 | 159 | array( |
160 | 160 | EE_CORE . '*.core.php', |
161 | 161 | EE_ADMIN . '*.core.php', |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | $this->CoffeeShop->addRecipe( |
171 | 171 | new Recipe( |
172 | 172 | 'EE_Admin_Page*', |
173 | - '', |
|
174 | - array(), |
|
175 | - array(), |
|
176 | - CoffeeMaker::BREW_LOAD_ONLY, |
|
173 | + '', |
|
174 | + array(), |
|
175 | + array(), |
|
176 | + CoffeeMaker::BREW_LOAD_ONLY, |
|
177 | 177 | array( EE_ADMIN . '*.core.php' ) |
178 | 178 | ) |
179 | 179 | ); |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | // $this->CoffeeShop->addRecipe( |
182 | 182 | // new Recipe( |
183 | 183 | // '*_Admin_Page', |
184 | - // '', |
|
185 | - // array(), |
|
186 | - // array(), |
|
187 | - // CoffeeMaker::BREW_SHARED, |
|
184 | + // '', |
|
185 | + // array(), |
|
186 | + // array(), |
|
187 | + // CoffeeMaker::BREW_SHARED, |
|
188 | 188 | // array( |
189 | 189 | // EE_ADMIN_PAGES . 'transactions' . DS . '*.core.php', |
190 | 190 | // ) |
@@ -194,23 +194,23 @@ discard block |
||
194 | 194 | |
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * bootstrap EE and the request stack |
|
199 | - * |
|
200 | - * @throws ServiceNotFoundException |
|
201 | - * @throws InvalidClassException |
|
202 | - * @throws InvalidDataTypeException |
|
203 | - * @throws InvalidIdentifierException |
|
204 | - * @throws exceptions\ServiceExistsException |
|
205 | - * @throws OutOfBoundsException |
|
206 | - * @throws exceptions\InstantiationException |
|
207 | - */ |
|
208 | - public function firstBrew() |
|
209 | - { |
|
210 | - $this->CoffeeShop->brew('EE_Request', array($_GET, $_POST, $_COOKIE)); |
|
211 | - $this->CoffeeShop->brew('EE_Response'); |
|
212 | - $this->CoffeeShop->brew('EE_Bootstrap'); |
|
213 | - } |
|
197 | + /** |
|
198 | + * bootstrap EE and the request stack |
|
199 | + * |
|
200 | + * @throws ServiceNotFoundException |
|
201 | + * @throws InvalidClassException |
|
202 | + * @throws InvalidDataTypeException |
|
203 | + * @throws InvalidIdentifierException |
|
204 | + * @throws exceptions\ServiceExistsException |
|
205 | + * @throws OutOfBoundsException |
|
206 | + * @throws exceptions\InstantiationException |
|
207 | + */ |
|
208 | + public function firstBrew() |
|
209 | + { |
|
210 | + $this->CoffeeShop->brew('EE_Request', array($_GET, $_POST, $_COOKIE)); |
|
211 | + $this->CoffeeShop->brew('EE_Response'); |
|
212 | + $this->CoffeeShop->brew('EE_Bootstrap'); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | 216 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | array(), |
133 | 133 | CoffeeMaker::BREW_LOAD_ONLY, |
134 | 134 | array( |
135 | - EE_INTERFACES . '*.php', |
|
136 | - EE_INTERFACES . '*.interfaces.php', |
|
135 | + EE_INTERFACES.'*.php', |
|
136 | + EE_INTERFACES.'*.interfaces.php', |
|
137 | 137 | ) |
138 | 138 | ) |
139 | 139 | ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | array(), |
146 | 146 | array(), |
147 | 147 | CoffeeMaker::BREW_SHARED, |
148 | - EE_MODELS . '*.model.php' |
|
148 | + EE_MODELS.'*.model.php' |
|
149 | 149 | ) |
150 | 150 | ); |
151 | 151 | // add a wildcard recipe for loading core classes |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | array(), |
158 | 158 | CoffeeMaker::BREW_SHARED, |
159 | 159 | array( |
160 | - EE_CORE . '*.core.php', |
|
161 | - EE_ADMIN . '*.core.php', |
|
162 | - EE_CPTS . '*.core.php', |
|
163 | - EE_CORE . 'data_migration_scripts' . DS . '*.core.php', |
|
164 | - EE_CORE . 'request_stack' . DS . '*.core.php', |
|
165 | - EE_CORE . 'middleware' . DS . '*.core.php', |
|
160 | + EE_CORE.'*.core.php', |
|
161 | + EE_ADMIN.'*.core.php', |
|
162 | + EE_CPTS.'*.core.php', |
|
163 | + EE_CORE.'data_migration_scripts'.DS.'*.core.php', |
|
164 | + EE_CORE.'request_stack'.DS.'*.core.php', |
|
165 | + EE_CORE.'middleware'.DS.'*.core.php', |
|
166 | 166 | ) |
167 | 167 | ) |
168 | 168 | ); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | array(), |
175 | 175 | array(), |
176 | 176 | CoffeeMaker::BREW_LOAD_ONLY, |
177 | - array( EE_ADMIN . '*.core.php' ) |
|
177 | + array(EE_ADMIN.'*.core.php') |
|
178 | 178 | ) |
179 | 179 | ); |
180 | 180 | // add a wildcard recipe for loading core classes |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | 2 | // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
3 | -if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) { |
|
4 | - set_error_handler( array( 'EE_Error', 'error_handler' )); |
|
5 | - register_shutdown_function( array( 'EE_Error', 'fatal_error_handler' )); |
|
3 | +if (defined('WP_DEBUG') && WP_DEBUG === TRUE && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === TRUE) { |
|
4 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
5 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @access private |
65 | 65 | * @var boolean |
66 | 66 | */ |
67 | - private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE ); |
|
67 | + private static $_espresso_notices = array('success' => FALSE, 'errors' => FALSE, 'attention' => FALSE); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @access public |
76 | 76 | * @echo string |
77 | 77 | */ |
78 | - function __construct( $message, $code = 0, Exception $previous = NULL ) { |
|
79 | - if ( version_compare( phpversion(), '5.3.0', '<' )) { |
|
80 | - parent::__construct( $message, $code ); |
|
78 | + function __construct($message, $code = 0, Exception $previous = NULL) { |
|
79 | + if (version_compare(phpversion(), '5.3.0', '<')) { |
|
80 | + parent::__construct($message, $code); |
|
81 | 81 | } else { |
82 | - parent::__construct( $message, $code, $previous ); |
|
82 | + parent::__construct($message, $code, $previous); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | * @param $line |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - public static function error_handler( $code, $message, $file, $line ) { |
|
98 | - $type = EE_Error::error_type( $code ); |
|
97 | + public static function error_handler($code, $message, $file, $line) { |
|
98 | + $type = EE_Error::error_type($code); |
|
99 | 99 | $site = site_url(); |
100 | - switch ( $site ) { |
|
100 | + switch ($site) { |
|
101 | 101 | case 'http://ee4.eventespresso.com/' : |
102 | 102 | case 'http://ee4decaf.eventespresso.com/' : |
103 | 103 | case 'http://ee4hf.eventespresso.com/' : |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | $to = '[email protected]'; |
111 | 111 | break; |
112 | 112 | default : |
113 | - $to = get_option( 'admin_email' ); |
|
113 | + $to = get_option('admin_email'); |
|
114 | 114 | } |
115 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
116 | - $msg = EE_Error::_format_error( $type, $message, $file, $line ); |
|
117 | - if ( function_exists( 'wp_mail' )) { |
|
118 | - add_filter( 'wp_mail_content_type', array( 'EE_Error', 'set_content_type' )); |
|
119 | - wp_mail( $to, $subject, $msg ); |
|
115 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
116 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
117 | + if (function_exists('wp_mail')) { |
|
118 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
119 | + wp_mail($to, $subject, $msg); |
|
120 | 120 | } |
121 | 121 | echo '<div id="message" class="espresso-notices error"><p>'; |
122 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
122 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
123 | 123 | echo '<br /></p></div>'; |
124 | 124 | } |
125 | 125 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param $code |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public static function error_type( $code ) { |
|
136 | - switch( $code ) { |
|
135 | + public static function error_type($code) { |
|
136 | + switch ($code) { |
|
137 | 137 | case E_ERROR: // 1 // |
138 | 138 | return 'E_ERROR'; |
139 | 139 | case E_WARNING: // 2 // |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public static function fatal_error_handler() { |
181 | 181 | $last_error = error_get_last(); |
182 | - if ( $last_error['type'] === E_ERROR ) { |
|
183 | - EE_Error::error_handler( E_ERROR, $last_error['message'], $last_error['file'], $last_error['line'] ); |
|
182 | + if ($last_error['type'] === E_ERROR) { |
|
183 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param $line |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - private static function _format_error( $code, $message, $file, $line ) { |
|
198 | + private static function _format_error($code, $message, $file, $line) { |
|
199 | 199 | $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
200 | 200 | $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
201 | 201 | $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param $content_type |
214 | 214 | * @return string |
215 | 215 | */ |
216 | - public static function set_content_type( $content_type ) { |
|
216 | + public static function set_content_type($content_type) { |
|
217 | 217 | return 'text/html'; |
218 | 218 | } |
219 | 219 | |
@@ -227,24 +227,24 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function get_error() { |
229 | 229 | |
230 | - if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){ |
|
230 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', FALSE)) { |
|
231 | 231 | throw $this; |
232 | 232 | } |
233 | 233 | // get separate user and developer messages if they exist |
234 | - $msg = explode( '||', $this->getMessage() ); |
|
234 | + $msg = explode('||', $this->getMessage()); |
|
235 | 235 | $user_msg = $msg[0]; |
236 | - $dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0]; |
|
236 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
237 | 237 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
238 | 238 | |
239 | 239 | // add details to _all_exceptions array |
240 | 240 | $x_time = time(); |
241 | - self::$_all_exceptions[ $x_time ]['name'] = get_class( $this ); |
|
242 | - self::$_all_exceptions[ $x_time ]['file'] = $this->getFile(); |
|
243 | - self::$_all_exceptions[ $x_time ]['line'] = $this->getLine(); |
|
244 | - self::$_all_exceptions[ $x_time ]['msg'] = $msg; |
|
245 | - self::$_all_exceptions[ $x_time ]['code'] = $this->getCode(); |
|
246 | - self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace(); |
|
247 | - self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
242 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
243 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
244 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
245 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
246 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
247 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
248 | 248 | self::$_error_count++; |
249 | 249 | |
250 | 250 | //add_action( 'shutdown', array( $this, 'display_errors' )); |
@@ -262,14 +262,14 @@ discard block |
||
262 | 262 | * @param string $type_to_check |
263 | 263 | * @return bool |
264 | 264 | */ |
265 | - public static function has_error( $check_stored = false, $type_to_check = 'errors' ){ |
|
265 | + public static function has_error($check_stored = false, $type_to_check = 'errors') { |
|
266 | 266 | $has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check]) |
267 | 267 | ? true |
268 | 268 | : false; |
269 | - if ( $check_stored && ! $has_error ) { |
|
270 | - $notices = (array) get_option( 'ee_notices', array() ); |
|
271 | - foreach ( $notices as $type => $notice ) { |
|
272 | - if ( $type === $type_to_check && $notice ) { |
|
269 | + if ($check_stored && ! $has_error) { |
|
270 | + $notices = (array) get_option('ee_notices', array()); |
|
271 | + foreach ($notices as $type => $notice) { |
|
272 | + if ($type === $type_to_check && $notice) { |
|
273 | 273 | return true; |
274 | 274 | } |
275 | 275 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @access public |
285 | 285 | * @echo string |
286 | 286 | */ |
287 | - public function display_errors(){ |
|
287 | + public function display_errors() { |
|
288 | 288 | |
289 | 289 | $trace_details = ''; |
290 | 290 | |
@@ -345,18 +345,18 @@ discard block |
||
345 | 345 | </style> |
346 | 346 | <div id="ee-error-message" class="error">'; |
347 | 347 | |
348 | - if ( ! WP_DEBUG ) { |
|
348 | + if ( ! WP_DEBUG) { |
|
349 | 349 | $output .= ' |
350 | 350 | <p>'; |
351 | 351 | } |
352 | 352 | |
353 | 353 | // cycle thru errors |
354 | - foreach ( self::$_all_exceptions as $time => $ex ) { |
|
354 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
355 | 355 | |
356 | 356 | // process trace info |
357 | - if ( empty( $ex['trace'] )) { |
|
357 | + if (empty($ex['trace'])) { |
|
358 | 358 | |
359 | - $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' ); |
|
359 | + $trace_details .= __('Sorry, but no trace information was available for this exception.', 'event_espresso'); |
|
360 | 360 | |
361 | 361 | } else { |
362 | 362 | |
@@ -371,50 +371,50 @@ discard block |
||
371 | 371 | <th scope="col" align="left">Method( arguments )</th> |
372 | 372 | </tr>'; |
373 | 373 | |
374 | - $last_on_stack = count( $ex['trace'] ) - 1; |
|
374 | + $last_on_stack = count($ex['trace']) - 1; |
|
375 | 375 | // reverse array so that stack is in proper chronological order |
376 | - $sorted_trace = array_reverse( $ex['trace'] ); |
|
376 | + $sorted_trace = array_reverse($ex['trace']); |
|
377 | 377 | |
378 | - foreach ( $sorted_trace as $nmbr => $trace ) { |
|
378 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
379 | 379 | |
380 | - $file = isset( $trace['file'] ) ? $trace['file'] : '' ; |
|
381 | - $class = isset( $trace['class'] ) ? $trace['class'] : ''; |
|
382 | - $type = isset( $trace['type'] ) ? $trace['type'] : ''; |
|
383 | - $function = isset( $trace['function'] ) ? $trace['function'] : ''; |
|
384 | - $args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : ''; |
|
385 | - $line = isset( $trace['line'] ) ? $trace['line'] : ''; |
|
380 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
381 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
382 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
383 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
384 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
385 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
386 | 386 | $zebra = $nmbr % 2 ? ' odd' : ''; |
387 | 387 | |
388 | - if ( empty( $file ) && ! empty( $class )) { |
|
389 | - $a = new ReflectionClass( $class ); |
|
388 | + if (empty($file) && ! empty($class)) { |
|
389 | + $a = new ReflectionClass($class); |
|
390 | 390 | $file = $a->getFileName(); |
391 | - if ( empty( $line ) && ! empty( $function )) { |
|
392 | - $b = new ReflectionMethod( $class, $function ); |
|
391 | + if (empty($line) && ! empty($function)) { |
|
392 | + $b = new ReflectionMethod($class, $function); |
|
393 | 393 | $line = $b->getStartLine(); |
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - if ( $nmbr == $last_on_stack ) { |
|
397 | + if ($nmbr == $last_on_stack) { |
|
398 | 398 | $file = $ex['file'] != '' ? $ex['file'] : $file; |
399 | 399 | $line = $ex['line'] != '' ? $ex['line'] : $line; |
400 | - $error_code = self::generate_error_code ( $file, $trace['function'], $line ); |
|
400 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
401 | 401 | } |
402 | 402 | |
403 | - $nmbr_dsply = ! empty( $nmbr ) ? $nmbr : ' '; |
|
404 | - $line_dsply = ! empty( $line ) ? $line : ' '; |
|
405 | - $file_dsply = ! empty( $file ) ? $file : ' '; |
|
406 | - $class_dsply = ! empty( $class ) ? $class : ' '; |
|
407 | - $type_dsply = ! empty( $type ) ? $type : ' '; |
|
408 | - $function_dsply = ! empty( $function ) ? $function : ' '; |
|
409 | - $args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : ''; |
|
403 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
404 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
405 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
406 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
407 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
408 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
409 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
410 | 410 | |
411 | 411 | $trace_details .= ' |
412 | 412 | <tr> |
413 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
414 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
415 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
416 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
417 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
413 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
414 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
415 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
416 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
417 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
418 | 418 | </tr>'; |
419 | 419 | |
420 | 420 | |
@@ -429,9 +429,9 @@ discard block |
||
429 | 429 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
430 | 430 | |
431 | 431 | // add generic non-identifying messages for non-privileged uesrs |
432 | - if ( ! WP_DEBUG ) { |
|
432 | + if ( ! WP_DEBUG) { |
|
433 | 433 | |
434 | - $output .= '<span class="ee-error-user-msg-spn">' . trim( $ex['msg'] ) . '</span> <sup>' . $ex['code'] . '</sup><br />'; |
|
434 | + $output .= '<span class="ee-error-user-msg-spn">'.trim($ex['msg']).'</span> <sup>'.$ex['code'].'</sup><br />'; |
|
435 | 435 | |
436 | 436 | } else { |
437 | 437 | |
@@ -439,24 +439,24 @@ discard block |
||
439 | 439 | $output .= ' |
440 | 440 | <div class="ee-error-dev-msg-dv"> |
441 | 441 | <p class="ee-error-dev-msg-pg"> |
442 | - <strong class="ee-error-dev-msg-str">An ' . $ex['name'] . ' exception was thrown!</strong> <span>code: ' . $ex['code'] . '</span><br /> |
|
443 | - <span class="big-text">"' . trim( $ex['msg'] ) . '"</span><br/> |
|
444 | - <a id="display-ee-error-trace-' . self::$_error_count . $time . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' . self::$_error_count . $time . '"> |
|
445 | - ' . __( 'click to view backtrace and class/method details', 'event_espresso' ) . ' |
|
442 | + <strong class="ee-error-dev-msg-str">An ' . $ex['name'].' exception was thrown!</strong> <span>code: '.$ex['code'].'</span><br /> |
|
443 | + <span class="big-text">"' . trim($ex['msg']).'"</span><br/> |
|
444 | + <a id="display-ee-error-trace-' . self::$_error_count.$time.'" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'.self::$_error_count.$time.'"> |
|
445 | + ' . __('click to view backtrace and class/method details', 'event_espresso').' |
|
446 | 446 | </a><br /> |
447 | 447 | <span class="small-text lt-grey-text">'.$ex['file'].' ( line no: '.$ex['line'].' )</span> |
448 | 448 | </p> |
449 | - <div id="ee-error-trace-' . self::$_error_count . $time . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
449 | + <div id="ee-error-trace-' . self::$_error_count.$time.'-dv" class="ee-error-trace-dv" style="display: none;"> |
|
450 | 450 | ' . $trace_details; |
451 | 451 | |
452 | - if ( ! empty( $class )) { |
|
452 | + if ( ! empty($class)) { |
|
453 | 453 | $output .= ' |
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | - $a = new ReflectionClass( $class ); |
|
457 | + $a = new ReflectionClass($class); |
|
458 | 458 | $output .= ' |
459 | - <pre>' . $a . '</pre> |
|
459 | + <pre>' . $a.'</pre> |
|
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | 462 | } |
@@ -468,14 +468,14 @@ discard block |
||
468 | 468 | |
469 | 469 | } |
470 | 470 | |
471 | - $this->write_to_error_log( $time, $ex ); |
|
471 | + $this->write_to_error_log($time, $ex); |
|
472 | 472 | |
473 | 473 | } |
474 | 474 | |
475 | 475 | // remove last linebreak |
476 | - $output = substr( $output, 0, ( count( $output ) - 7 )); |
|
476 | + $output = substr($output, 0, (count($output) - 7)); |
|
477 | 477 | |
478 | - if ( ! WP_DEBUG ) { |
|
478 | + if ( ! WP_DEBUG) { |
|
479 | 479 | $output .= ' |
480 | 480 | </p>'; |
481 | 481 | } |
@@ -483,10 +483,10 @@ discard block |
||
483 | 483 | $output .= ' |
484 | 484 | </div>'; |
485 | 485 | |
486 | - $output .= self::_print_scripts( TRUE ); |
|
486 | + $output .= self::_print_scripts(TRUE); |
|
487 | 487 | |
488 | - if ( defined( 'DOING_AJAX' )) { |
|
489 | - echo wp_json_encode( array( 'error' => $output )); |
|
488 | + if (defined('DOING_AJAX')) { |
|
489 | + echo wp_json_encode(array('error' => $output)); |
|
490 | 490 | exit(); |
491 | 491 | } |
492 | 492 | |
@@ -506,29 +506,29 @@ discard block |
||
506 | 506 | * @ param array $arguments |
507 | 507 | * @ return string |
508 | 508 | */ |
509 | - private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) { |
|
509 | + private function _convert_args_to_string($arguments = array(), $array = FALSE) { |
|
510 | 510 | |
511 | 511 | $arg_string = ''; |
512 | - if ( ! empty( $arguments )) { |
|
512 | + if ( ! empty($arguments)) { |
|
513 | 513 | |
514 | 514 | $args = array(); |
515 | 515 | |
516 | - foreach ( $arguments as $arg ) { |
|
516 | + foreach ($arguments as $arg) { |
|
517 | 517 | |
518 | - if ( ! empty( $arg )) { |
|
518 | + if ( ! empty($arg)) { |
|
519 | 519 | |
520 | - if ( is_string( $arg )) { |
|
521 | - $args[] = " '" . $arg . "'"; |
|
522 | - } elseif ( is_array( $arg )) { |
|
523 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string( $arg, TRUE ); |
|
524 | - } elseif ( is_null( $arg )) { |
|
520 | + if (is_string($arg)) { |
|
521 | + $args[] = " '".$arg."'"; |
|
522 | + } elseif (is_array($arg)) { |
|
523 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, TRUE); |
|
524 | + } elseif (is_null($arg)) { |
|
525 | 525 | $args[] = ' NULL'; |
526 | - } elseif ( is_bool( $arg )) { |
|
527 | - $args[] = ( $arg ) ? ' TRUE' : ' FALSE'; |
|
528 | - } elseif ( is_object( $arg )) { |
|
529 | - $args[] = ' OBJECT ' . get_class( $arg ); |
|
530 | - } elseif ( is_resource( $arg )) { |
|
531 | - $args[] = get_resource_type( $arg ); |
|
526 | + } elseif (is_bool($arg)) { |
|
527 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
528 | + } elseif (is_object($arg)) { |
|
529 | + $args[] = ' OBJECT '.get_class($arg); |
|
530 | + } elseif (is_resource($arg)) { |
|
531 | + $args[] = get_resource_type($arg); |
|
532 | 532 | } else { |
533 | 533 | $args[] = $arg; |
534 | 534 | } |
@@ -536,9 +536,9 @@ discard block |
||
536 | 536 | } |
537 | 537 | |
538 | 538 | } |
539 | - $arg_string = implode( ', ', $args ); |
|
539 | + $arg_string = implode(', ', $args); |
|
540 | 540 | } |
541 | - if ( $array ) { |
|
541 | + if ($array) { |
|
542 | 542 | $arg_string .= ' )'; |
543 | 543 | } |
544 | 544 | return $arg_string; |
@@ -558,8 +558,8 @@ discard block |
||
558 | 558 | * @param string $line the line number where the error occurred - just use __LINE__ |
559 | 559 | * @return void |
560 | 560 | */ |
561 | - public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
562 | - self::_add_notice ( 'errors', $msg, $file, $func, $line ); |
|
561 | + public static function add_error($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
562 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
563 | 563 | self::$_error_count++; |
564 | 564 | } |
565 | 565 | |
@@ -572,11 +572,11 @@ discard block |
||
572 | 572 | * @param string $line |
573 | 573 | * @throws EE_Error |
574 | 574 | */ |
575 | - public static function throw_exception_if_debugging( $msg = null, $file = null, $func = null, $line = null ) { |
|
576 | - if( WP_DEBUG ) { |
|
577 | - throw new EE_Error( $msg ); |
|
578 | - } else { |
|
579 | - EE_Error::add_error( $msg, $file, $func, $line ); |
|
575 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) { |
|
576 | + if (WP_DEBUG) { |
|
577 | + throw new EE_Error($msg); |
|
578 | + } else { |
|
579 | + EE_Error::add_error($msg, $file, $func, $line); |
|
580 | 580 | } |
581 | 581 | } |
582 | 582 | |
@@ -594,8 +594,8 @@ discard block |
||
594 | 594 | * @param string $line the line number where the error occurred - just use __LINE__ |
595 | 595 | * @return void |
596 | 596 | */ |
597 | - public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
598 | - self::_add_notice ( 'success', $msg, $file, $func, $line ); |
|
597 | + public static function add_success($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
598 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | |
@@ -612,8 +612,8 @@ discard block |
||
612 | 612 | * @param string $line the line number where the error occurred - just use __LINE__ |
613 | 613 | * @return void |
614 | 614 | */ |
615 | - public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
616 | - self::_add_notice ( 'attention', $msg, $file, $func, $line ); |
|
615 | + public static function add_attention($msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
616 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | |
@@ -631,12 +631,12 @@ discard block |
||
631 | 631 | * @param string $line the line number where the error occurred - just use __LINE__ |
632 | 632 | * @return void |
633 | 633 | */ |
634 | - private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) { |
|
635 | - if ( empty( $msg )) { |
|
634 | + private static function _add_notice($type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL) { |
|
635 | + if (empty($msg)) { |
|
636 | 636 | EE_Error::doing_it_wrong( |
637 | - 'EE_Error::add_' . $type . '()', |
|
637 | + 'EE_Error::add_'.$type.'()', |
|
638 | 638 | sprintf( |
639 | - __( 'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso' ), |
|
639 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso'), |
|
640 | 640 | $type, |
641 | 641 | $file, |
642 | 642 | $line |
@@ -644,17 +644,17 @@ discard block |
||
644 | 644 | EVENT_ESPRESSO_VERSION |
645 | 645 | ); |
646 | 646 | } |
647 | - if ( $type == 'errors' && ( empty( $file ) || empty( $func ) || empty( $line ))) { |
|
647 | + if ($type == 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
648 | 648 | EE_Error::doing_it_wrong( |
649 | 649 | 'EE_Error::add_error()', |
650 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso' ), |
|
650 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso'), |
|
651 | 651 | EVENT_ESPRESSO_VERSION |
652 | 652 | ); |
653 | 653 | } |
654 | 654 | // get separate user and developer messages if they exist |
655 | - $msg = explode( '||', $msg ); |
|
655 | + $msg = explode('||', $msg); |
|
656 | 656 | $user_msg = $msg[0]; |
657 | - $dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0]; |
|
657 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
658 | 658 | /** |
659 | 659 | * Do an action so other code can be triggered when a notice is created |
660 | 660 | * @param string $type can be 'errors', 'attention', or 'success' |
@@ -664,22 +664,22 @@ discard block |
||
664 | 664 | * @param string $func function where error was generated |
665 | 665 | * @param string $line line where error was generated |
666 | 666 | */ |
667 | - do_action( 'AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line ); |
|
667 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
668 | 668 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
669 | 669 | // add notice if message exists |
670 | - if ( ! empty( $msg )) { |
|
670 | + if ( ! empty($msg)) { |
|
671 | 671 | // get error code |
672 | - $notice_code = EE_Error::generate_error_code( $file, $func, $line ); |
|
673 | - if ( WP_DEBUG && $type == 'errors' ) { |
|
674 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
672 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
673 | + if (WP_DEBUG && $type == 'errors') { |
|
674 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
675 | 675 | } |
676 | 676 | // add notice. Index by code if it's not blank |
677 | - if( $notice_code ) { |
|
678 | - self::$_espresso_notices[ $type ][ $notice_code ] = $msg; |
|
677 | + if ($notice_code) { |
|
678 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
679 | 679 | } else { |
680 | - self::$_espresso_notices[ $type ][] = $msg; |
|
680 | + self::$_espresso_notices[$type][] = $msg; |
|
681 | 681 | } |
682 | - add_action( 'wp_footer', array( 'EE_Error', 'enqueue_error_scripts' ), 1 ); |
|
682 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | } |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | * @access private |
734 | 734 | * @return void |
735 | 735 | */ |
736 | - public static function reset_notices(){ |
|
736 | + public static function reset_notices() { |
|
737 | 737 | self::$_espresso_notices['success'] = FALSE; |
738 | 738 | self::$_espresso_notices['attention'] = FALSE; |
739 | 739 | self::$_espresso_notices['errors'] = FALSE; |
@@ -746,14 +746,14 @@ discard block |
||
746 | 746 | * @access public |
747 | 747 | * @return int |
748 | 748 | */ |
749 | - public static function has_notices(){ |
|
749 | + public static function has_notices() { |
|
750 | 750 | $has_notices = 0; |
751 | 751 | // check for success messages |
752 | - $has_notices = self::$_espresso_notices['success'] && ! empty( self::$_espresso_notices['success'] ) ? 3 : $has_notices; |
|
752 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 : $has_notices; |
|
753 | 753 | // check for attention messages |
754 | - $has_notices = self::$_espresso_notices['attention'] && ! empty( self::$_espresso_notices['attention'] ) ? 2 : $has_notices; |
|
754 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 : $has_notices; |
|
755 | 755 | // check for error messages |
756 | - $has_notices = self::$_espresso_notices['errors'] && ! empty( self::$_espresso_notices['errors'] ) ? 1 : $has_notices; |
|
756 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 : $has_notices; |
|
757 | 757 | return $has_notices; |
758 | 758 | } |
759 | 759 | |
@@ -768,9 +768,9 @@ discard block |
||
768 | 768 | */ |
769 | 769 | public static function get_vanilla_notices() { |
770 | 770 | return array( |
771 | - 'success' => isset( self::$_espresso_notices['success'] ) ? self::$_espresso_notices['success'] : array(), |
|
772 | - 'attention' => isset( self::$_espresso_notices['attention'] ) ? self::$_espresso_notices['attention'] : array(), |
|
773 | - 'errors' => isset( self::$_espresso_notices['errors'] ) ? self::$_espresso_notices['errors'] : array(), |
|
771 | + 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
772 | + 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] : array(), |
|
773 | + 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
774 | 774 | ); |
775 | 775 | } |
776 | 776 | |
@@ -786,8 +786,8 @@ discard block |
||
786 | 786 | * @param boolean $remove_empty whether or not to unset empty messages |
787 | 787 | * @return array |
788 | 788 | */ |
789 | - public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) { |
|
790 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
789 | + public static function get_notices($format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE) { |
|
790 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
791 | 791 | |
792 | 792 | $success_messages = ''; |
793 | 793 | $attention_messages = ''; |
@@ -797,44 +797,44 @@ discard block |
||
797 | 797 | // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
798 | 798 | |
799 | 799 | // either save notices to the db |
800 | - if ( $save_to_transient ) { |
|
801 | - update_option( 'ee_notices', self::$_espresso_notices ); |
|
800 | + if ($save_to_transient) { |
|
801 | + update_option('ee_notices', self::$_espresso_notices); |
|
802 | 802 | return; |
803 | 803 | } |
804 | 804 | // grab any notices that have been previously saved |
805 | - if ( $notices = get_option( 'ee_notices', FALSE )) { |
|
806 | - foreach ( $notices as $type => $notice ) { |
|
807 | - if ( is_array( $notice ) && ! empty( $notice )) { |
|
805 | + if ($notices = get_option('ee_notices', FALSE)) { |
|
806 | + foreach ($notices as $type => $notice) { |
|
807 | + if (is_array($notice) && ! empty($notice)) { |
|
808 | 808 | // make sure that existing notice type is an array |
809 | - self::$_espresso_notices[ $type ] = is_array( self::$_espresso_notices[ $type ] ) && ! empty( self::$_espresso_notices[ $type ] ) ? self::$_espresso_notices[ $type ] : array(); |
|
809 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) && ! empty(self::$_espresso_notices[$type]) ? self::$_espresso_notices[$type] : array(); |
|
810 | 810 | // merge stored notices with any newly created ones |
811 | - self::$_espresso_notices[ $type ] = array_merge( self::$_espresso_notices[ $type ], $notice ); |
|
811 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
812 | 812 | $print_scripts = TRUE; |
813 | 813 | } |
814 | 814 | } |
815 | 815 | // now clear any stored notices |
816 | - update_option( 'ee_notices', FALSE ); |
|
816 | + update_option('ee_notices', FALSE); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | // check for success messages |
820 | - if ( self::$_espresso_notices['success'] && ! empty( self::$_espresso_notices['success'] )) { |
|
820 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
821 | 821 | // combine messages |
822 | - $success_messages .= implode( self::$_espresso_notices['success'], '<br />' ); |
|
822 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
823 | 823 | $print_scripts = TRUE; |
824 | 824 | } |
825 | 825 | |
826 | 826 | // check for attention messages |
827 | - if ( self::$_espresso_notices['attention'] && ! empty( self::$_espresso_notices['attention'] ) ) { |
|
827 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
828 | 828 | // combine messages |
829 | - $attention_messages .= implode( self::$_espresso_notices['attention'], '<br />' ); |
|
829 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
830 | 830 | $print_scripts = TRUE; |
831 | 831 | } |
832 | 832 | |
833 | 833 | // check for error messages |
834 | - if ( self::$_espresso_notices['errors'] && ! empty( self::$_espresso_notices['errors'] ) ) { |
|
835 | - $error_messages .= count( self::$_espresso_notices['errors'] ) > 1 ? __( 'The following errors have occurred:<br />', 'event_espresso' ) : __( 'An error has occurred:<br />', 'event_espresso' ); |
|
834 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
835 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 ? __('The following errors have occurred:<br />', 'event_espresso') : __('An error has occurred:<br />', 'event_espresso'); |
|
836 | 836 | // combine messages |
837 | - $error_messages .= implode( self::$_espresso_notices['errors'], '<br />' ); |
|
837 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
838 | 838 | $print_scripts = TRUE; |
839 | 839 | } |
840 | 840 | |
@@ -848,21 +848,21 @@ discard block |
||
848 | 848 | $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
849 | 849 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
850 | 850 | //showMessage( $success_messages ); |
851 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $success_messages . '</p>' . $close . '</div>'; |
|
851 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$success_messages.'</p>'.$close.'</div>'; |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | if ($attention_messages !== '') { |
855 | 855 | $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
856 | 856 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
857 | 857 | //showMessage( $error_messages, TRUE ); |
858 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $attention_messages . '</p>' . $close . '</div>'; |
|
858 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$attention_messages.'</p>'.$close.'</div>'; |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | if ($error_messages !== '') { |
862 | 862 | $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
863 | 863 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
864 | 864 | //showMessage( $error_messages, TRUE ); |
865 | - $notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $error_messages . '</p>' . $close . '</div>'; |
|
865 | + $notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$error_messages.'</p>'.$close.'</div>'; |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | $notices .= '</div>'; |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | 'errors' => $error_messages |
876 | 876 | ); |
877 | 877 | |
878 | - if ( $remove_empty ) { |
|
878 | + if ($remove_empty) { |
|
879 | 879 | // remove empty notices |
880 | 880 | foreach ($notices as $type => $notice) { |
881 | 881 | if (empty($notice)) { |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | } |
886 | 886 | } |
887 | 887 | |
888 | - if ( $print_scripts ) { |
|
888 | + if ($print_scripts) { |
|
889 | 889 | self::_print_scripts(); |
890 | 890 | } |
891 | 891 | |
@@ -905,17 +905,17 @@ discard block |
||
905 | 905 | * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
906 | 906 | * @return void |
907 | 907 | */ |
908 | - public static function add_persistent_admin_notice( $pan_name = '', $pan_message, $force_update = FALSE ) { |
|
909 | - if ( ! empty( $pan_name ) && ! empty( $pan_message )) { |
|
910 | - $persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() ); |
|
908 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = FALSE) { |
|
909 | + if ( ! empty($pan_name) && ! empty($pan_message)) { |
|
910 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
911 | 911 | //maybe initialize persistent_admin_notices |
912 | - if ( empty( $persistent_admin_notices )) { |
|
913 | - add_option( 'ee_pers_admin_notices', array(), '', 'no' ); |
|
912 | + if (empty($persistent_admin_notices)) { |
|
913 | + add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
914 | 914 | } |
915 | - $pan_name = sanitize_key( $pan_name ); |
|
916 | - if ( ! array_key_exists( $pan_name, $persistent_admin_notices ) || $force_update ) { |
|
917 | - $persistent_admin_notices[ $pan_name ] = $pan_message; |
|
918 | - update_option( 'ee_pers_admin_notices', $persistent_admin_notices ); |
|
915 | + $pan_name = sanitize_key($pan_name); |
|
916 | + if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
917 | + $persistent_admin_notices[$pan_name] = $pan_message; |
|
918 | + update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
919 | 919 | } |
920 | 920 | } |
921 | 921 | } |
@@ -931,34 +931,34 @@ discard block |
||
931 | 931 | * @param bool $return_immediately |
932 | 932 | * @return void |
933 | 933 | */ |
934 | - public static function dismiss_persistent_admin_notice( $pan_name = '', $purge = FALSE, $return_immediately = FALSE ) { |
|
935 | - $pan_name = EE_Registry::instance()->REQ->is_set( 'ee_nag_notice' ) ? EE_Registry::instance()->REQ->get( 'ee_nag_notice' ) : $pan_name; |
|
936 | - if ( ! empty( $pan_name )) { |
|
937 | - $persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() ); |
|
934 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = FALSE, $return_immediately = FALSE) { |
|
935 | + $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
936 | + if ( ! empty($pan_name)) { |
|
937 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
938 | 938 | // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
939 | - if ( is_array( $persistent_admin_notices ) && isset( $persistent_admin_notices[ $pan_name ] )) { |
|
939 | + if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
940 | 940 | // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
941 | - if ( $purge ) { |
|
942 | - unset( $persistent_admin_notices[ $pan_name ] ); |
|
941 | + if ($purge) { |
|
942 | + unset($persistent_admin_notices[$pan_name]); |
|
943 | 943 | } else { |
944 | - $persistent_admin_notices[ $pan_name ] = NULL; |
|
944 | + $persistent_admin_notices[$pan_name] = NULL; |
|
945 | 945 | } |
946 | - if ( update_option( 'ee_pers_admin_notices', $persistent_admin_notices ) === FALSE ) { |
|
947 | - EE_Error::add_error( sprintf( __( 'The persistent admin notice for "%s" could not be deleted.', 'event_espresso' ), $pan_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
946 | + if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === FALSE) { |
|
947 | + EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | } |
951 | - if ( $return_immediately ) { |
|
951 | + if ($return_immediately) { |
|
952 | 952 | return; |
953 | - } else if ( EE_Registry::instance()->REQ->ajax ) { |
|
953 | + } else if (EE_Registry::instance()->REQ->ajax) { |
|
954 | 954 | // grab any notices and concatenate into string |
955 | - echo wp_json_encode( array( 'errors' => implode( '<br />', EE_Error::get_notices( FALSE )))); |
|
955 | + echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(FALSE)))); |
|
956 | 956 | exit(); |
957 | 957 | } else { |
958 | 958 | // save errors to a transient to be displayed on next request (after redirect) |
959 | - EE_Error::get_notices( FALSE, TRUE ); |
|
960 | - $return_url = EE_Registry::instance()->REQ->is_set( 'return_url' ) ? EE_Registry::instance()->REQ->get( 'return_url' ) : ''; |
|
961 | - wp_safe_redirect( urldecode( $return_url )); |
|
959 | + EE_Error::get_notices(FALSE, TRUE); |
|
960 | + $return_url = EE_Registry::instance()->REQ->is_set('return_url') ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
961 | + wp_safe_redirect(urldecode($return_url)); |
|
962 | 962 | } |
963 | 963 | } |
964 | 964 | |
@@ -973,20 +973,20 @@ discard block |
||
973 | 973 | * @param string $return_url URL to go back to after nag notice is dismissed |
974 | 974 | * @return string |
975 | 975 | */ |
976 | - public static function display_persistent_admin_notices( $pan_name = '', $pan_message = '', $return_url = '' ) { |
|
977 | - if ( ! empty( $pan_name ) && ! empty( $pan_message )&& ! is_array( $pan_message )) { |
|
976 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') { |
|
977 | + if ( ! empty($pan_name) && ! empty($pan_message) && ! is_array($pan_message)) { |
|
978 | 978 | $args = array( |
979 | 979 | 'nag_notice' => $pan_name, |
980 | - 'return_url' => urlencode( $return_url ), |
|
980 | + 'return_url' => urlencode($return_url), |
|
981 | 981 | 'ajax_url' => WP_AJAX_URL, |
982 | - 'unknown_error' => __( 'An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso' ) |
|
982 | + 'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso') |
|
983 | 983 | ); |
984 | - wp_localize_script( 'espresso_core', 'ee_dismiss', $args ); |
|
984 | + wp_localize_script('espresso_core', 'ee_dismiss', $args); |
|
985 | 985 | return ' |
986 | - <div id="' . $pan_name . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
987 | - <p>' . $pan_message . '</p> |
|
988 | - <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name . '"> |
|
989 | - <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__( 'Dismiss', 'event_espresso' ) .' |
|
986 | + <div id="' . $pan_name.'" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
987 | + <p>' . $pan_message.'</p> |
|
988 | + <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name.'"> |
|
989 | + <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__('Dismiss', 'event_espresso').' |
|
990 | 990 | </a> |
991 | 991 | <div style="clear:both;"></div> |
992 | 992 | </div>'; |
@@ -1003,24 +1003,24 @@ discard block |
||
1003 | 1003 | * @param string $return_url |
1004 | 1004 | * @return array |
1005 | 1005 | */ |
1006 | - public static function get_persistent_admin_notices( $return_url = '' ) { |
|
1006 | + public static function get_persistent_admin_notices($return_url = '') { |
|
1007 | 1007 | $notices = ''; |
1008 | 1008 | // check for persistent admin notices |
1009 | 1009 | //filter the list though so plugins can notify the admin in a different way if they want |
1010 | 1010 | $persistent_admin_notices = apply_filters( |
1011 | 1011 | 'FHEE__EE_Error__get_persistent_admin_notices', |
1012 | - get_option( 'ee_pers_admin_notices', FALSE ), |
|
1012 | + get_option('ee_pers_admin_notices', FALSE), |
|
1013 | 1013 | 'ee_pers_admin_notices', |
1014 | 1014 | $return_url |
1015 | 1015 | ); |
1016 | - if ( $persistent_admin_notices ) { |
|
1016 | + if ($persistent_admin_notices) { |
|
1017 | 1017 | // load scripts |
1018 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
1019 | - wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
1020 | - wp_enqueue_script( 'ee_error_js' ); |
|
1018 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
1019 | + wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE); |
|
1020 | + wp_enqueue_script('ee_error_js'); |
|
1021 | 1021 | // and display notices |
1022 | - foreach( $persistent_admin_notices as $pan_name => $pan_message ) { |
|
1023 | - $notices .= self::display_persistent_admin_notices( $pan_name, $pan_message, $return_url ); |
|
1022 | + foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
1023 | + $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
1024 | 1024 | } |
1025 | 1025 | } |
1026 | 1026 | return $notices; |
@@ -1035,26 +1035,26 @@ discard block |
||
1035 | 1035 | * @param bool $force_print |
1036 | 1036 | * @return void |
1037 | 1037 | */ |
1038 | - private static function _print_scripts( $force_print = FALSE ) { |
|
1039 | - if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) { |
|
1040 | - if ( wp_script_is( 'ee_error_js', 'enqueued' )) { |
|
1038 | + private static function _print_scripts($force_print = FALSE) { |
|
1039 | + if ((did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts')) && ! $force_print) { |
|
1040 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1041 | 1041 | return; |
1042 | - } else if ( wp_script_is( 'ee_error_js', 'registered' )) { |
|
1043 | - add_filter( 'FHEE_load_css', '__return_true' ); |
|
1044 | - add_filter( 'FHEE_load_js', '__return_true' ); |
|
1045 | - wp_enqueue_script( 'ee_error_js' ); |
|
1046 | - wp_localize_script( 'ee_error_js','ee_settings', array( 'wp_debug'=>WP_DEBUG )); |
|
1042 | + } else if (wp_script_is('ee_error_js', 'registered')) { |
|
1043 | + add_filter('FHEE_load_css', '__return_true'); |
|
1044 | + add_filter('FHEE_load_js', '__return_true'); |
|
1045 | + wp_enqueue_script('ee_error_js'); |
|
1046 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug'=>WP_DEBUG)); |
|
1047 | 1047 | } |
1048 | 1048 | } else { |
1049 | 1049 | return ' |
1050 | 1050 | <script> |
1051 | 1051 | /* <![CDATA[ */ |
1052 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
1052 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
1053 | 1053 | /* ]]> */ |
1054 | 1054 | </script> |
1055 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
1056 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1057 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1055 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
1056 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1057 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1058 | 1058 | '; |
1059 | 1059 | |
1060 | 1060 | } |
@@ -1088,11 +1088,11 @@ discard block |
||
1088 | 1088 | * @param string $line |
1089 | 1089 | * @return string |
1090 | 1090 | */ |
1091 | - public static function generate_error_code ( $file = '', $func = '', $line = '' ) { |
|
1092 | - $file = explode( '.', basename( $file )); |
|
1093 | - $error_code = ! empty( $file[0] ) ? $file[0] : ''; |
|
1094 | - $error_code .= ! empty( $func ) ? ' - ' . $func : ''; |
|
1095 | - $error_code .= ! empty( $line ) ? ' - ' . $line : ''; |
|
1091 | + public static function generate_error_code($file = '', $func = '', $line = '') { |
|
1092 | + $file = explode('.', basename($file)); |
|
1093 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1094 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
1095 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
1096 | 1096 | return $error_code; |
1097 | 1097 | } |
1098 | 1098 | |
@@ -1108,36 +1108,36 @@ discard block |
||
1108 | 1108 | * @ param object $ex |
1109 | 1109 | * @ return void |
1110 | 1110 | */ |
1111 | - public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) { |
|
1111 | + public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) { |
|
1112 | 1112 | |
1113 | - if ( ! $ex ) { |
|
1113 | + if ( ! $ex) { |
|
1114 | 1114 | return; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - if ( ! $time ) { |
|
1117 | + if ( ! $time) { |
|
1118 | 1118 | $time = time(); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - $exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
1122 | - $exception_log .= '[' . date( 'Y-m-d H:i:s', $time ) . '] Exception Details' . PHP_EOL; |
|
1123 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1124 | - $exception_log .= 'Code: '. $ex['code'] . PHP_EOL; |
|
1125 | - $exception_log .= 'File: '. $ex['file'] . PHP_EOL; |
|
1126 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1127 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1128 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1129 | - $exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
1121 | + $exception_log = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
1122 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
1123 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
1124 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
1125 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
1126 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
1127 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
1128 | + $exception_log .= $ex['string'].PHP_EOL; |
|
1129 | + $exception_log .= '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
1130 | 1130 | |
1131 | 1131 | try { |
1132 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ); |
|
1133 | - EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' ); |
|
1134 | - if ( ! $clear ) { |
|
1132 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file); |
|
1133 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs'); |
|
1134 | + if ( ! $clear) { |
|
1135 | 1135 | //get existing log file and append new log info |
1136 | - $exception_log = EEH_File::get_file_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ) . $exception_log; |
|
1136 | + $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file).$exception_log; |
|
1137 | 1137 | } |
1138 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log ); |
|
1139 | - } catch( EE_Error $e ){ |
|
1140 | - EE_Error::add_error( sprintf( __( 'Event Espresso error logging could not be setup because: %s', 'event_espresso' ), $e->getMessage() )); |
|
1138 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, $exception_log); |
|
1139 | + } catch (EE_Error $e) { |
|
1140 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage())); |
|
1141 | 1141 | return; |
1142 | 1142 | } |
1143 | 1143 | |
@@ -1173,8 +1173,8 @@ discard block |
||
1173 | 1173 | $applies_when = '', |
1174 | 1174 | $error_type = null |
1175 | 1175 | ) { |
1176 | - if ( defined('WP_DEBUG') && WP_DEBUG ) { |
|
1177 | - EEH_Debug_Tools::instance()->doing_it_wrong( $function, $message, $version, $applies_when, $error_type ); |
|
1176 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1177 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1178 | 1178 | } |
1179 | 1179 | } |
1180 | 1180 | |
@@ -1208,13 +1208,13 @@ discard block |
||
1208 | 1208 | */ |
1209 | 1209 | function espresso_error_enqueue_scripts() { |
1210 | 1210 | // js for error handling |
1211 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE ); |
|
1212 | - wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE ); |
|
1211 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE); |
|
1212 | + wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE); |
|
1213 | 1213 | } |
1214 | -if ( is_admin() ) { |
|
1215 | - add_action( 'admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 ); |
|
1214 | +if (is_admin()) { |
|
1215 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1216 | 1216 | } else { |
1217 | - add_action( 'wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 ); |
|
1217 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 |
@@ -9,69 +9,69 @@ |
||
9 | 9 | interface EEI_Attendee |
10 | 10 | { |
11 | 11 | |
12 | - public function fname(); |
|
12 | + public function fname(); |
|
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - public function lname(); |
|
16 | + public function lname(); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
20 | - public function full_name(); |
|
20 | + public function full_name(); |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - public function email(); |
|
24 | + public function email(); |
|
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - public function phone(); |
|
28 | + public function phone(); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - public function address(); |
|
32 | + public function address(); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - public function address2(); |
|
36 | + public function address2(); |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - public function city(); |
|
40 | + public function city(); |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - public function state_ID(); |
|
44 | + public function state_ID(); |
|
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | - public function state_name(); |
|
48 | + public function state_name(); |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return EE_State |
|
54 | - */ |
|
55 | - public function state_obj(); |
|
52 | + /** |
|
53 | + * @return EE_State |
|
54 | + */ |
|
55 | + public function state_obj(); |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - public function country_ID(); |
|
59 | + public function country_ID(); |
|
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | - public function country_name(); |
|
63 | + public function country_name(); |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @return EE_Country |
|
69 | - */ |
|
70 | - public function country_obj(); |
|
67 | + /** |
|
68 | + * @return EE_Country |
|
69 | + */ |
|
70 | + public function country_obj(); |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - public function zip(); |
|
74 | + public function zip(); |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | // End of file EEI_Attendee.interface.php |
@@ -9,90 +9,90 @@ |
||
9 | 9 | interface EEHI_Line_Item |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * Adds an item to the purchase in the right spot |
|
14 | - * |
|
15 | - * @param EE_Line_Item $total_line_item |
|
16 | - * @param EE_Line_Item $line_item |
|
17 | - */ |
|
18 | - public function add_item(EE_Line_Item $total_line_item, EE_Line_Item $line_item); |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
24 | - * tax and updates the total line item accordingly |
|
25 | - * |
|
26 | - * @param EE_Line_Item $total_line_item |
|
27 | - * @param float $amount |
|
28 | - * @param string $name |
|
29 | - * @param string $description |
|
30 | - * @param string $code |
|
31 | - * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
32 | - * the same code is found, $amount will be added onto it; otherwise will simply |
|
33 | - * set the taxes to match $amount |
|
34 | - * @return EE_Line_Item the new tax created |
|
35 | - */ |
|
36 | - public function set_total_tax_to( |
|
37 | - EE_Line_Item $total_line_item, |
|
38 | - $amount, |
|
39 | - $name = null, |
|
40 | - $description = null, |
|
41 | - $code = null, |
|
42 | - $add_to_existing_line_item = false |
|
43 | - ); |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Makes all the line items which are children of $line_item taxable (or not). |
|
49 | - * Does NOT save the line items |
|
50 | - * |
|
51 | - * @param EE_Line_Item $line_item |
|
52 | - * @param boolean $taxable |
|
53 | - * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
54 | - * it will be whitelisted (ie, except from becoming taxable) |
|
55 | - */ |
|
56 | - public static function set_line_items_taxable( |
|
57 | - EE_Line_Item $line_item, |
|
58 | - $taxable = true, |
|
59 | - $code_substring_for_whitelist = null |
|
60 | - ); |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
66 | - * in the correct spot in the line item tree. |
|
67 | - * |
|
68 | - * @param EE_Line_Item $total_line_item |
|
69 | - * @param string $name |
|
70 | - * @param float $unit_price |
|
71 | - * @param string $description |
|
72 | - * @param int $quantity |
|
73 | - * @param boolean $taxable |
|
74 | - * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
75 | - * @return boolean success |
|
76 | - */ |
|
77 | - public function add_unrelated_item( |
|
78 | - EE_Line_Item $total_line_item, |
|
79 | - $name, |
|
80 | - $unit_price, |
|
81 | - $description = '', |
|
82 | - $quantity = 1, |
|
83 | - $taxable = false, |
|
84 | - $code = null |
|
85 | - ); |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Gets the line item for the taxes subtotal |
|
91 | - * |
|
92 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
93 | - * @return \EE_Line_Item |
|
94 | - */ |
|
95 | - public static function get_taxes_subtotal(EE_Line_Item $total_line_item); |
|
12 | + /** |
|
13 | + * Adds an item to the purchase in the right spot |
|
14 | + * |
|
15 | + * @param EE_Line_Item $total_line_item |
|
16 | + * @param EE_Line_Item $line_item |
|
17 | + */ |
|
18 | + public function add_item(EE_Line_Item $total_line_item, EE_Line_Item $line_item); |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
24 | + * tax and updates the total line item accordingly |
|
25 | + * |
|
26 | + * @param EE_Line_Item $total_line_item |
|
27 | + * @param float $amount |
|
28 | + * @param string $name |
|
29 | + * @param string $description |
|
30 | + * @param string $code |
|
31 | + * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
32 | + * the same code is found, $amount will be added onto it; otherwise will simply |
|
33 | + * set the taxes to match $amount |
|
34 | + * @return EE_Line_Item the new tax created |
|
35 | + */ |
|
36 | + public function set_total_tax_to( |
|
37 | + EE_Line_Item $total_line_item, |
|
38 | + $amount, |
|
39 | + $name = null, |
|
40 | + $description = null, |
|
41 | + $code = null, |
|
42 | + $add_to_existing_line_item = false |
|
43 | + ); |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Makes all the line items which are children of $line_item taxable (or not). |
|
49 | + * Does NOT save the line items |
|
50 | + * |
|
51 | + * @param EE_Line_Item $line_item |
|
52 | + * @param boolean $taxable |
|
53 | + * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
54 | + * it will be whitelisted (ie, except from becoming taxable) |
|
55 | + */ |
|
56 | + public static function set_line_items_taxable( |
|
57 | + EE_Line_Item $line_item, |
|
58 | + $taxable = true, |
|
59 | + $code_substring_for_whitelist = null |
|
60 | + ); |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
66 | + * in the correct spot in the line item tree. |
|
67 | + * |
|
68 | + * @param EE_Line_Item $total_line_item |
|
69 | + * @param string $name |
|
70 | + * @param float $unit_price |
|
71 | + * @param string $description |
|
72 | + * @param int $quantity |
|
73 | + * @param boolean $taxable |
|
74 | + * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
75 | + * @return boolean success |
|
76 | + */ |
|
77 | + public function add_unrelated_item( |
|
78 | + EE_Line_Item $total_line_item, |
|
79 | + $name, |
|
80 | + $unit_price, |
|
81 | + $description = '', |
|
82 | + $quantity = 1, |
|
83 | + $taxable = false, |
|
84 | + $code = null |
|
85 | + ); |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Gets the line item for the taxes subtotal |
|
91 | + * |
|
92 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
93 | + * @return \EE_Line_Item |
|
94 | + */ |
|
95 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item); |
|
96 | 96 | } |
97 | 97 | // End of file EEHI_Line_Item.interface.php |
98 | 98 | // Location: core/interfaces/line_items/EEHI_Line_Item.interface.php |
99 | 99 | \ No newline at end of file |
@@ -9,12 +9,12 @@ |
||
9 | 9 | interface EEI_Line_Item_Display |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param EE_Line_Item $line_item |
|
14 | - * @param array $options |
|
15 | - * @return mixed |
|
16 | - */ |
|
17 | - public function display_line_item(EE_Line_Item $line_item, $options = array()); |
|
12 | + /** |
|
13 | + * @param EE_Line_Item $line_item |
|
14 | + * @param array $options |
|
15 | + * @return mixed |
|
16 | + */ |
|
17 | + public function display_line_item(EE_Line_Item $line_item, $options = array()); |
|
18 | 18 | |
19 | 19 | } |
20 | 20 |
@@ -9,65 +9,65 @@ |
||
9 | 9 | interface EEI_Transaction extends EEI_Base |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @return EEI_Payment |
|
14 | - */ |
|
15 | - public function last_payment(); |
|
12 | + /** |
|
13 | + * @return EEI_Payment |
|
14 | + */ |
|
15 | + public function last_payment(); |
|
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Gets the total that should eb paid for this transaction |
|
21 | - * |
|
22 | - * @return float |
|
23 | - */ |
|
24 | - public function total(); |
|
19 | + /** |
|
20 | + * Gets the total that should eb paid for this transaction |
|
21 | + * |
|
22 | + * @return float |
|
23 | + */ |
|
24 | + public function total(); |
|
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Get the line item that represents the total for the transaction |
|
30 | - * |
|
31 | - * @return EEI_Line_Item |
|
32 | - */ |
|
33 | - public function total_line_item(); |
|
28 | + /** |
|
29 | + * Get the line item that represents the total for the transaction |
|
30 | + * |
|
31 | + * @return EEI_Line_Item |
|
32 | + */ |
|
33 | + public function total_line_item(); |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Gets the primary registration for this transaction |
|
39 | - * |
|
40 | - * @return EEI_Registration |
|
41 | - */ |
|
42 | - public function primary_registration(); |
|
37 | + /** |
|
38 | + * Gets the primary registration for this transaction |
|
39 | + * |
|
40 | + * @return EEI_Registration |
|
41 | + */ |
|
42 | + public function primary_registration(); |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Returns the balance due on the transaction |
|
48 | - * |
|
49 | - * @return float |
|
50 | - */ |
|
51 | - public function remaining(); |
|
46 | + /** |
|
47 | + * Returns the balance due on the transaction |
|
48 | + * |
|
49 | + * @return float |
|
50 | + */ |
|
51 | + public function remaining(); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * get Total Amount Paid to Date |
|
57 | - * |
|
58 | - * @access public |
|
59 | - * @return float |
|
60 | - */ |
|
61 | - public function paid(); |
|
55 | + /** |
|
56 | + * get Total Amount Paid to Date |
|
57 | + * |
|
58 | + * @access public |
|
59 | + * @return float |
|
60 | + */ |
|
61 | + public function paid(); |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * Retrieves all the pending payments on this transaction |
|
67 | - * |
|
68 | - * @return EEI_Payment[] |
|
69 | - */ |
|
70 | - public function pending_payments(); |
|
65 | + /** |
|
66 | + * Retrieves all the pending payments on this transaction |
|
67 | + * |
|
68 | + * @return EEI_Payment[] |
|
69 | + */ |
|
70 | + public function pending_payments(); |
|
71 | 71 | |
72 | 72 | |
73 | 73 |