1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arp\LaminasMonolog\Factory\Handler; |
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
8
|
|
|
use Arp\LaminasMonolog\Factory\FactoryFormatterProviderTrait; |
9
|
|
|
use Arp\LaminasMonolog\Factory\FactoryLoggerProviderTrait; |
10
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
11
|
|
|
use Laminas\ServiceManager\ServiceLocatorInterface; |
12
|
|
|
use Monolog\Handler\PsrHandler; |
13
|
|
|
use Monolog\Logger; |
14
|
|
|
use Psr\Container\ContainerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Alex Patterson <[email protected]> |
18
|
|
|
* @package Arp\LaminasMonolog\Factory\Handler |
19
|
|
|
*/ |
20
|
|
|
final class PsrHandlerFactory extends AbstractFactory |
21
|
|
|
{ |
22
|
|
|
use FactoryLoggerProviderTrait; |
23
|
|
|
use FactoryFormatterProviderTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param ContainerInterface&ServiceLocatorInterface $container |
27
|
|
|
* @param string $requestedName |
28
|
|
|
* @param array<mixed>|null $options |
29
|
|
|
* |
30
|
|
|
* @return PsrHandler |
31
|
|
|
* |
32
|
|
|
* @throws ServiceNotCreatedException |
33
|
|
|
*/ |
34
|
|
|
public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): PsrHandler |
35
|
|
|
{ |
36
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName); |
37
|
|
|
|
38
|
|
|
if (empty($options['logger'])) { |
39
|
|
|
throw new ServiceNotCreatedException( |
40
|
|
|
sprintf('The required \'logger\' configuration option is missing for service \'%s\'', $requestedName) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$handler = new PsrHandler( |
45
|
|
|
$this->getLogger($container, $options['logger'], $requestedName), |
46
|
|
|
isset($options['level']) ? (int)$options['level'] : Logger::DEBUG, |
47
|
|
|
isset($options['bubble']) ? (bool)$options['bubble'] : true |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
if (!empty($options['formatter'])) { |
51
|
|
|
$handler->setFormatter( |
52
|
|
|
$this->getFormatter($container, $options['formatter'], $requestedName) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $handler; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|