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

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

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.

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

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)

prefilterYamlFragments()

This function filters the loaded yaml fragments, removing any that can't ever have their "only" and "except" rules match.

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

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.

Details

addModule($path)

Adds a path as a module

Parameters

$path

moduleExists($module)

Returns true if the passed module exists

Parameters

$module

__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.

Parameters

string $base

The project base path.

bool $includeTests
bool $forceRegen

Force the manifest to be regenerated.

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.

Parameters

callable $callback

void activateConfig()

Includes all of the php _config.php files found by this manifest. Called by SS_Config when adding this manifest

Return Value

void

any get(string $class, string $name, any $default = null)

Gets the (merged) config value for the given class and config property name

Parameters

string $class
  • The class to get the config property value for
string $name
  • The config property to get the value for
any $default
  • What to return if no value was contained in any YAML file for the passed $class and $name

Return Value

any
  • The merged set of all values contained in all the YAML configuration files for the passed $class and $name, or $default if there are none

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.

Return Value

string

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

Parameters

bool $includeTests
bool $cache

Cache the result.

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.

Parameters

$basename
$pathname
$depth

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.

Parameters

$basename
$pathname
$depth

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

Parameters

$rules

array - A hash of rules as allowed in the only or except portion of a config fragment header

Return Value

bool
  • True if the rules are met, false if not. (Note that depending on whether we were passed an only or an except rule, which values means accept or reject a fragment

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

Parameters

$rules

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

Parameters

$cache

matchesVariantRules($rules)

Returns false if the non-prefilterable parts of the rule aren't met, and true if they are

Parameters

$rules

void mergeInYamlFragment($into, $fragment)

Recursively merge a yaml fragment's configuration array into the primary merged configuration array.

Parameters

$into
$fragment

Return Value

void