Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

src/Eccube/Twig/Extension/EccubeBlockExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

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
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
47 243
            }, ['needs_context' => true, 'pre_escape' => 'html', 'is_safe' => ['html']]),
48
        ];
49
    }
50
}
51