|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WShafer\PSR11MonoLog\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Monolog\Handler\HandlerInterface; |
|
6
|
|
|
use WShafer\PSR11MonoLog\ConfigInterface; |
|
7
|
|
|
use WShafer\PSR11MonoLog\Exception\MissingServiceException; |
|
8
|
|
|
use WShafer\PSR11MonoLog\Exception\UnknownServiceException; |
|
9
|
|
|
|
|
10
|
|
|
class HandlerManager extends AbstractServiceManager |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var FormatterManager */ |
|
13
|
|
|
protected $formatterManager; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var ProcessorManager |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $processorManager; |
|
19
|
|
|
|
|
20
|
1 |
|
public function getServiceConfig($id): ConfigInterface |
|
21
|
|
|
{ |
|
22
|
1 |
|
return $this->config->getHandlerConfig($id); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function hasServiceConfig($id): bool |
|
26
|
|
|
{ |
|
27
|
1 |
|
return $this->config->hasHandlerConfig($id); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
7 |
|
public function get($id) |
|
31
|
|
|
{ |
|
32
|
7 |
|
if (array_key_exists($id, $this->services)) { |
|
33
|
1 |
|
return $this->services[$id]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** @var HandlerInterface $handler */ |
|
37
|
7 |
|
$handler = parent::get($id); |
|
38
|
|
|
|
|
39
|
7 |
|
$config = $this->config->getHandlerConfig($id); |
|
40
|
|
|
|
|
41
|
7 |
|
if (!$config) { |
|
42
|
2 |
|
return $handler; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
5 |
|
$formatter= $config->getFormatter(); |
|
46
|
|
|
|
|
47
|
5 |
|
if ($formatter) { |
|
48
|
3 |
|
$handler->setFormatter($this->getFormatter($formatter)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
$processors = $config->getProcessors(); |
|
52
|
3 |
|
foreach ($processors as $processorName) { |
|
53
|
2 |
|
$handler->pushProcessor($this->getProcessorManager()->get($processorName)); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
return $handler; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
6 |
|
public function setFormatterManager(FormatterManager $manager) |
|
60
|
|
|
{ |
|
61
|
6 |
|
$this->formatterManager = $manager; |
|
62
|
6 |
|
} |
|
63
|
|
|
|
|
64
|
4 |
|
public function getFormatterManager() : FormatterManager |
|
65
|
|
|
{ |
|
66
|
4 |
|
if (!$this->formatterManager) { |
|
67
|
1 |
|
throw new MissingServiceException( |
|
68
|
1 |
|
'Unable to get FormatterManager.' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
return $this->formatterManager; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
3 |
|
protected function getFormatter($id) |
|
76
|
|
|
{ |
|
77
|
3 |
|
if (!$this->getFormatterManager()->has($id)) { |
|
78
|
1 |
|
throw new UnknownServiceException( |
|
79
|
1 |
|
'Unable to locate formatter '.$id |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
return $this->getFormatterManager()->get($id); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
2 |
|
public function setProcessorManager($processorManager) |
|
87
|
|
|
{ |
|
88
|
2 |
|
$this->processorManager = $processorManager; |
|
89
|
2 |
|
} |
|
90
|
|
|
|
|
91
|
3 |
|
public function getProcessorManager() |
|
92
|
|
|
{ |
|
93
|
3 |
|
if (!$this->processorManager) { |
|
94
|
1 |
|
throw new MissingServiceException( |
|
95
|
1 |
|
'Unable to get ProcessorManager.' |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
2 |
|
return $this->processorManager; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: