public function YamlFileLoader::load in Zircon Profile 8.0
Same name in this branch
- 8.0 vendor/symfony/routing/Loader/YamlFileLoader.php \Symfony\Component\Routing\Loader\YamlFileLoader::load()
- 8.0 vendor/symfony/translation/Loader/YamlFileLoader.php \Symfony\Component\Translation\Loader\YamlFileLoader::load()
- 8.0 vendor/symfony/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::load()
- 8.0 core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::load()
Same name and namespace in other branches
- 8 vendor/symfony/routing/Loader/YamlFileLoader.php \Symfony\Component\Routing\Loader\YamlFileLoader::load()
Loads a Yaml file.
Parameters
string $file A Yaml file path:
string|null $type The resource type:
Return value
RouteCollection A RouteCollection instance
Throws
\InvalidArgumentException When a route can't be parsed because YAML is invalid
File
- vendor/
symfony/ routing/ Loader/ YamlFileLoader.php, line 44
Class
- YamlFileLoader
- YamlFileLoader loads Yaml routing files.
Namespace
Symfony\Component\Routing\LoaderCode
public function load($file, $type = null) {
$path = $this->locator
->locate($file);
if (!stream_is_local($path)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
}
if (!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
}
if (null === $this->yamlParser) {
$this->yamlParser = new YamlParser();
}
try {
$parsedConfig = $this->yamlParser
->parse(file_get_contents($path));
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
}
$collection = new RouteCollection();
$collection
->addResource(new FileResource($path));
// empty file
if (null === $parsedConfig) {
return $collection;
}
// not an array
if (!is_array($parsedConfig)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
}
foreach ($parsedConfig as $name => $config) {
if (isset($config['pattern'])) {
if (isset($config['path'])) {
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
}
@trigger_error(sprintf('The "pattern" option in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "path" option in the route definition instead.', $path), E_USER_DEPRECATED);
$config['path'] = $config['pattern'];
unset($config['pattern']);
}
$this
->validate($config, $name, $path);
if (isset($config['resource'])) {
$this
->parseImport($collection, $config, $path, $file);
}
else {
$this
->parseRoute($collection, $name, $config, $path);
}
}
return $collection;
}