|
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\Settings; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface; |
|
15
|
|
|
use Sylius\Bundle\SettingsBundle\Model\SettingsInterface; |
|
16
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
|
17
|
|
|
use Sylius\Component\Registry\ServiceRegistryInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Kamil Kokot <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class ThemeSettingsManager implements ThemeSettingsManagerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var SettingsManagerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $decoratedSettingsManager; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ServiceRegistryInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $schemaRegistry; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ThemeSettingsSchemaProviderInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $themeSettingsSchemaProvider; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param SettingsManagerInterface $decoratedSettingsManager |
|
41
|
|
|
* @param ServiceRegistryInterface $schemaRegistry |
|
42
|
|
|
* @param ThemeSettingsSchemaProviderInterface $themeSettingsSchemaProvider |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
SettingsManagerInterface $decoratedSettingsManager, |
|
46
|
|
|
ServiceRegistryInterface $schemaRegistry, |
|
47
|
|
|
ThemeSettingsSchemaProviderInterface $themeSettingsSchemaProvider |
|
48
|
|
|
) { |
|
49
|
|
|
$this->decoratedSettingsManager = $decoratedSettingsManager; |
|
50
|
|
|
$this->schemaRegistry = $schemaRegistry; |
|
51
|
|
|
$this->themeSettingsSchemaProvider = $themeSettingsSchemaProvider; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function load(ThemeInterface $theme, $namespace = null) |
|
58
|
|
|
{ |
|
59
|
|
|
$schemaAlias = sprintf('theme_%s', $theme->getCode()); |
|
60
|
|
|
|
|
61
|
|
|
if (!$this->schemaRegistry->has($schemaAlias)) { |
|
62
|
|
|
$schema = $this->themeSettingsSchemaProvider->getSchema($theme); |
|
63
|
|
|
|
|
64
|
|
|
$this->schemaRegistry->register($schemaAlias, $schema); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->decoratedSettingsManager->load($schemaAlias, $namespace); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function save(SettingsInterface $settings) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->decoratedSettingsManager->save($settings); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|