Completed
Push — master ( a3d6f2...653760 )
by WEBEWEB
02:00
created

bootstrapDOMObject()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 3
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 Twig_Extension;
15
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface;
16
use WBW\Library\Core\Utility\Argument\StringUtility;
17
18
/**
19
 * Abstract Bootstrap Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension
23
 * @abstract
24
 */
25
abstract class AbstractBootstrapTwigExtension extends Twig_Extension {
26
27
    /**
28
     * Default content.
29
     *
30
     * @var string
31
     */
32
    const DEFAULT_CONTENT = "&nbsp;";
33
34
    /**
35
     * Default href.
36
     *
37
     * @var string
38
     */
39
    const DEFAULT_HREF = NavigationInterface::NAVIGATION_HREF_DEFAULT;
40
41
    /**
42
     * Constructor.
43
     */
44
    protected function __construct() {
45
        // NOTHING TO DO.
46
    }
47
48
    /**
49
     * Displays a Bootstrap DOM object.
50
     *
51
     * @param string $object The object.
52
     * @param string $attrs The attributes.
53
     * @param string $content The content.
54
     * @return string Returns the Bootstrap DOM object.
55
     */
56
    protected function bootstrapDOMObject($object, $attrs, $content) {
57
58
        // Initialize the templates.
59
        $template = "<%object%%attributes%>%innerHTML%</%object%>";
60
61
        // Initialize the parameters.
62
        $attributes = null !== $attrs ? " " . trim($attrs) : "";
63
        $innerHTML  = null !== $content ? trim($content) : "";
64
65
        // Return the HTML.
66
        return StringUtility::replace($template, ["%object%", "%attributes%", "%innerHTML%"], [$object, $attributes, $innerHTML]);
67
    }
68
69
}
70