Permalink
Browse files

fix the loaders to not use the deprecated API

it also fixes the xml and yaml loader that was not using the empty hostname pattern when importing a resource to reset the hostname pattern for it.
  • Loading branch information...
Tobion committed Nov 17, 2012
1 parent 36abbd6 commit b6d1e221e7c3a6ed4594fa88380122b8ea1abb07
@@ -78,7 +78,7 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
$resource = $node->getAttribute('resource');
$type = $node->getAttribute('type');
$prefix = $node->getAttribute('prefix');
- $hostnamePattern = $node->getAttribute('hostname-pattern');
+ $hostnamePattern = $node->hasAttribute('hostname-pattern') ? $node->getAttribute('hostname-pattern') : null;
$defaults = array();
$requirements = array();
@@ -105,7 +105,15 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
}
$this->setCurrentDir(dirname($path));
- $collection->addCollection($this->import($resource, ('' !== $type ? $type : null), false, $file), $prefix, $defaults, $requirements, $options, $hostnamePattern);
+
+ $subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file);
+ /* @var RouteCollection $subCollection */
+ $subCollection->addPrefix($prefix);
+ if (null !== $hostnamePattern) {
+ $subCollection->setHostnamePattern($hostnamePattern);
+ }
+ $subCollection->addConfigs($defaults, $requirements, $options);
+ $collection->addCollection($subCollection);
break;
default:
throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
@@ -66,14 +66,22 @@ public function load($file, $type = null)
if (isset($config['resource'])) {
$type = isset($config['type']) ? $config['type'] : null;
- $prefix = isset($config['prefix']) ? $config['prefix'] : null;
+ $prefix = isset($config['prefix']) ? $config['prefix'] : '';
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
- $hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : '';
+ $hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : null;
$this->setCurrentDir(dirname($path));
- $collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options, $hostnamePattern);
+
+ $subCollection = $this->import($config['resource'], $type, false, $file);
+ /* @var RouteCollection $subCollection */
+ $subCollection->addPrefix($prefix);
+ if (null !== $hostnamePattern) {
+ $subCollection->setHostnamePattern($hostnamePattern);
+ }
+ $subCollection->addConfigs($defaults, $requirements, $options);
+ $collection->addCollection($subCollection);
} else {
$this->parseRoute($collection, $name, $config, $path);
}

0 comments on commit b6d1e22

Please sign in to comment.