8000 fix namespace handling in xml loader; it could not handle prefixes · symfony/symfony@83fc5ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 83fc5ff

Browse files
committed
fix namespace handling in xml loader; it could not handle prefixes
1 parent 1a60a3c commit 83fc5ff

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*/
2626
class XmlFileLoader extends FileLoader
2727
{
28+
const NAMESPACE_URI = 'http://symfony.com/schema/routing';
29+
const SCHEME_PATH = '/schema/routing/routing-1.0.xsd';
30+
2831
/**
2932
* Loads an XML file.
3033
*
@@ -70,7 +73,11 @@ public function load($file, $type = null)
7073
*/
7174
protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file)
7275
{
73-
switch ($node->tagName) {
76+
if (self::NAMESPACE_URI !== $node->namespaceURI) {
77+
return;
78+
}
79+
80+
switch ($node->localName) {
7481
case 'route':
7582
$this->parseRoute($collection, $node, $path);
7683
break;
@@ -84,23 +91,19 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
8491
$requirements = array();
8592
$options = array();
8693

87-
foreach ($node->childNodes as $n) {
88-
if (!$n instanceof \DOMElement) {
89-
continue;
90-
}
91-
92-
switch ($n->tagName) {
94+
foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) {
95+
switch ($n->localName) {
9396
case 'default':
94-
$defaults[$n->getAttribute('key')] = trim($n->nodeValue);
97+
$defaults[$n->getAttribute('key')] = trim($n->textContent);
9598
break;
9699
case 'requirement':
97-
$requirements[$n->getAttribute('key')] = trim($n->nodeValue);
100+
$requirements[$n->getAttribute('key')] = trim($n->textContent);
98101
break;
99102
case 'option':
100-
$options[$n->getAttribute('key')] = trim($n->nodeValue);
103+
$options[$n->getAttribute('key')] = trim($n->textContent);
101104
break;
102105
default:
103-
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->tagName, $file));
106+
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->localName, $file));
104107
}
105108
}
106109

@@ -119,7 +122,7 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
119122
$collection->addCollection($subCollection);
120123
break;
121124
default:
122-
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->tagName, $file));
125+
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $file));
123126
}
124127
}
125128

@@ -148,23 +151,19 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $definiti
148151
$requirements = array();
149152
$options = array();
150153

151-
foreach ($definition->childNodes as $node) {
152-
if (!$node instanceof \DOMElement) {
153-
continue;
154-
}
155-
156-
switch ($node->tagName) {
154+
foreach ($definition->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $node) {
155+
switch ($node->localName) {
157156
case 'default':
158-
$defaults[$node->getAttribute('key')] = trim($node->nodeValue);
157+
$defaults[$node->getAttribute('key')] = trim($node->textContent);
159158
break;
160159
case 'option':
161-
$options[$node->getAttribute('key')] = trim($node->nodeValue);
160+
$options[$node->getAttribute('key')] = trim($node->textContent);
162161
break;
163162
case 'requirement':
164-
$requirements[$node->getAttribute('key')] = trim($node->nodeValue);
163+
$r 8000 equirements[$node->getAttribute('key')] = trim($node->textContent);
165164
break;
166165
default:
167-
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $node->tagName, $file));
166+
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $node->localName, $file));
168167
}
169168
}
170169

@@ -220,12 +219,10 @@ protected function loadFile($file)
220219
*/
221220
protected function validate(\DOMDocument $dom)
222221
{
223-
$location = __DIR__.'/schema/routing/routing-1.0.xsd';
224-
225222
$current = libxml_use_internal_errors(true);
226223
libxml_clear_errors();
227224

228-
if (!$dom->schemaValidate($location)) {
225+
if (!$dom->schemaValidate(__DIR__ . static::SCHEME_PATH)) {
229226
throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors($current)));
230227
}
231228
libxml_use_internal_errors($current);

0 commit comments

Comments
 (0)
0