@@ -24,40 +24,40 @@ |
||
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var LoaderInterface $loader |
|
| 29 | - */ |
|
| 30 | - private $loader; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * CommandFactory constructor |
|
| 36 | - * |
|
| 37 | - * @param LoaderInterface $loader |
|
| 38 | - * @throws InvalidDataTypeException |
|
| 39 | - * @throws InvalidInterfaceException |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - */ |
|
| 42 | - public function __construct(LoaderInterface $loader = null) |
|
| 43 | - { |
|
| 44 | - $this->loader = $loader; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $command_fqcn |
|
| 51 | - * @param array $arguments |
|
| 52 | - * @return mixed |
|
| 53 | - * @throws InvalidArgumentException |
|
| 54 | - * @throws InvalidDataTypeException |
|
| 55 | - * @throws InvalidInterfaceException |
|
| 56 | - */ |
|
| 57 | - public function getNew($command_fqcn, $arguments = array()) |
|
| 58 | - { |
|
| 59 | - return $this->loader->getNew($command_fqcn, $arguments); |
|
| 60 | - } |
|
| 27 | + /** |
|
| 28 | + * @var LoaderInterface $loader |
|
| 29 | + */ |
|
| 30 | + private $loader; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * CommandFactory constructor |
|
| 36 | + * |
|
| 37 | + * @param LoaderInterface $loader |
|
| 38 | + * @throws InvalidDataTypeException |
|
| 39 | + * @throws InvalidInterfaceException |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + */ |
|
| 42 | + public function __construct(LoaderInterface $loader = null) |
|
| 43 | + { |
|
| 44 | + $this->loader = $loader; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $command_fqcn |
|
| 51 | + * @param array $arguments |
|
| 52 | + * @return mixed |
|
| 53 | + * @throws InvalidArgumentException |
|
| 54 | + * @throws InvalidDataTypeException |
|
| 55 | + * @throws InvalidInterfaceException |
|
| 56 | + */ |
|
| 57 | + public function getNew($command_fqcn, $arguments = array()) |
|
| 58 | + { |
|
| 59 | + return $this->loader->getNew($command_fqcn, $arguments); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | interface CommandFactoryInterface |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param string $command_fqcn |
|
| 18 | - * @param array $arguments |
|
| 19 | - * @return mixed |
|
| 20 | - * @throws InvalidArgumentException |
|
| 21 | - * @throws InvalidDataTypeException |
|
| 22 | - * @throws InvalidInterfaceException |
|
| 23 | - */ |
|
| 24 | - public function getNew($command_fqcn, $arguments = array()); |
|
| 16 | + /** |
|
| 17 | + * @param string $command_fqcn |
|
| 18 | + * @param array $arguments |
|
| 19 | + * @return mixed |
|
| 20 | + * @throws InvalidArgumentException |
|
| 21 | + * @throws InvalidDataTypeException |
|
| 22 | + * @throws InvalidInterfaceException |
|
| 23 | + */ |
|
| 24 | + public function getNew($command_fqcn, $arguments = array()); |
|
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | // End of file CommandFactoryInterface.php |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 7 | 7 | |
| 8 | 8 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 9 | - exit('No direct script access allowed'); |
|
| 9 | + exit('No direct script access allowed'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | |
@@ -24,109 +24,109 @@ discard block |
||
| 24 | 24 | class CommandHandlerManager implements CommandHandlerManagerInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var CommandHandlerInterface[] $command_handlers |
|
| 29 | - */ |
|
| 30 | - protected $command_handlers; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type LoaderInterface $loader |
|
| 34 | - */ |
|
| 35 | - private $loader; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * CommandHandlerManager constructor |
|
| 41 | - * |
|
| 42 | - * @param LoaderInterface $loader |
|
| 43 | - */ |
|
| 44 | - public function __construct(LoaderInterface $loader) |
|
| 45 | - { |
|
| 46 | - $this->loader = $loader; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * By default, Commands and CommandHandlers would normally |
|
| 53 | - * reside in the same folder under the same namespace, |
|
| 54 | - * and the names of the two classes would only differ in that |
|
| 55 | - * one ends in "Command" and the other ends in "CommandHandler". |
|
| 56 | - * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
| 57 | - * then this method allows you to add that CommandHandler and specify the FQCN |
|
| 58 | - * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
| 59 | - * For example: |
|
| 60 | - * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
| 61 | - * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
| 62 | - * but if you wanted to instead process that commend using: |
|
| 63 | - * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
| 64 | - * then the following code: |
|
| 65 | - * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
| 66 | - * $CommandHandlerManager->addCommandHandler( |
|
| 67 | - * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
| 68 | - * 'Vendor\some\namespace\DoSomethingCommand' |
|
| 69 | - * ); |
|
| 70 | - * would result in the alternate CommandHandler being used to process that Command |
|
| 71 | - * |
|
| 72 | - * @param CommandHandlerInterface $command_handler |
|
| 73 | - * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
| 74 | - * @return void |
|
| 75 | - * @throws InvalidCommandHandlerException |
|
| 76 | - */ |
|
| 77 | - public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
| 78 | - { |
|
| 79 | - $command = ! empty($fqcn_for_command) |
|
| 80 | - ? $fqcn_for_command |
|
| 81 | - : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
| 82 | - if (empty($command)) { |
|
| 83 | - throw new InvalidCommandHandlerException($command); |
|
| 84 | - } |
|
| 85 | - $this->command_handlers[$command] = $command_handler; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param CommandInterface $command |
|
| 92 | - * @param CommandBusInterface $command_bus |
|
| 93 | - * @return mixed |
|
| 94 | - * @throws DomainException |
|
| 95 | - * @throws CommandHandlerNotFoundException |
|
| 96 | - */ |
|
| 97 | - public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
| 98 | - { |
|
| 99 | - $command_name = get_class($command); |
|
| 100 | - $command_handler = apply_filters( |
|
| 101 | - 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
| 102 | - str_replace('Command', 'CommandHandler', $command_name), |
|
| 103 | - $command |
|
| 104 | - ); |
|
| 105 | - $handler = null; |
|
| 106 | - // has a command handler already been set for this class ? |
|
| 107 | - // if not, can we find one via the FQCN ? |
|
| 108 | - if (isset($this->command_handlers[$command_name])) { |
|
| 109 | - $handler = $this->command_handlers[$command_name]; |
|
| 110 | - } else if (class_exists($command_handler)) { |
|
| 111 | - $handler = $this->loader->getShared($command_handler); |
|
| 112 | - } |
|
| 113 | - // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
| 114 | - if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
| 115 | - if (! $command_bus instanceof CommandBusInterface) { |
|
| 116 | - throw new DomainException( |
|
| 117 | - esc_html__( |
|
| 118 | - 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
| 119 | - 'event_espresso' |
|
| 120 | - ) |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - $handler->setCommandBus($command_bus); |
|
| 124 | - } |
|
| 125 | - if ($handler instanceof CommandHandlerInterface) { |
|
| 126 | - return $handler; |
|
| 127 | - } |
|
| 128 | - throw new CommandHandlerNotFoundException($command_handler); |
|
| 129 | - } |
|
| 27 | + /** |
|
| 28 | + * @var CommandHandlerInterface[] $command_handlers |
|
| 29 | + */ |
|
| 30 | + protected $command_handlers; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type LoaderInterface $loader |
|
| 34 | + */ |
|
| 35 | + private $loader; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * CommandHandlerManager constructor |
|
| 41 | + * |
|
| 42 | + * @param LoaderInterface $loader |
|
| 43 | + */ |
|
| 44 | + public function __construct(LoaderInterface $loader) |
|
| 45 | + { |
|
| 46 | + $this->loader = $loader; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * By default, Commands and CommandHandlers would normally |
|
| 53 | + * reside in the same folder under the same namespace, |
|
| 54 | + * and the names of the two classes would only differ in that |
|
| 55 | + * one ends in "Command" and the other ends in "CommandHandler". |
|
| 56 | + * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
| 57 | + * then this method allows you to add that CommandHandler and specify the FQCN |
|
| 58 | + * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
| 59 | + * For example: |
|
| 60 | + * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
| 61 | + * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
| 62 | + * but if you wanted to instead process that commend using: |
|
| 63 | + * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
| 64 | + * then the following code: |
|
| 65 | + * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
| 66 | + * $CommandHandlerManager->addCommandHandler( |
|
| 67 | + * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
| 68 | + * 'Vendor\some\namespace\DoSomethingCommand' |
|
| 69 | + * ); |
|
| 70 | + * would result in the alternate CommandHandler being used to process that Command |
|
| 71 | + * |
|
| 72 | + * @param CommandHandlerInterface $command_handler |
|
| 73 | + * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
| 74 | + * @return void |
|
| 75 | + * @throws InvalidCommandHandlerException |
|
| 76 | + */ |
|
| 77 | + public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
| 78 | + { |
|
| 79 | + $command = ! empty($fqcn_for_command) |
|
| 80 | + ? $fqcn_for_command |
|
| 81 | + : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
| 82 | + if (empty($command)) { |
|
| 83 | + throw new InvalidCommandHandlerException($command); |
|
| 84 | + } |
|
| 85 | + $this->command_handlers[$command] = $command_handler; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param CommandInterface $command |
|
| 92 | + * @param CommandBusInterface $command_bus |
|
| 93 | + * @return mixed |
|
| 94 | + * @throws DomainException |
|
| 95 | + * @throws CommandHandlerNotFoundException |
|
| 96 | + */ |
|
| 97 | + public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
| 98 | + { |
|
| 99 | + $command_name = get_class($command); |
|
| 100 | + $command_handler = apply_filters( |
|
| 101 | + 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
| 102 | + str_replace('Command', 'CommandHandler', $command_name), |
|
| 103 | + $command |
|
| 104 | + ); |
|
| 105 | + $handler = null; |
|
| 106 | + // has a command handler already been set for this class ? |
|
| 107 | + // if not, can we find one via the FQCN ? |
|
| 108 | + if (isset($this->command_handlers[$command_name])) { |
|
| 109 | + $handler = $this->command_handlers[$command_name]; |
|
| 110 | + } else if (class_exists($command_handler)) { |
|
| 111 | + $handler = $this->loader->getShared($command_handler); |
|
| 112 | + } |
|
| 113 | + // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
| 114 | + if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
| 115 | + if (! $command_bus instanceof CommandBusInterface) { |
|
| 116 | + throw new DomainException( |
|
| 117 | + esc_html__( |
|
| 118 | + 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
| 119 | + 'event_espresso' |
|
| 120 | + ) |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + $handler->setCommandBus($command_bus); |
|
| 124 | + } |
|
| 125 | + if ($handler instanceof CommandHandlerInterface) { |
|
| 126 | + return $handler; |
|
| 127 | + } |
|
| 128 | + throw new CommandHandlerNotFoundException($command_handler); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use DomainException; |
| 6 | 6 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 7 | 7 | |
| 8 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 9 | 9 | exit('No direct script access allowed'); |
| 10 | 10 | } |
| 11 | 11 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | // if Handler requires an instance of the CommandBus, but that has not yet been set |
| 114 | 114 | if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
| 115 | - if (! $command_bus instanceof CommandBusInterface) { |
|
| 115 | + if ( ! $command_bus instanceof CommandBusInterface) { |
|
| 116 | 116 | throw new DomainException( |
| 117 | 117 | esc_html__( |
| 118 | 118 | 'CompositeCommandHandler classes require an instance of the CommandBus.', |
@@ -24,140 +24,140 @@ |
||
| 24 | 24 | { |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var LoaderDecoratorInterface $new_loader |
|
| 29 | - */ |
|
| 30 | - private $new_loader; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var LoaderDecoratorInterface $shared_loader |
|
| 35 | - */ |
|
| 36 | - private $shared_loader; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Loader constructor. |
|
| 42 | - * |
|
| 43 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 44 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 45 | - * @throws InvalidInterfaceException |
|
| 46 | - * @throws InvalidArgumentException |
|
| 47 | - * @throws InvalidDataTypeException |
|
| 48 | - */ |
|
| 49 | - public function __construct(LoaderDecoratorInterface $new_loader = null, LoaderDecoratorInterface $shared_loader = null) |
|
| 50 | - { |
|
| 51 | - $this->new_loader = $this->setupNewLoader($new_loader); |
|
| 52 | - $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 59 | - * @return CoreLoader|LoaderDecoratorInterface |
|
| 60 | - * @throws InvalidArgumentException |
|
| 61 | - */ |
|
| 62 | - private function setupNewLoader(LoaderDecoratorInterface $new_loader = null) |
|
| 63 | - { |
|
| 64 | - // if not already generated, create a standard loader |
|
| 65 | - if (! $new_loader instanceof LoaderDecoratorInterface) { |
|
| 66 | - $new_loader = new CoreLoader(EE_Registry::instance()); |
|
| 67 | - } |
|
| 68 | - return $new_loader; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 75 | - * @return CoreLoader|LoaderDecoratorInterface |
|
| 76 | - * @throws InvalidDataTypeException |
|
| 77 | - * @throws InvalidInterfaceException |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - */ |
|
| 80 | - private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null) |
|
| 81 | - { |
|
| 82 | - // if not already generated, create a caching loader |
|
| 83 | - if (! $shared_loader instanceof LoaderDecoratorInterface) { |
|
| 84 | - $shared_loader = new CachingLoader( |
|
| 85 | - new CoreLoader(EE_Registry::instance()), |
|
| 86 | - new LooseCollection('') |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - return $shared_loader; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return LoaderDecoratorInterface |
|
| 96 | - */ |
|
| 97 | - public function getNewLoader() |
|
| 98 | - { |
|
| 99 | - return $this->new_loader; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return LoaderDecoratorInterface |
|
| 106 | - */ |
|
| 107 | - public function getSharedLoader() |
|
| 108 | - { |
|
| 109 | - return $this->shared_loader; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $fqcn |
|
| 116 | - * @param array $arguments |
|
| 117 | - * @param bool $shared |
|
| 118 | - * @return mixed |
|
| 119 | - */ |
|
| 120 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 121 | - { |
|
| 122 | - return $shared |
|
| 123 | - ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
| 124 | - : $this->getNewLoader()->load($fqcn, $arguments); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param string $fqcn |
|
| 131 | - * @param array $arguments |
|
| 132 | - * @return mixed |
|
| 133 | - */ |
|
| 134 | - public function getNew($fqcn, $arguments = array()) |
|
| 135 | - { |
|
| 136 | - return $this->getNewLoader()->load($fqcn, $arguments); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param string $fqcn |
|
| 143 | - * @param array $arguments |
|
| 144 | - * @return mixed |
|
| 145 | - */ |
|
| 146 | - public function getShared($fqcn, $arguments = array()) |
|
| 147 | - { |
|
| 148 | - return $this->getSharedLoader()->load($fqcn, $arguments); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * calls reset() on loaders if that method exists |
|
| 155 | - */ |
|
| 156 | - public function reset() |
|
| 157 | - { |
|
| 158 | - $this->new_loader->reset(); |
|
| 159 | - $this->shared_loader->reset(); |
|
| 160 | - } |
|
| 27 | + /** |
|
| 28 | + * @var LoaderDecoratorInterface $new_loader |
|
| 29 | + */ |
|
| 30 | + private $new_loader; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var LoaderDecoratorInterface $shared_loader |
|
| 35 | + */ |
|
| 36 | + private $shared_loader; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Loader constructor. |
|
| 42 | + * |
|
| 43 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 44 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 45 | + * @throws InvalidInterfaceException |
|
| 46 | + * @throws InvalidArgumentException |
|
| 47 | + * @throws InvalidDataTypeException |
|
| 48 | + */ |
|
| 49 | + public function __construct(LoaderDecoratorInterface $new_loader = null, LoaderDecoratorInterface $shared_loader = null) |
|
| 50 | + { |
|
| 51 | + $this->new_loader = $this->setupNewLoader($new_loader); |
|
| 52 | + $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 59 | + * @return CoreLoader|LoaderDecoratorInterface |
|
| 60 | + * @throws InvalidArgumentException |
|
| 61 | + */ |
|
| 62 | + private function setupNewLoader(LoaderDecoratorInterface $new_loader = null) |
|
| 63 | + { |
|
| 64 | + // if not already generated, create a standard loader |
|
| 65 | + if (! $new_loader instanceof LoaderDecoratorInterface) { |
|
| 66 | + $new_loader = new CoreLoader(EE_Registry::instance()); |
|
| 67 | + } |
|
| 68 | + return $new_loader; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 75 | + * @return CoreLoader|LoaderDecoratorInterface |
|
| 76 | + * @throws InvalidDataTypeException |
|
| 77 | + * @throws InvalidInterfaceException |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + */ |
|
| 80 | + private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null) |
|
| 81 | + { |
|
| 82 | + // if not already generated, create a caching loader |
|
| 83 | + if (! $shared_loader instanceof LoaderDecoratorInterface) { |
|
| 84 | + $shared_loader = new CachingLoader( |
|
| 85 | + new CoreLoader(EE_Registry::instance()), |
|
| 86 | + new LooseCollection('') |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + return $shared_loader; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return LoaderDecoratorInterface |
|
| 96 | + */ |
|
| 97 | + public function getNewLoader() |
|
| 98 | + { |
|
| 99 | + return $this->new_loader; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return LoaderDecoratorInterface |
|
| 106 | + */ |
|
| 107 | + public function getSharedLoader() |
|
| 108 | + { |
|
| 109 | + return $this->shared_loader; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $fqcn |
|
| 116 | + * @param array $arguments |
|
| 117 | + * @param bool $shared |
|
| 118 | + * @return mixed |
|
| 119 | + */ |
|
| 120 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 121 | + { |
|
| 122 | + return $shared |
|
| 123 | + ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
| 124 | + : $this->getNewLoader()->load($fqcn, $arguments); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param string $fqcn |
|
| 131 | + * @param array $arguments |
|
| 132 | + * @return mixed |
|
| 133 | + */ |
|
| 134 | + public function getNew($fqcn, $arguments = array()) |
|
| 135 | + { |
|
| 136 | + return $this->getNewLoader()->load($fqcn, $arguments); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param string $fqcn |
|
| 143 | + * @param array $arguments |
|
| 144 | + * @return mixed |
|
| 145 | + */ |
|
| 146 | + public function getShared($fqcn, $arguments = array()) |
|
| 147 | + { |
|
| 148 | + return $this->getSharedLoader()->load($fqcn, $arguments); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * calls reset() on loaders if that method exists |
|
| 155 | + */ |
|
| 156 | + public function reset() |
|
| 157 | + { |
|
| 158 | + $this->new_loader->reset(); |
|
| 159 | + $this->shared_loader->reset(); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | } |
| 163 | 163 | // End of file Loader.php |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | private function setupNewLoader(LoaderDecoratorInterface $new_loader = null) |
| 63 | 63 | { |
| 64 | 64 | // if not already generated, create a standard loader |
| 65 | - if (! $new_loader instanceof LoaderDecoratorInterface) { |
|
| 65 | + if ( ! $new_loader instanceof LoaderDecoratorInterface) { |
|
| 66 | 66 | $new_loader = new CoreLoader(EE_Registry::instance()); |
| 67 | 67 | } |
| 68 | 68 | return $new_loader; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | private function setupSharedLoader(LoaderDecoratorInterface $shared_loader = null) |
| 81 | 81 | { |
| 82 | 82 | // if not already generated, create a caching loader |
| 83 | - if (! $shared_loader instanceof LoaderDecoratorInterface) { |
|
| 83 | + if ( ! $shared_loader instanceof LoaderDecoratorInterface) { |
|
| 84 | 84 | $shared_loader = new CachingLoader( |
| 85 | 85 | new CoreLoader(EE_Registry::instance()), |
| 86 | 86 | new LooseCollection('') |
@@ -9,19 +9,19 @@ |
||
| 9 | 9 | interface LoaderDecoratorInterface |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param string $fqcn |
|
| 14 | - * @param array $arguments |
|
| 15 | - * @return mixed |
|
| 16 | - */ |
|
| 17 | - public function load($fqcn, $arguments = array()); |
|
| 12 | + /** |
|
| 13 | + * @param string $fqcn |
|
| 14 | + * @param array $arguments |
|
| 15 | + * @return mixed |
|
| 16 | + */ |
|
| 17 | + public function load($fqcn, $arguments = array()); |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * calls reset() on loader if method exists |
|
| 23 | - */ |
|
| 24 | - public function reset(); |
|
| 21 | + /** |
|
| 22 | + * calls reset() on loader if method exists |
|
| 23 | + */ |
|
| 24 | + public function reset(); |
|
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | // End of file LoaderInterface.php |
@@ -9,39 +9,39 @@ |
||
| 9 | 9 | interface LoaderInterface |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Can be for instantiating a new instance of a class, |
|
| 14 | - * or for getting a shared instance of a class (default) |
|
| 15 | - * |
|
| 16 | - * @param string $fqcn |
|
| 17 | - * @param array $arguments |
|
| 18 | - * @param bool $shared |
|
| 19 | - * @return mixed |
|
| 20 | - */ |
|
| 21 | - public function load($fqcn, $arguments = array(), $shared = true); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Used for instantiating a new instance of a class |
|
| 25 | - * |
|
| 26 | - * @param string $fqcn |
|
| 27 | - * @param array $arguments |
|
| 28 | - * @return mixed |
|
| 29 | - */ |
|
| 30 | - public function getNew($fqcn, $arguments = array()); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Used for getting a shared instance of a class |
|
| 34 | - * |
|
| 35 | - * @param string $fqcn |
|
| 36 | - * @param array $arguments |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function getShared($fqcn, $arguments = array()); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * calls reset() on loader if method exists |
|
| 43 | - */ |
|
| 44 | - public function reset(); |
|
| 12 | + /** |
|
| 13 | + * Can be for instantiating a new instance of a class, |
|
| 14 | + * or for getting a shared instance of a class (default) |
|
| 15 | + * |
|
| 16 | + * @param string $fqcn |
|
| 17 | + * @param array $arguments |
|
| 18 | + * @param bool $shared |
|
| 19 | + * @return mixed |
|
| 20 | + */ |
|
| 21 | + public function load($fqcn, $arguments = array(), $shared = true); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Used for instantiating a new instance of a class |
|
| 25 | + * |
|
| 26 | + * @param string $fqcn |
|
| 27 | + * @param array $arguments |
|
| 28 | + * @return mixed |
|
| 29 | + */ |
|
| 30 | + public function getNew($fqcn, $arguments = array()); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Used for getting a shared instance of a class |
|
| 34 | + * |
|
| 35 | + * @param string $fqcn |
|
| 36 | + * @param array $arguments |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function getShared($fqcn, $arguments = array()); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * calls reset() on loader if method exists |
|
| 43 | + */ |
|
| 44 | + public function reset(); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | // End of file LoaderInterface.php |
@@ -22,114 +22,114 @@ |
||
| 22 | 22 | class CachingLoader extends LoaderDecorator |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var CollectionInterface $cache |
|
| 27 | - */ |
|
| 28 | - protected $cache; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string $identifier |
|
| 32 | - */ |
|
| 33 | - protected $identifier; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * CachingLoader constructor. |
|
| 39 | - * |
|
| 40 | - * @param LoaderDecoratorInterface $loader |
|
| 41 | - * @param CollectionInterface $cache |
|
| 42 | - * @param string $identifier |
|
| 43 | - * @throws InvalidDataTypeException |
|
| 44 | - */ |
|
| 45 | - public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
| 46 | - { |
|
| 47 | - parent::__construct($loader); |
|
| 48 | - $this->cache = $cache; |
|
| 49 | - $this->setIdentifier($identifier); |
|
| 50 | - if ($this->identifier !== '') { |
|
| 51 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
| 52 | - // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
| 53 | - // where "IDENTIFIER" = the string that was set during construction |
|
| 54 | - add_action( |
|
| 55 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
| 56 | - array($this, 'reset') |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - // to clear ALL caches, simply do the following: |
|
| 60 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
| 61 | - add_action( |
|
| 62 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
| 63 | - array($this, 'reset') |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function identifier() |
|
| 73 | - { |
|
| 74 | - return $this->identifier; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $identifier |
|
| 81 | - * @throws InvalidDataTypeException |
|
| 82 | - */ |
|
| 83 | - private function setIdentifier($identifier) |
|
| 84 | - { |
|
| 85 | - if ( ! is_string($identifier)) { |
|
| 86 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
| 87 | - } |
|
| 88 | - $this->identifier = $identifier; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param string $fqcn |
|
| 95 | - * @param array $arguments |
|
| 96 | - * @return mixed |
|
| 97 | - * @throws InvalidEntityException |
|
| 98 | - * @throws ServiceNotFoundException |
|
| 99 | - */ |
|
| 100 | - public function load($fqcn, $arguments = array()) |
|
| 101 | - { |
|
| 102 | - $fqcn = ltrim($fqcn, '\\'); |
|
| 103 | - // caching can be turned off via the following code: |
|
| 104 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
| 105 | - if( |
|
| 106 | - apply_filters( |
|
| 107 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
| 108 | - false, |
|
| 109 | - $this |
|
| 110 | - ) |
|
| 111 | - ){ |
|
| 112 | - return $this->loader->load($fqcn, $arguments); |
|
| 113 | - } |
|
| 114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
| 115 | - if($this->cache->has($identifier)){ |
|
| 116 | - return $this->cache->get($identifier); |
|
| 117 | - } |
|
| 118 | - $object = $this->loader->load($fqcn, $arguments); |
|
| 119 | - $this->cache->add($object, $identifier); |
|
| 120 | - return $object; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * empties cache and calls reset() on loader if method exists |
|
| 127 | - */ |
|
| 128 | - public function reset() |
|
| 129 | - { |
|
| 130 | - $this->cache->detachAll(); |
|
| 131 | - $this->loader->reset(); |
|
| 132 | - } |
|
| 25 | + /** |
|
| 26 | + * @var CollectionInterface $cache |
|
| 27 | + */ |
|
| 28 | + protected $cache; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string $identifier |
|
| 32 | + */ |
|
| 33 | + protected $identifier; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * CachingLoader constructor. |
|
| 39 | + * |
|
| 40 | + * @param LoaderDecoratorInterface $loader |
|
| 41 | + * @param CollectionInterface $cache |
|
| 42 | + * @param string $identifier |
|
| 43 | + * @throws InvalidDataTypeException |
|
| 44 | + */ |
|
| 45 | + public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
| 46 | + { |
|
| 47 | + parent::__construct($loader); |
|
| 48 | + $this->cache = $cache; |
|
| 49 | + $this->setIdentifier($identifier); |
|
| 50 | + if ($this->identifier !== '') { |
|
| 51 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
| 52 | + // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
| 53 | + // where "IDENTIFIER" = the string that was set during construction |
|
| 54 | + add_action( |
|
| 55 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
| 56 | + array($this, 'reset') |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + // to clear ALL caches, simply do the following: |
|
| 60 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
| 61 | + add_action( |
|
| 62 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
| 63 | + array($this, 'reset') |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function identifier() |
|
| 73 | + { |
|
| 74 | + return $this->identifier; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $identifier |
|
| 81 | + * @throws InvalidDataTypeException |
|
| 82 | + */ |
|
| 83 | + private function setIdentifier($identifier) |
|
| 84 | + { |
|
| 85 | + if ( ! is_string($identifier)) { |
|
| 86 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
| 87 | + } |
|
| 88 | + $this->identifier = $identifier; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param string $fqcn |
|
| 95 | + * @param array $arguments |
|
| 96 | + * @return mixed |
|
| 97 | + * @throws InvalidEntityException |
|
| 98 | + * @throws ServiceNotFoundException |
|
| 99 | + */ |
|
| 100 | + public function load($fqcn, $arguments = array()) |
|
| 101 | + { |
|
| 102 | + $fqcn = ltrim($fqcn, '\\'); |
|
| 103 | + // caching can be turned off via the following code: |
|
| 104 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
| 105 | + if( |
|
| 106 | + apply_filters( |
|
| 107 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
| 108 | + false, |
|
| 109 | + $this |
|
| 110 | + ) |
|
| 111 | + ){ |
|
| 112 | + return $this->loader->load($fqcn, $arguments); |
|
| 113 | + } |
|
| 114 | + $identifier = md5($fqcn . serialize($arguments)); |
|
| 115 | + if($this->cache->has($identifier)){ |
|
| 116 | + return $this->cache->get($identifier); |
|
| 117 | + } |
|
| 118 | + $object = $this->loader->load($fqcn, $arguments); |
|
| 119 | + $this->cache->add($object, $identifier); |
|
| 120 | + return $object; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * empties cache and calls reset() on loader if method exists |
|
| 127 | + */ |
|
| 128 | + public function reset() |
|
| 129 | + { |
|
| 130 | + $this->cache->detachAll(); |
|
| 131 | + $this->loader->reset(); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | 135 | } |
@@ -19,22 +19,22 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var LoaderDecoratorInterface $loader |
|
| 24 | - */ |
|
| 25 | - protected $loader; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * LoaderDecorator constructor. |
|
| 31 | - * |
|
| 32 | - * @param LoaderDecoratorInterface $loader |
|
| 33 | - */ |
|
| 34 | - public function __construct(LoaderDecoratorInterface $loader) |
|
| 35 | - { |
|
| 36 | - $this->loader = $loader; |
|
| 37 | - } |
|
| 22 | + /** |
|
| 23 | + * @var LoaderDecoratorInterface $loader |
|
| 24 | + */ |
|
| 25 | + protected $loader; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * LoaderDecorator constructor. |
|
| 31 | + * |
|
| 32 | + * @param LoaderDecoratorInterface $loader |
|
| 33 | + */ |
|
| 34 | + public function __construct(LoaderDecoratorInterface $loader) |
|
| 35 | + { |
|
| 36 | + $this->loader = $loader; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
@@ -23,58 +23,58 @@ |
||
| 23 | 23 | class CoreLoader implements LoaderDecoratorInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registry|CoffeeShop $generator |
|
| 28 | - */ |
|
| 29 | - private $generator; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * CoreLoader constructor. |
|
| 35 | - * |
|
| 36 | - * @param EE_Registry|CoffeeShop $generator |
|
| 37 | - * @throws InvalidArgumentException |
|
| 38 | - */ |
|
| 39 | - public function __construct($generator) |
|
| 40 | - { |
|
| 41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 42 | - throw new InvalidArgumentException( |
|
| 43 | - esc_html__( |
|
| 44 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 45 | - 'event_espresso' |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - $this->generator = $generator; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param string $fqcn |
|
| 56 | - * @param array $arguments |
|
| 57 | - * @return mixed |
|
| 58 | - * @throws ServiceNotFoundException |
|
| 59 | - */ |
|
| 60 | - public function load($fqcn, $arguments = array()) |
|
| 61 | - { |
|
| 62 | - return $this->generator instanceof EE_Registry |
|
| 63 | - ? $this->generator->create($fqcn, $arguments) |
|
| 64 | - : $this->generator->brew($fqcn, $arguments); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * calls reset() on generator if method exists |
|
| 71 | - */ |
|
| 72 | - public function reset() |
|
| 73 | - { |
|
| 74 | - if (method_exists($this->generator, 'reset')) { |
|
| 75 | - $this->generator->reset(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registry|CoffeeShop $generator |
|
| 28 | + */ |
|
| 29 | + private $generator; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * CoreLoader constructor. |
|
| 35 | + * |
|
| 36 | + * @param EE_Registry|CoffeeShop $generator |
|
| 37 | + * @throws InvalidArgumentException |
|
| 38 | + */ |
|
| 39 | + public function __construct($generator) |
|
| 40 | + { |
|
| 41 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 42 | + throw new InvalidArgumentException( |
|
| 43 | + esc_html__( |
|
| 44 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 45 | + 'event_espresso' |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + $this->generator = $generator; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param string $fqcn |
|
| 56 | + * @param array $arguments |
|
| 57 | + * @return mixed |
|
| 58 | + * @throws ServiceNotFoundException |
|
| 59 | + */ |
|
| 60 | + public function load($fqcn, $arguments = array()) |
|
| 61 | + { |
|
| 62 | + return $this->generator instanceof EE_Registry |
|
| 63 | + ? $this->generator->create($fqcn, $arguments) |
|
| 64 | + : $this->generator->brew($fqcn, $arguments); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * calls reset() on generator if method exists |
|
| 71 | + */ |
|
| 72 | + public function reset() |
|
| 73 | + { |
|
| 74 | + if (method_exists($this->generator, 'reset')) { |
|
| 75 | + $this->generator->reset(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | // End of file CoreLoader.php |