Completed
Push — master ( a27d66...168bdb )
by WEBEWEB
05:24
created

ProgressBarTwigExtension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 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\Component;
13
14
use Twig\TwigFilter;
15
use Twig\TwigFunction;
16
use WBW\Bundle\BootstrapBundle\ProgressBar\ProgressBarFactory;
17
18
/**
19
 * Progress bar Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 * @link https://getbootstrap.com/docs/3.3/components/#progress
24
 */
25
class ProgressBarTwigExtension extends AbstractProgressBarTwigExtension {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.progress_bar";
33
34
    /**
35
     * Displays a Bootstrap multiple bars.
36
     *
37
     * @param string[] $progressBars The progress bars.
38
     * @return string Returns the Bootstrap multiple bars.
39
     */
40
    public function bootstrapMultipleBars(array $progressBars) {
41
        $output = implode("", $progressBars);
42
        return str_replace(["</div><div class=\"progress\">"], [""], $output);
43
    }
44
45
    /**
46
     * Displays a Bootstrap progress bar "basic".
47
     *
48
     * @param array $args The arguments.
49
     * @return string Returns the Bootstrap progress bar "basic".
50
     */
51
    public function bootstrapProgressBarBasicFunction(array $args = []) {
52
        return $this->bootstrapProgressBar(ProgressBarFactory::parseBasicProgressBar($args));
53
    }
54
55
    /**
56
     * Displays a Bootstrap progress bar "danger".
57
     *
58
     * @param array $args The arguments.
59
     * @return string Returns the Bootstrap progress bar "danger".
60
     */
61
    public function bootstrapProgressBarDangerFunction(array $args = []) {
62
        return $this->bootstrapProgressBar(ProgressBarFactory::parseDangerProgressBar($args));
63
    }
64
65
    /**
66
     * Displays a Bootstrap progress bar "info".
67
     *
68
     * @param array $args The arguments.
69
     * @return string Returns the Bootstrap progress bar "info".
70
     */
71
    public function bootstrapProgressBarInfoFunction(array $args = []) {
72
        return $this->bootstrapProgressBar(ProgressBarFactory::parseInfoProgressBar($args));
73
    }
74
75
    /**
76
     * Displays a Bootstrap progress bar "success".
77
     *
78
     * @param array $args The arguments.
79
     * @return string Returns the Bootstrap progress bar "success".
80
     */
81
    public function bootstrapProgressBarSuccessFunction(array $args = []) {
82
        return $this->bootstrapProgressBar(ProgressBarFactory::parseSuccessProgressBar($args));
83
    }
84
85
    /**
86
     * Displays a Bootstrap progress bar "warning".
87
     *
88
     * @param array $args The arguments.
89
     * @return string Returns the Bootstrap progress bar "warning".
90
     */
91
    public function bootstrapProgressBarWarningFunction(array $args = []) {
92
        return $this->bootstrapProgressBar(ProgressBarFactory::parseWarningProgressBar($args));
93
    }
94
95
    /**
96
     * Get the Twig filters.
97
     *
98
     * @return TwigFilter[] Returns the Twig filters.
99
     */
100
    public function getFilters() {
101
        return [
102
            new TwigFilter("bootstrapMultipleBars", [$this, "bootstrapMultipleBars"], ["is_safe" => ["html"]]),
103
            new TwigFilter("bsMultipleBars", [$this, "bootstrapMultipleBars"], ["is_safe" => ["html"]]),
104
        ];
105
    }
106
107
    /**
108
     * Get the Twig functions.
109
     *
110
     * @return TwigFunction[] Returns the Twig functions.
111
     */
112
    public function getFunctions() {
113
        return [
114
            new TwigFunction("bootstrapProgressBarBasic", [$this, "bootstrapProgressBarBasicFunction"], ["is_safe" => ["html"]]),
115
            new TwigFunction("bsProgressBarBasic", [$this, "bootstrapProgressBarBasicFunction"], ["is_safe" => ["html"]]),
116
117
            new TwigFunction("bootstrapProgressBarDanger", [$this, "bootstrapProgressBarDangerFunction"], ["is_safe" => ["html"]]),
118
            new TwigFunction("bsProgressBarDanger", [$this, "bootstrapProgressBarDangerFunction"], ["is_safe" => ["html"]]),
119
120
            new TwigFunction("bootstrapProgressBarInfo", [$this, "bootstrapProgressBarInfoFunction"], ["is_safe" => ["html"]]),
121
            new TwigFunction("bsProgressBarInfo", [$this, "bootstrapProgressBarInfoFunction"], ["is_safe" => ["html"]]),
122
123
            new TwigFunction("bootstrapProgressBarSuccess", [$this, "bootstrapProgressBarSuccessFunction"], ["is_safe" => ["html"]]),
124
            new TwigFunction("bsProgressBarSuccess", [$this, "bootstrapProgressBarSuccessFunction"], ["is_safe" => ["html"]]),
125
126
            new TwigFunction("bootstrapProgressBarWarning", [$this, "bootstrapProgressBarWarningFunction"], ["is_safe" => ["html"]]),
127
            new TwigFunction("bsProgressBarWarning", [$this, "bootstrapProgressBarWarningFunction"], ["is_safe" => ["html"]]),
128
129
            new TwigFunction("bootstrapMultipleBars", [$this, "bootstrapMultipleBars"], ["is_safe" => ["html"]]),
130
            new TwigFunction("bsMultipleBars", [$this, "bootstrapMultipleBars"], ["is_safe" => ["html"]]),
131
        ];
132
    }
133
}
134