Completed
Push — feature-20rc1 ( 008ae2 )
by Rob
16:55
created

LoggerInjectCompilerPass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
/**
18
 * @author Rob Frawley 2nd <[email protected]>
19
 */
20
class LoggerInjectCompilerPass extends AbstractCompilerPass
21
{
22
    /**
23
     * @var string
24
     */
25
    private $tagName;
26
27
    /**
28
     * @var string
29
     */
30
    private $service;
31
32
    /**
33
     * @param string $loggerTagName
34
     * @param string $loggerService
35
     */
36
    public function __construct(
37
        string $loggerTagName = 'liip_imagine.logger_inject',
38
        string $loggerService = 'liip_imagine.logger'
39
    ) {
40
        $this->tagName = $loggerTagName;
41
        $this->service = $loggerService;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function process(ContainerBuilder $container): void
48
    {
49
        foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tag) {
50
            $container->getDefinition($id)->addMethodCall('setLogger', [new Reference($this->service)]);
51
            $this->log($container, 'Injecting logger for service: %s', $id);
52
        }
53
    }
54
}
55