SS_ConfigManifest
class SS_ConfigManifest (View source)
A utility class which builds a manifest of configuration items
Properties
array | $yamlConfig | The calculated config from _config/*.yml, sorted, filtered and merged. Variant specific. |
|
array | $modules | A side-effect of collecting the _config fragments is the calculation of all module directories, since the definition of a module is "a directory that contains either a _config.php file or a _config directory |
Methods
Adds a path as a module
Returns true if the passed module exists
Constructs and initialises a new configuration object, either loading from the cache or re-scanning for classes.
Register a callback to be called whenever the calculated merged config changes
Includes all of the php _config.php files found by this manifest. Called by SS_Config when adding this manifest
Gets the (merged) config value for the given class and config property name
Returns the string that uniquely identifies this variant. The variant is the combination of classes, modules, environment, environment variables and constants that selects which yaml fragments actually make it into the configuration because of "only" and "except" rules.
Completely regenerates the manifest file. Scans through finding all php _config.php and yaml _config/*.ya?ml files,parses the yaml files into fragments, sorts them and figures out what values need to be checked to pick the correct variant.
Handle finding a php file. We just keep a record of all php files found, we don't include them at this stage
Handle finding a yml file. Parse the file by spliting it into header/fragment pairs, and normalising some of the header values (especially: give anonymous name if none assigned, splt/complete before and after matchers)
This function filters the loaded yaml fragments, removing any that can't ever have their "only" and "except" rules match.
Returns false if the prefilterable parts of the rule aren't met, and true if they are
Builds the variant key spec - the list of values that need to be build to give a key that uniquely identifies this variant.
Adds any variables referenced in the passed rules to the $this->variantKeySpec array
Calculates which yaml config fragments are applicable in this variant, and merge those all together into the $this->yamlConfig propperty
Returns false if the non-prefilterable parts of the rule aren't met, and true if they are
Recursively merge a yaml fragment's configuration array into the primary merged configuration array.
Details
addModule($path)
Adds a path as a module
moduleExists($module)
Returns true if the passed module exists
__construct(string $base, bool $includeTests = false, bool $forceRegen = false)
Constructs and initialises a new configuration object, either loading from the cache or re-scanning for classes.
registerChangeCallback(callable $callback)
Register a callback to be called whenever the calculated merged config changes
In some situations the merged config can change - for instance, code in _config.php can cause which Only and Except fragments match. Registering a callback with this function allows code to be called when this happens.
void
activateConfig()
Includes all of the php _config.php files found by this manifest. Called by SS_Config when adding this manifest
any
get(string $class, string $name, any $default = null)
Gets the (merged) config value for the given class and config property name
string
variantKey()
Returns the string that uniquely identifies this variant. The variant is the combination of classes, modules, environment, environment variables and constants that selects which yaml fragments actually make it into the configuration because of "only" and "except" rules.
regenerate(bool $includeTests = false, bool $cache = true)
Completely regenerates the manifest file. Scans through finding all php _config.php and yaml _config/*.ya?ml files,parses the yaml files into fragments, sorts them and figures out what values need to be checked to pick the correct variant.
Does not build the actual variant
addSourceConfigFile($basename, $pathname, $depth)
Handle finding a php file. We just keep a record of all php files found, we don't include them at this stage
Public so that ManifestFileFinder can call it. Not for general use.
addYAMLConfigFile($basename, $pathname, $depth)
Handle finding a yml file. Parse the file by spliting it into header/fragment pairs, and normalising some of the header values (especially: give anonymous name if none assigned, splt/complete before and after matchers)
Public so that ManifestFileFinder can call it. Not for general use.
prefilterYamlFragments()
This function filters the loaded yaml fragments, removing any that can't ever have their "only" and "except" rules match.
Some tests in "only" and "except" rules need to be checked per request, but some are manifest based - these are invariant over requests and only need checking on manifest rebuild. So we can prefilter these before saving yamlConfigFragments to speed up the process of checking the per-request variant/
bool
matchesPrefilterVariantRules($rules)
Returns false if the prefilterable parts of the rule aren't met, and true if they are
buildVariantKeySpec()
Builds the variant key spec - the list of values that need to be build to give a key that uniquely identifies this variant.
addVariantKeySpecRules($rules)
Adds any variables referenced in the passed rules to the $this->variantKeySpec array
buildYamlConfigVariant($cache = true)
Calculates which yaml config fragments are applicable in this variant, and merge those all together into the $this->yamlConfig propperty
Checks cache and takes care of loading yamlConfigFragments if they aren't already present, but expects $variantKeySpec to already be set
matchesVariantRules($rules)
Returns false if the non-prefilterable parts of the rule aren't met, and true if they are
void
mergeInYamlFragment($into, $fragment)
Recursively merge a yaml fragment's configuration array into the primary merged configuration array.