Completed
Push — master ( 586888...6f962e )
by Paweł
16s
created

SettingsExtension::getThemeSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ThemeBundle\Twig;
13
14
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
15
use Sylius\Bundle\ThemeBundle\Settings\ThemeSettingsManagerInterface;
16
17
/**
18
 * @author Kamil Kokot <[email protected]>
19
 */
20
final class SettingsExtension extends \Twig_Extension
21
{
22
    /**
23
     * @var ThemeContextInterface
24
     */
25
    private $themeContext;
26
27
    /**
28
     * @var ThemeSettingsManagerInterface
29
     */
30
    private $themeSettingsManager;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function __construct(ThemeContextInterface $themeContext, ThemeSettingsManagerInterface $themeSettingsManager)
36
    {
37
        $this->themeContext = $themeContext;
38
        $this->themeSettingsManager = $themeSettingsManager;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getFunctions()
45
    {
46
        return [
47
            new \Twig_SimpleFunction('sylius_theme_settings', [$this, 'getThemeSettings']),
48
        ];
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getThemeSettings()
55
    {
56
        $theme = $this->themeContext->getTheme();
57
58
        if (null === $theme) {
59
            return [];
60
        }
61
62
        return $this->themeSettingsManager->load($theme);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getName()
69
    {
70
        return 'sylius_theme_settings';
71
    }
72
}
73