YamlFileLoader implements LoggerAwareInterface uses LoggerAwareTrait

A YAML file loader that allows to load YAML files, based on the Symfony/Yaml component

In addition to just load a YAML file, it adds some special functionality.

  • A special "imports" key in the YAML file allows to include other YAML files recursively. The actual YAML file gets loaded after the import statements, which are interpreted first, at the very beginning. Imports can be referenced with a relative path.

  • Merging configuration options of import files when having simple "lists" will add items to the list instead of overwriting them.

  • Special placeholder values set via %optionA.suboptionB% replace the value with the named path of the configuration The placeholders will act as a full replacement of this value.

  • Environment placeholder values set via %env(option)% will be replaced by env variables of the same name

Table of Contents

Interfaces

LoggerAwareInterface

Constants

PATTERN_PARTS  = '%[^(%]+?\([\'"]?([^(]*?)[\'"]?\)%|%([^%()]*?)%'
PROCESS_IMPORTS  = 2
PROCESS_PLACEHOLDERS  = 1

Methods

load()  : array<string|int, mixed>
Loads and parses a YAML file, and returns an array with the found data
containsPlaceholder()  : bool
Finds possible placeholders.
getFileContents()  : string
Put into a separate method to ease the pains with unit tests
getParts()  : array<string|int, mixed>
getStreamlinedFileName()  : string
Fetches the absolute file name, but if a different file name is given, it is built relative to that.
hasFlag()  : bool
loadAndParse()  : array<string|int, mixed>
Internal method which does all the logic. Built so it can be re-used recursively.
processImports()  : array<string|int, mixed>
Checks for the special "imports" key on the main level of a file, which calls "load" recursively.
processPlaceholderLine()  : mixed
processPlaceholders()  : array<string|int, mixed>
Main function that gets called recursively to check for %...% placeholders inside the array
processSinglePlaceholder()  : mixed

Constants

PATTERN_PARTS

public mixed PATTERN_PARTS = '%[^(%]+?\([\'"]?([^(]*?)[\'"]?\)%|%([^%()]*?)%'

PROCESS_IMPORTS

public mixed PROCESS_IMPORTS = 2

PROCESS_PLACEHOLDERS

public mixed PROCESS_PLACEHOLDERS = 1

Methods

load()

Loads and parses a YAML file, and returns an array with the found data

public load(string $fileName[, int $flags = self::PROCESS_PLACEHOLDERS | self::PROCESS_IMPORTS ]) : array<string|int, mixed>
Parameters
$fileName : string

either relative to TYPO3's base project folder or prefixed with EXT:...

$flags : int = self::PROCESS_PLACEHOLDERS | self::PROCESS_IMPORTS

Flags to configure behaviour of the loader: see public PROCESS_ constants above

Return values
array<string|int, mixed>

the configuration as array

containsPlaceholder()

Finds possible placeholders.

protected containsPlaceholder(mixed $value) : bool

May find false positives for complexer structures, but they will be sorted later on.

Parameters
$value : mixed
Return values
bool

getFileContents()

Put into a separate method to ease the pains with unit tests

protected getFileContents(string $fileName) : string
Parameters
$fileName : string
Return values
string

the contents or empty string if file_get_contents fails

getParts()

protected getParts(string $placeholders) : array<string|int, mixed>
Parameters
$placeholders : string
Return values
array<string|int, mixed>

getStreamlinedFileName()

Fetches the absolute file name, but if a different file name is given, it is built relative to that.

protected getStreamlinedFileName(string $fileName, string|null $currentFileName) : string
Parameters
$fileName : string

either relative to TYPO3's base project folder or prefixed with EXT:...

$currentFileName : string|null

when called recursively this contains the absolute file name of the file that included this file

Tags
throws
YamlFileLoadingException

when the file was not accessible

Return values
string

the contents of the file

hasFlag()

protected hasFlag(int $flag) : bool
Parameters
$flag : int
Return values
bool

loadAndParse()

Internal method which does all the logic. Built so it can be re-used recursively.

protected loadAndParse(string $fileName, string|null $currentFileName) : array<string|int, mixed>
Parameters
$fileName : string

either relative to TYPO3's base project folder or prefixed with EXT:...

$currentFileName : string|null

when called recursively

Return values
array<string|int, mixed>

the configuration as array

processImports()

Checks for the special "imports" key on the main level of a file, which calls "load" recursively.

protected processImports(array<string|int, mixed> $content, string|null $fileName) : array<string|int, mixed>
Parameters
$content : array<string|int, mixed>
$fileName : string|null
Return values
array<string|int, mixed>

processPlaceholderLine()

protected processPlaceholderLine(string $line, array<string|int, mixed> $referenceArray) : mixed
Parameters
$line : string
$referenceArray : array<string|int, mixed>

processPlaceholders()

Main function that gets called recursively to check for %...% placeholders inside the array

protected processPlaceholders(array<string|int, mixed> $content, array<string|int, mixed> $referenceArray) : array<string|int, mixed>
Parameters
$content : array<string|int, mixed>

the current sub-level content array

$referenceArray : array<string|int, mixed>

the global configuration array

Return values
array<string|int, mixed>

the modified sub-level content array

processSinglePlaceholder()

protected processSinglePlaceholder(string $placeholder, string $value, array<string|int, mixed> $referenceArray) : mixed
Parameters
$placeholder : string
$value : string
$referenceArray : array<string|int, mixed>

        
On this page

Search results