From a1535f35023f1728f6308d60845c2db5aa9acf4f Mon Sep 17 00:00:00 2001 From: costin Date: Thu, 30 Jan 2020 14:46:31 +0200 Subject: [PATCH] Migrate Zend to Laminas, Expressive to Mezzio --- CHANGELOG.md | 18 +++++ README.md | 46 ++++++------ composer.json | 74 +++++++++---------- log.global.php.dist | 6 +- src/ConfigProvider.php | 12 +-- src/Factory/FilterPluginManagerFactory.php | 2 +- src/Factory/FormatterPluginManagerFactory.php | 2 +- src/Factory/LoggerAbstractServiceFactory.php | 8 +- src/Factory/ProcessorPluginManagerFactory.php | 2 +- src/Factory/WriterPluginManagerFactory.php | 2 +- 10 files changed, 95 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2496464..bac2419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## 2.0.0 - 2020-01-30 + +### Changed +* Laminas and Mezzio migration. + +### Added +* Nothing + +### Deprecated +* Nothing + +### Removed +* Support + +### Fixed +* Nothing + + ## 1.1.2 - 2018-11-13 ### Changed diff --git a/README.md b/README.md index 1c6d205..ae15942 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,12 @@ DotKernel log component extending and customizing * Open the `Dot\Log\ConfigProvider` * In the dependencies section you will see an absctract factory (LoggerAbstractServiceFactory::class) * This class responds to "selectors" instead of class names - - Instead of requesting the `Zend\Log\Logger::class` from the container, dot-log.my_logger should be requested (or just `my_logger` if using zend-log) + - Instead of requesting the `Laminas\Log\Logger::class` from the container, dot-log.my_logger should be requested (or just `my_logger` if using laminas-log) ## Configuring the writer(s) Loggers must have at least one writer. -A writer is an object that inherits from `Zend\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend. (from zend-log's writer documentation) +A writer is an object that inherits from `Laminas\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend. (from laminas-log's writer documentation) @@ -32,7 +32,7 @@ return [ 'writers' => [ 'FileWriter' => [ 'name' => 'FileWriter', - 'priority' => \Zend\Log\Logger::ALERT, // this is equal to 1 + 'priority' => \Laminas\Log\Logger::ALERT, // this is equal to 1 'options' => [ 'stream' => __DIR__.'/../../data/logs/dk.log', ], @@ -64,7 +64,7 @@ As per PSR-3 document. The log levels are: emergency (0), alert (1), critical (2), error (3), warn (4), notice (5), info (6), debug (7) (in order of priority/importance) -Although the plain Logger in Zend Log is not fully compatible with PSR-3, it provides a way to log all of these message types. +Although the plain Logger in Laminas Log is not fully compatible with PSR-3, it provides a way to log all of these message types. The following example has three file writers using filters: @@ -82,7 +82,7 @@ return [ 'writers' => [ 'FileWriter' => [ 'name' => 'FileWriter', - 'priority' => \Zend\Log\Logger::ALERT, + 'priority' => \Laminas\Log\Logger::ALERT, 'options' => [ 'stream' => __DIR__.'/../../data/logs/dk.log', 'filters' => [ @@ -90,7 +90,7 @@ return [ 'name' => 'priority', 'options' => [ 'operator' => '>=', - 'priority' => \Zend\Log\Logger::EMERG, + 'priority' => \Laminas\Log\Logger::EMERG, ] ], ], @@ -99,7 +99,7 @@ return [ // Only warnings 'OnlyWarningsWriter' => [ 'name' => 'stream', - 'priority' => \Zend\Log\Logger::ALERT, + 'priority' => \Laminas\Log\Logger::ALERT, 'options' => [ 'stream' => __DIR__.'/../../data/logs/warnings_only.log', 'filters' => [ @@ -107,7 +107,7 @@ return [ 'name' => 'priority', 'options' => [ 'operator' => '==', - 'priority' => \Zend\Log\Logger::WARN, + 'priority' => \Laminas\Log\Logger::WARN, ], ], ], @@ -116,7 +116,7 @@ return [ // Warnings and more important messages 'WarningOrHigherWriter' => [ 'name' => 'stream', - 'priority' => \Zend\Log\Logger::ALERT, + 'priority' => \Laminas\Log\Logger::ALERT, 'options' => [ 'stream' => __DIR__.'/../../data/logs/important_messages.log', 'filters' => [ @@ -126,7 +126,7 @@ return [ // note, the smaller the priority, the more important is the message // 0 - emergency, 1 - alert, 2- error, 3 - warn. .etc 'operator' => '<=', - 'priority' => \Zend\Log\Logger::WARN, + 'priority' => \Laminas\Log\Logger::WARN, ], ], ], @@ -149,28 +149,28 @@ It was added opposite to the others just to demonstrate the other operator is al -More examples on filters: https://zendframework.github.io/zend-log/filters/ +More examples on filters: https://docs.laminas.dev/laminas-log/filters/ ## Formatting Messages -When using `dot-log` or `zend-log`, the logged value is not limited to a string. Arrays can be logged as well. +When using `dot-log` or `laminas-log`, the logged value is not limited to a string. Arrays can be logged as well. For a better readability, these arrays can be serialized. -Zend Log provides String formatting, XML, JSON and FirePHP formatting. +Laminas Log provides String formatting, XML, JSON and FirePHP formatting. The formatter accepts following parameters: -name - the formatter class (it must implement Zend\Log\Formatter\FormatterInterface) +name - the formatter class (it must implement Laminas\Log\Formatter\FormatterInterface) options - options to pass to the formatter constructor if required The following formats the message as JSON data: 'formatter' => [ - 'name' => \Zend\Log\Formatter\Json::class, + 'name' => \Laminas\Log\Formatter\Json::class, ], @@ -193,7 +193,7 @@ return [ 'writers' => [ 'FileWriter' => [ 'name' => 'FileWriter', - 'priority' => \Zend\Log\Logger::ALERT, + 'priority' => \Laminas\Log\Logger::ALERT, 'options' => [ 'stream' => __DIR__.'/../../data/logs/dk.log', // explicitly log all messages @@ -202,12 +202,12 @@ return [ 'name' => 'priority', 'options' => [ 'operator' => '>=', - 'priority' => \Zend\Log\Logger::EMERG, + 'priority' => \Laminas\Log\Logger::EMERG, ], ], ], 'formatter' => [ - 'name' => \Zend\Log\Formatter\Json::class, + 'name' => \Laminas\Log\Formatter\Json::class, ], ], ], @@ -223,7 +223,7 @@ Basic usage of the logger is illustraded below. The messages are written to see which logs are written and which are not written. ```php -use Zend\Log\Logger; +use Laminas\Log\Logger; ``` ... ```php @@ -242,9 +242,9 @@ $logger->log(Logger::NOTICE, 'NOTICE from log()'); ``` Sources: -* https://zendframework.github.io/zend-log/ -* https://zendframework.github.io/zend-log/writers/ -* https://zendframework.github.io/zend-log/filters/ +* https://docs.laminas.dev/laminas-log/ +* https://docs.laminas.dev/laminas-log/writers/ +* https://docs.laminas.dev/laminas-log/filters/ -Extracted from [this article](https://www.dotkernel.com/dotkernel/logging-with-dot-log-in-zend-expressive-and-dotkernel) +Extracted from [this article](https://www.dotkernel.com/dotkernel/logging-with-dot-log-in-mezzio-and-dotkernel) diff --git a/composer.json b/composer.json index 563aabc..6a2de72 100644 --- a/composer.json +++ b/composer.json @@ -1,40 +1,40 @@ { - "name": "dotkernel/dot-log", - "type": "library", - "description": "DotKernel log component extending and customizing zend-log", - "license": "MIT", - "authors": [ - { - "name": "DotKernel Team", - "email": "team@dotkernel.com" + "name": "dotkernel/dot-log", + "type": "library", + "description": "DotKernel log component extending and customizing laminas-log", + "license": "MIT", + "authors": [ + { + "name": "DotKernel Team", + "email": "team@dotkernel.com" + } + ], + "require": { + "php": "^7.2", + "psr/http-message": "^1.0", + "laminas/laminas-servicemanager": "^3.3.0", + "laminas/laminas-log": "^2.9.0", + "laminas/laminas-dependency-plugin": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8", + "squizlabs/php_codesniffer": "^2.3", + "dotkernel/dot-mail": "^2.0" + }, + "autoload": { + "psr-4": { + "Dot\\Log\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "DotTest\\Log\\": "test/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "2.0-dev", + "dev-develop": "2.1-dev" + } } - ], - "require": { - "php": "^7.1", - "psr/http-message": "^1.0", - "zendframework/zend-servicemanager": "^3.3.0", - "zendframework/zend-log": "^2.9.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8", - "squizlabs/php_codesniffer": "^2.3", - - "dotkernel/dot-mail": "^1.0" - }, - "autoload": { - "psr-4": { - "Dot\\Log\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "DotTest\\Log\\": "test/" - } - }, - "extra": { - "branch-alias": { - "dev-master": "1.1-dev", - "dev-develop": "1.2-dev" - } - } } diff --git a/log.global.php.dist b/log.global.php.dist index 9695e63..a4342c5 100644 --- a/log.global.php.dist +++ b/log.global.php.dist @@ -10,7 +10,7 @@ return [ 'stream_logger' => [ 'writers' => [ 'name' => 'stream', - 'priority' => \Zend\Log\Logger::DEBUG, + 'priority' => \Laminas\Log\Logger::DEBUG, 'options' => [ 'stream' => 'php://output', 'formatter' => [ @@ -29,7 +29,7 @@ return [ 'db_logger' => [ 'writers' => [ 'name' => 'db', - 'priority' => \Zend\Log\Logger::INFO, + 'priority' => \Laminas\Log\Logger::INFO, 'options' => [ //service name of the database adapter 'db' => 'database', @@ -62,7 +62,7 @@ return [ 'mail_logger' => [ 'writers' => [ 'name' => 'mail', - 'priority' => \Zend\Log\Logger::ERR, + 'priority' => \Laminas\Log\Logger::ERR, 'options' => [ 'mail_service' => 'dot-mail.mail-service.service_name', diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index f9e5681..830aab8 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -14,12 +14,12 @@ use Dot\Log\Factory\LoggerAbstractServiceFactory; use Dot\Log\Factory\ProcessorPluginManagerFactory; use Dot\Log\Factory\WriterPluginManagerFactory; -use Zend\Log\FilterPluginManager; -use Zend\Log\FormatterPluginManager; -use Zend\Log\Logger; -use Zend\Log\LoggerServiceFactory; -use Zend\Log\ProcessorPluginManager; -use Zend\Log\WriterPluginManager; +use Laminas\Log\FilterPluginManager; +use Laminas\Log\FormatterPluginManager; +use Laminas\Log\Logger; +use Laminas\Log\LoggerServiceFactory; +use Laminas\Log\ProcessorPluginManager; +use Laminas\Log\WriterPluginManager; /** * Class ConfigProvider diff --git a/src/Factory/FilterPluginManagerFactory.php b/src/Factory/FilterPluginManagerFactory.php index 25eb776..ad85fe1 100644 --- a/src/Factory/FilterPluginManagerFactory.php +++ b/src/Factory/FilterPluginManagerFactory.php @@ -10,7 +10,7 @@ namespace Dot\Log\Factory; use Psr\Container\ContainerInterface; -use Zend\Log\FilterPluginManager; +use Laminas\Log\FilterPluginManager; /** * Class FilterPluginManagerFactory diff --git a/src/Factory/FormatterPluginManagerFactory.php b/src/Factory/FormatterPluginManagerFactory.php index 27b4dd6..9fe3597 100644 --- a/src/Factory/FormatterPluginManagerFactory.php +++ b/src/Factory/FormatterPluginManagerFactory.php @@ -10,7 +10,7 @@ namespace Dot\Log\Factory; use Psr\Container\ContainerInterface; -use Zend\Log\FormatterPluginManager; +use Laminas\Log\FormatterPluginManager; /** * Class FormatterPluginManagerFactory diff --git a/src/Factory/LoggerAbstractServiceFactory.php b/src/Factory/LoggerAbstractServiceFactory.php index a0669de..99d055a 100644 --- a/src/Factory/LoggerAbstractServiceFactory.php +++ b/src/Factory/LoggerAbstractServiceFactory.php @@ -11,13 +11,13 @@ use Dot\Mail\Service\MailServiceInterface; use Interop\Container\ContainerInterface; -use Zend\Log\Writer\Mail; +use Laminas\Log\Writer\Mail; /** * Class LoggerAbstractServiceFactory * @package Dot\Log */ -class LoggerAbstractServiceFactory extends \Zend\Log\LoggerAbstractServiceFactory +class LoggerAbstractServiceFactory extends \Laminas\Log\LoggerAbstractServiceFactory { const PREFIX = 'dot-log'; @@ -49,7 +49,7 @@ public function canCreate(ContainerInterface $container, $requestedName) * @param ContainerInterface $container * @param string $requestedName * @param array|null $options - * @return object|\Zend\Log\Logger + * @return object|\Laminas\Log\Logger */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { @@ -91,7 +91,7 @@ protected function processConfig(&$config, ContainerInterface $services) if (isset($writerConfig['name']) && ('mail' === $writerConfig['name'] || Mail::class === $writerConfig['name'] - || 'zendlogwritermail' === $writerConfig['name'] + || 'laminaslogwritermail' === $writerConfig['name'] ) && isset($writerConfig['options']['mail_service']) && is_string($writerConfig['options']['mail_service']) diff --git a/src/Factory/ProcessorPluginManagerFactory.php b/src/Factory/ProcessorPluginManagerFactory.php index dfee3a4..ed6c362 100644 --- a/src/Factory/ProcessorPluginManagerFactory.php +++ b/src/Factory/ProcessorPluginManagerFactory.php @@ -10,7 +10,7 @@ namespace Dot\Log\Factory; use Psr\Container\ContainerInterface; -use Zend\Log\ProcessorPluginManager; +use Laminas\Log\ProcessorPluginManager; /** * Class ProcessorPluginManagerFactory diff --git a/src/Factory/WriterPluginManagerFactory.php b/src/Factory/WriterPluginManagerFactory.php index 09a081e..4719eeb 100644 --- a/src/Factory/WriterPluginManagerFactory.php +++ b/src/Factory/WriterPluginManagerFactory.php @@ -10,7 +10,7 @@ namespace Dot\Log\Factory; use Psr\Container\ContainerInterface; -use Zend\Log\WriterPluginManager; +use Laminas\Log\WriterPluginManager; /** * Class WriterPluginManagerFactory