Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. YamlFileLoader.php

function YamlFileLoader::loadFile

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::loadFile()

Loads a YAML file.

Throws

InvalidArgumentException when the given file is not a local file or when it does not exist

1 call to YamlFileLoader::loadFile()
YamlFileLoader::load in vendor/symfony/dependency-injection/Loader/YamlFileLoader.php

File

vendor/symfony/dependency-injection/Loader/YamlFileLoader.php, line 767

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

protected function loadFile(string $file) : ?array {
    if (!class_exists(YamlParser::class)) {
        throw new RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed. Try running "composer require symfony/yaml".');
    }
    if (!stream_is_local($file)) {
        throw new InvalidArgumentException(\sprintf('This is not a local file "%s".', $file));
    }
    if (!is_file($file)) {
        throw new InvalidArgumentException(\sprintf('The file "%s" does not exist.', $file));
    }
    $this->yamlParser ??= new YamlParser();
    try {
        $configuration = $this->yamlParser
            ->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
    } catch (ParseException $e) {
        throw new InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML: ', $file) . $e->getMessage(), 0, $e);
    }
    return $this->validate($configuration, $file);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal