fontAwesomeIconFunction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Assets;
13
14
use Twig\TwigFilter;
15
use Twig\TwigFunction;
16
use WBW\Bundle\CoreBundle\Factory\IconFactory;
17
use WBW\Library\Symfony\Renderer\Assets\IconRendererInterface;
18
19
/**
20
 * Font Awesome Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb>
23
 * @package WBW\Bundle\CoreBundle\Twig\Extension\Assets
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.assets.font_awesome";
33
34
    /**
35
     * Display 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 = []): string {
41
        return $this->fontAwesomeIcon(IconFactory::parseFontAwesomeIcon($args));
42
    }
43
44
    /**
45
     * Display 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): string {
51
        return $this->fontAwesomeList($items);
52
    }
53
54
    /**
55
     * Display a Font Awesome list icon.
56
     *
57
     * @param string $icon The icon.
58
     * @param string|null $content The content.
59
     * @return string Returns the Font Awesome list icon.
60
     */
61
    public function fontAwesomeListIconFilter(string $icon, ?string $content): string {
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(): array {
71
72
        return [
73
            new TwigFilter("fontAwesomeList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]),
74
            new TwigFilter("faList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]),
75
76
            new TwigFilter("fontAwesomeListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]),
77
            new TwigFilter("faListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]),
78
        ];
79
    }
80
81
    /**
82
     * Get the Twig functions.
83
     *
84
     * @return TwigFunction[] Returns the Twig functions.
85
     */
86
    public function getFunctions(): array {
87
88
        return [
89
            new TwigFunction("fontAwesomeIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]),
90
            new TwigFunction("faIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]),
91
        ];
92
    }
93
94
    /**
95
     * {@inheritDoc}
96
     */
97
    public function renderIcon(?string $name, ?string $style): string {
98
        return $this->fontAwesomeIconFunction(["name" => $name, "style" => $style]);
99
    }
100
}
101