Failed Conditions
Pull Request — experimental/sf (#31)
by Kentaro
06:59
created

PluginPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1
wmc 7
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 33 7
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 3
    /**
25
     * プラグインのコンポーネント定義を制御する.
26 3
     *
27
     * 無効状態のプラグインに対し, 付与されているサービスタグをクリアすることで,
28 3
     * プラグインが作成しているEventListener等の拡張機構が呼び出されないようにする.
29 1
     *
30
     * サービスタグが収集されるタイミング(一般的にPassConfig::TYPE_BEFORE_OPTIMIZATIONの0)より先に実行される必要があります.
31 1
     *
32
     * @param ContainerBuilder $container
33
     */
34 2
    public function process(ContainerBuilder $container)
35
    {
36 2
        // 無効状態のプラグインコード一覧を取得.
37 2
        // 無効なプラグインの一覧はEccubeExtensionで定義している.
38
        $plugins = $container->getParameter('eccube.plugins.disabled');
39 2
40 2
        if (empty($plugins)) {
41
            $container->log($this, 'disabled plugins not found.');
42 2
43 2
            return;
44
        }
45
46
        $definitions = $container->getDefinitions();
47
48
        foreach ($definitions as $definition) {
49
            $class = $definition->getClass();
50
51
            foreach ($plugins as $plugin) {
52
                $namespace = 'Plugin\\'.$plugin.'\\';
53
54
                if (false !== \strpos($class, $namespace)) {
55
                    foreach ($definition->getTags() as $tag => $attr) {
56
                        // PluginManagerからレポジトリを取得する場合があるため,
57
                        // doctrine.repository_serviceタグはスキップする.
58
                        if ($tag === 'doctrine.repository_service') {
59
                            continue;
60
                        }
61
                        $definition->clearTag($tag);
62
                    }
63
                }
64
            }
65
        }
66
    }
67
}
68