1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivoaz ContentEditable bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Ivo Azirjans <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivoaz\Bundle\ContentEditableBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Ivo Azirjans <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class IvoazContentEditableExtension extends Extension |
24
|
|
|
{ |
25
|
|
|
private static $objectManagers = [ |
26
|
|
|
Configuration::MODEL_ORM => 'doctrine.orm.%s_entity_manager', |
27
|
|
|
Configuration::MODEL_MONGODB => 'doctrine_mongodb.odm.%s_document_manager', |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
private static $defaultModelManagerNameParameters = [ |
31
|
|
|
Configuration::MODEL_ORM => 'doctrine.default_entity_manager', |
32
|
|
|
Configuration::MODEL_MONGODB => 'doctrine_mongodb.odm.default_document_manager', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
9 |
|
public function load(array $configs, ContainerBuilder $container) |
39
|
|
|
{ |
40
|
9 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
41
|
9 |
|
$loader->load('services.xml'); |
42
|
|
|
|
43
|
9 |
|
$configuration = new Configuration(); |
44
|
9 |
|
$config = $this->processConfiguration($configuration, $configs); |
45
|
|
|
|
46
|
9 |
|
$modelType = $config['model_type']; |
47
|
9 |
|
$container->setParameter(sprintf('ivoaz_content_editable.model_type_%s', $modelType), true); |
48
|
|
|
|
49
|
9 |
|
if ($config['model_manager_name']) { |
50
|
1 |
|
$managerName = $config['model_manager_name']; |
51
|
1 |
|
} else { |
52
|
8 |
|
$managerName = $container->getParameter(self::$defaultModelManagerNameParameters[$modelType]); |
53
|
|
|
} |
54
|
|
|
|
55
|
9 |
|
$container->setParameter('ivoaz_content_editable.model_manager_name', $managerName); |
56
|
|
|
|
57
|
9 |
|
$objectManager = sprintf(self::$objectManagers[$modelType], $managerName); |
58
|
9 |
|
$container->setAlias('ivoaz_content_editable.object_manager', new Alias($objectManager, false)); |
59
|
|
|
|
60
|
9 |
|
$editor = $config['editor']; |
61
|
9 |
|
$container->setAlias('ivoaz_content_editable.editor', new Alias($editor, false)); |
62
|
9 |
|
} |
63
|
|
|
} |
64
|
|
|
|