Completed
Push — wip-platform ( 03cba6...2999ab )
by
unknown
05:53 queued 02:49
created

FakeHook::getFunctions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Twig;
13
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
class FakeHook extends \Twig_Extension
17
{
18
    /**
19
     * @var bool
20
     */
21
    private $hookAlreadyRegistred = null;
22
23
    /**
24
     * @var string
25
     */
26
    private $env;
27
28
    public function __construct(ContainerInterface $container, string $env)
29
    {
30
        $this->hookAlreadyRegistred = $container->get('twig')->hasExtension('blast_hook');
31
        $this->env = $env;
32
    }
33
34
    public function getFunctions()
35
    {
36
        $functions = [];
37
        if ($this->hookAlreadyRegistred === false) {
38
            $functions[] = new \Twig_SimpleFunction('blast_hook', array($this, 'displayFakeHook'), ['is_safe' => ['html']]);
39
        }
40
41
        return $functions;
42
    }
43
44
    public function displayFakeHook()
45
    {
46
        return $this->env !== 'prod' ? '<!-- Blast hook -->' : '';
47
    }
48
}
49