Completed
Pull Request — master (#170)
by Simonas
04:25
created

SettingExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
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 ONGR\SettingsBundle\Twig;
13
use Doctrine\Common\Cache\PhpFileCache;
14
use ONGR\SettingsBundle\Document\Setting;
15
use ONGR\SettingsBundle\Service\SettingsManager;
16
17
/**
18
 * Class SettingExtension to show settings value on twig.
19
 */
20
class SettingExtension extends \Twig_Extension
21
{
22
    /**
23
     * Extension name
24
     */
25
    const NAME = 'ongr_setting_extension';
26
27
    /**
28
     * @var SettingsManager
29
     */
30
    private $manager;
31
32
    /**
33
     * @param SettingsManager $manager
34
     */
35
    public function __construct($manager)
36
    {
37
        $this->manager = $manager;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getName()
44
    {
45
        return self::NAME;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getFunctions()
52
    {
53
        return [
54
            new \Twig_SimpleFunction('ongr_setting', [$this, 'getSettingValue']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
55
        ];
56
    }
57
58
    /**
59
     * @param string $name
60
     * @param bool   $default
61
     *
62
     * @return mixed
63
     */
64
    public function getSettingValue($name, $default = false)
65
    {
66
        return $this->manager->getValue($name, $default);
67
    }
68
}
69