Completed
Push — master ( 4655cc...858fcc )
by WEBEWEB
01:40
created

IconUITwigExtension::renderIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2017 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\AdminBSBBundle\Twig\Extension\UI;
13
14
use Twig_SimpleFunction;
15
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractAdminBSBTwigExtension;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\IconRendererTwigExtensionInterface;
17
use WBW\Library\Core\Utility\Argument\ArrayUtility;
18
19
/**
20
 * Icon UI Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI
24
 */
25
class IconUITwigExtension extends AbstractUITwigExtension implements IconRendererTwigExtensionInterface {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "webeweb.bundle.adminbsbbundle.twig.extension.ui.icon";
33
34
    /**
35
     * Constructor.
36
     */
37
    public function __construct() {
38
        parent::__construct();
39
    }
40
41
    /**
42
     * Displays an AdminBSB basic icon.
43
     *
44
     * @param array $args The arguments.
45
     * @return string Returns the AdminBSB basic icon.
46
     */
47
    public function adminBSBBasicIconFunction(array $args = []) {
48
        return $this->adminBSBIcon(ArrayUtility::get($args, "name"), ArrayUtility::get($args, "style"));
49
    }
50
51
    /**
52
     * Get the Twig functions.
53
     *
54
     * @return array Returns the Twig functions.
55
     */
56
    public function getFunctions() {
57
        return [
58
            new Twig_SimpleFunction("adminBSBBasicIcon", [$this, "adminBSBBasicIconFunction"], ["is_safe" => ["html"]]),
59
            new Twig_SimpleFunction("adminBSBMaterialDesignIcon", [$this, "adminBSBMaterialDesignIconFunction"], ["is_safe" => ["html"]]),
60
        ];
61
    }
62
63
    /**
64
     * Displays an AdminBSB material design icon.
65
     *
66
     * @param array $args The arguments.
67
     * @return string Returns the AdminBSB material design icon.
68
     */
69
    public function adminBSBMaterialDesignIconFunction(array $args = []) {
70
        return $this->adminBSBIcon(ArrayUtility::get($args, "name"), ArrayUtility::get($args, "style"), AbstractAdminBSBTwigExtension::fixColor(ArrayUtility::get($args, "color"), "col-"));
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function renderIcon($name, $style) {
77
        return $this->adminBSBBasicIconFunction(["name" => $name, "style" => $style]);
78
    }
79
80
}
81