Completed
Push — master ( 555845...a5fea9 )
by WEBEWEB
11:15
created

MeteoconsPluginTwigExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
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\Plugin;
13
14
use Twig_SimpleFunction;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\IconRendererTwigExtensionInterface;
16
use WBW\Library\Core\Utility\Argument\ArrayUtility;
17
18
/**
19
 * Meteocons plugin Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
23
 */
24
class MeteoconsPluginTwigExtension extends AbstractPluginTwigExtension implements IconRendererTwigExtensionInterface {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "webeweb.bootstrapbundle.twig.extension.plugin.meteocons";
32
33
    /**
34
     * Constructor.
35
     */
36
    public function __construct() {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Get the Twig functions.
42
     *
43
     * @return array Returns the Twig functions.
44
     */
45
    public function getFunctions() {
46
        return [
47
            new Twig_SimpleFunction("meteoconsIcon", [$this, "meteoconsIconFunction"], ["is_safe" => ["html"]]),
48
        ];
49
    }
50
51
    /**
52
     * Displays a Meteocons icon.
53
     *
54
     * @param array $args The arguments.
55
     * @return string Returns a Meteocons icon.
56
     */
57
    public function meteoconsIconFunction(array $args = []) {
58
        return $this->meteoconsIcon(ArrayUtility::get($args, "name", "A"), ArrayUtility::get($args, "style"));
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function renderIcon($name, $style) {
65
        return $this->meteoconsIconFunction(["name" => $name, "style" => $style]);
66
    }
67
68
}
69