|
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
|
|
|
public function __construct($debug = false) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->debug = $debug; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getConfigTreeBuilder() |
|
42
|
|
|
{ |
|
43
|
|
|
$treeBuilder = $this->createTreeBuilder('ivory_serializer'); |
|
44
|
|
|
$treeBuilder->getRootNode() |
|
45
|
|
|
->children() |
|
46
|
|
|
->append($this->createEventNode()) |
|
47
|
|
|
->append($this->createMappingNode()) |
|
48
|
|
|
->append($this->createTypesNode()) |
|
49
|
|
|
->append($this->createVisitorsNode()); |
|
50
|
|
|
|
|
51
|
|
|
return $treeBuilder; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return ArrayNodeDefinition |
|
56
|
|
|
*/ |
|
57
|
|
|
private function createMappingNode() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->createNode('mapping') |
|
60
|
|
|
->addDefaultsIfNotSet() |
|
61
|
|
|
->children() |
|
62
|
|
|
->booleanNode('annotation')->defaultValue(class_exists(AnnotationReader::class))->end() |
|
63
|
|
|
->booleanNode('reflection')->defaultTrue()->end() |
|
64
|
|
|
->arrayNode('cache') |
|
65
|
|
|
->addDefaultsIfNotSet() |
|
66
|
|
|
->children() |
|
67
|
|
|
->booleanNode('debug')->defaultValue($this->debug)->end() |
|
68
|
|
|
->scalarNode('prefix')->defaultValue('ivory_serializer')->end() |
|
69
|
|
|
->scalarNode('pool')->defaultValue('cache.system')->end() |
|
70
|
|
|
->end() |
|
71
|
|
|
->end() |
|
72
|
|
|
->arrayNode('auto') |
|
73
|
|
|
->addDefaultsIfNotSet() |
|
74
|
|
|
->children() |
|
75
|
|
|
->booleanNode('enabled')->defaultTrue()->end() |
|
76
|
|
|
->arrayNode('paths') |
|
77
|
|
|
->prototype('scalar')->end() |
|
78
|
|
|
->defaultValue([ |
|
79
|
|
|
'Resources/config/ivory-serializer', |
|
80
|
|
|
'Resources/config/ivory-serializer.json', |
|
81
|
|
|
'Resources/config/ivory-serializer.xml', |
|
82
|
|
|
'Resources/config/ivory-serializer.yml', |
|
83
|
|
|
]) |
|
84
|
|
|
->end() |
|
85
|
|
|
->end() |
|
86
|
|
|
->end() |
|
87
|
|
|
->arrayNode('paths') |
|
88
|
|
|
->prototype('scalar')->end() |
|
89
|
|
|
->end() |
|
90
|
|
|
->end(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return ArrayNodeDefinition |
|
95
|
|
|
*/ |
|
96
|
|
|
private function createEventNode() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->createNode('event') |
|
99
|
|
|
->addDefaultsIfNotSet() |
|
100
|
|
|
->children() |
|
101
|
|
|
->booleanNode('enabled')->defaultValue(class_exists(EventDispatcher::class))->end() |
|
102
|
|
|
->end(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return ArrayNodeDefinition |
|
107
|
|
|
*/ |
|
108
|
|
|
private function createTypesNode() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->createNode('types') |
|
111
|
|
|
->addDefaultsIfNotSet() |
|
112
|
|
|
->children() |
|
113
|
|
|
->arrayNode('date_time') |
|
114
|
|
|
->addDefaultsIfNotSet() |
|
115
|
|
|
->children() |
|
116
|
|
|
->scalarNode('format')->defaultValue(\DateTime::RFC3339)->end() |
|
117
|
|
|
->scalarNode('timezone')->defaultValue(date_default_timezone_get())->end() |
|
118
|
|
|
->end() |
|
119
|
|
|
->end() |
|
120
|
|
|
->arrayNode('exception') |
|
121
|
|
|
->addDefaultsIfNotSet() |
|
122
|
|
|
->children() |
|
123
|
|
|
->booleanNode('debug')->defaultValue($this->debug)->end() |
|
124
|
|
|
->end() |
|
125
|
|
|
->end() |
|
126
|
|
|
->end(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return ArrayNodeDefinition |
|
131
|
|
|
*/ |
|
132
|
|
|
private function createVisitorsNode() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->createNode('visitors') |
|
135
|
|
|
->addDefaultsIfNotSet() |
|
136
|
|
|
->children() |
|
137
|
|
|
->arrayNode('csv') |
|
138
|
|
|
->addDefaultsIfNotSet() |
|
139
|
|
|
->children() |
|
140
|
|
|
->scalarNode('delimiter')->defaultValue(',')->end() |
|
141
|
|
|
->scalarNode('enclosure')->defaultValue('"')->end() |
|
142
|
|
|
->scalarNode('escape_char')->defaultValue('\\')->end() |
|
143
|
|
|
->scalarNode('key_separator')->defaultValue('.')->end() |
|
144
|
|
|
->end() |
|
145
|
|
|
->end() |
|
146
|
|
|
->arrayNode('json') |
|
147
|
|
|
->addDefaultsIfNotSet() |
|
148
|
|
|
->children() |
|
149
|
|
|
->integerNode('max_depth')->defaultValue(512)->end() |
|
150
|
|
|
->integerNode('options')->defaultValue(0)->end() |
|
151
|
|
|
->end() |
|
152
|
|
|
->end() |
|
153
|
|
|
->arrayNode('xml') |
|
154
|
|
|
->addDefaultsIfNotSet() |
|
155
|
|
|
->children() |
|
156
|
|
|
->scalarNode('version')->defaultValue('1.0')->end() |
|
157
|
|
|
->scalarNode('encoding')->defaultValue('UTF-8')->end() |
|
158
|
|
|
->booleanNode('format_output')->defaultValue($this->debug)->end() |
|
159
|
|
|
->scalarNode('root')->defaultValue('result')->end() |
|
160
|
|
|
->scalarNode('entry')->defaultValue('entry')->end() |
|
161
|
|
|
->scalarNode('entry_attribute')->defaultValue('key')->end() |
|
162
|
|
|
->end() |
|
163
|
|
|
->end() |
|
164
|
|
|
->arrayNode('yaml') |
|
165
|
|
|
->addDefaultsIfNotSet() |
|
166
|
|
|
->children() |
|
167
|
|
|
->integerNode('inline')->defaultValue(2)->end() |
|
168
|
|
|
->integerNode('indent')->defaultValue(4)->end() |
|
169
|
|
|
->integerNode('options')->defaultValue(0)->end() |
|
170
|
|
|
->end() |
|
171
|
|
|
->end() |
|
172
|
|
|
->end(); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
private function createNode(string $name = null, string $type = 'array'): ArrayNodeDefinition |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->createTreeBuilder($name, $type)->getRootNode(); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
private function createTreeBuilder(string $name = null, string $type = 'array'): TreeBuilder |
|
181
|
|
|
{ |
|
182
|
|
|
return new TreeBuilder($name, $type); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|