Skip to content

Commit

Permalink
fix the loaders to not use the deprecated API
Browse files Browse the repository at this point in the history
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 Dec 6, 2012
1 parent 36abbd6 commit b6d1e22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down
14 changes: 11 additions & 3 deletions src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b6d1e22

Please sign in to comment.