Completed
Push — master ( 662165...7658f4 )
by WEBEWEB
02:47
created

setRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\Plugin;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\BootstrapRendererTwigExtension;
16
use WBW\Library\Core\Utility\Argument\StringUtility;
17
18
/**
19
 * Abstract jQuery input mask Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
23
 * @abstract
24
 */
25
abstract class AbstractJQueryInputMaskTwigExtension extends AbstractBootstrapTwigExtension {
26
27
    /**
28
     * Renderer.
29
     *
30
     * @var BootstrapRendererTwigExtension
31
     */
32
    private $renderer;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param BootstrapRendererTwigExtension $renderer The renderer.
38
     */
39
    protected function __construct(BootstrapRendererTwigExtension $renderer) {
40
        parent::__construct();
41
        $this->setRenderer($renderer);
42
    }
43
44
    /**
45
     * Get the renderer.
46
     *
47
     * @return BootstrapRendererTwigExtension Returns the renderer.
48
     */
49
    public function getRenderer() {
50
        return $this->renderer;
51
    }
52
53
    /**
54
     * Displays a jQuery input mask.
55
     *
56
     * @param string $selector The input mask selector.
57
     * @param string $mask The input mask.
58
     * @param array $options The input mask options.
59
     * @param boolean $scriptTag Script tag ?
60
     * @return string Returns the jQuery input mask.
61
     */
62
    protected function jQueryInputMask($selector, $mask, array $options, $scriptTag) {
63
64
        // Initialize the template.
65
        $template = "$('%selector%').inputmask(\"%mask%\",%arguments%);";
66
67
        // Initialize the parameters.
68
        $innerHTML = StringUtility::replace($template, ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]);
69
70
        // Return the HTML
71
        if (true === $scriptTag) {
72
            return self::bootstrapHTMLElement("script", "\n" . $innerHTML . "\n", ["type" => "text/javascript"]);
73
        }
74
        return $innerHTML;
75
    }
76
77
    /**
78
     * Set the renderer.
79
     *
80
     * @param BootstrapRendererTwigExtension $renderer The renderer.
81
     * @return AbstractJQueryInputMaskTwigExtension Returns this jQuery Twig extension.
82
     */
83
    protected function setRenderer(BootstrapRendererTwigExtension $renderer) {
84
        $this->renderer = $renderer;
85
        return $this;
86
    }
87
88
}
89