/
Configuration.php
135 lines (123 loc) · 5.19 KB
/
Configuration.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Doctrine\Bundle\OXMBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* @author Igor Golovanov <igor.golovanov@gmail.com>
*/
class Configuration implements ConfigurationInterface
{
private $debug;
/**
* Constructor.
*
* @param Boolean $debug The kernel.debug value
*/
public function __construct($debug)
{
$this->debug = (Boolean) $debug;
}
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('doctrine_oxm');
$this->addXmlEntityManagersSection($rootNode);
$this->addStoragesSection($rootNode);
$rootNode
->children()
->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/oxm/Proxies')->end()
->scalarNode('auto_generate_proxy_classes')->defaultFalse()->end()
->scalarNode('default_xml_entity_manager')->end()
->scalarNode('default_xml_marshaller')->end()
->scalarNode('default_storage')->defaultValue('default')->end()
->end()
;
return $treeBuilder;
}
/**
* Configures the "xml_entity_managers" section
*/
private function addXmlEntityManagersSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->fixXmlConfig('xml_entity_manager')
->children()
->arrayNode('xml_entity_managers')
->useAttributeAsKey('id')
->prototype('array')
->treatNullLike(array())
->children()
->scalarNode('storage')->end()
->scalarNode('auto_mapping')->defaultFalse()->end()
->arrayNode('metadata_cache_driver')
->beforeNormalization()
->ifTrue(function($v) { return !is_array($v); })
->then(function($v) { return array('type' => $v); })
->end()
->children()
->scalarNode('type')->end()
->scalarNode('class')->end()
->scalarNode('host')->end()
->scalarNode('port')->end()
->scalarNode('instance_class')->end()
->end()
->end()
->end()
->fixXmlConfig('mapping')
->children()
->arrayNode('mappings')
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->ifString()
->then(function($v) { return array ('type' => $v); })
->end()
->treatNullLike(array())
->treatFalseLike(array('mapping' => false))
->performNoDeepMerging()
->children()
->scalarNode('mapping')->defaultValue(true)->end()
->scalarNode('type')->end()
->scalarNode('dir')->end()
->scalarNode('prefix')->end()
->scalarNode('alias')->end()
->booleanNode('is_bundle')->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
;
}
/**
* Adds the configuration for the "storages" key
*/
private function addStoragesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->fixXmlConfig('storage')
->children()
->arrayNode('storages')
->useAttributeAsKey('id')
->prototype('array')
->performNoDeepMerging()
->children()
->scalarNode('type')->defaultValue('filesystem')->end()
->scalarNode('path')->defaultValue('%kernel.root_dir%/doctrine-oxm-storage')->end()
->scalarNode('extension')->defaultValue('xml')->end()
->end()
->end()
->end()
->end()
;
}
}