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 Eccube\Common\EccubeNav; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
|
20
|
|
View Code Duplication |
class NavCompilerPass implements CompilerPassInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
const NAV_TAG = 'eccube.nav'; |
23
|
|
|
|
24
|
1 |
|
public function process(ContainerBuilder $container) |
25
|
|
|
{ |
26
|
1 |
|
$ids = $container->findTaggedServiceIds(self::NAV_TAG); |
27
|
1 |
|
$nav = $container->getParameter('eccube_nav'); |
28
|
|
|
|
29
|
1 |
|
foreach ($ids as $id => $tags) { |
30
|
|
|
$def = $container->getDefinition($id); |
31
|
|
|
$class = $container->getParameterBag()->resolveValue($def->getClass()); |
32
|
|
|
if (!is_subclass_of($class, EccubeNav::class)) { |
33
|
|
|
throw new \InvalidArgumentException( |
34
|
|
|
sprintf('Service "%s" must implement interface "%s".', $id, EccubeNav::class)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @var $class EccubeNav */ |
38
|
|
|
$addNav = $class::getNav(); |
39
|
|
|
$nav = array_replace_recursive($nav, $addNav); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$container->setParameter('eccube_nav', $nav); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.