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 Exception; |
||||
16 | use InvalidArgumentException; |
||||
17 | use Sauls\Bundle\Components\DependencyInjection\Compiler\RegisterWidgetsPass; |
||||
18 | use Sauls\Component\Helper\Exception\PropertyNotAccessibleException; |
||||
19 | use Sauls\Component\Widget\View\ViewInterface; |
||||
20 | use Sauls\Component\Widget\WidgetInterface; |
||||
21 | use Symfony\Component\Config\FileLocator; |
||||
22 | use Symfony\Component\Config\Loader\LoaderInterface; |
||||
23 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||||
24 | use Symfony\Component\DependencyInjection\Extension\Extension; |
||||
25 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
||||
26 | |||||
27 | use function dirname; |
||||
28 | use function Sauls\Component\Helper\array_get_value; |
||||
29 | |||||
30 | class SaulsComponentsExtension extends Extension |
||||
31 | { |
||||
32 | /** |
||||
33 | * @throws Exception |
||||
34 | * @throws PropertyNotAccessibleException |
||||
35 | * @throws InvalidArgumentException When provided tag is not defined in this extension |
||||
36 | */ |
||||
37 | 6 | public function load(array $configs, ContainerBuilder $container) |
|||
38 | { |
||||
39 | 6 | $configuration = $this->getConfiguration($configs, $container); |
|||
40 | 6 | $config = $this->processConfiguration($configuration, $configs); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
41 | |||||
42 | 6 | $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config')); |
|||
43 | |||||
44 | 6 | $this->loadHelpersConfiguration($config, $container, $loader); |
|||
45 | 6 | $this->loadWidgetsConfiguration($config, $container, $loader); |
|||
46 | 6 | $this->loadComponentsConfiguration($config, $container, $loader); |
|||
47 | 6 | } |
|||
48 | |||||
49 | /** |
||||
50 | * @throws Exception |
||||
51 | * @throws PropertyNotAccessibleException |
||||
52 | */ |
||||
53 | 6 | private function loadHelpersConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|||
0 ignored issues
–
show
The parameter
$container is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
54 | { |
||||
55 | 6 | if ($this->componentIsNotEnabled('helpers', $configs)) { |
|||
56 | 1 | return; |
|||
57 | } |
||||
58 | |||||
59 | 5 | $loader->load('helpers.yaml'); |
|||
60 | 5 | } |
|||
61 | |||||
62 | /** |
||||
63 | * @throws Exception |
||||
64 | * @throws PropertyNotAccessibleException |
||||
65 | */ |
||||
66 | 6 | private function componentIsNotEnabled(string $componentName, array $configs): bool |
|||
67 | { |
||||
68 | 6 | return false === array_get_value($configs, $componentName, false); |
|||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * @throws Exception |
||||
73 | * @throws PropertyNotAccessibleException |
||||
74 | */ |
||||
75 | 6 | private function loadWidgetsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|||
76 | { |
||||
77 | 6 | if ($this->componentIsNotEnabled('widgets', $configs)) { |
|||
78 | 1 | return; |
|||
79 | } |
||||
80 | |||||
81 | 5 | $loader->load('widgets.yaml'); |
|||
82 | |||||
83 | $container |
||||
84 | 5 | ->registerForAutoconfiguration(WidgetInterface::class) |
|||
85 | 5 | ->addTag('sauls_widget.widget') |
|||
86 | 5 | ->setPublic(true); |
|||
87 | |||||
88 | $container |
||||
89 | 5 | ->registerForAutoconfiguration(ViewInterface::class) |
|||
90 | 5 | ->addTag('sauls_widget.view') |
|||
91 | 5 | ->setPublic(true); |
|||
92 | 5 | } |
|||
93 | |||||
94 | 6 | private function loadComponentsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|||
95 | { |
||||
96 | 6 | $this->loadSecurityAccessComponent($configs, $container, $loader); |
|||
97 | 6 | } |
|||
98 | |||||
99 | 6 | private function loadSecurityAccessComponent(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|||
100 | { |
||||
101 | 6 | if ($this->componentIsNotEnabled('components.access', $configs)) { |
|||
102 | 5 | return; |
|||
103 | } |
||||
104 | |||||
105 | 1 | $loader->load('component/security/access.yaml'); |
|||
106 | |||||
107 | 1 | $container->setParameter( |
|||
108 | 1 | 'sauls_components.component.access.options', |
|||
109 | 1 | array_get_value($configs, 'components.access') |
|||
110 | ); |
||||
111 | 1 | } |
|||
112 | } |
||||
113 |