Completed
Push — master ( fa4abd...e15627 )
by WEBEWEB
02:20
created

AbstractPluginTwigExtension::fontAwesome()   D

Complexity

Conditions 8
Paths 128

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 4.6666
c 0
b 0
f 0
cc 8
eloc 15
nc 128
nop 7
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 WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Library\Core\Utility\Argument\StringUtility;
16
17
/**
18
 * Abstract plugin Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
22
 * @abstract
23
 */
24
abstract class AbstractPluginTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        // NOTHING TO DO.
31
    }
32
33
    /**
34
     * Displays a Bootstrap input mask.
35
     *
36
     * @param string $selector The input mask selector.
37
     * @param string $mask The input mask.
38
     * @param boolean $scriptTag Script tag ?
39
     * @param array $options The input mask options.
40
     * @return string Returns the Bootstrap input mask.
41
     */
42
    protected function bootstrapInputMask($selector, $mask, $scriptTag, array $options) {
43
44
        // Initialize the template.
45
        $template = ["$('%selector%').inputmask(\"%mask%\",%arguments%);"];
46
        if (true === $scriptTag) {
47
            array_unshift($template, "<script type=\"text/javascript\">");
48
            array_push($template, "</script>");
49
        }
50
51
        // Return the HTML.
52
        return StringUtility::replace(implode("\n", $template), ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]);
53
    }
54
55
    /**
56
     * Displays a Font Awesome.
57
     *
58
     * @param string $style The Font Awesome style.
59
     * @param string $name The Font Awesome name.
60
     * @param string $size The Font Awesome size.
61
     * @param boolean $fixedWidth Fixed width ?
62
     * @param boolean $bordered Bordered ?
63
     * @param string $pull The Font Awesome pull.
64
     * @param string $animated The Font Awesome animation.
65
     * @return string Returns the Font Awesome.
66
     */
67
    protected function fontAwesome($style, $name, $size, $fixedWidth, $bordered, $pull, $animated) {
68
69
        // Initialize the values.
70
        $styles   = ["", "s", "r", "l", "b"];
71
        $sizes    = ["xs", "sm", "lg", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x"];
72
        $pulls    = ["left", "right"];
73
        $animates = ["spin", "pulse"];
74
75
        // Initialize the template.
76
        $template = "<i %attributes%></i>";
77
78
        // Initialize the attributes.
79
        $attributes = [];
80
81
        $attributes["class"][] = true === in_array($style, $styles) ? "fa" . $style : "fa";
82
        $attributes["class"][] = null !== $name ? "fa-" . $name : null;
83
        $attributes["class"][] = true === in_array($size, $sizes) ? "fa-" . $size : null;
84
        $attributes["class"][] = true === $fixedWidth ? "fa-fw" : null;
85
        $attributes["class"][] = true === $bordered ? "fa-border" : null;
86
        $attributes["class"][] = true === in_array($pull, $pulls) ? "fa-pull-" . $pull : null;
87
        $attributes["class"][] = true === in_array($animated, $animates) ? "fa-" . $animated : null;
88
89
        // Return the HTML.
90
        return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]);
91
    }
92
93
}
94