|
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; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\Component\GlyphiconComponentTwigExtension; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin\FontAwesomePluginTwigExtension; |
|
16
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin\MaterialDesignIconicFontPluginTwigExtension; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Bootstrap renderer Twig extension. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension |
|
23
|
|
|
*/ |
|
24
|
|
|
class BootstrapRendererTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function renderIcon($name, $style = null) { |
|
30
|
|
|
|
|
31
|
|
|
// Determines the handler. |
|
32
|
|
|
$handler = explode(":", $name); |
|
33
|
|
|
|
|
34
|
|
|
// Get and check the parse count. |
|
35
|
|
|
$parseNb = count($handler); |
|
36
|
|
|
if ($parseNb < 1 || 2 < $parseNb) { |
|
37
|
|
|
return ""; |
|
38
|
|
|
} |
|
39
|
|
|
if (1 === count($handler)) { |
|
40
|
|
|
$handler = ["g", $name]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Initialize the output. |
|
44
|
|
|
$output = ""; |
|
45
|
|
|
|
|
46
|
|
|
// Swith into handler. |
|
47
|
|
|
switch ($handler[0]) { |
|
48
|
|
|
|
|
49
|
|
|
case "b": // Bootstrap |
|
50
|
|
|
case "g": // Glyphicon |
|
51
|
|
|
$output = (new GlyphiconComponentTwigExtension())->renderIcon($handler[1], $style); |
|
52
|
|
|
break; |
|
53
|
|
|
|
|
54
|
|
|
case "fa": // Font Awesome |
|
55
|
|
|
$output = (new FontAwesomePluginTwigExtension())->renderIcon($handler[1], $style); |
|
56
|
|
|
break; |
|
57
|
|
|
|
|
58
|
|
|
case "zmdi": // Material Design Iconic Font |
|
59
|
|
|
$output = (new MaterialDesignIconicFontPluginTwigExtension())->renderIcon($handler[1], $style); |
|
60
|
|
|
break; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// Return the output. |
|
64
|
|
|
return $output; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|