1
|
|
|
<?php |
2
|
|
|
namespace Skrz\Bundle\AutowiringBundle\DependencyInjection; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
5
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Jakub Kulhan <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class SkrzAutowiringExtension extends Extension implements ConfigurationInterface |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* {@inheritDoc} |
17
|
|
|
*/ |
18
|
|
|
public function getAlias() |
19
|
|
|
{ |
20
|
|
|
return "autowiring"; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
12 |
|
public function getConfigTreeBuilder() |
27
|
|
|
{ |
28
|
12 |
|
$treeBuilder = new TreeBuilder(); |
29
|
12 |
|
$rootNode = $treeBuilder->root("autowiring"); |
30
|
|
|
|
31
|
12 |
|
$ignoredServicesNode = $rootNode->children()->arrayNode("ignored_services"); |
32
|
12 |
|
$ignoredServicesNode->defaultValue([])->prototype("scalar"); |
33
|
|
|
|
34
|
12 |
|
$preferredServicesNode = $rootNode->children()->arrayNode("preferred_services"); |
35
|
12 |
|
$preferredServicesNode->defaultValue([])->prototype("scalar"); |
36
|
|
|
|
37
|
12 |
|
$fastAnnotationChecksNode = $rootNode->children()->arrayNode("fast_annotation_checks"); |
38
|
12 |
|
$fastAnnotationChecksNode->defaultValue([])->prototype("scalar"); |
39
|
|
|
|
40
|
12 |
|
$fastAnnotationChecksEnabledNode = $rootNode->children()->booleanNode("fast_annotation_checks_enabled"); |
41
|
12 |
|
$fastAnnotationChecksEnabledNode->defaultValue(true); |
42
|
|
|
|
43
|
12 |
|
return $treeBuilder; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
1 |
|
public function load(array $config, ContainerBuilder $container) |
50
|
|
|
{ |
51
|
1 |
|
$autowiringConfig = $this->processConfiguration($this, $config); |
52
|
1 |
|
$container->setParameter("autowiring.ignored_services", $autowiringConfig["ignored_services"]); |
53
|
1 |
|
$container->setParameter("autowiring.preferred_services", $autowiringConfig["preferred_services"]); |
54
|
|
|
|
55
|
1 |
|
if ($autowiringConfig["fast_annotation_checks_enabled"]) { |
56
|
1 |
|
$container->setParameter("autowiring.fast_annotation_checks", array_merge([ |
57
|
1 |
|
"@Component", |
58
|
|
|
"@Controller", |
59
|
|
|
"@Repository", |
60
|
|
|
"@Service", |
61
|
1 |
|
], $autowiringConfig["fast_annotation_checks"])); |
62
|
|
|
} |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|