1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Serializer bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\SerializerBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
17
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
18
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Configuration implements ConfigurationInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var bool |
27
|
|
|
*/ |
28
|
|
|
private $debug; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param bool $debug |
32
|
|
|
*/ |
33
|
243 |
|
public function __construct($debug = false) |
34
|
|
|
{ |
35
|
243 |
|
$this->debug = $debug; |
36
|
243 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
243 |
|
public function getConfigTreeBuilder() |
42
|
|
|
{ |
43
|
243 |
|
$treeBuilder = $this->createTreeBuilder(); |
44
|
243 |
|
$treeBuilder->root('ivory_serializer') |
45
|
243 |
|
->children() |
46
|
243 |
|
->append($this->createEventNode()) |
47
|
243 |
|
->append($this->createMappingNode()) |
48
|
243 |
|
->append($this->createTypesNode()) |
49
|
243 |
|
->append($this->createVisitorsNode()); |
50
|
|
|
|
51
|
243 |
|
return $treeBuilder; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ArrayNodeDefinition |
56
|
|
|
*/ |
57
|
243 |
|
private function createMappingNode() |
58
|
|
|
{ |
59
|
243 |
|
return $this->createNode('mapping') |
60
|
243 |
|
->addDefaultsIfNotSet() |
61
|
243 |
|
->children() |
62
|
243 |
|
->booleanNode('annotation')->defaultValue(class_exists(AnnotationReader::class))->end() |
63
|
243 |
|
->booleanNode('reflection')->defaultTrue()->end() |
64
|
243 |
|
->arrayNode('cache') |
65
|
243 |
|
->addDefaultsIfNotSet() |
66
|
243 |
|
->children() |
67
|
243 |
|
->booleanNode('debug')->defaultValue($this->debug)->end() |
68
|
243 |
|
->scalarNode('prefix')->defaultValue('ivory_serializer')->end() |
69
|
243 |
|
->scalarNode('pool')->defaultValue('cache.system')->end() |
70
|
243 |
|
->end() |
71
|
243 |
|
->end() |
72
|
243 |
|
->arrayNode('auto') |
73
|
243 |
|
->addDefaultsIfNotSet() |
74
|
243 |
|
->children() |
75
|
243 |
|
->booleanNode('enabled')->defaultTrue()->end() |
76
|
243 |
|
->arrayNode('paths') |
77
|
243 |
|
->prototype('scalar')->end() |
78
|
243 |
|
->defaultValue([ |
79
|
243 |
|
'Resources/config/serializer', |
80
|
189 |
|
'Resources/config/serialization.json', |
81
|
189 |
|
'Resources/config/serialization.xml', |
82
|
189 |
|
'Resources/config/serialization.yml', |
83
|
189 |
|
]) |
84
|
243 |
|
->end() |
85
|
243 |
|
->end() |
86
|
243 |
|
->end() |
87
|
243 |
|
->arrayNode('paths') |
88
|
243 |
|
->prototype('scalar')->end() |
89
|
243 |
|
->end() |
90
|
243 |
|
->end(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return ArrayNodeDefinition |
95
|
|
|
*/ |
96
|
243 |
|
private function createEventNode() |
97
|
|
|
{ |
98
|
243 |
|
return $this->createNode('event') |
99
|
243 |
|
->addDefaultsIfNotSet() |
100
|
243 |
|
->children() |
101
|
243 |
|
->booleanNode('enabled')->defaultValue(class_exists(EventDispatcher::class))->end() |
102
|
243 |
|
->end(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return ArrayNodeDefinition |
107
|
|
|
*/ |
108
|
243 |
|
private function createTypesNode() |
109
|
|
|
{ |
110
|
243 |
|
return $this->createNode('types') |
111
|
243 |
|
->addDefaultsIfNotSet() |
112
|
243 |
|
->children() |
113
|
243 |
|
->arrayNode('date_time') |
114
|
243 |
|
->addDefaultsIfNotSet() |
115
|
243 |
|
->children() |
116
|
243 |
|
->scalarNode('format')->defaultValue(\DateTime::RFC3339)->end() |
117
|
243 |
|
->scalarNode('timezone')->defaultValue(date_default_timezone_get())->end() |
118
|
243 |
|
->end() |
119
|
243 |
|
->end() |
120
|
243 |
|
->arrayNode('exception') |
121
|
243 |
|
->addDefaultsIfNotSet() |
122
|
243 |
|
->children() |
123
|
243 |
|
->booleanNode('debug')->defaultValue($this->debug)->end() |
124
|
243 |
|
->end() |
125
|
243 |
|
->end() |
126
|
243 |
|
->end(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return ArrayNodeDefinition |
131
|
|
|
*/ |
132
|
243 |
|
private function createVisitorsNode() |
133
|
|
|
{ |
134
|
243 |
|
return $this->createNode('visitors') |
135
|
243 |
|
->addDefaultsIfNotSet() |
136
|
243 |
|
->children() |
137
|
243 |
|
->arrayNode('csv') |
138
|
243 |
|
->addDefaultsIfNotSet() |
139
|
243 |
|
->children() |
140
|
243 |
|
->scalarNode('delimiter')->defaultValue(',')->end() |
141
|
243 |
|
->scalarNode('enclosure')->defaultValue('"')->end() |
142
|
243 |
|
->scalarNode('escape_char')->defaultValue('\\')->end() |
143
|
243 |
|
->scalarNode('key_separator')->defaultValue('.')->end() |
144
|
243 |
|
->end() |
145
|
243 |
|
->end() |
146
|
243 |
|
->arrayNode('json') |
147
|
243 |
|
->addDefaultsIfNotSet() |
148
|
243 |
|
->children() |
149
|
243 |
|
->integerNode('max_depth')->defaultValue(512)->end() |
150
|
243 |
|
->integerNode('options')->defaultValue(0)->end() |
151
|
243 |
|
->end() |
152
|
243 |
|
->end() |
153
|
243 |
|
->arrayNode('xml') |
154
|
243 |
|
->addDefaultsIfNotSet() |
155
|
243 |
|
->children() |
156
|
243 |
|
->scalarNode('version')->defaultValue('1.0')->end() |
157
|
243 |
|
->scalarNode('encoding')->defaultValue('UTF-8')->end() |
158
|
243 |
|
->booleanNode('format_output')->defaultValue($this->debug)->end() |
159
|
243 |
|
->scalarNode('root')->defaultValue('result')->end() |
160
|
243 |
|
->scalarNode('entry')->defaultValue('entry')->end() |
161
|
243 |
|
->scalarNode('entry_attribute')->defaultValue('key')->end() |
162
|
243 |
|
->end() |
163
|
243 |
|
->end() |
164
|
243 |
|
->arrayNode('yaml') |
165
|
243 |
|
->addDefaultsIfNotSet() |
166
|
243 |
|
->children() |
167
|
243 |
|
->integerNode('inline')->defaultValue(2)->end() |
168
|
243 |
|
->integerNode('indent')->defaultValue(4)->end() |
169
|
243 |
|
->integerNode('options')->defaultValue(0)->end() |
170
|
243 |
|
->end() |
171
|
243 |
|
->end() |
172
|
243 |
|
->end(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param string $name |
177
|
|
|
* |
178
|
|
|
* @return ArrayNodeDefinition |
179
|
|
|
*/ |
180
|
243 |
|
private function createNode($name) |
181
|
|
|
{ |
182
|
243 |
|
return $this->createTreeBuilder()->root($name); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return TreeBuilder |
187
|
|
|
*/ |
188
|
243 |
|
private function createTreeBuilder() |
189
|
|
|
{ |
190
|
243 |
|
return new TreeBuilder(); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|