Skip to content

Commit

Permalink
[Routing] make xml loader more tolerant
Browse files Browse the repository at this point in the history
schemes and methods may also be delimited by whitespace, comma or pipe.
this eases migration as now schemes="GET|POST" also works
  • Loading branch information
Tobion committed Mar 5, 2013
1 parent 49984b6 commit 41ad9d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Expand Up @@ -126,8 +126,8 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
$node->removeAttribute('pattern');
}

$schemes = array_filter(explode(' ', $node->getAttribute('schemes')));
$methods = array_filter(explode(' ', $node->getAttribute('methods')));
$schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
$methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);

list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);

Expand All @@ -154,8 +154,8 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
$type = $node->getAttribute('type');
$prefix = $node->getAttribute('prefix');
$host = $node->hasAttribute('host') ? $node->getAttribute('host') : null;
$schemes = $node->hasAttribute('schemes') ? array_filter(explode(' ', $node->getAttribute('schemes'))) : null;
$methods = $node->hasAttribute('methods') ? array_filter(explode(' ', $node->getAttribute('methods'))) : null;
$schemes = $node->hasAttribute('schemes') ? preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY) : null;
$methods = $node->hasAttribute('methods') ? preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY) : null;

list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);

Expand Down
Expand Up @@ -17,16 +17,6 @@

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

<xsd:simpleType name="word">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z]){3,}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="stringlist">
<xsd:list itemType="word"/>
</xsd:simpleType>

<xsd:complexType name="routes">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import" type="import" />
Expand All @@ -49,8 +39,8 @@
<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="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="import">
Expand All @@ -60,8 +50,8 @@
<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="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="element">
Expand Down

0 comments on commit 41ad9d8

Please sign in to comment.