@@ -91,7 +91,7 @@ |
||
| 91 | 91 | public function __construct($slug, $description) |
| 92 | 92 | { |
| 93 | 93 | parent::__construct($slug, $description); |
| 94 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 94 | + if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 95 | 95 | throw new InvalidArgumentException( |
| 96 | 96 | sprintf( |
| 97 | 97 | esc_html__( |
@@ -20,139 +20,139 @@ |
||
| 20 | 20 | class RequestTypeContext extends Context |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * indicates that the current request involves some form of activation |
|
| 25 | - */ |
|
| 26 | - const ACTIVATION = 'activation-request'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
| 30 | - */ |
|
| 31 | - const ADMIN = 'non-ajax-admin-request'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
| 35 | - */ |
|
| 36 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
| 40 | - */ |
|
| 41 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
| 45 | - */ |
|
| 46 | - const AJAX_OTHER = 'other-ajax-request'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * indicates that the current request is for the EE REST API |
|
| 50 | - */ |
|
| 51 | - const API = 'rest-api'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * indicates that the current request is from the command line |
|
| 55 | - */ |
|
| 56 | - const CLI = 'command-line'; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * indicates that the current request is for a WP_Cron |
|
| 60 | - */ |
|
| 61 | - const CRON = 'wp-cron'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * indicates that the current request is for a feed (ie: RSS) |
|
| 65 | - */ |
|
| 66 | - const FEED = 'feed-request'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
| 70 | - */ |
|
| 71 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
| 75 | - */ |
|
| 76 | - const IFRAME = 'iframe-request'; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var boolean $is_activation |
|
| 80 | - */ |
|
| 81 | - private $is_activation = false; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var array $valid_request_types |
|
| 85 | - */ |
|
| 86 | - private $valid_request_types = array(); |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * RequestTypeContext constructor. |
|
| 91 | - * |
|
| 92 | - * @param string $slug |
|
| 93 | - * @param string $description |
|
| 94 | - * @throws InvalidArgumentException |
|
| 95 | - */ |
|
| 96 | - public function __construct($slug, $description) |
|
| 97 | - { |
|
| 98 | - parent::__construct($slug, $description); |
|
| 99 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 100 | - throw new InvalidArgumentException( |
|
| 101 | - sprintf( |
|
| 102 | - esc_html__( |
|
| 103 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 104 | - 'event_espresso' |
|
| 105 | - ), |
|
| 106 | - var_export($this->validRequestTypes(), true) |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return array |
|
| 115 | - */ |
|
| 116 | - public function validRequestTypes() |
|
| 117 | - { |
|
| 118 | - if (empty($this->valid_request_types)) { |
|
| 119 | - $this->valid_request_types = apply_filters( |
|
| 120 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 121 | - array( |
|
| 122 | - RequestTypeContext::ACTIVATION, |
|
| 123 | - RequestTypeContext::ADMIN, |
|
| 124 | - RequestTypeContext::AJAX_ADMIN, |
|
| 125 | - RequestTypeContext::AJAX_FRONT, |
|
| 126 | - RequestTypeContext::AJAX_OTHER, |
|
| 127 | - RequestTypeContext::API, |
|
| 128 | - RequestTypeContext::CLI, |
|
| 129 | - RequestTypeContext::CRON, |
|
| 130 | - RequestTypeContext::FEED, |
|
| 131 | - RequestTypeContext::FRONTEND, |
|
| 132 | - RequestTypeContext::IFRAME, |
|
| 133 | - ) |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - return $this->valid_request_types; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - public function isActivation() |
|
| 144 | - { |
|
| 145 | - return $this->is_activation; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param bool $is_activation |
|
| 151 | - */ |
|
| 152 | - public function setIsActivation($is_activation) |
|
| 153 | - { |
|
| 154 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 155 | - } |
|
| 23 | + /** |
|
| 24 | + * indicates that the current request involves some form of activation |
|
| 25 | + */ |
|
| 26 | + const ACTIVATION = 'activation-request'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
| 30 | + */ |
|
| 31 | + const ADMIN = 'non-ajax-admin-request'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
| 35 | + */ |
|
| 36 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
| 40 | + */ |
|
| 41 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
| 45 | + */ |
|
| 46 | + const AJAX_OTHER = 'other-ajax-request'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * indicates that the current request is for the EE REST API |
|
| 50 | + */ |
|
| 51 | + const API = 'rest-api'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * indicates that the current request is from the command line |
|
| 55 | + */ |
|
| 56 | + const CLI = 'command-line'; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * indicates that the current request is for a WP_Cron |
|
| 60 | + */ |
|
| 61 | + const CRON = 'wp-cron'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * indicates that the current request is for a feed (ie: RSS) |
|
| 65 | + */ |
|
| 66 | + const FEED = 'feed-request'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
| 70 | + */ |
|
| 71 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
| 75 | + */ |
|
| 76 | + const IFRAME = 'iframe-request'; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var boolean $is_activation |
|
| 80 | + */ |
|
| 81 | + private $is_activation = false; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var array $valid_request_types |
|
| 85 | + */ |
|
| 86 | + private $valid_request_types = array(); |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * RequestTypeContext constructor. |
|
| 91 | + * |
|
| 92 | + * @param string $slug |
|
| 93 | + * @param string $description |
|
| 94 | + * @throws InvalidArgumentException |
|
| 95 | + */ |
|
| 96 | + public function __construct($slug, $description) |
|
| 97 | + { |
|
| 98 | + parent::__construct($slug, $description); |
|
| 99 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 100 | + throw new InvalidArgumentException( |
|
| 101 | + sprintf( |
|
| 102 | + esc_html__( |
|
| 103 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 104 | + 'event_espresso' |
|
| 105 | + ), |
|
| 106 | + var_export($this->validRequestTypes(), true) |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return array |
|
| 115 | + */ |
|
| 116 | + public function validRequestTypes() |
|
| 117 | + { |
|
| 118 | + if (empty($this->valid_request_types)) { |
|
| 119 | + $this->valid_request_types = apply_filters( |
|
| 120 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 121 | + array( |
|
| 122 | + RequestTypeContext::ACTIVATION, |
|
| 123 | + RequestTypeContext::ADMIN, |
|
| 124 | + RequestTypeContext::AJAX_ADMIN, |
|
| 125 | + RequestTypeContext::AJAX_FRONT, |
|
| 126 | + RequestTypeContext::AJAX_OTHER, |
|
| 127 | + RequestTypeContext::API, |
|
| 128 | + RequestTypeContext::CLI, |
|
| 129 | + RequestTypeContext::CRON, |
|
| 130 | + RequestTypeContext::FEED, |
|
| 131 | + RequestTypeContext::FRONTEND, |
|
| 132 | + RequestTypeContext::IFRAME, |
|
| 133 | + ) |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + return $this->valid_request_types; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + public function isActivation() |
|
| 144 | + { |
|
| 145 | + return $this->is_activation; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param bool $is_activation |
|
| 151 | + */ |
|
| 152 | + public function setIsActivation($is_activation) |
|
| 153 | + { |
|
| 154 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | |
@@ -16,18 +16,18 @@ |
||
| 16 | 16 | class Domain extends DomainBase |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * URL path component used to denote an API request |
|
| 21 | - */ |
|
| 22 | - const API_NAMESPACE = 'ee/v'; |
|
| 19 | + /** |
|
| 20 | + * URL path component used to denote an API request |
|
| 21 | + */ |
|
| 22 | + const API_NAMESPACE = 'ee/v'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
| 26 | - * Page ui. |
|
| 27 | - */ |
|
| 28 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
| 29 | - = 'manual_registration_status_change_from_registration_admin'; |
|
| 24 | + /** |
|
| 25 | + * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
| 26 | + * Page ui. |
|
| 27 | + */ |
|
| 28 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
| 29 | + = 'manual_registration_status_change_from_registration_admin'; |
|
| 30 | 30 | |
| 31 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 32 | - = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
| 31 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 32 | + = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
| 33 | 33 | } |
@@ -31,20 +31,20 @@ |
||
| 31 | 31 | * @return \EventEspresso\core\Psr4Autoloader |
| 32 | 32 | */ |
| 33 | 33 | public function initializeAutoloader() { |
| 34 | - static $initialized = false; |
|
| 35 | - if ( ! $initialized) { |
|
| 36 | - // instantiate PSR4 autoloader |
|
| 34 | + static $initialized = false; |
|
| 35 | + if ( ! $initialized) { |
|
| 36 | + // instantiate PSR4 autoloader |
|
| 37 | 37 | espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' ); |
| 38 | - EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
|
| 39 | - // register the autoloader |
|
| 40 | - EE_Psr4AutoloaderInit::$psr4_loader->register(); |
|
| 41 | - // register the base directories for the namespace prefix |
|
| 42 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
| 43 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 44 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
|
| 45 | - $initialized = true; |
|
| 46 | - } |
|
| 47 | - } |
|
| 38 | + EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
|
| 39 | + // register the autoloader |
|
| 40 | + EE_Psr4AutoloaderInit::$psr4_loader->register(); |
|
| 41 | + // register the base directories for the namespace prefix |
|
| 42 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
| 43 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 44 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
|
| 45 | + $initialized = true; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
@@ -34,13 +34,13 @@ |
||
| 34 | 34 | static $initialized = false; |
| 35 | 35 | if ( ! $initialized) { |
| 36 | 36 | // instantiate PSR4 autoloader |
| 37 | - espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' ); |
|
| 37 | + espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php'); |
|
| 38 | 38 | EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
| 39 | 39 | // register the autoloader |
| 40 | 40 | EE_Psr4AutoloaderInit::$psr4_loader->register(); |
| 41 | 41 | // register the base directories for the namespace prefix |
| 42 | 42 | EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
| 43 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 43 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch'); |
|
| 44 | 44 | EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
| 45 | 45 | $initialized = true; |
| 46 | 46 | } |
@@ -182,7 +182,7 @@ |
||
| 182 | 182 | is_string($param_name) && isset($ingredients[$param_name]) |
| 183 | 183 | ) { |
| 184 | 184 | // attempt to inject the dependency |
| 185 | - $resolved_parameters[$index] = $ingredients[ $param_name ]; |
|
| 185 | + $resolved_parameters[$index] = $ingredients[$param_name]; |
|
| 186 | 186 | } else if ( |
| 187 | 187 | // param is specified in the list of ingredients for this Recipe |
| 188 | 188 | isset($ingredients[$param_class]) |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use UnexpectedValueException; |
| 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 | |
@@ -26,225 +26,225 @@ discard block |
||
| 26 | 26 | class DependencyInjector implements InjectorInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var CoffeePotInterface $coffee_pot |
|
| 31 | - */ |
|
| 32 | - private $coffee_pot; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EEH_Array $array_helper |
|
| 36 | - */ |
|
| 37 | - private $array_helper; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var ReflectionClass[] $reflectors |
|
| 41 | - */ |
|
| 42 | - private $reflectors; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var ReflectionMethod[] $constructors |
|
| 46 | - */ |
|
| 47 | - private $constructors; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var ReflectionParameter[] $parameters |
|
| 51 | - */ |
|
| 52 | - private $parameters; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * DependencyInjector constructor |
|
| 58 | - * |
|
| 59 | - * @param CoffeePotInterface $coffee_pot |
|
| 60 | - * @param EEH_Array $array_helper |
|
| 61 | - */ |
|
| 62 | - public function __construct(CoffeePotInterface $coffee_pot, EEH_Array $array_helper) |
|
| 63 | - { |
|
| 64 | - $this->coffee_pot = $coffee_pot; |
|
| 65 | - $this->array_helper = $array_helper; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * getReflectionClass |
|
| 72 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 73 | - * and returns that instead of creating a new one |
|
| 74 | - * |
|
| 75 | - * @param string $class_name |
|
| 76 | - * @return ReflectionClass |
|
| 77 | - */ |
|
| 78 | - public function getReflectionClass($class_name) |
|
| 79 | - { |
|
| 80 | - if ( |
|
| 81 | - ! isset($this->reflectors[$class_name]) |
|
| 82 | - || ! $this->reflectors[$class_name] instanceof ReflectionClass |
|
| 83 | - ) { |
|
| 84 | - $this->reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 85 | - } |
|
| 86 | - return $this->reflectors[$class_name]; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * getConstructor |
|
| 93 | - * checks if a ReflectionMethod object has already been generated for the class constructor |
|
| 94 | - * and returns that instead of creating a new one |
|
| 95 | - * |
|
| 96 | - * @param ReflectionClass $reflector |
|
| 97 | - * @return ReflectionMethod |
|
| 98 | - */ |
|
| 99 | - protected function getConstructor(ReflectionClass $reflector) |
|
| 100 | - { |
|
| 101 | - if ( |
|
| 102 | - ! isset($this->constructors[$reflector->getName()]) |
|
| 103 | - || ! $this->constructors[$reflector->getName()] instanceof ReflectionMethod |
|
| 104 | - ) { |
|
| 105 | - $this->constructors[$reflector->getName()] = $reflector->getConstructor(); |
|
| 106 | - } |
|
| 107 | - return $this->constructors[$reflector->getName()]; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * getParameters |
|
| 114 | - * checks if an array of ReflectionParameter objects has already been generated for the class constructor |
|
| 115 | - * and returns that instead of creating a new one |
|
| 116 | - * |
|
| 117 | - * @param ReflectionMethod $constructor |
|
| 118 | - * @return ReflectionParameter[] |
|
| 119 | - */ |
|
| 120 | - protected function getParameters(ReflectionMethod $constructor) |
|
| 121 | - { |
|
| 122 | - if ( ! isset($this->parameters[$constructor->class])) { |
|
| 123 | - $this->parameters[$constructor->class] = $constructor->getParameters(); |
|
| 124 | - } |
|
| 125 | - return $this->parameters[$constructor->class]; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * resolveDependencies |
|
| 132 | - * examines the constructor for the requested class to determine |
|
| 133 | - * if any dependencies exist, and if they can be injected. |
|
| 134 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 135 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 136 | - * For example: |
|
| 137 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 138 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 139 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 140 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 141 | - * and the correct classes can be loaded |
|
| 142 | - * |
|
| 143 | - * @param RecipeInterface $recipe |
|
| 144 | - * @param ReflectionClass $reflector |
|
| 145 | - * @param array $arguments |
|
| 146 | - * @return array |
|
| 147 | - * @throws UnexpectedValueException |
|
| 148 | - */ |
|
| 149 | - public function resolveDependencies(RecipeInterface $recipe, ReflectionClass $reflector, $arguments = array()) |
|
| 150 | - { |
|
| 151 | - // if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 152 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 153 | - $arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments) |
|
| 154 | - ? $arguments |
|
| 155 | - : array($arguments); |
|
| 156 | - $resolved_parameters = array(); |
|
| 157 | - // let's examine the constructor |
|
| 158 | - // let's examine the constructor |
|
| 159 | - $constructor = $this->getConstructor($reflector); |
|
| 160 | - // whu? huh? nothing? |
|
| 161 | - if ( ! $constructor) { |
|
| 162 | - return $arguments; |
|
| 163 | - } |
|
| 164 | - // get constructor parameters |
|
| 165 | - $params = $this->getParameters($constructor); |
|
| 166 | - if (empty($params)) { |
|
| 167 | - return $resolved_parameters; |
|
| 168 | - } |
|
| 169 | - $ingredients = $recipe->ingredients(); |
|
| 170 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 171 | - $argument_keys = array_keys($arguments); |
|
| 172 | - // now loop thru all of the constructors expected parameters |
|
| 173 | - foreach ($params as $index => $param) { |
|
| 174 | - if ( ! $param instanceof ReflectionParameter) { |
|
| 175 | - continue; |
|
| 176 | - } |
|
| 177 | - // is this a dependency for a specific class ? |
|
| 178 | - $param_class = $param->getClass() ? $param->getClass()->name : ''; |
|
| 179 | - $param_name = $param->getName() ? $param->getName() : ''; |
|
| 180 | - if ( |
|
| 181 | - // param is not a class but is specified in the list of ingredients for this Recipe |
|
| 182 | - is_string($param_name) && isset($ingredients[$param_name]) |
|
| 183 | - ) { |
|
| 184 | - // attempt to inject the dependency |
|
| 185 | - $resolved_parameters[$index] = $ingredients[ $param_name ]; |
|
| 186 | - } else if ( |
|
| 187 | - // param is specified in the list of ingredients for this Recipe |
|
| 188 | - isset($ingredients[$param_class]) |
|
| 189 | - ) { |
|
| 190 | - // attempt to inject the dependency |
|
| 191 | - $resolved_parameters[$index] = $this->injectDependency($reflector, $ingredients[$param_class]); |
|
| 192 | - } else if ( |
|
| 193 | - // param is not even a class |
|
| 194 | - empty($param_class) |
|
| 195 | - // and something already exists in the incoming arguments for this param |
|
| 196 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 197 | - ) { |
|
| 198 | - // add parameter from incoming arguments |
|
| 199 | - $resolved_parameters[$index] = $arguments[$argument_keys[$index]]; |
|
| 200 | - } else if ( |
|
| 201 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 202 | - ! empty($param_class) |
|
| 203 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 204 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 205 | - ) { |
|
| 206 | - // add parameter from incoming arguments |
|
| 207 | - $resolved_parameters[$index] = $arguments[$argument_keys[$index]]; |
|
| 208 | - } else if ( |
|
| 209 | - // parameter is type hinted as a class, and should be injected |
|
| 210 | - ! empty($param_class) |
|
| 211 | - ) { |
|
| 212 | - // attempt to inject the dependency |
|
| 213 | - $resolved_parameters[$index] = $this->injectDependency($reflector, $param_class); |
|
| 214 | - } else if ($param->isOptional()) { |
|
| 215 | - $resolved_parameters[$index] = $param->getDefaultValue(); |
|
| 216 | - } else { |
|
| 217 | - $resolved_parameters[$index] = null; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - return $resolved_parameters; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param ReflectionClass $reflector |
|
| 227 | - * @param string $param_class |
|
| 228 | - * @return mixed |
|
| 229 | - * @throws UnexpectedValueException |
|
| 230 | - */ |
|
| 231 | - private function injectDependency(ReflectionClass $reflector, $param_class) |
|
| 232 | - { |
|
| 233 | - $dependency = $this->coffee_pot->brew($param_class); |
|
| 234 | - if ( ! $dependency instanceof $param_class) { |
|
| 235 | - throw new UnexpectedValueException( |
|
| 236 | - sprintf( |
|
| 237 | - esc_html__( |
|
| 238 | - 'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ), |
|
| 241 | - $param_class, |
|
| 242 | - $reflector->getName() |
|
| 243 | - ) |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - return $dependency; |
|
| 247 | - } |
|
| 29 | + /** |
|
| 30 | + * @var CoffeePotInterface $coffee_pot |
|
| 31 | + */ |
|
| 32 | + private $coffee_pot; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EEH_Array $array_helper |
|
| 36 | + */ |
|
| 37 | + private $array_helper; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var ReflectionClass[] $reflectors |
|
| 41 | + */ |
|
| 42 | + private $reflectors; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var ReflectionMethod[] $constructors |
|
| 46 | + */ |
|
| 47 | + private $constructors; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var ReflectionParameter[] $parameters |
|
| 51 | + */ |
|
| 52 | + private $parameters; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * DependencyInjector constructor |
|
| 58 | + * |
|
| 59 | + * @param CoffeePotInterface $coffee_pot |
|
| 60 | + * @param EEH_Array $array_helper |
|
| 61 | + */ |
|
| 62 | + public function __construct(CoffeePotInterface $coffee_pot, EEH_Array $array_helper) |
|
| 63 | + { |
|
| 64 | + $this->coffee_pot = $coffee_pot; |
|
| 65 | + $this->array_helper = $array_helper; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * getReflectionClass |
|
| 72 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 73 | + * and returns that instead of creating a new one |
|
| 74 | + * |
|
| 75 | + * @param string $class_name |
|
| 76 | + * @return ReflectionClass |
|
| 77 | + */ |
|
| 78 | + public function getReflectionClass($class_name) |
|
| 79 | + { |
|
| 80 | + if ( |
|
| 81 | + ! isset($this->reflectors[$class_name]) |
|
| 82 | + || ! $this->reflectors[$class_name] instanceof ReflectionClass |
|
| 83 | + ) { |
|
| 84 | + $this->reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 85 | + } |
|
| 86 | + return $this->reflectors[$class_name]; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * getConstructor |
|
| 93 | + * checks if a ReflectionMethod object has already been generated for the class constructor |
|
| 94 | + * and returns that instead of creating a new one |
|
| 95 | + * |
|
| 96 | + * @param ReflectionClass $reflector |
|
| 97 | + * @return ReflectionMethod |
|
| 98 | + */ |
|
| 99 | + protected function getConstructor(ReflectionClass $reflector) |
|
| 100 | + { |
|
| 101 | + if ( |
|
| 102 | + ! isset($this->constructors[$reflector->getName()]) |
|
| 103 | + || ! $this->constructors[$reflector->getName()] instanceof ReflectionMethod |
|
| 104 | + ) { |
|
| 105 | + $this->constructors[$reflector->getName()] = $reflector->getConstructor(); |
|
| 106 | + } |
|
| 107 | + return $this->constructors[$reflector->getName()]; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * getParameters |
|
| 114 | + * checks if an array of ReflectionParameter objects has already been generated for the class constructor |
|
| 115 | + * and returns that instead of creating a new one |
|
| 116 | + * |
|
| 117 | + * @param ReflectionMethod $constructor |
|
| 118 | + * @return ReflectionParameter[] |
|
| 119 | + */ |
|
| 120 | + protected function getParameters(ReflectionMethod $constructor) |
|
| 121 | + { |
|
| 122 | + if ( ! isset($this->parameters[$constructor->class])) { |
|
| 123 | + $this->parameters[$constructor->class] = $constructor->getParameters(); |
|
| 124 | + } |
|
| 125 | + return $this->parameters[$constructor->class]; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * resolveDependencies |
|
| 132 | + * examines the constructor for the requested class to determine |
|
| 133 | + * if any dependencies exist, and if they can be injected. |
|
| 134 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 135 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 136 | + * For example: |
|
| 137 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 138 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 139 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 140 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 141 | + * and the correct classes can be loaded |
|
| 142 | + * |
|
| 143 | + * @param RecipeInterface $recipe |
|
| 144 | + * @param ReflectionClass $reflector |
|
| 145 | + * @param array $arguments |
|
| 146 | + * @return array |
|
| 147 | + * @throws UnexpectedValueException |
|
| 148 | + */ |
|
| 149 | + public function resolveDependencies(RecipeInterface $recipe, ReflectionClass $reflector, $arguments = array()) |
|
| 150 | + { |
|
| 151 | + // if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 152 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 153 | + $arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments) |
|
| 154 | + ? $arguments |
|
| 155 | + : array($arguments); |
|
| 156 | + $resolved_parameters = array(); |
|
| 157 | + // let's examine the constructor |
|
| 158 | + // let's examine the constructor |
|
| 159 | + $constructor = $this->getConstructor($reflector); |
|
| 160 | + // whu? huh? nothing? |
|
| 161 | + if ( ! $constructor) { |
|
| 162 | + return $arguments; |
|
| 163 | + } |
|
| 164 | + // get constructor parameters |
|
| 165 | + $params = $this->getParameters($constructor); |
|
| 166 | + if (empty($params)) { |
|
| 167 | + return $resolved_parameters; |
|
| 168 | + } |
|
| 169 | + $ingredients = $recipe->ingredients(); |
|
| 170 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 171 | + $argument_keys = array_keys($arguments); |
|
| 172 | + // now loop thru all of the constructors expected parameters |
|
| 173 | + foreach ($params as $index => $param) { |
|
| 174 | + if ( ! $param instanceof ReflectionParameter) { |
|
| 175 | + continue; |
|
| 176 | + } |
|
| 177 | + // is this a dependency for a specific class ? |
|
| 178 | + $param_class = $param->getClass() ? $param->getClass()->name : ''; |
|
| 179 | + $param_name = $param->getName() ? $param->getName() : ''; |
|
| 180 | + if ( |
|
| 181 | + // param is not a class but is specified in the list of ingredients for this Recipe |
|
| 182 | + is_string($param_name) && isset($ingredients[$param_name]) |
|
| 183 | + ) { |
|
| 184 | + // attempt to inject the dependency |
|
| 185 | + $resolved_parameters[$index] = $ingredients[ $param_name ]; |
|
| 186 | + } else if ( |
|
| 187 | + // param is specified in the list of ingredients for this Recipe |
|
| 188 | + isset($ingredients[$param_class]) |
|
| 189 | + ) { |
|
| 190 | + // attempt to inject the dependency |
|
| 191 | + $resolved_parameters[$index] = $this->injectDependency($reflector, $ingredients[$param_class]); |
|
| 192 | + } else if ( |
|
| 193 | + // param is not even a class |
|
| 194 | + empty($param_class) |
|
| 195 | + // and something already exists in the incoming arguments for this param |
|
| 196 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 197 | + ) { |
|
| 198 | + // add parameter from incoming arguments |
|
| 199 | + $resolved_parameters[$index] = $arguments[$argument_keys[$index]]; |
|
| 200 | + } else if ( |
|
| 201 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 202 | + ! empty($param_class) |
|
| 203 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 204 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 205 | + ) { |
|
| 206 | + // add parameter from incoming arguments |
|
| 207 | + $resolved_parameters[$index] = $arguments[$argument_keys[$index]]; |
|
| 208 | + } else if ( |
|
| 209 | + // parameter is type hinted as a class, and should be injected |
|
| 210 | + ! empty($param_class) |
|
| 211 | + ) { |
|
| 212 | + // attempt to inject the dependency |
|
| 213 | + $resolved_parameters[$index] = $this->injectDependency($reflector, $param_class); |
|
| 214 | + } else if ($param->isOptional()) { |
|
| 215 | + $resolved_parameters[$index] = $param->getDefaultValue(); |
|
| 216 | + } else { |
|
| 217 | + $resolved_parameters[$index] = null; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + return $resolved_parameters; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param ReflectionClass $reflector |
|
| 227 | + * @param string $param_class |
|
| 228 | + * @return mixed |
|
| 229 | + * @throws UnexpectedValueException |
|
| 230 | + */ |
|
| 231 | + private function injectDependency(ReflectionClass $reflector, $param_class) |
|
| 232 | + { |
|
| 233 | + $dependency = $this->coffee_pot->brew($param_class); |
|
| 234 | + if ( ! $dependency instanceof $param_class) { |
|
| 235 | + throw new UnexpectedValueException( |
|
| 236 | + sprintf( |
|
| 237 | + esc_html__( |
|
| 238 | + 'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ), |
|
| 241 | + $param_class, |
|
| 242 | + $reflector->getName() |
|
| 243 | + ) |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + return $dependency; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | // End of file DependencyInjector.php |
@@ -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,326 +24,326 @@ 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 | - * @throws InvalidIdentifierException |
|
| 115 | - * @throws RuntimeException |
|
| 116 | - * @throws InvalidInterfaceException |
|
| 117 | - * @throws InvalidClassException |
|
| 118 | - * @throws InvalidDataTypeException |
|
| 119 | - */ |
|
| 120 | - public function __construct( |
|
| 121 | - $identifier, |
|
| 122 | - $fqcn = '', |
|
| 123 | - array $filters = array(), |
|
| 124 | - array $ingredients = array(), |
|
| 125 | - $type = CoffeeMaker::BREW_NEW, |
|
| 126 | - array $paths = array() |
|
| 127 | - ) |
|
| 128 | - { |
|
| 129 | - $this->setIdentifier($identifier); |
|
| 130 | - $this->setFilters($filters); |
|
| 131 | - $this->setIngredients($ingredients); |
|
| 132 | - $this->setType($type); |
|
| 133 | - $this->setPaths($paths); |
|
| 134 | - $this->setFqcn($fqcn); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function identifier() |
|
| 143 | - { |
|
| 144 | - return $this->identifier; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function fqcn() |
|
| 153 | - { |
|
| 154 | - return $this->fqcn; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - public function filters() |
|
| 163 | - { |
|
| 164 | - return $this->filters; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function ingredients() |
|
| 173 | - { |
|
| 174 | - return $this->ingredients; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function type() |
|
| 183 | - { |
|
| 184 | - return $this->type; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 192 | - public function paths() |
|
| 193 | - { |
|
| 194 | - return $this->paths; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
| 201 | - * Typically a Fully Qualified Class Name |
|
| 202 | - * @throws InvalidIdentifierException |
|
| 203 | - */ |
|
| 204 | - public function setIdentifier($identifier) |
|
| 205 | - { |
|
| 206 | - if ( ! is_string($identifier) || empty($identifier)) { |
|
| 207 | - throw new InvalidIdentifierException( |
|
| 208 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
| 209 | - __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - $this->identifier = $identifier; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Ensures incoming string is a valid Fully Qualified Class Name, |
|
| 219 | - * except if this is the default wildcard Recipe ( * ), |
|
| 220 | - * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
| 221 | - * for classes that are not PSR-4 compatible |
|
| 222 | - * PLZ NOTE: |
|
| 223 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
| 224 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
| 225 | - * |
|
| 226 | - * @param string $fqcn |
|
| 227 | - * @throws InvalidDataTypeException |
|
| 228 | - * @throws InvalidClassException |
|
| 229 | - * @throws InvalidInterfaceException |
|
| 230 | - */ |
|
| 231 | - public function setFqcn($fqcn) |
|
| 232 | - { |
|
| 233 | - $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
| 234 | - if ( ! is_string($fqcn)) { |
|
| 235 | - throw new InvalidDataTypeException( |
|
| 236 | - '$fqcn', |
|
| 237 | - is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
| 238 | - __('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - $fqcn = ltrim($fqcn, '\\'); |
|
| 242 | - if ( |
|
| 243 | - $fqcn !== Recipe::DEFAULT_ID |
|
| 244 | - && ! empty($fqcn) |
|
| 245 | - && empty($this->paths) |
|
| 246 | - && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
| 247 | - ) { |
|
| 248 | - throw new InvalidClassException($fqcn); |
|
| 249 | - } |
|
| 250 | - $this->fqcn = $fqcn; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
| 257 | - * example: |
|
| 258 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
| 259 | - * @throws InvalidDataTypeException |
|
| 260 | - */ |
|
| 261 | - public function setIngredients(array $ingredients) |
|
| 262 | - { |
|
| 263 | - if (empty($ingredients)) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - if ( ! is_array($ingredients)) { |
|
| 267 | - throw new InvalidDataTypeException( |
|
| 268 | - '$ingredients', |
|
| 269 | - is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
| 270 | - __('array of class dependencies', 'event_espresso') |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
| 279 | - * @throws InvalidIdentifierException |
|
| 280 | - */ |
|
| 281 | - public function setType($type = CoffeeMaker::BREW_NEW) |
|
| 282 | - { |
|
| 283 | - $this->type = CoffeeMaker::validateType($type); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
| 290 | - * example: |
|
| 291 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
| 292 | - * @throws InvalidDataTypeException |
|
| 293 | - */ |
|
| 294 | - public function setFilters(array $filters) |
|
| 295 | - { |
|
| 296 | - if (empty($filters)) { |
|
| 297 | - return; |
|
| 298 | - } |
|
| 299 | - if ( ! is_array($filters)) { |
|
| 300 | - throw new InvalidDataTypeException( |
|
| 301 | - '$filters', |
|
| 302 | - is_object($filters) ? get_class($filters) : gettype($filters), |
|
| 303 | - __('array of class aliases', 'event_espresso') |
|
| 304 | - ); |
|
| 305 | - } |
|
| 306 | - $this->filters = array_merge($this->filters, $filters); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
| 313 | - * and merges them in with any existing filepaths |
|
| 314 | - * PLZ NOTE: |
|
| 315 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
| 316 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
| 317 | - * |
|
| 318 | - * @param string|array $paths |
|
| 319 | - * @throws RuntimeException |
|
| 320 | - * @throws InvalidDataTypeException |
|
| 321 | - */ |
|
| 322 | - public function setPaths($paths = array()) |
|
| 323 | - { |
|
| 324 | - if (empty($paths)) { |
|
| 325 | - return; |
|
| 326 | - } |
|
| 327 | - if ( ! (is_string($paths) || is_array($paths))) { |
|
| 328 | - throw new InvalidDataTypeException( |
|
| 329 | - '$path', |
|
| 330 | - is_object($paths) ? get_class($paths) : gettype($paths), |
|
| 331 | - __('string or array of strings (full server filepath(s))', 'event_espresso') |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - $paths = (array)$paths; |
|
| 335 | - foreach ($paths as $path) { |
|
| 336 | - if (strpos($path, '*') === false && ! is_readable($path)) { |
|
| 337 | - throw new RuntimeException( |
|
| 338 | - sprintf( |
|
| 339 | - __('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
| 340 | - $path |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - $this->paths = array_merge($this->paths, $paths); |
|
| 346 | - } |
|
| 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 | + * @throws InvalidIdentifierException |
|
| 115 | + * @throws RuntimeException |
|
| 116 | + * @throws InvalidInterfaceException |
|
| 117 | + * @throws InvalidClassException |
|
| 118 | + * @throws InvalidDataTypeException |
|
| 119 | + */ |
|
| 120 | + public function __construct( |
|
| 121 | + $identifier, |
|
| 122 | + $fqcn = '', |
|
| 123 | + array $filters = array(), |
|
| 124 | + array $ingredients = array(), |
|
| 125 | + $type = CoffeeMaker::BREW_NEW, |
|
| 126 | + array $paths = array() |
|
| 127 | + ) |
|
| 128 | + { |
|
| 129 | + $this->setIdentifier($identifier); |
|
| 130 | + $this->setFilters($filters); |
|
| 131 | + $this->setIngredients($ingredients); |
|
| 132 | + $this->setType($type); |
|
| 133 | + $this->setPaths($paths); |
|
| 134 | + $this->setFqcn($fqcn); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function identifier() |
|
| 143 | + { |
|
| 144 | + return $this->identifier; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function fqcn() |
|
| 153 | + { |
|
| 154 | + return $this->fqcn; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + public function filters() |
|
| 163 | + { |
|
| 164 | + return $this->filters; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function ingredients() |
|
| 173 | + { |
|
| 174 | + return $this->ingredients; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function type() |
|
| 183 | + { |
|
| 184 | + return $this->type; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | + public function paths() |
|
| 193 | + { |
|
| 194 | + return $this->paths; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
| 201 | + * Typically a Fully Qualified Class Name |
|
| 202 | + * @throws InvalidIdentifierException |
|
| 203 | + */ |
|
| 204 | + public function setIdentifier($identifier) |
|
| 205 | + { |
|
| 206 | + if ( ! is_string($identifier) || empty($identifier)) { |
|
| 207 | + throw new InvalidIdentifierException( |
|
| 208 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
| 209 | + __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + $this->identifier = $identifier; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Ensures incoming string is a valid Fully Qualified Class Name, |
|
| 219 | + * except if this is the default wildcard Recipe ( * ), |
|
| 220 | + * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
| 221 | + * for classes that are not PSR-4 compatible |
|
| 222 | + * PLZ NOTE: |
|
| 223 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
| 224 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
| 225 | + * |
|
| 226 | + * @param string $fqcn |
|
| 227 | + * @throws InvalidDataTypeException |
|
| 228 | + * @throws InvalidClassException |
|
| 229 | + * @throws InvalidInterfaceException |
|
| 230 | + */ |
|
| 231 | + public function setFqcn($fqcn) |
|
| 232 | + { |
|
| 233 | + $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
| 234 | + if ( ! is_string($fqcn)) { |
|
| 235 | + throw new InvalidDataTypeException( |
|
| 236 | + '$fqcn', |
|
| 237 | + is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
| 238 | + __('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + $fqcn = ltrim($fqcn, '\\'); |
|
| 242 | + if ( |
|
| 243 | + $fqcn !== Recipe::DEFAULT_ID |
|
| 244 | + && ! empty($fqcn) |
|
| 245 | + && empty($this->paths) |
|
| 246 | + && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
| 247 | + ) { |
|
| 248 | + throw new InvalidClassException($fqcn); |
|
| 249 | + } |
|
| 250 | + $this->fqcn = $fqcn; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
| 257 | + * example: |
|
| 258 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
| 259 | + * @throws InvalidDataTypeException |
|
| 260 | + */ |
|
| 261 | + public function setIngredients(array $ingredients) |
|
| 262 | + { |
|
| 263 | + if (empty($ingredients)) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + if ( ! is_array($ingredients)) { |
|
| 267 | + throw new InvalidDataTypeException( |
|
| 268 | + '$ingredients', |
|
| 269 | + is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
| 270 | + __('array of class dependencies', 'event_espresso') |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
| 279 | + * @throws InvalidIdentifierException |
|
| 280 | + */ |
|
| 281 | + public function setType($type = CoffeeMaker::BREW_NEW) |
|
| 282 | + { |
|
| 283 | + $this->type = CoffeeMaker::validateType($type); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
| 290 | + * example: |
|
| 291 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
| 292 | + * @throws InvalidDataTypeException |
|
| 293 | + */ |
|
| 294 | + public function setFilters(array $filters) |
|
| 295 | + { |
|
| 296 | + if (empty($filters)) { |
|
| 297 | + return; |
|
| 298 | + } |
|
| 299 | + if ( ! is_array($filters)) { |
|
| 300 | + throw new InvalidDataTypeException( |
|
| 301 | + '$filters', |
|
| 302 | + is_object($filters) ? get_class($filters) : gettype($filters), |
|
| 303 | + __('array of class aliases', 'event_espresso') |
|
| 304 | + ); |
|
| 305 | + } |
|
| 306 | + $this->filters = array_merge($this->filters, $filters); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
| 313 | + * and merges them in with any existing filepaths |
|
| 314 | + * PLZ NOTE: |
|
| 315 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
| 316 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
| 317 | + * |
|
| 318 | + * @param string|array $paths |
|
| 319 | + * @throws RuntimeException |
|
| 320 | + * @throws InvalidDataTypeException |
|
| 321 | + */ |
|
| 322 | + public function setPaths($paths = array()) |
|
| 323 | + { |
|
| 324 | + if (empty($paths)) { |
|
| 325 | + return; |
|
| 326 | + } |
|
| 327 | + if ( ! (is_string($paths) || is_array($paths))) { |
|
| 328 | + throw new InvalidDataTypeException( |
|
| 329 | + '$path', |
|
| 330 | + is_object($paths) ? get_class($paths) : gettype($paths), |
|
| 331 | + __('string or array of strings (full server filepath(s))', 'event_espresso') |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + $paths = (array)$paths; |
|
| 335 | + foreach ($paths as $path) { |
|
| 336 | + if (strpos($path, '*') === false && ! is_readable($path)) { |
|
| 337 | + throw new RuntimeException( |
|
| 338 | + sprintf( |
|
| 339 | + __('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
| 340 | + $path |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + $this->paths = array_merge($this->paths, $paths); |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | 348 | |
| 349 | 349 | |
@@ -331,7 +331,7 @@ |
||
| 331 | 331 | __('string or array of strings (full server filepath(s))', 'event_espresso') |
| 332 | 332 | ); |
| 333 | 333 | } |
| 334 | - $paths = (array)$paths; |
|
| 334 | + $paths = (array) $paths; |
|
| 335 | 335 | foreach ($paths as $path) { |
| 336 | 336 | if (strpos($path, '*') === false && ! is_readable($path)) { |
| 337 | 337 | throw new RuntimeException( |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use EventEspresso\core\services\request\RequestInterface; |
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 9 | 9 | |
| 10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | 11 | exit('No direct script access allowed'); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public static function instance() { |
| 131 | 131 | // check if class object is instantiated, and instantiated properly |
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | 133 | self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
| 134 | 134 | } |
| 135 | 135 | return self::$_instance; |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | ) { |
| 212 | 212 | $class = trim($class, '\\'); |
| 213 | 213 | $registered = false; |
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 214 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
| 215 | + self::$_instance->_dependency_map[$class] = array(); |
|
| 216 | 216 | } |
| 217 | 217 | // we need to make sure that any aliases used when registering a dependency |
| 218 | 218 | // get resolved to the correct class name |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $alias = self::$_instance->get_alias($dependency); |
| 221 | 221 | if ( |
| 222 | 222 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
| 224 | 224 | ) { |
| 225 | 225 | unset($dependencies[$dependency]); |
| 226 | 226 | $dependencies[$alias] = $load_source; |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
| 234 | 234 | // Union is way faster than array_merge() but should be used with caution... |
| 235 | 235 | // especially with numerically indexed arrays |
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
| 237 | 237 | // now we need to ensure that the resulting dependencies |
| 238 | 238 | // array only has the entries that are required for the class |
| 239 | 239 | // so first count how many dependencies were originally registered for the class |
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
| 241 | 241 | // if that count is non-zero (meaning dependencies were already registered) |
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 242 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
| 243 | 243 | // then truncate the final array to match that count |
| 244 | 244 | ? array_slice($dependencies, 0, $dependency_count) |
| 245 | 245 | // otherwise just take the incoming array because nothing previously existed |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public static function register_class_loader($class_name, $loader = 'load_core') |
| 259 | 259 | { |
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 260 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | 261 | throw new DomainException( |
| 262 | 262 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
| 263 | 263 | ); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | ); |
| 282 | 282 | } |
| 283 | 283 | $class_name = self::$_instance->get_alias($class_name); |
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 284 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | 285 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | public function class_loader($class_name) |
| 367 | 367 | { |
| 368 | 368 | // all legacy models use load_model() |
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 369 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 370 | 370 | return 'load_model'; |
| 371 | 371 | } |
| 372 | 372 | $class_name = $this->get_alias($class_name); |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | public function add_alias($class_name, $alias, $for_class = '') |
| 396 | 396 | { |
| 397 | 397 | if ($for_class !== '') { |
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 398 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 399 | 399 | $this->_aliases[$for_class] = array(); |
| 400 | 400 | } |
| 401 | 401 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -441,10 +441,10 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function get_alias($class_name = '', $for_class = '') |
| 443 | 443 | { |
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 444 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 445 | 445 | return $class_name; |
| 446 | 446 | } |
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
| 448 | 448 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
| 449 | 449 | } |
| 450 | 450 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -714,13 +714,13 @@ discard block |
||
| 714 | 714 | 'EE_Front_Controller' => 'load_core', |
| 715 | 715 | 'EE_Module_Request_Router' => 'load_core', |
| 716 | 716 | 'EE_Registry' => 'load_core', |
| 717 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 717 | + 'EE_Request' => function() use (&$legacy_request) { |
|
| 718 | 718 | return $legacy_request; |
| 719 | 719 | }, |
| 720 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 720 | + 'EventEspresso\core\services\request\Request' => function() use (&$request) { |
|
| 721 | 721 | return $request; |
| 722 | 722 | }, |
| 723 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 723 | + 'EventEspresso\core\services\request\Response' => function() use (&$response) { |
|
| 724 | 724 | return $response; |
| 725 | 725 | }, |
| 726 | 726 | 'EE_Request_Handler' => 'load_core', |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 743 | 743 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 744 | 744 | 'EE_Payment_Method_Manager' => 'load_lib', |
| 745 | - 'EE_Messages_Generator' => function () { |
|
| 745 | + 'EE_Messages_Generator' => function() { |
|
| 746 | 746 | return EE_Registry::instance()->load_lib( |
| 747 | 747 | 'Messages_Generator', |
| 748 | 748 | array(), |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | false |
| 751 | 751 | ); |
| 752 | 752 | }, |
| 753 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 753 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 754 | 754 | return EE_Registry::instance()->load_lib( |
| 755 | 755 | 'Messages_Template_Defaults', |
| 756 | 756 | $arguments, |
@@ -763,22 +763,22 @@ discard block |
||
| 763 | 763 | // 'EEM_Message_Template_Group' => 'load_model', |
| 764 | 764 | // 'EEM_Message_Template' => 'load_model', |
| 765 | 765 | //load_helper |
| 766 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 766 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 767 | 767 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 768 | 768 | return new EEH_Parse_Shortcodes(); |
| 769 | 769 | } |
| 770 | 770 | return null; |
| 771 | 771 | }, |
| 772 | - 'EE_Template_Config' => function () { |
|
| 772 | + 'EE_Template_Config' => function() { |
|
| 773 | 773 | return EE_Config::instance()->template_settings; |
| 774 | 774 | }, |
| 775 | - 'EE_Currency_Config' => function () { |
|
| 775 | + 'EE_Currency_Config' => function() { |
|
| 776 | 776 | return EE_Config::instance()->currency; |
| 777 | 777 | }, |
| 778 | - 'EE_Registration_Config' => function () { |
|
| 778 | + 'EE_Registration_Config' => function() { |
|
| 779 | 779 | return EE_Config::instance()->registration; |
| 780 | 780 | }, |
| 781 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 781 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
| 782 | 782 | return LoaderFactory::getLoader(); |
| 783 | 783 | }, |
| 784 | 784 | ); |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
| 834 | 834 | 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
| 835 | 835 | ); |
| 836 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 836 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 837 | 837 | $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
| 838 | 838 | } |
| 839 | 839 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 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 | |
@@ -25,834 +25,834 @@ discard block |
||
| 25 | 25 | class EE_Dependency_Map |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This means that the requested class dependency is not present in the dependency map |
|
| 30 | - */ |
|
| 31 | - const not_registered = 0; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | - */ |
|
| 36 | - const load_new_object = 1; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | - */ |
|
| 42 | - const load_from_cache = 2; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * When registering a dependency, |
|
| 46 | - * this indicates to keep any existing dependencies that already exist, |
|
| 47 | - * and simply discard any new dependencies declared in the incoming data |
|
| 48 | - */ |
|
| 49 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * When registering a dependency, |
|
| 53 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | - */ |
|
| 55 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type EE_Dependency_Map $_instance |
|
| 61 | - */ |
|
| 62 | - protected static $_instance; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type RequestInterface $request |
|
| 66 | - */ |
|
| 67 | - protected $request; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type LegacyRequestInterface $legacy_request |
|
| 71 | - */ |
|
| 72 | - protected $legacy_request; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type ResponseInterface $response |
|
| 76 | - */ |
|
| 77 | - protected $response; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type LoaderInterface $loader |
|
| 81 | - */ |
|
| 82 | - protected $loader; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type array $_dependency_map |
|
| 86 | - */ |
|
| 87 | - protected $_dependency_map = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @type array $_class_loaders |
|
| 91 | - */ |
|
| 92 | - protected $_class_loaders = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @type array $_aliases |
|
| 96 | - */ |
|
| 97 | - protected $_aliases = array(); |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * EE_Dependency_Map constructor. |
|
| 103 | - */ |
|
| 104 | - protected function __construct() |
|
| 105 | - { |
|
| 106 | - // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | - do_action('EE_Dependency_Map____construct'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - */ |
|
| 117 | - public function initialize() |
|
| 118 | - { |
|
| 119 | - $this->_register_core_dependencies(); |
|
| 120 | - $this->_register_core_class_loaders(); |
|
| 121 | - $this->_register_core_aliases(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @singleton method used to instantiate class object |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance() { |
|
| 131 | - // check if class object is instantiated, and instantiated properly |
|
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | - self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | - } |
|
| 135 | - return self::$_instance; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param RequestInterface $request |
|
| 141 | - */ |
|
| 142 | - public function setRequest(RequestInterface $request) |
|
| 143 | - { |
|
| 144 | - $this->request = $request; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param LegacyRequestInterface $legacy_request |
|
| 150 | - */ |
|
| 151 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | - { |
|
| 153 | - $this->legacy_request = $legacy_request; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param ResponseInterface $response |
|
| 159 | - */ |
|
| 160 | - public function setResponse(ResponseInterface $response) |
|
| 161 | - { |
|
| 162 | - $this->response = $response; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param LoaderInterface $loader |
|
| 169 | - */ |
|
| 170 | - public function setLoader(LoaderInterface $loader) |
|
| 171 | - { |
|
| 172 | - $this->loader = $loader; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param string $class |
|
| 179 | - * @param array $dependencies |
|
| 180 | - * @param int $overwrite |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public static function register_dependencies( |
|
| 184 | - $class, |
|
| 185 | - array $dependencies, |
|
| 186 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | - ) { |
|
| 188 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | - * to the class specified by the first parameter. |
|
| 196 | - * IMPORTANT !!! |
|
| 197 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | - * the order of the constructor parameters for the class in question. |
|
| 199 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | - * |
|
| 202 | - * @param string $class |
|
| 203 | - * @param array $dependencies |
|
| 204 | - * @param int $overwrite |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function registerDependencies( |
|
| 208 | - $class, |
|
| 209 | - array $dependencies, |
|
| 210 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | - ) { |
|
| 212 | - $class = trim($class, '\\'); |
|
| 213 | - $registered = false; |
|
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | - } |
|
| 217 | - // we need to make sure that any aliases used when registering a dependency |
|
| 218 | - // get resolved to the correct class name |
|
| 219 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | - $alias = self::$_instance->get_alias($dependency); |
|
| 221 | - if ( |
|
| 222 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | - ) { |
|
| 225 | - unset($dependencies[$dependency]); |
|
| 226 | - $dependencies[$alias] = $load_source; |
|
| 227 | - $registered = true; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - // now add our two lists of dependencies together. |
|
| 231 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | - // especially with numerically indexed arrays |
|
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | - // now we need to ensure that the resulting dependencies |
|
| 238 | - // array only has the entries that are required for the class |
|
| 239 | - // so first count how many dependencies were originally registered for the class |
|
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | - // then truncate the final array to match that count |
|
| 244 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | - // otherwise just take the incoming array because nothing previously existed |
|
| 246 | - : $dependencies; |
|
| 247 | - return $registered; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param string $class_name |
|
| 254 | - * @param string $loader |
|
| 255 | - * @return bool |
|
| 256 | - * @throws DomainException |
|
| 257 | - */ |
|
| 258 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | - { |
|
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | - throw new DomainException( |
|
| 262 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | - if ( |
|
| 267 | - ! is_callable($loader) |
|
| 268 | - && ( |
|
| 269 | - strpos($loader, 'load_') !== 0 |
|
| 270 | - || ! method_exists('EE_Registry', $loader) |
|
| 271 | - ) |
|
| 272 | - ) { |
|
| 273 | - throw new DomainException( |
|
| 274 | - sprintf( |
|
| 275 | - esc_html__( |
|
| 276 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | - 'event_espresso' |
|
| 278 | - ), |
|
| 279 | - $loader |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | - return true; |
|
| 287 | - } |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return array |
|
| 295 | - */ |
|
| 296 | - public function dependency_map() |
|
| 297 | - { |
|
| 298 | - return $this->_dependency_map; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | - * |
|
| 306 | - * @param string $class_name |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function has($class_name = '') |
|
| 310 | - { |
|
| 311 | - // all legacy models have the same dependencies |
|
| 312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | - $class_name = 'LEGACY_MODELS'; |
|
| 314 | - } |
|
| 315 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | - * |
|
| 323 | - * @param string $class_name |
|
| 324 | - * @param string $dependency |
|
| 325 | - * @return bool |
|
| 326 | - */ |
|
| 327 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | - { |
|
| 329 | - // all legacy models have the same dependencies |
|
| 330 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | - $class_name = 'LEGACY_MODELS'; |
|
| 332 | - } |
|
| 333 | - $dependency = $this->get_alias($dependency); |
|
| 334 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | - ? true |
|
| 336 | - : false; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | - * |
|
| 344 | - * @param string $class_name |
|
| 345 | - * @param string $dependency |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | - { |
|
| 350 | - // all legacy models have the same dependencies |
|
| 351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | - $class_name = 'LEGACY_MODELS'; |
|
| 353 | - } |
|
| 354 | - $dependency = $this->get_alias($dependency); |
|
| 355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | - : EE_Dependency_Map::not_registered; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $class_name |
|
| 364 | - * @return string | Closure |
|
| 365 | - */ |
|
| 366 | - public function class_loader($class_name) |
|
| 367 | - { |
|
| 368 | - // all legacy models use load_model() |
|
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | - return 'load_model'; |
|
| 371 | - } |
|
| 372 | - $class_name = $this->get_alias($class_name); |
|
| 373 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @return array |
|
| 380 | - */ |
|
| 381 | - public function class_loaders() |
|
| 382 | - { |
|
| 383 | - return $this->_class_loaders; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * adds an alias for a classname |
|
| 390 | - * |
|
| 391 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | - */ |
|
| 395 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | - { |
|
| 397 | - if ($for_class !== '') { |
|
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 399 | - $this->_aliases[$for_class] = array(); |
|
| 400 | - } |
|
| 401 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | - } |
|
| 403 | - $this->_aliases[$class_name] = $alias; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * returns TRUE if the provided class name has an alias |
|
| 410 | - * |
|
| 411 | - * @param string $class_name |
|
| 412 | - * @param string $for_class |
|
| 413 | - * @return bool |
|
| 414 | - */ |
|
| 415 | - public function has_alias($class_name = '', $for_class = '') |
|
| 416 | - { |
|
| 417 | - return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | - || ( |
|
| 419 | - isset($this->_aliases[$class_name]) |
|
| 420 | - && ! is_array($this->_aliases[$class_name]) |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | - * for example: |
|
| 430 | - * if the following two entries were added to the _aliases array: |
|
| 431 | - * array( |
|
| 432 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | - * ) |
|
| 435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | - * to load an instance of 'some\namespace\classname' |
|
| 437 | - * |
|
| 438 | - * @param string $class_name |
|
| 439 | - * @param string $for_class |
|
| 440 | - * @return string |
|
| 441 | - */ |
|
| 442 | - public function get_alias($class_name = '', $for_class = '') |
|
| 443 | - { |
|
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | - return $class_name; |
|
| 446 | - } |
|
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | - } |
|
| 450 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | - * This is done by using the following class constants: |
|
| 459 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | - */ |
|
| 462 | - protected function _register_core_dependencies() |
|
| 463 | - { |
|
| 464 | - $this->_dependency_map = array( |
|
| 465 | - 'EE_Request_Handler' => array( |
|
| 466 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - ), |
|
| 468 | - 'EE_System' => array( |
|
| 469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | - ), |
|
| 474 | - 'EE_Session' => array( |
|
| 475 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - ), |
|
| 479 | - 'EE_Cart' => array( |
|
| 480 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 481 | - ), |
|
| 482 | - 'EE_Front_Controller' => array( |
|
| 483 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 488 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 489 | - ), |
|
| 490 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 491 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 492 | - ), |
|
| 493 | - 'EE_Message_Resource_Manager' => array( |
|
| 494 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 495 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 497 | - ), |
|
| 498 | - 'EE_Message_Factory' => array( |
|
| 499 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EE_messages' => array( |
|
| 502 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - ), |
|
| 504 | - 'EE_Messages_Generator' => array( |
|
| 505 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 506 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 507 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 509 | - ), |
|
| 510 | - 'EE_Messages_Processor' => array( |
|
| 511 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ), |
|
| 513 | - 'EE_Messages_Queue' => array( |
|
| 514 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 515 | - ), |
|
| 516 | - 'EE_Messages_Template_Defaults' => array( |
|
| 517 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 519 | - ), |
|
| 520 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 521 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 522 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 525 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 528 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - ), |
|
| 531 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 532 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 533 | - ), |
|
| 534 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 535 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 536 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 537 | - ), |
|
| 538 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 539 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 540 | - ), |
|
| 541 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 542 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 543 | - ), |
|
| 544 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 545 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 546 | - ), |
|
| 547 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 548 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 549 | - ), |
|
| 550 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 551 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 552 | - ), |
|
| 553 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 554 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 555 | - ), |
|
| 556 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 557 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 558 | - ), |
|
| 559 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 560 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 561 | - ), |
|
| 562 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 563 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - ), |
|
| 565 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 566 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 567 | - ), |
|
| 568 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 569 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 570 | - ), |
|
| 571 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 572 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - ), |
|
| 574 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 575 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - ), |
|
| 577 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 578 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 579 | - ), |
|
| 580 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - ), |
|
| 584 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - ), |
|
| 588 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - ), |
|
| 592 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - ), |
|
| 596 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - ), |
|
| 600 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ), |
|
| 604 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - ), |
|
| 608 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 609 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - ), |
|
| 612 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 613 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ), |
|
| 616 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 617 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 619 | - ), |
|
| 620 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 621 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 622 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | - ), |
|
| 624 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 625 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 626 | - ), |
|
| 627 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 628 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 629 | - ), |
|
| 630 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 631 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - ), |
|
| 633 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 634 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 635 | - ), |
|
| 636 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 637 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 638 | - ), |
|
| 639 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 641 | - ), |
|
| 642 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 643 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 644 | - ), |
|
| 645 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 646 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 647 | - ), |
|
| 648 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 649 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 650 | - ), |
|
| 651 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 652 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 653 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 654 | - ), |
|
| 655 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 656 | - null, |
|
| 657 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 658 | - ), |
|
| 659 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 660 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 661 | - ), |
|
| 662 | - 'LEGACY_MODELS' => array( |
|
| 663 | - null, |
|
| 664 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 665 | - ), |
|
| 666 | - 'EE_Module_Request_Router' => array( |
|
| 667 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 668 | - ), |
|
| 669 | - 'EE_Registration_Processor' => array( |
|
| 670 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 671 | - ), |
|
| 672 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 673 | - null, |
|
| 674 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 675 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 676 | - ), |
|
| 677 | - ); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * Registers how core classes are loaded. |
|
| 684 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 685 | - * 'EE_Request_Handler' => 'load_core' |
|
| 686 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 687 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 688 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 689 | - * 'Some_Class' => function () { |
|
| 690 | - * return new Some_Class(); |
|
| 691 | - * }, |
|
| 692 | - * This is required for instantiating dependencies |
|
| 693 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 694 | - * 'Required_Interface' => function () { |
|
| 695 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 696 | - * }, |
|
| 697 | - * |
|
| 698 | - * @throws InvalidInterfaceException |
|
| 699 | - * @throws InvalidDataTypeException |
|
| 700 | - * @throws InvalidArgumentException |
|
| 701 | - */ |
|
| 702 | - protected function _register_core_class_loaders() |
|
| 703 | - { |
|
| 704 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 705 | - //be used in a closure. |
|
| 706 | - $request = &$this->request; |
|
| 707 | - $response = &$this->response; |
|
| 708 | - $legacy_request = &$this->legacy_request; |
|
| 709 | - // $loader = &$this->loader; |
|
| 710 | - $this->_class_loaders = array( |
|
| 711 | - //load_core |
|
| 712 | - 'EE_Capabilities' => 'load_core', |
|
| 713 | - 'EE_Encryption' => 'load_core', |
|
| 714 | - 'EE_Front_Controller' => 'load_core', |
|
| 715 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 716 | - 'EE_Registry' => 'load_core', |
|
| 717 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 718 | - return $legacy_request; |
|
| 719 | - }, |
|
| 720 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 721 | - return $request; |
|
| 722 | - }, |
|
| 723 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 724 | - return $response; |
|
| 725 | - }, |
|
| 726 | - 'EE_Request_Handler' => 'load_core', |
|
| 727 | - 'EE_Session' => 'load_core', |
|
| 728 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 729 | - 'EE_System' => 'load_core', |
|
| 730 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 731 | - 'EE_Register_CPTs' => 'load_core', |
|
| 732 | - 'EE_Admin' => 'load_core', |
|
| 733 | - //load_lib |
|
| 734 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 735 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 736 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 737 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 738 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 739 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 740 | - 'EE_Message_Repository' => 'load_lib', |
|
| 741 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 742 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 743 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 744 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 745 | - 'EE_Messages_Generator' => function () { |
|
| 746 | - return EE_Registry::instance()->load_lib( |
|
| 747 | - 'Messages_Generator', |
|
| 748 | - array(), |
|
| 749 | - false, |
|
| 750 | - false |
|
| 751 | - ); |
|
| 752 | - }, |
|
| 753 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 754 | - return EE_Registry::instance()->load_lib( |
|
| 755 | - 'Messages_Template_Defaults', |
|
| 756 | - $arguments, |
|
| 757 | - false, |
|
| 758 | - false |
|
| 759 | - ); |
|
| 760 | - }, |
|
| 761 | - //load_model |
|
| 762 | - // 'EEM_Attendee' => 'load_model', |
|
| 763 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
| 764 | - // 'EEM_Message_Template' => 'load_model', |
|
| 765 | - //load_helper |
|
| 766 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 767 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 768 | - return new EEH_Parse_Shortcodes(); |
|
| 769 | - } |
|
| 770 | - return null; |
|
| 771 | - }, |
|
| 772 | - 'EE_Template_Config' => function () { |
|
| 773 | - return EE_Config::instance()->template_settings; |
|
| 774 | - }, |
|
| 775 | - 'EE_Currency_Config' => function () { |
|
| 776 | - return EE_Config::instance()->currency; |
|
| 777 | - }, |
|
| 778 | - 'EE_Registration_Config' => function () { |
|
| 779 | - return EE_Config::instance()->registration; |
|
| 780 | - }, |
|
| 781 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 782 | - return LoaderFactory::getLoader(); |
|
| 783 | - }, |
|
| 784 | - ); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * can be used for supplying alternate names for classes, |
|
| 791 | - * or for connecting interface names to instantiable classes |
|
| 792 | - */ |
|
| 793 | - protected function _register_core_aliases() |
|
| 794 | - { |
|
| 795 | - $this->_aliases = array( |
|
| 796 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 797 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 798 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 799 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 800 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 801 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 802 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 803 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 804 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 805 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 806 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 807 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 808 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 809 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 810 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 811 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 812 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 813 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 814 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 815 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 816 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 817 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 818 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 819 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 820 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 821 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 822 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 823 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 824 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 825 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 826 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 827 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 828 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 829 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 830 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 831 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 832 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 833 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 834 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 835 | - ); |
|
| 836 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 837 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 845 | - * request Primarily used by unit tests. |
|
| 846 | - * |
|
| 847 | - * @throws InvalidDataTypeException |
|
| 848 | - * @throws InvalidInterfaceException |
|
| 849 | - * @throws InvalidArgumentException |
|
| 850 | - */ |
|
| 851 | - public function reset() |
|
| 852 | - { |
|
| 853 | - $this->_register_core_class_loaders(); |
|
| 854 | - $this->_register_core_dependencies(); |
|
| 855 | - } |
|
| 28 | + /** |
|
| 29 | + * This means that the requested class dependency is not present in the dependency map |
|
| 30 | + */ |
|
| 31 | + const not_registered = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | + */ |
|
| 36 | + const load_new_object = 1; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | + */ |
|
| 42 | + const load_from_cache = 2; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * When registering a dependency, |
|
| 46 | + * this indicates to keep any existing dependencies that already exist, |
|
| 47 | + * and simply discard any new dependencies declared in the incoming data |
|
| 48 | + */ |
|
| 49 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * When registering a dependency, |
|
| 53 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | + */ |
|
| 55 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type EE_Dependency_Map $_instance |
|
| 61 | + */ |
|
| 62 | + protected static $_instance; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type RequestInterface $request |
|
| 66 | + */ |
|
| 67 | + protected $request; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type LegacyRequestInterface $legacy_request |
|
| 71 | + */ |
|
| 72 | + protected $legacy_request; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type ResponseInterface $response |
|
| 76 | + */ |
|
| 77 | + protected $response; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type LoaderInterface $loader |
|
| 81 | + */ |
|
| 82 | + protected $loader; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type array $_dependency_map |
|
| 86 | + */ |
|
| 87 | + protected $_dependency_map = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @type array $_class_loaders |
|
| 91 | + */ |
|
| 92 | + protected $_class_loaders = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @type array $_aliases |
|
| 96 | + */ |
|
| 97 | + protected $_aliases = array(); |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * EE_Dependency_Map constructor. |
|
| 103 | + */ |
|
| 104 | + protected function __construct() |
|
| 105 | + { |
|
| 106 | + // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | + do_action('EE_Dependency_Map____construct'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + */ |
|
| 117 | + public function initialize() |
|
| 118 | + { |
|
| 119 | + $this->_register_core_dependencies(); |
|
| 120 | + $this->_register_core_class_loaders(); |
|
| 121 | + $this->_register_core_aliases(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @singleton method used to instantiate class object |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance() { |
|
| 131 | + // check if class object is instantiated, and instantiated properly |
|
| 132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | + self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | + } |
|
| 135 | + return self::$_instance; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param RequestInterface $request |
|
| 141 | + */ |
|
| 142 | + public function setRequest(RequestInterface $request) |
|
| 143 | + { |
|
| 144 | + $this->request = $request; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param LegacyRequestInterface $legacy_request |
|
| 150 | + */ |
|
| 151 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | + { |
|
| 153 | + $this->legacy_request = $legacy_request; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param ResponseInterface $response |
|
| 159 | + */ |
|
| 160 | + public function setResponse(ResponseInterface $response) |
|
| 161 | + { |
|
| 162 | + $this->response = $response; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param LoaderInterface $loader |
|
| 169 | + */ |
|
| 170 | + public function setLoader(LoaderInterface $loader) |
|
| 171 | + { |
|
| 172 | + $this->loader = $loader; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param string $class |
|
| 179 | + * @param array $dependencies |
|
| 180 | + * @param int $overwrite |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public static function register_dependencies( |
|
| 184 | + $class, |
|
| 185 | + array $dependencies, |
|
| 186 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | + ) { |
|
| 188 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | + * to the class specified by the first parameter. |
|
| 196 | + * IMPORTANT !!! |
|
| 197 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | + * the order of the constructor parameters for the class in question. |
|
| 199 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | + * |
|
| 202 | + * @param string $class |
|
| 203 | + * @param array $dependencies |
|
| 204 | + * @param int $overwrite |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function registerDependencies( |
|
| 208 | + $class, |
|
| 209 | + array $dependencies, |
|
| 210 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | + ) { |
|
| 212 | + $class = trim($class, '\\'); |
|
| 213 | + $registered = false; |
|
| 214 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | + } |
|
| 217 | + // we need to make sure that any aliases used when registering a dependency |
|
| 218 | + // get resolved to the correct class name |
|
| 219 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | + $alias = self::$_instance->get_alias($dependency); |
|
| 221 | + if ( |
|
| 222 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | + ) { |
|
| 225 | + unset($dependencies[$dependency]); |
|
| 226 | + $dependencies[$alias] = $load_source; |
|
| 227 | + $registered = true; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + // now add our two lists of dependencies together. |
|
| 231 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | + // especially with numerically indexed arrays |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | + // now we need to ensure that the resulting dependencies |
|
| 238 | + // array only has the entries that are required for the class |
|
| 239 | + // so first count how many dependencies were originally registered for the class |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | + // then truncate the final array to match that count |
|
| 244 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | + // otherwise just take the incoming array because nothing previously existed |
|
| 246 | + : $dependencies; |
|
| 247 | + return $registered; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param string $class_name |
|
| 254 | + * @param string $loader |
|
| 255 | + * @return bool |
|
| 256 | + * @throws DomainException |
|
| 257 | + */ |
|
| 258 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | + { |
|
| 260 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | + throw new DomainException( |
|
| 262 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | + if ( |
|
| 267 | + ! is_callable($loader) |
|
| 268 | + && ( |
|
| 269 | + strpos($loader, 'load_') !== 0 |
|
| 270 | + || ! method_exists('EE_Registry', $loader) |
|
| 271 | + ) |
|
| 272 | + ) { |
|
| 273 | + throw new DomainException( |
|
| 274 | + sprintf( |
|
| 275 | + esc_html__( |
|
| 276 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | + 'event_espresso' |
|
| 278 | + ), |
|
| 279 | + $loader |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | + return true; |
|
| 287 | + } |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return array |
|
| 295 | + */ |
|
| 296 | + public function dependency_map() |
|
| 297 | + { |
|
| 298 | + return $this->_dependency_map; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | + * |
|
| 306 | + * @param string $class_name |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function has($class_name = '') |
|
| 310 | + { |
|
| 311 | + // all legacy models have the same dependencies |
|
| 312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | + $class_name = 'LEGACY_MODELS'; |
|
| 314 | + } |
|
| 315 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | + * |
|
| 323 | + * @param string $class_name |
|
| 324 | + * @param string $dependency |
|
| 325 | + * @return bool |
|
| 326 | + */ |
|
| 327 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | + { |
|
| 329 | + // all legacy models have the same dependencies |
|
| 330 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | + $class_name = 'LEGACY_MODELS'; |
|
| 332 | + } |
|
| 333 | + $dependency = $this->get_alias($dependency); |
|
| 334 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | + ? true |
|
| 336 | + : false; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | + * |
|
| 344 | + * @param string $class_name |
|
| 345 | + * @param string $dependency |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | + { |
|
| 350 | + // all legacy models have the same dependencies |
|
| 351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | + $class_name = 'LEGACY_MODELS'; |
|
| 353 | + } |
|
| 354 | + $dependency = $this->get_alias($dependency); |
|
| 355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | + : EE_Dependency_Map::not_registered; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $class_name |
|
| 364 | + * @return string | Closure |
|
| 365 | + */ |
|
| 366 | + public function class_loader($class_name) |
|
| 367 | + { |
|
| 368 | + // all legacy models use load_model() |
|
| 369 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | + return 'load_model'; |
|
| 371 | + } |
|
| 372 | + $class_name = $this->get_alias($class_name); |
|
| 373 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return array |
|
| 380 | + */ |
|
| 381 | + public function class_loaders() |
|
| 382 | + { |
|
| 383 | + return $this->_class_loaders; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * adds an alias for a classname |
|
| 390 | + * |
|
| 391 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | + */ |
|
| 395 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | + { |
|
| 397 | + if ($for_class !== '') { |
|
| 398 | + if (! isset($this->_aliases[$for_class])) { |
|
| 399 | + $this->_aliases[$for_class] = array(); |
|
| 400 | + } |
|
| 401 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | + } |
|
| 403 | + $this->_aliases[$class_name] = $alias; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * returns TRUE if the provided class name has an alias |
|
| 410 | + * |
|
| 411 | + * @param string $class_name |
|
| 412 | + * @param string $for_class |
|
| 413 | + * @return bool |
|
| 414 | + */ |
|
| 415 | + public function has_alias($class_name = '', $for_class = '') |
|
| 416 | + { |
|
| 417 | + return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | + || ( |
|
| 419 | + isset($this->_aliases[$class_name]) |
|
| 420 | + && ! is_array($this->_aliases[$class_name]) |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | + * for example: |
|
| 430 | + * if the following two entries were added to the _aliases array: |
|
| 431 | + * array( |
|
| 432 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | + * ) |
|
| 435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | + * to load an instance of 'some\namespace\classname' |
|
| 437 | + * |
|
| 438 | + * @param string $class_name |
|
| 439 | + * @param string $for_class |
|
| 440 | + * @return string |
|
| 441 | + */ |
|
| 442 | + public function get_alias($class_name = '', $for_class = '') |
|
| 443 | + { |
|
| 444 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | + return $class_name; |
|
| 446 | + } |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | + } |
|
| 450 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | + * This is done by using the following class constants: |
|
| 459 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | + */ |
|
| 462 | + protected function _register_core_dependencies() |
|
| 463 | + { |
|
| 464 | + $this->_dependency_map = array( |
|
| 465 | + 'EE_Request_Handler' => array( |
|
| 466 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + ), |
|
| 468 | + 'EE_System' => array( |
|
| 469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | + ), |
|
| 474 | + 'EE_Session' => array( |
|
| 475 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + ), |
|
| 479 | + 'EE_Cart' => array( |
|
| 480 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 481 | + ), |
|
| 482 | + 'EE_Front_Controller' => array( |
|
| 483 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 488 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 489 | + ), |
|
| 490 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 491 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 492 | + ), |
|
| 493 | + 'EE_Message_Resource_Manager' => array( |
|
| 494 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 495 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 497 | + ), |
|
| 498 | + 'EE_Message_Factory' => array( |
|
| 499 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EE_messages' => array( |
|
| 502 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + ), |
|
| 504 | + 'EE_Messages_Generator' => array( |
|
| 505 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 506 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 507 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 509 | + ), |
|
| 510 | + 'EE_Messages_Processor' => array( |
|
| 511 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ), |
|
| 513 | + 'EE_Messages_Queue' => array( |
|
| 514 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 515 | + ), |
|
| 516 | + 'EE_Messages_Template_Defaults' => array( |
|
| 517 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 519 | + ), |
|
| 520 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 521 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 522 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 525 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 528 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + ), |
|
| 531 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 532 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 533 | + ), |
|
| 534 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 535 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 536 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 537 | + ), |
|
| 538 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 539 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 540 | + ), |
|
| 541 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 542 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 543 | + ), |
|
| 544 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 545 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 546 | + ), |
|
| 547 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 548 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 549 | + ), |
|
| 550 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 551 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 552 | + ), |
|
| 553 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 554 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 555 | + ), |
|
| 556 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 557 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 558 | + ), |
|
| 559 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 560 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 561 | + ), |
|
| 562 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 563 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + ), |
|
| 565 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 566 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 567 | + ), |
|
| 568 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 569 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 570 | + ), |
|
| 571 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 572 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + ), |
|
| 574 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 575 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + ), |
|
| 577 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 578 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 579 | + ), |
|
| 580 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + ), |
|
| 584 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + ), |
|
| 588 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + ), |
|
| 592 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + ), |
|
| 596 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + ), |
|
| 600 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ), |
|
| 604 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + ), |
|
| 608 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 609 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + ), |
|
| 612 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 613 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ), |
|
| 616 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 617 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 619 | + ), |
|
| 620 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 621 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 622 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | + ), |
|
| 624 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 625 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 626 | + ), |
|
| 627 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 628 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 629 | + ), |
|
| 630 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 631 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + ), |
|
| 633 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 634 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 635 | + ), |
|
| 636 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 637 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 638 | + ), |
|
| 639 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 641 | + ), |
|
| 642 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 643 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 644 | + ), |
|
| 645 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 646 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 647 | + ), |
|
| 648 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 649 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 650 | + ), |
|
| 651 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 652 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 653 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 654 | + ), |
|
| 655 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 656 | + null, |
|
| 657 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 658 | + ), |
|
| 659 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 660 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 661 | + ), |
|
| 662 | + 'LEGACY_MODELS' => array( |
|
| 663 | + null, |
|
| 664 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 665 | + ), |
|
| 666 | + 'EE_Module_Request_Router' => array( |
|
| 667 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 668 | + ), |
|
| 669 | + 'EE_Registration_Processor' => array( |
|
| 670 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 671 | + ), |
|
| 672 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 673 | + null, |
|
| 674 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 675 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 676 | + ), |
|
| 677 | + ); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * Registers how core classes are loaded. |
|
| 684 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 685 | + * 'EE_Request_Handler' => 'load_core' |
|
| 686 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 687 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 688 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 689 | + * 'Some_Class' => function () { |
|
| 690 | + * return new Some_Class(); |
|
| 691 | + * }, |
|
| 692 | + * This is required for instantiating dependencies |
|
| 693 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 694 | + * 'Required_Interface' => function () { |
|
| 695 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 696 | + * }, |
|
| 697 | + * |
|
| 698 | + * @throws InvalidInterfaceException |
|
| 699 | + * @throws InvalidDataTypeException |
|
| 700 | + * @throws InvalidArgumentException |
|
| 701 | + */ |
|
| 702 | + protected function _register_core_class_loaders() |
|
| 703 | + { |
|
| 704 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 705 | + //be used in a closure. |
|
| 706 | + $request = &$this->request; |
|
| 707 | + $response = &$this->response; |
|
| 708 | + $legacy_request = &$this->legacy_request; |
|
| 709 | + // $loader = &$this->loader; |
|
| 710 | + $this->_class_loaders = array( |
|
| 711 | + //load_core |
|
| 712 | + 'EE_Capabilities' => 'load_core', |
|
| 713 | + 'EE_Encryption' => 'load_core', |
|
| 714 | + 'EE_Front_Controller' => 'load_core', |
|
| 715 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 716 | + 'EE_Registry' => 'load_core', |
|
| 717 | + 'EE_Request' => function () use (&$legacy_request) { |
|
| 718 | + return $legacy_request; |
|
| 719 | + }, |
|
| 720 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 721 | + return $request; |
|
| 722 | + }, |
|
| 723 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 724 | + return $response; |
|
| 725 | + }, |
|
| 726 | + 'EE_Request_Handler' => 'load_core', |
|
| 727 | + 'EE_Session' => 'load_core', |
|
| 728 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 729 | + 'EE_System' => 'load_core', |
|
| 730 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 731 | + 'EE_Register_CPTs' => 'load_core', |
|
| 732 | + 'EE_Admin' => 'load_core', |
|
| 733 | + //load_lib |
|
| 734 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 735 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 736 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 737 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 738 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 739 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 740 | + 'EE_Message_Repository' => 'load_lib', |
|
| 741 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 742 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 743 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 744 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 745 | + 'EE_Messages_Generator' => function () { |
|
| 746 | + return EE_Registry::instance()->load_lib( |
|
| 747 | + 'Messages_Generator', |
|
| 748 | + array(), |
|
| 749 | + false, |
|
| 750 | + false |
|
| 751 | + ); |
|
| 752 | + }, |
|
| 753 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 754 | + return EE_Registry::instance()->load_lib( |
|
| 755 | + 'Messages_Template_Defaults', |
|
| 756 | + $arguments, |
|
| 757 | + false, |
|
| 758 | + false |
|
| 759 | + ); |
|
| 760 | + }, |
|
| 761 | + //load_model |
|
| 762 | + // 'EEM_Attendee' => 'load_model', |
|
| 763 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
| 764 | + // 'EEM_Message_Template' => 'load_model', |
|
| 765 | + //load_helper |
|
| 766 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 767 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 768 | + return new EEH_Parse_Shortcodes(); |
|
| 769 | + } |
|
| 770 | + return null; |
|
| 771 | + }, |
|
| 772 | + 'EE_Template_Config' => function () { |
|
| 773 | + return EE_Config::instance()->template_settings; |
|
| 774 | + }, |
|
| 775 | + 'EE_Currency_Config' => function () { |
|
| 776 | + return EE_Config::instance()->currency; |
|
| 777 | + }, |
|
| 778 | + 'EE_Registration_Config' => function () { |
|
| 779 | + return EE_Config::instance()->registration; |
|
| 780 | + }, |
|
| 781 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 782 | + return LoaderFactory::getLoader(); |
|
| 783 | + }, |
|
| 784 | + ); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * can be used for supplying alternate names for classes, |
|
| 791 | + * or for connecting interface names to instantiable classes |
|
| 792 | + */ |
|
| 793 | + protected function _register_core_aliases() |
|
| 794 | + { |
|
| 795 | + $this->_aliases = array( |
|
| 796 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 797 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 798 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 799 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 800 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 801 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 802 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 803 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 804 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 805 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 806 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 807 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 808 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 809 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 810 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 811 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 812 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 813 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 814 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 815 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 816 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 817 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 818 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 819 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 820 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 821 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 822 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 823 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 824 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 825 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 826 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 827 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 828 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 829 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 830 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 831 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 832 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 833 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 834 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 835 | + ); |
|
| 836 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 837 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 845 | + * request Primarily used by unit tests. |
|
| 846 | + * |
|
| 847 | + * @throws InvalidDataTypeException |
|
| 848 | + * @throws InvalidInterfaceException |
|
| 849 | + * @throws InvalidArgumentException |
|
| 850 | + */ |
|
| 851 | + public function reset() |
|
| 852 | + { |
|
| 853 | + $this->_register_core_class_loaders(); |
|
| 854 | + $this->_register_core_dependencies(); |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | 857 | |
| 858 | 858 | } |
@@ -9,14 +9,14 @@ |
||
| 9 | 9 | interface EEI_Request_Stack_Core_App |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * gives the core app a chance to handle the response after the request stack has fully processed |
|
| 14 | - * |
|
| 15 | - * @deprecated 4.9.53 |
|
| 16 | - * @param EE_Request $request |
|
| 17 | - * @param EE_Response $response |
|
| 18 | - */ |
|
| 19 | - public function handle_response(EE_Request $request, EE_Response $response); |
|
| 12 | + /** |
|
| 13 | + * gives the core app a chance to handle the response after the request stack has fully processed |
|
| 14 | + * |
|
| 15 | + * @deprecated 4.9.53 |
|
| 16 | + * @param EE_Request $request |
|
| 17 | + * @param EE_Response $response |
|
| 18 | + */ |
|
| 19 | + public function handle_response(EE_Request $request, EE_Response $response); |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | // End of file EEI_Request_Stack_Core_App.interface.php |
@@ -9,24 +9,24 @@ |
||
| 9 | 9 | interface EEI_Request_Decorator |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * converts a Request to a Response |
|
| 14 | - * can perform their logic either before or after the core application has run like so: |
|
| 15 | - * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
| 16 | - * $this->request = $request; |
|
| 17 | - * $this->response = $response; |
|
| 18 | - * // logic performed BEFORE core app has run |
|
| 19 | - * $this->process_request_stack( $this->request, $this->response ); |
|
| 20 | - * // logic performed AFTER core app has run |
|
| 21 | - * return $response; |
|
| 22 | - * } |
|
| 23 | - * |
|
| 24 | - * @deprecated 4.9.53 |
|
| 25 | - * @param EE_Request $request |
|
| 26 | - * @param EE_Response $response |
|
| 27 | - * @return EE_Response |
|
| 28 | - */ |
|
| 29 | - public function handle_request(EE_Request $request, EE_Response $response); |
|
| 12 | + /** |
|
| 13 | + * converts a Request to a Response |
|
| 14 | + * can perform their logic either before or after the core application has run like so: |
|
| 15 | + * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
| 16 | + * $this->request = $request; |
|
| 17 | + * $this->response = $response; |
|
| 18 | + * // logic performed BEFORE core app has run |
|
| 19 | + * $this->process_request_stack( $this->request, $this->response ); |
|
| 20 | + * // logic performed AFTER core app has run |
|
| 21 | + * return $response; |
|
| 22 | + * } |
|
| 23 | + * |
|
| 24 | + * @deprecated 4.9.53 |
|
| 25 | + * @param EE_Request $request |
|
| 26 | + * @param EE_Response $response |
|
| 27 | + * @return EE_Response |
|
| 28 | + */ |
|
| 29 | + public function handle_request(EE_Request $request, EE_Response $response); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | } |
@@ -18,86 +18,86 @@ |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * load_espresso_addons |
|
| 23 | - * runs during the WP 'plugins_loaded' action at priority 1 |
|
| 24 | - * and is the initial loading phase for EE addons |
|
| 25 | - * no other logic should be performed at this point |
|
| 26 | - */ |
|
| 27 | - public static function load_espresso_addons() |
|
| 28 | - { |
|
| 29 | - do_action('AHEE__EE_Bootstrap__load_espresso_addons'); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * detect_activations_or_upgrades |
|
| 36 | - * runs during the WP 'plugins_loaded' action at priority 3 |
|
| 37 | - * Now that all of the addons have been loaded, |
|
| 38 | - * we can determine if anything needs activating or upgrading |
|
| 39 | - */ |
|
| 40 | - public static function detect_activations_or_upgrades() |
|
| 41 | - { |
|
| 42 | - do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * load_core_configuration |
|
| 49 | - * runs during the WP 'plugins_loaded' action at priority 5 |
|
| 50 | - * Now that the database is assumed to be at the correct version |
|
| 51 | - * we can load and set all of the system configurations |
|
| 52 | - */ |
|
| 53 | - public static function load_core_configuration() |
|
| 54 | - { |
|
| 55 | - do_action('AHEE__EE_Bootstrap__load_core_configuration'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * register_shortcodes_modules_and_widgets |
|
| 62 | - * runs during the WP 'plugins_loaded' action at priority 7 |
|
| 63 | - * and handles registering all o four shortcodes, modules and widgets |
|
| 64 | - * so that they are ready to be used throughout the system |
|
| 65 | - */ |
|
| 66 | - public static function register_shortcodes_modules_and_widgets() |
|
| 67 | - { |
|
| 68 | - do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * brew_espresso |
|
| 75 | - * runs during the WP 'plugins_loaded' action at priority 9 |
|
| 76 | - * bootstrapping is considered complete at this point, |
|
| 77 | - * so let the fun begin... |
|
| 78 | - */ |
|
| 79 | - public static function brew_espresso() |
|
| 80 | - { |
|
| 81 | - do_action('AHEE__EE_Bootstrap__brew_espresso'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @deprecated 4.9.53 |
|
| 88 | - */ |
|
| 89 | - public function run_request_stack() |
|
| 90 | - { |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @deprecated 4.9.53 |
|
| 97 | - */ |
|
| 98 | - public function build_request_stack() |
|
| 99 | - { |
|
| 100 | - } |
|
| 21 | + /** |
|
| 22 | + * load_espresso_addons |
|
| 23 | + * runs during the WP 'plugins_loaded' action at priority 1 |
|
| 24 | + * and is the initial loading phase for EE addons |
|
| 25 | + * no other logic should be performed at this point |
|
| 26 | + */ |
|
| 27 | + public static function load_espresso_addons() |
|
| 28 | + { |
|
| 29 | + do_action('AHEE__EE_Bootstrap__load_espresso_addons'); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * detect_activations_or_upgrades |
|
| 36 | + * runs during the WP 'plugins_loaded' action at priority 3 |
|
| 37 | + * Now that all of the addons have been loaded, |
|
| 38 | + * we can determine if anything needs activating or upgrading |
|
| 39 | + */ |
|
| 40 | + public static function detect_activations_or_upgrades() |
|
| 41 | + { |
|
| 42 | + do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * load_core_configuration |
|
| 49 | + * runs during the WP 'plugins_loaded' action at priority 5 |
|
| 50 | + * Now that the database is assumed to be at the correct version |
|
| 51 | + * we can load and set all of the system configurations |
|
| 52 | + */ |
|
| 53 | + public static function load_core_configuration() |
|
| 54 | + { |
|
| 55 | + do_action('AHEE__EE_Bootstrap__load_core_configuration'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * register_shortcodes_modules_and_widgets |
|
| 62 | + * runs during the WP 'plugins_loaded' action at priority 7 |
|
| 63 | + * and handles registering all o four shortcodes, modules and widgets |
|
| 64 | + * so that they are ready to be used throughout the system |
|
| 65 | + */ |
|
| 66 | + public static function register_shortcodes_modules_and_widgets() |
|
| 67 | + { |
|
| 68 | + do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * brew_espresso |
|
| 75 | + * runs during the WP 'plugins_loaded' action at priority 9 |
|
| 76 | + * bootstrapping is considered complete at this point, |
|
| 77 | + * so let the fun begin... |
|
| 78 | + */ |
|
| 79 | + public static function brew_espresso() |
|
| 80 | + { |
|
| 81 | + do_action('AHEE__EE_Bootstrap__brew_espresso'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @deprecated 4.9.53 |
|
| 88 | + */ |
|
| 89 | + public function run_request_stack() |
|
| 90 | + { |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @deprecated 4.9.53 |
|
| 97 | + */ |
|
| 98 | + public function build_request_stack() |
|
| 99 | + { |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | // End of file EE_Bootstrap.core.php |