final class DocumentReader

Reads configuration and definition documents written in YAML or Markdown.

A file ending in .md or .markdown is read as Markdown cards; any other file as YAML. Every document is validated against its bundled schema and any local schema it declares.

Properties§

public MarkdownDocument $markdown = new \Requirements\Config\MarkdownDocument()

Methods§

public function __construct(public MarkdownDocument $markdown = new \Requirements\Config\MarkdownDocument())

Parameters

$markdownMarkdownDocumentReads Markdown definitions and remembers how they were written
Calls 1
public function read(
    string $path,
    string $kind,
    array<string, mixed> $markdown = [],
    string|null $directory = null,
): stdClass

Reads and validates a document.

Parameters

$pathstringThe document file
$kindstring"config" or "definition", naming the schema
$markdownarray<string, mixed>The markdown options
$directorystring|nullThe configuration directory; the file's directory when null

Returns

stdClass The document

Throws

InvalidInputException When the document breaks its schema or is not a mapping
JsonException When a schema cannot be decoded
ParseException When a YAML document is malformed
Test cases 12
Called from 3
Calls 8
public static function isMarkdown(string $path): bool

Tells whether a file is read as Markdown.

Parameters

$pathstringThe file

Returns

bool True for the .md and .markdown extensions, in any case
Test cases 1
Called from 3
Calls 3
public static function mapping(stdClass $document, string $file): array<string, mixed>

Converts a read document to a mapping.

Parameters

$documentstdClassThe document
$filestringThe document file, used in the error message

Returns

array<string, mixed> The document as nested arrays

Throws

InvalidInputException When the document is not a mapping
JsonException When the document cannot be converted
Test cases 5
Called from 2
Calls 3
public static function yaml(mixed $data): string

Writes data as a formatted YAML document.

Parameters

$datamixedThe document

Returns

string The YAML text
Test cases 1
Called from 2
Calls 4
  • static-call Yaml::dump() line 92
  • class-const Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK() line 92
  • class-const Yaml::DUMP_OBJECT_AS_MAP() line 92
  • class-const Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE() line 92

Test cases 34§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 17
Other tests reaching this symbol 17

Relations§

Instantiated in 3
Static calls 6
Method calls 3