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/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::validate()
  2. 11.1.x core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::validate()

Throws

\InvalidArgumentException If one of the provided config keys is not supported, something is missing or the combination is nonsense

1 call to YamlFileLoader::validate()
YamlFileLoader::load in vendor/symfony/routing/Loader/YamlFileLoader.php

File

vendor/symfony/routing/Loader/YamlFileLoader.php, line 244

Class

YamlFileLoader
YamlFileLoader loads Yaml routing files.

Namespace

Symfony\Component\Routing\Loader

Code

protected function validate(mixed $config, string $name, string $path) : void {
    if (!\is_array($config)) {
        throw new \InvalidArgumentException(\sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));
    }
    if (isset($config['alias'])) {
        $this->validateAlias($config, $name, $path);
        return;
    }
    if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {
        throw new \InvalidArgumentException(\sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS)));
    }
    if (isset($config['resource']) && isset($config['path'])) {
        throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
    }
    if (!isset($config['resource']) && isset($config['type'])) {
        throw new \InvalidArgumentException(\sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
    }
    if (!isset($config['resource']) && !isset($config['path'])) {
        throw new \InvalidArgumentException(\sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
    }
    if (isset($config['controller']) && isset($config['defaults']['_controller'])) {
        throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));
    }
    if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) {
        throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name));
    }
}

API Navigation

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