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\Plugin; |
13
|
|
|
|
14
|
|
|
use Twig_Environment; |
15
|
|
|
use WBW\Bundle\CoreBundle\Icon\MaterialDesignIconicFontIconInterface; |
16
|
|
|
use WBW\Bundle\CoreBundle\Icon\MaterialDesignIconicFontIconRenderer; |
17
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\AbstractTwigExtension; |
18
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract Material Design Iconic Font Twig extension. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\Core\Twig\Extension\Plugin |
25
|
|
|
* @abstract |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractMaterialDesignIconicFontTwigExtension extends AbstractTwigExtension { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Constructor. |
31
|
|
|
* |
32
|
|
|
* @param Twig_Environment $twigEnvironment The twig environment. |
33
|
|
|
*/ |
34
|
|
|
protected function __construct(Twig_Environment $twigEnvironment) { |
35
|
|
|
parent::__construct($twigEnvironment); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Displays a Material Design Iconic Font icon. |
40
|
|
|
* |
41
|
|
|
* @param MaterialDesignIconicFontIconInterface $icon The icon. |
42
|
|
|
* @return string Returns the Material Design Iconic Font icon. |
43
|
|
|
*/ |
44
|
|
|
protected function materialDesignIconicFontIcon(MaterialDesignIconicFontIconInterface $icon) { |
45
|
|
|
|
46
|
|
|
// Initialize the values. |
47
|
|
|
$sizes = ["lg", "2x", "3x", "4x", "5x"]; |
|
|
|
|
48
|
|
|
$borders = ["border", "border-circle"]; |
|
|
|
|
49
|
|
|
$pulls = ["left", "right"]; |
|
|
|
|
50
|
|
|
$spins = ["spin", "spin-reverse"]; |
|
|
|
|
51
|
|
|
$rotates = ["90", "180", "270"]; |
|
|
|
|
52
|
|
|
$flips = ["horizontal", "vertical"]; |
|
|
|
|
53
|
|
|
|
54
|
|
|
// Initialize the attributes. |
55
|
|
|
$attributes = []; |
56
|
|
|
|
57
|
|
|
$attributes["class"][] = "zmdi"; |
58
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderName($icon); |
|
|
|
|
59
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderSize($icon); |
|
|
|
|
60
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderFixedWidth($icon); |
|
|
|
|
61
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderBorder($icon); |
|
|
|
|
62
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderPull($icon); |
|
|
|
|
63
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderSpin($icon); |
|
|
|
|
64
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderRotate($icon); |
|
|
|
|
65
|
|
|
$attributes["class"][] = MaterialDesignIconicFontIconRenderer::renderFlip($icon); |
|
|
|
|
66
|
|
|
$attributes["style"] = MaterialDesignIconicFontIconRenderer::renderStyle($icon); |
67
|
|
|
|
68
|
|
|
// Return the HTML. |
69
|
|
|
return static::coreHTMLElement("i", null, $attributes); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Displays a Material Design Iconic Font list. |
74
|
|
|
* |
75
|
|
|
* @param array|string $items The items. |
76
|
|
|
* @return string Returns the Material Design Iconic Font list. |
77
|
|
|
*/ |
78
|
|
|
protected function materialDesignIconicFontList($items) { |
79
|
|
|
|
80
|
|
|
// Initialize the parameters. |
81
|
|
|
$innerHTML = true === is_array($items) ? implode("\n", $items) : $items; |
82
|
|
|
|
83
|
|
|
// Return the HTML. |
84
|
|
|
return static::coreHTMLElement("ul", $innerHTML, ["class" => "zmdi-hc-ul"]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Displays a Material Design Iconic Font list icon. |
89
|
|
|
* |
90
|
|
|
* @param string $icon The icon. |
91
|
|
|
* @param string $content The content. |
92
|
|
|
* @return string Returns the Material Design Iconic Font list icon. |
93
|
|
|
*/ |
94
|
|
|
protected function materialDesignIconicFontListIcon($icon, $content) { |
95
|
|
|
|
96
|
|
|
// Initialize the parameters. |
97
|
|
|
$glyphicon = null !== $icon ? StringHelper::replace($icon, ["class=\"zmdi"], ["class=\"zmdi-hc-li zmdi"]) : ""; |
98
|
|
|
$innerHTML = null !== $content ? $content : ""; |
99
|
|
|
|
100
|
|
|
// Return the HTML. |
101
|
|
|
return static::coreHTMLElement("li", $glyphicon . $innerHTML); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.