From 71430ec5557e5584dc605648edf095a0994897e8 Mon Sep 17 00:00:00 2001 From: Joel Alphonso Date: Tue, 8 Nov 2022 15:37:08 -0500 Subject: [PATCH] fix(event): rename event services container keys to be prefixed with `app/` --- .../Admin/Action/ElfinderConnectorAction.php | 2 +- .../ServiceProvider/AdminServiceProvider.php | 44 ------------------- .../app/src/Charcoal/App/Facade/Event.php | 4 +- .../ServiceProvider/EventServiceProvider.php | 38 ++++++++++++++++ 4 files changed, 41 insertions(+), 47 deletions(-) diff --git a/packages/admin/src/Charcoal/Admin/Action/ElfinderConnectorAction.php b/packages/admin/src/Charcoal/Admin/Action/ElfinderConnectorAction.php index d744a4956..efc1397cd 100644 --- a/packages/admin/src/Charcoal/Admin/Action/ElfinderConnectorAction.php +++ b/packages/admin/src/Charcoal/Admin/Action/ElfinderConnectorAction.php @@ -914,7 +914,7 @@ public function setDependencies(Container $container) $this->filesystemConfig = $container['filesystem/config']; $this->filesystems = $container['filesystems']; - $this->setEventDispatcher($container['admin/event/dispatcher']); + $this->setEventDispatcher($container['app/event/dispatcher']); } /** diff --git a/packages/admin/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php b/packages/admin/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php index 814fabc7e..cc9ad9e20 100644 --- a/packages/admin/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php +++ b/packages/admin/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php @@ -4,8 +4,6 @@ // From Pimple use Charcoal\Admin\AssetsConfig; -use Charcoal\Event\EventDispatcher; -use Charcoal\Event\EventDispatcherBuilder; use Pimple\Container; use Pimple\ServiceProviderInterface; use Assetic\Asset\AssetReference; @@ -85,7 +83,6 @@ public function register(Container $container) $this->registerAuthExtensions($container); $this->registerViewExtensions($container); $this->registerAssetsManager($container); - $this->registerAdminEventDispatcher($container); // Register Access-Control-List (acl) $container->register(new AclServiceProvider()); @@ -551,45 +548,4 @@ protected function registerFactoryServices(Container $container) ]); }; } - - /** - * @param Container $container Pimple DI container. - * @return void - */ - protected function registerAdminEventDispatcher(Container $container) - { - /** - * @param Container $container - * @return array - */ - $container['admin/event/listeners'] = function (Container $container): array { - return ($container['admin/config']->get('events.listeners') ?? []); - }; - - /** - * Subscribers are classes that implements `\League\Event\ListenerSubscriber` - * It allows to subscribe many grouped listeners at once. - * - * @param Container $container - * @return array - */ - $container['admin/event/subscribers'] = function (Container $container): array { - return ($container['admin/config'] ->get('events.subscribers') ?? []); - }; - - /** - * Build an event dispatcher using admin config. - * - * @param Container $container - * @return EventDispatcher - */ - $container['admin/event/dispatcher'] = function (Container $container): EventDispatcher { - /** @var EventDispatcherBuilder $eventDispatcherBuilder */ - $eventDispatcherBuilder = $container['event/dispatcher/builder']; - return $eventDispatcherBuilder->build( - $container['admin/event/listeners'], - $container['admin/event/subscribers'] - ); - }; - } } diff --git a/packages/app/src/Charcoal/App/Facade/Event.php b/packages/app/src/Charcoal/App/Facade/Event.php index d66251f34..475140e5f 100644 --- a/packages/app/src/Charcoal/App/Facade/Event.php +++ b/packages/app/src/Charcoal/App/Facade/Event.php @@ -9,7 +9,7 @@ /** * Facade: Event Dispatcher * - * Alias for the 'admin/event/dispatcher' container service. + * Alias for the 'app/event/dispatcher' container service. * Provides access to the admin event dispatcher. * * @method static object dispatch(object $event) @@ -25,6 +25,6 @@ class Event extends Facade { protected static function getFacadeName(): string { - return 'admin/event/dispatcher'; + return 'app/event/dispatcher'; } } diff --git a/packages/event/src/Charcoal/Event/ServiceProvider/EventServiceProvider.php b/packages/event/src/Charcoal/Event/ServiceProvider/EventServiceProvider.php index 6f4c49e03..0776917f8 100644 --- a/packages/event/src/Charcoal/Event/ServiceProvider/EventServiceProvider.php +++ b/packages/event/src/Charcoal/Event/ServiceProvider/EventServiceProvider.php @@ -2,6 +2,7 @@ namespace Charcoal\Event\ServiceProvider; +use Charcoal\Event\EventDispatcher; use Charcoal\Event\EventDispatcherBuilder; use Charcoal\Event\EventListenerInterface; use Charcoal\Factory\FactoryInterface; @@ -83,5 +84,42 @@ public function register(Container $container) } ]); }; + + // The App event services + // ========================================================================== + + /** + * @param Container $container + * @return array + */ + $container['app/event/listeners'] = function (Container $container): array { + return ($container['admin/config']->get('events.listeners') ?? []); + }; + + /** + * Subscribers are classes that implements `\League\Event\ListenerSubscriber` + * It allows to subscribe many grouped listeners at once. + * + * @param Container $container + * @return array + */ + $container['app/event/subscribers'] = function (Container $container): array { + return ($container['admin/config'] ->get('events.subscribers') ?? []); + }; + + /** + * Build an event dispatcher using admin config. + * + * @param Container $container + * @return EventDispatcher + */ + $container['app/event/dispatcher'] = function (Container $container): EventDispatcher { + /** @var EventDispatcherBuilder $eventDispatcherBuilder */ + $eventDispatcherBuilder = $container['event/dispatcher/builder']; + return $eventDispatcherBuilder->build( + $container['app/event/listeners'], + $container['app/event/subscribers'] + ); + }; } }