diff --git a/build.sh b/build.sh index e29f90d4..7969b6aa 100755 --- a/build.sh +++ b/build.sh @@ -20,8 +20,14 @@ rsync -av * "${builtcontent}" \ --exclude=bin/test \ --exclude=data/infra \ --exclude=data/travis \ + --exclude=data/cache/* \ + --exclude=data/log/* \ + --exclude=data/locks/* \ + --exclude=data/proxies/* \ --exclude=data/migrations_template.txt \ - --exclude=data/GeoLite2-City.mmdb \ + --exclude=data/GeoLite2-City.* \ + --exclude=data/database.sqlite \ + --exclude=data/shlink-tests.db \ --exclude=**/.gitignore \ --exclude=CHANGELOG.md \ --exclude=composer.lock \ @@ -47,7 +53,6 @@ ${composerBin} install --no-dev --optimize-autoloader --apcu-autoloader --no-pro # Delete development files echo 'Deleting dev files...' rm composer.* -rm -f data/database.sqlite # Update shlink version in config sed -i "s/%SHLINK_VERSION%/${version}/g" config/autoload/app_options.global.php diff --git a/composer.json b/composer.json index aa3221ff..b067f8ed 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "lstrojny/functional-php": "^1.8", "mikehaertl/phpwkhtmltopdf": "^2.2", "monolog/monolog": "^1.21", - "ocramius/proxy-manager": "^2.0", + "ocramius/proxy-manager": "~2.2.2", "phly/phly-event-dispatcher": "^1.0", "predis/predis": "^1.1", "shlinkio/shlink-installer": "^1.2.1", diff --git a/config/autoload/locks.global.php b/config/autoload/locks.global.php index cbf3a000..be9e7736 100644 --- a/config/autoload/locks.global.php +++ b/config/autoload/locks.global.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Shlinkio\Shlink\Common\Cache\RedisFactory; use Shlinkio\Shlink\Common\Lock\RetryLockStoreDelegatorFactory; +use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory; use Symfony\Component\Lock; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; @@ -27,6 +28,9 @@ return [ Lock\Store\RedisStore::class => [ RetryLockStoreDelegatorFactory::class, ], + Lock\Factory::class => [ + LoggerAwareDelegatorFactory::class, + ], ], ], diff --git a/module/Common/src/Logger/LoggerAwareDelegatorFactory.php b/module/Common/src/Logger/LoggerAwareDelegatorFactory.php new file mode 100644 index 00000000..8cb04499 --- /dev/null +++ b/module/Common/src/Logger/LoggerAwareDelegatorFactory.php @@ -0,0 +1,20 @@ +setLogger($container->get(Log\LoggerInterface::class)); + } + + return $instance; + } +} diff --git a/module/Common/test/Logger/LoggerAwareDelegatorFactoryTest.php b/module/Common/test/Logger/LoggerAwareDelegatorFactoryTest.php new file mode 100644 index 00000000..8723077b --- /dev/null +++ b/module/Common/test/Logger/LoggerAwareDelegatorFactoryTest.php @@ -0,0 +1,55 @@ +container = $this->prophesize(ContainerInterface::class); + $this->delegator = new LoggerAwareDelegatorFactory(); + } + + /** + * @test + * @dataProvider provideInstances + */ + public function injectsLoggerOnInstanceWhenImplementingLoggerAware($instance, int $expectedCalls): void + { + $callback = function () use ($instance) { + return $instance; + }; + $getLogger = $this->container->get(Log\LoggerInterface::class)->willReturn(new Log\NullLogger()); + + $result = ($this->delegator)($this->container->reveal(), '', $callback); + + $this->assertSame($instance, $result); + $getLogger->shouldHaveBeenCalledTimes($expectedCalls); + } + + public function provideInstances(): iterable + { + yield 'no logger aware' => [new stdClass(), 0]; + yield 'logger aware' => [new class implements Log\LoggerAwareInterface { + public function setLogger(LoggerInterface $logger): void + { + Assert::assertInstanceOf(Log\NullLogger::class, $logger); + } + }, 1]; + } +} diff --git a/module/EventDispatcher/config/event_dispatcher.config.php b/module/EventDispatcher/config/event_dispatcher.config.php index 336162b8..ed932155 100644 --- a/module/EventDispatcher/config/event_dispatcher.config.php +++ b/module/EventDispatcher/config/event_dispatcher.config.php @@ -5,6 +5,7 @@ namespace Shlinkio\Shlink\EventDispatcher; use Phly\EventDispatcher as Phly; use Psr\EventDispatcher as Psr; +use Zend\ServiceManager\Proxy\LazyServiceFactory; return [ @@ -21,6 +22,16 @@ return [ 'aliases' => [ Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class, ], + 'delegators' => [ + Psr\ListenerProviderInterface::class => [ + LazyServiceFactory::class, + ], + ], + 'lazy_services' => [ + 'class_map' => [ + Psr\ListenerProviderInterface::class => Psr\ListenerProviderInterface::class, + ], + ], ], ];