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