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 Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
21
|
|
|
use Sauls\Bundle\Components\DependencyInjection\Compiler\RegisterCollectionConvertersPass; |
22
|
|
|
|
23
|
|
|
class SaulsComponentsExtension extends Extension |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @throws \Exception |
27
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
28
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
29
|
|
|
*/ |
30
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
4 |
|
$loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); |
33
|
|
|
|
34
|
4 |
|
$this->loadHelpersConfiguration($configs, $container, $loader); |
35
|
4 |
|
$this->loadWidgetsConfiguration($configs, $container, $loader); |
36
|
|
|
|
37
|
4 |
|
$container->addCompilerPass(new RegisterCollectionConvertersPass()); |
38
|
4 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @throws \Exception |
42
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
43
|
|
|
*/ |
44
|
4 |
|
private function loadHelpersConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
|
|
|
45
|
|
|
{ |
46
|
4 |
|
if ($this->componentIsNotEnabled('helpers', $configs)) { |
47
|
1 |
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
3 |
|
$loader->load('helpers.yaml'); |
51
|
3 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @throws \Exception |
55
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
56
|
|
|
*/ |
57
|
4 |
|
private function loadWidgetsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader) |
|
|
|
|
58
|
|
|
{ |
59
|
4 |
|
if ($this->componentIsNotEnabled('widgets', $configs)) { |
60
|
1 |
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
$loader->load('widgets.yaml'); |
64
|
3 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @throws \Exception |
68
|
|
|
* @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException |
69
|
|
|
*/ |
70
|
4 |
|
private function componentIsNotEnabled(string $componentName, array $configs): bool |
|
|
|
|
71
|
|
|
{ |
72
|
4 |
|
return false === array_get_value($configs, 'helpers', false); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.