Completed
Push — master ( 537349...e26b4a )
by Westin
11:04
created

ElasticaHandlerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11MonoLog\Handler;
5
6
use Monolog\Handler\ElasticaHandler;
7
use Monolog\Logger;
8
use WShafer\PSR11MonoLog\ContainerAwareInterface;
9
use WShafer\PSR11MonoLog\FactoryInterface;
10
use WShafer\PSR11MonoLog\ServiceTrait;
11
12
class ElasticaHandlerFactory implements FactoryInterface, ContainerAwareInterface
13
{
14
    use ServiceTrait;
15
16
    public function __invoke(array $options)
17
    {
18
        $client      = $this->getService($options['client'] ?? null);
19
        $index       = (string)  ($options['index']       ?? 'monolog');
20
        $type        = (string)  ($options['type']        ?? 'record');
21
        $ignoreError = (boolean) ($options['ignoreError'] ?? false);
22
        $level       = (int)     ($options['level']       ?? Logger::DEBUG);
23
        $bubble      = (boolean) ($options['bubble']      ?? true);
24
25
        return new ElasticaHandler(
26
            $client,
27
            [
28
                'index'        => $index,
29
                'type'         => $type,
30
                'ignore_error' => $ignoreError
31
            ],
32
            $level,
33
            $bubble
34
        );
35
    }
36
}
37