Conditions | 5 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
7 | public function __invoke(array $args) |
||
8 | { |
||
9 | $this->args = $args; |
||
10 | |||
11 | if (!isset($this->args['class']) || empty($this->args['class'])) { |
||
12 | throw new \OutOfBoundsException('You should define key class to create a log formatter'); |
||
13 | } |
||
14 | |||
15 | $class = new \ReflectionClass($args['class']); |
||
16 | $params = []; |
||
17 | |||
18 | if ($constructor = $class->getConstructor()) { |
||
19 | $params = $this->getParams($constructor); |
||
20 | } |
||
21 | |||
22 | $object = $class->newInstanceArgs($params); |
||
23 | |||
24 | if (!$object instanceof \Monolog\Formatter\FormatterInterface) { |
||
25 | throw new \InvalidArgumentException('Class must be instance of "\Monolog\Formatter\FormatterInterface"'); |
||
26 | } |
||
27 | |||
28 | return $object; |
||
29 | } |
||
30 | } |
||
31 |