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

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\Plugin;
13
14
use Twig_SimpleFilter;
15
use Twig_SimpleFunction;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\IconRendererTwigExtensionInterface;
17
use WBW\Library\Core\Utility\Argument\ArrayUtility;
18
use WBW\Library\Core\Utility\Argument\StringUtility;
19
20
/**
21
 * Material Design Iconic Font plugin Twig extension.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
25
 */
26
class MaterialDesignIconicFontPluginTwigExtension extends AbstractPluginTwigExtension implements IconRendererTwigExtensionInterface {
27
28
    /**
29
     * Service name.
30
     *
31
     * @var string
32
     */
33
    const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.plugin.materialdesigniconicfont";
34
35
    /**
36
     * Constructor.
37
     */
38
    public function __construct() {
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Get the Twig filters.
44
     *
45
     * @return Twig_SimpleFilter[] Returns the Twig filters.
46
     */
47
    public function getFilters() {
48
        return [
49
            new Twig_SimpleFilter("materialDesignIconicFontList", [$this, "materialDesignIconicFontListFilter"], ["is_safe" => ["html"]]),
50
            new Twig_SimpleFilter("materialDesignIconicFontListIcon", [$this, "materialDesignIconicFontListIconFilter"], ["is_safe" => ["html"]]),
51
        ];
52
    }
53
54
    /**
55
     * Get the Twig functions.
56
     *
57
     * @return array Returns the Twig functions.
58
     */
59
    public function getFunctions() {
60
        return [
61
            new Twig_SimpleFunction("materialDesignIconicFontIcon", [$this, "materialDesignIconicFontIconFunction"], ["is_safe" => ["html"]]),
62
        ];
63
    }
64
65
    /**
66
     * Displays a Font Awesome.
67
     *
68
     * @param array $args The arguments.
69
     * @return Returns a Font Awesome.
70
     */
71
    public function materialDesignIconicFontIconFunction(array $args = []) {
72
        return $this->materialDesignIconicFontIcon(ArrayUtility::get($args, "name", "home"), ArrayUtility::get($args, "size"), ArrayUtility::get($args, "fixedWidth", false), ArrayUtility::get($args, "border", false), ArrayUtility::get($args, "pull"), ArrayUtility::get($args, "spin"), ArrayUtility::get($args, "rotate"), ArrayUtility::get($args, "flip"), ArrayUtility::get($args, "style"));
73
    }
74
75
    /**
76
     * Displays a Material Design Iconic Font list.
77
     *
78
     * @param array|string $items The list items.
79
     * @return string Returns the Material Design Iconic Font list.
80
     */
81
    public function materialDesignIconicFontListFilter($items) {
82
83
        // Initialize the template.
84
        $template = "<ul class=\"zmdi-hc-ul\">%innerHTML%</ul>";
85
86
        // Initialize the parameters.
87
        $innerHTML = true === is_array($items) ? implode("\n", $items) : $items;
88
89
        // Return the HTML.
90
        return StringUtility::replace($template, ["%innerHTML%"], [$innerHTML]);
91
    }
92
93
    /**
94
     * Displays a Material Design Iconic Font list icon.
95
     *
96
     * @param string $icon The Material Design Iconic Fonticon.
97
     * @param string $content The content.
98
     * @return string Returns the Material Design Iconic Font list icon.
99
     */
100
    public function materialDesignIconicFontListIconFilter($icon, $content) {
101
102
        // Initialize the template.
103
        $template = "<li>%glyphicon%%innerHTML%</li>";
104
105
        // Initialize the parameters.
106
        $glyphicon = null !== $icon ? StringUtility::replace($icon, ["class=\"zmdi"], ["class=\"zmdi-hc-li zmdi"]) : "";
107
        $innerHTML = null !== $content ? $content : "";
108
109
        // Return the HTML.
110
        return StringUtility::replace($template, ["%glyphicon%", "%innerHTML%"], [$glyphicon, $innerHTML]);
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function renderIcon($name, $style) {
117
        return $this->materialDesignIconicFontIconFunction(["name" => $name, "style" => $style]);
118
    }
119
120
}
121