Completed
Push — master ( 68ef34...daea7e )
by WEBEWEB
01:52
created

FactoryBootstrapTwigExtension::bootstrapIcon()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 37
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 5.3846
c 1
b 0
f 0
cc 8
eloc 20
nc 11
nop 1
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
 * Factory Bootstrap Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension
23
 */
24
class FactoryBootstrapTwigExtension {
25
26
    /**
27
     * Displays a Bootstrap icon.
28
     *
29
     * @param string $name The icon name.
30
     * @return string Returns the Bootstrap icon.
31
     */
32
    public static function bootstrapIcon($name) {
33
34
        // Determines the handler.
35
        $handler = explode(":", $name);
36
37
        // Get and check the parse count.
38
        $parseNb = count($handler);
39
        if ($parseNb < 1 || 2 < $parseNb) {
40
            return "";
41
        }
42
        if (1 === count($handler)) {
43
            $handler = ["g", $name];
44
        }
45
46
        // Initialize the output.
47
        $output = "";
48
49
        // Swith into handler.
50
        switch ($handler[0]) {
51
52
            case "b":
53
            case "g": // Glyphicon
54
                $output = (new GlyphiconComponentTwigExtension())->bootstrapGlyphiconFunction(["name" => $handler[1]]);
55
                break;
56
57
            case "fa": // Font Awesome
58
                $output = (new FontAwesomePluginTwigExtension())->fontAwesomeIconFunction(["name" => $handler[1]]);
59
                break;
60
61
            case "mdi": // Material Design Iconic Font
62
                $output = (new MaterialDesignIconicFontPluginTwigExtension())->materialDesignIconicFontIconFunction(["name" => $handler[1]]);
63
                break;
64
        }
65
66
        // Return the output.
67
        return $output;
68
    }
69
70
}
71