Compare commits

...

15 Commits

Author SHA1 Message Date
jay b67436c44f remove has 2026-08-12 17:39:13 -04:00
jay 18deba3b66 update version 2026-08-12 16:18:44 -04:00
jay 713ba001e5 remove has 2026-08-12 16:14:18 -04:00
jay 3872996fa7 use APPLICATION_NAME 2026-08-12 15:49:35 -04:00
jay fecc73408a require vlucas/phpdotenv 2026-08-12 15:49:25 -04:00
jay 03a338b98e 0.0.1 2026-08-12 14:55:59 -04:00
jay 6bb1d8fc8f event driven 2026-08-12 14:48:03 -04:00
jay aacb6a5462 spacing 2026-08-12 14:39:36 -04:00
jay a8d0667c50 remove method call 2026-08-12 14:36:35 -04:00
jay 23b22556e7 add addLoggerSubscription method 2026-08-12 14:31:33 -04:00
jay e00189b590 require potter/event 2026-08-12 14:31:12 -04:00
jay ee140d7e6d add getLogger method 2026-08-12 13:39:53 -04:00
jay 28fa24f67e require potter/console 2026-08-10 15:22:48 -04:00
jay 0fe00bf368 0.0.1 2026-08-10 15:22:39 -04:00
jay e1aef5107c delete 2026-08-10 15:07:48 -04:00
3 changed files with 43 additions and 11 deletions
-2
View File
@@ -1,2 +0,0 @@
# Logger
+9 -1
View File
@@ -15,8 +15,16 @@
],
"minimum-stability": "stable",
"require": {
"graham-campbell/result-type": ">=1.1.4",
"monolog/monolog": ">=3.10.0",
"phpoption/phpoption": ">=1.9.5",
"potter/console": ">=0.0.1",
"potter/container": ">=0.0.1",
"psr/log": ">=3.0.2"
"potter/event": ">=0.0.1",
"psr/log": ">=3.0.2",
"symfony/polyfill-ctype": ">=1.37.0",
"symfony/polyfill-mbstring": ">=1.38.2",
"symfony/polyfill-php80": ">=1.37.0",
"vlucas/phpdotenv": ">=5.6.4"
}
}
+33 -7
View File
@@ -5,15 +5,12 @@ declare(strict_types=1);
namespace Potter\Logger;
use \Potter\Container;
use \Potter\Event\Event;
trait Behaviour
{
abstract private static function addConsoleBehaviour(Container $container): void;
private static function addLogger(Container $container): void
{
self::addConsoleBehaviour($container);
self::addLoggerHandlers($container);
$container->addShared(Logger::class)
->addArgument(static::class)
->addArgument(self::getLoggerHandlers($container));
@@ -21,18 +18,47 @@ trait Behaviour
private static function addLoggerBehaviour(Container $container): void
{
self::addLoggerEnvironment($container);
self::addLoggerHandler($container);
self::addLogger($container);
self::addLoggerSubscription($container);
}
private static function addLoggerHandlers(Container $container): void
private static function addLoggerEnvironment(Container $container): void
{
static::getEnvironment($container)->required('APPLICATION_NAME');
}
private static function addLoggerHandler(Container $container): void
{
$container->addShared(Handler::class)
->addArgument(self::getLoggerHandlers($container));
->addArgument(\Potter\Console\Logger::class);
}
private static function addLoggerSubscription(Container $container): void
{
$dispatcher = static::getDispatcher($container);
$dispatcher->subscribeTo('applicationStart', function (Event $event) {
$container = $event->getArgument('container');
self::getLogger($container)->notice('Application start: ' . $_ENV['APPLICATION_NAME']); });
$dispatcher->subscribeTo('applicationStop', function (Event $event) {
$container = $event->getArgument('container');
self::getLogger($container)->notice('Application stop: ' . $_ENV['APPLICATION_NAME']); });
}
abstract private static function getDispatcher(Container $container): \Potter\Event\Dispatcher;
abstract private static function getEnvironment(Container $container): \Dotenv\Dotenv;
private static function getLogger(Container $container): Logger
{
return $container->get(Logger::class);
}
private static function getLoggerHandlers(Container $container): array
{
return [$container->get(Handler::class)];
}
}