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

Breadcrumb

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

function Parser::parseFile

Parses a YAML file into a PHP value.

Parameters

string $filename The path to the YAML file to be parsed:

int-mask-of<Yaml::PARSE_*> $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior:

Throws

ParseException If the file could not be read or the YAML is not valid

File

vendor/symfony/yaml/Parser.php, line 50

Class

Parser
Parser parses YAML strings to convert them to PHP arrays.

Namespace

Symfony\Component\Yaml

Code

public function parseFile(string $filename, int $flags = 0) : mixed {
    if (!is_file($filename)) {
        throw new ParseException(\sprintf('File "%s" does not exist.', $filename));
    }
    if (!is_readable($filename)) {
        throw new ParseException(\sprintf('File "%s" cannot be read.', $filename));
    }
    $this->filename = $filename;
    try {
        return $this->parse(file_get_contents($filename), $flags);
    } finally {
        $this->filename = null;
    }
}

API Navigation

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