diff --git a/CHANGELOG.md b/CHANGELOG.md index f9ffb39e..30dd12e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] + +#### Added + +* *Nothing* + +#### Changed + +* *Nothing* + +#### Deprecated + +* *Nothing* + +#### Removed + +* [#301](https://github.com/shlinkio/shlink/issues/301) Removed custom `AccessLogFactory` in favor of the implementation included in [zendframework/zend-expressive-swoole](https://github.com/zendframework/zend-expressive-swoole) v2.2.0 + +#### Fixed + +* *Nothing* + + ## 1.15.0 - 2018-12-02 #### Added diff --git a/composer.json b/composer.json index 0c82a512..ce688a63 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "zendframework/zend-expressive-fastroute": "^3.0", "zendframework/zend-expressive-helpers": "^5.0", "zendframework/zend-expressive-platesrenderer": "^2.0", - "zendframework/zend-expressive-swoole": "^2.1", + "zendframework/zend-expressive-swoole": "^2.2", "zendframework/zend-i18n": "^2.7", "zendframework/zend-inputfilter": "^2.8", "zendframework/zend-paginator": "^2.6", diff --git a/config/autoload/logger.global.php b/config/autoload/logger.global.php index 0477f4b2..c485516d 100644 --- a/config/autoload/logger.global.php +++ b/config/autoload/logger.global.php @@ -7,7 +7,6 @@ use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\StreamHandler; use Monolog\Logger; use Monolog\Processor; -use Zend\Expressive\Swoole\Log\AccessLogInterface; use const PHP_EOL; return [ @@ -32,7 +31,6 @@ return [ 'class' => StreamHandler::class, 'level' => Logger::INFO, 'stream' => 'php://stdout', - 'formatter' => 'dashed', ], ], @@ -61,15 +59,13 @@ return [ 'factories' => [ 'Logger_Shlink' => Common\Factory\LoggerFactory::class, 'Logger_Swoole' => Common\Factory\LoggerFactory::class, - - AccessLogInterface::class => Common\Logger\Swoole\AccessLogFactory::class, ], ], 'zend-expressive-swoole' => [ 'swoole-http-server' => [ 'logger' => [ - 'logger_name' => 'Logger_Swoole', + 'logger-name' => 'Logger_Swoole', ], ], ], diff --git a/indocker b/indocker index 24b8094c..789386ac 100755 --- a/indocker +++ b/indocker @@ -1,8 +1,7 @@ #!/usr/bin/env bash # Run docker containers if they are not up yet -if [[ $(docker ps | grep shlink_swoole) ]]; then : -else +if ! [[ $(docker ps | grep shlink_swoole) ]]; then docker-compose up -d fi diff --git a/module/Common/src/Logger/Swoole/AccessLogFactory.php b/module/Common/src/Logger/Swoole/AccessLogFactory.php deleted file mode 100644 index 60822762..00000000 --- a/module/Common/src/Logger/Swoole/AccessLogFactory.php +++ /dev/null @@ -1,51 +0,0 @@ -has('config') ? $container->get('config') : []; - $config = $config['zend-expressive-swoole']['swoole-http-server']['logger'] ?? []; - - return new Log\Psr3AccessLogDecorator( - $this->getLogger($container, $config), - $this->getFormatter($container, $config), - $config['use-hostname-lookups'] ?? false - ); - } - - private function getLogger(ContainerInterface $container, array $config): LoggerInterface - { - $loggerName = $config['logger_name'] ?? LoggerInterface::class; - return $container->has($loggerName) ? $container->get($loggerName) : new Log\StdoutLogger(); - } - - private function getFormatter(ContainerInterface $container, array $config): Log\AccessLogFormatterInterface - { - if ($container->has(Log\AccessLogFormatterInterface::class)) { - return $container->get(Log\AccessLogFormatterInterface::class); - } - - return new Log\AccessLogFormatter($config['format'] ?? Log\AccessLogFormatter::FORMAT_COMMON); - } -} diff --git a/module/Common/test/Logger/Swoole/AccessLogFactoryTest.php b/module/Common/test/Logger/Swoole/AccessLogFactoryTest.php deleted file mode 100644 index 986c117a..00000000 --- a/module/Common/test/Logger/Swoole/AccessLogFactoryTest.php +++ /dev/null @@ -1,138 +0,0 @@ -factory = new AccessLogFactory(); - } - - /** - * @test - */ - public function createsService() - { - $service = ($this->factory)(new ServiceManager(), ''); - $this->assertInstanceOf(Psr3AccessLogDecorator::class, $service); - } - - /** - * @test - * @dataProvider provideLoggers - * @param array $config - * @param string|LoggerInterface $expectedLogger - */ - public function wrapsProperLogger(array $config, $expectedLogger) - { - $service = ($this->factory)(new ServiceManager(['services' => $config]), ''); - - $ref = new ReflectionObject($service); - $loggerProp = $ref->getProperty('logger'); - $loggerProp->setAccessible(true); - $logger = $loggerProp->getValue($service); - - if (is_string($expectedLogger)) { - $this->assertInstanceOf($expectedLogger, $logger); - } else { - $this->assertSame($expectedLogger, $logger); - } - } - - public function provideLoggers(): iterable - { - yield 'without-any-logger' => [[], StdoutLogger::class]; - yield 'with-standard-logger' => (function () { - $logger = new NullLogger(); - return [[LoggerInterface::class => $logger], $logger]; - })(); - yield 'with-custom-logger' => (function () { - $logger = new NullLogger(); - return [[ - 'config' => [ - 'zend-expressive-swoole' => [ - 'swoole-http-server' => [ - 'logger' => [ - 'logger_name' => 'my-logger', - ], - ], - ], - ], - 'my-logger' => $logger, - ], $logger]; - })(); - } - - /** - * @test - * @dataProvider provideFormatters - * @param array $config - * @param string|AccessLogFormatterInterface $expectedFormatter - */ - public function wrappsProperFormatter(array $config, $expectedFormatter, string $expectedFormat) - { - $service = ($this->factory)(new ServiceManager(['services' => $config]), ''); - - $ref = new ReflectionObject($service); - $formatterProp = $ref->getProperty('formatter'); - $formatterProp->setAccessible(true); - $formatter = $formatterProp->getValue($service); - - $ref = new ReflectionObject($formatter); - $formatProp = $ref->getProperty('format'); - $formatProp->setAccessible(true); - $format = $formatProp->getValue($formatter); - - if (is_string($expectedFormatter)) { - $this->assertInstanceOf($expectedFormatter, $formatter); - } else { - $this->assertSame($expectedFormatter, $formatter); - } - $this->assertSame($expectedFormat, $format); - } - - public function provideFormatters(): iterable - { - yield 'with-registered-formatter-and-default-format' => (function () { - $formatter = new AccessLogFormatter(); - return [[AccessLogFormatterInterface::class => $formatter], $formatter, AccessLogFormatter::FORMAT_COMMON]; - })(); - yield 'with-registered-formatter-and-custom-format' => (function () { - $formatter = new AccessLogFormatter(AccessLogFormatter::FORMAT_AGENT); - return [[AccessLogFormatterInterface::class => $formatter], $formatter, AccessLogFormatter::FORMAT_AGENT]; - })(); - yield 'with-no-formatter-and-not-configured-format' => [ - [], - AccessLogFormatter::class, - AccessLogFormatter::FORMAT_COMMON, - ]; - yield 'with-no-formatter-and-configured-format' => [[ - 'config' => [ - 'zend-expressive-swoole' => [ - 'swoole-http-server' => [ - 'logger' => [ - 'format' => AccessLogFormatter::FORMAT_COMBINED_DEBIAN, - ], - ], - ], - ], - ], AccessLogFormatter::class, AccessLogFormatter::FORMAT_COMBINED_DEBIAN]; - } -}