1 | <?php |
||
17 | abstract class AbstractDiContainerLoggerFactory |
||
18 | { |
||
19 | /** @var string */ |
||
20 | protected $loggerName; |
||
21 | |||
22 | /** @var LoggerFactory */ |
||
23 | private static $loggerFactory; |
||
24 | |||
25 | /** @var ContainerInterface */ |
||
26 | private $container; |
||
27 | |||
28 | 11 | public function __construct(string $loggerName = 'default') |
|
32 | |||
33 | 11 | public function __invoke(ContainerInterface $container): Logger |
|
45 | |||
46 | 2 | public static function __callStatic(string $name, array $arguments): Logger |
|
54 | |||
55 | abstract protected function getLoggerConfig(string $loggerName): array; |
||
56 | |||
57 | 11 | protected function createLogger(array $config): Logger |
|
69 | |||
70 | 11 | protected function getContainer(): ContainerInterface |
|
74 | |||
75 | 11 | private function prepareHandlers(array $handlers): array |
|
87 | |||
88 | 8 | private function prepareProcessors(array $processors): array |
|
98 | |||
99 | 5 | private function resolveHandler(string $handlerName): HandlerInterface |
|
103 | |||
104 | 4 | private function resolveFormatter(string $formatterName): FormatterInterface |
|
108 | |||
109 | 4 | private function resolveProcessor(string $processorName): callable |
|
113 | |||
114 | 7 | private function resolveFromContainer(string $serviceOrFactory) |
|
115 | { |
||
116 | try { |
||
117 | 7 | if ($this->container->has($serviceOrFactory)) { |
|
118 | 3 | return $this->container->get($serviceOrFactory); |
|
119 | } |
||
120 | |||
121 | 7 | if (class_exists($serviceOrFactory)) { |
|
122 | 4 | $factory = new $serviceOrFactory(); |
|
123 | 7 | return $factory($this->container); |
|
124 | } |
||
125 | 1 | } catch (Throwable $ex) { |
|
126 | 1 | throw CannotResolveLoggerComponent::resolutionFailed($serviceOrFactory, $ex); |
|
127 | } |
||
128 | |||
129 | 3 | throw CannotResolveLoggerComponent::unknownService($serviceOrFactory); |
|
130 | } |
||
131 | |||
132 | 7 | protected static function getLoggerFactory(): LoggerFactory |
|
140 | } |
||
141 |