Skip to content

Commit

Permalink
Merge pull request #919 from mvrhov/xsdSync
Browse files Browse the repository at this point in the history
allow symfony loader to load it's unrecognized routes
  • Loading branch information
lsmith77 committed Jan 5, 2015
2 parents 8c76b05 + f7eabf5 commit 6c8b756
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 51 deletions.
91 changes: 46 additions & 45 deletions Resources/config/schema/routing-1.0.xsd
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsd:schema xmlns="http://symfony.com/schema/routing"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://symfony.com/schema/routing"
elementFormDefault="qualified">
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://symfony.com/schema/routing"
elementFormDefault="qualified">

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

<xsd:element name="routes" type="routes" />
<xsd:element name="routes" type="routes" />

<xsd:complexType name="routes">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import" type="import" />
<xsd:element name="route" type="route" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="routes">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import" type="import" />
<xsd:element name="route" type="route" />
</xsd:choice>
</xsd:complexType>

<xsd:group name="configs">
<xsd:choice>
<xsd:element name="default" nillable="true" type="element" />
<xsd:element name="requirement" type="element" />
<xsd:element name="option" type="element" />
</xsd:choice>
</xsd:group>
<xsd:group name="configs">
<xsd:choice>
<xsd:element name="default" nillable="true" type="element" />
<xsd:element name="requirement" type="element" />
<xsd:element name="option" type="element" />
<xsd:element name="condition" type="xsd:string" />
</xsd:choice>
</xsd:group>

<xsd:complexType name="route">
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
<xsd:complexType name="route">
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />

<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="pattern" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="pattern" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="import">
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
<xsd:complexType name="import">
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />

<xsd:attribute name="resource" type="xsd:string" use="required" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="prefix" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>
<xsd:attribute name="resource" type="xsd:string" use="required" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="prefix" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="element">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="key" type="xsd:string" use="required" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="element">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="key" type="xsd:string" use="required" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
21 changes: 15 additions & 6 deletions Resources/config/schema/routing/rest_routing-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@
</xsd:choice>
</xsd:complexType>

<!-- configs and route should be kept in sync with symfony schema -->
<xsd:group name="configs">
<xsd:choice>
<xsd:element name="default" nillable="true" type="element" />
<xsd:element name="requirement" type="element" />
<xsd:element name="option" type="element" />
</xsd:choice>
</xsd:group>

<xsd:complexType name="route">
<xsd:sequence>
<xsd:element name="default" type="element" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="requirement" type="element" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />

<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="pattern" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="import">
Expand Down
20 changes: 20 additions & 0 deletions Routing/Loader/RestXmlCollectionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
$node->appendChild($option);
}

$length = $node->childNodes->length;
for ($i = 0; $i < $length; $i++) {
$loopNode = $node->childNodes->item($i);
if ($loopNode->nodeType == XML_TEXT_NODE) {
continue;
}

$newNode = $node->ownerDocument->createElementNS(
self::NAMESPACE_URI,
$loopNode->nodeName,
$loopNode->nodeValue
);

foreach ($loopNode->attributes as $value) {
$newNode->setAttribute($value->name, $value->value);
}

$node->appendChild($newNode);
}

parent::parseRoute($collection, $node, $path);
}

Expand Down
1 change: 1 addition & 0 deletions Tests/Routing/Loader/RestXmlCollectionLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testManualRoutes()

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

public function testManualRoutesWithoutIncludeFormat()
Expand Down
1 change: 1 addition & 0 deletions Tests/Routing/Loader/RestYamlCollectionLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testManualRoutes()

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

public function testManualRoutesWithoutIncludeFormat()
Expand Down

0 comments on commit 6c8b756

Please sign in to comment.