Completed
Push — master ( 9276df...2eb3b6 )
by WEBEWEB
01:27
created

GlyphiconTwigExtension::renderIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
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\TwigFunction;
15
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface;
16
use WBW\Library\Core\Argument\ArrayHelper;
17
18
/**
19
 * Glyphicon Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 * @link https://getbootstrap.com/docs/3.3/components/#glyphicons
24
 */
25
class GlyphiconTwigExtension extends AbstractGlyphiconTwigExtension implements IconRendererInterface {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.glyphicon";
33
34
    /**
35
     * Displays a Bootstrap glyphicon.
36
     *
37
     * @param array $args The arguments.
38
     * @return string Returns the Bootstrap glyphicon.
39
     */
40
    public function bootstrapGlyphiconFunction(array $args = []) {
41
        return $this->bootstrapGlyphicon(ArrayHelper::get($args, "name", "home"), ArrayHelper::get($args, "style"));
42
    }
43
44
    /**
45
     * Get the Twig functions.
46
     *
47
     * @return TwigFunction[] Returns the Twig functions.
48
     */
49
    public function getFunctions() {
50
        if (3 === $this->getVersion()) {
51
            return $this->getFunctions3();
52
        }
53
        return [];
54
    }
55
56
    /**
57
     * Get the Twig functions.
58
     *
59
     * @return TwigFunction[] Returns the Twig functions.
60
     */
61
    protected function getFunctions3() {
62
        return [
63
            new TwigFunction("bootstrapGlyphicon", [$this, "bootstrapGlyphiconFunction"], ["is_safe" => ["html"]]),
64
            new TwigFunction("bsGlyphicon", [$this, "bootstrapGlyphiconFunction"], ["is_safe" => ["html"]]),
65
        ];
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function renderIcon($name, $style) {
72
        return $this->bootstrapGlyphiconFunction(["name" => $name, "style" => $style]);
73
    }
74
}
75