These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of EC-CUBE |
||
5 | * |
||
6 | * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.ec-cube.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\Twig\Extension; |
||
15 | |||
16 | use Twig\Environment; |
||
17 | use Twig\Extension\AbstractExtension; |
||
18 | use Twig\TwigFunction; |
||
19 | |||
20 | class EccubeBlockExtension extends AbstractExtension |
||
21 | { |
||
22 | protected $twig; |
||
23 | |||
24 | protected $blockTemplates; |
||
25 | |||
26 | 472 | public function __construct(Environment $twig, array $blockTemplates) |
|
27 | { |
||
28 | 472 | $this->twig = $twig; |
|
29 | 472 | $this->blockTemplates = $blockTemplates; |
|
30 | } |
||
31 | |||
32 | public function getFunctions() |
||
33 | { |
||
34 | return [ |
||
35 | 243 | new TwigFunction('eccube_block_*', function ($context, $name, array $parameters = []) { |
|
36 | 47 | if (!empty($parameters)) { |
|
37 | 46 | $context = array_merge($context, $parameters); |
|
38 | } |
||
39 | 47 | $files = $this->blockTemplates; |
|
40 | 47 | foreach ($files as $file) { |
|
41 | 2 | $template = $this->twig->loadTemplate($file); |
|
42 | 2 | if ($template->hasBlock($name, $context)) { |
|
43 | 2 | return $template->renderBlock($name, $context); |
|
44 | } |
||
45 | } |
||
46 | 45 | @trigger_error($name.' block is not found', E_USER_WARNING); |
|
0 ignored issues
–
show
|
|||
47 | 243 | }, ['needs_context' => true, 'pre_escape' => 'html', 'is_safe' => ['html']]), |
|
48 | ]; |
||
49 | } |
||
50 | } |
||
51 |
If you suppress an error, we recommend checking for the error condition explicitly: