Skip to content

Commit 6c8b756

Browse files
committed
Merge pull request #919 from mvrhov/xsdSync
allow symfony loader to load it's unrecognized routes
2 parents 8c76b05 + f7eabf5 commit 6c8b756

File tree

5 files changed

+83
-51
lines changed

5 files changed

+83
-51
lines changed
Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,65 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22

33
<xsd:schema xmlns="http://symfony.com/schema/routing"
4-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5-
targetNamespace="http://symfony.com/schema/routing"
6-
elementFormDefault="qualified">
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
targetNamespace="http://symfony.com/schema/routing"
6+
elementFormDefault="qualified">
77

8-
<xsd:annotation>
9-
<xsd:documentation><![CDATA[
8+
<xsd:annotation>
9+
<xsd:documentation><![CDATA[
1010
Symfony XML Routing Schema, version 1.0
1111
Authors: Fabien Potencier, Tobias Schultze
1212
1313
This scheme defines the elements and attributes that can be used to define
1414
routes. A route maps an HTTP request to a set of configuration variables.
1515
]]></xsd:documentation>
16-
</xsd:annotation>
16+
</xsd:annotation>
1717

18-
<xsd:element name="routes" type="routes" />
18+
<xsd:element name="routes" type="routes" />
1919

20-
<xsd:complexType name="routes">
21-
<xsd:choice minOccurs="0" maxOccurs="unbounded">
22-
<xsd:element name="import" type="import" />
23-
<xsd:element name="route" type="route" />
24-
</xsd:choice>
25-
</xsd:complexType>
20+
<xsd:complexType name="routes">
21+
<xsd:choice minOccurs="0" maxOccurs="unbounded">
22+
<xsd:element name="import" type="import" />
23+
<xsd:element name="route" type="route" />
24+
</xsd:choice>
25+
</xsd:complexType>
2626

27-
<xsd:group name="configs">
28-
<xsd:choice>
29-
<xsd:element name="default" nillable="true" type="element" />
30-
<xsd:element name="requirement" type="element" />
31-
<xsd:element name="option" type="element" />
32-
</xsd:choice>
33-
</xsd:group>
27+
<xsd:group name="configs">
28+
<xsd:choice>
29+
<xsd:element name="default" nillable="true" type="element" />
30+
<xsd:element name="requirement" type="element" />
31+
<xsd:element name="option" type="element" />
32+
<xsd:element name="condition" type="xsd:string" />
33+
</xsd:choice>
34+
</xsd:group>
3435

35-
<xsd:complexType name="route">
36-
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
36+
<xsd:complexType name="route">
37+
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
3738

38-
<xsd:attribute name="id" type="xsd:string" use="required" />
39-
<xsd:attribute name="path" type="xsd:string" />
40-
<xsd:attribute name="pattern" type="xsd:string" />
41-
<xsd:attribute name="host" type="xsd:string" />
42-
<xsd:attribute name="schemes" type="xsd:string" />
43-
<xsd:attribute name="methods" type="xsd:string" />
44-
</xsd:complexType>
39+
<xsd:attribute name="id" type="xsd:string" use="required" />
40+
<xsd:attribute name="path" type="xsd:string" />
41+
<xsd:attribute name="pattern" type="xsd:string" />
42+
<xsd:attribute name="host" type="xsd:string" />
43+
<xsd:attribute name="schemes" type="xsd:string" />
44+
<xsd:attribute name="methods" type="xsd:string" />
45+
</xsd:complexType>
4546

46-
<xsd:complexType name="import">
47-
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
47+
<xsd:complexType name="import">
48+
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
4849

49-
<xsd:attribute name="resource" type="xsd:string" use="required" />
50-
<xsd:attribute name="type" type="xsd:string" />
51-
<xsd:attribute name="prefix" type="xsd:string" />
52-
<xsd:attribute name="host" type="xsd:string" />
53-
<xsd:attribute name="schemes" type="xsd:string" />
54-
<xsd:attribute name="methods" type="xsd:string" />
55-
</xsd:complexType>
50+
<xsd:attribute name="resource" type="xsd:string" use="required" />
51+
<xsd:attribute name="type" type="xsd:string" />
52+
<xsd:attribute name="prefix" type="xsd:string" />
53+
<xsd:attribute name="host" type="xsd:string" />
54+
<xsd:attribute name="schemes" type="xsd:string" />
55+
<xsd:attribute name="methods" type="xsd:string" />
56+
</xsd:complexType>
5657

57-
<xsd:complexType name="element">
58-
<xsd:simpleContent>
59-
<xsd:extension base="xsd:string">
60-
<xsd:attribute name="key" type="xsd:string" use="required" />
61-
</xsd:extension>
62-
</xsd:simpleContent>
63-
</xsd:complexType>
58+
<xsd:complexType name="element">
59+
<xsd:simpleContent>
60+
<xsd:extension base="xsd:string">
61+
<xsd:attribute name="key" type="xsd:string" use="required" />
62+
</xsd:extension>
63+
</xsd:simpleContent>
64+
</xsd:complexType>
6465
</xsd:schema>

Resources/config/schema/routing/rest_routing-1.0.xsd

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@
1414
</xsd:choice>
1515
</xsd:complexType>
1616

17+
<!-- configs and route should be kept in sync with symfony schema -->
18+
<xsd:group name="configs">
19+
<xsd:choice>
20+
<xsd:element name="default" nillable="true" type="element" />
21+
<xsd:element name="requirement" type="element" />
22+
<xsd:element name="option" type="element" />
23+
</xsd:choice>
24+
</xsd:group>
25+
1726
<xsd:complexType name="route">
18-
<xsd:sequence>
19-
<xsd:element name="default" type="element" minOccurs="0" maxOccurs="unbounded" />
20-
<xsd:element name="requirement" type="element" minOccurs="0" maxOccurs="unbounded" />
21-
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
22-
</xsd:sequence>
27+
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
2328

24-
<xsd:attribute name="id" type="xsd:string" />
29+
<xsd:attribute name="id" type="xsd:string" use="required" />
30+
<xsd:attribute name="path" type="xsd:string" />
2531
<xsd:attribute name="pattern" type="xsd:string" />
32+
<xsd:attribute name="host" type="xsd:string" />
33+
<xsd:attribute name="schemes" type="xsd:string" />
34+
<xsd:attribute name="methods" type="xsd:string" />
2635
</xsd:complexType>
2736

2837
<xsd:complexType name="import">

Routing/Loader/RestXmlCollectionLoader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
157157
$node->appendChild($option);
158158
}
159159

160+
$length = $node->childNodes->length;
161+
for ($i = 0; $i < $length; $i++) {
162+
$loopNode = $node->childNodes->item($i);
163+
if ($loopNode->nodeType == XML_TEXT_NODE) {
164+
continue;
165+
}
166+
167+
$newNode = $node->ownerDocument->createElementNS(
168+
self::NAMESPACE_URI,
169+
$loopNode->nodeName,
170+
$loopNode->nodeValue
171+
);
172+
173+
foreach ($loopNode->attributes as $value) {
174+
$newNode->setAttribute($value->name, $value->value);
175+
}
176+
177+
$node->appendChild($newNode);
178+
}
179+
160180
parent::parseRoute($collection, $node, $path);
161181
}
162182

Tests/Routing/Loader/RestXmlCollectionLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function testManualRoutes()
6767

6868
$this->assertEquals('/users.{_format}', $route->getPath());
6969
$this->assertEquals('json|xml|html', $route->getRequirement('_format'));
70+
$this->assertEquals('FOSRestBundle:UsersController:getUsers', $route->getDefault('_controller'));
7071
}
7172

7273
public function testManualRoutesWithoutIncludeFormat()

Tests/Routing/Loader/RestYamlCollectionLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function testManualRoutes()
108108

109109
$this->assertEquals('/users.{_format}', $route->getPath());
110110
$this->assertEquals('json|xml|html', $route->getRequirement('_format'));
111+
$this->assertEquals('FOSRestBundle:UsersController:getUsers', $route->getDefault('_controller'));
111112
}
112113

113114
public function testManualRoutesWithoutIncludeFormat()

0 commit comments

Comments
 (0)