Loads a Yaml file.
@api
string $file A Yaml file path:
string $type The resource type:
RouteCollection A RouteCollection instance
\InvalidArgumentException When route can't be parsed
public function load($file, $type = null) {
$path = $this->locator
->locate($file);
$config = Yaml::parse($path);
$collection = new RouteCollection();
$collection
->addResource(new FileResource($path));
// empty file
if (null === $config) {
$config = array();
}
// not an array
if (!is_array($config)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file));
}
foreach ($config as $name => $config) {
$config = $this
->normalizeRouteConfig($config);
if (isset($config['resource'])) {
$type = isset($config['type']) ? $config['type'] : null;
$prefix = isset($config['prefix']) ? $config['prefix'] : null;
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
$this
->setCurrentDir(dirname($path));
$collection
->addCollection($this
->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options);
}
else {
$this
->parseRoute($collection, $name, $config, $path);
}
}
return $collection;
}