Skip to content

Commit

Permalink
Merge pull request #64 from dotkernel/issue-44
Browse files Browse the repository at this point in the history
Issue #44: Added support for `laminas/laminas-servicemanager:4.x`
  • Loading branch information
alexmerlin authored Jan 17, 2025
2 parents e54eedf + 7af9d88 commit 893bff9
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 104 deletions.
6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -11,14 +11,12 @@
[![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
* 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
Expand Down Expand Up @@ -162,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.

Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -14,18 +14,18 @@
],
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "[email protected]"
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"laminas/laminas-servicemanager": "^3.22",
"laminas/laminas-validator": "^2.64"
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"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": {
Expand All @@ -48,7 +48,8 @@
"scripts": {
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
Expand Down
8 changes: 5 additions & 3 deletions docs/book/v3/formatting-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
```
2 changes: 0 additions & 2 deletions docs/book/v3/overview.md
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 5 additions & 3 deletions docs/book/v4/formatting-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
```
2 changes: 2 additions & 0 deletions docs/book/v4/overview.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 18 additions & 9 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,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;
Expand Down Expand Up @@ -84,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,
];
Expand Down Expand Up @@ -133,6 +132,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)
{
Expand Down Expand Up @@ -210,7 +211,7 @@ public function __destruct()
foreach ($this->writers as $writer) {
try {
$writer->shutdown();
} catch (Exception $e) {
} catch (Exception) {
}
}
}
Expand All @@ -232,15 +233,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
{
Expand Down Expand Up @@ -284,6 +287,9 @@ public function getProcessorPluginManager(): ?ProcessorPluginManager
return $this->processorPlugins;
}

/**
* @param class-string|ProcessorPluginManager $plugins
*/
public function setProcessorPluginManager(string|ProcessorPluginManager $plugins): static
{
if (is_string($plugins)) {
Expand All @@ -302,13 +308,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,
Expand Down
11 changes: 4 additions & 7 deletions src/Manager/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class FilterPluginManager extends AbstractPluginManager
{
/** @var string[] */
protected $aliases = [
protected array $aliases = [
'priority' => Priority::class,
'regex' => Regex::class,
'suppress' => SuppressFilter::class,
Expand All @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions src/Manager/FormatterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions src/Manager/ProcessorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,27 @@
class ProcessorPluginManager extends AbstractPluginManager
{
/** @var string[] */
protected $aliases = [
protected array $aliases = [
'backtrace' => Backtrace::class,
'psrplaceholder' => PsrPlaceholder::class,
'referenceid' => ReferenceId::class,
'requestid' => RequestId::class,
];

/** @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.
Expand Down
11 changes: 4 additions & 7 deletions src/Manager/WriterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class WriterPluginManager extends AbstractPluginManager
{
/** @var string[] */
protected $aliases = [
protected array $aliases = [
'noop' => Noop::class,
'stream' => Stream::class,

Expand All @@ -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.
Expand Down
Loading

0 comments on commit 893bff9

Please sign in to comment.