@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -22,660 +22,660 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | - */ |
|
| 34 | - const load_new_object = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | - */ |
|
| 40 | - const load_from_cache = 2; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @type EE_Dependency_Map $_instance |
|
| 44 | - */ |
|
| 45 | - protected static $_instance; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @type EE_Request $request |
|
| 49 | - */ |
|
| 50 | - protected $_request; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @type EE_Response $response |
|
| 54 | - */ |
|
| 55 | - protected $_response; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @type LoaderInterface $loader |
|
| 59 | - */ |
|
| 60 | - protected $loader; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @type array $_dependency_map |
|
| 64 | - */ |
|
| 65 | - protected $_dependency_map = array(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @type array $_class_loaders |
|
| 69 | - */ |
|
| 70 | - protected $_class_loaders = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @type array $_aliases |
|
| 74 | - */ |
|
| 75 | - protected $_aliases = array(); |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * EE_Dependency_Map constructor. |
|
| 81 | - * |
|
| 82 | - * @param EE_Request $request |
|
| 83 | - * @param EE_Response $response |
|
| 84 | - */ |
|
| 85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | - { |
|
| 87 | - $this->_request = $request; |
|
| 88 | - $this->_response = $response; |
|
| 89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | - do_action('EE_Dependency_Map____construct'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - * @throws InvalidInterfaceException |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - */ |
|
| 100 | - public function initialize() |
|
| 101 | - { |
|
| 102 | - $this->_register_core_dependencies(); |
|
| 103 | - $this->_register_core_class_loaders(); |
|
| 104 | - $this->_register_core_aliases(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @singleton method used to instantiate class object |
|
| 111 | - * @access public |
|
| 112 | - * @param EE_Request $request |
|
| 113 | - * @param EE_Response $response |
|
| 114 | - * @return EE_Dependency_Map |
|
| 115 | - */ |
|
| 116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | - { |
|
| 118 | - // check if class object is instantiated, and instantiated properly |
|
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | - } |
|
| 122 | - return self::$_instance; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param LoaderInterface $loader |
|
| 129 | - */ |
|
| 130 | - public function setLoader(LoaderInterface $loader) |
|
| 131 | - { |
|
| 132 | - $this->loader = $loader; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param string $class |
|
| 139 | - * @param array $dependencies |
|
| 140 | - * @return boolean |
|
| 141 | - */ |
|
| 142 | - public static function register_dependencies($class, $dependencies) |
|
| 143 | - { |
|
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | - // we need to make sure that any aliases used when registering a dependency |
|
| 146 | - // get resolved to the correct class name |
|
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | - $alias = self::$_instance->get_alias($dependency); |
|
| 149 | - unset($dependencies[$dependency]); |
|
| 150 | - $dependencies[$alias] = $load_source; |
|
| 151 | - } |
|
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $class_name |
|
| 162 | - * @param string $loader |
|
| 163 | - * @return bool |
|
| 164 | - * @throws EE_Error |
|
| 165 | - */ |
|
| 166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | - { |
|
| 168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | - if ( |
|
| 170 | - ! is_callable($loader) |
|
| 171 | - && ( |
|
| 172 | - strpos($loader, 'load_') !== 0 |
|
| 173 | - || ! method_exists('EE_Registry', $loader) |
|
| 174 | - ) |
|
| 175 | - ) { |
|
| 176 | - throw new EE_Error( |
|
| 177 | - sprintf( |
|
| 178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | - $loader |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function dependency_map() |
|
| 197 | - { |
|
| 198 | - return $this->_dependency_map; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | - * |
|
| 206 | - * @param string $class_name |
|
| 207 | - * @return boolean |
|
| 208 | - */ |
|
| 209 | - public function has($class_name = '') |
|
| 210 | - { |
|
| 211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | - * |
|
| 219 | - * @param string $class_name |
|
| 220 | - * @param string $dependency |
|
| 221 | - * @return bool |
|
| 222 | - */ |
|
| 223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | - { |
|
| 225 | - $dependency = $this->get_alias($dependency); |
|
| 226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | - ? true |
|
| 228 | - : false; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | - * |
|
| 236 | - * @param string $class_name |
|
| 237 | - * @param string $dependency |
|
| 238 | - * @return int |
|
| 239 | - */ |
|
| 240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | - { |
|
| 242 | - $dependency = $this->get_alias($dependency); |
|
| 243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | - : EE_Dependency_Map::not_registered; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param string $class_name |
|
| 252 | - * @return string | Closure |
|
| 253 | - */ |
|
| 254 | - public function class_loader($class_name) |
|
| 255 | - { |
|
| 256 | - $class_name = $this->get_alias($class_name); |
|
| 257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @return array |
|
| 264 | - */ |
|
| 265 | - public function class_loaders() |
|
| 266 | - { |
|
| 267 | - return $this->_class_loaders; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * adds an alias for a classname |
|
| 274 | - * |
|
| 275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | - */ |
|
| 279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | - { |
|
| 281 | - if ($for_class !== '') { |
|
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 283 | - $this->_aliases[$for_class] = array(); |
|
| 284 | - } |
|
| 285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | - } |
|
| 287 | - $this->_aliases[$class_name] = $alias; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * returns TRUE if the provided class name has an alias |
|
| 294 | - * |
|
| 295 | - * @param string $class_name |
|
| 296 | - * @param string $for_class |
|
| 297 | - * @return bool |
|
| 298 | - */ |
|
| 299 | - public function has_alias($class_name = '', $for_class = '') |
|
| 300 | - { |
|
| 301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | - || ( |
|
| 303 | - isset($this->_aliases[$class_name]) |
|
| 304 | - && ! is_array($this->_aliases[$class_name]) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | - * for example: |
|
| 314 | - * if the following two entries were added to the _aliases array: |
|
| 315 | - * array( |
|
| 316 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | - * ) |
|
| 319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | - * to load an instance of 'some\namespace\classname' |
|
| 321 | - * |
|
| 322 | - * @param string $class_name |
|
| 323 | - * @param string $for_class |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function get_alias($class_name = '', $for_class = '') |
|
| 327 | - { |
|
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | - return $class_name; |
|
| 330 | - } |
|
| 331 | - if ($for_class !== '') { |
|
| 332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | - } |
|
| 334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | - * This is done by using the following class constants: |
|
| 343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | - */ |
|
| 346 | - protected function _register_core_dependencies() |
|
| 347 | - { |
|
| 348 | - $this->_dependency_map = array( |
|
| 349 | - 'EE_Request_Handler' => array( |
|
| 350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | - ), |
|
| 352 | - 'EE_System' => array( |
|
| 353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | - ), |
|
| 355 | - 'EE_Session' => array( |
|
| 356 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | - ), |
|
| 359 | - 'EE_Cart' => array( |
|
| 360 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | - ), |
|
| 362 | - 'EE_Front_Controller' => array( |
|
| 363 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | - ), |
|
| 367 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | - ), |
|
| 370 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | - ), |
|
| 373 | - 'EE_Message_Resource_Manager' => array( |
|
| 374 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | - ), |
|
| 378 | - 'EE_Message_Factory' => array( |
|
| 379 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | - ), |
|
| 381 | - 'EE_messages' => array( |
|
| 382 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | - ), |
|
| 384 | - 'EE_Messages_Generator' => array( |
|
| 385 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | - ), |
|
| 390 | - 'EE_Messages_Processor' => array( |
|
| 391 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | - ), |
|
| 393 | - 'EE_Messages_Queue' => array( |
|
| 394 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | - ), |
|
| 396 | - 'EE_Messages_Template_Defaults' => array( |
|
| 397 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | - ), |
|
| 400 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | - ), |
|
| 404 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | - ), |
|
| 407 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | - ), |
|
| 411 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | - ), |
|
| 414 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | - ), |
|
| 418 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | - ), |
|
| 421 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | - ), |
|
| 424 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | - ), |
|
| 427 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | - ), |
|
| 430 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | - ), |
|
| 433 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | - ), |
|
| 436 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | - ), |
|
| 439 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - ), |
|
| 445 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - ), |
|
| 448 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | - ), |
|
| 451 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | - ), |
|
| 465 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - ), |
|
| 469 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - ), |
|
| 473 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - ), |
|
| 477 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | - ), |
|
| 481 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - ), |
|
| 485 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | - ), |
|
| 489 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - ), |
|
| 493 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ), |
|
| 497 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - ), |
|
| 504 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | - ), |
|
| 507 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | - ), |
|
| 510 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ), |
|
| 513 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - ), |
|
| 516 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - ), |
|
| 519 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | - ), |
|
| 522 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - 'EventEspresso\core\services\validation\EmailValidationService' => array( |
|
| 529 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 531 | - ) |
|
| 532 | - ); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Registers how core classes are loaded. |
|
| 539 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 540 | - * 'EE_Request_Handler' => 'load_core' |
|
| 541 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 542 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 543 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 544 | - * 'Some_Class' => function () { |
|
| 545 | - * return new Some_Class(); |
|
| 546 | - * }, |
|
| 547 | - * This is required for instantiating dependencies |
|
| 548 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 549 | - * 'Required_Interface' => function () { |
|
| 550 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 551 | - * }, |
|
| 552 | - */ |
|
| 553 | - protected function _register_core_class_loaders() |
|
| 554 | - { |
|
| 555 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 556 | - //be used in a closure. |
|
| 557 | - $request = &$this->_request; |
|
| 558 | - $response = &$this->_response; |
|
| 559 | - $loader = &$this->loader; |
|
| 560 | - $this->_class_loaders = array( |
|
| 561 | - //load_core |
|
| 562 | - 'EE_Capabilities' => 'load_core', |
|
| 563 | - 'EE_Encryption' => 'load_core', |
|
| 564 | - 'EE_Front_Controller' => 'load_core', |
|
| 565 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 566 | - 'EE_Registry' => 'load_core', |
|
| 567 | - 'EE_Request' => function () use (&$request) { |
|
| 568 | - return $request; |
|
| 569 | - }, |
|
| 570 | - 'EE_Response' => function () use (&$response) { |
|
| 571 | - return $response; |
|
| 572 | - }, |
|
| 573 | - 'EE_Request_Handler' => 'load_core', |
|
| 574 | - 'EE_Session' => 'load_core', |
|
| 575 | - 'EE_System' => 'load_core', |
|
| 576 | - //load_lib |
|
| 577 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 578 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 579 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 580 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 581 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 582 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 583 | - 'EE_Message_Repository' => 'load_lib', |
|
| 584 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 585 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 586 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 587 | - 'EE_Messages_Generator' => function () { |
|
| 588 | - return EE_Registry::instance()->load_lib( |
|
| 589 | - 'Messages_Generator', |
|
| 590 | - array(), |
|
| 591 | - false, |
|
| 592 | - false |
|
| 593 | - ); |
|
| 594 | - }, |
|
| 595 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 596 | - return EE_Registry::instance()->load_lib( |
|
| 597 | - 'Messages_Template_Defaults', |
|
| 598 | - $arguments, |
|
| 599 | - false, |
|
| 600 | - false |
|
| 601 | - ); |
|
| 602 | - }, |
|
| 603 | - //load_model |
|
| 604 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 605 | - 'EEM_Message_Template' => 'load_model', |
|
| 606 | - //load_helper |
|
| 607 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 608 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 609 | - return new EEH_Parse_Shortcodes(); |
|
| 610 | - } |
|
| 611 | - return null; |
|
| 612 | - }, |
|
| 613 | - 'EE_Template_Config' => function () { |
|
| 614 | - return EE_Config::instance()->template_settings; |
|
| 615 | - }, |
|
| 616 | - 'EE_Currency_Config' => function () { |
|
| 617 | - return EE_Config::instance()->currency; |
|
| 618 | - }, |
|
| 619 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 620 | - return $loader; |
|
| 621 | - }, |
|
| 622 | - 'EE_Config' => 'load_core' |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * can be used for supplying alternate names for classes, |
|
| 630 | - * or for connecting interface names to instantiable classes |
|
| 631 | - */ |
|
| 632 | - protected function _register_core_aliases() |
|
| 633 | - { |
|
| 634 | - $this->_aliases = array( |
|
| 635 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 636 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 637 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 638 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 639 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 640 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 641 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 642 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 643 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 644 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 645 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 646 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 647 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 648 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 649 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 650 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 651 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 652 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 653 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 654 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 655 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 656 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 657 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 658 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 659 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 660 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 661 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 662 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 663 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\EmailValidatorInterface', |
|
| 664 | - 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' => 'EventEspresso\core\services\validation\EmailValidationService', |
|
| 665 | - ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 672 | - * request Primarily used by unit tests. |
|
| 673 | - */ |
|
| 674 | - public function reset() |
|
| 675 | - { |
|
| 676 | - $this->_register_core_class_loaders(); |
|
| 677 | - $this->_register_core_dependencies(); |
|
| 678 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | + */ |
|
| 34 | + const load_new_object = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | + */ |
|
| 40 | + const load_from_cache = 2; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @type EE_Dependency_Map $_instance |
|
| 44 | + */ |
|
| 45 | + protected static $_instance; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @type EE_Request $request |
|
| 49 | + */ |
|
| 50 | + protected $_request; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @type EE_Response $response |
|
| 54 | + */ |
|
| 55 | + protected $_response; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @type LoaderInterface $loader |
|
| 59 | + */ |
|
| 60 | + protected $loader; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @type array $_dependency_map |
|
| 64 | + */ |
|
| 65 | + protected $_dependency_map = array(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @type array $_class_loaders |
|
| 69 | + */ |
|
| 70 | + protected $_class_loaders = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @type array $_aliases |
|
| 74 | + */ |
|
| 75 | + protected $_aliases = array(); |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * EE_Dependency_Map constructor. |
|
| 81 | + * |
|
| 82 | + * @param EE_Request $request |
|
| 83 | + * @param EE_Response $response |
|
| 84 | + */ |
|
| 85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | + { |
|
| 87 | + $this->_request = $request; |
|
| 88 | + $this->_response = $response; |
|
| 89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | + do_action('EE_Dependency_Map____construct'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + * @throws InvalidInterfaceException |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + */ |
|
| 100 | + public function initialize() |
|
| 101 | + { |
|
| 102 | + $this->_register_core_dependencies(); |
|
| 103 | + $this->_register_core_class_loaders(); |
|
| 104 | + $this->_register_core_aliases(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @singleton method used to instantiate class object |
|
| 111 | + * @access public |
|
| 112 | + * @param EE_Request $request |
|
| 113 | + * @param EE_Response $response |
|
| 114 | + * @return EE_Dependency_Map |
|
| 115 | + */ |
|
| 116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | + { |
|
| 118 | + // check if class object is instantiated, and instantiated properly |
|
| 119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | + } |
|
| 122 | + return self::$_instance; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param LoaderInterface $loader |
|
| 129 | + */ |
|
| 130 | + public function setLoader(LoaderInterface $loader) |
|
| 131 | + { |
|
| 132 | + $this->loader = $loader; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $class |
|
| 139 | + * @param array $dependencies |
|
| 140 | + * @return boolean |
|
| 141 | + */ |
|
| 142 | + public static function register_dependencies($class, $dependencies) |
|
| 143 | + { |
|
| 144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | + // we need to make sure that any aliases used when registering a dependency |
|
| 146 | + // get resolved to the correct class name |
|
| 147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | + $alias = self::$_instance->get_alias($dependency); |
|
| 149 | + unset($dependencies[$dependency]); |
|
| 150 | + $dependencies[$alias] = $load_source; |
|
| 151 | + } |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $class_name |
|
| 162 | + * @param string $loader |
|
| 163 | + * @return bool |
|
| 164 | + * @throws EE_Error |
|
| 165 | + */ |
|
| 166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | + { |
|
| 168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | + if ( |
|
| 170 | + ! is_callable($loader) |
|
| 171 | + && ( |
|
| 172 | + strpos($loader, 'load_') !== 0 |
|
| 173 | + || ! method_exists('EE_Registry', $loader) |
|
| 174 | + ) |
|
| 175 | + ) { |
|
| 176 | + throw new EE_Error( |
|
| 177 | + sprintf( |
|
| 178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | + $loader |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function dependency_map() |
|
| 197 | + { |
|
| 198 | + return $this->_dependency_map; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | + * |
|
| 206 | + * @param string $class_name |
|
| 207 | + * @return boolean |
|
| 208 | + */ |
|
| 209 | + public function has($class_name = '') |
|
| 210 | + { |
|
| 211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | + * |
|
| 219 | + * @param string $class_name |
|
| 220 | + * @param string $dependency |
|
| 221 | + * @return bool |
|
| 222 | + */ |
|
| 223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | + { |
|
| 225 | + $dependency = $this->get_alias($dependency); |
|
| 226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | + ? true |
|
| 228 | + : false; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | + * |
|
| 236 | + * @param string $class_name |
|
| 237 | + * @param string $dependency |
|
| 238 | + * @return int |
|
| 239 | + */ |
|
| 240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | + { |
|
| 242 | + $dependency = $this->get_alias($dependency); |
|
| 243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | + : EE_Dependency_Map::not_registered; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param string $class_name |
|
| 252 | + * @return string | Closure |
|
| 253 | + */ |
|
| 254 | + public function class_loader($class_name) |
|
| 255 | + { |
|
| 256 | + $class_name = $this->get_alias($class_name); |
|
| 257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @return array |
|
| 264 | + */ |
|
| 265 | + public function class_loaders() |
|
| 266 | + { |
|
| 267 | + return $this->_class_loaders; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * adds an alias for a classname |
|
| 274 | + * |
|
| 275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | + */ |
|
| 279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | + { |
|
| 281 | + if ($for_class !== '') { |
|
| 282 | + if (! isset($this->_aliases[$for_class])) { |
|
| 283 | + $this->_aliases[$for_class] = array(); |
|
| 284 | + } |
|
| 285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | + } |
|
| 287 | + $this->_aliases[$class_name] = $alias; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * returns TRUE if the provided class name has an alias |
|
| 294 | + * |
|
| 295 | + * @param string $class_name |
|
| 296 | + * @param string $for_class |
|
| 297 | + * @return bool |
|
| 298 | + */ |
|
| 299 | + public function has_alias($class_name = '', $for_class = '') |
|
| 300 | + { |
|
| 301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | + || ( |
|
| 303 | + isset($this->_aliases[$class_name]) |
|
| 304 | + && ! is_array($this->_aliases[$class_name]) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | + * for example: |
|
| 314 | + * if the following two entries were added to the _aliases array: |
|
| 315 | + * array( |
|
| 316 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | + * ) |
|
| 319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | + * to load an instance of 'some\namespace\classname' |
|
| 321 | + * |
|
| 322 | + * @param string $class_name |
|
| 323 | + * @param string $for_class |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function get_alias($class_name = '', $for_class = '') |
|
| 327 | + { |
|
| 328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | + return $class_name; |
|
| 330 | + } |
|
| 331 | + if ($for_class !== '') { |
|
| 332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | + } |
|
| 334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | + * This is done by using the following class constants: |
|
| 343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | + */ |
|
| 346 | + protected function _register_core_dependencies() |
|
| 347 | + { |
|
| 348 | + $this->_dependency_map = array( |
|
| 349 | + 'EE_Request_Handler' => array( |
|
| 350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | + ), |
|
| 352 | + 'EE_System' => array( |
|
| 353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | + ), |
|
| 355 | + 'EE_Session' => array( |
|
| 356 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | + ), |
|
| 359 | + 'EE_Cart' => array( |
|
| 360 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | + ), |
|
| 362 | + 'EE_Front_Controller' => array( |
|
| 363 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | + ), |
|
| 367 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | + ), |
|
| 370 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | + ), |
|
| 373 | + 'EE_Message_Resource_Manager' => array( |
|
| 374 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | + ), |
|
| 378 | + 'EE_Message_Factory' => array( |
|
| 379 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | + ), |
|
| 381 | + 'EE_messages' => array( |
|
| 382 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | + ), |
|
| 384 | + 'EE_Messages_Generator' => array( |
|
| 385 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | + ), |
|
| 390 | + 'EE_Messages_Processor' => array( |
|
| 391 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | + ), |
|
| 393 | + 'EE_Messages_Queue' => array( |
|
| 394 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | + ), |
|
| 396 | + 'EE_Messages_Template_Defaults' => array( |
|
| 397 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | + ), |
|
| 400 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | + ), |
|
| 404 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | + ), |
|
| 407 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | + ), |
|
| 411 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | + ), |
|
| 414 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | + ), |
|
| 418 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | + ), |
|
| 421 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | + ), |
|
| 424 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | + ), |
|
| 427 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | + ), |
|
| 430 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | + ), |
|
| 433 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | + ), |
|
| 436 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | + ), |
|
| 439 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + ), |
|
| 445 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + ), |
|
| 448 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | + ), |
|
| 451 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | + ), |
|
| 465 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + ), |
|
| 469 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + ), |
|
| 473 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + ), |
|
| 477 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | + ), |
|
| 481 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + ), |
|
| 485 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | + ), |
|
| 489 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + ), |
|
| 493 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ), |
|
| 497 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + ), |
|
| 504 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | + ), |
|
| 507 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | + ), |
|
| 510 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ), |
|
| 513 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + ), |
|
| 516 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + ), |
|
| 519 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | + ), |
|
| 522 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + 'EventEspresso\core\services\validation\EmailValidationService' => array( |
|
| 529 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 531 | + ) |
|
| 532 | + ); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Registers how core classes are loaded. |
|
| 539 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 540 | + * 'EE_Request_Handler' => 'load_core' |
|
| 541 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 542 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 543 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 544 | + * 'Some_Class' => function () { |
|
| 545 | + * return new Some_Class(); |
|
| 546 | + * }, |
|
| 547 | + * This is required for instantiating dependencies |
|
| 548 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 549 | + * 'Required_Interface' => function () { |
|
| 550 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 551 | + * }, |
|
| 552 | + */ |
|
| 553 | + protected function _register_core_class_loaders() |
|
| 554 | + { |
|
| 555 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 556 | + //be used in a closure. |
|
| 557 | + $request = &$this->_request; |
|
| 558 | + $response = &$this->_response; |
|
| 559 | + $loader = &$this->loader; |
|
| 560 | + $this->_class_loaders = array( |
|
| 561 | + //load_core |
|
| 562 | + 'EE_Capabilities' => 'load_core', |
|
| 563 | + 'EE_Encryption' => 'load_core', |
|
| 564 | + 'EE_Front_Controller' => 'load_core', |
|
| 565 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 566 | + 'EE_Registry' => 'load_core', |
|
| 567 | + 'EE_Request' => function () use (&$request) { |
|
| 568 | + return $request; |
|
| 569 | + }, |
|
| 570 | + 'EE_Response' => function () use (&$response) { |
|
| 571 | + return $response; |
|
| 572 | + }, |
|
| 573 | + 'EE_Request_Handler' => 'load_core', |
|
| 574 | + 'EE_Session' => 'load_core', |
|
| 575 | + 'EE_System' => 'load_core', |
|
| 576 | + //load_lib |
|
| 577 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 578 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 579 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 580 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 581 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 582 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 583 | + 'EE_Message_Repository' => 'load_lib', |
|
| 584 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 585 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 586 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 587 | + 'EE_Messages_Generator' => function () { |
|
| 588 | + return EE_Registry::instance()->load_lib( |
|
| 589 | + 'Messages_Generator', |
|
| 590 | + array(), |
|
| 591 | + false, |
|
| 592 | + false |
|
| 593 | + ); |
|
| 594 | + }, |
|
| 595 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 596 | + return EE_Registry::instance()->load_lib( |
|
| 597 | + 'Messages_Template_Defaults', |
|
| 598 | + $arguments, |
|
| 599 | + false, |
|
| 600 | + false |
|
| 601 | + ); |
|
| 602 | + }, |
|
| 603 | + //load_model |
|
| 604 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 605 | + 'EEM_Message_Template' => 'load_model', |
|
| 606 | + //load_helper |
|
| 607 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 608 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 609 | + return new EEH_Parse_Shortcodes(); |
|
| 610 | + } |
|
| 611 | + return null; |
|
| 612 | + }, |
|
| 613 | + 'EE_Template_Config' => function () { |
|
| 614 | + return EE_Config::instance()->template_settings; |
|
| 615 | + }, |
|
| 616 | + 'EE_Currency_Config' => function () { |
|
| 617 | + return EE_Config::instance()->currency; |
|
| 618 | + }, |
|
| 619 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 620 | + return $loader; |
|
| 621 | + }, |
|
| 622 | + 'EE_Config' => 'load_core' |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * can be used for supplying alternate names for classes, |
|
| 630 | + * or for connecting interface names to instantiable classes |
|
| 631 | + */ |
|
| 632 | + protected function _register_core_aliases() |
|
| 633 | + { |
|
| 634 | + $this->_aliases = array( |
|
| 635 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 636 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 637 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 638 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 639 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 640 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 641 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 642 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 643 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 644 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 645 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 646 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 647 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 648 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 649 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 650 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 651 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 652 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 653 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 654 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 655 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 656 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 657 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 658 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 659 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 660 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 661 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 662 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 663 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\EmailValidatorInterface', |
|
| 664 | + 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' => 'EventEspresso\core\services\validation\EmailValidationService', |
|
| 665 | + ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 672 | + * request Primarily used by unit tests. |
|
| 673 | + */ |
|
| 674 | + public function reset() |
|
| 675 | + { |
|
| 676 | + $this->_register_core_class_loaders(); |
|
| 677 | + $this->_register_core_dependencies(); |
|
| 678 | + } |
|
| 679 | 679 | |
| 680 | 680 | |
| 681 | 681 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 117 | 117 | { |
| 118 | 118 | // check if class object is instantiated, and instantiated properly |
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 121 | 121 | } |
| 122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function register_dependencies($class, $dependencies) |
| 143 | 143 | { |
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | 145 | // we need to make sure that any aliases used when registering a dependency |
| 146 | 146 | // get resolved to the correct class name |
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 148 | 148 | $alias = self::$_instance->get_alias($dependency); |
| 149 | 149 | unset($dependencies[$dependency]); |
| 150 | 150 | $dependencies[$alias] = $load_source; |
| 151 | 151 | } |
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
| 153 | 153 | return true; |
| 154 | 154 | } |
| 155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 186 | 186 | return true; |
| 187 | 187 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | public function add_alias($class_name, $alias, $for_class = '') |
| 280 | 280 | { |
| 281 | 281 | if ($for_class !== '') { |
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 282 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 283 | 283 | $this->_aliases[$for_class] = array(); |
| 284 | 284 | } |
| 285 | 285 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | public function get_alias($class_name = '', $for_class = '') |
| 327 | 327 | { |
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 328 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 329 | 329 | return $class_name; |
| 330 | 330 | } |
| 331 | 331 | if ($for_class !== '') { |
@@ -564,10 +564,10 @@ discard block |
||
| 564 | 564 | 'EE_Front_Controller' => 'load_core', |
| 565 | 565 | 'EE_Module_Request_Router' => 'load_core', |
| 566 | 566 | 'EE_Registry' => 'load_core', |
| 567 | - 'EE_Request' => function () use (&$request) { |
|
| 567 | + 'EE_Request' => function() use (&$request) { |
|
| 568 | 568 | return $request; |
| 569 | 569 | }, |
| 570 | - 'EE_Response' => function () use (&$response) { |
|
| 570 | + 'EE_Response' => function() use (&$response) { |
|
| 571 | 571 | return $response; |
| 572 | 572 | }, |
| 573 | 573 | 'EE_Request_Handler' => 'load_core', |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | 'EE_Messages_Queue' => 'load_lib', |
| 585 | 585 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 586 | 586 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 587 | - 'EE_Messages_Generator' => function () { |
|
| 587 | + 'EE_Messages_Generator' => function() { |
|
| 588 | 588 | return EE_Registry::instance()->load_lib( |
| 589 | 589 | 'Messages_Generator', |
| 590 | 590 | array(), |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | false |
| 593 | 593 | ); |
| 594 | 594 | }, |
| 595 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 595 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 596 | 596 | return EE_Registry::instance()->load_lib( |
| 597 | 597 | 'Messages_Template_Defaults', |
| 598 | 598 | $arguments, |
@@ -604,19 +604,19 @@ discard block |
||
| 604 | 604 | 'EEM_Message_Template_Group' => 'load_model', |
| 605 | 605 | 'EEM_Message_Template' => 'load_model', |
| 606 | 606 | //load_helper |
| 607 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 607 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 608 | 608 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 609 | 609 | return new EEH_Parse_Shortcodes(); |
| 610 | 610 | } |
| 611 | 611 | return null; |
| 612 | 612 | }, |
| 613 | - 'EE_Template_Config' => function () { |
|
| 613 | + 'EE_Template_Config' => function() { |
|
| 614 | 614 | return EE_Config::instance()->template_settings; |
| 615 | 615 | }, |
| 616 | - 'EE_Currency_Config' => function () { |
|
| 616 | + 'EE_Currency_Config' => function() { |
|
| 617 | 617 | return EE_Config::instance()->currency; |
| 618 | 618 | }, |
| 619 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 619 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
| 620 | 620 | return $loader; |
| 621 | 621 | }, |
| 622 | 622 | 'EE_Config' => 'load_core' |
@@ -18,76 +18,76 @@ |
||
| 18 | 18 | class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param null $validation_error_message |
|
| 23 | - */ |
|
| 24 | - public function __construct($validation_error_message = null) |
|
| 25 | - { |
|
| 26 | - if (! $validation_error_message) { |
|
| 27 | - $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
|
| 28 | - } |
|
| 29 | - parent::__construct($validation_error_message); |
|
| 30 | - } |
|
| 21 | + /** |
|
| 22 | + * @param null $validation_error_message |
|
| 23 | + */ |
|
| 24 | + public function __construct($validation_error_message = null) |
|
| 25 | + { |
|
| 26 | + if (! $validation_error_message) { |
|
| 27 | + $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
|
| 28 | + } |
|
| 29 | + parent::__construct($validation_error_message); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * just checks the field isn't blank |
|
| 36 | - * |
|
| 37 | - * @param $normalized_value |
|
| 38 | - * @return bool |
|
| 39 | - * @throws InvalidArgumentException |
|
| 40 | - * @throws InvalidInterfaceException |
|
| 41 | - * @throws InvalidDataTypeException |
|
| 42 | - * @throws EE_Validation_Error |
|
| 43 | - */ |
|
| 44 | - public function validate($normalized_value) |
|
| 45 | - { |
|
| 46 | - if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
| 47 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 48 | - } |
|
| 49 | - return true; |
|
| 50 | - } |
|
| 34 | + /** |
|
| 35 | + * just checks the field isn't blank |
|
| 36 | + * |
|
| 37 | + * @param $normalized_value |
|
| 38 | + * @return bool |
|
| 39 | + * @throws InvalidArgumentException |
|
| 40 | + * @throws InvalidInterfaceException |
|
| 41 | + * @throws InvalidDataTypeException |
|
| 42 | + * @throws EE_Validation_Error |
|
| 43 | + */ |
|
| 44 | + public function validate($normalized_value) |
|
| 45 | + { |
|
| 46 | + if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
| 47 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 48 | + } |
|
| 49 | + return true; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function get_jquery_validation_rule_array() |
|
| 58 | - { |
|
| 59 | - return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function get_jquery_validation_rule_array() |
|
| 58 | + { |
|
| 59 | + return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Validate an email address. |
|
| 66 | - * Provide email address (raw input) |
|
| 67 | - * |
|
| 68 | - * @param $email |
|
| 69 | - * @return bool of whether the email is valid or not |
|
| 70 | - * @throws InvalidArgumentException |
|
| 71 | - * @throws InvalidInterfaceException |
|
| 72 | - * @throws InvalidDataTypeException |
|
| 73 | - * @throws EE_Validation_Error |
|
| 74 | - */ |
|
| 75 | - private function _validate_email($email) |
|
| 76 | - { |
|
| 77 | - $loader = new Loader(); |
|
| 78 | - $validation_service = $loader->getShared( |
|
| 79 | - 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' |
|
| 80 | - ); |
|
| 81 | - try { |
|
| 82 | - $validation_service->validate($email); |
|
| 83 | - } catch (EmailValidationException $e) { |
|
| 84 | - throw new EE_Validation_Error( |
|
| 85 | - $e->getMessage(), |
|
| 86 | - 'invalid_email', |
|
| 87 | - $this->_input, |
|
| 88 | - $e |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 64 | + /** |
|
| 65 | + * Validate an email address. |
|
| 66 | + * Provide email address (raw input) |
|
| 67 | + * |
|
| 68 | + * @param $email |
|
| 69 | + * @return bool of whether the email is valid or not |
|
| 70 | + * @throws InvalidArgumentException |
|
| 71 | + * @throws InvalidInterfaceException |
|
| 72 | + * @throws InvalidDataTypeException |
|
| 73 | + * @throws EE_Validation_Error |
|
| 74 | + */ |
|
| 75 | + private function _validate_email($email) |
|
| 76 | + { |
|
| 77 | + $loader = new Loader(); |
|
| 78 | + $validation_service = $loader->getShared( |
|
| 79 | + 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' |
|
| 80 | + ); |
|
| 81 | + try { |
|
| 82 | + $validation_service->validate($email); |
|
| 83 | + } catch (EmailValidationException $e) { |
|
| 84 | + throw new EE_Validation_Error( |
|
| 85 | + $e->getMessage(), |
|
| 86 | + 'invalid_email', |
|
| 87 | + $this->_input, |
|
| 88 | + $e |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -20,117 +20,117 @@ |
||
| 20 | 20 | class Basic implements EmailValidatorInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param string $email_address |
|
| 25 | - * @return bool |
|
| 26 | - * @throws EmailValidationException |
|
| 27 | - */ |
|
| 28 | - public function validate($email_address) |
|
| 29 | - { |
|
| 30 | - if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
| 31 | - // email not in correct {string}@{string} format |
|
| 32 | - throw new EmailValidationException( |
|
| 33 | - esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
| 34 | - ); |
|
| 35 | - } |
|
| 36 | - $atIndex = $this->getAtIndex($email_address); |
|
| 37 | - $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
| 38 | - $localLen = strlen($local); |
|
| 39 | - if ($localLen < 1) { |
|
| 40 | - //no local part |
|
| 41 | - throw new EmailValidationException( |
|
| 42 | - esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - if ($localLen > 64) { |
|
| 46 | - // local part length exceeded |
|
| 47 | - throw new EmailValidationException( |
|
| 48 | - esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - if ($local[0] === '.') { |
|
| 52 | - // local part starts with '.' |
|
| 53 | - throw new EmailValidationException( |
|
| 54 | - esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - if ($local[$localLen - 1] === '.') { |
|
| 58 | - // local part starts or ends with '.' |
|
| 59 | - throw new EmailValidationException( |
|
| 60 | - esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - if (preg_match('/\\.\\./', $local)) { |
|
| 64 | - // local part has two consecutive dots |
|
| 65 | - throw new EmailValidationException( |
|
| 66 | - esc_html__( |
|
| 67 | - 'Email local-part (before the @) must not have two consecutive periods.', |
|
| 68 | - 'event_espresso' |
|
| 69 | - ) |
|
| 70 | - ); |
|
| 71 | - } |
|
| 72 | - $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
| 73 | - $domainLen = strlen($domain); |
|
| 74 | - if ($domainLen < 1) { |
|
| 75 | - throw new EmailValidationException( |
|
| 76 | - esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - if ($domainLen > 255) { |
|
| 80 | - // domain part length exceeded |
|
| 81 | - throw new EmailValidationException( |
|
| 82 | - esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - if (preg_match('/\\.\\./', $domain)) { |
|
| 86 | - // domain part has two consecutive dots |
|
| 87 | - throw new EmailValidationException( |
|
| 88 | - esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * returns the location of the @ symbol |
|
| 98 | - * |
|
| 99 | - * @param string $email_address |
|
| 100 | - * @return bool|string |
|
| 101 | - */ |
|
| 102 | - protected function getAtIndex($email_address) |
|
| 103 | - { |
|
| 104 | - return strrpos($email_address, '@'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Gets the local part of the email |
|
| 111 | - * |
|
| 112 | - * @param string $email_address |
|
| 113 | - * @param bool|int $atIndex |
|
| 114 | - * @return bool|string |
|
| 115 | - */ |
|
| 116 | - protected function getLocalPartOfEmail($email_address, $atIndex) |
|
| 117 | - { |
|
| 118 | - return substr($email_address, 0, $atIndex); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Gets the domain part of the email |
|
| 125 | - * |
|
| 126 | - * @param string $email_address |
|
| 127 | - * @param bool|int $atIndex |
|
| 128 | - * @return bool|string |
|
| 129 | - */ |
|
| 130 | - protected function getDomainPartOfEmail($email_address, $atIndex) |
|
| 131 | - { |
|
| 132 | - return substr($email_address, $atIndex + 1); |
|
| 133 | - } |
|
| 23 | + /** |
|
| 24 | + * @param string $email_address |
|
| 25 | + * @return bool |
|
| 26 | + * @throws EmailValidationException |
|
| 27 | + */ |
|
| 28 | + public function validate($email_address) |
|
| 29 | + { |
|
| 30 | + if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
| 31 | + // email not in correct {string}@{string} format |
|
| 32 | + throw new EmailValidationException( |
|
| 33 | + esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | + $atIndex = $this->getAtIndex($email_address); |
|
| 37 | + $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
| 38 | + $localLen = strlen($local); |
|
| 39 | + if ($localLen < 1) { |
|
| 40 | + //no local part |
|
| 41 | + throw new EmailValidationException( |
|
| 42 | + esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + if ($localLen > 64) { |
|
| 46 | + // local part length exceeded |
|
| 47 | + throw new EmailValidationException( |
|
| 48 | + esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + if ($local[0] === '.') { |
|
| 52 | + // local part starts with '.' |
|
| 53 | + throw new EmailValidationException( |
|
| 54 | + esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + if ($local[$localLen - 1] === '.') { |
|
| 58 | + // local part starts or ends with '.' |
|
| 59 | + throw new EmailValidationException( |
|
| 60 | + esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + if (preg_match('/\\.\\./', $local)) { |
|
| 64 | + // local part has two consecutive dots |
|
| 65 | + throw new EmailValidationException( |
|
| 66 | + esc_html__( |
|
| 67 | + 'Email local-part (before the @) must not have two consecutive periods.', |
|
| 68 | + 'event_espresso' |
|
| 69 | + ) |
|
| 70 | + ); |
|
| 71 | + } |
|
| 72 | + $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
| 73 | + $domainLen = strlen($domain); |
|
| 74 | + if ($domainLen < 1) { |
|
| 75 | + throw new EmailValidationException( |
|
| 76 | + esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + if ($domainLen > 255) { |
|
| 80 | + // domain part length exceeded |
|
| 81 | + throw new EmailValidationException( |
|
| 82 | + esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + if (preg_match('/\\.\\./', $domain)) { |
|
| 86 | + // domain part has two consecutive dots |
|
| 87 | + throw new EmailValidationException( |
|
| 88 | + esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * returns the location of the @ symbol |
|
| 98 | + * |
|
| 99 | + * @param string $email_address |
|
| 100 | + * @return bool|string |
|
| 101 | + */ |
|
| 102 | + protected function getAtIndex($email_address) |
|
| 103 | + { |
|
| 104 | + return strrpos($email_address, '@'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Gets the local part of the email |
|
| 111 | + * |
|
| 112 | + * @param string $email_address |
|
| 113 | + * @param bool|int $atIndex |
|
| 114 | + * @return bool|string |
|
| 115 | + */ |
|
| 116 | + protected function getLocalPartOfEmail($email_address, $atIndex) |
|
| 117 | + { |
|
| 118 | + return substr($email_address, 0, $atIndex); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Gets the domain part of the email |
|
| 125 | + * |
|
| 126 | + * @param string $email_address |
|
| 127 | + * @param bool|int $atIndex |
|
| 128 | + * @return bool|string |
|
| 129 | + */ |
|
| 130 | + protected function getDomainPartOfEmail($email_address, $atIndex) |
|
| 131 | + { |
|
| 132 | + return substr($email_address, $atIndex + 1); |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | // End of file Basic.php |
| 136 | 136 | // Location: core\services\validation/Basic.php |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function validate($email_address) |
| 29 | 29 | { |
| 30 | - if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
| 30 | + if ( ! preg_match('/^.+\@\S+$/', $email_address)) { |
|
| 31 | 31 | // email not in correct {string}@{string} format |
| 32 | 32 | throw new EmailValidationException( |
| 33 | 33 | esc_html__('Email does not have the required @ sign.', 'event_espresso') |
@@ -20,44 +20,44 @@ |
||
| 20 | 20 | class InternationalDNS extends International |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Validates the email in teh same way as the parent, but also |
|
| 25 | - * verifies the domain exists. |
|
| 26 | - * @param string $email_address |
|
| 27 | - * @return bool |
|
| 28 | - * @throws EmailValidationException |
|
| 29 | - */ |
|
| 30 | - public function validate($email_address) |
|
| 31 | - { |
|
| 32 | - parent::validate($email_address); |
|
| 33 | - $domain = $this->getDomainPartOfEmail( |
|
| 34 | - $email_address, |
|
| 35 | - $this->getAtIndex($email_address) |
|
| 36 | - ); |
|
| 37 | - if (! checkdnsrr($domain, 'MX')) { |
|
| 38 | - // domain not found in MX records |
|
| 39 | - throw new EmailValidationException( |
|
| 40 | - __( |
|
| 41 | - // @codingStandardsIgnoreStart |
|
| 42 | - 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
| 43 | - // @codingStandardsIgnoreEnd |
|
| 44 | - 'event_espresso' |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 47 | - } |
|
| 48 | - if (! checkdnsrr($domain, 'A')) { |
|
| 49 | - // domain not found in A records |
|
| 50 | - throw new EmailValidationException( |
|
| 51 | - __( |
|
| 52 | - // @codingStandardsIgnoreStart |
|
| 53 | - 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
| 54 | - // @codingStandardsIgnoreEnd |
|
| 55 | - 'event_espresso' |
|
| 56 | - ) |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 23 | + /** |
|
| 24 | + * Validates the email in teh same way as the parent, but also |
|
| 25 | + * verifies the domain exists. |
|
| 26 | + * @param string $email_address |
|
| 27 | + * @return bool |
|
| 28 | + * @throws EmailValidationException |
|
| 29 | + */ |
|
| 30 | + public function validate($email_address) |
|
| 31 | + { |
|
| 32 | + parent::validate($email_address); |
|
| 33 | + $domain = $this->getDomainPartOfEmail( |
|
| 34 | + $email_address, |
|
| 35 | + $this->getAtIndex($email_address) |
|
| 36 | + ); |
|
| 37 | + if (! checkdnsrr($domain, 'MX')) { |
|
| 38 | + // domain not found in MX records |
|
| 39 | + throw new EmailValidationException( |
|
| 40 | + __( |
|
| 41 | + // @codingStandardsIgnoreStart |
|
| 42 | + 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
| 43 | + // @codingStandardsIgnoreEnd |
|
| 44 | + 'event_espresso' |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | + if (! checkdnsrr($domain, 'A')) { |
|
| 49 | + // domain not found in A records |
|
| 50 | + throw new EmailValidationException( |
|
| 51 | + __( |
|
| 52 | + // @codingStandardsIgnoreStart |
|
| 53 | + 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
| 54 | + // @codingStandardsIgnoreEnd |
|
| 55 | + 'event_espresso' |
|
| 56 | + ) |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $email_address, |
| 35 | 35 | $this->getAtIndex($email_address) |
| 36 | 36 | ); |
| 37 | - if (! checkdnsrr($domain, 'MX')) { |
|
| 37 | + if ( ! checkdnsrr($domain, 'MX')) { |
|
| 38 | 38 | // domain not found in MX records |
| 39 | 39 | throw new EmailValidationException( |
| 40 | 40 | __( |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | ) |
| 46 | 46 | ); |
| 47 | 47 | } |
| 48 | - if (! checkdnsrr($domain, 'A')) { |
|
| 48 | + if ( ! checkdnsrr($domain, 'A')) { |
|
| 49 | 49 | // domain not found in A records |
| 50 | 50 | throw new EmailValidationException( |
| 51 | 51 | __( |
@@ -20,28 +20,28 @@ |
||
| 20 | 20 | class International extends Basic |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param string $email_address |
|
| 25 | - * @return bool |
|
| 26 | - * @throws EmailValidationException |
|
| 27 | - */ |
|
| 28 | - public function validate($email_address) |
|
| 29 | - { |
|
| 30 | - parent::validate($email_address); |
|
| 31 | - if (// plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
| 32 | - ! preg_match( |
|
| 33 | - // @codingStandardsIgnoreStart |
|
| 34 | - '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
| 35 | - // @codingStandardsIgnoreEnd |
|
| 36 | - $email_address |
|
| 37 | - ) |
|
| 38 | - ) { |
|
| 39 | - throw new EmailValidationException( |
|
| 40 | - esc_html__('Email address is invalid.', 'event_espresso') |
|
| 41 | - ); |
|
| 42 | - } |
|
| 43 | - return true; |
|
| 44 | - } |
|
| 23 | + /** |
|
| 24 | + * @param string $email_address |
|
| 25 | + * @return bool |
|
| 26 | + * @throws EmailValidationException |
|
| 27 | + */ |
|
| 28 | + public function validate($email_address) |
|
| 29 | + { |
|
| 30 | + parent::validate($email_address); |
|
| 31 | + if (// plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
| 32 | + ! preg_match( |
|
| 33 | + // @codingStandardsIgnoreStart |
|
| 34 | + '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
| 35 | + // @codingStandardsIgnoreEnd |
|
| 36 | + $email_address |
|
| 37 | + ) |
|
| 38 | + ) { |
|
| 39 | + throw new EmailValidationException( |
|
| 40 | + esc_html__('Email address is invalid.', 'event_espresso') |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | + return true; |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | // End of file International.php |
| 47 | 47 | // Location: core\services\validation/International.php |
@@ -20,22 +20,22 @@ |
||
| 20 | 20 | class WordPress extends Basic |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * |
|
| 25 | - * @param string $email_address |
|
| 26 | - * @return boolean |
|
| 27 | - * @throws EmailValidationException |
|
| 28 | - */ |
|
| 29 | - public function validate($email_address) |
|
| 30 | - { |
|
| 31 | - parent::validate($email_address); |
|
| 32 | - if( ! is_email($email_address)){ |
|
| 33 | - throw new EmailValidationException( |
|
| 34 | - esc_html__('The email address provided is not valid.', 'event_espresso') |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - return true; |
|
| 38 | - } |
|
| 23 | + /** |
|
| 24 | + * |
|
| 25 | + * @param string $email_address |
|
| 26 | + * @return boolean |
|
| 27 | + * @throws EmailValidationException |
|
| 28 | + */ |
|
| 29 | + public function validate($email_address) |
|
| 30 | + { |
|
| 31 | + parent::validate($email_address); |
|
| 32 | + if( ! is_email($email_address)){ |
|
| 33 | + throw new EmailValidationException( |
|
| 34 | + esc_html__('The email address provided is not valid.', 'event_espresso') |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + return true; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | public function validate($email_address) |
| 30 | 30 | { |
| 31 | 31 | parent::validate($email_address); |
| 32 | - if( ! is_email($email_address)){ |
|
| 32 | + if ( ! is_email($email_address)) { |
|
| 33 | 33 | throw new EmailValidationException( |
| 34 | 34 | esc_html__('The email address provided is not valid.', 'event_espresso') |
| 35 | 35 | ); |
@@ -23,69 +23,69 @@ |
||
| 23 | 23 | class EmailValidationService implements EmailValidatorInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Config $config |
|
| 28 | - */ |
|
| 29 | - protected $config; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var Loader $loader |
|
| 33 | - */ |
|
| 34 | - protected $loader; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * EmailValidationService constructor. |
|
| 40 | - * Accepts an \EE_Config as an argument. |
|
| 41 | - * |
|
| 42 | - * @param EE_Config $config |
|
| 43 | - * @param Loader $loader |
|
| 44 | - */ |
|
| 45 | - public function __construct(EE_Config $config, Loader $loader) |
|
| 46 | - { |
|
| 47 | - $this->config = $config; |
|
| 48 | - $this->loader = $loader; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Validates the email address. If it's invalid, an EmailValidationException |
|
| 55 | - * is thrown that describes why its invalid. |
|
| 56 | - * |
|
| 57 | - * @param string $email_address |
|
| 58 | - * @return boolean |
|
| 59 | - * @throws EmailValidationException |
|
| 60 | - */ |
|
| 61 | - public function validate($email_address) |
|
| 62 | - { |
|
| 63 | - //pick the correct validator according to the config |
|
| 64 | - switch ($this->config->registration->email_validation_level) { |
|
| 65 | - case 'basic': |
|
| 66 | - $validator = $this->loader->getShared( |
|
| 67 | - 'EventEspresso\core\services\validation\strategies\Basic' |
|
| 68 | - ); |
|
| 69 | - break; |
|
| 70 | - case 'i18n': |
|
| 71 | - $validator = $this->loader->getShared( |
|
| 72 | - 'EventEspresso\core\services\validation\strategies\International' |
|
| 73 | - ) ; |
|
| 74 | - break; |
|
| 75 | - case 'i18n_dns': |
|
| 76 | - $validator = $this->loader->getShared( |
|
| 77 | - 'EventEspresso\core\services\validation\strategies\InternationalDNS' |
|
| 78 | - ) ; |
|
| 79 | - break; |
|
| 80 | - case 'wp_default': |
|
| 81 | - default: |
|
| 82 | - $validator = $this->loader->getShared( |
|
| 83 | - 'EventEspresso\core\services\validation\strategies\WordPress' |
|
| 84 | - ) ; |
|
| 85 | - break; |
|
| 86 | - } |
|
| 87 | - return $validator->validate($email_address); |
|
| 88 | - } |
|
| 26 | + /** |
|
| 27 | + * @var EE_Config $config |
|
| 28 | + */ |
|
| 29 | + protected $config; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var Loader $loader |
|
| 33 | + */ |
|
| 34 | + protected $loader; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * EmailValidationService constructor. |
|
| 40 | + * Accepts an \EE_Config as an argument. |
|
| 41 | + * |
|
| 42 | + * @param EE_Config $config |
|
| 43 | + * @param Loader $loader |
|
| 44 | + */ |
|
| 45 | + public function __construct(EE_Config $config, Loader $loader) |
|
| 46 | + { |
|
| 47 | + $this->config = $config; |
|
| 48 | + $this->loader = $loader; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Validates the email address. If it's invalid, an EmailValidationException |
|
| 55 | + * is thrown that describes why its invalid. |
|
| 56 | + * |
|
| 57 | + * @param string $email_address |
|
| 58 | + * @return boolean |
|
| 59 | + * @throws EmailValidationException |
|
| 60 | + */ |
|
| 61 | + public function validate($email_address) |
|
| 62 | + { |
|
| 63 | + //pick the correct validator according to the config |
|
| 64 | + switch ($this->config->registration->email_validation_level) { |
|
| 65 | + case 'basic': |
|
| 66 | + $validator = $this->loader->getShared( |
|
| 67 | + 'EventEspresso\core\services\validation\strategies\Basic' |
|
| 68 | + ); |
|
| 69 | + break; |
|
| 70 | + case 'i18n': |
|
| 71 | + $validator = $this->loader->getShared( |
|
| 72 | + 'EventEspresso\core\services\validation\strategies\International' |
|
| 73 | + ) ; |
|
| 74 | + break; |
|
| 75 | + case 'i18n_dns': |
|
| 76 | + $validator = $this->loader->getShared( |
|
| 77 | + 'EventEspresso\core\services\validation\strategies\InternationalDNS' |
|
| 78 | + ) ; |
|
| 79 | + break; |
|
| 80 | + case 'wp_default': |
|
| 81 | + default: |
|
| 82 | + $validator = $this->loader->getShared( |
|
| 83 | + 'EventEspresso\core\services\validation\strategies\WordPress' |
|
| 84 | + ) ; |
|
| 85 | + break; |
|
| 86 | + } |
|
| 87 | + return $validator->validate($email_address); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | } |
@@ -70,18 +70,18 @@ |
||
| 70 | 70 | case 'i18n': |
| 71 | 71 | $validator = $this->loader->getShared( |
| 72 | 72 | 'EventEspresso\core\services\validation\strategies\International' |
| 73 | - ) ; |
|
| 73 | + ); |
|
| 74 | 74 | break; |
| 75 | 75 | case 'i18n_dns': |
| 76 | 76 | $validator = $this->loader->getShared( |
| 77 | 77 | 'EventEspresso\core\services\validation\strategies\InternationalDNS' |
| 78 | - ) ; |
|
| 78 | + ); |
|
| 79 | 79 | break; |
| 80 | 80 | case 'wp_default': |
| 81 | 81 | default: |
| 82 | 82 | $validator = $this->loader->getShared( |
| 83 | 83 | 'EventEspresso\core\services\validation\strategies\WordPress' |
| 84 | - ) ; |
|
| 84 | + ); |
|
| 85 | 85 | break; |
| 86 | 86 | } |
| 87 | 87 | return $validator->validate($email_address); |
@@ -18,14 +18,14 @@ |
||
| 18 | 18 | interface EmailValidatorInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
| 23 | - * |
|
| 24 | - * @param string $email_address |
|
| 25 | - * @return boolean |
|
| 26 | - * @throws EmailValidationException |
|
| 27 | - */ |
|
| 28 | - public function validate($email_address); |
|
| 21 | + /** |
|
| 22 | + * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
| 23 | + * |
|
| 24 | + * @param string $email_address |
|
| 25 | + * @return boolean |
|
| 26 | + * @throws EmailValidationException |
|
| 27 | + */ |
|
| 28 | + public function validate($email_address); |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | } |
@@ -14,41 +14,41 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Email_Field extends EE_Text_Field_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @param string $table_column |
|
| 19 | - * @param string $nicename |
|
| 20 | - * @param bool $nullable |
|
| 21 | - * @param null $default_value |
|
| 22 | - */ |
|
| 23 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 24 | - { |
|
| 25 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 26 | - $this->setSchemaFormat('email'); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $table_column |
|
| 19 | + * @param string $nicename |
|
| 20 | + * @param bool $nullable |
|
| 21 | + * @param null $default_value |
|
| 22 | + */ |
|
| 23 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 24 | + { |
|
| 25 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 26 | + $this->setSchemaFormat('email'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
| 33 | - * so we need to undo that on setting of these fields |
|
| 34 | - * |
|
| 35 | - * @param string $email_address |
|
| 36 | - * @return string |
|
| 37 | - * @throws InvalidArgumentException |
|
| 38 | - * @throws InvalidInterfaceException |
|
| 39 | - * @throws InvalidDataTypeException |
|
| 40 | - */ |
|
| 41 | - public function prepare_for_set($email_address) |
|
| 42 | - { |
|
| 43 | - $loader = new Loader(); |
|
| 44 | - $validation_service = $loader->getShared( |
|
| 45 | - 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' |
|
| 46 | - ); |
|
| 47 | - try { |
|
| 48 | - $validation_service->validate($email_address); |
|
| 49 | - return $email_address; |
|
| 50 | - } catch (EmailValidationException $e) { |
|
| 51 | - return ''; |
|
| 52 | - } |
|
| 53 | - } |
|
| 31 | + /** |
|
| 32 | + * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
| 33 | + * so we need to undo that on setting of these fields |
|
| 34 | + * |
|
| 35 | + * @param string $email_address |
|
| 36 | + * @return string |
|
| 37 | + * @throws InvalidArgumentException |
|
| 38 | + * @throws InvalidInterfaceException |
|
| 39 | + * @throws InvalidDataTypeException |
|
| 40 | + */ |
|
| 41 | + public function prepare_for_set($email_address) |
|
| 42 | + { |
|
| 43 | + $loader = new Loader(); |
|
| 44 | + $validation_service = $loader->getShared( |
|
| 45 | + 'EventEspresso\core\domain\services\validation\EmailValidatorInterface' |
|
| 46 | + ); |
|
| 47 | + try { |
|
| 48 | + $validation_service->validate($email_address); |
|
| 49 | + return $email_address; |
|
| 50 | + } catch (EmailValidationException $e) { |
|
| 51 | + return ''; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | } |