|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kaliop\eZObjectWrapperBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This is the class that loads and manages your bundle configuration |
|
13
|
|
|
* |
|
14
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
|
15
|
|
|
*/ |
|
16
|
|
|
class KaliopeZObjectWrapperExtension extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
protected $entityManagerService = 'ezobject_wrapper.entity_manager'; |
|
19
|
|
|
|
|
20
|
|
|
public function getAlias() |
|
21
|
|
|
{ |
|
22
|
|
|
return 'ezobject_wrapper'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
29
|
|
|
{ |
|
30
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
31
|
|
|
$loader->load('services.yml'); |
|
32
|
|
|
|
|
33
|
|
|
$configuration = new Configuration(); |
|
34
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
35
|
|
|
|
|
36
|
|
|
$this->injectConfiguration($config, $container); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function injectConfiguration(array $config, ContainerBuilder $container) |
|
40
|
|
|
{ |
|
41
|
|
|
if ($container->hasDefinition($this->entityManagerService)) { |
|
42
|
|
|
$factoryDefinition = $container->findDefinition($this->entityManagerService); |
|
43
|
|
|
|
|
44
|
|
|
$factoryDefinition->addMethodCall('registerDefaultClass', array($config['default_repository_class'])); |
|
45
|
|
|
|
|
46
|
|
|
foreach ($config['class_map'] as $type => $class) { |
|
47
|
|
|
$factoryDefinition |
|
48
|
|
|
->addMethodCall('registerClass', array($class, $type)); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|