class SS_ConfigManifest (View source)

A utility class which builds a manifest of configuration items

Properties

protected string $base
protected string $key
protected bool $includeTests
protected array $variantKeySpec

All the values needed to be collected to determine the correct combination of fragements for the current environment.

protected array $phpConfigSources

All the _config.php files. Need to be included every request & can't be cached. Not variant specific.

protected array $yamlConfigFragments

All the _config/*.yml fragments pre-parsed and sorted in ascending include order. Not variant specific.

public array $yamlConfig

The calculated config from _config/*.yml, sorted, filtered and merged. Variant specific.

protected string $yamlConfigVariantKey

The variant key state as when yamlConfig was loaded

protected $configChangeCallbacks
public 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

public
addModule($path)

Adds a path as a module

public
moduleExists($module)

Returns true if the passed module exists

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

protected
Zend_Cache_Core
getCache()

Provides a hook for mock unit tests despite no DI

public
registerChangeCallback(callable $callback)

Register a callback to be called whenever the calculated merged config changes

public
void
activateConfig()

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

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

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

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

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

public
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
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)

protected
void
sortYamlFragments()

Sorts the YAML fragments so that the "before" and "after" rules are met.

protected
string
relativeOrder($a, $b)

Return a string "after", "before" or "undefined" depending on whether the YAML fragment array element passed as $a should be positioned after, before, or either compared to the YAML fragment array element passed as $b

public
prefilterYamlFragments()

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

public
bool
matchesPrefilterVariantRules($rules)

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

public
buildVariantKeySpec()

Builds the variant key spec - the list of values that need to be build to give a key that uniquely identifies this variant.

public
addVariantKeySpecRules($rules)

Adds any variables referenced in the passed rules to the $this->variantKeySpec array

public
buildYamlConfigVariant($cache = true)

Calculates which yaml config fragments are applicable in this variant, and merge those all together into the $this->yamlConfig propperty

public
matchesVariantRules($rules)

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

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

protected Zend_Cache_Core getCache()

Provides a hook for mock unit tests despite no DI

Return Value

Zend_Cache_Core

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

protected void sortYamlFragments()

Sorts the YAML fragments so that the "before" and "after" rules are met.

Throws an error if there's a loop

We can't use regular sorts here - we need a topological sort. Easiest way is with a DAG, so build up a DAG based on the before/after rules, then sort that.

Return Value

void

protected string relativeOrder($a, $b)

Return a string "after", "before" or "undefined" depending on whether the YAML fragment array element passed as $a should be positioned after, before, or either compared to the YAML fragment array element passed as $b

Parameters

$a

Array - a YAML config fragment as loaded by addYAMLConfigFile

$b

Array - a YAML config fragment as loaded by addYAMLConfigFile

Return Value

string

"after", "before" or "undefined"

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