Completed
Push — master ( 4b8173...652bbf )
by WEBEWEB
01:31
created

FontAwesomeTwigExtension::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 core-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\CoreBundle\Twig\Extension\Asset;
13
14
use Twig\TwigFilter;
15
use Twig\TwigFunction;
16
use WBW\Bundle\CoreBundle\Icon\IconFactory;
17
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface;
18
19
/**
20
 * Font Awesome Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\CoreBundle\Twig\Extension\Asset
24
 */
25
class FontAwesomeTwigExtension extends AbstractFontAwesomeTwigExtension implements IconRendererInterface {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "wbw.core.twig.extension.asset.font_awesome";
33
34
    /**
35
     * Displays a Font Awesome icon.
36
     *
37
     * @param array $args The arguments.
38
     * @return string Returns the Font Awesome icon.
39
     */
40
    public function fontAwesomeIconFunction(array $args = []) {
41
        return $this->fontAwesomeIcon(IconFactory::parseFontAwesomeIcon($args));
42
    }
43
44
    /**
45
     * Displays a Font Awesome list.
46
     *
47
     * @param array|string $items The items.
48
     * @return string Returns the Font Awesome list.
49
     */
50
    public function fontAwesomeListFilter($items) {
51
        return $this->fontAwesomeList($items);
52
    }
53
54
    /**
55
     * Displays a Font Awesome list icon.
56
     *
57
     * @param string $icon The icon.
58
     * @param string $content The content.
59
     * @return string Returns the Font Awesome list icon.
60
     */
61
    public function fontAwesomeListIconFilter($icon, $content) {
62
        return $this->fontAwesomeListIcon($icon, $content);
63
    }
64
65
    /**
66
     * Get the Twig filters.
67
     *
68
     * @return TwigFilter[] Returns the Twig filters.
69
     */
70
    public function getFilters() {
71
        return [
72
            new TwigFilter("fontAwesomeList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]),
73
            new TwigFilter("faList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]),
74
75
            new TwigFilter("fontAwesomeListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]),
76
            new TwigFilter("faListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]),
77
        ];
78
    }
79
80
    /**
81
     * Get the Twig functions.
82
     *
83
     * @return TwigFunction[] Returns the Twig functions.
84
     */
85
    public function getFunctions() {
86
        return [
87
            new TwigFunction("fontAwesomeIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]),
88
            new TwigFunction("faIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]),
89
        ];
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function renderIcon($name, $style) {
96
        return $this->fontAwesomeIconFunction(["name" => $name, "style" => $style]);
97
    }
98
}
99