Skip to content

Commit 53f32f4

Browse files
committed
Support filter parameter configuration in XML
Update XSD for filter parameter syntax, and allow non-scalar parameter values (i.e. arrays and objects) to be defined with JSON.
1 parent 514c246 commit 53f32f4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
100100
->arrayNode('filters')
101101
->useAttributeAsKey('name')
102102
->prototype('array')
103+
->fixXmlConfig('parameter')
103104
->beforeNormalization()
104105
->ifString()
105106
->then(function($v) { return array('class' => $v); })
@@ -119,7 +120,14 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
119120
->booleanNode('enabled')->defaultFalse()->end()
120121
->arrayNode('parameters')
121122
->treatNullLike(array())
122-
->prototype('scalar')
123+
->useAttributeAsKey('name')
124+
->prototype('variable')
125+
->beforeNormalization()
126+
// Detect JSON object and array syntax (for XML)
127+
->ifTrue(function($v) { return is_string($v) && (preg_match('/\[.*\]/', $v) || preg_match('/\{.*\}/', $v)); })
128+
// Decode objects to associative arrays for consistency with YAML
129+
->then(function($v) { return json_decode($v, true); })
130+
->end()
123131
->end()
124132
->end()
125133
->end()

Resources/config/schema/mongodb-1.0.xsd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,22 @@
123123
</xsd:complexType>
124124

125125
<xsd:complexType name="filter">
126+
<xsd:sequence>
127+
<xsd:element name="parameter" type="filter-parameter" minOccurs="0" maxOccurs="unbounded" />
128+
</xsd:sequence>
126129
<xsd:attribute name="name" type="xsd:string" use="required" />
127130
<xsd:attribute name="class" type="xsd:string" use="required" />
128131
<xsd:attribute name="enabled" type="xsd:boolean" />
129132
</xsd:complexType>
130133

134+
<xsd:complexType name="filter-parameter">
135+
<xsd:simpleContent>
136+
<xsd:extension base="xsd:string">
137+
<xsd:attribute name="name" type="xsd:string" use="required" />
138+
</xsd:extension>
139+
</xsd:simpleContent>
140+
</xsd:complexType>
141+
131142
<xsd:complexType name="mapping">
132143
<xsd:attribute name="name" type="xsd:string" use="required" />
133144
<xsd:attribute name="alias" type="xsd:string" />

0 commit comments

Comments
 (0)