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\EccubeTwigBlock; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
|
20
|
|
|
class TwigBlockPass implements CompilerPassInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
const TWIG_BLOCK_TAG = 'eccube.twig_block'; |
23
|
|
|
|
24
|
1 |
|
public function process(ContainerBuilder $container) |
25
|
|
|
{ |
26
|
1 |
|
$ids = $container->findTaggedServiceIds(self::TWIG_BLOCK_TAG); |
27
|
1 |
|
$templates = $container->getParameter('eccube_twig_block_templates'); |
28
|
|
|
|
29
|
1 |
|
foreach ($ids as $id => $tags) { |
30
|
1 |
|
$def = $container->getDefinition($id); |
31
|
1 |
|
$class = $container->getParameterBag()->resolveValue($def->getClass()); |
32
|
1 |
|
if (!is_subclass_of($class, EccubeTwigBlock::class)) { |
33
|
|
|
throw new \InvalidArgumentException( |
34
|
|
|
sprintf('Service "%s" must implement interface "%s".', $id, EccubeTwigBlock::class)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @var $class EccubeTwigBlock */ |
38
|
1 |
|
$blocks = $class::getTwigBlock(); |
39
|
1 |
|
foreach ($blocks as $block) { |
40
|
1 |
|
$templates[] = $block; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
$container->setParameter('eccube_twig_block_templates', $templates); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|