|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the sauls/components-bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Saulius Vaičeliūnas <[email protected]> |
|
6
|
|
|
* @link http://saulius.vaiceliunas.lt |
|
7
|
|
|
* @copyright 2018 |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Sauls\Bundle\Components\DependencyInjection; |
|
14
|
|
|
|
|
15
|
|
|
use function Sauls\Component\Helper\array_get_value; |
|
16
|
|
|
use Sauls\Component\Widget\View\ViewInterface; |
|
17
|
|
|
use Sauls\Component\Widget\WidgetInterface; |
|
18
|
|
|
use Symfony\Component\Config\FileLocator; |
|
19
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
23
|
|
|
|
|
24
|
|
|
class SaulsComponentsExtension extends Extension |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
|
29
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
|
30
|
|
|
*/ |
|
31
|
5 |
|
public function load(array $configs, ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
5 |
|
$configuration = $this->getConfiguration($configs, $container); |
|
35
|
5 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
36
|
|
|
|
|
37
|
5 |
|
$loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); |
|
38
|
|
|
|
|
39
|
5 |
|
$this->loadHelpersConfiguration($config, $container, $loader); |
|
40
|
5 |
|
$this->loadWidgetsConfiguration($config, $container, $loader); |
|
41
|
5 |
|
$this->loadComponentsConfiguration($config, $container, $loader); |
|
42
|
5 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @throws \Exception |
|
46
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
|
47
|
|
|
*/ |
|
48
|
5 |
|
private function loadHelpersConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
5 |
|
if ($this->componentIsNotEnabled('helpers', $configs)) { |
|
51
|
1 |
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
4 |
|
$loader->load('helpers.yaml'); |
|
55
|
4 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @throws \Exception |
|
59
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
|
60
|
|
|
*/ |
|
61
|
5 |
|
private function loadWidgetsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
62
|
|
|
{ |
|
63
|
5 |
|
if ($this->componentIsNotEnabled('widgets', $configs)) { |
|
64
|
1 |
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
$loader->load('widgets.yaml'); |
|
68
|
|
|
|
|
69
|
|
|
$container |
|
70
|
4 |
|
->registerForAutoconfiguration(WidgetInterface::class) |
|
71
|
4 |
|
->addTag('sauls_widget.widget') |
|
72
|
4 |
|
->setPublic(true); |
|
73
|
|
|
|
|
74
|
|
|
$container |
|
75
|
4 |
|
->registerForAutoconfiguration(ViewInterface::class) |
|
76
|
4 |
|
->addTag('sauls_widget.view') |
|
77
|
4 |
|
->setPrivate(true); |
|
78
|
4 |
|
} |
|
79
|
|
|
|
|
80
|
5 |
|
private function loadComponentsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
81
|
|
|
{ |
|
82
|
5 |
|
$this->loadSecurityAccessComponent($configs, $container, $loader); |
|
83
|
5 |
|
} |
|
84
|
|
|
|
|
85
|
5 |
|
private function loadSecurityAccessComponent(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
86
|
|
|
{ |
|
87
|
5 |
|
if ($this->componentIsNotEnabled('components.access', $configs)) { |
|
88
|
4 |
|
return; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
$loader->load('component/security/access.yaml'); |
|
92
|
|
|
|
|
93
|
1 |
|
$container->setParameter( |
|
94
|
1 |
|
'sauls_components.component.access.options', |
|
95
|
1 |
|
array_get_value($configs, 'components.access') |
|
96
|
|
|
); |
|
97
|
1 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @throws \Exception |
|
101
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
|
102
|
|
|
*/ |
|
103
|
5 |
|
private function componentIsNotEnabled(string $componentName, array $configs): bool |
|
104
|
|
|
{ |
|
105
|
5 |
|
return false === array_get_value($configs, $componentName, false); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.