Skip to content

Commit

Permalink
[WIP] fix XML routing config
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Nov 25, 2013
1 parent a6eff7a commit 00488ac
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
64 changes: 64 additions & 0 deletions Resources/config/schema/routing-1.0.xsd
@@ -0,0 +1,64 @@
<?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">

<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: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: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: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: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: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>
22 changes: 19 additions & 3 deletions Routing/Loader/RestXmlCollectionLoader.php
Expand Up @@ -110,12 +110,26 @@ public function supports($resource, $type = null)
*/
protected function validate(\DOMDocument $dom)
{
$location = __DIR__.'/../../Resources/config/schema/routing/rest_routing-1.0.xsd';
$restRoutinglocation = realpath(__DIR__.'/../../Resources/config/schema/routing/rest_routing-1.0.xsd');
$routinglocation = realpath(__DIR__.'/../../Resources/config/schema/routing/routing-1.0.xsd');
$source = <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns="http://symfony.com/schema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://symfony.com/schema"
elementFormDefault="qualified">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:import namespace="http://friendsofsymfony.github.com/schema/rest" schemaLocation="$restRoutinglocation" />
<xsd:import namespace="http://symfony.com/schema/routing" schemaLocation="$routinglocation" />
</xsd:schema>
EOF
;

$current = libxml_use_internal_errors(true);
libxml_clear_errors();

if (!$dom->schemaValidate($location)) {
if (!$dom->schemaValidateSource($source)) {
throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors_($current)));
}
libxml_use_internal_errors($current);
Expand All @@ -127,7 +141,9 @@ protected function validate(\DOMDocument $dom)
protected function loadFile($file)
{
if (class_exists('Symfony\Component\Config\Util\XmlUtils')) {
return XmlUtils::loadFile($file, __DIR__ . '/../../Resources/config/schema/routing/rest_routing-1.0.xsd');
$dom = XmlUtils::loadFile($file);
$this->validate($dom);
return $dom;
}

return parent::loadFile($file);
Expand Down

0 comments on commit 00488ac

Please sign in to comment.