8000 WIP [Routing] add scheme and method route definition option by Tobion · Pull Request #6049 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

WIP [Routing] add scheme and method route definition option #6049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 15, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
made schemes and methods available in XmlFileLoader
it uses an attribute list instead of multiple scheme/method elements that I also experimented with
  • Loading branch information
Tobion committed Dec 12, 2012
commit e803f4663c0b488b9a76f501d4fcb5cb6a89f51d
13 changes: 12 additions & 1 deletion src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "pattern" attribute.', $path));
}

$schemes = array_filter(explode(' ', $node->getAttribute('schemes')));
$methods = array_filter(explode(' ', $node->getAttribute('methods')));

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

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

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

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

Expand All @@ -152,6 +157,12 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
if (null !== $hostnamePattern) {
$subCollection->setHostnamePattern($hostnamePattern);
}
if (null !== $schemes) {
$subCollection->setSchemes($schemes);
}
if (null !== $methods) {
$subCollection->setMethods($methods);
}
$subCollection->addDefaults($defaults);
$subCollection->addRequirements($requirements);
$subCollection->addOptions($options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

<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 @@ -38,6 +48,8 @@
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="pattern" type="xsd:string" use="required" />
<xsd:attribute name="hostname-pattern" type="xsd:string" />
<xsd:attribute name="schemes" type="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
</xsd:complexType>

<xsd:complexType name="import">
Expand All @@ -47,6 +59,8 @@
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="prefix" type="xsd:string" />
<xsd:attribute name="hostname-pattern" type="xsd:string" />
<xsd:attribute name="schemes" type="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
</xsd:complexType>

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