Conditions | 5 |
Paths | 5 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function __invoke(array $args) |
||
10 | { |
||
11 | $this->args = $args; |
||
12 | |||
13 | if (!isset($this->args['class']) || empty($this->args['class'])) { |
||
14 | throw new \OutOfBoundsException('You should define key class to create a log handler'); |
||
15 | } |
||
16 | |||
17 | if (isset($this->args['params']['level'])) { |
||
18 | $this->args['params']['level'] = Logger::translateLevel($this->args['params']['level']); |
||
19 | } |
||
20 | |||
21 | $class = new \ReflectionClass($this->args['class']); |
||
22 | $params = $this->getParams($class->getConstructor()); |
||
23 | |||
24 | $object = $class->newInstanceArgs($params); |
||
25 | |||
26 | if (isset($this->args['formatter'])) { |
||
27 | $formatterFactory = new Formatter(); |
||
28 | $formatter = $formatterFactory($this->args['formatter']); |
||
29 | |||
30 | $object->setFormatter($formatter); |
||
31 | } |
||
32 | |||
33 | return $object; |
||
34 | } |
||
35 | } |
||
36 |