Completed
Push — master ( fe56e6...5cceca )
by WEBEWEB
04:07
created

GridTwigExtension::bootstrapGridFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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\Grid;
13
14
use Twig_SimpleFunction;
15
use WBW\Library\Core\Utility\ArrayUtility;
16
17
/**
18
 * Grid Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Grid
22
 * @final
23
 */
24
final class GridTwigExtension extends AbstractGridTwigExtension {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.grid.grid";
32
33
    /**
34
     * Constructor.
35
     */
36
    public function __construct() {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Displays a Bootstrap grid.
42
     *
43
     * @param array $args The arguments.
44
     * @return string Returns the Bootstrap grid.
45
     */
46
    public function bootstrapGridFunction(array $args = []) {
47
48
        // Initialize the output.
49
        $output = [];
50
51
        $output[] = $this->bootstrapStackedGridFunction($args);
52
        $output[] = $this->bootstrapOffsetGridFunction($args);
53
        $output[] = $this->bootstrapPushGridFunction($args);
54
        $output[] = $this->bootstrapPullGridFunction($args);
55
56
        // Return the output.
57
        return trim(implode(" ", $output));
58
    }
59
60
    /**
61
     * Displays a Bootstrap offset grid.
62
     *
63
     * @param array $args The arguments.
64
     * @return string Returns the Bootstrap offset grid.
65
     */
66
    public function bootstrapOffsetGridFunction(array $args = []) {
67
        return $this->bootstrapGrid(ArrayUtility::get($args, "lgOffset"), ArrayUtility::get($args, "mdOffset"), ArrayUtility::get($args, "smOffset"), ArrayUtility::get($args, "xsOffset"), "offset-");
68
    }
69
70
    /**
71
     * Displays a Bootstrap pull grid.
72
     *
73
     * @param array $args The arguments.
74
     * @return string Returns the Bootstrap pull grid.
75
     */
76
    public function bootstrapPullGridFunction(array $args = []) {
77
        return $this->bootstrapGrid(ArrayUtility::get($args, "lgPull"), ArrayUtility::get($args, "mdPull"), ArrayUtility::get($args, "smPull"), ArrayUtility::get($args, "xsPull"), "pull-");
78
    }
79
80
    /**
81
     * Displays a Bootstrap push grid.
82
     *
83
     * @param array $args The arguments.
84
     * @return string Returns the Bootstrap push grid.
85
     */
86
    public function bootstrapPushGridFunction(array $args = []) {
87
        return $this->bootstrapGrid(ArrayUtility::get($args, "lgPush"), ArrayUtility::get($args, "mdPush"), ArrayUtility::get($args, "smPush"), ArrayUtility::get($args, "xsPush"), "push-");
88
    }
89
90
    /**
91
     * Displays a Bootstrap stacked-to-horizontal grid.
92
     *
93
     * @param array $args The arguments.
94
     * @return string Returns the Bootstrap stacked-to-horizontal grid.
95
     */
96
    public function bootstrapStackedGridFunction(array $args = []) {
97
        return $this->bootstrapGrid(ArrayUtility::get($args, "lg"), ArrayUtility::get($args, "md"), ArrayUtility::get($args, "sm"), ArrayUtility::get($args, "xs"), "");
98
    }
99
100
    /**
101
     * Get the Twig functions.
102
     *
103
     * @return array Returns the Twig functions.
104
     */
105
    public function getFunctions() {
106
        return [
107
            new Twig_SimpleFunction("bootstrapGrid", [$this, "bootstrapGridFunction"], ["is_safe" => ["html"]]),
108
            new Twig_SimpleFunction("bootstrapOffsetGrid", [$this, "bootstrapOffsetGridFunction"], ["is_safe" => ["html"]]),
109
            new Twig_SimpleFunction("bootstrapPullGrid", [$this, "bootstrapPullGridFunction"], ["is_safe" => ["html"]]),
110
            new Twig_SimpleFunction("bootstrapPushGrid", [$this, "bootstrapPushGridFunction"], ["is_safe" => ["html"]]),
111
            new Twig_SimpleFunction("bootstrapStackedGrid", [$this, "bootstrapStackedGridFunction"], ["is_safe" => ["html"]]),
112
        ];
113
    }
114
115
}
116