Issues (3627)

Templating/Twig/Extension/AssetExtension.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CoreBundle\Templating\Twig\Extension;
13
14
use Mautic\CoreBundle\Templating\Helper\AssetsHelper;
15
use Twig_Extension;
16
use Twig_SimpleFunction;
17
18
class AssetExtension extends Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

18
class AssetExtension extends /** @scrutinizer ignore-deprecated */ Twig_Extension
Loading history...
19
{
20
    /**
21
     * @var AssetsHelper
22
     */
23
    protected $assetsHelper;
24
25
    /**
26
     * AssetExtension constructor.
27
     */
28
    public function __construct(AssetsHelper $assetsHelper)
29
    {
30
        $this->assetsHelper = $assetsHelper;
31
    }
32
33
    /**
34
     * @see Twig_Extension::getFunctions()
35
     */
36
    public function getFunctions()
37
    {
38
        return [
39
            'outputScripts'           => new Twig_SimpleFunction('outputScripts', [$this, 'outputScripts'], ['is_safe' => ['all']]),
40
            'outputHeadDeclarations'  => new Twig_SimpleFunction('outputHeadDeclarations', [$this, 'outputHeadDeclarations'], ['is_safe' => ['all']]),
41
            'getAssetUrl'             => new Twig_SimpleFunction('getAssetUrl', [$this, 'getAssetUrl'], ['is_safe' => ['html']]),
42
            'outputStyles'            => new Twig_SimpleFunction('outputStyles', [$this, 'outputStyles'], ['is_safe' => ['html']]),
43
            'outputSystemScripts'     => new Twig_SimpleFunction('outputSystemScripts', [$this, 'outputSystemScripts'], ['is_safe' => ['html']]),
44
            'outputSystemStylesheets' => new Twig_SimpleFunction('outputSystemStylesheets', [$this, 'outputSystemStylesheets'], ['is_safe' => ['html']]),
45
        ];
46
    }
47
48
    public function getName()
49
    {
50
        return 'coreasset';
51
    }
52
53
    public function outputSystemStylesheets()
54
    {
55
        ob_start();
56
57
        $this->assetsHelper->outputSystemStylesheets();
58
59
        return ob_get_clean();
60
    }
61
62
    /**
63
     * @param bool $includeEditor
64
     *
65
     * @return string
66
     */
67
    public function outputSystemScripts($includeEditor = false)
68
    {
69
        ob_start();
70
71
        $this->assetsHelper->outputSystemScripts($includeEditor);
72
73
        return ob_get_clean();
74
    }
75
76
    public function outputScripts($name)
77
    {
78
        ob_start();
79
80
        $this->assetsHelper->outputScripts($name);
81
82
        return ob_get_clean();
83
    }
84
85
    public function outputStyles()
86
    {
87
        ob_start();
88
89
        $this->assetsHelper->outputStyles();
90
91
        return ob_get_clean();
92
    }
93
94
    public function outputHeadDeclarations()
95
    {
96
        ob_start();
97
98
        $this->assetsHelper->outputHeadDeclarations();
99
100
        return ob_get_clean();
101
    }
102
103
    public function getAssetUrl($path, $packageName = null, $version = null, $absolute = false, $ignorePrefix = false)
104
    {
105
        return $this->assetsHelper->getUrl($path, $packageName, $version, $absolute, $ignorePrefix);
106
    }
107
}
108