Created delegator factory that injects logger on services implementing LoggerAware, and used it for locks factory

This commit is contained in:
Alejandro Celaya
2019-08-08 13:42:14 +02:00
parent 8db9962282
commit 38016b3ba3
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log;
class LoggerAwareDelegatorFactory
{
public function __invoke(ContainerInterface $container, $name, callable $callback)
{
$instance = $callback();
if ($instance instanceof Log\LoggerAwareInterface) {
$instance->setLogger($container->get(Log\LoggerInterface::class));
}
return $instance;
}
}