remove has
This commit is contained in:
@@ -18,28 +18,27 @@ trait Behaviour
|
|||||||
|
|
||||||
private static function addLoggerBehaviour(Container $container): void
|
private static function addLoggerBehaviour(Container $container): void
|
||||||
{
|
{
|
||||||
|
self::addLoggerEnvironment($container);
|
||||||
self::addLoggerHandler($container);
|
self::addLoggerHandler($container);
|
||||||
self::addLogger($container);
|
self::addLogger($container);
|
||||||
self::addLoggerSubscription($container);
|
self::addLoggerSubscription($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function addLoggerEnvironment(Container $container): void
|
||||||
|
{
|
||||||
|
static::getEnvironment($container)->required('APPLICATION_NAME');
|
||||||
|
}
|
||||||
|
|
||||||
private static function addLoggerHandler(Container $container): void
|
private static function addLoggerHandler(Container $container): void
|
||||||
{
|
{
|
||||||
if ($container->has(Handler::class)) {
|
|
||||||
return; }
|
|
||||||
|
|
||||||
$container->addShared(Handler::class)
|
$container->addShared(Handler::class)
|
||||||
->addArgument(\Potter\Console\Logger::class);
|
->addArgument(\Potter\Console\Logger::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addLoggerSubscription(Container $container): void
|
private static function addLoggerSubscription(Container $container): void
|
||||||
{
|
{
|
||||||
if (!static::hasDispatcher($container)) {
|
|
||||||
return; }
|
|
||||||
$dispatcher = static::getDispatcher($container);
|
$dispatcher = static::getDispatcher($container);
|
||||||
|
|
||||||
static::getEnvironment($container)->required('APPLICATION_NAME');
|
|
||||||
|
|
||||||
$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)) {
|
||||||
@@ -67,10 +66,6 @@ trait Behaviour
|
|||||||
return [$container->get(Handler::class)];
|
return [$container->get(Handler::class)];
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract private static function hasDispatcher(Container $container): bool;
|
|
||||||
|
|
||||||
abstract private static function hasEnvironment(Container $container): bool;
|
|
||||||
|
|
||||||
private static function hasLogger(Container $container): bool
|
private static function hasLogger(Container $container): bool
|
||||||
{
|
{
|
||||||
return $container->has(Logger::class);
|
return $container->has(Logger::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user