@@ -23,44 +23,44 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class RouteMatchSpecificationFactory extends FactoryWithDependencyResolver implements InterminableInterface |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * RouteMatchSpecificationFactory constructor |
|
| 28 | - * |
|
| 29 | - * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
| 30 | - * @param LoaderInterface $loader |
|
| 31 | - */ |
|
| 32 | - public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
| 33 | - { |
|
| 34 | - parent::__construct($dependency_resolver, $loader); |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * RouteMatchSpecificationFactory constructor |
|
| 28 | + * |
|
| 29 | + * @param RouteMatchSpecificationDependencyResolver $dependency_resolver |
|
| 30 | + * @param LoaderInterface $loader |
|
| 31 | + */ |
|
| 32 | + public function __construct(RouteMatchSpecificationDependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
| 33 | + { |
|
| 34 | + parent::__construct($dependency_resolver, $loader); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $fqcn |
|
| 39 | - * @return RouteMatchSpecification |
|
| 40 | - * @throws InvalidDataTypeException |
|
| 41 | - * @since 4.9.71.p |
|
| 42 | - */ |
|
| 43 | - public function createNewRouteMatchSpecification(string $fqcn): RouteMatchSpecification |
|
| 44 | - { |
|
| 45 | - $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
| 46 | - return $this->loader()->getShared($fqcn); |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string $fqcn |
|
| 39 | + * @return RouteMatchSpecification |
|
| 40 | + * @throws InvalidDataTypeException |
|
| 41 | + * @since 4.9.71.p |
|
| 42 | + */ |
|
| 43 | + public function createNewRouteMatchSpecification(string $fqcn): RouteMatchSpecification |
|
| 44 | + { |
|
| 45 | + $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
| 46 | + return $this->loader()->getShared($fqcn); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $fqcn |
|
| 52 | - * @return RouteMatchSpecification |
|
| 53 | - * @throws InvalidArgumentException |
|
| 54 | - * @throws InvalidDataTypeException |
|
| 55 | - * @throws InvalidInterfaceException |
|
| 56 | - * @since 4.9.71.p |
|
| 57 | - */ |
|
| 58 | - public static function create($fqcn): RouteMatchSpecification |
|
| 59 | - { |
|
| 60 | - /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
| 61 | - $specification_factory = LoaderFactory::getLoader()->getShared( |
|
| 62 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' |
|
| 63 | - ); |
|
| 64 | - return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
| 65 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $fqcn |
|
| 52 | + * @return RouteMatchSpecification |
|
| 53 | + * @throws InvalidArgumentException |
|
| 54 | + * @throws InvalidDataTypeException |
|
| 55 | + * @throws InvalidInterfaceException |
|
| 56 | + * @since 4.9.71.p |
|
| 57 | + */ |
|
| 58 | + public static function create($fqcn): RouteMatchSpecification |
|
| 59 | + { |
|
| 60 | + /** @var RouteMatchSpecificationFactory $specification_factory */ |
|
| 61 | + $specification_factory = LoaderFactory::getLoader()->getShared( |
|
| 62 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' |
|
| 63 | + ); |
|
| 64 | + return $specification_factory->createNewRouteMatchSpecification($fqcn); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -15,36 +15,36 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class RouteMatchSpecificationCollection extends Collection |
| 17 | 17 | { |
| 18 | - const COLLECTION_NAME = 'route_match_specifications'; |
|
| 18 | + const COLLECTION_NAME = 'route_match_specifications'; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * RouteMatchSpecificationCollection constructor |
|
| 23 | - * |
|
| 24 | - * @throws InvalidInterfaceException |
|
| 25 | - */ |
|
| 26 | - public function __construct() |
|
| 27 | - { |
|
| 28 | - parent::__construct( |
|
| 29 | - 'EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecificationInterface', |
|
| 30 | - RouteMatchSpecificationCollection::COLLECTION_NAME |
|
| 31 | - ); |
|
| 32 | - } |
|
| 21 | + /** |
|
| 22 | + * RouteMatchSpecificationCollection constructor |
|
| 23 | + * |
|
| 24 | + * @throws InvalidInterfaceException |
|
| 25 | + */ |
|
| 26 | + public function __construct() |
|
| 27 | + { |
|
| 28 | + parent::__construct( |
|
| 29 | + 'EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecificationInterface', |
|
| 30 | + RouteMatchSpecificationCollection::COLLECTION_NAME |
|
| 31 | + ); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * getIdentifier |
|
| 37 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 38 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
| 39 | - * |
|
| 40 | - * @param $object |
|
| 41 | - * @param mixed $identifier |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function getIdentifier($object, $identifier = null): string |
|
| 45 | - { |
|
| 46 | - return ! empty($identifier) |
|
| 47 | - ? $identifier |
|
| 48 | - : get_class($object); |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * getIdentifier |
|
| 37 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 38 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
| 39 | + * |
|
| 40 | + * @param $object |
|
| 41 | + * @param mixed $identifier |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function getIdentifier($object, $identifier = null): string |
|
| 45 | + { |
|
| 46 | + return ! empty($identifier) |
|
| 47 | + ? $identifier |
|
| 48 | + : get_class($object); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -15,76 +15,76 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class RouteCollection extends Collection |
| 17 | 17 | { |
| 18 | - const COLLECTION_NAME = 'routes'; |
|
| 18 | + const COLLECTION_NAME = 'routes'; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * RouteMatchSpecificationCollection constructor |
|
| 23 | - * |
|
| 24 | - * @throws InvalidInterfaceException |
|
| 25 | - */ |
|
| 26 | - public function __construct() |
|
| 27 | - { |
|
| 28 | - parent::__construct( |
|
| 29 | - 'EventEspresso\core\services\routing\RouteInterface', |
|
| 30 | - RouteCollection::COLLECTION_NAME |
|
| 31 | - ); |
|
| 32 | - } |
|
| 21 | + /** |
|
| 22 | + * RouteMatchSpecificationCollection constructor |
|
| 23 | + * |
|
| 24 | + * @throws InvalidInterfaceException |
|
| 25 | + */ |
|
| 26 | + public function __construct() |
|
| 27 | + { |
|
| 28 | + parent::__construct( |
|
| 29 | + 'EventEspresso\core\services\routing\RouteInterface', |
|
| 30 | + RouteCollection::COLLECTION_NAME |
|
| 31 | + ); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * getIdentifier |
|
| 37 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 38 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
| 39 | - * |
|
| 40 | - * @param $object |
|
| 41 | - * @param mixed $identifier |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function getIdentifier($object, $identifier = null): string |
|
| 45 | - { |
|
| 46 | - return ! empty($identifier) |
|
| 47 | - ? $identifier |
|
| 48 | - : get_class($object); |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * getIdentifier |
|
| 37 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
| 38 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
| 39 | + * |
|
| 40 | + * @param $object |
|
| 41 | + * @param mixed $identifier |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function getIdentifier($object, $identifier = null): string |
|
| 45 | + { |
|
| 46 | + return ! empty($identifier) |
|
| 47 | + ? $identifier |
|
| 48 | + : get_class($object); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * finds and returns all Routes that have yet to be handled |
|
| 54 | - * |
|
| 55 | - * @return RouteInterface[] |
|
| 56 | - */ |
|
| 57 | - public function getRoutesForCurrentRequest(): array |
|
| 58 | - { |
|
| 59 | - $routes = []; |
|
| 60 | - $this->rewind(); |
|
| 61 | - while ($this->valid()) { |
|
| 62 | - /** @var RouteInterface $route */ |
|
| 63 | - $route = $this->current(); |
|
| 64 | - if ($route->matchesCurrentRequest()) { |
|
| 65 | - $routes[] = $route; |
|
| 66 | - } |
|
| 67 | - $this->next(); |
|
| 68 | - } |
|
| 69 | - $this->rewind(); |
|
| 70 | - return $routes; |
|
| 71 | - } |
|
| 52 | + /** |
|
| 53 | + * finds and returns all Routes that have yet to be handled |
|
| 54 | + * |
|
| 55 | + * @return RouteInterface[] |
|
| 56 | + */ |
|
| 57 | + public function getRoutesForCurrentRequest(): array |
|
| 58 | + { |
|
| 59 | + $routes = []; |
|
| 60 | + $this->rewind(); |
|
| 61 | + while ($this->valid()) { |
|
| 62 | + /** @var RouteInterface $route */ |
|
| 63 | + $route = $this->current(); |
|
| 64 | + if ($route->matchesCurrentRequest()) { |
|
| 65 | + $routes[] = $route; |
|
| 66 | + } |
|
| 67 | + $this->next(); |
|
| 68 | + } |
|
| 69 | + $this->rewind(); |
|
| 70 | + return $routes; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * calls RouteInterface::handleRequest() on all Routes that |
|
| 76 | - * - match current request |
|
| 77 | - * - have yet to be handled |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public function handleRoutesForCurrentRequest() |
|
| 82 | - { |
|
| 83 | - $this->rewind(); |
|
| 84 | - while ($this->valid()) { |
|
| 85 | - $this->current()->handleRequest(); |
|
| 86 | - $this->next(); |
|
| 87 | - } |
|
| 88 | - $this->rewind(); |
|
| 89 | - } |
|
| 74 | + /** |
|
| 75 | + * calls RouteInterface::handleRequest() on all Routes that |
|
| 76 | + * - match current request |
|
| 77 | + * - have yet to be handled |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public function handleRoutesForCurrentRequest() |
|
| 82 | + { |
|
| 83 | + $this->rewind(); |
|
| 84 | + while ($this->valid()) { |
|
| 85 | + $this->current()->handleRequest(); |
|
| 86 | + $this->next(); |
|
| 87 | + } |
|
| 88 | + $this->rewind(); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -15,119 +15,119 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ObjectIdentifier |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * used to separate the FQCN from the class's arguments identifier |
|
| 20 | - */ |
|
| 21 | - const DELIMITER = '____'; |
|
| 18 | + /** |
|
| 19 | + * used to separate the FQCN from the class's arguments identifier |
|
| 20 | + */ |
|
| 21 | + const DELIMITER = '____'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var ClassInterfaceCache $class_cache |
|
| 25 | - */ |
|
| 26 | - private $class_cache; |
|
| 23 | + /** |
|
| 24 | + * @var ClassInterfaceCache $class_cache |
|
| 25 | + */ |
|
| 26 | + private $class_cache; |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * ObjectIdentifier constructor. |
|
| 31 | - * |
|
| 32 | - * @param ClassInterfaceCache $class_cache |
|
| 33 | - */ |
|
| 34 | - public function __construct(ClassInterfaceCache $class_cache) |
|
| 35 | - { |
|
| 36 | - $this->class_cache = $class_cache; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * ObjectIdentifier constructor. |
|
| 31 | + * |
|
| 32 | + * @param ClassInterfaceCache $class_cache |
|
| 33 | + */ |
|
| 34 | + public function __construct(ClassInterfaceCache $class_cache) |
|
| 35 | + { |
|
| 36 | + $this->class_cache = $class_cache; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Returns true if the supplied $object_identifier contains |
|
| 42 | - * the delimiter used to separate an fqcn from the arguments hash |
|
| 43 | - * |
|
| 44 | - * @param string $object_identifier |
|
| 45 | - * @return bool |
|
| 46 | - */ |
|
| 47 | - public function hasArguments(string $object_identifier): bool |
|
| 48 | - { |
|
| 49 | - // type casting to bool instead of using strpos() !== false |
|
| 50 | - // because an object identifier should never begin with the delimiter |
|
| 51 | - // therefore the delimiter should NOT be found at position 0 |
|
| 52 | - return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); |
|
| 53 | - } |
|
| 40 | + /** |
|
| 41 | + * Returns true if the supplied $object_identifier contains |
|
| 42 | + * the delimiter used to separate an fqcn from the arguments hash |
|
| 43 | + * |
|
| 44 | + * @param string $object_identifier |
|
| 45 | + * @return bool |
|
| 46 | + */ |
|
| 47 | + public function hasArguments(string $object_identifier): bool |
|
| 48 | + { |
|
| 49 | + // type casting to bool instead of using strpos() !== false |
|
| 50 | + // because an object identifier should never begin with the delimiter |
|
| 51 | + // therefore the delimiter should NOT be found at position 0 |
|
| 52 | + return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Returns true if the supplied FQCN equals the supplied $object_identifier |
|
| 58 | - * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier |
|
| 59 | - * AND that $object_identifier is for an object with arguments. |
|
| 60 | - * This allows a request for an object using a FQCN to match |
|
| 61 | - * a previously instantiated object with arguments |
|
| 62 | - * without having to know those arguments. |
|
| 63 | - * |
|
| 64 | - * @param string $fqcn |
|
| 65 | - * @param string $object_identifier |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function fqcnMatchesObjectIdentifier(string $fqcn, string $object_identifier): bool |
|
| 69 | - { |
|
| 70 | - $fqcn = str_replace('\\', '_', $fqcn); |
|
| 71 | - return $fqcn === $object_identifier |
|
| 72 | - || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; |
|
| 73 | - } |
|
| 56 | + /** |
|
| 57 | + * Returns true if the supplied FQCN equals the supplied $object_identifier |
|
| 58 | + * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier |
|
| 59 | + * AND that $object_identifier is for an object with arguments. |
|
| 60 | + * This allows a request for an object using a FQCN to match |
|
| 61 | + * a previously instantiated object with arguments |
|
| 62 | + * without having to know those arguments. |
|
| 63 | + * |
|
| 64 | + * @param string $fqcn |
|
| 65 | + * @param string $object_identifier |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function fqcnMatchesObjectIdentifier(string $fqcn, string $object_identifier): bool |
|
| 69 | + { |
|
| 70 | + $fqcn = str_replace('\\', '_', $fqcn); |
|
| 71 | + return $fqcn === $object_identifier |
|
| 72 | + || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * build a string representation of an object's FQCN and arguments |
|
| 78 | - * |
|
| 79 | - * @param string $fqcn |
|
| 80 | - * @param array $arguments |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function getIdentifier(string $fqcn, array $arguments = array()): string |
|
| 84 | - { |
|
| 85 | - // only build identifier from arguments if class is not ReservedInstanceInterface |
|
| 86 | - $identifier = ! $this->class_cache->hasInterface( |
|
| 87 | - $fqcn, |
|
| 88 | - 'EventEspresso\core\interfaces\ReservedInstanceInterface' |
|
| 89 | - ) |
|
| 90 | - ? $this->getIdentifierForArguments($arguments) |
|
| 91 | - : ''; |
|
| 92 | - if (! empty($identifier)) { |
|
| 93 | - $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); |
|
| 94 | - } |
|
| 95 | - $fqcn = str_replace('\\', '_', $fqcn); |
|
| 96 | - return $fqcn; |
|
| 97 | - } |
|
| 76 | + /** |
|
| 77 | + * build a string representation of an object's FQCN and arguments |
|
| 78 | + * |
|
| 79 | + * @param string $fqcn |
|
| 80 | + * @param array $arguments |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function getIdentifier(string $fqcn, array $arguments = array()): string |
|
| 84 | + { |
|
| 85 | + // only build identifier from arguments if class is not ReservedInstanceInterface |
|
| 86 | + $identifier = ! $this->class_cache->hasInterface( |
|
| 87 | + $fqcn, |
|
| 88 | + 'EventEspresso\core\interfaces\ReservedInstanceInterface' |
|
| 89 | + ) |
|
| 90 | + ? $this->getIdentifierForArguments($arguments) |
|
| 91 | + : ''; |
|
| 92 | + if (! empty($identifier)) { |
|
| 93 | + $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); |
|
| 94 | + } |
|
| 95 | + $fqcn = str_replace('\\', '_', $fqcn); |
|
| 96 | + return $fqcn; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * build a string representation of a object's arguments |
|
| 102 | - * (mostly because Closures can't be serialized) |
|
| 103 | - * |
|
| 104 | - * @param array $arguments |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 107 | - protected function getIdentifierForArguments(array $arguments): string |
|
| 108 | - { |
|
| 109 | - if (empty($arguments)) { |
|
| 110 | - return ''; |
|
| 111 | - } |
|
| 112 | - $identifier = ''; |
|
| 113 | - foreach ($arguments as $key => $argument) { |
|
| 114 | - // don't include arguments used to assist with loading legacy classes |
|
| 115 | - if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) { |
|
| 116 | - continue; |
|
| 117 | - } |
|
| 118 | - switch (true) { |
|
| 119 | - case is_object($argument): |
|
| 120 | - case $argument instanceof Closure: |
|
| 121 | - $identifier .= spl_object_hash($argument); |
|
| 122 | - break; |
|
| 123 | - case is_array($argument): |
|
| 124 | - $identifier .= $this->getIdentifierForArguments($argument); |
|
| 125 | - break; |
|
| 126 | - default: |
|
| 127 | - $identifier .= $argument; |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - return $identifier; |
|
| 132 | - } |
|
| 100 | + /** |
|
| 101 | + * build a string representation of a object's arguments |
|
| 102 | + * (mostly because Closures can't be serialized) |
|
| 103 | + * |
|
| 104 | + * @param array $arguments |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | + protected function getIdentifierForArguments(array $arguments): string |
|
| 108 | + { |
|
| 109 | + if (empty($arguments)) { |
|
| 110 | + return ''; |
|
| 111 | + } |
|
| 112 | + $identifier = ''; |
|
| 113 | + foreach ($arguments as $key => $argument) { |
|
| 114 | + // don't include arguments used to assist with loading legacy classes |
|
| 115 | + if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) { |
|
| 116 | + continue; |
|
| 117 | + } |
|
| 118 | + switch (true) { |
|
| 119 | + case is_object($argument): |
|
| 120 | + case $argument instanceof Closure: |
|
| 121 | + $identifier .= spl_object_hash($argument); |
|
| 122 | + break; |
|
| 123 | + case is_array($argument): |
|
| 124 | + $identifier .= $this->getIdentifierForArguments($argument); |
|
| 125 | + break; |
|
| 126 | + default: |
|
| 127 | + $identifier .= $argument; |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + return $identifier; |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -19,536 +19,536 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Collection extends SplObjectStorage implements CollectionInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * a unique string for identifying this collection |
|
| 24 | - * |
|
| 25 | - * @type string $collection_identifier |
|
| 26 | - */ |
|
| 27 | - protected $collection_identifier; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
| 32 | - * this should be set from within the child class constructor |
|
| 33 | - * |
|
| 34 | - * @type string $interface |
|
| 35 | - */ |
|
| 36 | - protected $collection_interface; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * a short dash separated string describing the contents of this collection |
|
| 40 | - * used as the base for the $collection_identifier |
|
| 41 | - * defaults to the class short name if not set |
|
| 42 | - * |
|
| 43 | - * @type string $collection_identifier |
|
| 44 | - */ |
|
| 45 | - protected $collection_name; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Collection constructor |
|
| 50 | - * |
|
| 51 | - * @param string $collection_interface |
|
| 52 | - * @param string $collection_name |
|
| 53 | - * @throws InvalidInterfaceException |
|
| 54 | - */ |
|
| 55 | - public function __construct(string $collection_interface, string $collection_name = '') |
|
| 56 | - { |
|
| 57 | - $this->setCollectionInterface($collection_interface); |
|
| 58 | - $this->setCollectionName($collection_name); |
|
| 59 | - $this->setCollectionIdentifier(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @return string |
|
| 65 | - * @since 4.10.33.p |
|
| 66 | - */ |
|
| 67 | - public function collectionInterface(): string |
|
| 68 | - { |
|
| 69 | - return $this->collection_interface; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * setCollectionInterface |
|
| 75 | - * |
|
| 76 | - * @param string $collection_interface |
|
| 77 | - * @throws InvalidInterfaceException |
|
| 78 | - */ |
|
| 79 | - protected function setCollectionInterface(string $collection_interface) |
|
| 80 | - { |
|
| 81 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 82 | - throw new InvalidInterfaceException($collection_interface); |
|
| 83 | - } |
|
| 84 | - $this->collection_interface = $collection_interface; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function collectionName(): string |
|
| 92 | - { |
|
| 93 | - return $this->collection_name; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param string $collection_name |
|
| 99 | - */ |
|
| 100 | - protected function setCollectionName(string $collection_name) |
|
| 101 | - { |
|
| 102 | - $this->collection_name = ! empty($collection_name) |
|
| 103 | - ? sanitize_key($collection_name) |
|
| 104 | - : basename(str_replace('\\', '/', get_class($this))); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - public function collectionIdentifier(): string |
|
| 112 | - { |
|
| 113 | - return $this->collection_identifier; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
| 119 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
| 120 | - * |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected function setCollectionIdentifier() |
|
| 124 | - { |
|
| 125 | - // hash a few collection details |
|
| 126 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
| 127 | - // grab a few characters from the start, middle, and end of the hash |
|
| 128 | - $id = array(); |
|
| 129 | - for ($x = 0; $x < 19; $x += 9) { |
|
| 130 | - $id[] = substr($identifier, $x, 3); |
|
| 131 | - } |
|
| 132 | - $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * add |
|
| 138 | - * attaches an object to the Collection |
|
| 139 | - * and sets any supplied data associated with the current iterator entry |
|
| 140 | - * by calling EE_Object_Collection::set_identifier() |
|
| 141 | - * |
|
| 142 | - * @param mixed $object |
|
| 143 | - * @param mixed $identifier |
|
| 144 | - * @return bool |
|
| 145 | - * @throws InvalidEntityException |
|
| 146 | - * @throws DuplicateCollectionIdentifierException |
|
| 147 | - */ |
|
| 148 | - public function add($object, $identifier = null): bool |
|
| 149 | - { |
|
| 150 | - if (! $object instanceof $this->collection_interface) { |
|
| 151 | - throw new InvalidEntityException($object, $this->collection_interface); |
|
| 152 | - } |
|
| 153 | - $identifier = $this->getIdentifier($object, $identifier); |
|
| 154 | - if ($this->contains($object) || $this->has($identifier)) { |
|
| 155 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
| 156 | - } |
|
| 157 | - parent::attach($object, $identifier); |
|
| 158 | - return $this->contains($object); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * getIdentifier |
|
| 164 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
| 165 | - * |
|
| 166 | - * @param $object |
|
| 167 | - * @param mixed $identifier |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getIdentifier($object, $identifier = null): string |
|
| 171 | - { |
|
| 172 | - return ! empty($identifier) ? $identifier : spl_object_hash($object); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * setIdentifier |
|
| 178 | - * Sets the data associated with an object in the Collection |
|
| 179 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
| 180 | - * |
|
| 181 | - * @param $object |
|
| 182 | - * @param mixed $identifier |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - public function setIdentifier($object, $identifier = null): bool |
|
| 186 | - { |
|
| 187 | - $identifier = $this->getIdentifier($object, $identifier); |
|
| 188 | - $this->rewind(); |
|
| 189 | - while ($this->valid()) { |
|
| 190 | - if ($object === $this->current()) { |
|
| 191 | - $this->setInfo($identifier); |
|
| 192 | - $this->rewind(); |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - $this->next(); |
|
| 196 | - } |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * get |
|
| 203 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
| 204 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
| 205 | - * |
|
| 206 | - * @param mixed $identifier |
|
| 207 | - * @return mixed |
|
| 208 | - */ |
|
| 209 | - public function get($identifier) |
|
| 210 | - { |
|
| 211 | - $this->rewind(); |
|
| 212 | - while ($this->valid()) { |
|
| 213 | - if ($identifier === $this->getInfo()) { |
|
| 214 | - $object = $this->current(); |
|
| 215 | - $this->rewind(); |
|
| 216 | - return $object; |
|
| 217 | - } |
|
| 218 | - $this->next(); |
|
| 219 | - } |
|
| 220 | - return null; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * has |
|
| 226 | - * returns TRUE or FALSE |
|
| 227 | - * depending on whether the object is within the Collection |
|
| 228 | - * based on the supplied $identifier |
|
| 229 | - * |
|
| 230 | - * @param mixed $identifier |
|
| 231 | - * @return bool |
|
| 232 | - */ |
|
| 233 | - public function has($identifier): bool |
|
| 234 | - { |
|
| 235 | - $this->rewind(); |
|
| 236 | - while ($this->valid()) { |
|
| 237 | - if ($identifier === $this->getInfo()) { |
|
| 238 | - $this->rewind(); |
|
| 239 | - return true; |
|
| 240 | - } |
|
| 241 | - $this->next(); |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * hasObject |
|
| 249 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
| 250 | - * |
|
| 251 | - * @param $object |
|
| 252 | - * @return bool |
|
| 253 | - */ |
|
| 254 | - public function hasObject($object): bool |
|
| 255 | - { |
|
| 256 | - return $this->contains($object); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * hasObjects |
|
| 262 | - * returns true if there are objects within the Collection, and false if it is empty |
|
| 263 | - * |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - public function hasObjects(): bool |
|
| 267 | - { |
|
| 268 | - return $this->count() !== 0; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * isEmpty |
|
| 274 | - * returns true if there are no objects within the Collection, and false if there are |
|
| 275 | - * |
|
| 276 | - * @return bool |
|
| 277 | - */ |
|
| 278 | - public function isEmpty(): bool |
|
| 279 | - { |
|
| 280 | - return $this->count() === 0; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * remove |
|
| 286 | - * detaches an object from the Collection |
|
| 287 | - * |
|
| 288 | - * @param $object |
|
| 289 | - * @return bool |
|
| 290 | - */ |
|
| 291 | - public function remove($object): bool |
|
| 292 | - { |
|
| 293 | - $this->detach($object); |
|
| 294 | - return true; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * detaches the object matching the supplied identifier from the Collection |
|
| 300 | - * |
|
| 301 | - * @param mixed $identifier |
|
| 302 | - * @return bool |
|
| 303 | - */ |
|
| 304 | - public function removeByIdentifier($identifier): bool |
|
| 305 | - { |
|
| 306 | - $this->rewind(); |
|
| 307 | - while ($this->valid()) { |
|
| 308 | - $object = $this->current(); |
|
| 309 | - $this->next(); |
|
| 310 | - if ($identifier === $this->getInfo()) { |
|
| 311 | - $this->detach($object); |
|
| 312 | - unset($object); |
|
| 313 | - return true; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * setCurrent |
|
| 322 | - * advances pointer to the object whose identifier matches that which was provided |
|
| 323 | - * |
|
| 324 | - * @param mixed $identifier |
|
| 325 | - * @return boolean |
|
| 326 | - */ |
|
| 327 | - public function setCurrent($identifier): bool |
|
| 328 | - { |
|
| 329 | - $this->rewind(); |
|
| 330 | - while ($this->valid()) { |
|
| 331 | - if ($identifier === $this->getInfo()) { |
|
| 332 | - return true; |
|
| 333 | - } |
|
| 334 | - $this->next(); |
|
| 335 | - } |
|
| 336 | - return false; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * setCurrentUsingObject |
|
| 342 | - * advances pointer to the provided object |
|
| 343 | - * |
|
| 344 | - * @param $object |
|
| 345 | - * @return boolean |
|
| 346 | - */ |
|
| 347 | - public function setCurrentUsingObject($object): bool |
|
| 348 | - { |
|
| 349 | - $this->rewind(); |
|
| 350 | - while ($this->valid()) { |
|
| 351 | - if ($this->current() === $object) { |
|
| 352 | - return true; |
|
| 353 | - } |
|
| 354 | - $this->next(); |
|
| 355 | - } |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Returns the object occupying the index before the current object, |
|
| 362 | - * unless this is already the first object, in which case it just returns the first object |
|
| 363 | - * |
|
| 364 | - * @return mixed |
|
| 365 | - */ |
|
| 366 | - public function previous() |
|
| 367 | - { |
|
| 368 | - $index = $this->indexOf($this->current()); |
|
| 369 | - if ($index === 0) { |
|
| 370 | - return $this->current(); |
|
| 371 | - } |
|
| 372 | - $index--; |
|
| 373 | - return $this->objectAtIndex($index); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Returns the index of a given object, or false if not found |
|
| 379 | - * |
|
| 380 | - * @see http://stackoverflow.com/a/8736013 |
|
| 381 | - * @param $object |
|
| 382 | - * @return boolean|int |
|
| 383 | - */ |
|
| 384 | - public function indexOf($object) |
|
| 385 | - { |
|
| 386 | - if (! $this->contains($object)) { |
|
| 387 | - return false; |
|
| 388 | - } |
|
| 389 | - foreach ($this as $index => $obj) { |
|
| 390 | - if ($obj === $object) { |
|
| 391 | - return $index; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - return false; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Returns the object at the given index |
|
| 400 | - * |
|
| 401 | - * @see http://stackoverflow.com/a/8736013 |
|
| 402 | - * @param int $index |
|
| 403 | - * @return mixed |
|
| 404 | - */ |
|
| 405 | - public function objectAtIndex($index) |
|
| 406 | - { |
|
| 407 | - $iterator = new LimitIterator($this, $index, 1); |
|
| 408 | - $iterator->rewind(); |
|
| 409 | - return $iterator->current(); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Returns the sequence of objects as specified by the offset and length |
|
| 415 | - * |
|
| 416 | - * @see http://stackoverflow.com/a/8736013 |
|
| 417 | - * @param int $offset |
|
| 418 | - * @param int $length |
|
| 419 | - * @return array |
|
| 420 | - */ |
|
| 421 | - public function slice($offset, $length): array |
|
| 422 | - { |
|
| 423 | - $slice = array(); |
|
| 424 | - $iterator = new LimitIterator($this, $offset, $length); |
|
| 425 | - foreach ($iterator as $object) { |
|
| 426 | - $slice[] = $object; |
|
| 427 | - } |
|
| 428 | - return $slice; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Inserts an object at a certain point |
|
| 434 | - * |
|
| 435 | - * @see http://stackoverflow.com/a/8736013 |
|
| 436 | - * @param mixed $object A single object |
|
| 437 | - * @param int $index |
|
| 438 | - * @param mixed $identifier |
|
| 439 | - * @return bool |
|
| 440 | - * @throws DuplicateCollectionIdentifierException |
|
| 441 | - * @throws InvalidEntityException |
|
| 442 | - */ |
|
| 443 | - public function insertObjectAt($object, int $index, $identifier = null): bool |
|
| 444 | - { |
|
| 445 | - // check to ensure that objects don't already exist in the collection |
|
| 446 | - if ($this->has($identifier)) { |
|
| 447 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
| 448 | - } |
|
| 449 | - // detach any objects at or past this index |
|
| 450 | - $remaining_objects = array(); |
|
| 451 | - if ($index < $this->count()) { |
|
| 452 | - $remaining_objects = $this->slice($index, $this->count() - $index); |
|
| 453 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
| 454 | - // we need to grab the identifiers for each object and use them as keys |
|
| 455 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
| 456 | - // and then remove the object from the current tracking array |
|
| 457 | - unset($remaining_objects[ $key ]); |
|
| 458 | - // and then remove it from the Collection |
|
| 459 | - $this->detach($remaining_object); |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - // add the new object we're splicing in |
|
| 463 | - $this->add($object, $identifier); |
|
| 464 | - // attach the objects we previously detached |
|
| 465 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
| 466 | - $this->add($remaining_object, $key); |
|
| 467 | - } |
|
| 468 | - return $this->contains($object); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Inserts an object (or an array of objects) at a certain point |
|
| 474 | - * |
|
| 475 | - * @see http://stackoverflow.com/a/8736013 |
|
| 476 | - * @param mixed $objects A single object or an array of objects |
|
| 477 | - * @param int $index |
|
| 478 | - */ |
|
| 479 | - public function insertAt($objects, $index) |
|
| 480 | - { |
|
| 481 | - if (! is_array($objects)) { |
|
| 482 | - $objects = array($objects); |
|
| 483 | - } |
|
| 484 | - // check to ensure that objects don't already exist in the collection |
|
| 485 | - foreach ($objects as $key => $object) { |
|
| 486 | - if ($this->contains($object)) { |
|
| 487 | - unset($objects[ $key ]); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - // do we have any objects left? |
|
| 491 | - if (! $objects) { |
|
| 492 | - return; |
|
| 493 | - } |
|
| 494 | - // detach any objects at or past this index |
|
| 495 | - $remaining = array(); |
|
| 496 | - if ($index < $this->count()) { |
|
| 497 | - $remaining = $this->slice($index, $this->count() - $index); |
|
| 498 | - foreach ($remaining as $object) { |
|
| 499 | - $this->detach($object); |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - // add the new objects we're splicing in |
|
| 503 | - foreach ($objects as $object) { |
|
| 504 | - $this->add($object); |
|
| 505 | - } |
|
| 506 | - // attach the objects we previously detached |
|
| 507 | - foreach ($remaining as $object) { |
|
| 508 | - $this->add($object); |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Removes the object at the given index |
|
| 515 | - * |
|
| 516 | - * @see http://stackoverflow.com/a/8736013 |
|
| 517 | - * @param int $index |
|
| 518 | - */ |
|
| 519 | - public function removeAt($index) |
|
| 520 | - { |
|
| 521 | - $this->detach($this->objectAtIndex($index)); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * detaches ALL objects from the Collection |
|
| 527 | - */ |
|
| 528 | - public function detachAll() |
|
| 529 | - { |
|
| 530 | - $this->rewind(); |
|
| 531 | - while ($this->valid()) { |
|
| 532 | - $object = $this->current(); |
|
| 533 | - $this->next(); |
|
| 534 | - $this->detach($object); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * unsets and detaches ALL objects from the Collection |
|
| 541 | - */ |
|
| 542 | - public function trashAndDetachAll() |
|
| 543 | - { |
|
| 544 | - $this->rewind(); |
|
| 545 | - while ($this->valid()) { |
|
| 546 | - $object = $this->current(); |
|
| 547 | - $this->next(); |
|
| 548 | - if (! $object instanceof InterminableInterface) { |
|
| 549 | - $this->detach($object); |
|
| 550 | - unset($object); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 22 | + /** |
|
| 23 | + * a unique string for identifying this collection |
|
| 24 | + * |
|
| 25 | + * @type string $collection_identifier |
|
| 26 | + */ |
|
| 27 | + protected $collection_identifier; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
| 32 | + * this should be set from within the child class constructor |
|
| 33 | + * |
|
| 34 | + * @type string $interface |
|
| 35 | + */ |
|
| 36 | + protected $collection_interface; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * a short dash separated string describing the contents of this collection |
|
| 40 | + * used as the base for the $collection_identifier |
|
| 41 | + * defaults to the class short name if not set |
|
| 42 | + * |
|
| 43 | + * @type string $collection_identifier |
|
| 44 | + */ |
|
| 45 | + protected $collection_name; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Collection constructor |
|
| 50 | + * |
|
| 51 | + * @param string $collection_interface |
|
| 52 | + * @param string $collection_name |
|
| 53 | + * @throws InvalidInterfaceException |
|
| 54 | + */ |
|
| 55 | + public function __construct(string $collection_interface, string $collection_name = '') |
|
| 56 | + { |
|
| 57 | + $this->setCollectionInterface($collection_interface); |
|
| 58 | + $this->setCollectionName($collection_name); |
|
| 59 | + $this->setCollectionIdentifier(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @return string |
|
| 65 | + * @since 4.10.33.p |
|
| 66 | + */ |
|
| 67 | + public function collectionInterface(): string |
|
| 68 | + { |
|
| 69 | + return $this->collection_interface; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * setCollectionInterface |
|
| 75 | + * |
|
| 76 | + * @param string $collection_interface |
|
| 77 | + * @throws InvalidInterfaceException |
|
| 78 | + */ |
|
| 79 | + protected function setCollectionInterface(string $collection_interface) |
|
| 80 | + { |
|
| 81 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 82 | + throw new InvalidInterfaceException($collection_interface); |
|
| 83 | + } |
|
| 84 | + $this->collection_interface = $collection_interface; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function collectionName(): string |
|
| 92 | + { |
|
| 93 | + return $this->collection_name; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param string $collection_name |
|
| 99 | + */ |
|
| 100 | + protected function setCollectionName(string $collection_name) |
|
| 101 | + { |
|
| 102 | + $this->collection_name = ! empty($collection_name) |
|
| 103 | + ? sanitize_key($collection_name) |
|
| 104 | + : basename(str_replace('\\', '/', get_class($this))); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + public function collectionIdentifier(): string |
|
| 112 | + { |
|
| 113 | + return $this->collection_identifier; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
| 119 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
| 120 | + * |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected function setCollectionIdentifier() |
|
| 124 | + { |
|
| 125 | + // hash a few collection details |
|
| 126 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
| 127 | + // grab a few characters from the start, middle, and end of the hash |
|
| 128 | + $id = array(); |
|
| 129 | + for ($x = 0; $x < 19; $x += 9) { |
|
| 130 | + $id[] = substr($identifier, $x, 3); |
|
| 131 | + } |
|
| 132 | + $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * add |
|
| 138 | + * attaches an object to the Collection |
|
| 139 | + * and sets any supplied data associated with the current iterator entry |
|
| 140 | + * by calling EE_Object_Collection::set_identifier() |
|
| 141 | + * |
|
| 142 | + * @param mixed $object |
|
| 143 | + * @param mixed $identifier |
|
| 144 | + * @return bool |
|
| 145 | + * @throws InvalidEntityException |
|
| 146 | + * @throws DuplicateCollectionIdentifierException |
|
| 147 | + */ |
|
| 148 | + public function add($object, $identifier = null): bool |
|
| 149 | + { |
|
| 150 | + if (! $object instanceof $this->collection_interface) { |
|
| 151 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
| 152 | + } |
|
| 153 | + $identifier = $this->getIdentifier($object, $identifier); |
|
| 154 | + if ($this->contains($object) || $this->has($identifier)) { |
|
| 155 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
| 156 | + } |
|
| 157 | + parent::attach($object, $identifier); |
|
| 158 | + return $this->contains($object); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * getIdentifier |
|
| 164 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
| 165 | + * |
|
| 166 | + * @param $object |
|
| 167 | + * @param mixed $identifier |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getIdentifier($object, $identifier = null): string |
|
| 171 | + { |
|
| 172 | + return ! empty($identifier) ? $identifier : spl_object_hash($object); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * setIdentifier |
|
| 178 | + * Sets the data associated with an object in the Collection |
|
| 179 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
| 180 | + * |
|
| 181 | + * @param $object |
|
| 182 | + * @param mixed $identifier |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + public function setIdentifier($object, $identifier = null): bool |
|
| 186 | + { |
|
| 187 | + $identifier = $this->getIdentifier($object, $identifier); |
|
| 188 | + $this->rewind(); |
|
| 189 | + while ($this->valid()) { |
|
| 190 | + if ($object === $this->current()) { |
|
| 191 | + $this->setInfo($identifier); |
|
| 192 | + $this->rewind(); |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + $this->next(); |
|
| 196 | + } |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * get |
|
| 203 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
| 204 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
| 205 | + * |
|
| 206 | + * @param mixed $identifier |
|
| 207 | + * @return mixed |
|
| 208 | + */ |
|
| 209 | + public function get($identifier) |
|
| 210 | + { |
|
| 211 | + $this->rewind(); |
|
| 212 | + while ($this->valid()) { |
|
| 213 | + if ($identifier === $this->getInfo()) { |
|
| 214 | + $object = $this->current(); |
|
| 215 | + $this->rewind(); |
|
| 216 | + return $object; |
|
| 217 | + } |
|
| 218 | + $this->next(); |
|
| 219 | + } |
|
| 220 | + return null; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * has |
|
| 226 | + * returns TRUE or FALSE |
|
| 227 | + * depending on whether the object is within the Collection |
|
| 228 | + * based on the supplied $identifier |
|
| 229 | + * |
|
| 230 | + * @param mixed $identifier |
|
| 231 | + * @return bool |
|
| 232 | + */ |
|
| 233 | + public function has($identifier): bool |
|
| 234 | + { |
|
| 235 | + $this->rewind(); |
|
| 236 | + while ($this->valid()) { |
|
| 237 | + if ($identifier === $this->getInfo()) { |
|
| 238 | + $this->rewind(); |
|
| 239 | + return true; |
|
| 240 | + } |
|
| 241 | + $this->next(); |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * hasObject |
|
| 249 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
| 250 | + * |
|
| 251 | + * @param $object |
|
| 252 | + * @return bool |
|
| 253 | + */ |
|
| 254 | + public function hasObject($object): bool |
|
| 255 | + { |
|
| 256 | + return $this->contains($object); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * hasObjects |
|
| 262 | + * returns true if there are objects within the Collection, and false if it is empty |
|
| 263 | + * |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + public function hasObjects(): bool |
|
| 267 | + { |
|
| 268 | + return $this->count() !== 0; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * isEmpty |
|
| 274 | + * returns true if there are no objects within the Collection, and false if there are |
|
| 275 | + * |
|
| 276 | + * @return bool |
|
| 277 | + */ |
|
| 278 | + public function isEmpty(): bool |
|
| 279 | + { |
|
| 280 | + return $this->count() === 0; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * remove |
|
| 286 | + * detaches an object from the Collection |
|
| 287 | + * |
|
| 288 | + * @param $object |
|
| 289 | + * @return bool |
|
| 290 | + */ |
|
| 291 | + public function remove($object): bool |
|
| 292 | + { |
|
| 293 | + $this->detach($object); |
|
| 294 | + return true; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * detaches the object matching the supplied identifier from the Collection |
|
| 300 | + * |
|
| 301 | + * @param mixed $identifier |
|
| 302 | + * @return bool |
|
| 303 | + */ |
|
| 304 | + public function removeByIdentifier($identifier): bool |
|
| 305 | + { |
|
| 306 | + $this->rewind(); |
|
| 307 | + while ($this->valid()) { |
|
| 308 | + $object = $this->current(); |
|
| 309 | + $this->next(); |
|
| 310 | + if ($identifier === $this->getInfo()) { |
|
| 311 | + $this->detach($object); |
|
| 312 | + unset($object); |
|
| 313 | + return true; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * setCurrent |
|
| 322 | + * advances pointer to the object whose identifier matches that which was provided |
|
| 323 | + * |
|
| 324 | + * @param mixed $identifier |
|
| 325 | + * @return boolean |
|
| 326 | + */ |
|
| 327 | + public function setCurrent($identifier): bool |
|
| 328 | + { |
|
| 329 | + $this->rewind(); |
|
| 330 | + while ($this->valid()) { |
|
| 331 | + if ($identifier === $this->getInfo()) { |
|
| 332 | + return true; |
|
| 333 | + } |
|
| 334 | + $this->next(); |
|
| 335 | + } |
|
| 336 | + return false; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * setCurrentUsingObject |
|
| 342 | + * advances pointer to the provided object |
|
| 343 | + * |
|
| 344 | + * @param $object |
|
| 345 | + * @return boolean |
|
| 346 | + */ |
|
| 347 | + public function setCurrentUsingObject($object): bool |
|
| 348 | + { |
|
| 349 | + $this->rewind(); |
|
| 350 | + while ($this->valid()) { |
|
| 351 | + if ($this->current() === $object) { |
|
| 352 | + return true; |
|
| 353 | + } |
|
| 354 | + $this->next(); |
|
| 355 | + } |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Returns the object occupying the index before the current object, |
|
| 362 | + * unless this is already the first object, in which case it just returns the first object |
|
| 363 | + * |
|
| 364 | + * @return mixed |
|
| 365 | + */ |
|
| 366 | + public function previous() |
|
| 367 | + { |
|
| 368 | + $index = $this->indexOf($this->current()); |
|
| 369 | + if ($index === 0) { |
|
| 370 | + return $this->current(); |
|
| 371 | + } |
|
| 372 | + $index--; |
|
| 373 | + return $this->objectAtIndex($index); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Returns the index of a given object, or false if not found |
|
| 379 | + * |
|
| 380 | + * @see http://stackoverflow.com/a/8736013 |
|
| 381 | + * @param $object |
|
| 382 | + * @return boolean|int |
|
| 383 | + */ |
|
| 384 | + public function indexOf($object) |
|
| 385 | + { |
|
| 386 | + if (! $this->contains($object)) { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 389 | + foreach ($this as $index => $obj) { |
|
| 390 | + if ($obj === $object) { |
|
| 391 | + return $index; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + return false; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Returns the object at the given index |
|
| 400 | + * |
|
| 401 | + * @see http://stackoverflow.com/a/8736013 |
|
| 402 | + * @param int $index |
|
| 403 | + * @return mixed |
|
| 404 | + */ |
|
| 405 | + public function objectAtIndex($index) |
|
| 406 | + { |
|
| 407 | + $iterator = new LimitIterator($this, $index, 1); |
|
| 408 | + $iterator->rewind(); |
|
| 409 | + return $iterator->current(); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Returns the sequence of objects as specified by the offset and length |
|
| 415 | + * |
|
| 416 | + * @see http://stackoverflow.com/a/8736013 |
|
| 417 | + * @param int $offset |
|
| 418 | + * @param int $length |
|
| 419 | + * @return array |
|
| 420 | + */ |
|
| 421 | + public function slice($offset, $length): array |
|
| 422 | + { |
|
| 423 | + $slice = array(); |
|
| 424 | + $iterator = new LimitIterator($this, $offset, $length); |
|
| 425 | + foreach ($iterator as $object) { |
|
| 426 | + $slice[] = $object; |
|
| 427 | + } |
|
| 428 | + return $slice; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Inserts an object at a certain point |
|
| 434 | + * |
|
| 435 | + * @see http://stackoverflow.com/a/8736013 |
|
| 436 | + * @param mixed $object A single object |
|
| 437 | + * @param int $index |
|
| 438 | + * @param mixed $identifier |
|
| 439 | + * @return bool |
|
| 440 | + * @throws DuplicateCollectionIdentifierException |
|
| 441 | + * @throws InvalidEntityException |
|
| 442 | + */ |
|
| 443 | + public function insertObjectAt($object, int $index, $identifier = null): bool |
|
| 444 | + { |
|
| 445 | + // check to ensure that objects don't already exist in the collection |
|
| 446 | + if ($this->has($identifier)) { |
|
| 447 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
| 448 | + } |
|
| 449 | + // detach any objects at or past this index |
|
| 450 | + $remaining_objects = array(); |
|
| 451 | + if ($index < $this->count()) { |
|
| 452 | + $remaining_objects = $this->slice($index, $this->count() - $index); |
|
| 453 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
| 454 | + // we need to grab the identifiers for each object and use them as keys |
|
| 455 | + $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
| 456 | + // and then remove the object from the current tracking array |
|
| 457 | + unset($remaining_objects[ $key ]); |
|
| 458 | + // and then remove it from the Collection |
|
| 459 | + $this->detach($remaining_object); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + // add the new object we're splicing in |
|
| 463 | + $this->add($object, $identifier); |
|
| 464 | + // attach the objects we previously detached |
|
| 465 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
| 466 | + $this->add($remaining_object, $key); |
|
| 467 | + } |
|
| 468 | + return $this->contains($object); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Inserts an object (or an array of objects) at a certain point |
|
| 474 | + * |
|
| 475 | + * @see http://stackoverflow.com/a/8736013 |
|
| 476 | + * @param mixed $objects A single object or an array of objects |
|
| 477 | + * @param int $index |
|
| 478 | + */ |
|
| 479 | + public function insertAt($objects, $index) |
|
| 480 | + { |
|
| 481 | + if (! is_array($objects)) { |
|
| 482 | + $objects = array($objects); |
|
| 483 | + } |
|
| 484 | + // check to ensure that objects don't already exist in the collection |
|
| 485 | + foreach ($objects as $key => $object) { |
|
| 486 | + if ($this->contains($object)) { |
|
| 487 | + unset($objects[ $key ]); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + // do we have any objects left? |
|
| 491 | + if (! $objects) { |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | + // detach any objects at or past this index |
|
| 495 | + $remaining = array(); |
|
| 496 | + if ($index < $this->count()) { |
|
| 497 | + $remaining = $this->slice($index, $this->count() - $index); |
|
| 498 | + foreach ($remaining as $object) { |
|
| 499 | + $this->detach($object); |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + // add the new objects we're splicing in |
|
| 503 | + foreach ($objects as $object) { |
|
| 504 | + $this->add($object); |
|
| 505 | + } |
|
| 506 | + // attach the objects we previously detached |
|
| 507 | + foreach ($remaining as $object) { |
|
| 508 | + $this->add($object); |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Removes the object at the given index |
|
| 515 | + * |
|
| 516 | + * @see http://stackoverflow.com/a/8736013 |
|
| 517 | + * @param int $index |
|
| 518 | + */ |
|
| 519 | + public function removeAt($index) |
|
| 520 | + { |
|
| 521 | + $this->detach($this->objectAtIndex($index)); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * detaches ALL objects from the Collection |
|
| 527 | + */ |
|
| 528 | + public function detachAll() |
|
| 529 | + { |
|
| 530 | + $this->rewind(); |
|
| 531 | + while ($this->valid()) { |
|
| 532 | + $object = $this->current(); |
|
| 533 | + $this->next(); |
|
| 534 | + $this->detach($object); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * unsets and detaches ALL objects from the Collection |
|
| 541 | + */ |
|
| 542 | + public function trashAndDetachAll() |
|
| 543 | + { |
|
| 544 | + $this->rewind(); |
|
| 545 | + while ($this->valid()) { |
|
| 546 | + $object = $this->current(); |
|
| 547 | + $this->next(); |
|
| 548 | + if (! $object instanceof InterminableInterface) { |
|
| 549 | + $this->detach($object); |
|
| 550 | + unset($object); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | 554 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | protected function setCollectionInterface(string $collection_interface) |
| 80 | 80 | { |
| 81 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 81 | + if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
| 82 | 82 | throw new InvalidInterfaceException($collection_interface); |
| 83 | 83 | } |
| 84 | 84 | $this->collection_interface = $collection_interface; |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | protected function setCollectionIdentifier() |
| 124 | 124 | { |
| 125 | 125 | // hash a few collection details |
| 126 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
| 126 | + $identifier = md5(spl_object_hash($this).$this->collection_interface.time()); |
|
| 127 | 127 | // grab a few characters from the start, middle, and end of the hash |
| 128 | 128 | $id = array(); |
| 129 | 129 | for ($x = 0; $x < 19; $x += 9) { |
| 130 | 130 | $id[] = substr($identifier, $x, 3); |
| 131 | 131 | } |
| 132 | - $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
| 132 | + $this->collection_identifier = $this->collection_name.'-'.strtoupper(implode('-', $id)); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function add($object, $identifier = null): bool |
| 149 | 149 | { |
| 150 | - if (! $object instanceof $this->collection_interface) { |
|
| 150 | + if ( ! $object instanceof $this->collection_interface) { |
|
| 151 | 151 | throw new InvalidEntityException($object, $this->collection_interface); |
| 152 | 152 | } |
| 153 | 153 | $identifier = $this->getIdentifier($object, $identifier); |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | */ |
| 384 | 384 | public function indexOf($object) |
| 385 | 385 | { |
| 386 | - if (! $this->contains($object)) { |
|
| 386 | + if ( ! $this->contains($object)) { |
|
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | 389 | foreach ($this as $index => $obj) { |
@@ -452,9 +452,9 @@ discard block |
||
| 452 | 452 | $remaining_objects = $this->slice($index, $this->count() - $index); |
| 453 | 453 | foreach ($remaining_objects as $key => $remaining_object) { |
| 454 | 454 | // we need to grab the identifiers for each object and use them as keys |
| 455 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
| 455 | + $remaining_objects[$remaining_object->getInfo()] = $remaining_object; |
|
| 456 | 456 | // and then remove the object from the current tracking array |
| 457 | - unset($remaining_objects[ $key ]); |
|
| 457 | + unset($remaining_objects[$key]); |
|
| 458 | 458 | // and then remove it from the Collection |
| 459 | 459 | $this->detach($remaining_object); |
| 460 | 460 | } |
@@ -478,17 +478,17 @@ discard block |
||
| 478 | 478 | */ |
| 479 | 479 | public function insertAt($objects, $index) |
| 480 | 480 | { |
| 481 | - if (! is_array($objects)) { |
|
| 481 | + if ( ! is_array($objects)) { |
|
| 482 | 482 | $objects = array($objects); |
| 483 | 483 | } |
| 484 | 484 | // check to ensure that objects don't already exist in the collection |
| 485 | 485 | foreach ($objects as $key => $object) { |
| 486 | 486 | if ($this->contains($object)) { |
| 487 | - unset($objects[ $key ]); |
|
| 487 | + unset($objects[$key]); |
|
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | // do we have any objects left? |
| 491 | - if (! $objects) { |
|
| 491 | + if ( ! $objects) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | // detach any objects at or past this index |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | while ($this->valid()) { |
| 546 | 546 | $object = $this->current(); |
| 547 | 547 | $this->next(); |
| 548 | - if (! $object instanceof InterminableInterface) { |
|
| 548 | + if ( ! $object instanceof InterminableInterface) { |
|
| 549 | 549 | $this->detach($object); |
| 550 | 550 | unset($object); |
| 551 | 551 | } |
@@ -15,244 +15,244 @@ |
||
| 15 | 15 | class EspressoLegacyAdminAssetManager extends AssetManager |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 18 | + const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 19 | 19 | |
| 20 | - const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 20 | + const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 21 | 21 | |
| 22 | - const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 22 | + const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 23 | 23 | |
| 24 | - const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 24 | + const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 25 | 25 | |
| 26 | - const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 26 | + const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 27 | 27 | |
| 28 | - const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 28 | + const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 29 | 29 | |
| 30 | - const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 30 | + const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 31 | 31 | |
| 32 | - const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 32 | + const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 33 | 33 | |
| 34 | - const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 34 | + const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 35 | 35 | |
| 36 | - const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 36 | + const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 37 | 37 | |
| 38 | - const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links-js'; |
|
| 38 | + const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links-js'; |
|
| 39 | 39 | |
| 40 | - const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 41 | - |
|
| 42 | - const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 40 | + const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 41 | + |
|
| 42 | + const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 43 | 43 | |
| 44 | - const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 45 | - |
|
| 46 | - const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 47 | - |
|
| 48 | - const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 49 | - |
|
| 50 | - const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links-css'; |
|
| 51 | - |
|
| 52 | - const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 53 | - |
|
| 54 | - const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @inheritDoc |
|
| 59 | - */ |
|
| 60 | - public function addAssets() |
|
| 61 | - { |
|
| 62 | - $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 63 | - $this->registerJavascript($joyride); |
|
| 64 | - $this->registerStyleSheets($joyride); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Register javascript assets |
|
| 70 | - * |
|
| 71 | - * @param bool $joyride |
|
| 72 | - */ |
|
| 73 | - private function registerJavascript($joyride = false) |
|
| 74 | - { |
|
| 75 | - $this->addJavascript( |
|
| 76 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 77 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 78 | - [ |
|
| 79 | - JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 80 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 81 | - ] |
|
| 82 | - ); |
|
| 83 | - $this->addJavascript( |
|
| 84 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 85 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 86 | - [ |
|
| 87 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 88 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 89 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 90 | - ] |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // script for sorting tables |
|
| 94 | - $this->addJavascript( |
|
| 95 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 96 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 97 | - [ |
|
| 98 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 99 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 100 | - ] |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - // script for parsing uri's |
|
| 104 | - $this->addJavascript( |
|
| 105 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 106 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - // and parsing associative serialized form elements |
|
| 110 | - $this->addJavascript( |
|
| 111 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 112 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 113 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 114 | - |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - // helpers scripts |
|
| 118 | - $this->addJavascript( |
|
| 119 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 120 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 121 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $this->addJavascript( |
|
| 125 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 126 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - $this->addJavascript( |
|
| 130 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 131 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 132 | - [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - $this->addJavascript( |
|
| 136 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 137 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 138 | - [ |
|
| 139 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 140 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 141 | - ] |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - // google charts |
|
| 145 | - $this->addJavascript( |
|
| 146 | - EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 147 | - 'https://www.gstatic.com/charts/loader.js' |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 151 | - // Note: the intention of this script is to only do TARGETED injections. |
|
| 152 | - //ie: only injecting on certain script calls. |
|
| 153 | - $this->addJavascript( |
|
| 154 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 155 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 156 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - $this->loadQtipJs(); |
|
| 160 | - |
|
| 161 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 162 | - // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 163 | - if (! $joyride) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $this->addJavascript( |
|
| 168 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 169 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 170 | - [], |
|
| 171 | - true, |
|
| 172 | - '2.1' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - // wanna go for a joyride? |
|
| 176 | - $this->addJavascript( |
|
| 177 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 178 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 179 | - [ |
|
| 180 | - JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 181 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 182 | - ], |
|
| 183 | - true, |
|
| 184 | - '2.1' |
|
| 185 | - )->setEnqueueImmediately(); |
|
| 186 | - |
|
| 187 | - $this->addJavascript( |
|
| 188 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 189 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 190 | - [ |
|
| 191 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 192 | - ], |
|
| 193 | - true, |
|
| 194 | - '2.1' |
|
| 195 | - )->setEnqueueImmediately(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Register CSS assets. |
|
| 201 | - * |
|
| 202 | - * @param bool $joyride |
|
| 203 | - */ |
|
| 204 | - private function registerStyleSheets($joyride = false) |
|
| 205 | - { |
|
| 206 | - |
|
| 207 | - $this->addStylesheet( |
|
| 208 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 209 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - $this->addStylesheet( |
|
| 213 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 214 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - $this->addStylesheet( |
|
| 218 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 219 | - EE_ADMIN_URL . 'assets/ee-admin-page.css' |
|
| 220 | - )->setEnqueueImmediately(); |
|
| 221 | - |
|
| 222 | - if (! $joyride) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - // joyride style |
|
| 226 | - $this->addStylesheet( |
|
| 227 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 228 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 229 | - [], |
|
| 230 | - 'all', |
|
| 231 | - '2.1' |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - $this->addStylesheet( |
|
| 235 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 236 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 237 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE], |
|
| 238 | - 'all', |
|
| 239 | - EVENT_ESPRESSO_VERSION |
|
| 240 | - )->setEnqueueImmediately(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * registers assets for cleaning your ears |
|
| 246 | - */ |
|
| 247 | - public function loadQtipJs() |
|
| 248 | - { |
|
| 249 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 250 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 251 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 252 | - $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 253 | - if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 254 | - $qtip_loader->register_and_enqueue(); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 44 | + const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 45 | + |
|
| 46 | + const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 47 | + |
|
| 48 | + const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 49 | + |
|
| 50 | + const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links-css'; |
|
| 51 | + |
|
| 52 | + const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 53 | + |
|
| 54 | + const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @inheritDoc |
|
| 59 | + */ |
|
| 60 | + public function addAssets() |
|
| 61 | + { |
|
| 62 | + $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 63 | + $this->registerJavascript($joyride); |
|
| 64 | + $this->registerStyleSheets($joyride); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Register javascript assets |
|
| 70 | + * |
|
| 71 | + * @param bool $joyride |
|
| 72 | + */ |
|
| 73 | + private function registerJavascript($joyride = false) |
|
| 74 | + { |
|
| 75 | + $this->addJavascript( |
|
| 76 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 77 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 78 | + [ |
|
| 79 | + JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 80 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 81 | + ] |
|
| 82 | + ); |
|
| 83 | + $this->addJavascript( |
|
| 84 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 85 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 86 | + [ |
|
| 87 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 88 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 89 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 90 | + ] |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // script for sorting tables |
|
| 94 | + $this->addJavascript( |
|
| 95 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 96 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 97 | + [ |
|
| 98 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 99 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 100 | + ] |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + // script for parsing uri's |
|
| 104 | + $this->addJavascript( |
|
| 105 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 106 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + // and parsing associative serialized form elements |
|
| 110 | + $this->addJavascript( |
|
| 111 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 112 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 113 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 114 | + |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + // helpers scripts |
|
| 118 | + $this->addJavascript( |
|
| 119 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 120 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 121 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $this->addJavascript( |
|
| 125 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 126 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + $this->addJavascript( |
|
| 130 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 131 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 132 | + [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + $this->addJavascript( |
|
| 136 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 137 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 138 | + [ |
|
| 139 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 140 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 141 | + ] |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + // google charts |
|
| 145 | + $this->addJavascript( |
|
| 146 | + EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 147 | + 'https://www.gstatic.com/charts/loader.js' |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 151 | + // Note: the intention of this script is to only do TARGETED injections. |
|
| 152 | + //ie: only injecting on certain script calls. |
|
| 153 | + $this->addJavascript( |
|
| 154 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 155 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 156 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + $this->loadQtipJs(); |
|
| 160 | + |
|
| 161 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 162 | + // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 163 | + if (! $joyride) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $this->addJavascript( |
|
| 168 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 169 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 170 | + [], |
|
| 171 | + true, |
|
| 172 | + '2.1' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + // wanna go for a joyride? |
|
| 176 | + $this->addJavascript( |
|
| 177 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 178 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 179 | + [ |
|
| 180 | + JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 181 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 182 | + ], |
|
| 183 | + true, |
|
| 184 | + '2.1' |
|
| 185 | + )->setEnqueueImmediately(); |
|
| 186 | + |
|
| 187 | + $this->addJavascript( |
|
| 188 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 189 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 190 | + [ |
|
| 191 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 192 | + ], |
|
| 193 | + true, |
|
| 194 | + '2.1' |
|
| 195 | + )->setEnqueueImmediately(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Register CSS assets. |
|
| 201 | + * |
|
| 202 | + * @param bool $joyride |
|
| 203 | + */ |
|
| 204 | + private function registerStyleSheets($joyride = false) |
|
| 205 | + { |
|
| 206 | + |
|
| 207 | + $this->addStylesheet( |
|
| 208 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 209 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + $this->addStylesheet( |
|
| 213 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 214 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + $this->addStylesheet( |
|
| 218 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 219 | + EE_ADMIN_URL . 'assets/ee-admin-page.css' |
|
| 220 | + )->setEnqueueImmediately(); |
|
| 221 | + |
|
| 222 | + if (! $joyride) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + // joyride style |
|
| 226 | + $this->addStylesheet( |
|
| 227 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 228 | + EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 229 | + [], |
|
| 230 | + 'all', |
|
| 231 | + '2.1' |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + $this->addStylesheet( |
|
| 235 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 236 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 237 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE], |
|
| 238 | + 'all', |
|
| 239 | + EVENT_ESPRESSO_VERSION |
|
| 240 | + )->setEnqueueImmediately(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * registers assets for cleaning your ears |
|
| 246 | + */ |
|
| 247 | + public function loadQtipJs() |
|
| 248 | + { |
|
| 249 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 250 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 251 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 252 | + $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 253 | + if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 254 | + $qtip_loader->register_and_enqueue(); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | } |
@@ -29,176 +29,176 @@ |
||
| 29 | 29 | class CoreAssetManager extends AssetManager |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - // WordPress core / Third party JS asset handles |
|
| 33 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
| 34 | - |
|
| 35 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 36 | - |
|
| 37 | - const JS_HANDLE_I18N = 'eei18n'; |
|
| 38 | - |
|
| 39 | - const JS_HANDLE_RAMDA = 'ramda'; |
|
| 40 | - |
|
| 41 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 42 | - |
|
| 43 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page-js'; |
|
| 44 | - |
|
| 45 | - const RAMDA_VERSION = '0.27.1'; |
|
| 46 | - |
|
| 47 | - // EE CSS assets handles |
|
| 48 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 49 | - |
|
| 50 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 51 | - |
|
| 52 | - const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page-css'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var EE_Currency_Config $currency_config |
|
| 56 | - */ |
|
| 57 | - protected $currency_config; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var EE_Template_Config $template_config |
|
| 61 | - */ |
|
| 62 | - protected $template_config; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * CoreAssetRegister constructor. |
|
| 67 | - * |
|
| 68 | - * @param AssetCollection $assets |
|
| 69 | - * @param EE_Currency_Config $currency_config |
|
| 70 | - * @param EE_Template_Config $template_config |
|
| 71 | - * @param DomainInterface $domain |
|
| 72 | - * @param Registry $registry |
|
| 73 | - */ |
|
| 74 | - public function __construct( |
|
| 75 | - AssetCollection $assets, |
|
| 76 | - EE_Currency_Config $currency_config, |
|
| 77 | - EE_Template_Config $template_config, |
|
| 78 | - DomainInterface $domain, |
|
| 79 | - Registry $registry |
|
| 80 | - ) { |
|
| 81 | - $this->currency_config = $currency_config; |
|
| 82 | - $this->template_config = $template_config; |
|
| 83 | - parent::__construct($domain, $assets, $registry); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @throws DomainException |
|
| 89 | - * @throws DuplicateCollectionIdentifierException |
|
| 90 | - * @throws InvalidArgumentException |
|
| 91 | - * @throws InvalidDataTypeException |
|
| 92 | - * @throws InvalidEntityException |
|
| 93 | - * @throws InvalidInterfaceException |
|
| 94 | - * @since 4.9.62.p |
|
| 95 | - */ |
|
| 96 | - public function addAssets() |
|
| 97 | - { |
|
| 98 | - $this->addJavascriptFiles(); |
|
| 99 | - $this->addStylesheetFiles(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @throws DomainException |
|
| 105 | - * @throws DuplicateCollectionIdentifierException |
|
| 106 | - * @throws InvalidArgumentException |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidEntityException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - * @since 4.9.62.p |
|
| 111 | - */ |
|
| 112 | - public function addJavascriptFiles() |
|
| 113 | - { |
|
| 114 | - $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
| 115 | - $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
| 116 | - $this->addJavascript( |
|
| 117 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 118 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 119 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 120 | - )->setInlineDataCallback( |
|
| 121 | - function () { |
|
| 122 | - wp_localize_script( |
|
| 123 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 124 | - CoreAssetManager::JS_HANDLE_I18N, |
|
| 125 | - EE_Registry::$i18n_js_strings |
|
| 126 | - ); |
|
| 127 | - } |
|
| 128 | - ); |
|
| 129 | - $this->loadQtipJs(); |
|
| 130 | - $this->addVendorJavascript( |
|
| 131 | - CoreAssetManager::JS_HANDLE_RAMDA, |
|
| 132 | - [], |
|
| 133 | - true, |
|
| 134 | - CoreAssetManager::RAMDA_VERSION |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @throws DuplicateCollectionIdentifierException |
|
| 141 | - * @throws InvalidDataTypeException |
|
| 142 | - * @throws InvalidEntityException |
|
| 143 | - * @throws DomainException |
|
| 144 | - * @since 4.9.62.p |
|
| 145 | - */ |
|
| 146 | - public function addStylesheetFiles() |
|
| 147 | - { |
|
| 148 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 149 | - $this->addStylesheet( |
|
| 150 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 151 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
| 152 | - ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
| 153 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 154 | - ['dashicons'] |
|
| 155 | - ); |
|
| 156 | - //Load custom style sheet if available |
|
| 157 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 158 | - $this->addStylesheet( |
|
| 159 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 160 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 161 | - [CoreAssetManager::CSS_HANDLE_DEFAULT] |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Returns configuration data for the js Currency VO. |
|
| 170 | - * |
|
| 171 | - * @return array |
|
| 172 | - * @since 4.9.71.p |
|
| 173 | - */ |
|
| 174 | - private function getCurrencySettings() |
|
| 175 | - { |
|
| 176 | - return [ |
|
| 177 | - 'code' => $this->currency_config->code, |
|
| 178 | - 'singularLabel' => $this->currency_config->name, |
|
| 179 | - 'pluralLabel' => $this->currency_config->plural, |
|
| 180 | - 'sign' => $this->currency_config->sign, |
|
| 181 | - 'signB4' => $this->currency_config->sign_b4, |
|
| 182 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 183 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 184 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 185 | - ]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * replacement: |
|
| 191 | - * EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs() |
|
| 192 | - * |
|
| 193 | - * @param JavascriptAsset $script |
|
| 194 | - * @deprecated $VID:$ |
|
| 195 | - */ |
|
| 196 | - public function loadQtipJs(JavascriptAsset $script = null) |
|
| 197 | - { |
|
| 198 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 199 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 200 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 201 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 202 | - } |
|
| 203 | - } |
|
| 32 | + // WordPress core / Third party JS asset handles |
|
| 33 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
| 34 | + |
|
| 35 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 36 | + |
|
| 37 | + const JS_HANDLE_I18N = 'eei18n'; |
|
| 38 | + |
|
| 39 | + const JS_HANDLE_RAMDA = 'ramda'; |
|
| 40 | + |
|
| 41 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 42 | + |
|
| 43 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page-js'; |
|
| 44 | + |
|
| 45 | + const RAMDA_VERSION = '0.27.1'; |
|
| 46 | + |
|
| 47 | + // EE CSS assets handles |
|
| 48 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 49 | + |
|
| 50 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 51 | + |
|
| 52 | + const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page-css'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var EE_Currency_Config $currency_config |
|
| 56 | + */ |
|
| 57 | + protected $currency_config; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var EE_Template_Config $template_config |
|
| 61 | + */ |
|
| 62 | + protected $template_config; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * CoreAssetRegister constructor. |
|
| 67 | + * |
|
| 68 | + * @param AssetCollection $assets |
|
| 69 | + * @param EE_Currency_Config $currency_config |
|
| 70 | + * @param EE_Template_Config $template_config |
|
| 71 | + * @param DomainInterface $domain |
|
| 72 | + * @param Registry $registry |
|
| 73 | + */ |
|
| 74 | + public function __construct( |
|
| 75 | + AssetCollection $assets, |
|
| 76 | + EE_Currency_Config $currency_config, |
|
| 77 | + EE_Template_Config $template_config, |
|
| 78 | + DomainInterface $domain, |
|
| 79 | + Registry $registry |
|
| 80 | + ) { |
|
| 81 | + $this->currency_config = $currency_config; |
|
| 82 | + $this->template_config = $template_config; |
|
| 83 | + parent::__construct($domain, $assets, $registry); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @throws DomainException |
|
| 89 | + * @throws DuplicateCollectionIdentifierException |
|
| 90 | + * @throws InvalidArgumentException |
|
| 91 | + * @throws InvalidDataTypeException |
|
| 92 | + * @throws InvalidEntityException |
|
| 93 | + * @throws InvalidInterfaceException |
|
| 94 | + * @since 4.9.62.p |
|
| 95 | + */ |
|
| 96 | + public function addAssets() |
|
| 97 | + { |
|
| 98 | + $this->addJavascriptFiles(); |
|
| 99 | + $this->addStylesheetFiles(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @throws DomainException |
|
| 105 | + * @throws DuplicateCollectionIdentifierException |
|
| 106 | + * @throws InvalidArgumentException |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidEntityException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + * @since 4.9.62.p |
|
| 111 | + */ |
|
| 112 | + public function addJavascriptFiles() |
|
| 113 | + { |
|
| 114 | + $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
| 115 | + $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
| 116 | + $this->addJavascript( |
|
| 117 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 118 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 119 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 120 | + )->setInlineDataCallback( |
|
| 121 | + function () { |
|
| 122 | + wp_localize_script( |
|
| 123 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 124 | + CoreAssetManager::JS_HANDLE_I18N, |
|
| 125 | + EE_Registry::$i18n_js_strings |
|
| 126 | + ); |
|
| 127 | + } |
|
| 128 | + ); |
|
| 129 | + $this->loadQtipJs(); |
|
| 130 | + $this->addVendorJavascript( |
|
| 131 | + CoreAssetManager::JS_HANDLE_RAMDA, |
|
| 132 | + [], |
|
| 133 | + true, |
|
| 134 | + CoreAssetManager::RAMDA_VERSION |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @throws DuplicateCollectionIdentifierException |
|
| 141 | + * @throws InvalidDataTypeException |
|
| 142 | + * @throws InvalidEntityException |
|
| 143 | + * @throws DomainException |
|
| 144 | + * @since 4.9.62.p |
|
| 145 | + */ |
|
| 146 | + public function addStylesheetFiles() |
|
| 147 | + { |
|
| 148 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 149 | + $this->addStylesheet( |
|
| 150 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 151 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
| 152 | + ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
| 153 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 154 | + ['dashicons'] |
|
| 155 | + ); |
|
| 156 | + //Load custom style sheet if available |
|
| 157 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 158 | + $this->addStylesheet( |
|
| 159 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 160 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 161 | + [CoreAssetManager::CSS_HANDLE_DEFAULT] |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Returns configuration data for the js Currency VO. |
|
| 170 | + * |
|
| 171 | + * @return array |
|
| 172 | + * @since 4.9.71.p |
|
| 173 | + */ |
|
| 174 | + private function getCurrencySettings() |
|
| 175 | + { |
|
| 176 | + return [ |
|
| 177 | + 'code' => $this->currency_config->code, |
|
| 178 | + 'singularLabel' => $this->currency_config->name, |
|
| 179 | + 'pluralLabel' => $this->currency_config->plural, |
|
| 180 | + 'sign' => $this->currency_config->sign, |
|
| 181 | + 'signB4' => $this->currency_config->sign_b4, |
|
| 182 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 183 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 184 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 185 | + ]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * replacement: |
|
| 191 | + * EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs() |
|
| 192 | + * |
|
| 193 | + * @param JavascriptAsset $script |
|
| 194 | + * @deprecated $VID:$ |
|
| 195 | + */ |
|
| 196 | + public function loadQtipJs(JavascriptAsset $script = null) |
|
| 197 | + { |
|
| 198 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 199 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 200 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 201 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | const JS_HANDLE_I18N = 'eei18n'; |
| 38 | 38 | |
| 39 | - const JS_HANDLE_RAMDA = 'ramda'; |
|
| 39 | + const JS_HANDLE_RAMDA = 'ramda'; |
|
| 40 | 40 | |
| 41 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 41 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 42 | 42 | |
| 43 | 43 | const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page-js'; |
| 44 | 44 | |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
| 116 | 116 | $this->addJavascript( |
| 117 | 117 | CoreAssetManager::JS_HANDLE_CORE, |
| 118 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 118 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 119 | 119 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 120 | 120 | )->setInlineDataCallback( |
| 121 | - function () { |
|
| 121 | + function() { |
|
| 122 | 122 | wp_localize_script( |
| 123 | 123 | CoreAssetManager::JS_HANDLE_CORE, |
| 124 | 124 | CoreAssetManager::JS_HANDLE_I18N, |
@@ -148,16 +148,16 @@ discard block |
||
| 148 | 148 | if ($this->template_config->enable_default_style && ! is_admin()) { |
| 149 | 149 | $this->addStylesheet( |
| 150 | 150 | CoreAssetManager::CSS_HANDLE_DEFAULT, |
| 151 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
| 151 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css') |
|
| 152 | 152 | ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
| 153 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 153 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
| 154 | 154 | ['dashicons'] |
| 155 | 155 | ); |
| 156 | 156 | //Load custom style sheet if available |
| 157 | 157 | if ($this->template_config->custom_style_sheet !== null) { |
| 158 | 158 | $this->addStylesheet( |
| 159 | 159 | CoreAssetManager::CSS_HANDLE_CUSTOM, |
| 160 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 160 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 161 | 161 | [CoreAssetManager::CSS_HANDLE_DEFAULT] |
| 162 | 162 | ); |
| 163 | 163 | } |
@@ -14,151 +14,151 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | interface RequestTypeContextCheckerInterface extends InterminableInterface |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * true if the current request involves some form of activation |
|
| 19 | - * |
|
| 20 | - * @return bool |
|
| 21 | - */ |
|
| 22 | - public function isActivation(); |
|
| 17 | + /** |
|
| 18 | + * true if the current request involves some form of activation |
|
| 19 | + * |
|
| 20 | + * @return bool |
|
| 21 | + */ |
|
| 22 | + public function isActivation(); |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param $is_activation |
|
| 27 | - */ |
|
| 28 | - public function setIsActivation($is_activation); |
|
| 25 | + /** |
|
| 26 | + * @param $is_activation |
|
| 27 | + */ |
|
| 28 | + public function setIsActivation($is_activation); |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * true if the current request is for the admin and is not being made via AJAX |
|
| 33 | - * |
|
| 34 | - * @return bool |
|
| 35 | - */ |
|
| 36 | - public function isAdmin(); |
|
| 31 | + /** |
|
| 32 | + * true if the current request is for the admin and is not being made via AJAX |
|
| 33 | + * |
|
| 34 | + * @return bool |
|
| 35 | + */ |
|
| 36 | + public function isAdmin(); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * true if the current request is for the admin AND is being made via AJAX |
|
| 41 | - * and the ajax request contains the request parameter "ee_admin_ajax" |
|
| 42 | - * |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public function isAdminAjax(); |
|
| 39 | + /** |
|
| 40 | + * true if the current request is for the admin AND is being made via AJAX |
|
| 41 | + * and the ajax request contains the request parameter "ee_admin_ajax" |
|
| 42 | + * |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public function isAdminAjax(); |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * true if the current request is being made via AJAX... any AJAX |
|
| 50 | - * |
|
| 51 | - * @return bool |
|
| 52 | - */ |
|
| 53 | - public function isAjax(); |
|
| 48 | + /** |
|
| 49 | + * true if the current request is being made via AJAX... any AJAX |
|
| 50 | + * |
|
| 51 | + * @return bool |
|
| 52 | + */ |
|
| 53 | + public function isAjax(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * true if the current request is for the EE REST API |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isApi(); |
|
| 56 | + /** |
|
| 57 | + * true if the current request is for the EE REST API |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isApi(); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * true if the current request is from the command line |
|
| 66 | - * |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function isCli(); |
|
| 64 | + /** |
|
| 65 | + * true if the current request is from the command line |
|
| 66 | + * |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function isCli(); |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * true if the current request is for a WP_Cron |
|
| 74 | - * |
|
| 75 | - * @return bool |
|
| 76 | - */ |
|
| 77 | - public function isCron(); |
|
| 72 | + /** |
|
| 73 | + * true if the current request is for a WP_Cron |
|
| 74 | + * |
|
| 75 | + * @return bool |
|
| 76 | + */ |
|
| 77 | + public function isCron(); |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
| 82 | - * |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function isEeAjax(); |
|
| 80 | + /** |
|
| 81 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
| 82 | + * |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function isEeAjax(); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * true if the current request is for a feed (ie: RSS) |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function isFeed(); |
|
| 88 | + /** |
|
| 89 | + * true if the current request is for a feed (ie: RSS) |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function isFeed(); |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * true if the current request is for the frontend and is not being made via AJAX |
|
| 98 | - * |
|
| 99 | - * @return bool |
|
| 100 | - */ |
|
| 101 | - public function isFrontend(); |
|
| 96 | + /** |
|
| 97 | + * true if the current request is for the frontend and is not being made via AJAX |
|
| 98 | + * |
|
| 99 | + * @return bool |
|
| 100 | + */ |
|
| 101 | + public function isFrontend(); |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public function isFrontAjax(); |
|
| 104 | + /** |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public function isFrontAjax(); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function isGQL(); |
|
| 109 | + /** |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function isGQL(); |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function isIframe(); |
|
| 115 | + /** |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function isIframe(); |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
| 123 | - * |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - public function isOtherAjax(); |
|
| 121 | + /** |
|
| 122 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
| 123 | + * |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + public function isOtherAjax(); |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * true if the current request is occurring while unit testing |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function isUnitTesting(); |
|
| 129 | + /** |
|
| 130 | + * true if the current request is occurring while unit testing |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function isUnitTesting(); |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * true if the current request is for the WP REST API |
|
| 138 | - * |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function isWordPressApi(); |
|
| 136 | + /** |
|
| 137 | + * true if the current request is for the WP REST API |
|
| 138 | + * |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function isWordPressApi(); |
|
| 142 | 142 | |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * true if the current request is being made via AJAX for the WP Heartbeat |
|
| 146 | - * |
|
| 147 | - * @return bool |
|
| 148 | - */ |
|
| 149 | - public function isWordPressHeartbeat(); |
|
| 144 | + /** |
|
| 145 | + * true if the current request is being made via AJAX for the WP Heartbeat |
|
| 146 | + * |
|
| 147 | + * @return bool |
|
| 148 | + */ |
|
| 149 | + public function isWordPressHeartbeat(); |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * true if the current request is a loopback sent from WP core to test for errors |
|
| 154 | - * |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function isWordPressScrape(); |
|
| 152 | + /** |
|
| 153 | + * true if the current request is a loopback sent from WP core to test for errors |
|
| 154 | + * |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function isWordPressScrape(); |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @return string |
|
| 162 | - */ |
|
| 163 | - public function slug(); |
|
| 160 | + /** |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 163 | + public function slug(); |
|
| 164 | 164 | } |
@@ -16,128 +16,128 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RequestTypeContextFactory implements RequestTypeContextFactoryInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var LoaderInterface $loader |
|
| 21 | - */ |
|
| 22 | - private $loader; |
|
| 19 | + /** |
|
| 20 | + * @var LoaderInterface $loader |
|
| 21 | + */ |
|
| 22 | + private $loader; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * RequestTypeContextFactory constructor. |
|
| 27 | - * |
|
| 28 | - * @param LoaderInterface $loader |
|
| 29 | - */ |
|
| 30 | - public function __construct(LoaderInterface $loader) |
|
| 31 | - { |
|
| 32 | - $this->loader = $loader; |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * RequestTypeContextFactory constructor. |
|
| 27 | + * |
|
| 28 | + * @param LoaderInterface $loader |
|
| 29 | + */ |
|
| 30 | + public function __construct(LoaderInterface $loader) |
|
| 31 | + { |
|
| 32 | + $this->loader = $loader; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $slug |
|
| 38 | - * @return RequestTypeContext |
|
| 39 | - */ |
|
| 40 | - public function create($slug): RequestTypeContext |
|
| 41 | - { |
|
| 42 | - switch ($slug) { |
|
| 43 | - case RequestTypeContext::ACTIVATION: |
|
| 44 | - $description = esc_html__( |
|
| 45 | - 'The current request is for some form of activation', |
|
| 46 | - 'event_espresso' |
|
| 47 | - ); |
|
| 48 | - break; |
|
| 49 | - case RequestTypeContext::API: |
|
| 50 | - $description = esc_html__( |
|
| 51 | - 'The current request is for the EE REST API', |
|
| 52 | - 'event_espresso' |
|
| 53 | - ); |
|
| 54 | - break; |
|
| 55 | - case RequestTypeContext::AJAX_FRONT: |
|
| 56 | - $description = esc_html__( |
|
| 57 | - 'The current request is for the frontend via AJAX', |
|
| 58 | - 'event_espresso' |
|
| 59 | - ); |
|
| 60 | - break; |
|
| 61 | - case RequestTypeContext::AJAX_ADMIN: |
|
| 62 | - $description = esc_html__( |
|
| 63 | - 'The current request is for the admin via AJAX', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ); |
|
| 66 | - break; |
|
| 67 | - case RequestTypeContext::AJAX_HEARTBEAT: |
|
| 68 | - $description = esc_html__( |
|
| 69 | - 'The current request is for the WP Heartbeat', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ); |
|
| 72 | - break; |
|
| 73 | - case RequestTypeContext::AJAX_OTHER: |
|
| 74 | - $description = esc_html__( |
|
| 75 | - 'The current request is for non-EE related code via AJAX', |
|
| 76 | - 'event_espresso' |
|
| 77 | - ); |
|
| 78 | - break; |
|
| 79 | - case RequestTypeContext::CRON: |
|
| 80 | - $description = esc_html__( |
|
| 81 | - 'The current request is for a WP_Cron', |
|
| 82 | - 'event_espresso' |
|
| 83 | - ); |
|
| 84 | - break; |
|
| 85 | - case RequestTypeContext::CLI: |
|
| 86 | - $description = esc_html__( |
|
| 87 | - 'The current request is from the command line', |
|
| 88 | - 'event_espresso' |
|
| 89 | - ); |
|
| 90 | - break; |
|
| 91 | - case RequestTypeContext::ADMIN: |
|
| 92 | - $description = esc_html__( |
|
| 93 | - 'The current request is for the admin', |
|
| 94 | - 'event_espresso' |
|
| 95 | - ); |
|
| 96 | - break; |
|
| 97 | - case RequestTypeContext::IFRAME: |
|
| 98 | - $description = esc_html__( |
|
| 99 | - 'The current request is for an iframe', |
|
| 100 | - 'event_espresso' |
|
| 101 | - ); |
|
| 102 | - break; |
|
| 103 | - case RequestTypeContext::FEED: |
|
| 104 | - $description = esc_html__( |
|
| 105 | - 'The current request is for a feed (ie: RSS)', |
|
| 106 | - 'event_espresso' |
|
| 107 | - ); |
|
| 108 | - break; |
|
| 109 | - case RequestTypeContext::GQL: |
|
| 110 | - $description = esc_html__( |
|
| 111 | - 'The current request is for the EE GraphQL Manager', |
|
| 112 | - 'event_espresso' |
|
| 113 | - ); |
|
| 114 | - break; |
|
| 115 | - case RequestTypeContext::WP_API: |
|
| 116 | - $description = esc_html__( |
|
| 117 | - 'The current request is for the WordPress REST API', |
|
| 118 | - 'event_espresso' |
|
| 119 | - ); |
|
| 120 | - break; |
|
| 121 | - case RequestTypeContext::WP_SCRAPE: |
|
| 122 | - $description = esc_html__( |
|
| 123 | - 'The current request is for a WordPress loopback scrape', |
|
| 124 | - 'event_espresso' |
|
| 125 | - ); |
|
| 126 | - break; |
|
| 127 | - case RequestTypeContext::FRONTEND: |
|
| 128 | - default: |
|
| 129 | - $description = esc_html__( |
|
| 130 | - 'The current request is for the frontend', |
|
| 131 | - 'event_espresso' |
|
| 132 | - ); |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - // we're using the Loader with sharing turned on, |
|
| 136 | - // so that the generated RequestTypeContext object is accessible anywhere |
|
| 137 | - // by simply requesting it again from the loader |
|
| 138 | - return $this->loader->getShared( |
|
| 139 | - 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
| 140 | - array($slug, $description) |
|
| 141 | - ); |
|
| 142 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $slug |
|
| 38 | + * @return RequestTypeContext |
|
| 39 | + */ |
|
| 40 | + public function create($slug): RequestTypeContext |
|
| 41 | + { |
|
| 42 | + switch ($slug) { |
|
| 43 | + case RequestTypeContext::ACTIVATION: |
|
| 44 | + $description = esc_html__( |
|
| 45 | + 'The current request is for some form of activation', |
|
| 46 | + 'event_espresso' |
|
| 47 | + ); |
|
| 48 | + break; |
|
| 49 | + case RequestTypeContext::API: |
|
| 50 | + $description = esc_html__( |
|
| 51 | + 'The current request is for the EE REST API', |
|
| 52 | + 'event_espresso' |
|
| 53 | + ); |
|
| 54 | + break; |
|
| 55 | + case RequestTypeContext::AJAX_FRONT: |
|
| 56 | + $description = esc_html__( |
|
| 57 | + 'The current request is for the frontend via AJAX', |
|
| 58 | + 'event_espresso' |
|
| 59 | + ); |
|
| 60 | + break; |
|
| 61 | + case RequestTypeContext::AJAX_ADMIN: |
|
| 62 | + $description = esc_html__( |
|
| 63 | + 'The current request is for the admin via AJAX', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ); |
|
| 66 | + break; |
|
| 67 | + case RequestTypeContext::AJAX_HEARTBEAT: |
|
| 68 | + $description = esc_html__( |
|
| 69 | + 'The current request is for the WP Heartbeat', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ); |
|
| 72 | + break; |
|
| 73 | + case RequestTypeContext::AJAX_OTHER: |
|
| 74 | + $description = esc_html__( |
|
| 75 | + 'The current request is for non-EE related code via AJAX', |
|
| 76 | + 'event_espresso' |
|
| 77 | + ); |
|
| 78 | + break; |
|
| 79 | + case RequestTypeContext::CRON: |
|
| 80 | + $description = esc_html__( |
|
| 81 | + 'The current request is for a WP_Cron', |
|
| 82 | + 'event_espresso' |
|
| 83 | + ); |
|
| 84 | + break; |
|
| 85 | + case RequestTypeContext::CLI: |
|
| 86 | + $description = esc_html__( |
|
| 87 | + 'The current request is from the command line', |
|
| 88 | + 'event_espresso' |
|
| 89 | + ); |
|
| 90 | + break; |
|
| 91 | + case RequestTypeContext::ADMIN: |
|
| 92 | + $description = esc_html__( |
|
| 93 | + 'The current request is for the admin', |
|
| 94 | + 'event_espresso' |
|
| 95 | + ); |
|
| 96 | + break; |
|
| 97 | + case RequestTypeContext::IFRAME: |
|
| 98 | + $description = esc_html__( |
|
| 99 | + 'The current request is for an iframe', |
|
| 100 | + 'event_espresso' |
|
| 101 | + ); |
|
| 102 | + break; |
|
| 103 | + case RequestTypeContext::FEED: |
|
| 104 | + $description = esc_html__( |
|
| 105 | + 'The current request is for a feed (ie: RSS)', |
|
| 106 | + 'event_espresso' |
|
| 107 | + ); |
|
| 108 | + break; |
|
| 109 | + case RequestTypeContext::GQL: |
|
| 110 | + $description = esc_html__( |
|
| 111 | + 'The current request is for the EE GraphQL Manager', |
|
| 112 | + 'event_espresso' |
|
| 113 | + ); |
|
| 114 | + break; |
|
| 115 | + case RequestTypeContext::WP_API: |
|
| 116 | + $description = esc_html__( |
|
| 117 | + 'The current request is for the WordPress REST API', |
|
| 118 | + 'event_espresso' |
|
| 119 | + ); |
|
| 120 | + break; |
|
| 121 | + case RequestTypeContext::WP_SCRAPE: |
|
| 122 | + $description = esc_html__( |
|
| 123 | + 'The current request is for a WordPress loopback scrape', |
|
| 124 | + 'event_espresso' |
|
| 125 | + ); |
|
| 126 | + break; |
|
| 127 | + case RequestTypeContext::FRONTEND: |
|
| 128 | + default: |
|
| 129 | + $description = esc_html__( |
|
| 130 | + 'The current request is for the frontend', |
|
| 131 | + 'event_espresso' |
|
| 132 | + ); |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + // we're using the Loader with sharing turned on, |
|
| 136 | + // so that the generated RequestTypeContext object is accessible anywhere |
|
| 137 | + // by simply requesting it again from the loader |
|
| 138 | + return $this->loader->getShared( |
|
| 139 | + 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
| 140 | + array($slug, $description) |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | 143 | } |