@@ -20,976 +20,976 @@ |
||
| 20 | 20 | class EE_Dependency_Map |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * This means that the requested class dependency is not present in the dependency map |
|
| 25 | - */ |
|
| 26 | - const not_registered = 0; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | - */ |
|
| 31 | - const load_new_object = 1; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | - */ |
|
| 37 | - const load_from_cache = 2; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * When registering a dependency, |
|
| 41 | - * this indicates to keep any existing dependencies that already exist, |
|
| 42 | - * and simply discard any new dependencies declared in the incoming data |
|
| 43 | - */ |
|
| 44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * When registering a dependency, |
|
| 48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | - */ |
|
| 50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @type EE_Dependency_Map $_instance |
|
| 55 | - */ |
|
| 56 | - protected static $_instance; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var ClassInterfaceCache $class_cache |
|
| 60 | - */ |
|
| 61 | - private $class_cache; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @type RequestInterface $request |
|
| 65 | - */ |
|
| 66 | - protected $request; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @type LegacyRequestInterface $legacy_request |
|
| 70 | - */ |
|
| 71 | - protected $legacy_request; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @type ResponseInterface $response |
|
| 75 | - */ |
|
| 76 | - protected $response; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @type LoaderInterface $loader |
|
| 80 | - */ |
|
| 81 | - protected $loader; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @type array $_dependency_map |
|
| 85 | - */ |
|
| 86 | - protected $_dependency_map = array(); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @type array $_class_loaders |
|
| 90 | - */ |
|
| 91 | - protected $_class_loaders = array(); |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * EE_Dependency_Map constructor. |
|
| 96 | - * |
|
| 97 | - * @param ClassInterfaceCache $class_cache |
|
| 98 | - */ |
|
| 99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | - { |
|
| 101 | - $this->class_cache = $class_cache; |
|
| 102 | - do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return void |
|
| 108 | - */ |
|
| 109 | - public function initialize() |
|
| 110 | - { |
|
| 111 | - $this->_register_core_dependencies(); |
|
| 112 | - $this->_register_core_class_loaders(); |
|
| 113 | - $this->_register_core_aliases(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @singleton method used to instantiate class object |
|
| 119 | - * @param ClassInterfaceCache|null $class_cache |
|
| 120 | - * @return EE_Dependency_Map |
|
| 121 | - */ |
|
| 122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 123 | - { |
|
| 124 | - // check if class object is instantiated, and instantiated properly |
|
| 125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
| 126 | - && $class_cache instanceof ClassInterfaceCache |
|
| 127 | - ) { |
|
| 128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
| 129 | - } |
|
| 130 | - return self::$_instance; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param RequestInterface $request |
|
| 136 | - */ |
|
| 137 | - public function setRequest(RequestInterface $request) |
|
| 138 | - { |
|
| 139 | - $this->request = $request; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param LegacyRequestInterface $legacy_request |
|
| 145 | - */ |
|
| 146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 147 | - { |
|
| 148 | - $this->legacy_request = $legacy_request; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param ResponseInterface $response |
|
| 154 | - */ |
|
| 155 | - public function setResponse(ResponseInterface $response) |
|
| 156 | - { |
|
| 157 | - $this->response = $response; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param LoaderInterface $loader |
|
| 163 | - */ |
|
| 164 | - public function setLoader(LoaderInterface $loader) |
|
| 165 | - { |
|
| 166 | - $this->loader = $loader; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $class |
|
| 172 | - * @param array $dependencies |
|
| 173 | - * @param int $overwrite |
|
| 174 | - * @return bool |
|
| 175 | - */ |
|
| 176 | - public static function register_dependencies( |
|
| 177 | - $class, |
|
| 178 | - array $dependencies, |
|
| 179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 180 | - ) { |
|
| 181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 187 | - * to the class specified by the first parameter. |
|
| 188 | - * IMPORTANT !!! |
|
| 189 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 190 | - * the order of the constructor parameters for the class in question. |
|
| 191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 193 | - * |
|
| 194 | - * @param string $class |
|
| 195 | - * @param array $dependencies |
|
| 196 | - * @param int $overwrite |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function registerDependencies( |
|
| 200 | - $class, |
|
| 201 | - array $dependencies, |
|
| 202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 203 | - ) { |
|
| 204 | - $class = trim($class, '\\'); |
|
| 205 | - $registered = false; |
|
| 206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 208 | - } |
|
| 209 | - // we need to make sure that any aliases used when registering a dependency |
|
| 210 | - // get resolved to the correct class name |
|
| 211 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
| 213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 215 | - ) { |
|
| 216 | - unset($dependencies[ $dependency ]); |
|
| 217 | - $dependencies[ $alias ] = $load_source; |
|
| 218 | - $registered = true; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - // now add our two lists of dependencies together. |
|
| 222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 223 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 225 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 226 | - // especially with numerically indexed arrays |
|
| 227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 228 | - // now we need to ensure that the resulting dependencies |
|
| 229 | - // array only has the entries that are required for the class |
|
| 230 | - // so first count how many dependencies were originally registered for the class |
|
| 231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 234 | - // then truncate the final array to match that count |
|
| 235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 236 | - // otherwise just take the incoming array because nothing previously existed |
|
| 237 | - : $dependencies; |
|
| 238 | - return $registered; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string $class_name |
|
| 244 | - * @param string $loader |
|
| 245 | - * @return bool |
|
| 246 | - * @throws DomainException |
|
| 247 | - */ |
|
| 248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 249 | - { |
|
| 250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 251 | - throw new DomainException( |
|
| 252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 256 | - if (! is_callable($loader) |
|
| 257 | - && ( |
|
| 258 | - strpos($loader, 'load_') !== 0 |
|
| 259 | - || ! method_exists('EE_Registry', $loader) |
|
| 260 | - ) |
|
| 261 | - ) { |
|
| 262 | - throw new DomainException( |
|
| 263 | - sprintf( |
|
| 264 | - esc_html__( |
|
| 265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ), |
|
| 268 | - $loader |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
| 273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
| 274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 275 | - return true; |
|
| 276 | - } |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function dependency_map() |
|
| 285 | - { |
|
| 286 | - return $this->_dependency_map; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 292 | - * |
|
| 293 | - * @param string $class_name |
|
| 294 | - * @return boolean |
|
| 295 | - */ |
|
| 296 | - public function has($class_name = '') |
|
| 297 | - { |
|
| 298 | - // all legacy models have the same dependencies |
|
| 299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 300 | - $class_name = 'LEGACY_MODELS'; |
|
| 301 | - } |
|
| 302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 308 | - * |
|
| 309 | - * @param string $class_name |
|
| 310 | - * @param string $dependency |
|
| 311 | - * @return bool |
|
| 312 | - */ |
|
| 313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 314 | - { |
|
| 315 | - // all legacy models have the same dependencies |
|
| 316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | - $class_name = 'LEGACY_MODELS'; |
|
| 318 | - } |
|
| 319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
| 321 | - ? true |
|
| 322 | - : false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 328 | - * |
|
| 329 | - * @param string $class_name |
|
| 330 | - * @param string $dependency |
|
| 331 | - * @return int |
|
| 332 | - */ |
|
| 333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 334 | - { |
|
| 335 | - // all legacy models have the same dependencies |
|
| 336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | - $class_name = 'LEGACY_MODELS'; |
|
| 338 | - } |
|
| 339 | - $dependency = $this->getFqnForAlias($dependency); |
|
| 340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 342 | - : EE_Dependency_Map::not_registered; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param string $class_name |
|
| 348 | - * @return string | Closure |
|
| 349 | - */ |
|
| 350 | - public function class_loader($class_name) |
|
| 351 | - { |
|
| 352 | - // all legacy models use load_model() |
|
| 353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 354 | - return 'load_model'; |
|
| 355 | - } |
|
| 356 | - $class_name = $this->getFqnForAlias($class_name); |
|
| 357 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @return array |
|
| 363 | - */ |
|
| 364 | - public function class_loaders() |
|
| 365 | - { |
|
| 366 | - return $this->_class_loaders; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * adds an alias for a classname |
|
| 372 | - * |
|
| 373 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 374 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 375 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 376 | - */ |
|
| 377 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
| 378 | - { |
|
| 379 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
| 385 | - * WHY? |
|
| 386 | - * Because if a class is type hinting for a concretion, |
|
| 387 | - * then why would we need to find another class to supply it? |
|
| 388 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 389 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 390 | - * Don't go looking for some substitute. |
|
| 391 | - * Whereas if a class is type hinting for an interface... |
|
| 392 | - * then we need to find an actual class to use. |
|
| 393 | - * So the interface IS the alias for some other FQN, |
|
| 394 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 395 | - * represents some other class. |
|
| 396 | - * |
|
| 397 | - * @param string $fqn |
|
| 398 | - * @param string $for_class |
|
| 399 | - * @return bool |
|
| 400 | - */ |
|
| 401 | - public function isAlias($fqn = '', $for_class = '') |
|
| 402 | - { |
|
| 403 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 409 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 410 | - * for example: |
|
| 411 | - * if the following two entries were added to the _aliases array: |
|
| 412 | - * array( |
|
| 413 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 414 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 415 | - * ) |
|
| 416 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 417 | - * to load an instance of 'some\namespace\classname' |
|
| 418 | - * |
|
| 419 | - * @param string $alias |
|
| 420 | - * @param string $for_class |
|
| 421 | - * @return string |
|
| 422 | - */ |
|
| 423 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
| 424 | - { |
|
| 425 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | - * This is done by using the following class constants: |
|
| 433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | - */ |
|
| 436 | - protected function _register_core_dependencies() |
|
| 437 | - { |
|
| 438 | - $this->_dependency_map = array( |
|
| 439 | - 'EE_Request_Handler' => array( |
|
| 440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EE_System' => array( |
|
| 443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 446 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - ), |
|
| 448 | - 'EE_Session' => array( |
|
| 449 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 450 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 451 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 452 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EE_Cart' => array( |
|
| 455 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_Front_Controller' => array( |
|
| 458 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 461 | - ), |
|
| 462 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 463 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | - ), |
|
| 465 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 466 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 467 | - ), |
|
| 468 | - 'EE_Message_Resource_Manager' => array( |
|
| 469 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 471 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - ), |
|
| 473 | - 'EE_Message_Factory' => array( |
|
| 474 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - ), |
|
| 476 | - 'EE_messages' => array( |
|
| 477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - ), |
|
| 479 | - 'EE_Messages_Generator' => array( |
|
| 480 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 481 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 483 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - ), |
|
| 485 | - 'EE_Messages_Processor' => array( |
|
| 486 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - ), |
|
| 488 | - 'EE_Messages_Queue' => array( |
|
| 489 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 490 | - ), |
|
| 491 | - 'EE_Messages_Template_Defaults' => array( |
|
| 492 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 494 | - ), |
|
| 495 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 496 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 497 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 498 | - ), |
|
| 499 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 500 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - ), |
|
| 502 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 503 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 505 | - ), |
|
| 506 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 507 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 508 | - ), |
|
| 509 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 510 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ), |
|
| 513 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 514 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - ), |
|
| 516 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 517 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - ), |
|
| 519 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 520 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 521 | - ), |
|
| 522 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 523 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 526 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 529 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - ), |
|
| 531 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 532 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 533 | - ), |
|
| 534 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 535 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 536 | - ), |
|
| 537 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 538 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 539 | - ), |
|
| 540 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 541 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 542 | - ), |
|
| 543 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 544 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 545 | - ), |
|
| 546 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 547 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 548 | - ), |
|
| 549 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 550 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 551 | - ), |
|
| 552 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 553 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 554 | - ), |
|
| 555 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 556 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 557 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 558 | - ), |
|
| 559 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 560 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 561 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ), |
|
| 563 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 566 | - ), |
|
| 567 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 570 | - ), |
|
| 571 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - ), |
|
| 575 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 578 | - ), |
|
| 579 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - ), |
|
| 583 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 586 | - ), |
|
| 587 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 590 | - ), |
|
| 591 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - ), |
|
| 595 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
| 596 | - array(), |
|
| 597 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 598 | - ), |
|
| 599 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 600 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 601 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
| 602 | - ), |
|
| 603 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 604 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 605 | - ), |
|
| 606 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 607 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | - ), |
|
| 609 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 610 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - ), |
|
| 612 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 613 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 614 | - ), |
|
| 615 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 616 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 617 | - ), |
|
| 618 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 619 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | - ), |
|
| 621 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 623 | - ), |
|
| 624 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 625 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 626 | - ), |
|
| 627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 628 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 629 | - ), |
|
| 630 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 631 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 633 | - ), |
|
| 634 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 635 | - null, |
|
| 636 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 637 | - ), |
|
| 638 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 639 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 640 | - ), |
|
| 641 | - 'LEGACY_MODELS' => array( |
|
| 642 | - null, |
|
| 643 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 644 | - ), |
|
| 645 | - 'EE_Module_Request_Router' => array( |
|
| 646 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 647 | - ), |
|
| 648 | - 'EE_Registration_Processor' => array( |
|
| 649 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 650 | - ), |
|
| 651 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 652 | - null, |
|
| 653 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 654 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 655 | - ), |
|
| 656 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 657 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 658 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 659 | - ), |
|
| 660 | - 'EE_Admin_Transactions_List_Table' => array( |
|
| 661 | - null, |
|
| 662 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 663 | - ), |
|
| 664 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 665 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 666 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
| 668 | - ), |
|
| 669 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 670 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 671 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 672 | - ), |
|
| 673 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 674 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 675 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 676 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 677 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 678 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 679 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 680 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 681 | - ), |
|
| 682 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 683 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 684 | - ), |
|
| 685 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 686 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 687 | - ), |
|
| 688 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 689 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 690 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 691 | - ), |
|
| 692 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 693 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - ), |
|
| 695 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 696 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 697 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 698 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 699 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 700 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 701 | - ), |
|
| 702 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 703 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 704 | - ), |
|
| 705 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
| 706 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 707 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 708 | - ), |
|
| 709 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
| 710 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 711 | - ), |
|
| 712 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
| 713 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - ), |
|
| 715 | - 'EE_CPT_Strategy' => array( |
|
| 716 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 717 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 718 | - ), |
|
| 719 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
| 720 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 721 | - ), |
|
| 722 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
| 723 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 724 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 725 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 726 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 727 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 728 | - ), |
|
| 729 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
| 730 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 731 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
| 732 | - ), |
|
| 733 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
| 734 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 735 | - ), |
|
| 736 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
| 737 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 738 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
| 739 | - ), |
|
| 740 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
| 741 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
| 742 | - ), |
|
| 743 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
| 744 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 745 | - ), |
|
| 746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
| 747 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 748 | - ), |
|
| 749 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
| 750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 751 | - ), |
|
| 752 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
| 753 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
| 754 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
| 755 | - ), |
|
| 756 | - ); |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Registers how core classes are loaded. |
|
| 762 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 763 | - * 'EE_Request_Handler' => 'load_core' |
|
| 764 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 765 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 766 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 767 | - * 'Some_Class' => function () { |
|
| 768 | - * return new Some_Class(); |
|
| 769 | - * }, |
|
| 770 | - * This is required for instantiating dependencies |
|
| 771 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 772 | - * 'Required_Interface' => function () { |
|
| 773 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 774 | - * }, |
|
| 775 | - */ |
|
| 776 | - protected function _register_core_class_loaders() |
|
| 777 | - { |
|
| 778 | - // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 779 | - // be used in a closure. |
|
| 780 | - $request = &$this->request; |
|
| 781 | - $response = &$this->response; |
|
| 782 | - $legacy_request = &$this->legacy_request; |
|
| 783 | - // $loader = &$this->loader; |
|
| 784 | - $this->_class_loaders = array( |
|
| 785 | - // load_core |
|
| 786 | - 'EE_Capabilities' => 'load_core', |
|
| 787 | - 'EE_Encryption' => 'load_core', |
|
| 788 | - 'EE_Front_Controller' => 'load_core', |
|
| 789 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 790 | - 'EE_Registry' => 'load_core', |
|
| 791 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 792 | - return $legacy_request; |
|
| 793 | - }, |
|
| 794 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 795 | - return $request; |
|
| 796 | - }, |
|
| 797 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 798 | - return $response; |
|
| 799 | - }, |
|
| 800 | - 'EE_Base' => 'load_core', |
|
| 801 | - 'EE_Request_Handler' => 'load_core', |
|
| 802 | - 'EE_Session' => 'load_core', |
|
| 803 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 804 | - 'EE_System' => 'load_core', |
|
| 805 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 806 | - 'EE_Register_CPTs' => 'load_core', |
|
| 807 | - 'EE_Admin' => 'load_core', |
|
| 808 | - 'EE_CPT_Strategy' => 'load_core', |
|
| 809 | - // load_lib |
|
| 810 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 811 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 812 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 813 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 814 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 815 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 816 | - 'EE_Message_Repository' => 'load_lib', |
|
| 817 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 818 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 819 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 820 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 821 | - 'EE_Messages_Generator' => function () { |
|
| 822 | - return EE_Registry::instance()->load_lib( |
|
| 823 | - 'Messages_Generator', |
|
| 824 | - array(), |
|
| 825 | - false, |
|
| 826 | - false |
|
| 827 | - ); |
|
| 828 | - }, |
|
| 829 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 830 | - return EE_Registry::instance()->load_lib( |
|
| 831 | - 'Messages_Template_Defaults', |
|
| 832 | - $arguments, |
|
| 833 | - false, |
|
| 834 | - false |
|
| 835 | - ); |
|
| 836 | - }, |
|
| 837 | - // load_helper |
|
| 838 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 839 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 840 | - return new EEH_Parse_Shortcodes(); |
|
| 841 | - } |
|
| 842 | - return null; |
|
| 843 | - }, |
|
| 844 | - 'EE_Template_Config' => function () { |
|
| 845 | - return EE_Config::instance()->template_settings; |
|
| 846 | - }, |
|
| 847 | - 'EE_Currency_Config' => function () { |
|
| 848 | - return EE_Config::instance()->currency; |
|
| 849 | - }, |
|
| 850 | - 'EE_Registration_Config' => function () { |
|
| 851 | - return EE_Config::instance()->registration; |
|
| 852 | - }, |
|
| 853 | - 'EE_Core_Config' => function () { |
|
| 854 | - return EE_Config::instance()->core; |
|
| 855 | - }, |
|
| 856 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 857 | - return LoaderFactory::getLoader(); |
|
| 858 | - }, |
|
| 859 | - 'EE_Network_Config' => function () { |
|
| 860 | - return EE_Network_Config::instance(); |
|
| 861 | - }, |
|
| 862 | - 'EE_Config' => function () { |
|
| 863 | - return EE_Config::instance(); |
|
| 864 | - }, |
|
| 865 | - 'EventEspresso\core\domain\Domain' => function () { |
|
| 866 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
| 867 | - }, |
|
| 868 | - ); |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * can be used for supplying alternate names for classes, |
|
| 874 | - * or for connecting interface names to instantiable classes |
|
| 875 | - */ |
|
| 876 | - protected function _register_core_aliases() |
|
| 877 | - { |
|
| 878 | - $aliases = array( |
|
| 879 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 880 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 881 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 882 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 883 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 884 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 885 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 886 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 887 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 888 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 889 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 890 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 891 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 892 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 893 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 894 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 895 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 896 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 897 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 898 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 899 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 900 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 901 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 902 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 903 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 904 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 905 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 906 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 907 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 908 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 909 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 910 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 911 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 912 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 913 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 914 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 915 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 916 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 917 | - ); |
|
| 918 | - foreach ($aliases as $alias => $fqn) { |
|
| 919 | - if (is_array($fqn)) { |
|
| 920 | - foreach ($fqn as $class => $for_class) { |
|
| 921 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 922 | - } |
|
| 923 | - continue; |
|
| 924 | - } |
|
| 925 | - $this->class_cache->addAlias($fqn, $alias); |
|
| 926 | - } |
|
| 927 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 928 | - $this->class_cache->addAlias( |
|
| 929 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 930 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 931 | - ); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 938 | - * request Primarily used by unit tests. |
|
| 939 | - */ |
|
| 940 | - public function reset() |
|
| 941 | - { |
|
| 942 | - $this->_register_core_class_loaders(); |
|
| 943 | - $this->_register_core_dependencies(); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
| 949 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 950 | - * WHY? |
|
| 951 | - * Because if a class is type hinting for a concretion, |
|
| 952 | - * then why would we need to find another class to supply it? |
|
| 953 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 954 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 955 | - * Don't go looking for some substitute. |
|
| 956 | - * Whereas if a class is type hinting for an interface... |
|
| 957 | - * then we need to find an actual class to use. |
|
| 958 | - * So the interface IS the alias for some other FQN, |
|
| 959 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 960 | - * represents some other class. |
|
| 961 | - * |
|
| 962 | - * @deprecated 4.9.62.p |
|
| 963 | - * @param string $fqn |
|
| 964 | - * @param string $for_class |
|
| 965 | - * @return bool |
|
| 966 | - */ |
|
| 967 | - public function has_alias($fqn = '', $for_class = '') |
|
| 968 | - { |
|
| 969 | - return $this->isAlias($fqn, $for_class); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 975 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 976 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 977 | - * for example: |
|
| 978 | - * if the following two entries were added to the _aliases array: |
|
| 979 | - * array( |
|
| 980 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 981 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 982 | - * ) |
|
| 983 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 984 | - * to load an instance of 'some\namespace\classname' |
|
| 985 | - * |
|
| 986 | - * @deprecated 4.9.62.p |
|
| 987 | - * @param string $alias |
|
| 988 | - * @param string $for_class |
|
| 989 | - * @return string |
|
| 990 | - */ |
|
| 991 | - public function get_alias($alias = '', $for_class = '') |
|
| 992 | - { |
|
| 993 | - return $this->getFqnForAlias($alias, $for_class); |
|
| 994 | - } |
|
| 23 | + /** |
|
| 24 | + * This means that the requested class dependency is not present in the dependency map |
|
| 25 | + */ |
|
| 26 | + const not_registered = 0; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | + */ |
|
| 31 | + const load_new_object = 1; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | + */ |
|
| 37 | + const load_from_cache = 2; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * When registering a dependency, |
|
| 41 | + * this indicates to keep any existing dependencies that already exist, |
|
| 42 | + * and simply discard any new dependencies declared in the incoming data |
|
| 43 | + */ |
|
| 44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * When registering a dependency, |
|
| 48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | + */ |
|
| 50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @type EE_Dependency_Map $_instance |
|
| 55 | + */ |
|
| 56 | + protected static $_instance; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var ClassInterfaceCache $class_cache |
|
| 60 | + */ |
|
| 61 | + private $class_cache; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @type RequestInterface $request |
|
| 65 | + */ |
|
| 66 | + protected $request; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @type LegacyRequestInterface $legacy_request |
|
| 70 | + */ |
|
| 71 | + protected $legacy_request; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @type ResponseInterface $response |
|
| 75 | + */ |
|
| 76 | + protected $response; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @type LoaderInterface $loader |
|
| 80 | + */ |
|
| 81 | + protected $loader; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @type array $_dependency_map |
|
| 85 | + */ |
|
| 86 | + protected $_dependency_map = array(); |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @type array $_class_loaders |
|
| 90 | + */ |
|
| 91 | + protected $_class_loaders = array(); |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * EE_Dependency_Map constructor. |
|
| 96 | + * |
|
| 97 | + * @param ClassInterfaceCache $class_cache |
|
| 98 | + */ |
|
| 99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | + { |
|
| 101 | + $this->class_cache = $class_cache; |
|
| 102 | + do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return void |
|
| 108 | + */ |
|
| 109 | + public function initialize() |
|
| 110 | + { |
|
| 111 | + $this->_register_core_dependencies(); |
|
| 112 | + $this->_register_core_class_loaders(); |
|
| 113 | + $this->_register_core_aliases(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @singleton method used to instantiate class object |
|
| 119 | + * @param ClassInterfaceCache|null $class_cache |
|
| 120 | + * @return EE_Dependency_Map |
|
| 121 | + */ |
|
| 122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 123 | + { |
|
| 124 | + // check if class object is instantiated, and instantiated properly |
|
| 125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
| 126 | + && $class_cache instanceof ClassInterfaceCache |
|
| 127 | + ) { |
|
| 128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
| 129 | + } |
|
| 130 | + return self::$_instance; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param RequestInterface $request |
|
| 136 | + */ |
|
| 137 | + public function setRequest(RequestInterface $request) |
|
| 138 | + { |
|
| 139 | + $this->request = $request; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param LegacyRequestInterface $legacy_request |
|
| 145 | + */ |
|
| 146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 147 | + { |
|
| 148 | + $this->legacy_request = $legacy_request; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param ResponseInterface $response |
|
| 154 | + */ |
|
| 155 | + public function setResponse(ResponseInterface $response) |
|
| 156 | + { |
|
| 157 | + $this->response = $response; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param LoaderInterface $loader |
|
| 163 | + */ |
|
| 164 | + public function setLoader(LoaderInterface $loader) |
|
| 165 | + { |
|
| 166 | + $this->loader = $loader; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $class |
|
| 172 | + * @param array $dependencies |
|
| 173 | + * @param int $overwrite |
|
| 174 | + * @return bool |
|
| 175 | + */ |
|
| 176 | + public static function register_dependencies( |
|
| 177 | + $class, |
|
| 178 | + array $dependencies, |
|
| 179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 180 | + ) { |
|
| 181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 187 | + * to the class specified by the first parameter. |
|
| 188 | + * IMPORTANT !!! |
|
| 189 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 190 | + * the order of the constructor parameters for the class in question. |
|
| 191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 193 | + * |
|
| 194 | + * @param string $class |
|
| 195 | + * @param array $dependencies |
|
| 196 | + * @param int $overwrite |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function registerDependencies( |
|
| 200 | + $class, |
|
| 201 | + array $dependencies, |
|
| 202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 203 | + ) { |
|
| 204 | + $class = trim($class, '\\'); |
|
| 205 | + $registered = false; |
|
| 206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 208 | + } |
|
| 209 | + // we need to make sure that any aliases used when registering a dependency |
|
| 210 | + // get resolved to the correct class name |
|
| 211 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
| 213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 215 | + ) { |
|
| 216 | + unset($dependencies[ $dependency ]); |
|
| 217 | + $dependencies[ $alias ] = $load_source; |
|
| 218 | + $registered = true; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + // now add our two lists of dependencies together. |
|
| 222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 223 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 225 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 226 | + // especially with numerically indexed arrays |
|
| 227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 228 | + // now we need to ensure that the resulting dependencies |
|
| 229 | + // array only has the entries that are required for the class |
|
| 230 | + // so first count how many dependencies were originally registered for the class |
|
| 231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 234 | + // then truncate the final array to match that count |
|
| 235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 236 | + // otherwise just take the incoming array because nothing previously existed |
|
| 237 | + : $dependencies; |
|
| 238 | + return $registered; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string $class_name |
|
| 244 | + * @param string $loader |
|
| 245 | + * @return bool |
|
| 246 | + * @throws DomainException |
|
| 247 | + */ |
|
| 248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 249 | + { |
|
| 250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 251 | + throw new DomainException( |
|
| 252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 256 | + if (! is_callable($loader) |
|
| 257 | + && ( |
|
| 258 | + strpos($loader, 'load_') !== 0 |
|
| 259 | + || ! method_exists('EE_Registry', $loader) |
|
| 260 | + ) |
|
| 261 | + ) { |
|
| 262 | + throw new DomainException( |
|
| 263 | + sprintf( |
|
| 264 | + esc_html__( |
|
| 265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ), |
|
| 268 | + $loader |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
| 273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
| 274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 275 | + return true; |
|
| 276 | + } |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function dependency_map() |
|
| 285 | + { |
|
| 286 | + return $this->_dependency_map; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 292 | + * |
|
| 293 | + * @param string $class_name |
|
| 294 | + * @return boolean |
|
| 295 | + */ |
|
| 296 | + public function has($class_name = '') |
|
| 297 | + { |
|
| 298 | + // all legacy models have the same dependencies |
|
| 299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 300 | + $class_name = 'LEGACY_MODELS'; |
|
| 301 | + } |
|
| 302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 308 | + * |
|
| 309 | + * @param string $class_name |
|
| 310 | + * @param string $dependency |
|
| 311 | + * @return bool |
|
| 312 | + */ |
|
| 313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 314 | + { |
|
| 315 | + // all legacy models have the same dependencies |
|
| 316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | + $class_name = 'LEGACY_MODELS'; |
|
| 318 | + } |
|
| 319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
| 321 | + ? true |
|
| 322 | + : false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 328 | + * |
|
| 329 | + * @param string $class_name |
|
| 330 | + * @param string $dependency |
|
| 331 | + * @return int |
|
| 332 | + */ |
|
| 333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 334 | + { |
|
| 335 | + // all legacy models have the same dependencies |
|
| 336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | + $class_name = 'LEGACY_MODELS'; |
|
| 338 | + } |
|
| 339 | + $dependency = $this->getFqnForAlias($dependency); |
|
| 340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 342 | + : EE_Dependency_Map::not_registered; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param string $class_name |
|
| 348 | + * @return string | Closure |
|
| 349 | + */ |
|
| 350 | + public function class_loader($class_name) |
|
| 351 | + { |
|
| 352 | + // all legacy models use load_model() |
|
| 353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 354 | + return 'load_model'; |
|
| 355 | + } |
|
| 356 | + $class_name = $this->getFqnForAlias($class_name); |
|
| 357 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @return array |
|
| 363 | + */ |
|
| 364 | + public function class_loaders() |
|
| 365 | + { |
|
| 366 | + return $this->_class_loaders; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * adds an alias for a classname |
|
| 372 | + * |
|
| 373 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 374 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 375 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 376 | + */ |
|
| 377 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
| 378 | + { |
|
| 379 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
| 385 | + * WHY? |
|
| 386 | + * Because if a class is type hinting for a concretion, |
|
| 387 | + * then why would we need to find another class to supply it? |
|
| 388 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 389 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 390 | + * Don't go looking for some substitute. |
|
| 391 | + * Whereas if a class is type hinting for an interface... |
|
| 392 | + * then we need to find an actual class to use. |
|
| 393 | + * So the interface IS the alias for some other FQN, |
|
| 394 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 395 | + * represents some other class. |
|
| 396 | + * |
|
| 397 | + * @param string $fqn |
|
| 398 | + * @param string $for_class |
|
| 399 | + * @return bool |
|
| 400 | + */ |
|
| 401 | + public function isAlias($fqn = '', $for_class = '') |
|
| 402 | + { |
|
| 403 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 409 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 410 | + * for example: |
|
| 411 | + * if the following two entries were added to the _aliases array: |
|
| 412 | + * array( |
|
| 413 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 414 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 415 | + * ) |
|
| 416 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 417 | + * to load an instance of 'some\namespace\classname' |
|
| 418 | + * |
|
| 419 | + * @param string $alias |
|
| 420 | + * @param string $for_class |
|
| 421 | + * @return string |
|
| 422 | + */ |
|
| 423 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
| 424 | + { |
|
| 425 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | + * This is done by using the following class constants: |
|
| 433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | + */ |
|
| 436 | + protected function _register_core_dependencies() |
|
| 437 | + { |
|
| 438 | + $this->_dependency_map = array( |
|
| 439 | + 'EE_Request_Handler' => array( |
|
| 440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EE_System' => array( |
|
| 443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 446 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + ), |
|
| 448 | + 'EE_Session' => array( |
|
| 449 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 450 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 451 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 452 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EE_Cart' => array( |
|
| 455 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_Front_Controller' => array( |
|
| 458 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 461 | + ), |
|
| 462 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 463 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | + ), |
|
| 465 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 466 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 467 | + ), |
|
| 468 | + 'EE_Message_Resource_Manager' => array( |
|
| 469 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 471 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + ), |
|
| 473 | + 'EE_Message_Factory' => array( |
|
| 474 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + ), |
|
| 476 | + 'EE_messages' => array( |
|
| 477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + ), |
|
| 479 | + 'EE_Messages_Generator' => array( |
|
| 480 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 481 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 483 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + ), |
|
| 485 | + 'EE_Messages_Processor' => array( |
|
| 486 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + ), |
|
| 488 | + 'EE_Messages_Queue' => array( |
|
| 489 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 490 | + ), |
|
| 491 | + 'EE_Messages_Template_Defaults' => array( |
|
| 492 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 494 | + ), |
|
| 495 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 496 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 497 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 498 | + ), |
|
| 499 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 500 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + ), |
|
| 502 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 503 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 505 | + ), |
|
| 506 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 507 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 508 | + ), |
|
| 509 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 510 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ), |
|
| 513 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 514 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + ), |
|
| 516 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 517 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + ), |
|
| 519 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 520 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 521 | + ), |
|
| 522 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 523 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 526 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 529 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + ), |
|
| 531 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 532 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 533 | + ), |
|
| 534 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 535 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 536 | + ), |
|
| 537 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 538 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 539 | + ), |
|
| 540 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 541 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 542 | + ), |
|
| 543 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 544 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 545 | + ), |
|
| 546 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 547 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 548 | + ), |
|
| 549 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 550 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 551 | + ), |
|
| 552 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 553 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 554 | + ), |
|
| 555 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 556 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 557 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 558 | + ), |
|
| 559 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 560 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 561 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ), |
|
| 563 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 566 | + ), |
|
| 567 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 570 | + ), |
|
| 571 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + ), |
|
| 575 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 578 | + ), |
|
| 579 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + ), |
|
| 583 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 586 | + ), |
|
| 587 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 590 | + ), |
|
| 591 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + ), |
|
| 595 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
| 596 | + array(), |
|
| 597 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 598 | + ), |
|
| 599 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 600 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 601 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
| 602 | + ), |
|
| 603 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 604 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 605 | + ), |
|
| 606 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 607 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | + ), |
|
| 609 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 610 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + ), |
|
| 612 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 613 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 614 | + ), |
|
| 615 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 616 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 617 | + ), |
|
| 618 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 619 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | + ), |
|
| 621 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 623 | + ), |
|
| 624 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 625 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 626 | + ), |
|
| 627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 628 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 629 | + ), |
|
| 630 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 631 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 633 | + ), |
|
| 634 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 635 | + null, |
|
| 636 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 637 | + ), |
|
| 638 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 639 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 640 | + ), |
|
| 641 | + 'LEGACY_MODELS' => array( |
|
| 642 | + null, |
|
| 643 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 644 | + ), |
|
| 645 | + 'EE_Module_Request_Router' => array( |
|
| 646 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 647 | + ), |
|
| 648 | + 'EE_Registration_Processor' => array( |
|
| 649 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 650 | + ), |
|
| 651 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 652 | + null, |
|
| 653 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 654 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 655 | + ), |
|
| 656 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 657 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 658 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 659 | + ), |
|
| 660 | + 'EE_Admin_Transactions_List_Table' => array( |
|
| 661 | + null, |
|
| 662 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 663 | + ), |
|
| 664 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 665 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 666 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
| 668 | + ), |
|
| 669 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 670 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 671 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 672 | + ), |
|
| 673 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 674 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 675 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 676 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 677 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 678 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 679 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 680 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 681 | + ), |
|
| 682 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 683 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 684 | + ), |
|
| 685 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 686 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 687 | + ), |
|
| 688 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 689 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 690 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 691 | + ), |
|
| 692 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 693 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + ), |
|
| 695 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 696 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 697 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 698 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 699 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 700 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 701 | + ), |
|
| 702 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 703 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 704 | + ), |
|
| 705 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
| 706 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 707 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 708 | + ), |
|
| 709 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
| 710 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 711 | + ), |
|
| 712 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
| 713 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + ), |
|
| 715 | + 'EE_CPT_Strategy' => array( |
|
| 716 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 717 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 718 | + ), |
|
| 719 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
| 720 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 721 | + ), |
|
| 722 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
| 723 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 724 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 725 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 726 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 727 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 728 | + ), |
|
| 729 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
| 730 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 731 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
| 732 | + ), |
|
| 733 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
| 734 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 735 | + ), |
|
| 736 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
| 737 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 738 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
| 739 | + ), |
|
| 740 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
| 741 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
| 742 | + ), |
|
| 743 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
| 744 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 745 | + ), |
|
| 746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
| 747 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 748 | + ), |
|
| 749 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
| 750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 751 | + ), |
|
| 752 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
| 753 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
| 754 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
| 755 | + ), |
|
| 756 | + ); |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Registers how core classes are loaded. |
|
| 762 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 763 | + * 'EE_Request_Handler' => 'load_core' |
|
| 764 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 765 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 766 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 767 | + * 'Some_Class' => function () { |
|
| 768 | + * return new Some_Class(); |
|
| 769 | + * }, |
|
| 770 | + * This is required for instantiating dependencies |
|
| 771 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 772 | + * 'Required_Interface' => function () { |
|
| 773 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 774 | + * }, |
|
| 775 | + */ |
|
| 776 | + protected function _register_core_class_loaders() |
|
| 777 | + { |
|
| 778 | + // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 779 | + // be used in a closure. |
|
| 780 | + $request = &$this->request; |
|
| 781 | + $response = &$this->response; |
|
| 782 | + $legacy_request = &$this->legacy_request; |
|
| 783 | + // $loader = &$this->loader; |
|
| 784 | + $this->_class_loaders = array( |
|
| 785 | + // load_core |
|
| 786 | + 'EE_Capabilities' => 'load_core', |
|
| 787 | + 'EE_Encryption' => 'load_core', |
|
| 788 | + 'EE_Front_Controller' => 'load_core', |
|
| 789 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 790 | + 'EE_Registry' => 'load_core', |
|
| 791 | + 'EE_Request' => function () use (&$legacy_request) { |
|
| 792 | + return $legacy_request; |
|
| 793 | + }, |
|
| 794 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 795 | + return $request; |
|
| 796 | + }, |
|
| 797 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 798 | + return $response; |
|
| 799 | + }, |
|
| 800 | + 'EE_Base' => 'load_core', |
|
| 801 | + 'EE_Request_Handler' => 'load_core', |
|
| 802 | + 'EE_Session' => 'load_core', |
|
| 803 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 804 | + 'EE_System' => 'load_core', |
|
| 805 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 806 | + 'EE_Register_CPTs' => 'load_core', |
|
| 807 | + 'EE_Admin' => 'load_core', |
|
| 808 | + 'EE_CPT_Strategy' => 'load_core', |
|
| 809 | + // load_lib |
|
| 810 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 811 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 812 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 813 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 814 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 815 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 816 | + 'EE_Message_Repository' => 'load_lib', |
|
| 817 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 818 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 819 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 820 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 821 | + 'EE_Messages_Generator' => function () { |
|
| 822 | + return EE_Registry::instance()->load_lib( |
|
| 823 | + 'Messages_Generator', |
|
| 824 | + array(), |
|
| 825 | + false, |
|
| 826 | + false |
|
| 827 | + ); |
|
| 828 | + }, |
|
| 829 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 830 | + return EE_Registry::instance()->load_lib( |
|
| 831 | + 'Messages_Template_Defaults', |
|
| 832 | + $arguments, |
|
| 833 | + false, |
|
| 834 | + false |
|
| 835 | + ); |
|
| 836 | + }, |
|
| 837 | + // load_helper |
|
| 838 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 839 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 840 | + return new EEH_Parse_Shortcodes(); |
|
| 841 | + } |
|
| 842 | + return null; |
|
| 843 | + }, |
|
| 844 | + 'EE_Template_Config' => function () { |
|
| 845 | + return EE_Config::instance()->template_settings; |
|
| 846 | + }, |
|
| 847 | + 'EE_Currency_Config' => function () { |
|
| 848 | + return EE_Config::instance()->currency; |
|
| 849 | + }, |
|
| 850 | + 'EE_Registration_Config' => function () { |
|
| 851 | + return EE_Config::instance()->registration; |
|
| 852 | + }, |
|
| 853 | + 'EE_Core_Config' => function () { |
|
| 854 | + return EE_Config::instance()->core; |
|
| 855 | + }, |
|
| 856 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 857 | + return LoaderFactory::getLoader(); |
|
| 858 | + }, |
|
| 859 | + 'EE_Network_Config' => function () { |
|
| 860 | + return EE_Network_Config::instance(); |
|
| 861 | + }, |
|
| 862 | + 'EE_Config' => function () { |
|
| 863 | + return EE_Config::instance(); |
|
| 864 | + }, |
|
| 865 | + 'EventEspresso\core\domain\Domain' => function () { |
|
| 866 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
| 867 | + }, |
|
| 868 | + ); |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * can be used for supplying alternate names for classes, |
|
| 874 | + * or for connecting interface names to instantiable classes |
|
| 875 | + */ |
|
| 876 | + protected function _register_core_aliases() |
|
| 877 | + { |
|
| 878 | + $aliases = array( |
|
| 879 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 880 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 881 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 882 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 883 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 884 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 885 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 886 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 887 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 888 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 889 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 890 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 891 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 892 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 893 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 894 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 895 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 896 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 897 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 898 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 899 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 900 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 901 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 902 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 903 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 904 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 905 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 906 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 907 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 908 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 909 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 910 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 911 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 912 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 913 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 914 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 915 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 916 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 917 | + ); |
|
| 918 | + foreach ($aliases as $alias => $fqn) { |
|
| 919 | + if (is_array($fqn)) { |
|
| 920 | + foreach ($fqn as $class => $for_class) { |
|
| 921 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 922 | + } |
|
| 923 | + continue; |
|
| 924 | + } |
|
| 925 | + $this->class_cache->addAlias($fqn, $alias); |
|
| 926 | + } |
|
| 927 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 928 | + $this->class_cache->addAlias( |
|
| 929 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 930 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 931 | + ); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 938 | + * request Primarily used by unit tests. |
|
| 939 | + */ |
|
| 940 | + public function reset() |
|
| 941 | + { |
|
| 942 | + $this->_register_core_class_loaders(); |
|
| 943 | + $this->_register_core_dependencies(); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
| 949 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 950 | + * WHY? |
|
| 951 | + * Because if a class is type hinting for a concretion, |
|
| 952 | + * then why would we need to find another class to supply it? |
|
| 953 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 954 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 955 | + * Don't go looking for some substitute. |
|
| 956 | + * Whereas if a class is type hinting for an interface... |
|
| 957 | + * then we need to find an actual class to use. |
|
| 958 | + * So the interface IS the alias for some other FQN, |
|
| 959 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 960 | + * represents some other class. |
|
| 961 | + * |
|
| 962 | + * @deprecated 4.9.62.p |
|
| 963 | + * @param string $fqn |
|
| 964 | + * @param string $for_class |
|
| 965 | + * @return bool |
|
| 966 | + */ |
|
| 967 | + public function has_alias($fqn = '', $for_class = '') |
|
| 968 | + { |
|
| 969 | + return $this->isAlias($fqn, $for_class); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 975 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 976 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 977 | + * for example: |
|
| 978 | + * if the following two entries were added to the _aliases array: |
|
| 979 | + * array( |
|
| 980 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 981 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 982 | + * ) |
|
| 983 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 984 | + * to load an instance of 'some\namespace\classname' |
|
| 985 | + * |
|
| 986 | + * @deprecated 4.9.62.p |
|
| 987 | + * @param string $alias |
|
| 988 | + * @param string $for_class |
|
| 989 | + * @return string |
|
| 990 | + */ |
|
| 991 | + public function get_alias($alias = '', $for_class = '') |
|
| 992 | + { |
|
| 993 | + return $this->getFqnForAlias($alias, $for_class); |
|
| 994 | + } |
|
| 995 | 995 | } |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.000'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.000'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -21,86 +21,86 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * AssetCollection constructor |
|
| 26 | - * |
|
| 27 | - * @throws InvalidInterfaceException |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * AssetCollection constructor |
|
| 26 | + * |
|
| 27 | + * @throws InvalidInterfaceException |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return StylesheetAsset[] |
|
| 37 | - * @since 4.9.62.p |
|
| 38 | - */ |
|
| 39 | - public function getStylesheetAssets() |
|
| 40 | - { |
|
| 41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * @return StylesheetAsset[] |
|
| 37 | + * @since 4.9.62.p |
|
| 38 | + */ |
|
| 39 | + public function getStylesheetAssets() |
|
| 40 | + { |
|
| 41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return JavascriptAsset[] |
|
| 47 | - * @since 4.9.62.p |
|
| 48 | - */ |
|
| 49 | - public function getJavascriptAssets() |
|
| 50 | - { |
|
| 51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * @return JavascriptAsset[] |
|
| 47 | + * @since 4.9.62.p |
|
| 48 | + */ |
|
| 49 | + public function getJavascriptAssets() |
|
| 50 | + { |
|
| 51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return ManifestFile[] |
|
| 57 | - * @since 4.9.62.p |
|
| 58 | - */ |
|
| 59 | - public function getManifestFiles() |
|
| 60 | - { |
|
| 61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * @return ManifestFile[] |
|
| 57 | + * @since 4.9.62.p |
|
| 58 | + */ |
|
| 59 | + public function getManifestFiles() |
|
| 60 | + { |
|
| 61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param $type |
|
| 67 | - * @return array |
|
| 68 | - * @since 4.9.62.p |
|
| 69 | - */ |
|
| 70 | - protected function getAssetsOfType($type) |
|
| 71 | - { |
|
| 72 | - $files = array(); |
|
| 73 | - $this->rewind(); |
|
| 74 | - while ($this->valid()) { |
|
| 75 | - /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
| 76 | - $asset = $this->current(); |
|
| 77 | - if ($asset->type() === $type) { |
|
| 78 | - $files[ $asset->handle() ] = $asset; |
|
| 79 | - } |
|
| 80 | - $this->next(); |
|
| 81 | - } |
|
| 82 | - $this->rewind(); |
|
| 83 | - return $files; |
|
| 84 | - } |
|
| 65 | + /** |
|
| 66 | + * @param $type |
|
| 67 | + * @return array |
|
| 68 | + * @since 4.9.62.p |
|
| 69 | + */ |
|
| 70 | + protected function getAssetsOfType($type) |
|
| 71 | + { |
|
| 72 | + $files = array(); |
|
| 73 | + $this->rewind(); |
|
| 74 | + while ($this->valid()) { |
|
| 75 | + /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
| 76 | + $asset = $this->current(); |
|
| 77 | + if ($asset->type() === $type) { |
|
| 78 | + $files[ $asset->handle() ] = $asset; |
|
| 79 | + } |
|
| 80 | + $this->next(); |
|
| 81 | + } |
|
| 82 | + $this->rewind(); |
|
| 83 | + return $files; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return JavascriptAsset[] |
|
| 89 | - * @since 4.9.62.p |
|
| 90 | - */ |
|
| 91 | - public function getJavascriptAssetsWithData() |
|
| 92 | - { |
|
| 93 | - $files = array(); |
|
| 94 | - $this->rewind(); |
|
| 95 | - while ($this->valid()) { |
|
| 96 | - /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
| 97 | - $asset = $this->current(); |
|
| 98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
| 99 | - $files[ $asset->handle() ] = $asset; |
|
| 100 | - } |
|
| 101 | - $this->next(); |
|
| 102 | - } |
|
| 103 | - $this->rewind(); |
|
| 104 | - return $files; |
|
| 105 | - } |
|
| 87 | + /** |
|
| 88 | + * @return JavascriptAsset[] |
|
| 89 | + * @since 4.9.62.p |
|
| 90 | + */ |
|
| 91 | + public function getJavascriptAssetsWithData() |
|
| 92 | + { |
|
| 93 | + $files = array(); |
|
| 94 | + $this->rewind(); |
|
| 95 | + while ($this->valid()) { |
|
| 96 | + /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
| 97 | + $asset = $this->current(); |
|
| 98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
| 99 | + $files[ $asset->handle() ] = $asset; |
|
| 100 | + } |
|
| 101 | + $this->next(); |
|
| 102 | + } |
|
| 103 | + $this->rewind(); |
|
| 104 | + return $files; |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
| 76 | 76 | $asset = $this->current(); |
| 77 | 77 | if ($asset->type() === $type) { |
| 78 | - $files[ $asset->handle() ] = $asset; |
|
| 78 | + $files[$asset->handle()] = $asset; |
|
| 79 | 79 | } |
| 80 | 80 | $this->next(); |
| 81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
| 97 | 97 | $asset = $this->current(); |
| 98 | 98 | if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
| 99 | - $files[ $asset->handle() ] = $asset; |
|
| 99 | + $files[$asset->handle()] = $asset; |
|
| 100 | 100 | } |
| 101 | 101 | $this->next(); |
| 102 | 102 | } |
@@ -23,559 +23,559 @@ |
||
| 23 | 23 | class Registry |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var AssetCollection $assets |
|
| 30 | - */ |
|
| 31 | - protected $assets; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var I18nRegistry |
|
| 35 | - */ |
|
| 36 | - private $i18n_registry; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $jsdata = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 47 | - * page source. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - private $script_handles_with_data = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Holds the manifest data obtained from registered manifest files. |
|
| 55 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 56 | - * Shape of this array is: |
|
| 57 | - * array( |
|
| 58 | - * 'some_namespace_slug' => array( |
|
| 59 | - * 'some_chunk_name' => array( |
|
| 60 | - * 'js' => 'filename.js' |
|
| 61 | - * 'css' => 'filename.js' |
|
| 62 | - * ), |
|
| 63 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
| 64 | - * ) |
|
| 65 | - * ) |
|
| 66 | - * |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - private $manifest_data = array(); |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Registry constructor. |
|
| 74 | - * Hooking into WP actions for script registry. |
|
| 75 | - * |
|
| 76 | - * @param AssetCollection $assets |
|
| 77 | - * @param I18nRegistry $i18n_registry |
|
| 78 | - */ |
|
| 79 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
| 80 | - { |
|
| 81 | - $this->assets = $assets; |
|
| 82 | - $this->i18n_registry = $i18n_registry; |
|
| 83 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
| 84 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
| 85 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
| 86 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
| 87 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
| 88 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
| 89 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 90 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
| 96 | - * translation handling. |
|
| 97 | - * |
|
| 98 | - * @return I18nRegistry |
|
| 99 | - */ |
|
| 100 | - public function getI18nRegistry() |
|
| 101 | - { |
|
| 102 | - return $this->i18n_registry; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
| 108 | - * |
|
| 109 | - * @since 4.9.62.p |
|
| 110 | - * @throws Exception |
|
| 111 | - */ |
|
| 112 | - public function registerScriptsAndStyles() |
|
| 113 | - { |
|
| 114 | - try { |
|
| 115 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
| 116 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
| 117 | - } catch (Exception $exception) { |
|
| 118 | - new ExceptionStackTraceDisplay($exception); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Registers JS assets with WP core |
|
| 125 | - * |
|
| 126 | - * @since 4.9.62.p |
|
| 127 | - * @param JavascriptAsset[] $scripts |
|
| 128 | - * @throws AssetRegistrationException |
|
| 129 | - * @throws InvalidDataTypeException |
|
| 130 | - */ |
|
| 131 | - public function registerScripts(array $scripts) |
|
| 132 | - { |
|
| 133 | - foreach ($scripts as $script) { |
|
| 134 | - // skip to next script if this has already been done |
|
| 135 | - if ($script->isRegistered()) { |
|
| 136 | - continue; |
|
| 137 | - } |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 140 | - $script |
|
| 141 | - ); |
|
| 142 | - $registered = wp_register_script( |
|
| 143 | - $script->handle(), |
|
| 144 | - $script->source(), |
|
| 145 | - $script->dependencies(), |
|
| 146 | - $script->version(), |
|
| 147 | - $script->loadInFooter() |
|
| 148 | - ); |
|
| 149 | - if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
| 150 | - throw new AssetRegistrationException($script->handle()); |
|
| 151 | - } |
|
| 152 | - $script->setRegistered($registered); |
|
| 153 | - if ($script->requiresTranslation()) { |
|
| 154 | - $this->registerTranslation($script->handle()); |
|
| 155 | - } |
|
| 156 | - do_action( |
|
| 157 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
| 158 | - $script |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Registers CSS assets with WP core |
|
| 166 | - * |
|
| 167 | - * @since 4.9.62.p |
|
| 168 | - * @param StylesheetAsset[] $styles |
|
| 169 | - * @throws InvalidDataTypeException |
|
| 170 | - */ |
|
| 171 | - public function registerStyles(array $styles) |
|
| 172 | - { |
|
| 173 | - foreach ($styles as $style) { |
|
| 174 | - // skip to next style if this has already been done |
|
| 175 | - if ($style->isRegistered()) { |
|
| 176 | - continue; |
|
| 177 | - } |
|
| 178 | - do_action( |
|
| 179 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
| 180 | - $style |
|
| 181 | - ); |
|
| 182 | - wp_enqueue_style( |
|
| 183 | - $style->handle(), |
|
| 184 | - $style->source(), |
|
| 185 | - $style->dependencies(), |
|
| 186 | - $style->version(), |
|
| 187 | - $style->media() |
|
| 188 | - ); |
|
| 189 | - $style->setRegistered(); |
|
| 190 | - do_action( |
|
| 191 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
| 192 | - $style |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Call back for the script print in frontend and backend. |
|
| 200 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 201 | - * |
|
| 202 | - * @since 4.9.31.rc.015 |
|
| 203 | - */ |
|
| 204 | - public function enqueueData() |
|
| 205 | - { |
|
| 206 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 207 | - wp_add_inline_script( |
|
| 208 | - 'eejs-core', |
|
| 209 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
| 210 | - 'before' |
|
| 211 | - ); |
|
| 212 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
| 213 | - foreach ($scripts as $script) { |
|
| 214 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
| 215 | - if ($script->hasInlineDataCallback()) { |
|
| 216 | - $localize = $script->inlineDataCallback(); |
|
| 217 | - $localize(); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Used to add data to eejs.data object. |
|
| 225 | - * Note: Overriding existing data is not allowed. |
|
| 226 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 227 | - * If the data you add is something like this: |
|
| 228 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 229 | - * It will be exposed in the page source as: |
|
| 230 | - * eejs.data.my_plugin_data.foo == gar |
|
| 231 | - * |
|
| 232 | - * @param string $key Key used to access your data |
|
| 233 | - * @param string|array $value Value to attach to key |
|
| 234 | - * @throws InvalidArgumentException |
|
| 235 | - */ |
|
| 236 | - public function addData($key, $value) |
|
| 237 | - { |
|
| 238 | - if ($this->verifyDataNotExisting($key)) { |
|
| 239 | - $this->jsdata[ $key ] = $value; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 246 | - * elements in an array. |
|
| 247 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 248 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 249 | - * object like this, eejs.data.test = [ my_data, |
|
| 250 | - * ] |
|
| 251 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 252 | - * this will throw an exception. |
|
| 253 | - * |
|
| 254 | - * @param string $key Key to attach data to. |
|
| 255 | - * @param string|array $value Value being registered. |
|
| 256 | - * @throws InvalidArgumentException |
|
| 257 | - */ |
|
| 258 | - public function pushData($key, $value) |
|
| 259 | - { |
|
| 260 | - if (isset($this->jsdata[ $key ]) |
|
| 261 | - && ! is_array($this->jsdata[ $key ]) |
|
| 262 | - ) { |
|
| 263 | - throw new InvalidArgumentException( |
|
| 264 | - sprintf( |
|
| 265 | - __( |
|
| 266 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 26 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var AssetCollection $assets |
|
| 30 | + */ |
|
| 31 | + protected $assets; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var I18nRegistry |
|
| 35 | + */ |
|
| 36 | + private $i18n_registry; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $jsdata = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 47 | + * page source. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + private $script_handles_with_data = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Holds the manifest data obtained from registered manifest files. |
|
| 55 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
| 56 | + * Shape of this array is: |
|
| 57 | + * array( |
|
| 58 | + * 'some_namespace_slug' => array( |
|
| 59 | + * 'some_chunk_name' => array( |
|
| 60 | + * 'js' => 'filename.js' |
|
| 61 | + * 'css' => 'filename.js' |
|
| 62 | + * ), |
|
| 63 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
| 64 | + * ) |
|
| 65 | + * ) |
|
| 66 | + * |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + private $manifest_data = array(); |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Registry constructor. |
|
| 74 | + * Hooking into WP actions for script registry. |
|
| 75 | + * |
|
| 76 | + * @param AssetCollection $assets |
|
| 77 | + * @param I18nRegistry $i18n_registry |
|
| 78 | + */ |
|
| 79 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
| 80 | + { |
|
| 81 | + $this->assets = $assets; |
|
| 82 | + $this->i18n_registry = $i18n_registry; |
|
| 83 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
| 84 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
| 85 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
| 86 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
| 87 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
| 88 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
| 89 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 90 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
| 96 | + * translation handling. |
|
| 97 | + * |
|
| 98 | + * @return I18nRegistry |
|
| 99 | + */ |
|
| 100 | + public function getI18nRegistry() |
|
| 101 | + { |
|
| 102 | + return $this->i18n_registry; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
| 108 | + * |
|
| 109 | + * @since 4.9.62.p |
|
| 110 | + * @throws Exception |
|
| 111 | + */ |
|
| 112 | + public function registerScriptsAndStyles() |
|
| 113 | + { |
|
| 114 | + try { |
|
| 115 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
| 116 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
| 117 | + } catch (Exception $exception) { |
|
| 118 | + new ExceptionStackTraceDisplay($exception); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Registers JS assets with WP core |
|
| 125 | + * |
|
| 126 | + * @since 4.9.62.p |
|
| 127 | + * @param JavascriptAsset[] $scripts |
|
| 128 | + * @throws AssetRegistrationException |
|
| 129 | + * @throws InvalidDataTypeException |
|
| 130 | + */ |
|
| 131 | + public function registerScripts(array $scripts) |
|
| 132 | + { |
|
| 133 | + foreach ($scripts as $script) { |
|
| 134 | + // skip to next script if this has already been done |
|
| 135 | + if ($script->isRegistered()) { |
|
| 136 | + continue; |
|
| 137 | + } |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 140 | + $script |
|
| 141 | + ); |
|
| 142 | + $registered = wp_register_script( |
|
| 143 | + $script->handle(), |
|
| 144 | + $script->source(), |
|
| 145 | + $script->dependencies(), |
|
| 146 | + $script->version(), |
|
| 147 | + $script->loadInFooter() |
|
| 148 | + ); |
|
| 149 | + if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
| 150 | + throw new AssetRegistrationException($script->handle()); |
|
| 151 | + } |
|
| 152 | + $script->setRegistered($registered); |
|
| 153 | + if ($script->requiresTranslation()) { |
|
| 154 | + $this->registerTranslation($script->handle()); |
|
| 155 | + } |
|
| 156 | + do_action( |
|
| 157 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
| 158 | + $script |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Registers CSS assets with WP core |
|
| 166 | + * |
|
| 167 | + * @since 4.9.62.p |
|
| 168 | + * @param StylesheetAsset[] $styles |
|
| 169 | + * @throws InvalidDataTypeException |
|
| 170 | + */ |
|
| 171 | + public function registerStyles(array $styles) |
|
| 172 | + { |
|
| 173 | + foreach ($styles as $style) { |
|
| 174 | + // skip to next style if this has already been done |
|
| 175 | + if ($style->isRegistered()) { |
|
| 176 | + continue; |
|
| 177 | + } |
|
| 178 | + do_action( |
|
| 179 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
| 180 | + $style |
|
| 181 | + ); |
|
| 182 | + wp_enqueue_style( |
|
| 183 | + $style->handle(), |
|
| 184 | + $style->source(), |
|
| 185 | + $style->dependencies(), |
|
| 186 | + $style->version(), |
|
| 187 | + $style->media() |
|
| 188 | + ); |
|
| 189 | + $style->setRegistered(); |
|
| 190 | + do_action( |
|
| 191 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
| 192 | + $style |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Call back for the script print in frontend and backend. |
|
| 200 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 201 | + * |
|
| 202 | + * @since 4.9.31.rc.015 |
|
| 203 | + */ |
|
| 204 | + public function enqueueData() |
|
| 205 | + { |
|
| 206 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 207 | + wp_add_inline_script( |
|
| 208 | + 'eejs-core', |
|
| 209 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
| 210 | + 'before' |
|
| 211 | + ); |
|
| 212 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
| 213 | + foreach ($scripts as $script) { |
|
| 214 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
| 215 | + if ($script->hasInlineDataCallback()) { |
|
| 216 | + $localize = $script->inlineDataCallback(); |
|
| 217 | + $localize(); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Used to add data to eejs.data object. |
|
| 225 | + * Note: Overriding existing data is not allowed. |
|
| 226 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 227 | + * If the data you add is something like this: |
|
| 228 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 229 | + * It will be exposed in the page source as: |
|
| 230 | + * eejs.data.my_plugin_data.foo == gar |
|
| 231 | + * |
|
| 232 | + * @param string $key Key used to access your data |
|
| 233 | + * @param string|array $value Value to attach to key |
|
| 234 | + * @throws InvalidArgumentException |
|
| 235 | + */ |
|
| 236 | + public function addData($key, $value) |
|
| 237 | + { |
|
| 238 | + if ($this->verifyDataNotExisting($key)) { |
|
| 239 | + $this->jsdata[ $key ] = $value; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 246 | + * elements in an array. |
|
| 247 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 248 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 249 | + * object like this, eejs.data.test = [ my_data, |
|
| 250 | + * ] |
|
| 251 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 252 | + * this will throw an exception. |
|
| 253 | + * |
|
| 254 | + * @param string $key Key to attach data to. |
|
| 255 | + * @param string|array $value Value being registered. |
|
| 256 | + * @throws InvalidArgumentException |
|
| 257 | + */ |
|
| 258 | + public function pushData($key, $value) |
|
| 259 | + { |
|
| 260 | + if (isset($this->jsdata[ $key ]) |
|
| 261 | + && ! is_array($this->jsdata[ $key ]) |
|
| 262 | + ) { |
|
| 263 | + throw new InvalidArgumentException( |
|
| 264 | + sprintf( |
|
| 265 | + __( |
|
| 266 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 267 | 267 | push values to this data element when it is an array.', |
| 268 | - 'event_espresso' |
|
| 269 | - ), |
|
| 270 | - $key, |
|
| 271 | - __METHOD__ |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - } |
|
| 275 | - $this->jsdata[ $key ][] = $value; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Used to set content used by javascript for a template. |
|
| 281 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 282 | - * |
|
| 283 | - * @param string $template_reference |
|
| 284 | - * @param string $template_content |
|
| 285 | - * @throws InvalidArgumentException |
|
| 286 | - */ |
|
| 287 | - public function addTemplate($template_reference, $template_content) |
|
| 288 | - { |
|
| 289 | - if (! isset($this->jsdata['templates'])) { |
|
| 290 | - $this->jsdata['templates'] = array(); |
|
| 291 | - } |
|
| 292 | - //no overrides allowed. |
|
| 293 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
| 294 | - throw new InvalidArgumentException( |
|
| 295 | - sprintf( |
|
| 296 | - __( |
|
| 297 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 298 | - 'event_espresso' |
|
| 299 | - ), |
|
| 300 | - $template_reference |
|
| 301 | - ) |
|
| 302 | - ); |
|
| 303 | - } |
|
| 304 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Retrieve the template content already registered for the given reference. |
|
| 310 | - * |
|
| 311 | - * @param string $template_reference |
|
| 312 | - * @return string |
|
| 313 | - */ |
|
| 314 | - public function getTemplate($template_reference) |
|
| 315 | - { |
|
| 316 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
| 317 | - ? $this->jsdata['templates'][ $template_reference ] |
|
| 318 | - : ''; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Retrieve registered data. |
|
| 324 | - * |
|
| 325 | - * @param string $key Name of key to attach data to. |
|
| 326 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 327 | - */ |
|
| 328 | - public function getData($key) |
|
| 329 | - { |
|
| 330 | - return isset($this->jsdata[ $key ]) |
|
| 331 | - ? $this->jsdata[ $key ] |
|
| 332 | - : false; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 338 | - * Overriding data is not allowed. |
|
| 339 | - * |
|
| 340 | - * @param string $key Index for data. |
|
| 341 | - * @return bool If valid then return true. |
|
| 342 | - * @throws InvalidArgumentException if data already exists. |
|
| 343 | - */ |
|
| 344 | - protected function verifyDataNotExisting($key) |
|
| 345 | - { |
|
| 346 | - if (isset($this->jsdata[ $key ])) { |
|
| 347 | - if (is_array($this->jsdata[ $key ])) { |
|
| 348 | - throw new InvalidArgumentException( |
|
| 349 | - sprintf( |
|
| 350 | - __( |
|
| 351 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 268 | + 'event_espresso' |
|
| 269 | + ), |
|
| 270 | + $key, |
|
| 271 | + __METHOD__ |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | + $this->jsdata[ $key ][] = $value; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Used to set content used by javascript for a template. |
|
| 281 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 282 | + * |
|
| 283 | + * @param string $template_reference |
|
| 284 | + * @param string $template_content |
|
| 285 | + * @throws InvalidArgumentException |
|
| 286 | + */ |
|
| 287 | + public function addTemplate($template_reference, $template_content) |
|
| 288 | + { |
|
| 289 | + if (! isset($this->jsdata['templates'])) { |
|
| 290 | + $this->jsdata['templates'] = array(); |
|
| 291 | + } |
|
| 292 | + //no overrides allowed. |
|
| 293 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
| 294 | + throw new InvalidArgumentException( |
|
| 295 | + sprintf( |
|
| 296 | + __( |
|
| 297 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 298 | + 'event_espresso' |
|
| 299 | + ), |
|
| 300 | + $template_reference |
|
| 301 | + ) |
|
| 302 | + ); |
|
| 303 | + } |
|
| 304 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Retrieve the template content already registered for the given reference. |
|
| 310 | + * |
|
| 311 | + * @param string $template_reference |
|
| 312 | + * @return string |
|
| 313 | + */ |
|
| 314 | + public function getTemplate($template_reference) |
|
| 315 | + { |
|
| 316 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
| 317 | + ? $this->jsdata['templates'][ $template_reference ] |
|
| 318 | + : ''; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Retrieve registered data. |
|
| 324 | + * |
|
| 325 | + * @param string $key Name of key to attach data to. |
|
| 326 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 327 | + */ |
|
| 328 | + public function getData($key) |
|
| 329 | + { |
|
| 330 | + return isset($this->jsdata[ $key ]) |
|
| 331 | + ? $this->jsdata[ $key ] |
|
| 332 | + : false; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 338 | + * Overriding data is not allowed. |
|
| 339 | + * |
|
| 340 | + * @param string $key Index for data. |
|
| 341 | + * @return bool If valid then return true. |
|
| 342 | + * @throws InvalidArgumentException if data already exists. |
|
| 343 | + */ |
|
| 344 | + protected function verifyDataNotExisting($key) |
|
| 345 | + { |
|
| 346 | + if (isset($this->jsdata[ $key ])) { |
|
| 347 | + if (is_array($this->jsdata[ $key ])) { |
|
| 348 | + throw new InvalidArgumentException( |
|
| 349 | + sprintf( |
|
| 350 | + __( |
|
| 351 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 352 | 352 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 353 | 353 | %2$s method to push your value to the array.', |
| 354 | - 'event_espresso' |
|
| 355 | - ), |
|
| 356 | - $key, |
|
| 357 | - 'pushData()' |
|
| 358 | - ) |
|
| 359 | - ); |
|
| 360 | - } |
|
| 361 | - throw new InvalidArgumentException( |
|
| 362 | - sprintf( |
|
| 363 | - __( |
|
| 364 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 354 | + 'event_espresso' |
|
| 355 | + ), |
|
| 356 | + $key, |
|
| 357 | + 'pushData()' |
|
| 358 | + ) |
|
| 359 | + ); |
|
| 360 | + } |
|
| 361 | + throw new InvalidArgumentException( |
|
| 362 | + sprintf( |
|
| 363 | + __( |
|
| 364 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 365 | 365 | allowed. Consider attaching your value to a different key', |
| 366 | - 'event_espresso' |
|
| 367 | - ), |
|
| 368 | - $key |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - return true; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Get the actual asset path for asset manifests. |
|
| 378 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 379 | - * |
|
| 380 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 381 | - * asset file location. |
|
| 382 | - * @param string $chunk_name |
|
| 383 | - * @param string $asset_type |
|
| 384 | - * @return string |
|
| 385 | - * @since 4.9.59.p |
|
| 386 | - */ |
|
| 387 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 388 | - { |
|
| 389 | - $url = isset( |
|
| 390 | - $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
| 391 | - $this->manifest_data[ $namespace ]['url_base'] |
|
| 392 | - ) |
|
| 393 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
| 394 | - . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
| 395 | - : $chunk_name; |
|
| 396 | - return apply_filters( |
|
| 397 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 398 | - $url, |
|
| 399 | - $namespace, |
|
| 400 | - $chunk_name, |
|
| 401 | - $asset_type |
|
| 402 | - ); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Return the url to a js file for the given namespace and chunk name. |
|
| 408 | - * |
|
| 409 | - * @param string $namespace |
|
| 410 | - * @param string $chunk_name |
|
| 411 | - * @return string |
|
| 412 | - */ |
|
| 413 | - public function getJsUrl($namespace, $chunk_name) |
|
| 414 | - { |
|
| 415 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Return the url to a css file for the given namespace and chunk name. |
|
| 421 | - * |
|
| 422 | - * @param string $namespace |
|
| 423 | - * @param string $chunk_name |
|
| 424 | - * @return string |
|
| 425 | - */ |
|
| 426 | - public function getCssUrl($namespace, $chunk_name) |
|
| 427 | - { |
|
| 428 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * @since 4.9.62.p |
|
| 434 | - * @throws InvalidArgumentException |
|
| 435 | - * @throws InvalidFilePathException |
|
| 436 | - */ |
|
| 437 | - public function registerManifestFiles() |
|
| 438 | - { |
|
| 439 | - $manifest_files = $this->assets->getManifestFiles(); |
|
| 440 | - foreach ($manifest_files as $manifest_file) { |
|
| 441 | - $this->registerManifestFile( |
|
| 442 | - $manifest_file->assetNamespace(), |
|
| 443 | - $manifest_file->urlBase(), |
|
| 444 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 445 | - ); |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 452 | - * |
|
| 453 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 454 | - * @param string $url_base The url base for the manifest file location. |
|
| 455 | - * @param string $manifest_file The absolute path to the manifest file. |
|
| 456 | - * @throws InvalidArgumentException |
|
| 457 | - * @throws InvalidFilePathException |
|
| 458 | - * @since 4.9.59.p |
|
| 459 | - */ |
|
| 460 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 461 | - { |
|
| 462 | - if (isset($this->manifest_data[ $namespace ])) { |
|
| 463 | - throw new InvalidArgumentException( |
|
| 464 | - sprintf( |
|
| 465 | - esc_html__( |
|
| 466 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 467 | - 'event_espresso' |
|
| 468 | - ), |
|
| 469 | - $namespace |
|
| 470 | - ) |
|
| 471 | - ); |
|
| 472 | - } |
|
| 473 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 474 | - if (is_admin()) { |
|
| 475 | - EE_Error::add_error( |
|
| 476 | - sprintf( |
|
| 477 | - esc_html__( |
|
| 478 | - 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
| 479 | - 'event_espresso' |
|
| 480 | - ), |
|
| 481 | - 'Event Espresso', |
|
| 482 | - $url_base, |
|
| 483 | - 'plugins_url', |
|
| 484 | - 'WP_PLUGIN_URL' |
|
| 485 | - ), |
|
| 486 | - __FILE__, |
|
| 487 | - __FUNCTION__, |
|
| 488 | - __LINE__ |
|
| 489 | - ); |
|
| 490 | - } |
|
| 491 | - return; |
|
| 492 | - } |
|
| 493 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
| 494 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
| 495 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Decodes json from the provided manifest file. |
|
| 502 | - * |
|
| 503 | - * @since 4.9.59.p |
|
| 504 | - * @param string $manifest_file Path to manifest file. |
|
| 505 | - * @return array |
|
| 506 | - * @throws InvalidFilePathException |
|
| 507 | - */ |
|
| 508 | - private function decodeManifestFile($manifest_file) |
|
| 509 | - { |
|
| 510 | - if (! file_exists($manifest_file)) { |
|
| 511 | - throw new InvalidFilePathException($manifest_file); |
|
| 512 | - } |
|
| 513 | - return json_decode(file_get_contents($manifest_file), true); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * This is used to set registered script handles that have data. |
|
| 519 | - * |
|
| 520 | - * @param string $script_handle |
|
| 521 | - */ |
|
| 522 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 523 | - { |
|
| 524 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /**i |
|
| 366 | + 'event_espresso' |
|
| 367 | + ), |
|
| 368 | + $key |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + return true; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Get the actual asset path for asset manifests. |
|
| 378 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
| 379 | + * |
|
| 380 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
| 381 | + * asset file location. |
|
| 382 | + * @param string $chunk_name |
|
| 383 | + * @param string $asset_type |
|
| 384 | + * @return string |
|
| 385 | + * @since 4.9.59.p |
|
| 386 | + */ |
|
| 387 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
| 388 | + { |
|
| 389 | + $url = isset( |
|
| 390 | + $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
| 391 | + $this->manifest_data[ $namespace ]['url_base'] |
|
| 392 | + ) |
|
| 393 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
| 394 | + . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
| 395 | + : $chunk_name; |
|
| 396 | + return apply_filters( |
|
| 397 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
| 398 | + $url, |
|
| 399 | + $namespace, |
|
| 400 | + $chunk_name, |
|
| 401 | + $asset_type |
|
| 402 | + ); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Return the url to a js file for the given namespace and chunk name. |
|
| 408 | + * |
|
| 409 | + * @param string $namespace |
|
| 410 | + * @param string $chunk_name |
|
| 411 | + * @return string |
|
| 412 | + */ |
|
| 413 | + public function getJsUrl($namespace, $chunk_name) |
|
| 414 | + { |
|
| 415 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Return the url to a css file for the given namespace and chunk name. |
|
| 421 | + * |
|
| 422 | + * @param string $namespace |
|
| 423 | + * @param string $chunk_name |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + public function getCssUrl($namespace, $chunk_name) |
|
| 427 | + { |
|
| 428 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * @since 4.9.62.p |
|
| 434 | + * @throws InvalidArgumentException |
|
| 435 | + * @throws InvalidFilePathException |
|
| 436 | + */ |
|
| 437 | + public function registerManifestFiles() |
|
| 438 | + { |
|
| 439 | + $manifest_files = $this->assets->getManifestFiles(); |
|
| 440 | + foreach ($manifest_files as $manifest_file) { |
|
| 441 | + $this->registerManifestFile( |
|
| 442 | + $manifest_file->assetNamespace(), |
|
| 443 | + $manifest_file->urlBase(), |
|
| 444 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 445 | + ); |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
| 452 | + * |
|
| 453 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
| 454 | + * @param string $url_base The url base for the manifest file location. |
|
| 455 | + * @param string $manifest_file The absolute path to the manifest file. |
|
| 456 | + * @throws InvalidArgumentException |
|
| 457 | + * @throws InvalidFilePathException |
|
| 458 | + * @since 4.9.59.p |
|
| 459 | + */ |
|
| 460 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
| 461 | + { |
|
| 462 | + if (isset($this->manifest_data[ $namespace ])) { |
|
| 463 | + throw new InvalidArgumentException( |
|
| 464 | + sprintf( |
|
| 465 | + esc_html__( |
|
| 466 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
| 467 | + 'event_espresso' |
|
| 468 | + ), |
|
| 469 | + $namespace |
|
| 470 | + ) |
|
| 471 | + ); |
|
| 472 | + } |
|
| 473 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
| 474 | + if (is_admin()) { |
|
| 475 | + EE_Error::add_error( |
|
| 476 | + sprintf( |
|
| 477 | + esc_html__( |
|
| 478 | + 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
| 479 | + 'event_espresso' |
|
| 480 | + ), |
|
| 481 | + 'Event Espresso', |
|
| 482 | + $url_base, |
|
| 483 | + 'plugins_url', |
|
| 484 | + 'WP_PLUGIN_URL' |
|
| 485 | + ), |
|
| 486 | + __FILE__, |
|
| 487 | + __FUNCTION__, |
|
| 488 | + __LINE__ |
|
| 489 | + ); |
|
| 490 | + } |
|
| 491 | + return; |
|
| 492 | + } |
|
| 493 | + $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
| 494 | + if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
| 495 | + $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Decodes json from the provided manifest file. |
|
| 502 | + * |
|
| 503 | + * @since 4.9.59.p |
|
| 504 | + * @param string $manifest_file Path to manifest file. |
|
| 505 | + * @return array |
|
| 506 | + * @throws InvalidFilePathException |
|
| 507 | + */ |
|
| 508 | + private function decodeManifestFile($manifest_file) |
|
| 509 | + { |
|
| 510 | + if (! file_exists($manifest_file)) { |
|
| 511 | + throw new InvalidFilePathException($manifest_file); |
|
| 512 | + } |
|
| 513 | + return json_decode(file_get_contents($manifest_file), true); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * This is used to set registered script handles that have data. |
|
| 519 | + * |
|
| 520 | + * @param string $script_handle |
|
| 521 | + */ |
|
| 522 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 523 | + { |
|
| 524 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /**i |
|
| 529 | 529 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
| 530 | 530 | * Dependency stored in WP_Scripts if its set. |
| 531 | 531 | */ |
| 532 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 533 | - { |
|
| 534 | - if (empty($this->script_handles_with_data)) { |
|
| 535 | - return; |
|
| 536 | - } |
|
| 537 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
| 538 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
| 545 | - * |
|
| 546 | - * @param string $script_handle |
|
| 547 | - */ |
|
| 548 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 549 | - { |
|
| 550 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
| 551 | - global $wp_scripts; |
|
| 552 | - $unset_handle = false; |
|
| 553 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 554 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
| 555 | - $unset_handle = true; |
|
| 556 | - } |
|
| 557 | - //deal with inline_scripts |
|
| 558 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
| 559 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
| 560 | - $unset_handle = true; |
|
| 561 | - } |
|
| 562 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
| 563 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
| 564 | - } |
|
| 565 | - if ($unset_handle) { |
|
| 566 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * register translations for a registered script |
|
| 574 | - * |
|
| 575 | - * @param string $handle |
|
| 576 | - */ |
|
| 577 | - public function registerTranslation($handle) |
|
| 578 | - { |
|
| 579 | - $this->i18n_registry->registerScriptI18n($handle); |
|
| 580 | - } |
|
| 532 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 533 | + { |
|
| 534 | + if (empty($this->script_handles_with_data)) { |
|
| 535 | + return; |
|
| 536 | + } |
|
| 537 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
| 538 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
| 545 | + * |
|
| 546 | + * @param string $script_handle |
|
| 547 | + */ |
|
| 548 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 549 | + { |
|
| 550 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
| 551 | + global $wp_scripts; |
|
| 552 | + $unset_handle = false; |
|
| 553 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 554 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
| 555 | + $unset_handle = true; |
|
| 556 | + } |
|
| 557 | + //deal with inline_scripts |
|
| 558 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
| 559 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
| 560 | + $unset_handle = true; |
|
| 561 | + } |
|
| 562 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
| 563 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
| 564 | + } |
|
| 565 | + if ($unset_handle) { |
|
| 566 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * register translations for a registered script |
|
| 574 | + * |
|
| 575 | + * @param string $handle |
|
| 576 | + */ |
|
| 577 | + public function registerTranslation($handle) |
|
| 578 | + { |
|
| 579 | + $this->i18n_registry->registerScriptI18n($handle); |
|
| 580 | + } |
|
| 581 | 581 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $script->version(), |
| 147 | 147 | $script->loadInFooter() |
| 148 | 148 | ); |
| 149 | - if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
| 149 | + if ( ! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
| 150 | 150 | throw new AssetRegistrationException($script->handle()); |
| 151 | 151 | } |
| 152 | 152 | $script->setRegistered($registered); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $this->removeAlreadyRegisteredDataForScriptHandles(); |
| 207 | 207 | wp_add_inline_script( |
| 208 | 208 | 'eejs-core', |
| 209 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
| 209 | + 'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)), |
|
| 210 | 210 | 'before' |
| 211 | 211 | ); |
| 212 | 212 | $scripts = $this->assets->getJavascriptAssetsWithData(); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | public function addData($key, $value) |
| 237 | 237 | { |
| 238 | 238 | if ($this->verifyDataNotExisting($key)) { |
| 239 | - $this->jsdata[ $key ] = $value; |
|
| 239 | + $this->jsdata[$key] = $value; |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function pushData($key, $value) |
| 259 | 259 | { |
| 260 | - if (isset($this->jsdata[ $key ]) |
|
| 261 | - && ! is_array($this->jsdata[ $key ]) |
|
| 260 | + if (isset($this->jsdata[$key]) |
|
| 261 | + && ! is_array($this->jsdata[$key]) |
|
| 262 | 262 | ) { |
| 263 | 263 | throw new InvalidArgumentException( |
| 264 | 264 | sprintf( |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | ) |
| 273 | 273 | ); |
| 274 | 274 | } |
| 275 | - $this->jsdata[ $key ][] = $value; |
|
| 275 | + $this->jsdata[$key][] = $value; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | |
@@ -286,11 +286,11 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | public function addTemplate($template_reference, $template_content) |
| 288 | 288 | { |
| 289 | - if (! isset($this->jsdata['templates'])) { |
|
| 289 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 290 | 290 | $this->jsdata['templates'] = array(); |
| 291 | 291 | } |
| 292 | 292 | //no overrides allowed. |
| 293 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
| 293 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 294 | 294 | throw new InvalidArgumentException( |
| 295 | 295 | sprintf( |
| 296 | 296 | __( |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | ) |
| 302 | 302 | ); |
| 303 | 303 | } |
| 304 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
| 304 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | public function getTemplate($template_reference) |
| 315 | 315 | { |
| 316 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
| 317 | - ? $this->jsdata['templates'][ $template_reference ] |
|
| 316 | + return isset($this->jsdata['templates'][$template_reference]) |
|
| 317 | + ? $this->jsdata['templates'][$template_reference] |
|
| 318 | 318 | : ''; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | */ |
| 328 | 328 | public function getData($key) |
| 329 | 329 | { |
| 330 | - return isset($this->jsdata[ $key ]) |
|
| 331 | - ? $this->jsdata[ $key ] |
|
| 330 | + return isset($this->jsdata[$key]) |
|
| 331 | + ? $this->jsdata[$key] |
|
| 332 | 332 | : false; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | protected function verifyDataNotExisting($key) |
| 345 | 345 | { |
| 346 | - if (isset($this->jsdata[ $key ])) { |
|
| 347 | - if (is_array($this->jsdata[ $key ])) { |
|
| 346 | + if (isset($this->jsdata[$key])) { |
|
| 347 | + if (is_array($this->jsdata[$key])) { |
|
| 348 | 348 | throw new InvalidArgumentException( |
| 349 | 349 | sprintf( |
| 350 | 350 | __( |
@@ -387,11 +387,11 @@ discard block |
||
| 387 | 387 | public function getAssetUrl($namespace, $chunk_name, $asset_type) |
| 388 | 388 | { |
| 389 | 389 | $url = isset( |
| 390 | - $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
| 391 | - $this->manifest_data[ $namespace ]['url_base'] |
|
| 390 | + $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type], |
|
| 391 | + $this->manifest_data[$namespace]['url_base'] |
|
| 392 | 392 | ) |
| 393 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
| 394 | - . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
| 393 | + ? $this->manifest_data[$namespace]['url_base'] |
|
| 394 | + . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type] |
|
| 395 | 395 | : $chunk_name; |
| 396 | 396 | return apply_filters( |
| 397 | 397 | 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | $this->registerManifestFile( |
| 442 | 442 | $manifest_file->assetNamespace(), |
| 443 | 443 | $manifest_file->urlBase(), |
| 444 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
| 444 | + $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST |
|
| 445 | 445 | ); |
| 446 | 446 | } |
| 447 | 447 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | public function registerManifestFile($namespace, $url_base, $manifest_file) |
| 461 | 461 | { |
| 462 | - if (isset($this->manifest_data[ $namespace ])) { |
|
| 462 | + if (isset($this->manifest_data[$namespace])) { |
|
| 463 | 463 | throw new InvalidArgumentException( |
| 464 | 464 | sprintf( |
| 465 | 465 | esc_html__( |
@@ -490,9 +490,9 @@ discard block |
||
| 490 | 490 | } |
| 491 | 491 | return; |
| 492 | 492 | } |
| 493 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
| 494 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
| 495 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
| 493 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
| 494 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
| 495 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | */ |
| 508 | 508 | private function decodeManifestFile($manifest_file) |
| 509 | 509 | { |
| 510 | - if (! file_exists($manifest_file)) { |
|
| 510 | + if ( ! file_exists($manifest_file)) { |
|
| 511 | 511 | throw new InvalidFilePathException($manifest_file); |
| 512 | 512 | } |
| 513 | 513 | return json_decode(file_get_contents($manifest_file), true); |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | private function addRegisteredScriptHandlesWithData($script_handle) |
| 523 | 523 | { |
| 524 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
| 524 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -547,23 +547,23 @@ discard block |
||
| 547 | 547 | */ |
| 548 | 548 | private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
| 549 | 549 | { |
| 550 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
| 550 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 551 | 551 | global $wp_scripts; |
| 552 | 552 | $unset_handle = false; |
| 553 | 553 | if ($wp_scripts->get_data($script_handle, 'data')) { |
| 554 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
| 554 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 555 | 555 | $unset_handle = true; |
| 556 | 556 | } |
| 557 | 557 | //deal with inline_scripts |
| 558 | 558 | if ($wp_scripts->get_data($script_handle, 'before')) { |
| 559 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
| 559 | + unset($wp_scripts->registered[$script_handle]->extra['before']); |
|
| 560 | 560 | $unset_handle = true; |
| 561 | 561 | } |
| 562 | 562 | if ($wp_scripts->get_data($script_handle, 'after')) { |
| 563 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
| 563 | + unset($wp_scripts->registered[$script_handle]->extra['after']); |
|
| 564 | 564 | } |
| 565 | 565 | if ($unset_handle) { |
| 566 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
| 566 | + unset($this->script_handles_with_data[$script_handle]); |
|
| 567 | 567 | } |
| 568 | 568 | } |
| 569 | 569 | } |
@@ -27,329 +27,329 @@ |
||
| 27 | 27 | class CoreAssetManager extends AssetManager |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - // WordPress core / Third party JS asset handles |
|
| 31 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
| 32 | - |
|
| 33 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 34 | - |
|
| 35 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 36 | - |
|
| 37 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 38 | - |
|
| 39 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 40 | - |
|
| 41 | - // EE JS assets handles |
|
| 42 | - const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
| 43 | - |
|
| 44 | - const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
| 45 | - |
|
| 46 | - const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
| 47 | - |
|
| 48 | - const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
| 49 | - |
|
| 50 | - const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
| 51 | - |
|
| 52 | - const JS_HANDLE_EE_I18N = 'eei18n'; |
|
| 53 | - |
|
| 54 | - const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
| 55 | - |
|
| 56 | - const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 57 | - |
|
| 58 | - // EE CSS assets handles |
|
| 59 | - const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
| 60 | - |
|
| 61 | - const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var EE_Currency_Config $currency_config |
|
| 65 | - */ |
|
| 66 | - protected $currency_config; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var EE_Template_Config $template_config |
|
| 70 | - */ |
|
| 71 | - protected $template_config; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * CoreAssetRegister constructor. |
|
| 76 | - * |
|
| 77 | - * @param AssetCollection $assets |
|
| 78 | - * @param EE_Currency_Config $currency_config |
|
| 79 | - * @param EE_Template_Config $template_config |
|
| 80 | - * @param DomainInterface $domain |
|
| 81 | - * @param Registry $registry |
|
| 82 | - */ |
|
| 83 | - public function __construct( |
|
| 84 | - AssetCollection $assets, |
|
| 85 | - EE_Currency_Config $currency_config, |
|
| 86 | - EE_Template_Config $template_config, |
|
| 87 | - DomainInterface $domain, |
|
| 88 | - Registry $registry |
|
| 89 | - ) { |
|
| 90 | - $this->currency_config = $currency_config; |
|
| 91 | - $this->template_config = $template_config; |
|
| 92 | - parent::__construct($domain, $assets, $registry); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @since 4.9.62.p |
|
| 98 | - * @throws DuplicateCollectionIdentifierException |
|
| 99 | - * @throws InvalidArgumentException |
|
| 100 | - * @throws InvalidDataTypeException |
|
| 101 | - * @throws InvalidEntityException |
|
| 102 | - */ |
|
| 103 | - public function addAssets() |
|
| 104 | - { |
|
| 105 | - $this->addJavascriptFiles(); |
|
| 106 | - $this->addStylesheetFiles(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @since 4.9.62.p |
|
| 112 | - * @throws DuplicateCollectionIdentifierException |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidDataTypeException |
|
| 115 | - * @throws InvalidEntityException |
|
| 116 | - */ |
|
| 117 | - public function addJavascriptFiles() |
|
| 118 | - { |
|
| 119 | - $this->loadCoreJs(); |
|
| 120 | - $this->loadJqueryValidate(); |
|
| 121 | - $this->loadAccountingJs(); |
|
| 122 | - add_action( |
|
| 123 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 124 | - array($this, 'loadQtipJs') |
|
| 125 | - ); |
|
| 126 | - $this->registerAdminAssets(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @since 4.9.62.p |
|
| 132 | - * @throws DuplicateCollectionIdentifierException |
|
| 133 | - * @throws InvalidDataTypeException |
|
| 134 | - * @throws InvalidEntityException |
|
| 135 | - */ |
|
| 136 | - public function addStylesheetFiles() |
|
| 137 | - { |
|
| 138 | - $this->loadCoreCss(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * core default javascript |
|
| 144 | - * |
|
| 145 | - * @since 4.9.62.p |
|
| 146 | - * @throws DuplicateCollectionIdentifierException |
|
| 147 | - * @throws InvalidArgumentException |
|
| 148 | - * @throws InvalidDataTypeException |
|
| 149 | - * @throws InvalidEntityException |
|
| 150 | - */ |
|
| 151 | - private function loadCoreJs() |
|
| 152 | - { |
|
| 153 | - $this->addJavascript( |
|
| 154 | - CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
| 155 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 156 | - ); |
|
| 157 | - |
|
| 158 | - $this->addJavascript( |
|
| 159 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
| 160 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 161 | - array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
| 162 | - ) |
|
| 163 | - ->setHasInlineData(); |
|
| 164 | - |
|
| 165 | - $this->addJavascript( |
|
| 166 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
| 167 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
| 168 | - array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - global $wp_version; |
|
| 172 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 173 | - //js.api |
|
| 174 | - $this->addJavascript( |
|
| 175 | - CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
| 176 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 177 | - array( |
|
| 178 | - CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
| 179 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 183 | - $this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/'))); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $this->addJavascript( |
|
| 187 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 188 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 189 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 190 | - ) |
|
| 191 | - ->setInlineDataCallback( |
|
| 192 | - function () { |
|
| 193 | - wp_localize_script( |
|
| 194 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 195 | - CoreAssetManager::JS_HANDLE_EE_I18N, |
|
| 196 | - EE_Registry::$i18n_js_strings |
|
| 197 | - ); |
|
| 198 | - } |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @since 4.9.62.p |
|
| 205 | - * @throws DuplicateCollectionIdentifierException |
|
| 206 | - * @throws InvalidDataTypeException |
|
| 207 | - * @throws InvalidEntityException |
|
| 208 | - */ |
|
| 209 | - private function loadCoreCss() |
|
| 210 | - { |
|
| 211 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 212 | - $this->addStylesheet( |
|
| 213 | - CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
| 214 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 215 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 216 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 217 | - array('dashicons') |
|
| 218 | - ); |
|
| 219 | - //Load custom style sheet if available |
|
| 220 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 221 | - $this->addStylesheet( |
|
| 222 | - CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
| 223 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 224 | - array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * jQuery Validate for form validation |
|
| 233 | - * |
|
| 234 | - * @since 4.9.62.p |
|
| 235 | - * @throws DuplicateCollectionIdentifierException |
|
| 236 | - * @throws InvalidDataTypeException |
|
| 237 | - * @throws InvalidEntityException |
|
| 238 | - */ |
|
| 239 | - private function loadJqueryValidate() |
|
| 240 | - { |
|
| 241 | - $this->addJavascript( |
|
| 242 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 243 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 244 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 245 | - ) |
|
| 246 | - ->setVersion('1.15.0'); |
|
| 247 | - |
|
| 248 | - $this->addJavascript( |
|
| 249 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 250 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 251 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 252 | - ) |
|
| 253 | - ->setVersion('1.15.0'); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * accounting.js for performing client-side calculations |
|
| 259 | - * |
|
| 260 | - * @since 4.9.62.p |
|
| 261 | - * @throws DuplicateCollectionIdentifierException |
|
| 262 | - * @throws InvalidDataTypeException |
|
| 263 | - * @throws InvalidEntityException |
|
| 264 | - */ |
|
| 265 | - private function loadAccountingJs() |
|
| 266 | - { |
|
| 267 | - //accounting.js library |
|
| 268 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 269 | - $this->addJavascript( |
|
| 270 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 271 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 272 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 273 | - ) |
|
| 274 | - ->setVersion('0.3.2'); |
|
| 275 | - |
|
| 276 | - $currency_config = $this->currency_config; |
|
| 277 | - $this->addJavascript( |
|
| 278 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 279 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 280 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 281 | - ) |
|
| 282 | - ->setInlineDataCallback( |
|
| 283 | - function () use ($currency_config) { |
|
| 284 | - wp_localize_script( |
|
| 285 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 286 | - 'EE_ACCOUNTING_CFG', |
|
| 287 | - array( |
|
| 288 | - 'currency' => array( |
|
| 289 | - 'symbol' => $currency_config->sign, |
|
| 290 | - 'format' => array( |
|
| 291 | - 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 292 | - 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 293 | - 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 294 | - ), |
|
| 295 | - 'decimal' => $currency_config->dec_mrk, |
|
| 296 | - 'thousand' => $currency_config->thsnds, |
|
| 297 | - 'precision' => $currency_config->dec_plc, |
|
| 298 | - ), |
|
| 299 | - 'number' => array( |
|
| 300 | - 'precision' => $currency_config->dec_plc, |
|
| 301 | - 'thousand' => $currency_config->thsnds, |
|
| 302 | - 'decimal' => $currency_config->dec_mrk, |
|
| 303 | - ), |
|
| 304 | - ) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - ) |
|
| 308 | - ->setVersion(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * registers assets for cleaning your ears |
|
| 314 | - * |
|
| 315 | - * @param JavascriptAsset $script |
|
| 316 | - */ |
|
| 317 | - public function loadQtipJs(JavascriptAsset $script) |
|
| 318 | - { |
|
| 319 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 320 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 321 | - if ( |
|
| 322 | - $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
| 323 | - && apply_filters('FHEE_load_qtip', false) |
|
| 324 | - ) { |
|
| 325 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * assets that are used in the WordPress admin |
|
| 332 | - * |
|
| 333 | - * @since 4.9.62.p |
|
| 334 | - * @throws DuplicateCollectionIdentifierException |
|
| 335 | - * @throws InvalidDataTypeException |
|
| 336 | - * @throws InvalidEntityException |
|
| 337 | - */ |
|
| 338 | - private function registerAdminAssets() |
|
| 339 | - { |
|
| 340 | - $this->addJavascript( |
|
| 341 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 342 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 343 | - array( |
|
| 344 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 345 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
| 346 | - ) |
|
| 347 | - ) |
|
| 348 | - ->setRequiresTranslation(); |
|
| 349 | - |
|
| 350 | - $this->addStylesheet( |
|
| 351 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 352 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 353 | - ); |
|
| 354 | - } |
|
| 30 | + // WordPress core / Third party JS asset handles |
|
| 31 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
| 32 | + |
|
| 33 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 34 | + |
|
| 35 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 36 | + |
|
| 37 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 38 | + |
|
| 39 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 40 | + |
|
| 41 | + // EE JS assets handles |
|
| 42 | + const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
| 43 | + |
|
| 44 | + const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
| 45 | + |
|
| 46 | + const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
| 47 | + |
|
| 48 | + const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
| 49 | + |
|
| 50 | + const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
| 51 | + |
|
| 52 | + const JS_HANDLE_EE_I18N = 'eei18n'; |
|
| 53 | + |
|
| 54 | + const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
| 55 | + |
|
| 56 | + const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 57 | + |
|
| 58 | + // EE CSS assets handles |
|
| 59 | + const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
| 60 | + |
|
| 61 | + const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var EE_Currency_Config $currency_config |
|
| 65 | + */ |
|
| 66 | + protected $currency_config; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var EE_Template_Config $template_config |
|
| 70 | + */ |
|
| 71 | + protected $template_config; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * CoreAssetRegister constructor. |
|
| 76 | + * |
|
| 77 | + * @param AssetCollection $assets |
|
| 78 | + * @param EE_Currency_Config $currency_config |
|
| 79 | + * @param EE_Template_Config $template_config |
|
| 80 | + * @param DomainInterface $domain |
|
| 81 | + * @param Registry $registry |
|
| 82 | + */ |
|
| 83 | + public function __construct( |
|
| 84 | + AssetCollection $assets, |
|
| 85 | + EE_Currency_Config $currency_config, |
|
| 86 | + EE_Template_Config $template_config, |
|
| 87 | + DomainInterface $domain, |
|
| 88 | + Registry $registry |
|
| 89 | + ) { |
|
| 90 | + $this->currency_config = $currency_config; |
|
| 91 | + $this->template_config = $template_config; |
|
| 92 | + parent::__construct($domain, $assets, $registry); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @since 4.9.62.p |
|
| 98 | + * @throws DuplicateCollectionIdentifierException |
|
| 99 | + * @throws InvalidArgumentException |
|
| 100 | + * @throws InvalidDataTypeException |
|
| 101 | + * @throws InvalidEntityException |
|
| 102 | + */ |
|
| 103 | + public function addAssets() |
|
| 104 | + { |
|
| 105 | + $this->addJavascriptFiles(); |
|
| 106 | + $this->addStylesheetFiles(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @since 4.9.62.p |
|
| 112 | + * @throws DuplicateCollectionIdentifierException |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidDataTypeException |
|
| 115 | + * @throws InvalidEntityException |
|
| 116 | + */ |
|
| 117 | + public function addJavascriptFiles() |
|
| 118 | + { |
|
| 119 | + $this->loadCoreJs(); |
|
| 120 | + $this->loadJqueryValidate(); |
|
| 121 | + $this->loadAccountingJs(); |
|
| 122 | + add_action( |
|
| 123 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 124 | + array($this, 'loadQtipJs') |
|
| 125 | + ); |
|
| 126 | + $this->registerAdminAssets(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @since 4.9.62.p |
|
| 132 | + * @throws DuplicateCollectionIdentifierException |
|
| 133 | + * @throws InvalidDataTypeException |
|
| 134 | + * @throws InvalidEntityException |
|
| 135 | + */ |
|
| 136 | + public function addStylesheetFiles() |
|
| 137 | + { |
|
| 138 | + $this->loadCoreCss(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * core default javascript |
|
| 144 | + * |
|
| 145 | + * @since 4.9.62.p |
|
| 146 | + * @throws DuplicateCollectionIdentifierException |
|
| 147 | + * @throws InvalidArgumentException |
|
| 148 | + * @throws InvalidDataTypeException |
|
| 149 | + * @throws InvalidEntityException |
|
| 150 | + */ |
|
| 151 | + private function loadCoreJs() |
|
| 152 | + { |
|
| 153 | + $this->addJavascript( |
|
| 154 | + CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
| 155 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 156 | + ); |
|
| 157 | + |
|
| 158 | + $this->addJavascript( |
|
| 159 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
| 160 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 161 | + array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
| 162 | + ) |
|
| 163 | + ->setHasInlineData(); |
|
| 164 | + |
|
| 165 | + $this->addJavascript( |
|
| 166 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
| 167 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
| 168 | + array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + global $wp_version; |
|
| 172 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 173 | + //js.api |
|
| 174 | + $this->addJavascript( |
|
| 175 | + CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
| 176 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 177 | + array( |
|
| 178 | + CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
| 179 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 183 | + $this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/'))); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $this->addJavascript( |
|
| 187 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 188 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 189 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 190 | + ) |
|
| 191 | + ->setInlineDataCallback( |
|
| 192 | + function () { |
|
| 193 | + wp_localize_script( |
|
| 194 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
| 195 | + CoreAssetManager::JS_HANDLE_EE_I18N, |
|
| 196 | + EE_Registry::$i18n_js_strings |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @since 4.9.62.p |
|
| 205 | + * @throws DuplicateCollectionIdentifierException |
|
| 206 | + * @throws InvalidDataTypeException |
|
| 207 | + * @throws InvalidEntityException |
|
| 208 | + */ |
|
| 209 | + private function loadCoreCss() |
|
| 210 | + { |
|
| 211 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 212 | + $this->addStylesheet( |
|
| 213 | + CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
| 214 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 215 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 216 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 217 | + array('dashicons') |
|
| 218 | + ); |
|
| 219 | + //Load custom style sheet if available |
|
| 220 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 221 | + $this->addStylesheet( |
|
| 222 | + CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
| 223 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 224 | + array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * jQuery Validate for form validation |
|
| 233 | + * |
|
| 234 | + * @since 4.9.62.p |
|
| 235 | + * @throws DuplicateCollectionIdentifierException |
|
| 236 | + * @throws InvalidDataTypeException |
|
| 237 | + * @throws InvalidEntityException |
|
| 238 | + */ |
|
| 239 | + private function loadJqueryValidate() |
|
| 240 | + { |
|
| 241 | + $this->addJavascript( |
|
| 242 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 243 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 244 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 245 | + ) |
|
| 246 | + ->setVersion('1.15.0'); |
|
| 247 | + |
|
| 248 | + $this->addJavascript( |
|
| 249 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 250 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 251 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 252 | + ) |
|
| 253 | + ->setVersion('1.15.0'); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * accounting.js for performing client-side calculations |
|
| 259 | + * |
|
| 260 | + * @since 4.9.62.p |
|
| 261 | + * @throws DuplicateCollectionIdentifierException |
|
| 262 | + * @throws InvalidDataTypeException |
|
| 263 | + * @throws InvalidEntityException |
|
| 264 | + */ |
|
| 265 | + private function loadAccountingJs() |
|
| 266 | + { |
|
| 267 | + //accounting.js library |
|
| 268 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 269 | + $this->addJavascript( |
|
| 270 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 271 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 272 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 273 | + ) |
|
| 274 | + ->setVersion('0.3.2'); |
|
| 275 | + |
|
| 276 | + $currency_config = $this->currency_config; |
|
| 277 | + $this->addJavascript( |
|
| 278 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 279 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 280 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 281 | + ) |
|
| 282 | + ->setInlineDataCallback( |
|
| 283 | + function () use ($currency_config) { |
|
| 284 | + wp_localize_script( |
|
| 285 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
| 286 | + 'EE_ACCOUNTING_CFG', |
|
| 287 | + array( |
|
| 288 | + 'currency' => array( |
|
| 289 | + 'symbol' => $currency_config->sign, |
|
| 290 | + 'format' => array( |
|
| 291 | + 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 292 | + 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 293 | + 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 294 | + ), |
|
| 295 | + 'decimal' => $currency_config->dec_mrk, |
|
| 296 | + 'thousand' => $currency_config->thsnds, |
|
| 297 | + 'precision' => $currency_config->dec_plc, |
|
| 298 | + ), |
|
| 299 | + 'number' => array( |
|
| 300 | + 'precision' => $currency_config->dec_plc, |
|
| 301 | + 'thousand' => $currency_config->thsnds, |
|
| 302 | + 'decimal' => $currency_config->dec_mrk, |
|
| 303 | + ), |
|
| 304 | + ) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + ) |
|
| 308 | + ->setVersion(); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * registers assets for cleaning your ears |
|
| 314 | + * |
|
| 315 | + * @param JavascriptAsset $script |
|
| 316 | + */ |
|
| 317 | + public function loadQtipJs(JavascriptAsset $script) |
|
| 318 | + { |
|
| 319 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 320 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 321 | + if ( |
|
| 322 | + $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
| 323 | + && apply_filters('FHEE_load_qtip', false) |
|
| 324 | + ) { |
|
| 325 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * assets that are used in the WordPress admin |
|
| 332 | + * |
|
| 333 | + * @since 4.9.62.p |
|
| 334 | + * @throws DuplicateCollectionIdentifierException |
|
| 335 | + * @throws InvalidDataTypeException |
|
| 336 | + * @throws InvalidEntityException |
|
| 337 | + */ |
|
| 338 | + private function registerAdminAssets() |
|
| 339 | + { |
|
| 340 | + $this->addJavascript( |
|
| 341 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 342 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 343 | + array( |
|
| 344 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 345 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
| 346 | + ) |
|
| 347 | + ) |
|
| 348 | + ->setRequiresTranslation(); |
|
| 349 | + |
|
| 350 | + $this->addStylesheet( |
|
| 351 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
| 352 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | 355 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | //js.api |
| 174 | 174 | $this->addJavascript( |
| 175 | 175 | CoreAssetManager::JS_HANDLE_EE_JS_API, |
| 176 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 176 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 177 | 177 | array( |
| 178 | 178 | CoreAssetManager::JS_HANDLE_UNDERSCORE, |
| 179 | 179 | CoreAssetManager::JS_HANDLE_EE_JS_CORE |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | $this->addJavascript( |
| 187 | 187 | CoreAssetManager::JS_HANDLE_EE_CORE, |
| 188 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 188 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 189 | 189 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 190 | 190 | ) |
| 191 | 191 | ->setInlineDataCallback( |
| 192 | - function () { |
|
| 192 | + function() { |
|
| 193 | 193 | wp_localize_script( |
| 194 | 194 | CoreAssetManager::JS_HANDLE_EE_CORE, |
| 195 | 195 | CoreAssetManager::JS_HANDLE_EE_I18N, |
@@ -211,16 +211,16 @@ discard block |
||
| 211 | 211 | if ($this->template_config->enable_default_style && ! is_admin()) { |
| 212 | 212 | $this->addStylesheet( |
| 213 | 213 | CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
| 214 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 214 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 215 | 215 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 216 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 216 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
| 217 | 217 | array('dashicons') |
| 218 | 218 | ); |
| 219 | 219 | //Load custom style sheet if available |
| 220 | 220 | if ($this->template_config->custom_style_sheet !== null) { |
| 221 | 221 | $this->addStylesheet( |
| 222 | 222 | CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
| 223 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 223 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 224 | 224 | array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
| 225 | 225 | ); |
| 226 | 226 | } |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | { |
| 241 | 241 | $this->addJavascript( |
| 242 | 242 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
| 243 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 243 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 244 | 244 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 245 | 245 | ) |
| 246 | 246 | ->setVersion('1.15.0'); |
| 247 | 247 | |
| 248 | 248 | $this->addJavascript( |
| 249 | 249 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
| 250 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 250 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 251 | 251 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
| 252 | 252 | ) |
| 253 | 253 | ->setVersion('1.15.0'); |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 269 | 269 | $this->addJavascript( |
| 270 | 270 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
| 271 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 271 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 272 | 272 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
| 273 | 273 | ) |
| 274 | 274 | ->setVersion('0.3.2'); |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | $currency_config = $this->currency_config; |
| 277 | 277 | $this->addJavascript( |
| 278 | 278 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
| 279 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 279 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 280 | 280 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
| 281 | 281 | ) |
| 282 | 282 | ->setInlineDataCallback( |
| 283 | - function () use ($currency_config) { |
|
| 283 | + function() use ($currency_config) { |
|
| 284 | 284 | wp_localize_script( |
| 285 | 285 | CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
| 286 | 286 | 'EE_ACCOUNTING_CFG', |
@@ -17,142 +17,142 @@ |
||
| 17 | 17 | class JavascriptAsset extends BrowserAsset |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var boolean $load_in_footer |
|
| 22 | - */ |
|
| 23 | - private $load_in_footer = false; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var boolean $requires_translation |
|
| 27 | - */ |
|
| 28 | - private $requires_translation = false; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var boolean $has_inline_data |
|
| 32 | - */ |
|
| 33 | - private $has_inline_data = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var Closure $inline_data_callback |
|
| 37 | - */ |
|
| 38 | - private $inline_data_callback; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Asset constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $handle |
|
| 45 | - * @param string $source |
|
| 46 | - * @param array $dependencies |
|
| 47 | - * @param bool $load_in_footer |
|
| 48 | - * @param DomainInterface $domain |
|
| 49 | - * @throws InvalidDataTypeException |
|
| 50 | - */ |
|
| 51 | - public function __construct( |
|
| 52 | - $handle, |
|
| 53 | - $source, |
|
| 54 | - array $dependencies, |
|
| 55 | - $load_in_footer, |
|
| 56 | - DomainInterface $domain |
|
| 57 | - ) { |
|
| 58 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
| 59 | - $this->setLoadInFooter($load_in_footer); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @return bool |
|
| 65 | - */ |
|
| 66 | - public function loadInFooter() |
|
| 67 | - { |
|
| 68 | - return $this->load_in_footer; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $load_in_footer |
|
| 74 | - */ |
|
| 75 | - private function setLoadInFooter($load_in_footer = true) |
|
| 76 | - { |
|
| 77 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return bool |
|
| 83 | - */ |
|
| 84 | - public function requiresTranslation() |
|
| 85 | - { |
|
| 86 | - return $this->requires_translation; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param bool $requires_translation |
|
| 92 | - * @return JavascriptAsset |
|
| 93 | - */ |
|
| 94 | - public function setRequiresTranslation($requires_translation = true) |
|
| 95 | - { |
|
| 96 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
| 97 | - return $this; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - public function hasInlineData() |
|
| 105 | - { |
|
| 106 | - return $this->has_inline_data; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param bool $has_inline_data |
|
| 112 | - * @return JavascriptAsset |
|
| 113 | - */ |
|
| 114 | - public function setHasInlineData($has_inline_data = true) |
|
| 115 | - { |
|
| 116 | - $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
| 117 | - return $this; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return Closure |
|
| 123 | - */ |
|
| 124 | - public function inlineDataCallback() |
|
| 125 | - { |
|
| 126 | - return $this->inline_data_callback; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function hasInlineDataCallback() |
|
| 134 | - { |
|
| 135 | - return $this->inline_data_callback instanceof Closure; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param Closure $inline_data_callback |
|
| 141 | - * @return JavascriptAsset |
|
| 142 | - */ |
|
| 143 | - public function setInlineDataCallback(Closure $inline_data_callback) |
|
| 144 | - { |
|
| 145 | - $this->inline_data_callback = $inline_data_callback; |
|
| 146 | - $this->setHasInlineData(); |
|
| 147 | - return $this; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @since 4.9.62.p |
|
| 153 | - */ |
|
| 154 | - public function enqueueAsset() |
|
| 155 | - { |
|
| 156 | - wp_enqueue_script($this->handle()); |
|
| 157 | - } |
|
| 20 | + /** |
|
| 21 | + * @var boolean $load_in_footer |
|
| 22 | + */ |
|
| 23 | + private $load_in_footer = false; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var boolean $requires_translation |
|
| 27 | + */ |
|
| 28 | + private $requires_translation = false; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var boolean $has_inline_data |
|
| 32 | + */ |
|
| 33 | + private $has_inline_data = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var Closure $inline_data_callback |
|
| 37 | + */ |
|
| 38 | + private $inline_data_callback; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Asset constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $handle |
|
| 45 | + * @param string $source |
|
| 46 | + * @param array $dependencies |
|
| 47 | + * @param bool $load_in_footer |
|
| 48 | + * @param DomainInterface $domain |
|
| 49 | + * @throws InvalidDataTypeException |
|
| 50 | + */ |
|
| 51 | + public function __construct( |
|
| 52 | + $handle, |
|
| 53 | + $source, |
|
| 54 | + array $dependencies, |
|
| 55 | + $load_in_footer, |
|
| 56 | + DomainInterface $domain |
|
| 57 | + ) { |
|
| 58 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
| 59 | + $this->setLoadInFooter($load_in_footer); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @return bool |
|
| 65 | + */ |
|
| 66 | + public function loadInFooter() |
|
| 67 | + { |
|
| 68 | + return $this->load_in_footer; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $load_in_footer |
|
| 74 | + */ |
|
| 75 | + private function setLoadInFooter($load_in_footer = true) |
|
| 76 | + { |
|
| 77 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return bool |
|
| 83 | + */ |
|
| 84 | + public function requiresTranslation() |
|
| 85 | + { |
|
| 86 | + return $this->requires_translation; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param bool $requires_translation |
|
| 92 | + * @return JavascriptAsset |
|
| 93 | + */ |
|
| 94 | + public function setRequiresTranslation($requires_translation = true) |
|
| 95 | + { |
|
| 96 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
| 97 | + return $this; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + public function hasInlineData() |
|
| 105 | + { |
|
| 106 | + return $this->has_inline_data; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param bool $has_inline_data |
|
| 112 | + * @return JavascriptAsset |
|
| 113 | + */ |
|
| 114 | + public function setHasInlineData($has_inline_data = true) |
|
| 115 | + { |
|
| 116 | + $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
| 117 | + return $this; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return Closure |
|
| 123 | + */ |
|
| 124 | + public function inlineDataCallback() |
|
| 125 | + { |
|
| 126 | + return $this->inline_data_callback; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function hasInlineDataCallback() |
|
| 134 | + { |
|
| 135 | + return $this->inline_data_callback instanceof Closure; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param Closure $inline_data_callback |
|
| 141 | + * @return JavascriptAsset |
|
| 142 | + */ |
|
| 143 | + public function setInlineDataCallback(Closure $inline_data_callback) |
|
| 144 | + { |
|
| 145 | + $this->inline_data_callback = $inline_data_callback; |
|
| 146 | + $this->setHasInlineData(); |
|
| 147 | + return $this; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @since 4.9.62.p |
|
| 153 | + */ |
|
| 154 | + public function enqueueAsset() |
|
| 155 | + { |
|
| 156 | + wp_enqueue_script($this->handle()); |
|
| 157 | + } |
|
| 158 | 158 | } |