Compare commits
3 Commits
23b22556e7
...
6bb1d8fc8f
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bb1d8fc8f | |||
| aacb6a5462 | |||
| a8d0667c50 |
@@ -13,16 +13,25 @@ trait Behaviour
|
|||||||
|
|
||||||
private static function addLogger(Container $container): void
|
private static function addLogger(Container $container): void
|
||||||
{
|
{
|
||||||
self::addConsoleBehaviour($container);
|
|
||||||
self::addLoggerHandler($container);
|
|
||||||
$loggerHandlers = self::getLoggerHandlers($container);
|
|
||||||
$container->addShared(Logger::class)
|
$container->addShared(Logger::class)
|
||||||
->addArgument(static::class)
|
->addArgument(static::class)
|
||||||
->addArgument($loggerHandlers);
|
->addArgument(self::getLoggerHandlers($container));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addLoggerBehaviour(Container $container): void
|
private static function addLoggerBehaviour(Container $container): void
|
||||||
{
|
{
|
||||||
|
if (static::hasDispatcher($container)) {
|
||||||
|
static::getDispatcher($container)
|
||||||
|
->subscribeTo('applicationStart', function (Event $event) {
|
||||||
|
self::_addLoggerBehaviour($event->getArgument('container')); });
|
||||||
|
} else {
|
||||||
|
self::_addLoggerBehaviour($container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function _addLoggerBehaviour(Container $container): void
|
||||||
|
{
|
||||||
|
self::addLoggerHandler($container);
|
||||||
self::addLogger($container);
|
self::addLogger($container);
|
||||||
self::addLoggerSubscription($container);
|
self::addLoggerSubscription($container);
|
||||||
}
|
}
|
||||||
@@ -30,8 +39,8 @@ trait Behaviour
|
|||||||
private static function addLoggerHandler(Container $container): void
|
private static function addLoggerHandler(Container $container): void
|
||||||
{
|
{
|
||||||
if ($container->has(Handler::class)) {
|
if ($container->has(Handler::class)) {
|
||||||
return;
|
return; }
|
||||||
}
|
|
||||||
$container->addShared(Handler::class)
|
$container->addShared(Handler::class)
|
||||||
->addArgument(\Potter\Console\Logger::class);
|
->addArgument(\Potter\Console\Logger::class);
|
||||||
}
|
}
|
||||||
@@ -39,23 +48,20 @@ trait Behaviour
|
|||||||
private static function addLoggerSubscription(Container $container): void
|
private static function addLoggerSubscription(Container $container): void
|
||||||
{
|
{
|
||||||
if (!static::hasDispatcher($container)) {
|
if (!static::hasDispatcher($container)) {
|
||||||
return;
|
return; }
|
||||||
}
|
|
||||||
$dispatcher = static::getDispatcher($container);
|
$dispatcher = static::getDispatcher($container);
|
||||||
|
|
||||||
$dispatcher->subscribeTo('applicationStart', function (Event $event) {
|
$dispatcher->subscribeTo('applicationStart', function (Event $event) {
|
||||||
$container = $event->getArgument('container');
|
$container = $event->getArgument('container');
|
||||||
if (!self::hasLogger($container)) {
|
if (!self::hasLogger($container)) {
|
||||||
return; }
|
return; }
|
||||||
self::getLogger($container)->notice('Application start.');
|
self::getLogger($container)->notice('Application start.'); });
|
||||||
});
|
|
||||||
|
|
||||||
$dispatcher->subscribeTo('applicationStop', function (Event $event) {
|
$dispatcher->subscribeTo('applicationStop', function (Event $event) {
|
||||||
$container = $event->getArgument('container');
|
$container = $event->getArgument('container');
|
||||||
if (!self::hasLogger($container)) {
|
if (!self::hasLogger($container)) {
|
||||||
return; }
|
return; }
|
||||||
self::getLogger($container)->notice('Application stop.');
|
self::getLogger($container)->notice('Application stop.'); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract private static function getDispatcher(Container $container): \Potter\Event\Dispatcher;
|
abstract private static function getDispatcher(Container $container): \Potter\Event\Dispatcher;
|
||||||
|
|||||||
Reference in New Issue
Block a user