Compare commits
4 Commits
3872996fa7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bd2fe57682 | |||
| b67436c44f | |||
| 18deba3b66 | |||
| 713ba001e5 |
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
"phpoption/phpoption": ">=1.9.5",
|
"phpoption/phpoption": ">=1.9.5",
|
||||||
"potter/console": ">=0.0.1",
|
"potter/console": ">=0.0.1",
|
||||||
"potter/container": ">=0.0.1",
|
"potter/container": ">=0.0.1",
|
||||||
"potter/event": ">=0.0.3",
|
"potter/event": ">=0.0.1",
|
||||||
"psr/log": ">=3.0.2",
|
"psr/log": ">=3.0.2",
|
||||||
"symfony/polyfill-ctype": ">=1.37.0",
|
"symfony/polyfill-ctype": ">=1.37.0",
|
||||||
"symfony/polyfill-mbstring": ">=1.38.2",
|
"symfony/polyfill-mbstring": ">=1.38.2",
|
||||||
|
|||||||
@@ -18,39 +18,38 @@ 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) {
|
||||||
|
self::getLogger(
|
||||||
|
$event->getArgument('container'))
|
||||||
|
->notice('Application start: ' . $_ENV['APPLICATION_NAME']); });
|
||||||
|
|
||||||
$dispatcher->subscribeTo('applicationStart', function (Event $event) {
|
$dispatcher->subscribeTo('applicationStop',
|
||||||
$container = $event->getArgument('container');
|
function (Event $event) {
|
||||||
if (!self::hasLogger($container)) {
|
self::getLogger(
|
||||||
return; }
|
$event->getArgument('container'))
|
||||||
self::getLogger($container)->notice('Application start: ' . $_ENV['APPLICATION_NAME']); });
|
->notice('Application stop: ' . $_ENV['APPLICATION_NAME']); });
|
||||||
|
|
||||||
$dispatcher->subscribeTo('applicationStop', function (Event $event) {
|
|
||||||
$container = $event->getArgument('container');
|
|
||||||
if (!self::hasLogger($container)) {
|
|
||||||
return; }
|
|
||||||
self::getLogger($container)->notice('Application stop: ' . $_ENV['APPLICATION_NAME']); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract private static function getDispatcher(Container $container): \Potter\Event\Dispatcher;
|
abstract private static function getDispatcher(Container $container): \Potter\Event\Dispatcher;
|
||||||
@@ -66,13 +65,4 @@ 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
|
|
||||||
{
|
|
||||||
return $container->has(Logger::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user