Completed
Push — master ( 51b9ae...79147b )
by Craig
10:12
created

AssetExtension::pageAddAsset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 4
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\ThemeModule\Twig\Extension;
13
14
use Zikula\ThemeModule\Api\PageAssetApi;
15
use Zikula\ThemeModule\Engine\AssetBag;
16
17
class AssetExtension extends \Twig_Extension
18
{
19
    /**
20
     * @var PageAssetApi
21
     */
22
    private $pageAssetApi;
23
24
    /**
25
     * AssetExtension constructor.
26
     * @param PageAssetApi $pageAssetApi
27
     */
28
    public function __construct(PageAssetApi $pageAssetApi)
29
    {
30
        $this->pageAssetApi = $pageAssetApi;
31
    }
32
33
    /**
34
     * Returns a list of functions to add to the existing list.
35
     *
36
     * @return array An array of functions
37
     */
38
    public function getFunctions()
39
    {
40
        return [
41
            new \Twig_SimpleFunction('pageAddAsset', [$this, 'pageAddAsset']),
42
        ];
43
    }
44
45
    /**
46
     * Zikula allows only the following asset types
47
     * <ul>
48
     *  <li>stylesheet</li>
49
     *  <li>javascript</li>
50
     *  <li>header</li>
51
     *  <li>footer</li>
52
     * </ul>
53
     *
54
     * @param string $type
55
     * @param string $value
56
     * @param int $weight
57
     */
58
    public function pageAddAsset($type, $value, $weight = AssetBag::WEIGHT_DEFAULT)
59
    {
60
        $this->pageAssetApi->add($type, $value, $weight);
61
    }
62
}
63