From 6bf62b6ba68cc991052acf433d98efec8e0b27fd Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Fri, 10 Jan 2025 11:09:20 +0200 Subject: [PATCH 1/3] Issue #44: Added support for laminas/laminas-servicemanager:4.x Signed-off-by: alexmerlin --- README.md | 4 +- composer.json | 9 ++-- src/Logger.php | 25 ++++++++--- src/Manager/FilterPluginManager.php | 11 ++--- src/Manager/FormatterPluginManager.php | 11 ++--- src/Manager/ProcessorPluginManager.php | 11 ++--- src/Manager/WriterPluginManager.php | 11 ++--- src/Writer/AbstractWriter.php | 37 +++++++++++++--- test/LoggerServiceFactoryTest.php | 46 ++++++-------------- test/LoggerTest.php | 60 +++++++++++++++++++++++--- 10 files changed, 137 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 2b29e05..ac715cc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # dot-log ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-log) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/4.0.0) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/4.1.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/network) @@ -11,8 +11,6 @@ [![Build Static](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-log/graph/badge.svg?token=JX19KTBRCZ)](https://codecov.io/gh/dotkernel/dot-log) -[![SymfonyInsight](https://insight.symfony.com/projects/287e81e8-b4fb-4452-bd8f-4f12c0ab1f76/big.svg)](https://insight.symfony.com/projects/287e81e8-b4fb-4452-bd8f-4f12c0ab1f76) - ## Adding The Config Provider * Enter config/config.php diff --git a/composer.json b/composer.json index 200ae39..37c95be 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ ], "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "laminas/laminas-servicemanager": "^3.22", - "laminas/laminas-validator": "^2.64" + "laminas/laminas-servicemanager": "^4.0", + "laminas/laminas-validator": "^3.0" }, "require-dev": { + "laminas/laminas-coding-standard": "^3.0", "phpunit/phpunit": "^10.2", - "laminas/laminas-coding-standard": "^2.5", "vimeo/psalm": "^5.13" }, "autoload": { @@ -48,7 +48,8 @@ "scripts": { "check": [ "@cs-check", - "@test" + "@test", + "@static-analysis" ], "cs-check": "phpcs", "cs-fix": "phpcbf", diff --git a/src/Logger.php b/src/Logger.php index 59cc991..c4d88b4 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -17,6 +17,7 @@ use Laminas\ServiceManager\ServiceManager; use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\SplPriorityQueue; +use Psr\Container\ContainerExceptionInterface; use Traversable; use function array_reverse; @@ -133,6 +134,8 @@ class Logger implements LoggerInterface * - writers: array of writers to add to this logger * - exceptionhandler: if true register this logger as exceptionhandler * - errorhandler: if true register this logger as errorhandler + * + * @throws ContainerExceptionInterface */ public function __construct(?iterable $options = null) { @@ -210,7 +213,7 @@ public function __destruct() foreach ($this->writers as $writer) { try { $writer->shutdown(); - } catch (Exception $e) { + } catch (Exception) { } } } @@ -232,15 +235,17 @@ public function setWriterPluginManager(WriterPluginManager $writerPlugins): stat /** * Get writer instance * - * @psalm-suppress InvalidReturnStatement + * @throws ContainerExceptionInterface */ - public function writerPlugin(string $name, ?array $options = null): WriterInterface + public function writerPlugin(string $name, ?array $options = null): ?WriterInterface { - return $this->getWriterPluginManager()->get($name, $options); + return $this->getWriterPluginManager()?->build($name, $options); } /** * Add a writer to a logger + * + * @throws ContainerExceptionInterface */ public function addWriter(WriterInterface|string $writer, int $priority = 1, ?array $options = null): static { @@ -284,6 +289,9 @@ public function getProcessorPluginManager(): ?ProcessorPluginManager return $this->processorPlugins; } + /** + * @param class-string|ProcessorPluginManager $plugins + */ public function setProcessorPluginManager(string|ProcessorPluginManager $plugins): static { if (is_string($plugins)) { @@ -302,13 +310,16 @@ public function setProcessorPluginManager(string|ProcessorPluginManager $plugins } /** - * @psalm-suppress InvalidReturnStatement + * @throws ContainerExceptionInterface */ - public function processorPlugin(string $name, ?array $options = null): ProcessorInterface + public function processorPlugin(string $name, ?array $options = null): ?ProcessorInterface { - return $this->getProcessorPluginManager()->get($name, $options); + return $this->getProcessorPluginManager()?->build($name, $options); } + /** + * @throws ContainerExceptionInterface + */ public function addProcessor( ProcessorInterface|string $processor, int $priority = 1, diff --git a/src/Manager/FilterPluginManager.php b/src/Manager/FilterPluginManager.php index 27c90fd..eecc7fd 100644 --- a/src/Manager/FilterPluginManager.php +++ b/src/Manager/FilterPluginManager.php @@ -24,7 +24,7 @@ class FilterPluginManager extends AbstractPluginManager { /** @var string[] */ - protected $aliases = [ + protected array $aliases = [ 'priority' => Priority::class, 'regex' => Regex::class, 'suppress' => SuppressFilter::class, @@ -33,22 +33,19 @@ class FilterPluginManager extends AbstractPluginManager ]; /** @var string[]|callable[] */ - protected $factories = [ + protected array $factories = [ Priority::class => InvokableFactory::class, Regex::class => InvokableFactory::class, SuppressFilter::class => InvokableFactory::class, Validator::class => InvokableFactory::class, ]; - /** @var ?string */ - protected $instanceOf = FilterInterface::class; + protected string $instanceOf = FilterInterface::class; /** * Allow many filters of the same type - * - * @var bool */ - protected $sharedByDefault = false; + protected bool $sharedByDefault = false; /** * Validate the plugin is of the expected type. diff --git a/src/Manager/FormatterPluginManager.php b/src/Manager/FormatterPluginManager.php index f94a795..43a95ba 100644 --- a/src/Manager/FormatterPluginManager.php +++ b/src/Manager/FormatterPluginManager.php @@ -21,24 +21,21 @@ class FormatterPluginManager extends AbstractPluginManager { /** @var string[] */ - protected $aliases = [ + protected array $aliases = [ 'simple' => Simple::class, ]; /** @var string[]|callable[] */ - protected $factories = [ + protected array $factories = [ Simple::class => InvokableFactory::class, ]; - /** @var ?string */ - protected $instanceOf = FormatterInterface::class; + protected string $instanceOf = FormatterInterface::class; /** * Allow many formatters of the same type - * - * @var bool */ - protected $sharedByDefault = false; + protected bool $sharedByDefault = false; /** * Validate the plugin is of the expected type. diff --git a/src/Manager/ProcessorPluginManager.php b/src/Manager/ProcessorPluginManager.php index 0eab386..dd4b56c 100644 --- a/src/Manager/ProcessorPluginManager.php +++ b/src/Manager/ProcessorPluginManager.php @@ -24,7 +24,7 @@ class ProcessorPluginManager extends AbstractPluginManager { /** @var string[] */ - protected $aliases = [ + protected array $aliases = [ 'backtrace' => Backtrace::class, 'psrplaceholder' => PsrPlaceholder::class, 'referenceid' => ReferenceId::class, @@ -32,22 +32,19 @@ class ProcessorPluginManager extends AbstractPluginManager ]; /** @var string[]|callable[] */ - protected $factories = [ + protected array $factories = [ Backtrace::class => InvokableFactory::class, PsrPlaceholder::class => InvokableFactory::class, ReferenceId::class => InvokableFactory::class, RequestId::class => InvokableFactory::class, ]; - /** @var ?string */ - protected $instanceOf = ProcessorInterface::class; + protected string $instanceOf = ProcessorInterface::class; /** * Allow many processors of the same type - * - * @var bool */ - protected $sharedByDefault = false; + protected bool $sharedByDefault = false; /** * Validate the plugin is of the expected type. diff --git a/src/Manager/WriterPluginManager.php b/src/Manager/WriterPluginManager.php index adeb236..9d2c47d 100644 --- a/src/Manager/WriterPluginManager.php +++ b/src/Manager/WriterPluginManager.php @@ -22,7 +22,7 @@ class WriterPluginManager extends AbstractPluginManager { /** @var string[] */ - protected $aliases = [ + protected array $aliases = [ 'noop' => Noop::class, 'stream' => Stream::class, @@ -33,20 +33,17 @@ class WriterPluginManager extends AbstractPluginManager ]; /** @var string[]|callable[] */ - protected $factories = [ + protected array $factories = [ Noop::class => WriterFactory::class, Stream::class => WriterFactory::class, ]; - /** @var ?string */ - protected $instanceOf = WriterInterface::class; + protected string $instanceOf = WriterInterface::class; /** * Allow many writers of the same type - * - * @var bool */ - protected $sharedByDefault = false; + protected bool $sharedByDefault = false; /** * Validate the plugin is of the expected type. diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index e656057..18cfbb1 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -15,8 +15,10 @@ use Exception; use Laminas\ServiceManager\ServiceManager; use Laminas\Stdlib\ErrorHandler; +use Psr\Container\ContainerExceptionInterface; use Traversable; +use function class_exists; use function gettype; use function is_array; use function is_int; @@ -35,7 +37,7 @@ abstract class AbstractWriter implements WriterInterface protected array $filters = []; - protected FormatterInterface $formatter; + protected ?FormatterInterface $formatter = null; /** * Use Laminas\Stdlib\ErrorHandler to report errors during calls to write @@ -53,6 +55,8 @@ abstract class AbstractWriter implements WriterInterface * Set options for a writer. Accepted options are: * - filters: array of filters to add to this filter * - formatter: formatter for this writer + * + * @throws ContainerExceptionInterface */ public function __construct(?iterable $options = null) { @@ -99,7 +103,13 @@ public function __construct(?iterable $options = null) throw new InvalidArgumentException('Options must contain a name for the formatter'); } $formatterOptions = $formatter['options'] ?? null; - $this->setFormatter($formatter['name'], $formatterOptions); + + $formatterClass = $formatter['name']; + if (class_exists($formatterClass)) { + $formatterClass = new $formatterClass(); + } + + $this->setFormatter($formatterClass, $formatterOptions); } } } @@ -107,6 +117,8 @@ public function __construct(?iterable $options = null) /** * Add a filter specific to this writer. + * + * @throws ContainerExceptionInterface */ public function addFilter(int|string|FilterInterface $filter, ?array $options = null): WriterInterface { @@ -138,6 +150,9 @@ public function getFilterPluginManager(): ?FilterPluginManager return $this->filterPlugins; } + /** + * @param class-string|FilterPluginManager $plugins + */ public function setFilterPluginManager(string|FilterPluginManager $plugins): static { if (is_string($plugins)) { @@ -155,9 +170,12 @@ public function setFilterPluginManager(string|FilterPluginManager $plugins): sta return $this; } + /** + * @throws ContainerExceptionInterface + */ public function filterPlugin(string $name, ?array $options = null): mixed { - return $this->getFilterPluginManager()->get($name, $options); + return $this->getFilterPluginManager()?->build($name, $options); } public function getFormatterPluginManager(): ?FormatterPluginManager @@ -168,6 +186,9 @@ public function getFormatterPluginManager(): ?FormatterPluginManager return $this->formatterPlugins; } + /** + * @param class-string|FormatterPluginManager $plugins + */ public function setFormatterPluginManager(string|FormatterPluginManager $plugins): static { if (is_string($plugins)) { @@ -187,9 +208,12 @@ public function setFormatterPluginManager(string|FormatterPluginManager $plugins return $this; } + /** + * @throws ContainerExceptionInterface + */ public function formatterPlugin(string $name, ?array $options = null): mixed { - return $this->getFormatterPluginManager()->get($name, $options); + return $this->getFormatterPluginManager()?->build($name, $options); } /** @@ -229,6 +253,9 @@ public function write(array $event): void } } + /** + * @throws ContainerExceptionInterface + */ public function setFormatter(FormatterInterface|string $formatter, ?array $options = null): WriterInterface { if (is_string($formatter)) { @@ -247,7 +274,7 @@ public function setFormatter(FormatterInterface|string $formatter, ?array $optio return $this; } - protected function getFormatter(): FormatterInterface + protected function getFormatter(): ?FormatterInterface { return $this->formatter; } diff --git a/test/LoggerServiceFactoryTest.php b/test/LoggerServiceFactoryTest.php index 294417f..fc7986c 100644 --- a/test/LoggerServiceFactoryTest.php +++ b/test/LoggerServiceFactoryTest.php @@ -8,16 +8,13 @@ use Dot\Log\LoggerServiceFactory; use Dot\Log\Manager\ProcessorPluginManager; use Dot\Log\Manager\WriterPluginManager; -use Dot\Log\Processor\ProcessorInterface; +use Dot\Log\Processor\PsrPlaceholder; use Dot\Log\Writer\Noop; -use Dot\Log\Writer\WriterInterface; -use Laminas\ServiceManager\Config; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\ServiceManager\ServiceManager; use Laminas\Stdlib\ArrayObject; -use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -34,8 +31,7 @@ class LoggerServiceFactoryTest extends TestCase */ protected function setUp(): void { - $this->serviceManager = new ServiceManager(); - $config = new Config([ + $this->serviceManager = new ServiceManager([ 'aliases' => [ 'Dot\Log' => Logger::class, ], @@ -48,7 +44,6 @@ protected function setUp(): void ], ], ]); - $config->configureServiceManager($this->serviceManager); } public static function providerValidLoggerService(): array @@ -93,15 +88,12 @@ public function testInvalidLoggerService(string $service): void /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface - * @throws Exception */ public function testWillInjectWriterPluginManagerIfAvailable(): void { - $writers = new WriterPluginManager(new ServiceManager()); - $mockWriter = $this->createMock(WriterInterface::class); - $writers->setService('CustomWriter', $mockWriter); + $writers = new WriterPluginManager(new ServiceManager()); - $config = new Config([ + $services = new ServiceManager([ 'factories' => [ Logger::class => LoggerServiceFactory::class, ], @@ -109,33 +101,27 @@ public function testWillInjectWriterPluginManagerIfAvailable(): void 'LogWriterManager' => $writers, 'config' => [ 'log' => [ - 'writers' => [['name' => 'CustomWriter', 'priority' => 1]], + 'writers' => [['name' => 'noop', 'priority' => 1]], ], ], ], ]); - $services = new ServiceManager(); - $config->configureServiceManager($services); $log = $services->get(Logger::class); $logWriters = $log->getWriters(); self::assertEquals(1, count($logWriters)); - $writer = $logWriters->current(); - self::assertSame($mockWriter, $writer); + $this->assertInstanceOf(Noop::class, $logWriters->current()); } /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface - * @throws Exception */ public function testWillInjectProcessorPluginManagerIfAvailable(): void { - $processors = new ProcessorPluginManager(new ServiceManager()); - $mockProcessor = $this->createMock(ProcessorInterface::class); - $processors->setService('CustomProcessor', $mockProcessor); + $processors = new ProcessorPluginManager(new ServiceManager()); - $config = new Config([ + $services = new ServiceManager([ 'factories' => [ Logger::class => LoggerServiceFactory::class, ], @@ -144,19 +130,16 @@ public function testWillInjectProcessorPluginManagerIfAvailable(): void 'config' => [ 'log' => [ 'writers' => [['name' => Noop::class, 'priority' => 1]], - 'processors' => [['name' => 'CustomProcessor', 'priority' => 1]], + 'processors' => [['name' => 'psrplaceholder', 'priority' => 1]], ], ], ], ]); - $services = new ServiceManager(); - $config->configureServiceManager($services); $log = $services->get(Logger::class); $logProcessors = $log->getProcessors(); self::assertEquals(1, count($logProcessors)); - $processor = $logProcessors->current(); - self::assertSame($mockProcessor, $processor); + $this->assertInstanceOf(PsrPlaceholder::class, $logProcessors->current()); } /** @@ -166,7 +149,7 @@ public function testWillInjectProcessorPluginManagerIfAvailable(): void */ public function testWritersValue(mixed $writers, int $count): void { - $config = new Config([ + $services = new ServiceManager([ 'factories' => [ Logger::class => LoggerServiceFactory::class, ], @@ -178,10 +161,7 @@ public function testWritersValue(mixed $writers, int $count): void ], ], ]); - $services = new ServiceManager(); - $config->configureServiceManager($services); - /** @var Logger $log */ $log = $services->get(Logger::class); self::assertCount($count, $log->getWriters()); } @@ -205,7 +185,7 @@ public static function dataWritersValues(): array */ public function testInvalidWriterConfig(mixed $value, string $type): void { - $config = new Config([ + $services = new ServiceManager([ 'factories' => [ Logger::class => LoggerServiceFactory::class, ], @@ -219,8 +199,6 @@ public function testInvalidWriterConfig(mixed $value, string $type): void ], ], ]); - $services = new ServiceManager(); - $config->configureServiceManager($services); self::expectException(ServiceNotCreatedException::class); self::expectExceptionMessage( diff --git a/test/LoggerTest.php b/test/LoggerTest.php index 408b2c8..b77337f 100644 --- a/test/LoggerTest.php +++ b/test/LoggerTest.php @@ -18,6 +18,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\Stdlib\SplPriorityQueue; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerExceptionInterface; use function count; use function set_exception_handler; @@ -38,11 +39,14 @@ public function testUsesWriterPluginManagerByDefault(): void $this->assertInstanceOf(WriterPluginManager::class, $this->subject->getWriterPluginManager()); } + /** + * @throws ContainerExceptionInterface + */ public function testPassingShortNameToPluginReturnsWriterByThatName(): void { $this->expectException(ServiceNotFoundException::class); $this->expectExceptionMessage( - 'A plugin by the name "mock" was not found in the plugin manager Dot\Log\Manager\WriterPluginManager' + 'Unable to resolve service "mock" to a factory; are you certain you provided it during configuration?' ); $this->subject->writerPlugin('mock'); } @@ -54,6 +58,9 @@ public function testEmptyWriter(): void $this->subject->log(Logger::INFO, 'test'); } + /** + * @throws ContainerExceptionInterface + */ public function testSetWriters(): void { $writer = $this->subject->writerPlugin('null'); @@ -67,6 +74,9 @@ public function testSetWriters(): void $this->assertInstanceOf(Noop::class, $writer); } + /** + * @throws ContainerExceptionInterface + */ public function testAddWriterWithPriority(): void { $writer = $this->subject->writerPlugin('null'); @@ -78,6 +88,9 @@ public function testAddWriterWithPriority(): void $this->assertInstanceOf(Noop::class, $writer); } + /** + * @throws ContainerExceptionInterface + */ public function testAddWithSamePriority(): void { $writer1 = $this->subject->writerPlugin('null'); @@ -93,26 +106,35 @@ public function testAddWithSamePriority(): void $this->assertInstanceOf(Noop::class, $writer); } + /** + * @throws ContainerExceptionInterface + */ public function testLogging(): void { $writer = new Mock(); $this->subject->addWriter($writer); $this->subject->log(Logger::INFO, 'tottakai'); - $this->assertEquals(count($writer->events), 1); + $this->assertEquals(1, count($writer->events)); $this->assertStringContainsString('tottakai', $writer->events[0]['message']); } + /** + * @throws ContainerExceptionInterface + */ public function testLoggingArray(): void { $writer = new Mock(); $this->subject->addWriter($writer); $this->subject->log(Logger::INFO, ['test']); - $this->assertEquals(count($writer->events), 1); + $this->assertEquals(1, count($writer->events)); $this->assertStringContainsString('test', $writer->events[0]['message']); } + /** + * @throws ContainerExceptionInterface + */ public function testAddFilter(): void { $writer = new Mock(); @@ -121,7 +143,7 @@ public function testAddFilter(): void $this->subject->addWriter($writer); $this->subject->log(Logger::INFO, ['test']); - $this->assertEquals(count($filter->events), 1); + $this->assertEquals(1, count($filter->events)); $this->assertStringContainsString('test', $filter->events[0]['message']); } @@ -135,6 +157,7 @@ public static function provideTestFilters(): array /** * @dataProvider provideTestFilters + * @throws ContainerExceptionInterface */ public function testAddFilterByNameWithParams(string $filter, array $options): void { @@ -143,7 +166,7 @@ public function testAddFilterByNameWithParams(string $filter, array $options): v $this->subject->addWriter($writer); $this->subject->log(Logger::INFO, '123'); - $this->assertEquals(count($writer->events), 1); + $this->assertEquals(1, count($writer->events)); $this->assertStringContainsString('123', $writer->events[0]['message']); } @@ -158,6 +181,7 @@ public static function provideAttributes(): array /** * @dataProvider provideAttributes + * @throws ContainerExceptionInterface */ public function testLoggingCustomAttributesForUserContext(array|ArrayObject $extra): void { @@ -165,11 +189,14 @@ public function testLoggingCustomAttributesForUserContext(array|ArrayObject $ext $this->subject->addWriter($writer); $this->subject->log(Logger::ERR, 'tottakai', $extra); - $this->assertEquals(count($writer->events), 1); + $this->assertEquals(1, count($writer->events)); $this->assertIsArray($writer->events[0]['extra']); $this->assertEquals(count($writer->events[0]['extra']), count($extra)); } + /** + * @throws ContainerExceptionInterface + */ public function testRegisterErrorHandler(): void { $writer = new Mock(); @@ -190,6 +217,9 @@ public function testRegisterErrorHandler(): void $this->assertEquals('Undefined variable $test', $writer->events[0]['message']); } + /** + * @throws ContainerExceptionInterface + */ public function testOptionsWithMock(): void { $options = [ @@ -207,6 +237,9 @@ public function testOptionsWithMock(): void $this->assertInstanceOf(Noop::class, $writers[0]); } + /** + * @throws ContainerExceptionInterface + */ public function testOptionsWithWriterOptions(): void { $options = [ @@ -229,6 +262,9 @@ public function testOptionsWithWriterOptions(): void $this->assertEquals('foo', $writers[0]->getLogSeparator()); } + /** + * @throws ContainerExceptionInterface + */ public function testOptionsWithMockAndProcessor(): void { $options = [ @@ -251,6 +287,9 @@ public function testOptionsWithMockAndProcessor(): void $this->assertInstanceOf(RequestId::class, $processors[0]); } + /** + * @throws ContainerExceptionInterface + */ public function testAddProcessor(): void { $processor = new Backtrace(); @@ -260,6 +299,9 @@ public function testAddProcessor(): void $this->assertEquals($processor, $processors[0]); } + /** + * @throws ContainerExceptionInterface + */ public function testAddProcessorByName(): void { $this->subject->addProcessor('backtrace'); @@ -272,6 +314,9 @@ public function testAddProcessorByName(): void $this->subject->log(Logger::ERR, 'foo'); } + /** + * @throws ContainerExceptionInterface + */ public function testExceptionHandler(): void { $writer = new Mock(); @@ -292,7 +337,7 @@ public function testExceptionHandler(): void // call the exception handler $exceptionHandler(new Exception('error', 200, new Exception('previos', 100))); - $exceptionHandler(new ErrorException('user notice', 1000, E_USER_NOTICE, __FILE__, __LINE__)); + $exceptionHandler(new ErrorException('user notice', 1_000, E_USER_NOTICE, __FILE__, __LINE__)); // check logged messages $expectedEvents = [ @@ -312,6 +357,7 @@ public function testExceptionHandler(): void /** * @group Laminas-7238 + * @throws ContainerExceptionInterface */ public function testCatchExceptionNotValidPriority(): void { From 621f8b95fdd06401fd61f2a7be0a8608619acee4 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Thu, 16 Jan 2025 15:43:51 +0200 Subject: [PATCH 2/3] Added support for PHP 8.4 Signed-off-by: alexmerlin --- .laminas-ci.json | 6 ++++++ composer.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .laminas-ci.json diff --git a/.laminas-ci.json b/.laminas-ci.json new file mode 100644 index 0000000..82cd446 --- /dev/null +++ b/.laminas-ci.json @@ -0,0 +1,6 @@ +{ + "ignore_php_platform_requirements": { + "8.4": true + }, + "backwardCompatibilityCheck": true +} diff --git a/composer.json b/composer.json index 37c95be..47372fd 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "laminas/laminas-servicemanager": "^4.0", "laminas/laminas-validator": "^3.0" }, From 7af9d88dbd37528935eb35c569ddd384ee4996ce Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Thu, 16 Jan 2025 16:24:37 +0200 Subject: [PATCH 3/3] Grab contents of #63 Signed-off-by: alexmerlin --- README.md | 4 ++-- composer.json | 4 ++-- docs/book/v3/formatting-messages.md | 8 +++++--- docs/book/v3/overview.md | 2 -- docs/book/v4/formatting-messages.md | 8 +++++--- docs/book/v4/overview.md | 2 ++ mkdocs.yml | 2 +- src/Logger.php | 2 -- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ac715cc..2ef25fa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ * Enter config/config.php * If there is no entry for the config provider below, add it: `\Dot\Log\ConfigProvider::class` -* Make sure it is added before with the Application-Specific components, eg.: `\Frontend\App\ConfigProvider.php`, `\Admin\App\ConfigProvider::class`, `MyProject\ConfigProvider::class` , etc. +* Make sure it is added before with the Application-Specific components, e.g.: `\Frontend\App\ConfigProvider.php`, `\Admin\App\ConfigProvider::class`, `MyProject\ConfigProvider::class` , etc. * Open the `Dot\Log\ConfigProvider` * In the dependencies section you will see an abstract factory (`LoggerAbstractServiceFactory::class`) * This class responds to "selectors" instead of class names @@ -160,7 +160,7 @@ As in the writer configuration, the developer can optionally use keys for associ IMPORTANT NOTE: the operator for more important messages is <=, this is because the number representation is smaller for a more important message type. -The filter added on the first writer is equal to not setting a filter, but it was been added to illustrate how to explicitly allow all messages. +The filter added on the first writer is equal to not setting a filter, but it has been added to illustrate how to explicitly allow all messages. It was added opposite to the others just to demonstrate the other operator is also an option. diff --git a/composer.json b/composer.json index 47372fd..f9a8f45 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dotkernel/dot-log", "type": "library", - "description": "DotKernel log component extending and customizing laminas-log", + "description": "Dotkernel log component extending and customizing laminas-log", "license": "MIT", "homepage": "https://github.com/dotkernel/dot-log", "keywords": [ @@ -14,7 +14,7 @@ ], "authors": [ { - "name": "DotKernel Team", + "name": "Dotkernel Team", "email": "team@dotkernel.com" } ], diff --git a/docs/book/v3/formatting-messages.md b/docs/book/v3/formatting-messages.md index c0b028a..d995e0c 100644 --- a/docs/book/v3/formatting-messages.md +++ b/docs/book/v3/formatting-messages.md @@ -9,6 +9,8 @@ The formatter accepts following parameters: The following snippet formats the message as JSON data: - 'formatter' => [ - 'name' => \Laminas\Log\Formatter\Json::class, - ], +```php +'formatter' => [ + 'name' => \Laminas\Log\Formatter\Json::class, +], +``` diff --git a/docs/book/v3/overview.md b/docs/book/v3/overview.md index 975a06d..829c29b 100644 --- a/docs/book/v3/overview.md +++ b/docs/book/v3/overview.md @@ -1,5 +1,3 @@ # Overview > dot-log is a wrapper on top of [laminas-log](https://github.com/laminas/laminas-log) -> -> ![OSS Lifecycle](https://img.shields.io/osslifecycle/laminas/laminas-log) diff --git a/docs/book/v4/formatting-messages.md b/docs/book/v4/formatting-messages.md index 4604825..5d1c4bb 100644 --- a/docs/book/v4/formatting-messages.md +++ b/docs/book/v4/formatting-messages.md @@ -9,6 +9,8 @@ The formatter accepts following parameters: The following snippet formats the message as JSON data: - 'formatter' => [ - 'name' => \Dot\Log\Formatter\Json::class, - ], +```php +'formatter' => [ + 'name' => \Dot\Log\Formatter\Json::class, +], +``` diff --git a/docs/book/v4/overview.md b/docs/book/v4/overview.md index 89f6888..615aaf0 100644 --- a/docs/book/v4/overview.md +++ b/docs/book/v4/overview.md @@ -1,3 +1,5 @@ # Overview Robust, composite logger with filtering, formatting, and PSR-3 support. + +> dot-log is a wrapper on top of [laminas-log](https://github.com/laminas/laminas-log) diff --git a/mkdocs.yml b/mkdocs.yml index 49551bc..5638928 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -27,7 +27,7 @@ nav: - "Example with formatter": v3/example-with-formatter.md - "Usage": v3/usage.md site_name: dot-log -site_description: "DotKernel log component" +site_description: "Dotkernel log component" repo_url: "https://github.com/dotkernel/dot-log" plugins: - search diff --git a/src/Logger.php b/src/Logger.php index c4d88b4..2a92990 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -46,7 +46,6 @@ use const E_NOTICE; use const E_PARSE; use const E_RECOVERABLE_ERROR; -use const E_STRICT; use const E_USER_DEPRECATED; use const E_USER_ERROR; use const E_USER_NOTICE; @@ -85,7 +84,6 @@ class Logger implements LoggerInterface E_PARSE => self::ERR, E_COMPILE_ERROR => self::ERR, E_COMPILE_WARNING => self::ERR, - E_STRICT => self::DEBUG, E_DEPRECATED => self::DEBUG, E_USER_DEPRECATED => self::DEBUG, ];