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

Breadcrumb

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

function YamlFileLoader::validate

Same name in this branch
  1. 11.1.x vendor/symfony/routing/Loader/YamlFileLoader.php \Symfony\Component\Routing\Loader\YamlFileLoader::validate()
  2. 11.1.x vendor/symfony/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::validate()

Validates a YAML file.

Parameters

mixed $content:

string $file:

Return value

array

Throws

InvalidArgumentException When service file is not valid.

1 call to YamlFileLoader::validate()
YamlFileLoader::loadFile in core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
Loads a YAML file.

File

core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php, line 469

Class

YamlFileLoader
YamlFileLoader loads YAML files service definitions.

Namespace

Drupal\Core\DependencyInjection

Code

private function validate($content, $file) {
    if (null === $content) {
        return $content;
    }
    if (!is_array($content)) {
        throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
    }
    if ($invalid_keys = array_keys(array_diff_key($content, array(
        'parameters' => 1,
        'services' => 1,
    )))) {
        throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid root key(s) "%s". Services have to be added under "services" and Parameters under "parameters".', $file, implode('", "', $invalid_keys)));
    }
    return $content;
}

API Navigation

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