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

Breadcrumb

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

function LintCommand::validate

1 call to LintCommand::validate()
LintCommand::execute in vendor/symfony/yaml/Command/LintCommand.php
Executes the current command.

File

vendor/symfony/yaml/Command/LintCommand.php, line 130

Class

LintCommand
Validates YAML files syntax and outputs encountered errors.

Namespace

Symfony\Component\Yaml\Command

Code

private function validate(string $content, int $flags, ?string $file = null) : array {
    $prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
        if (\E_USER_DEPRECATED === $level) {
            throw new ParseException($message, $this->getParser()
                ->getRealCurrentLineNb() + 1);
        }
        return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
    });
    try {
        $this->getParser()
            ->parse($content, Yaml::PARSE_CONSTANT | $flags);
    } catch (ParseException $e) {
        return [
            'file' => $file,
            'line' => $e->getParsedLine(),
            'valid' => false,
            'message' => $e->getMessage(),
        ];
    } finally {
        restore_error_handler();
    }
    return [
        'file' => $file,
        'valid' => true,
    ];
}
RSS feed
Powered by Drupal