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

AbstractBootstrapTwigExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

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 1
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;
13
14
use Twig_Extension;
15
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface;
16
use WBW\Library\Core\Utility\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::DEFAULT_HREF;
40
41
    /**
42
     * Constructor.
43
     */
44
    protected function __construct() {
45
        // NOTHING TO DO.
46
    }
47
48
    /**
49
     * Displays a Bootstrap simple tag.
50
     *
51
     * @param string $name The tag name.
52
     * @param string $content The tag content
53
     * @return string Returns the Bootstrap tag.
54
     */
55
    final protected function bootstrapSimpleTag($name, $content) {
56
57
        // Initialize the template.
58
        $template = "<" . $name . ">%innerHTML%</" . $name . ">";
59
60
        // Initialize the parameters.
61
        $innerHTML = null !== $content ? $content : "";
62
63
        // Return the HTML.
64
        return StringUtility::replace($template, ["%innerHTML%"], [$innerHTML]);
65
    }
66
67
}
68