Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e803f46

Browse files
committed
made schemes and methods available in XmlFileLoader
it uses an attribute list instead of multiple scheme/method elements that I also experimented with
1 parent d374e70 commit e803f46

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
116116
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "pattern" attribute.', $path));
117117
}
118118

119+
$schemes = array_filter(explode(' ', $node->getAttribute('schemes')));
120+
$methods = array_filter(explode(' ', $node->getAttribute('methods')));
121+
119122
list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);
120123

121-
$route = new Route($node->getAttribute('pattern'), $defaults, $requirements, $options, $node->getAttribute('hostname-pattern'));
124+
$route = new Route($node->getAttribute('pattern'), $defaults, $requirements, $options, $node->getAttribute('hostname-pattern'), $schemes, $methods);
122125
$collection->add($id, $route);
123126
}
124127

@@ -141,6 +144,8 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
141144
$type = $node->getAttribute('type');
142145
$prefix = $node->getAttribute('prefix');
143146
$hostnamePattern = $node->hasAttribute('hostname-pattern') ? $node->getAttribute('hostname-pattern') : null;
147+
$schemes = $node->hasAttribute('schemes') ? array_filter(explode(' ', $node->getAttribute('schemes'))) : null;
148+
$methods = $node->hasAttribute('methods') ? array_filter(explode(' ', $node->getAttribute('methods'))) : null;
144149

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

@@ -152,6 +157,12 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
152157
if (null !== $hostnamePattern) {
153158
$subCollection->setHostnamePattern($hostnamePattern);
154159
}
160+
if (null !== $schemes) {
161+
$subCollection->setSchemes($schemes);
162+
}
163+
if (null !== $methods) {
164+
$subCollection->setMethods($methods);
165+
}
155166
$subCollection->addDefaults($defaults);
156167
$subCollection->addRequirements($requirements);
157168
$subCollection->addOptions($options);

src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717

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

20+
<xsd:simpleType name="word">
21+
<xsd:restriction base="xsd:string">
22+
<xsd:pattern value="([a-zA-Z]){3,}"/>
23+
</xsd:restriction>
24+
</xsd:simpleType>
25+
26+
<xsd:simpleType name="stringlist">
27+
<xsd:list itemType="word"/>
28+
</xsd:simpleType>
29+
2030
<xsd:complexType name="routes">
2131
<xsd:choice minOccurs="0" maxOccurs="unbounded">
2232
<xsd:element name="import" type="import" />
@@ -38,6 +48,8 @@
3848
<xsd:attribute name="id" type="xsd:string" use="required" />
3949
<xsd:attribute name="pattern" type="xsd:string" use="required" />
4050
<xsd:attribute name="hostname-pattern" type="xsd:string" />
51+
<xsd:attribute name="schemes" type="stringlist" />
52+
<xsd:attribute name="methods" type="stringlist" />
4153
</xsd:complexType>
4254

4355
<xsd:complexType name="import">
@@ -47,6 +59,8 @@
4759
<xsd:attribute name="type" type="xsd:string" />
4860
<xsd:attribute name="prefix" type="xsd:string" />
4961
<xsd:attribute name="hostname-pattern" type="xsd:string" />
62+
<xsd:attribute name="schemes" type="stringlist" />
63+
<xsd:attribute name="methods" type="stringlist" />
5064
</xsd:complexType>
5165

5266
<xsd:complexType name="element">

0 commit comments

Comments
 (0)