Skip to content

Commit

Permalink
fix(event): rename event services container keys to be prefixed with …
Browse files Browse the repository at this point in the history
…`app/`
  • Loading branch information
JoelAlphonso committed Nov 8, 2022
1 parent e51eff5 commit 71430ec
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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']
);
};
}
}
4 changes: 2 additions & 2 deletions packages/app/src/Charcoal/App/Facade/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,6 +25,6 @@ class Event extends Facade
{
protected static function getFacadeName(): string
{
return 'admin/event/dispatcher';
return 'app/event/dispatcher';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Charcoal\Event\ServiceProvider;

use Charcoal\Event\EventDispatcher;
use Charcoal\Event\EventDispatcherBuilder;
use Charcoal\Event\EventListenerInterface;
use Charcoal\Factory\FactoryInterface;
Expand Down Expand Up @@ -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']
);
};
}
}

0 comments on commit 71430ec

Please sign in to comment.