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\DependencyInjection\Reference; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Ivo Azirjans <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class IvoazContentEditableExtension extends Extension |
25
|
|
|
{ |
26
|
|
|
private static $objectManagers = [ |
27
|
|
|
Configuration::MODEL_ORM => 'doctrine.orm.%s_entity_manager', |
28
|
2 |
|
Configuration::MODEL_MONGODB => 'doctrine_mongodb.odm.%s_document_manager', |
29
|
|
|
]; |
30
|
2 |
|
|
31
|
2 |
|
private static $defaultModelManagerNameParameters = [ |
32
|
|
|
Configuration::MODEL_ORM => 'doctrine.default_entity_manager', |
33
|
2 |
|
Configuration::MODEL_MONGODB => 'doctrine_mongodb.odm.default_document_manager', |
34
|
2 |
|
]; |
35
|
|
|
|
36
|
2 |
|
/** |
37
|
2 |
|
* {@inheritdoc} |
38
|
2 |
|
*/ |
39
|
|
|
public function load(array $configs, ContainerBuilder $container) |
40
|
2 |
|
{ |
41
|
2 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
42
|
2 |
|
$loader->load('services.xml'); |
43
|
2 |
|
|
44
|
|
|
$configuration = new Configuration(); |
45
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
46
|
|
|
|
47
|
|
|
$modelType = $config['model_type']; |
48
|
|
|
$container->setParameter(sprintf('ivoaz_content_editable.model_type_%s', $modelType), true); |
49
|
|
|
|
50
|
|
|
if ($config['model_manager_name']) { |
51
|
|
|
$managerName = $config['model_manager_name']; |
52
|
|
|
} else { |
53
|
|
|
$managerName = $container->getParameter(self::$defaultModelManagerNameParameters[$modelType]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$container->setParameter('ivoaz_content_editable.model_manager_name', $managerName); |
57
|
|
|
|
58
|
|
|
$objectManager = sprintf(self::$objectManagers[$modelType], $managerName); |
59
|
|
|
$container->setAlias('ivoaz_content_editable.object_manager', new Alias($objectManager, false)); |
60
|
|
|
|
61
|
|
|
$editor = $config['editor']; |
62
|
|
|
$container->setAlias('ivoaz_content_editable.editor', new Alias($editor, false)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|