Completed
Push — master ( c1ed37...714f13 )
by Korotkov
02:06
created

TwigFunctions::getTwig()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
namespace App\Http\Supports;
4
5
use Twig_SimpleFunction;
6
use Twig_Environment;
7
use Rudra\ContainerInterface;
8
9
trait TwigFunctions
10
{
11
12 View Code Duplication
    public function templateEngine(string $config): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
13
    {
14
        parent::templateEngine($config);
15
16
        $d = new Twig_SimpleFunction('d', function ($var) {
17
            return d($var);
18
        });
19
20
        $this->getTwig()->addFunction($d);
21
22
        $date = new Twig_SimpleFunction('date', function ($var) {
23
            return date($var);
24
        });
25
26
        $this->getTwig()->addFunction($date);
27
28
        $auth = new Twig_SimpleFunction('auth', function () {
29
            return $this->container()->get('auth')->access(true);
30
        });
31
32
        $this->getTwig()->addFunction($auth);
33
34
35
        $active = new Twig_SimpleFunction('active', function ($var) {
36
            return $this->container()->get('pagination')->activeClass($var);
37
        });
38
39
        $this->getTwig()->addFunction($active);
40
41
        $strstr = new Twig_SimpleFunction('strstr', function ($var) {
42
            return strstr($var, '<a id="strstr" name="strstr"></a>', true);
43
        });
44
45
        $this->getTwig()->addFunction($strstr);
46
47
        if (DEV) {
48
            $debugBarRenderer = $this->container()->get('debugbar')->getJavascriptRenderer();
49
            $this->getTwig()->addGlobal('debugbar', $debugBarRenderer);
50
        }
51
    }
52
53
    /**
54
     * @return Twig_Environment
55
     */
56
    public abstract function getTwig(): Twig_Environment;
57
58
    /**
59
     * @return mixed
60
     */
61
    public abstract function container(): ContainerInterface;
62
}