Completed
Push — master ( 67c65c...9a618a )
by WEBEWEB
06:47
created

AbstractFormTwigExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
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\Form;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Library\Core\Utility\StringUtility;
16
17
/**
18
 * Abstract form Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Form
22
 * @abstract
23
 */
24
abstract class AbstractFormTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays a Bootstrap input mask.
35
     *
36
     * @param string $selector The input mask selector.
37
     * @param boolean $scriptTag Script tag ?
38
     * @param array $arguments The input mask arguments.
39
     * @return string Returns the Bootstrap input mask.
40
     */
41
    final protected function bootstrapInputMask($selector, $scriptTag, array $arguments) {
42
43
        // Initialize the template.
44
        $template = ["$('%selector%').inputmask(%arguments%);"];
45
        if (true === $scriptTag) {
46
            array_unshift($template, "<script type=\"text/javascript\">");
47
            array_push($template, "</script>");
48
        }
49
50
        // Return the HTML.
51
        return StringUtility::replace(implode("\n", $template), ["%selector%", "%arguments%"], [$selector, json_encode($arguments)]);
52
    }
53
54
}
55