Completed
Push — master ( a6151b...66e545 )
by WEBEWEB
01:50
created

GlyphiconComponentTwigExtension::renderIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
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 WBW\Bundle\BootstrapBundle\Twig\Extension\Component;
13
14
use Twig_SimpleFunction;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\IconRendererTwigExtensionInterface;
16
use WBW\Library\Core\Utility\Argument\ArrayUtility;
17
18
/**
19
 * Glyphicon component Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 */
24
class GlyphiconComponentTwigExtension extends AbstractComponentTwigExtension implements IconRendererTwigExtensionInterface {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.component.glyphicon";
32
33
    /**
34
     * Constructor.
35
     */
36
    public function __construct() {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Displays a Bootstrap glyphicon.
42
     *
43
     * @param array $args The arguments.
44
     * @return string Returns the Bootstrap glyphicon.
45
     */
46
    public function bootstrapGlyphiconFunction(array $args = []) {
47
        return $this->bootstrapGlyphicon(ArrayUtility::get($args, "name", "home"), ArrayUtility::get($args, "style"));
48
    }
49
50
    /**
51
     * Get the Twig functions.
52
     *
53
     * @return Twig_SimpleFunction[] Returns the Twig functions.
54
     */
55
    public function getFunctions() {
56
        return [
57
            new Twig_SimpleFunction("bootstrapGlyphicon", [$this, "bootstrapGlyphiconFunction"], ["is_safe" => ["html"]]),
58
        ];
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function renderIcon($name, $style) {
65
        return $this->bootstrapGlyphiconFunction(["name" => $name, "style" => $style]);
66
    }
67
68
}
69