forked from skrz/autowiring-bundle
/
SkrzAutowiringBundle.php
61 lines (50 loc) · 1.72 KB
/
SkrzAutowiringBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Skrz\Bundle\AutowiringBundle;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\PhpParser;
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap;
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\AutoscanCompilerPass;
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\AutowiringCompilerPass;
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass;
use Skrz\Bundle\AutowiringBundle\DependencyInjection\SkrzAutowiringExtension;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* @author Jakub Kulhan <jakub.kulhan@gmail.com>
*/
class SkrzAutowiringBundle extends Bundle
{
/**
* {@inheritDoc}
*/
public function getContainerExtension()
{
if ($this->extension === null) {
$this->extension = new SkrzAutowiringExtension();
}
return $this->extension;
}
public function build(ContainerBuilder $container)
{
$annotationReader = new AnnotationReader;
$autoscanClassMap = new ClassMultiMap;
$container->addCompilerPass(
new ClassMapBuildCompilerPass($autoscanClassMap),
PassConfig::TYPE_BEFORE_OPTIMIZATION
);
$container->addCompilerPass(
new AutoscanCompilerPass($autoscanClassMap, $annotationReader),
PassConfig::TYPE_BEFORE_OPTIMIZATION
);
$autowiringClassMap = new ClassMultiMap;
$container->addCompilerPass(
new ClassMapBuildCompilerPass($autowiringClassMap),
PassConfig::TYPE_AFTER_REMOVING
);
$container->addCompilerPass(
new AutowiringCompilerPass($autowiringClassMap, $annotationReader, new PhpParser),
PassConfig::TYPE_AFTER_REMOVING
);
}
}