@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | |
197 | 197 | /** |
198 | - * @param $default_form_step |
|
198 | + * @param string $default_form_step |
|
199 | 199 | * @throws InvalidDataTypeException |
200 | 200 | */ |
201 | 201 | protected function setDefaultFormStep( $default_form_step ) { |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | |
505 | 505 | /** |
506 | 506 | * @param array $form_data |
507 | - * @return bool |
|
507 | + * @return boolean|null |
|
508 | 508 | * @throws InvalidArgumentException |
509 | 509 | * @throws InvalidDataTypeException |
510 | 510 | */ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | use Exception; |
17 | 17 | use InvalidArgumentException; |
18 | 18 | |
19 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
20 | - exit( 'No direct script access allowed' ); |
|
19 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
20 | + exit('No direct script access allowed'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | $progress_step_style = 'number_bubbles', |
116 | 116 | EE_Request $request |
117 | 117 | ) { |
118 | - $this->setBaseUrl( $base_url ); |
|
119 | - $this->setDefaultFormStep( $default_form_step ); |
|
120 | - $this->setFormAction( $form_action ); |
|
121 | - $this->setFormConfig( $form_config ); |
|
122 | - $this->setProgressStepStyle( $progress_step_style ); |
|
118 | + $this->setBaseUrl($base_url); |
|
119 | + $this->setDefaultFormStep($default_form_step); |
|
120 | + $this->setFormAction($form_action); |
|
121 | + $this->setFormConfig($form_config); |
|
122 | + $this->setProgressStepStyle($progress_step_style); |
|
123 | 123 | $this->request = $request; |
124 | 124 | } |
125 | 125 | |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
131 | 131 | */ |
132 | 132 | public function baseUrl() { |
133 | - if ( strpos( $this->base_url, $this->getCurrentStep()->slug() ) === false ) { |
|
133 | + if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
134 | 134 | add_query_arg( |
135 | - array( $this->form_step_url_key => $this->getCurrentStep()->slug() ), |
|
135 | + array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
136 | 136 | $this->base_url |
137 | 137 | ); |
138 | 138 | } |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | * @throws InvalidDataTypeException |
147 | 147 | * @throws InvalidArgumentException |
148 | 148 | */ |
149 | - protected function setBaseUrl( $base_url ) { |
|
150 | - if ( ! is_string( $base_url ) ) { |
|
151 | - throw new InvalidDataTypeException( '$base_url', $base_url, 'string' ); |
|
149 | + protected function setBaseUrl($base_url) { |
|
150 | + if ( ! is_string($base_url)) { |
|
151 | + throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
152 | 152 | } |
153 | - if ( empty( $base_url ) ) { |
|
153 | + if (empty($base_url)) { |
|
154 | 154 | throw new InvalidArgumentException( |
155 | - __( 'The base URL can not be an empty string.', 'event_espresso' ) |
|
155 | + __('The base URL can not be an empty string.', 'event_espresso') |
|
156 | 156 | ); |
157 | 157 | } |
158 | 158 | $this->base_url = $base_url; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @throws InvalidDataTypeException |
166 | 166 | */ |
167 | 167 | public function formStepUrlKey() { |
168 | - if ( empty( $this->form_step_url_key ) ) { |
|
168 | + if (empty($this->form_step_url_key)) { |
|
169 | 169 | $this->setFormStepUrlKey(); |
170 | 170 | } |
171 | 171 | return $this->form_step_url_key; |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | * @param string $form_step_url_key |
178 | 178 | * @throws InvalidDataTypeException |
179 | 179 | */ |
180 | - public function setFormStepUrlKey( $form_step_url_key = 'ee-form-step' ) { |
|
181 | - if ( ! is_string( $form_step_url_key ) ) { |
|
182 | - throw new InvalidDataTypeException( '$form_step_key', $form_step_url_key, 'string' ); |
|
180 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') { |
|
181 | + if ( ! is_string($form_step_url_key)) { |
|
182 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
183 | 183 | } |
184 | - $this->form_step_url_key = ! empty( $form_step_url_key ) ? $form_step_url_key : 'ee-form-step'; |
|
184 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * @param $default_form_step |
200 | 200 | * @throws InvalidDataTypeException |
201 | 201 | */ |
202 | - protected function setDefaultFormStep( $default_form_step ) { |
|
203 | - if ( ! is_string( $default_form_step ) ) { |
|
204 | - throw new InvalidDataTypeException( '$default_form_step', $default_form_step, 'string' ); |
|
202 | + protected function setDefaultFormStep($default_form_step) { |
|
203 | + if ( ! is_string($default_form_step)) { |
|
204 | + throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
205 | 205 | } |
206 | 206 | $this->default_form_step = $default_form_step; |
207 | 207 | } |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @throws InvalidDataTypeException |
215 | 215 | */ |
216 | 216 | protected function setCurrentStepFromRequest() { |
217 | - $current_step_slug = $this->request()->get( $this->formStepUrlKey(), $this->defaultFormStep() ); |
|
218 | - if ( ! $this->form_steps->setCurrent( $current_step_slug ) ) { |
|
217 | + $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep()); |
|
218 | + if ( ! $this->form_steps->setCurrent($current_step_slug)) { |
|
219 | 219 | throw new InvalidIdentifierException( |
220 | 220 | $current_step_slug, |
221 | 221 | $this->defaultFormStep(), |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
238 | 238 | */ |
239 | 239 | public function getCurrentStep() { |
240 | - if ( ! $this->form_steps->current() instanceof SequentialStepForm ) { |
|
241 | - throw new InvalidFormHandlerException( $this->form_steps->current() ); |
|
240 | + if ( ! $this->form_steps->current() instanceof SequentialStepForm) { |
|
241 | + throw new InvalidFormHandlerException($this->form_steps->current()); |
|
242 | 242 | } |
243 | 243 | return $this->form_steps->current(); |
244 | 244 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
251 | 251 | */ |
252 | 252 | public function formAction() { |
253 | - if ( ! is_string( $this->form_action ) || empty( $this->form_action ) ) { |
|
253 | + if ( ! is_string($this->form_action) || empty($this->form_action)) { |
|
254 | 254 | $this->form_action = $this->baseUrl(); |
255 | 255 | } |
256 | 256 | return $this->form_action; |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param string $form_action |
263 | 263 | * @throws InvalidDataTypeException |
264 | 264 | */ |
265 | - public function setFormAction( $form_action ) { |
|
266 | - if ( ! is_string( $form_action ) ) { |
|
267 | - throw new InvalidDataTypeException( '$form_action', $form_action, 'string' ); |
|
265 | + public function setFormAction($form_action) { |
|
266 | + if ( ! is_string($form_action)) { |
|
267 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
268 | 268 | } |
269 | 269 | $this->form_action = $form_action; |
270 | 270 | } |
@@ -275,15 +275,15 @@ discard block |
||
275 | 275 | * @param array $form_action_args |
276 | 276 | * @throws InvalidDataTypeException |
277 | 277 | */ |
278 | - public function addFormActionArgs( $form_action_args = array() ) { |
|
279 | - if ( ! is_array( $form_action_args ) ) { |
|
280 | - throw new InvalidDataTypeException( '$form_action_args', $form_action_args, 'array' ); |
|
278 | + public function addFormActionArgs($form_action_args = array()) { |
|
279 | + if ( ! is_array($form_action_args)) { |
|
280 | + throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
281 | 281 | } |
282 | - $form_action_args = ! empty( $form_action_args ) |
|
282 | + $form_action_args = ! empty($form_action_args) |
|
283 | 283 | ? $form_action_args |
284 | - : array( $this->formStepUrlKey() => $this->form_steps->current()->slug() ); |
|
284 | + : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
285 | 285 | $this->getCurrentStep()->setFormAction( |
286 | - add_query_arg( $form_action_args, $this->formAction() ) |
|
286 | + add_query_arg($form_action_args, $this->formAction()) |
|
287 | 287 | ); |
288 | 288 | $this->form_action = $this->getCurrentStep()->formAction(); |
289 | 289 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | /** |
303 | 303 | * @param string $form_config |
304 | 304 | */ |
305 | - public function setFormConfig( $form_config ) { |
|
305 | + public function setFormConfig($form_config) { |
|
306 | 306 | $this->form_config = $form_config; |
307 | 307 | } |
308 | 308 | |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | /** |
321 | 321 | * @param string $progress_step_style |
322 | 322 | */ |
323 | - public function setProgressStepStyle( $progress_step_style ) { |
|
323 | + public function setProgressStepStyle($progress_step_style) { |
|
324 | 324 | $this->progress_step_style = $progress_step_style; |
325 | 325 | } |
326 | 326 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | */ |
341 | 341 | protected function getProgressStepsCollection() { |
342 | 342 | static $collection = null; |
343 | - if ( ! $collection instanceof ProgressStepCollection ) { |
|
343 | + if ( ! $collection instanceof ProgressStepCollection) { |
|
344 | 344 | $collection = new ProgressStepCollection(); |
345 | 345 | } |
346 | 346 | return $collection; |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | * @throws InvalidClassException |
357 | 357 | * @throws InvalidInterfaceException |
358 | 358 | */ |
359 | - protected function generateProgressSteps( Collection $progress_steps_collection ) { |
|
359 | + protected function generateProgressSteps(Collection $progress_steps_collection) { |
|
360 | 360 | $current_step = $this->getCurrentStep(); |
361 | 361 | /** @var SequentialStepForm $form_step */ |
362 | - foreach ( $this->form_steps as $form_step ) { |
|
362 | + foreach ($this->form_steps as $form_step) { |
|
363 | 363 | // is this step active ? |
364 | - if ( ! $form_step->initialize() ) { |
|
364 | + if ( ! $form_step->initialize()) { |
|
365 | 365 | continue; |
366 | 366 | } |
367 | 367 | $progress_steps_collection->add( |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | ); |
376 | 376 | } |
377 | 377 | // set collection pointer back to current step |
378 | - $this->form_steps->setCurrentUsingObject( $current_step ); |
|
378 | + $this->form_steps->setCurrentUsingObject($current_step); |
|
379 | 379 | return new ProgressStepManager( |
380 | 380 | $this->progressStepStyle(), |
381 | 381 | $this->defaultFormStep(), |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @throws InvalidInterfaceException |
410 | 410 | * @throws InvalidArgumentException |
411 | 411 | */ |
412 | - public function processForm( $form_data = array() ) { |
|
412 | + public function processForm($form_data = array()) { |
|
413 | 413 | $this->buildCurrentStepFormForProcessing(); |
414 | - $this->processCurrentStepForm( $form_data ); |
|
414 | + $this->processCurrentStepForm($form_data); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | public function buildCurrentStepFormForDisplay() { |
428 | 428 | $form_step = $this->buildCurrentStepForm(); |
429 | 429 | // no displayable content ? then skip straight to processing |
430 | - if ( ! $form_step->displayable() ) { |
|
430 | + if ( ! $form_step->displayable()) { |
|
431 | 431 | $this->addFormActionArgs(); |
432 | - $form_step->setFormAction( $this->formAction() ); |
|
433 | - wp_safe_redirect( $form_step->formAction() ); |
|
432 | + $form_step->setFormAction($this->formAction()); |
|
433 | + wp_safe_redirect($form_step->formAction()); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @throws InvalidArgumentException |
446 | 446 | */ |
447 | 447 | public function buildCurrentStepFormForProcessing() { |
448 | - $this->buildCurrentStepForm( false ); |
|
448 | + $this->buildCurrentStepForm(false); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -460,14 +460,14 @@ discard block |
||
460 | 460 | * @throws InvalidInterfaceException |
461 | 461 | * @throws InvalidArgumentException |
462 | 462 | */ |
463 | - private function buildCurrentStepForm( $for_display = true ) { |
|
463 | + private function buildCurrentStepForm($for_display = true) { |
|
464 | 464 | $this->form_steps = $this->getFormStepsCollection(); |
465 | 465 | $this->setCurrentStepFromRequest(); |
466 | 466 | $form_step = $this->getCurrentStep(); |
467 | - if ( $form_step->submitBtnText() === __( 'Submit', 'event_espresso' ) ) { |
|
468 | - $form_step->setSubmitBtnText( __( 'Next Step', 'event_espresso' ) ); |
|
467 | + if ($form_step->submitBtnText() === __('Submit', 'event_espresso')) { |
|
468 | + $form_step->setSubmitBtnText(__('Next Step', 'event_espresso')); |
|
469 | 469 | } |
470 | - if ( $for_display && $form_step->displayable() ) { |
|
470 | + if ($for_display && $form_step->displayable()) { |
|
471 | 471 | $this->progress_step_manager = $this->generateProgressSteps( |
472 | 472 | $this->getProgressStepsCollection() |
473 | 473 | ); |
@@ -478,16 +478,16 @@ discard block |
||
478 | 478 | $this->progress_step_manager->setPreviousStepsCompleted(); |
479 | 479 | $this->progress_step_manager->enqueueStylesAndScripts(); |
480 | 480 | $this->addFormActionArgs(); |
481 | - $form_step->setFormAction( $this->formAction() ); |
|
481 | + $form_step->setFormAction($this->formAction()); |
|
482 | 482 | |
483 | 483 | } else { |
484 | - $form_step->setRedirectUrl( $this->baseUrl() ); |
|
484 | + $form_step->setRedirectUrl($this->baseUrl()); |
|
485 | 485 | $form_step->addRedirectArgs( |
486 | - array( $this->formStepUrlKey() => $this->form_steps->current()->slug() ) |
|
486 | + array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
487 | 487 | ); |
488 | 488 | } |
489 | 489 | $form_step->generate(); |
490 | - if ( $for_display ) { |
|
490 | + if ($for_display) { |
|
491 | 491 | $form_step->enqueueStylesAndScripts(); |
492 | 492 | } |
493 | 493 | return $form_step; |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param bool $return_as_string |
500 | 500 | * @return string |
501 | 501 | */ |
502 | - public function displayProgressSteps( $return_as_string = true ) { |
|
502 | + public function displayProgressSteps($return_as_string = true) { |
|
503 | 503 | $progress_steps = apply_filters( |
504 | 504 | 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
505 | 505 | '' |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
510 | 510 | '' |
511 | 511 | ); |
512 | - if ( $return_as_string ) { |
|
512 | + if ($return_as_string) { |
|
513 | 513 | return $progress_steps; |
514 | 514 | } |
515 | 515 | echo $progress_steps; |
@@ -523,8 +523,8 @@ discard block |
||
523 | 523 | * @return string |
524 | 524 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
525 | 525 | */ |
526 | - public function displayCurrentStepForm( $return_as_string = true ) { |
|
527 | - if ( $return_as_string ) { |
|
526 | + public function displayCurrentStepForm($return_as_string = true) { |
|
527 | + if ($return_as_string) { |
|
528 | 528 | return $this->getCurrentStep()->display(); |
529 | 529 | } |
530 | 530 | echo $this->getCurrentStep()->display(); |
@@ -539,32 +539,32 @@ discard block |
||
539 | 539 | * @throws InvalidArgumentException |
540 | 540 | * @throws InvalidDataTypeException |
541 | 541 | */ |
542 | - public function processCurrentStepForm( $form_data = array() ) { |
|
542 | + public function processCurrentStepForm($form_data = array()) { |
|
543 | 543 | // grab instance of current step because after calling next() below, |
544 | 544 | // any calls to getCurrentStep() will return the "next" step because we advanced |
545 | 545 | $current_step = $this->getCurrentStep(); |
546 | 546 | try { |
547 | 547 | // form processing should either throw exceptions or return true |
548 | - $current_step->process( $form_data ); |
|
549 | - } catch ( Exception $e ) { |
|
548 | + $current_step->process($form_data); |
|
549 | + } catch (Exception $e) { |
|
550 | 550 | // something went wrong, so... |
551 | 551 | // if WP_DEBUG === true, display the Exception and stack trace right now |
552 | - new ExceptionStackTraceDisplay( $e ); |
|
552 | + new ExceptionStackTraceDisplay($e); |
|
553 | 553 | // else convert the Exception to an EE_Error |
554 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
554 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
555 | 555 | // prevent redirect to next step or other if exception was thrown |
556 | 556 | if ( |
557 | 557 | $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
558 | 558 | || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
559 | 559 | ) { |
560 | - $current_step->setRedirectTo( SequentialStepForm::REDIRECT_TO_CURRENT_STEP ); |
|
560 | + $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | // save notices to a transient so that when we redirect back |
564 | 564 | // to the display portion for this step |
565 | 565 | // those notices can be displayed |
566 | - EE_Error::get_notices( false, true ); |
|
567 | - $this->redirectForm( $current_step ); |
|
566 | + EE_Error::get_notices(false, true); |
|
567 | + $this->redirectForm($current_step); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | |
@@ -574,13 +574,13 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepFormInterface $current_step |
576 | 576 | */ |
577 | - public function redirectForm( SequentialStepFormInterface $current_step ) { |
|
577 | + public function redirectForm(SequentialStepFormInterface $current_step) { |
|
578 | 578 | $redirect_step = $current_step; |
579 | - switch( $current_step->redirectTo() ) { |
|
579 | + switch ($current_step->redirectTo()) { |
|
580 | 580 | |
581 | 581 | case SequentialStepForm::REDIRECT_TO_OTHER : |
582 | 582 | // going somewhere else, so just check out now |
583 | - wp_safe_redirect( $redirect_step->redirectUrl() ); |
|
583 | + wp_safe_redirect($redirect_step->redirectUrl()); |
|
584 | 584 | exit(); |
585 | 585 | break; |
586 | 586 | |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | |
591 | 591 | case SequentialStepForm::REDIRECT_TO_NEXT_STEP : |
592 | 592 | $this->form_steps->next(); |
593 | - if ( $this->form_steps->valid() ) { |
|
593 | + if ($this->form_steps->valid()) { |
|
594 | 594 | $redirect_step = $this->form_steps->current(); |
595 | 595 | } |
596 | 596 | break; |
@@ -600,12 +600,12 @@ discard block |
||
600 | 600 | // $redirect_step is already set |
601 | 601 | |
602 | 602 | } |
603 | - $current_step->setRedirectUrl( $this->baseUrl() ); |
|
603 | + $current_step->setRedirectUrl($this->baseUrl()); |
|
604 | 604 | $current_step->addRedirectArgs( |
605 | 605 | // use the slug for whatever step we are redirecting too |
606 | - array( $this->formStepUrlKey() => $redirect_step->slug() ) |
|
606 | + array($this->formStepUrlKey() => $redirect_step->slug()) |
|
607 | 607 | ); |
608 | - wp_safe_redirect( $current_step->redirectUrl() ); |
|
608 | + wp_safe_redirect($current_step->redirectUrl()); |
|
609 | 609 | exit(); |
610 | 610 | } |
611 | 611 |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * Adds instructions on how to brew objects |
237 | 237 | * |
238 | 238 | * @param RecipeInterface $recipe |
239 | - * @return mixed |
|
239 | + * @return boolean |
|
240 | 240 | */ |
241 | 241 | public function addRecipe(RecipeInterface $recipe) |
242 | 242 | { |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | /** |
313 | 313 | * Adds a service to one of the internal collections |
314 | 314 | * |
315 | - * @param $identifier |
|
315 | + * @param string $identifier |
|
316 | 316 | * @param array $arguments |
317 | 317 | * @param string $type |
318 | 318 | * @return mixed |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // array for storing class aliases |
80 | 80 | $this->filters = array(); |
81 | 81 | // create collection for storing shared services |
82 | - $this->carafe = new LooseCollection( '' ); |
|
82 | + $this->carafe = new LooseCollection(''); |
|
83 | 83 | // create collection for storing recipes that tell how to build services and entities |
84 | 84 | $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
85 | 85 | // create collection for storing closures for constructing new entities |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | return; |
303 | 303 | } |
304 | 304 | $identifier = $this->processIdentifier($identifier); |
305 | - foreach ((array)$aliases as $alias) { |
|
305 | + foreach ((array) $aliases as $alias) { |
|
306 | 306 | $this->filters[$this->processIdentifier($alias)] = $identifier; |
307 | 307 | } |
308 | 308 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use OutOfBoundsException; |
14 | 14 | |
15 | 15 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -32,502 +32,502 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * This was the best coffee related name I could think of to represent class name "aliases" |
|
37 | - * So classes can be found via an alias identifier, |
|
38 | - * that is revealed when it is run through... the filters... eh? get it? |
|
39 | - * |
|
40 | - * @var array $filters |
|
41 | - */ |
|
42 | - private $filters = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * These are the classes that will actually build the objects (to order of course) |
|
46 | - * |
|
47 | - * @var array $coffee_makers |
|
48 | - */ |
|
49 | - private $coffee_makers = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * where the instantiated "singleton" objects are stored |
|
53 | - * |
|
54 | - * @var CollectionInterface $carafe |
|
55 | - */ |
|
56 | - private $carafe; |
|
57 | - |
|
58 | - /** |
|
59 | - * collection of Recipes that instruct us how to brew objects |
|
60 | - * |
|
61 | - * @var CollectionInterface $recipes |
|
62 | - */ |
|
63 | - private $recipes; |
|
64 | - |
|
65 | - /** |
|
66 | - * collection of closures for brewing objects |
|
67 | - * |
|
68 | - * @var CollectionInterface $reservoir |
|
69 | - */ |
|
70 | - private $reservoir; |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * CoffeeShop constructor |
|
76 | - */ |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - // array for storing class aliases |
|
80 | - $this->filters = array(); |
|
81 | - // create collection for storing shared services |
|
82 | - $this->carafe = new LooseCollection( '' ); |
|
83 | - // create collection for storing recipes that tell how to build services and entities |
|
84 | - $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
85 | - // create collection for storing closures for constructing new entities |
|
86 | - $this->reservoir = new Collection('Closure'); |
|
87 | - // create collection for storing the generators that build our services and entity closures |
|
88 | - $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Returns true if the container can return an entry for the given identifier. |
|
95 | - * Returns false otherwise. |
|
96 | - * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
97 | - * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
98 | - * |
|
99 | - * @param string $identifier Identifier of the entry to look for. |
|
100 | - * Typically a Fully Qualified Class Name |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function has($identifier) |
|
104 | - { |
|
105 | - $identifier = $this->filterIdentifier($identifier); |
|
106 | - return $this->carafe->has($identifier); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * finds a previously brewed (SHARED) service and returns it |
|
113 | - * |
|
114 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
115 | - * Typically a Fully Qualified Class Name |
|
116 | - * @return mixed |
|
117 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
118 | - */ |
|
119 | - public function get($identifier) |
|
120 | - { |
|
121 | - $identifier = $this->filterIdentifier($identifier); |
|
122 | - if ($this->carafe->has($identifier)) { |
|
123 | - return $this->carafe->get($identifier); |
|
124 | - } |
|
125 | - throw new ServiceNotFoundException($identifier); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * returns an instance of the requested entity type using the supplied arguments. |
|
132 | - * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
133 | - * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
134 | - * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
135 | - * then a new entity will be instantiated from the closure and returned. |
|
136 | - * If a closure does not exist, then one will be built and added to the reservoir |
|
137 | - * before instantiating the requested entity. |
|
138 | - * |
|
139 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
140 | - * Typically a Fully Qualified Class Name |
|
141 | - * @param array $arguments an array of arguments to be passed to the entity constructor |
|
142 | - * @param string $type |
|
143 | - * @return mixed |
|
144 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
145 | - */ |
|
146 | - public function brew($identifier, $arguments = array(), $type = '') |
|
147 | - { |
|
148 | - // resolve any class aliases that may exist |
|
149 | - $identifier = $this->filterIdentifier($identifier); |
|
150 | - try { |
|
151 | - // is a shared service being requested? |
|
152 | - if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
153 | - // if a shared service was requested and an instance is in the carafe, then return it |
|
154 | - return $this->get($identifier); |
|
155 | - } |
|
156 | - } catch (ServiceNotFoundException $e) { |
|
157 | - // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
158 | - // and instead, attempt to build whatever was requested |
|
159 | - } |
|
160 | - $brewed = false; |
|
161 | - // if the reservoir doesn't have a closure already for the requested identifier, |
|
162 | - // then neither a shared service nor a closure for making entities has been built yet |
|
163 | - if ( ! $this->reservoir->has($identifier)) { |
|
164 | - // so let's brew something up and add it to the proper collection |
|
165 | - $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
166 | - } |
|
167 | - // was the brewed item a callable factory function ? |
|
168 | - if (is_callable($brewed)) { |
|
169 | - // then instantiate a new entity from the cached closure |
|
170 | - $entity = $brewed($arguments); |
|
171 | - } else if ($brewed) { |
|
172 | - // requested object was a shared entity, so attempt to get it from the carafe again |
|
173 | - // because if it wasn't there before, then it should have just been brewed and added, |
|
174 | - // but if it still isn't there, then this time |
|
175 | - // the thrown ServiceNotFoundException will not be caught |
|
176 | - $entity = $this->get($identifier); |
|
177 | - } else { |
|
178 | - // if identifier is for a non-shared entity, |
|
179 | - // then either a cached closure already existed, or was just brewed |
|
180 | - $closure = $this->reservoir->get($identifier); |
|
181 | - $entity = $closure($arguments); |
|
182 | - } |
|
183 | - return $entity; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param CoffeeMakerInterface $coffee_maker |
|
190 | - * @param string $type |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
194 | - { |
|
195 | - $type = CoffeeMaker::validateType($type); |
|
196 | - return $this->coffee_makers->add($coffee_maker, $type); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $identifier |
|
203 | - * @param callable $closure |
|
204 | - * @return callable|null |
|
205 | - */ |
|
206 | - public function addClosure($identifier, $closure) |
|
207 | - { |
|
208 | - if ( ! is_callable($closure)) { |
|
209 | - throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
210 | - } |
|
211 | - $identifier = $this->processIdentifier($identifier); |
|
212 | - if ($this->reservoir->add($closure, $identifier)) { |
|
213 | - return $closure; |
|
214 | - } |
|
215 | - return null; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $identifier |
|
222 | - * @return boolean |
|
223 | - */ |
|
224 | - public function removeClosure($identifier) |
|
225 | - { |
|
226 | - $identifier = $this->processIdentifier($identifier); |
|
227 | - if ($this->reservoir->has($identifier)) { |
|
228 | - $this->reservoir->remove($this->reservoir->get($identifier)); |
|
229 | - if ( ! $this->reservoir->has($identifier)) { |
|
230 | - return true; |
|
231 | - } |
|
232 | - } |
|
233 | - return false; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
240 | - * Typically a Fully Qualified Class Name |
|
241 | - * @param mixed $service |
|
242 | - * @return bool |
|
243 | - */ |
|
244 | - public function addService($identifier, $service) |
|
245 | - { |
|
246 | - $identifier = $this->processIdentifier($identifier); |
|
247 | - $service = $this->validateService($identifier, $service); |
|
248 | - return $this->carafe->add($service, $identifier); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $identifier |
|
255 | - * @return boolean |
|
256 | - */ |
|
257 | - public function removeService($identifier) |
|
258 | - { |
|
259 | - $identifier = $this->processIdentifier($identifier); |
|
260 | - if ($this->carafe->has($identifier)) { |
|
261 | - $this->carafe->remove($this->carafe->get($identifier)); |
|
262 | - if ( ! $this->carafe->has($identifier)) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - return false; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Adds instructions on how to brew objects |
|
273 | - * |
|
274 | - * @param RecipeInterface $recipe |
|
275 | - * @return mixed |
|
276 | - */ |
|
277 | - public function addRecipe(RecipeInterface $recipe) |
|
278 | - { |
|
279 | - $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
280 | - $identifier = $this->processIdentifier($recipe->identifier()); |
|
281 | - return $this->recipes->add($recipe, $identifier); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param string $identifier The Recipe's identifier |
|
288 | - * @return boolean |
|
289 | - */ |
|
290 | - public function removeRecipe($identifier) |
|
291 | - { |
|
292 | - $identifier = $this->processIdentifier($identifier); |
|
293 | - if ($this->recipes->has($identifier)) { |
|
294 | - $this->recipes->remove( |
|
295 | - $this->recipes->get($identifier) |
|
296 | - ); |
|
297 | - if ( ! $this->recipes->has($identifier)) { |
|
298 | - return true; |
|
299 | - } |
|
300 | - } |
|
301 | - return false; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Get instructions on how to brew objects |
|
308 | - * |
|
309 | - * @param string $identifier Identifier for the entity class that the recipe applies to |
|
310 | - * Typically a Fully Qualified Class Name |
|
311 | - * @param string $type |
|
312 | - * @return RecipeInterface |
|
313 | - */ |
|
314 | - public function getRecipe($identifier, $type = '') |
|
315 | - { |
|
316 | - $identifier = $this->processIdentifier($identifier); |
|
317 | - if ($this->recipes->has($identifier)) { |
|
318 | - return $this->recipes->get($identifier); |
|
319 | - } |
|
320 | - $default_recipes = $this->getDefaultRecipes(); |
|
321 | - $matches = array(); |
|
322 | - foreach ($default_recipes as $wildcard => $default_recipe) { |
|
323 | - // is the wildcard recipe prefix in the identifier ? |
|
324 | - if (strpos($identifier, $wildcard) !== false) { |
|
325 | - // track matches and use the number of wildcard characters matched for the key |
|
326 | - $matches[strlen($wildcard)] = $default_recipe; |
|
327 | - } |
|
328 | - } |
|
329 | - if (count($matches) > 0) { |
|
330 | - // sort our recipes by the number of wildcard characters matched |
|
331 | - ksort($matches); |
|
332 | - // then grab the last recipe form the list, since it had the most matching characters |
|
333 | - $match = array_pop($matches); |
|
334 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
335 | - return $this->copyDefaultRecipe($match, $identifier, $type); |
|
336 | - } |
|
337 | - if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
338 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
339 | - return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
340 | - } |
|
341 | - throw new OutOfBoundsException( |
|
342 | - sprintf( |
|
343 | - __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
344 | - $identifier |
|
345 | - ) |
|
346 | - ); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * adds class name aliases to list of filters |
|
353 | - * |
|
354 | - * @param string $identifier Identifier for the entity class that the alias applies to |
|
355 | - * Typically a Fully Qualified Class Name |
|
356 | - * @param array|string $aliases |
|
357 | - * @return void |
|
358 | - * @throws InvalidIdentifierException |
|
359 | - */ |
|
360 | - public function addAliases($identifier, $aliases) |
|
361 | - { |
|
362 | - if (empty($aliases)) { |
|
363 | - return; |
|
364 | - } |
|
365 | - $identifier = $this->processIdentifier($identifier); |
|
366 | - foreach ((array)$aliases as $alias) { |
|
367 | - $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Adds a service to one of the internal collections |
|
375 | - * |
|
376 | - * @param $identifier |
|
377 | - * @param array $arguments |
|
378 | - * @param string $type |
|
379 | - * @return mixed |
|
380 | - * @throws ServiceExistsException |
|
381 | - */ |
|
382 | - private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
383 | - { |
|
384 | - if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
385 | - throw new ServiceExistsException($identifier); |
|
386 | - } |
|
387 | - $identifier = $this->filterIdentifier($identifier); |
|
388 | - $recipe = $this->getRecipe($identifier, $type); |
|
389 | - $type = ! empty($type) ? $type : $recipe->type(); |
|
390 | - $coffee_maker = $this->getCoffeeMaker($type); |
|
391 | - return $coffee_maker->brew($recipe, $arguments); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * filters alias identifiers to find the real class name |
|
398 | - * |
|
399 | - * @param string $identifier Identifier for the entity class that the filter applies to |
|
400 | - * Typically a Fully Qualified Class Name |
|
401 | - * @return string |
|
402 | - * @throws InvalidIdentifierException |
|
403 | - */ |
|
404 | - private function filterIdentifier($identifier) |
|
405 | - { |
|
406 | - $identifier = $this->processIdentifier($identifier); |
|
407 | - return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
408 | - ? $this->filters[$identifier] |
|
409 | - : $identifier; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * verifies and standardizes identifiers |
|
416 | - * |
|
417 | - * @param string $identifier Identifier for the entity class |
|
418 | - * Typically a Fully Qualified Class Name |
|
419 | - * @return string |
|
420 | - * @throws InvalidIdentifierException |
|
421 | - */ |
|
422 | - private function processIdentifier($identifier) |
|
423 | - { |
|
424 | - if ( ! is_string($identifier)) { |
|
425 | - throw new InvalidIdentifierException( |
|
426 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
427 | - '\Fully\Qualified\ClassName' |
|
428 | - ); |
|
429 | - } |
|
430 | - return ltrim($identifier, '\\'); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $type |
|
437 | - * @return CoffeeMakerInterface |
|
438 | - * @throws InvalidDataTypeException |
|
439 | - * @throws InvalidClassException |
|
440 | - */ |
|
441 | - private function getCoffeeMaker($type) |
|
442 | - { |
|
443 | - if ( ! $this->coffee_makers->has($type)) { |
|
444 | - throw new OutOfBoundsException( |
|
445 | - __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
446 | - ); |
|
447 | - } |
|
448 | - return $this->coffee_makers->get($type); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * Retrieves all recipes that use a wildcard "*" in their identifier |
|
455 | - * This allows recipes to be set up for handling |
|
456 | - * legacy classes that do not support PSR-4 autoloading. |
|
457 | - * for example: |
|
458 | - * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
459 | - * |
|
460 | - * @return array |
|
461 | - */ |
|
462 | - private function getDefaultRecipes() |
|
463 | - { |
|
464 | - $default_recipes = array(); |
|
465 | - $this->recipes->rewind(); |
|
466 | - while ($this->recipes->valid()) { |
|
467 | - $identifier = $this->recipes->getInfo(); |
|
468 | - // does this recipe use a wildcard ? (but is NOT the global default) |
|
469 | - if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
470 | - // strip the wildcard and use identifier as key |
|
471 | - $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
472 | - } |
|
473 | - $this->recipes->next(); |
|
474 | - } |
|
475 | - return $default_recipes; |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * clones a default recipe and then copies details |
|
482 | - * from the incoming request to it so that it can be used |
|
483 | - * |
|
484 | - * @param RecipeInterface $default_recipe |
|
485 | - * @param string $identifier |
|
486 | - * @param string $type |
|
487 | - * @return RecipeInterface |
|
488 | - */ |
|
489 | - private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
490 | - { |
|
491 | - $recipe = clone $default_recipe; |
|
492 | - if ( ! empty($type)) { |
|
493 | - $recipe->setType($type); |
|
494 | - } |
|
495 | - // is this the base default recipe ? |
|
496 | - if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
497 | - $recipe->setIdentifier($identifier); |
|
498 | - $recipe->setFqcn($identifier); |
|
499 | - return $recipe; |
|
500 | - } |
|
501 | - $recipe->setIdentifier($identifier); |
|
502 | - foreach ($default_recipe->paths() as $path) { |
|
503 | - $path = str_replace('*', $identifier, $path); |
|
504 | - if (is_readable($path)) { |
|
505 | - $recipe->setPaths($path); |
|
506 | - } |
|
507 | - } |
|
508 | - $recipe->setFqcn($identifier); |
|
509 | - return $recipe; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
516 | - * Typically a Fully Qualified Class Name |
|
517 | - * @param mixed $service |
|
518 | - * @return object |
|
519 | - * @throws InvalidServiceException |
|
520 | - */ |
|
521 | - private function validateService($identifier, $service) |
|
522 | - { |
|
523 | - if ( ! is_object($service)) { |
|
524 | - throw new InvalidServiceException( |
|
525 | - $identifier, |
|
526 | - $service |
|
527 | - ); |
|
528 | - } |
|
529 | - return $service; |
|
530 | - } |
|
35 | + /** |
|
36 | + * This was the best coffee related name I could think of to represent class name "aliases" |
|
37 | + * So classes can be found via an alias identifier, |
|
38 | + * that is revealed when it is run through... the filters... eh? get it? |
|
39 | + * |
|
40 | + * @var array $filters |
|
41 | + */ |
|
42 | + private $filters = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * These are the classes that will actually build the objects (to order of course) |
|
46 | + * |
|
47 | + * @var array $coffee_makers |
|
48 | + */ |
|
49 | + private $coffee_makers = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * where the instantiated "singleton" objects are stored |
|
53 | + * |
|
54 | + * @var CollectionInterface $carafe |
|
55 | + */ |
|
56 | + private $carafe; |
|
57 | + |
|
58 | + /** |
|
59 | + * collection of Recipes that instruct us how to brew objects |
|
60 | + * |
|
61 | + * @var CollectionInterface $recipes |
|
62 | + */ |
|
63 | + private $recipes; |
|
64 | + |
|
65 | + /** |
|
66 | + * collection of closures for brewing objects |
|
67 | + * |
|
68 | + * @var CollectionInterface $reservoir |
|
69 | + */ |
|
70 | + private $reservoir; |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * CoffeeShop constructor |
|
76 | + */ |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + // array for storing class aliases |
|
80 | + $this->filters = array(); |
|
81 | + // create collection for storing shared services |
|
82 | + $this->carafe = new LooseCollection( '' ); |
|
83 | + // create collection for storing recipes that tell how to build services and entities |
|
84 | + $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
85 | + // create collection for storing closures for constructing new entities |
|
86 | + $this->reservoir = new Collection('Closure'); |
|
87 | + // create collection for storing the generators that build our services and entity closures |
|
88 | + $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Returns true if the container can return an entry for the given identifier. |
|
95 | + * Returns false otherwise. |
|
96 | + * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
97 | + * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
98 | + * |
|
99 | + * @param string $identifier Identifier of the entry to look for. |
|
100 | + * Typically a Fully Qualified Class Name |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function has($identifier) |
|
104 | + { |
|
105 | + $identifier = $this->filterIdentifier($identifier); |
|
106 | + return $this->carafe->has($identifier); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * finds a previously brewed (SHARED) service and returns it |
|
113 | + * |
|
114 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
115 | + * Typically a Fully Qualified Class Name |
|
116 | + * @return mixed |
|
117 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
118 | + */ |
|
119 | + public function get($identifier) |
|
120 | + { |
|
121 | + $identifier = $this->filterIdentifier($identifier); |
|
122 | + if ($this->carafe->has($identifier)) { |
|
123 | + return $this->carafe->get($identifier); |
|
124 | + } |
|
125 | + throw new ServiceNotFoundException($identifier); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * returns an instance of the requested entity type using the supplied arguments. |
|
132 | + * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
133 | + * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
134 | + * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
135 | + * then a new entity will be instantiated from the closure and returned. |
|
136 | + * If a closure does not exist, then one will be built and added to the reservoir |
|
137 | + * before instantiating the requested entity. |
|
138 | + * |
|
139 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
140 | + * Typically a Fully Qualified Class Name |
|
141 | + * @param array $arguments an array of arguments to be passed to the entity constructor |
|
142 | + * @param string $type |
|
143 | + * @return mixed |
|
144 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
145 | + */ |
|
146 | + public function brew($identifier, $arguments = array(), $type = '') |
|
147 | + { |
|
148 | + // resolve any class aliases that may exist |
|
149 | + $identifier = $this->filterIdentifier($identifier); |
|
150 | + try { |
|
151 | + // is a shared service being requested? |
|
152 | + if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
153 | + // if a shared service was requested and an instance is in the carafe, then return it |
|
154 | + return $this->get($identifier); |
|
155 | + } |
|
156 | + } catch (ServiceNotFoundException $e) { |
|
157 | + // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
158 | + // and instead, attempt to build whatever was requested |
|
159 | + } |
|
160 | + $brewed = false; |
|
161 | + // if the reservoir doesn't have a closure already for the requested identifier, |
|
162 | + // then neither a shared service nor a closure for making entities has been built yet |
|
163 | + if ( ! $this->reservoir->has($identifier)) { |
|
164 | + // so let's brew something up and add it to the proper collection |
|
165 | + $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
166 | + } |
|
167 | + // was the brewed item a callable factory function ? |
|
168 | + if (is_callable($brewed)) { |
|
169 | + // then instantiate a new entity from the cached closure |
|
170 | + $entity = $brewed($arguments); |
|
171 | + } else if ($brewed) { |
|
172 | + // requested object was a shared entity, so attempt to get it from the carafe again |
|
173 | + // because if it wasn't there before, then it should have just been brewed and added, |
|
174 | + // but if it still isn't there, then this time |
|
175 | + // the thrown ServiceNotFoundException will not be caught |
|
176 | + $entity = $this->get($identifier); |
|
177 | + } else { |
|
178 | + // if identifier is for a non-shared entity, |
|
179 | + // then either a cached closure already existed, or was just brewed |
|
180 | + $closure = $this->reservoir->get($identifier); |
|
181 | + $entity = $closure($arguments); |
|
182 | + } |
|
183 | + return $entity; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param CoffeeMakerInterface $coffee_maker |
|
190 | + * @param string $type |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
194 | + { |
|
195 | + $type = CoffeeMaker::validateType($type); |
|
196 | + return $this->coffee_makers->add($coffee_maker, $type); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $identifier |
|
203 | + * @param callable $closure |
|
204 | + * @return callable|null |
|
205 | + */ |
|
206 | + public function addClosure($identifier, $closure) |
|
207 | + { |
|
208 | + if ( ! is_callable($closure)) { |
|
209 | + throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
210 | + } |
|
211 | + $identifier = $this->processIdentifier($identifier); |
|
212 | + if ($this->reservoir->add($closure, $identifier)) { |
|
213 | + return $closure; |
|
214 | + } |
|
215 | + return null; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $identifier |
|
222 | + * @return boolean |
|
223 | + */ |
|
224 | + public function removeClosure($identifier) |
|
225 | + { |
|
226 | + $identifier = $this->processIdentifier($identifier); |
|
227 | + if ($this->reservoir->has($identifier)) { |
|
228 | + $this->reservoir->remove($this->reservoir->get($identifier)); |
|
229 | + if ( ! $this->reservoir->has($identifier)) { |
|
230 | + return true; |
|
231 | + } |
|
232 | + } |
|
233 | + return false; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
240 | + * Typically a Fully Qualified Class Name |
|
241 | + * @param mixed $service |
|
242 | + * @return bool |
|
243 | + */ |
|
244 | + public function addService($identifier, $service) |
|
245 | + { |
|
246 | + $identifier = $this->processIdentifier($identifier); |
|
247 | + $service = $this->validateService($identifier, $service); |
|
248 | + return $this->carafe->add($service, $identifier); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $identifier |
|
255 | + * @return boolean |
|
256 | + */ |
|
257 | + public function removeService($identifier) |
|
258 | + { |
|
259 | + $identifier = $this->processIdentifier($identifier); |
|
260 | + if ($this->carafe->has($identifier)) { |
|
261 | + $this->carafe->remove($this->carafe->get($identifier)); |
|
262 | + if ( ! $this->carafe->has($identifier)) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + return false; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Adds instructions on how to brew objects |
|
273 | + * |
|
274 | + * @param RecipeInterface $recipe |
|
275 | + * @return mixed |
|
276 | + */ |
|
277 | + public function addRecipe(RecipeInterface $recipe) |
|
278 | + { |
|
279 | + $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
280 | + $identifier = $this->processIdentifier($recipe->identifier()); |
|
281 | + return $this->recipes->add($recipe, $identifier); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param string $identifier The Recipe's identifier |
|
288 | + * @return boolean |
|
289 | + */ |
|
290 | + public function removeRecipe($identifier) |
|
291 | + { |
|
292 | + $identifier = $this->processIdentifier($identifier); |
|
293 | + if ($this->recipes->has($identifier)) { |
|
294 | + $this->recipes->remove( |
|
295 | + $this->recipes->get($identifier) |
|
296 | + ); |
|
297 | + if ( ! $this->recipes->has($identifier)) { |
|
298 | + return true; |
|
299 | + } |
|
300 | + } |
|
301 | + return false; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Get instructions on how to brew objects |
|
308 | + * |
|
309 | + * @param string $identifier Identifier for the entity class that the recipe applies to |
|
310 | + * Typically a Fully Qualified Class Name |
|
311 | + * @param string $type |
|
312 | + * @return RecipeInterface |
|
313 | + */ |
|
314 | + public function getRecipe($identifier, $type = '') |
|
315 | + { |
|
316 | + $identifier = $this->processIdentifier($identifier); |
|
317 | + if ($this->recipes->has($identifier)) { |
|
318 | + return $this->recipes->get($identifier); |
|
319 | + } |
|
320 | + $default_recipes = $this->getDefaultRecipes(); |
|
321 | + $matches = array(); |
|
322 | + foreach ($default_recipes as $wildcard => $default_recipe) { |
|
323 | + // is the wildcard recipe prefix in the identifier ? |
|
324 | + if (strpos($identifier, $wildcard) !== false) { |
|
325 | + // track matches and use the number of wildcard characters matched for the key |
|
326 | + $matches[strlen($wildcard)] = $default_recipe; |
|
327 | + } |
|
328 | + } |
|
329 | + if (count($matches) > 0) { |
|
330 | + // sort our recipes by the number of wildcard characters matched |
|
331 | + ksort($matches); |
|
332 | + // then grab the last recipe form the list, since it had the most matching characters |
|
333 | + $match = array_pop($matches); |
|
334 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
335 | + return $this->copyDefaultRecipe($match, $identifier, $type); |
|
336 | + } |
|
337 | + if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
338 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
339 | + return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
340 | + } |
|
341 | + throw new OutOfBoundsException( |
|
342 | + sprintf( |
|
343 | + __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
344 | + $identifier |
|
345 | + ) |
|
346 | + ); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * adds class name aliases to list of filters |
|
353 | + * |
|
354 | + * @param string $identifier Identifier for the entity class that the alias applies to |
|
355 | + * Typically a Fully Qualified Class Name |
|
356 | + * @param array|string $aliases |
|
357 | + * @return void |
|
358 | + * @throws InvalidIdentifierException |
|
359 | + */ |
|
360 | + public function addAliases($identifier, $aliases) |
|
361 | + { |
|
362 | + if (empty($aliases)) { |
|
363 | + return; |
|
364 | + } |
|
365 | + $identifier = $this->processIdentifier($identifier); |
|
366 | + foreach ((array)$aliases as $alias) { |
|
367 | + $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Adds a service to one of the internal collections |
|
375 | + * |
|
376 | + * @param $identifier |
|
377 | + * @param array $arguments |
|
378 | + * @param string $type |
|
379 | + * @return mixed |
|
380 | + * @throws ServiceExistsException |
|
381 | + */ |
|
382 | + private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
383 | + { |
|
384 | + if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
385 | + throw new ServiceExistsException($identifier); |
|
386 | + } |
|
387 | + $identifier = $this->filterIdentifier($identifier); |
|
388 | + $recipe = $this->getRecipe($identifier, $type); |
|
389 | + $type = ! empty($type) ? $type : $recipe->type(); |
|
390 | + $coffee_maker = $this->getCoffeeMaker($type); |
|
391 | + return $coffee_maker->brew($recipe, $arguments); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * filters alias identifiers to find the real class name |
|
398 | + * |
|
399 | + * @param string $identifier Identifier for the entity class that the filter applies to |
|
400 | + * Typically a Fully Qualified Class Name |
|
401 | + * @return string |
|
402 | + * @throws InvalidIdentifierException |
|
403 | + */ |
|
404 | + private function filterIdentifier($identifier) |
|
405 | + { |
|
406 | + $identifier = $this->processIdentifier($identifier); |
|
407 | + return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
408 | + ? $this->filters[$identifier] |
|
409 | + : $identifier; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * verifies and standardizes identifiers |
|
416 | + * |
|
417 | + * @param string $identifier Identifier for the entity class |
|
418 | + * Typically a Fully Qualified Class Name |
|
419 | + * @return string |
|
420 | + * @throws InvalidIdentifierException |
|
421 | + */ |
|
422 | + private function processIdentifier($identifier) |
|
423 | + { |
|
424 | + if ( ! is_string($identifier)) { |
|
425 | + throw new InvalidIdentifierException( |
|
426 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
427 | + '\Fully\Qualified\ClassName' |
|
428 | + ); |
|
429 | + } |
|
430 | + return ltrim($identifier, '\\'); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $type |
|
437 | + * @return CoffeeMakerInterface |
|
438 | + * @throws InvalidDataTypeException |
|
439 | + * @throws InvalidClassException |
|
440 | + */ |
|
441 | + private function getCoffeeMaker($type) |
|
442 | + { |
|
443 | + if ( ! $this->coffee_makers->has($type)) { |
|
444 | + throw new OutOfBoundsException( |
|
445 | + __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
446 | + ); |
|
447 | + } |
|
448 | + return $this->coffee_makers->get($type); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * Retrieves all recipes that use a wildcard "*" in their identifier |
|
455 | + * This allows recipes to be set up for handling |
|
456 | + * legacy classes that do not support PSR-4 autoloading. |
|
457 | + * for example: |
|
458 | + * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
459 | + * |
|
460 | + * @return array |
|
461 | + */ |
|
462 | + private function getDefaultRecipes() |
|
463 | + { |
|
464 | + $default_recipes = array(); |
|
465 | + $this->recipes->rewind(); |
|
466 | + while ($this->recipes->valid()) { |
|
467 | + $identifier = $this->recipes->getInfo(); |
|
468 | + // does this recipe use a wildcard ? (but is NOT the global default) |
|
469 | + if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
470 | + // strip the wildcard and use identifier as key |
|
471 | + $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
472 | + } |
|
473 | + $this->recipes->next(); |
|
474 | + } |
|
475 | + return $default_recipes; |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * clones a default recipe and then copies details |
|
482 | + * from the incoming request to it so that it can be used |
|
483 | + * |
|
484 | + * @param RecipeInterface $default_recipe |
|
485 | + * @param string $identifier |
|
486 | + * @param string $type |
|
487 | + * @return RecipeInterface |
|
488 | + */ |
|
489 | + private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
490 | + { |
|
491 | + $recipe = clone $default_recipe; |
|
492 | + if ( ! empty($type)) { |
|
493 | + $recipe->setType($type); |
|
494 | + } |
|
495 | + // is this the base default recipe ? |
|
496 | + if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
497 | + $recipe->setIdentifier($identifier); |
|
498 | + $recipe->setFqcn($identifier); |
|
499 | + return $recipe; |
|
500 | + } |
|
501 | + $recipe->setIdentifier($identifier); |
|
502 | + foreach ($default_recipe->paths() as $path) { |
|
503 | + $path = str_replace('*', $identifier, $path); |
|
504 | + if (is_readable($path)) { |
|
505 | + $recipe->setPaths($path); |
|
506 | + } |
|
507 | + } |
|
508 | + $recipe->setFqcn($identifier); |
|
509 | + return $recipe; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
516 | + * Typically a Fully Qualified Class Name |
|
517 | + * @param mixed $service |
|
518 | + * @return object |
|
519 | + * @throws InvalidServiceException |
|
520 | + */ |
|
521 | + private function validateService($identifier, $service) |
|
522 | + { |
|
523 | + if ( ! is_object($service)) { |
|
524 | + throw new InvalidServiceException( |
|
525 | + $identifier, |
|
526 | + $service |
|
527 | + ); |
|
528 | + } |
|
529 | + return $service; |
|
530 | + } |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | // End of file CoffeeShop.php |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\services\container\exceptions; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -18,28 +18,28 @@ discard block |
||
18 | 18 | class ServiceNotFoundException extends \RuntimeException |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * ServiceNotFoundException constructor |
|
23 | - * |
|
24 | - * @param string $service_name the name of the requested service |
|
25 | - * @param string $message |
|
26 | - * @param int $code |
|
27 | - * @param \Exception $previous |
|
28 | - */ |
|
29 | - public function __construct( |
|
30 | - $service_name, |
|
31 | - $message = '', |
|
32 | - $code = 0, |
|
33 | - \Exception $previous = null |
|
34 | - ) { |
|
35 | - if (empty($message)) { |
|
36 | - $message = sprintf( |
|
37 | - __('The requested service "%1$s" could not found be found in the CoffeeShop.', 'event_espresso'), |
|
38 | - $service_name |
|
39 | - ); |
|
40 | - } |
|
41 | - parent::__construct($message, $code, $previous); |
|
42 | - } |
|
21 | + /** |
|
22 | + * ServiceNotFoundException constructor |
|
23 | + * |
|
24 | + * @param string $service_name the name of the requested service |
|
25 | + * @param string $message |
|
26 | + * @param int $code |
|
27 | + * @param \Exception $previous |
|
28 | + */ |
|
29 | + public function __construct( |
|
30 | + $service_name, |
|
31 | + $message = '', |
|
32 | + $code = 0, |
|
33 | + \Exception $previous = null |
|
34 | + ) { |
|
35 | + if (empty($message)) { |
|
36 | + $message = sprintf( |
|
37 | + __('The requested service "%1$s" could not found be found in the CoffeeShop.', 'event_espresso'), |
|
38 | + $service_name |
|
39 | + ); |
|
40 | + } |
|
41 | + parent::__construct($message, $code, $previous); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | // End of file ServiceNotFoundException.php |
45 | 45 | // Location: /ServiceNotFoundException.php |
46 | 46 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\services\container\exceptions; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * ServiceExistsException constructor |
|
24 | - * |
|
25 | - * @param string $service_name the name of the requested service |
|
26 | - * @param string $message |
|
27 | - * @param int $code |
|
28 | - * @param \Exception $previous |
|
29 | - */ |
|
30 | - public function __construct( |
|
31 | - $service_name, |
|
32 | - $message = '', |
|
33 | - $code = 0, |
|
34 | - \Exception $previous = null |
|
35 | - ) { |
|
36 | - if (empty($message)) { |
|
37 | - $message = sprintf( |
|
38 | - __('The "%1$s" service already exists in the CoffeeShop and can not be added again.', 'event_espresso'), |
|
39 | - $service_name |
|
40 | - ); |
|
41 | - } |
|
42 | - parent::__construct($message, $code, $previous); |
|
43 | - } |
|
22 | + /** |
|
23 | + * ServiceExistsException constructor |
|
24 | + * |
|
25 | + * @param string $service_name the name of the requested service |
|
26 | + * @param string $message |
|
27 | + * @param int $code |
|
28 | + * @param \Exception $previous |
|
29 | + */ |
|
30 | + public function __construct( |
|
31 | + $service_name, |
|
32 | + $message = '', |
|
33 | + $code = 0, |
|
34 | + \Exception $previous = null |
|
35 | + ) { |
|
36 | + if (empty($message)) { |
|
37 | + $message = sprintf( |
|
38 | + __('The "%1$s" service already exists in the CoffeeShop and can not be added again.', 'event_espresso'), |
|
39 | + $service_name |
|
40 | + ); |
|
41 | + } |
|
42 | + parent::__construct($message, $code, $previous); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\services\container\exceptions; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -18,29 +18,29 @@ discard block |
||
18 | 18 | class InvalidServiceException extends \UnexpectedValueException |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * InvalidServiceException constructor. |
|
23 | - * |
|
24 | - * @param string $service_name the name of the requested service |
|
25 | - * @param string $actual classname of what we got |
|
26 | - * @param string $message |
|
27 | - * @param int $code |
|
28 | - * @param \Exception $previous |
|
29 | - */ |
|
30 | - public function __construct($service_name, $actual, $message = '', $code = 0, \Exception $previous = null) |
|
31 | - { |
|
32 | - if (empty($message)) { |
|
33 | - $message = sprintf( |
|
34 | - __( |
|
35 | - 'The "%1$s" service could not be retrieved from the CoffeeShop, but "%2$s" was received.', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - $service_name, |
|
39 | - print_r($actual, true) |
|
40 | - ); |
|
41 | - } |
|
42 | - parent::__construct($message, $code, $previous); |
|
43 | - } |
|
21 | + /** |
|
22 | + * InvalidServiceException constructor. |
|
23 | + * |
|
24 | + * @param string $service_name the name of the requested service |
|
25 | + * @param string $actual classname of what we got |
|
26 | + * @param string $message |
|
27 | + * @param int $code |
|
28 | + * @param \Exception $previous |
|
29 | + */ |
|
30 | + public function __construct($service_name, $actual, $message = '', $code = 0, \Exception $previous = null) |
|
31 | + { |
|
32 | + if (empty($message)) { |
|
33 | + $message = sprintf( |
|
34 | + __( |
|
35 | + 'The "%1$s" service could not be retrieved from the CoffeeShop, but "%2$s" was received.', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + $service_name, |
|
39 | + print_r($actual, true) |
|
40 | + ); |
|
41 | + } |
|
42 | + parent::__construct($message, $code, $previous); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | // End of file InvalidServiceException.php |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <div class="padding"> |
2 | 2 | <p> |
3 | - <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf( esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>' ); ?> |
|
3 | + <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf(esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>'); ?> |
|
4 | 4 | </p> |
5 | 5 | <ul> |
6 | 6 | <li><strong><?php esc_html_e('Show a list of all of your events', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS]</li> |
7 | 7 | <li><strong><?php esc_html_e('Set a custom title for the event list', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS title="My Super Event List"]</li> |
8 | 8 | <li><strong><?php esc_html_e('Limit (paginate) the number of events that are shown in the event list on a page or post', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS limit=5]</li> |
9 | 9 | <li><strong><?php esc_html_e('Add a custom CSS class to each event post/article', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS css_class=my-custom-class]</li> |
10 | - <li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date( 'F Y' ); ?>"]</li> |
|
10 | + <li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date('F Y'); ?>"]</li> |
|
11 | 11 | <li><strong><?php esc_html_e('Show expired events in the event list', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS show_expired=true]</li> |
12 | 12 | <li><strong><?php esc_html_e('Sorts the event list in ascending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=ASC]</li> |
13 | 13 | <li><strong><?php esc_html_e('Sorts the event list in descending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=DESC]</li> |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <div class="padding"> |
2 | 2 | <?php |
3 | 3 | //we'll only show site-license keys if this is main_site() (which works for both multi-site and single-site wp installations) |
4 | - if ( is_main_site() ) { ?> |
|
4 | + if (is_main_site()) { ?> |
|
5 | 5 | <h2 class="ee-admin-settings-hdr" style="width:300px;"> |
6 | 6 | <?php _e('Your Event Espresso License Key', 'event_espresso'); ?> |
7 | 7 | </h2> |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | <tr <?php echo isset($_REQUEST['license_key']) && $_REQUEST['license_key'] == true ? 'class="yellow_alert"' : '' ?>> |
12 | 12 | <th> |
13 | 13 | <label for="site_license_key"> |
14 | - <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info');?> |
|
14 | + <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info'); ?> |
|
15 | 15 | </label> |
16 | 16 | </th> |
17 | 17 | <td> |
18 | 18 | <input name="site_license_key" id="site_license_key" size="10" class="regular-text" type="text" value="<?php echo $site_license_key; ?>" /><?php echo $site_license_key_verified; ?><br/> |
19 | 19 | <p class="description"> |
20 | - <?php printf( __('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>' ); ?> |
|
20 | + <?php printf(__('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>'); ?> |
|
21 | 21 | </p> |
22 | 22 | </td> |
23 | 23 | </tr> |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | <h2 id="contact_info_h4" class="ee-admin-settings-hdr"> |
33 | - <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info');?> |
|
33 | + <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info'); ?> |
|
34 | 34 | </h2> |
35 | 35 | |
36 | 36 | <table class="form-table"> |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | <input id="organization_city" class="regular-text" type="text" name="organization_city" value="<?php echo $organization_city; ?>" /> |
79 | 79 | </td> |
80 | 80 | </tr> |
81 | - <?php echo EEH_Form_Fields::generate_form_input( $states ); ?> |
|
82 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
81 | + <?php echo EEH_Form_Fields::generate_form_input($states); ?> |
|
82 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
83 | 83 | <tr> |
84 | 84 | <th> |
85 | 85 | <label for="organization_zip"> |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | <td> |
100 | 100 | <input class="regular-text" type="text" name="organization_email" value="<?php echo $organization_email; ?>" /> |
101 | 101 | <p class="description"> |
102 | - <?php echo sprintf( esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>' ); ?> |
|
102 | + <?php echo sprintf(esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>'); ?> |
|
103 | 103 | </p> |
104 | 104 | </td> |
105 | 105 | </tr> |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | </table> |
134 | 134 | |
135 | 135 | <h2 class="ee-admin-settings-hdr"> |
136 | - <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info');?> |
|
136 | + <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info'); ?> |
|
137 | 137 | </h2> |
138 | 138 | |
139 | 139 | <table class="form-table"> |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | </th> |
162 | 162 | <td> |
163 | 163 | <?php |
164 | - if ( $organization_logo_url ) { |
|
164 | + if ($organization_logo_url) { |
|
165 | 165 | ?> |
166 | 166 | <p id="default-logo-thumb"> |
167 | 167 | <img id="current-image-thumb" src="<?php echo $organization_logo_url ?>" alt="" /><br /> |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | <br/><br/> |
180 | 180 | |
181 | 181 | <h2 class="ee-admin-settings-hdr"> |
182 | - <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info');?> |
|
182 | + <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info'); ?> |
|
183 | 183 | </h2> |
184 | 184 | <p class="description"><?php _e('Enter any links to social accounts for your organization here', 'event_espresso'); ?></p> |
185 | 185 | |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | <br/><br/> |
257 | 257 | |
258 | 258 | |
259 | - <?php if ( is_main_site() ) : ?> |
|
259 | + <?php if (is_main_site()) : ?> |
|
260 | 260 | <p> |
261 | - <?php echo EE_PUE::espresso_data_collection_optin_text( FALSE ); ?> |
|
261 | + <?php echo EE_PUE::espresso_data_collection_optin_text(FALSE); ?> |
|
262 | 262 | </p> |
263 | 263 | |
264 | 264 | <table class="form-table"> |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | </th> |
273 | 273 | <td> |
274 | 274 | <?php |
275 | - $values=array( |
|
276 | - array('id'=>'yes','text'=> __('Yes! I want to help improve Event Espresso!','event_espresso')), |
|
277 | - array('id'=>'no','text'=> __('Not at this time. Maybe later.','event_espresso')) |
|
275 | + $values = array( |
|
276 | + array('id'=>'yes', 'text'=> __('Yes! I want to help improve Event Espresso!', 'event_espresso')), |
|
277 | + array('id'=>'no', 'text'=> __('Not at this time. Maybe later.', 'event_espresso')) |
|
278 | 278 | ); |
279 | - echo EEH_Form_Fields::select_input('ueip_optin', $values, !empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
279 | + echo EEH_Form_Fields::select_input('ueip_optin', $values, ! empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
280 | 280 | ?> |
281 | 281 | </td> |
282 | 282 | </tr> |
@@ -51,7 +51,7 @@ |
||
51 | 51 | </table> |
52 | 52 | <div class="ee-editor-footer-container"> |
53 | 53 | <div class="ee-editor-id-container"> |
54 | - <span class="ee-item-id"><?php echo $DTT_ID ? sprintf( esc_html__( 'Datetime ID: %d', 'event_espresso' ), $DTT_ID ) : ''; ?></span> |
|
54 | + <span class="ee-item-id"><?php echo $DTT_ID ? sprintf(esc_html__('Datetime ID: %d', 'event_espresso'), $DTT_ID) : ''; ?></span> |
|
55 | 55 | </div> |
56 | 56 | <div class="save-cancel-button-container"> |
57 | 57 | <button data-context="short-ticket" data-datetime-row="<?php echo $dtt_row; ?>" class="button-primary ee-create-button"> |
@@ -1,1 +1,1 @@ |
||
1 | -<?php printf( esc_html__('Authorize.Net AIM is an on-site payment method for accepting credit and debit card payments and is available to event organizers in the United States, Canada, United Kingdom, and Australia. An account with Authorize.Net is required to accept payments. Need an Authorize.Net account? %1$sClick here to sign up for a merchant account%2$s.', 'event_espresso'), '<a href="https://eventespresso.com/go/authorizenetaim/" target="_blank">','</a>' ); |
|
2 | 1 | \ No newline at end of file |
2 | +<?php printf(esc_html__('Authorize.Net AIM is an on-site payment method for accepting credit and debit card payments and is available to event organizers in the United States, Canada, United Kingdom, and Australia. An account with Authorize.Net is required to accept payments. Need an Authorize.Net account? %1$sClick here to sign up for a merchant account%2$s.', 'event_espresso'), '<a href="https://eventespresso.com/go/authorizenetaim/" target="_blank">', '</a>'); |
|
3 | 3 | \ No newline at end of file |