YamlTransformer
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
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 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.
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.
This generates an array of all document depndencies, keyed by document name.
Incapsulates the logic for adding before/after dependencies.
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/*).
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.
This method gets all headers and all yaml documents and stores them respectively.
This filteres out any yaml documents which don't pass their only or except statement tests.
Tests a rule against the given expected result.
Evaluate condition against a set of data using the appropriate conjuction for the flag
Details
__construct(string $baseDir, Finder $finder)
No description
static YamlTransformer
create(string $baseDir, Finder $finder)
No description
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.
protected bool
hasRule($rule)
Checks to see if a rule is present
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.
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.
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.
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 = YamlTransformer::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