Completed
Push — master ( 5a1160...cfcd01 )
by WEBEWEB
01:41
created

getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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