Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
51:40 queued 07:20
created

PluginPass::process()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7.0145

Importance

Changes 0
Metric Value
cc 7
nc 7
nop 1
dl 0
loc 33
ccs 14
cts 15
cp 0.9333
crap 7.0145
rs 8.4586
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
/**
20
 * プラグインのコンポーネント定義を制御するクラス.
21
 */
22
class PluginPass implements CompilerPassInterface
23
{
24
    /**
25
     * プラグインのコンポーネント定義を制御する.
26
     *
27
     * 無効状態のプラグインに対し, 付与されているサービスタグをクリアすることで,
28
     * プラグインが作成しているEventListener等の拡張機構が呼び出されないようにする.
29
     *
30
     * サービスタグが収集されるタイミング(一般的にPassConfig::TYPE_BEFORE_OPTIMIZATIONの0)より先に実行される必要があります.
31
     *
32
     * @param ContainerBuilder $container
33
     */
34 3
    public function process(ContainerBuilder $container)
35
    {
36
        // 無効状態のプラグインコード一覧を取得.
37
        // 無効なプラグインの一覧はEccubeExtensionで定義している.
38 3
        $plugins = $container->getParameter('eccube.plugins.disabled');
39
40 3
        if (empty($plugins)) {
41 1
            $container->log($this, 'disabled plugins not found.');
42
43 1
            return;
44
        }
45
46 2
        $definitions = $container->getDefinitions();
47
48 2
        foreach ($definitions as $definition) {
49 2
            $class = $definition->getClass();
50
51 2
            foreach ($plugins as $plugin) {
52 2
                $namespace = 'Plugin\\'.$plugin.'\\';
53
54 2
                if (false !== \strpos($class, $namespace)) {
55 2
                    foreach ($definition->getTags() as $tag => $attr) {
56
                        // PluginManagerからレポジトリを取得する場合があるため,
57
                        // doctrine.repository_serviceタグはスキップする.
58 2
                        if ($tag === 'doctrine.repository_service') {
59
                            continue;
60
                        }
61 2
                        $definition->clearTag($tag);
62
                    }
63
                }
64
            }
65
        }
66
    }
67
}
68