class YamlTransformer implements TransformerInterface (View source)

Constants

BEFORE_FLAG

AFTER_FLAG

ONLY_FLAG

EXCEPT_FLAG

Properties

protected array $files

A list of files. Real, full path.

protected array $documents

Store the yaml document content as an array.

protected string $baseDirectory

Base directory used to find yaml files.

protected Closure[] $rules

A list of closures to be used in only/except rules.

protected array $ignoreRules

A list of ignored before/after statements.

Methods

public
__construct(string $baseDir, Finder $finder)

No description

public static 
create(string $baseDir, Finder $finder)

No description

public
transform(MutableConfigCollectionInterface $collection)

This is responsible for parsing a single yaml file and returning it into a format that Config can understand. Config will then be responsible for turning thie output into the final merged config.

public
$this
addRule(string $rule, Closure $func)

This allows external rules to be added to only/except checks. Config is only supposed to be setup once, so adding rules is a one-way system. You cannot remove rules after being set. This also prevent built-in rules from being removed.

protected
bool
hasRule($rule)

Checks to see if a rule is present

public
ignoreRule(string $rule)

This allows config to ignore only/except rules that have been set. This enables apps to ignore built-in rules without causing errors where a rule is undefined.

protected
bool
isRuleIgnored(string $rule)

Checks to see if a rule is ignored

protected
array
getNamedYamlDocuments()

Returns an array of YAML documents keyed by name.

protected
array
splitYamlDocuments()

Because multiple documents aren't supported in symfony/yaml, we have to manually split the files up into their own documents before running them through the parser.

protected
array
calculateDependencies(array $documents)

This generates an array of all document depndencies, keyed by document name.

protected
array
addDependencies(array $header, string $flag, array $dependencies, array $documents)

Incapsulates the logic for adding before/after dependencies.

protected
array
getMatchingDocuments(string $pattern, array $documents, string $flag)

This returns an array of documents which match the given pattern. The pattern is expected to come from before/after blocks of yaml (eg. framwork/*).

protected
string
makeRelative(string $filename)

We need this to make the path relative from the base directory. We can't use realpath or relative path in Finder because we use a virtual filesystem in testing which doesn't support these methods.

protected
array
getSortedYamlDocuments()

This method gets all headers and all yaml documents and stores them respectively.

protected
array
filterByOnlyAndExcept()

This filteres out any yaml documents which don't pass their only or except statement tests.

protected
bool
testRules(array $header, string $flag)

Tests the only except rules for a header.

protected
bool
testSingleRule(string $rule, string|array $params, string $flag = self::ONLY_FLAG)

Tests a rule against the given expected result.

protected
bool
evaluateConditions(array $source, string $flag, callable $condition)

Evaluate condition against a set of data using the appropriate conjuction for the flag

Details

__construct(string $baseDir, Finder $finder)

No description

Parameters

string $baseDir

directory to scan for yaml files

Finder $finder

static YamlTransformer create(string $baseDir, Finder $finder)

No description

Parameters

string $baseDir

directory to scan for yaml files

Finder $finder

Return Value

YamlTransformer

MutableConfigCollectionInterface transform(MutableConfigCollectionInterface $collection)

This is responsible for parsing a single yaml file and returning it into a format that Config can understand. Config will then be responsible for turning thie output into the final merged config.

$this addRule(string $rule, Closure $func)

This allows external rules to be added to only/except checks. Config is only supposed to be setup once, so adding rules is a one-way system. You cannot remove rules after being set. This also prevent built-in rules from being removed.

Parameters

string $rule
Closure $func

Return Value

$this

protected bool hasRule($rule)

Checks to see if a rule is present

Parameters

$rule

Return Value

bool

ignoreRule(string $rule)

This allows config to ignore only/except rules that have been set. This enables apps to ignore built-in rules without causing errors where a rule is undefined.

This, is a one-way system and is only meant to be configured once. When you ignore a rule, you cannot un-ignore it.

Parameters

string $rule

protected bool isRuleIgnored(string $rule)

Checks to see if a rule is ignored

Parameters

string $rule

Return Value

bool

protected array getNamedYamlDocuments()

Returns an array of YAML documents keyed by name.

Return Value

array

Exceptions

Exception

protected array splitYamlDocuments()

Because multiple documents aren't supported in symfony/yaml, we have to manually split the files up into their own documents before running them through the parser.

Note: This is not a complete implementation of multi-document YAML parsing. There are valid yaml cases where this will fail, however they don't match our use-case.

Return Value

array

protected array calculateDependencies(array $documents)

This generates an array of all document depndencies, keyed by document name.

Parameters

array $documents

Return Value

array

protected array addDependencies(array $header, string $flag, array $dependencies, array $documents)

Incapsulates the logic for adding before/after dependencies.

Parameters

array $header
string $flag
array $dependencies
array $documents

Return Value

array

protected array getMatchingDocuments(string $pattern, array $documents, string $flag)

This returns an array of documents which match the given pattern. The pattern is expected to come from before/after blocks of yaml (eg. framwork/*).

Parameters

string $pattern
array $documents
string $flag

'before' / 'after'

Return Value

array

protected string makeRelative(string $filename)

We need this to make the path relative from the base directory. We can't use realpath or relative path in Finder because we use a virtual filesystem in testing which doesn't support these methods.

Parameters

string $filename

Return Value

string

protected array getSortedYamlDocuments()

This method gets all headers and all yaml documents and stores them respectively.

Return Value

array

a list of sorted yaml documents

protected array filterByOnlyAndExcept()

This filteres out any yaml documents which don't pass their only or except statement tests.

Return Value

array

protected bool testRules(array $header, string $flag)

Tests the only except rules for a header.

Parameters

array $header
string $flag

Return Value

bool

Exceptions

Exception

protected bool testSingleRule(string $rule, string|array $params, string $flag = self::ONLY_FLAG)

Tests a rule against the given expected result.

Parameters

string $rule
string|array $params
string $flag

Return Value

bool

Exceptions

Exception

protected bool evaluateConditions(array $source, string $flag, callable $condition)

Evaluate condition against a set of data using the appropriate conjuction for the flag

Parameters

array $source

Items to apply condition to

string $flag

Flag type

callable $condition

Callback to evaluate each item in the $source. Both key and value of each item in $source will be passed as arguments. This callback should return true, false, or null to skip

Return Value

bool

Evaluation of the applied condition