Completed
Push — master ( fdbeef...265a2d )
by jerome
25:01 queued 21:35
created

PhpseclibDebugCompilerPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of Dedipanel project
5
 *
6
 * (c) 2010-2015 Dedipanel <http://www.dedicated-panel.net>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DP\Core\CoreBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * Modify services requiring logger with phpseclib channel
19
 * and inject NullLogger if debug is disabled
20
 *
21
 * @package DP\Core\CoreBundle\DependencyInjection\Compiler
22
 */
23
class PhpseclibDebugCompilerPass implements CompilerPassInterface
24
{
25
    public function process(ContainerBuilder $container)
26
    {
27
        if (!$container->getParameterBag()->get('dedipanel.debug')) {
28
            $this->replaceByNullLogger($container, 'monolog.handler.phpseclib_wrapper');
29
            $this->replaceByNullLogger($container, 'monolog.handler.phpseclib_internal');
30
        }
31
    }
32
33
    /**
34
     * @param string $handler
35
     */
36
    private function replaceByNullLogger(ContainerBuilder $container, $handler)
37
    {
38
        $def = $container->getDefinition($handler);
39
        $def->setClass('%monolog.handler.null.class%');
40
41
        $container->setDefinition($handler, $def);
42
    }
43
}
44