Class DirectoryConfig.
Description
Loads and aggregates configuration from a specified directory containing PHP files. This class MUST validate the target directory and match file names using Laminas glob semantics. It MAY cache the aggregated result if a cached config file path is provided.
Description
LaminasConfigAggregatorConfig
Interfaces
Constants
Properties
Methods
Constructs a DirectoryConfig instance.
Implementing class MUST define the __invoke() method to return a ConfigInterface instance.
Retrieves a configuration value by key.
Retrieves an iterator for traversing the configuration data.
Checks for existence of a configuration key.
Removes a configuration key.
Sets configuration data.
Exports the entire configuration to an array.
Selects visible child directories when recursive discovery is enabled.
Yields directory paths and their canonical identities in depth-then-path order.
Discovers files in depth-then-path order without following directory symlinks.
Escapes only the directory, leaving the library's filename pattern intact.
Retrieves or initializes the configuration instance.
Checks a candidate's canonical parent against the selected literal directory.
Matches the configured pattern inside a literal directory and resolves each file.
Skips children that become inaccessible between discovery and opening.
Includes discovered PHP files only when the aggregator resolves this provider.
private
string|null
$cachedConfigFile
=
null
private
ConfigInterface|null
$config
=
null
Description
holds the loaded configuration instance
private
string
$directory
Constructs a DirectoryConfig instance.
public
__construct(
string
$directory[,
string|null
$cachedConfigFile = null]) : mixed
Description
This constructor SHALL validate the specified directory, and initialize the Laminas config aggregator with a lazy file provider using the defined pattern. An existing cache file SHALL be reused when provided. Generating a cache file additionally requires a truthy config_cache_enabled entry.
Parameters
$directory
:
string
Description
the directory path from which to load configuration files
$cachedConfigFile
:
string|null
=
null
Description
optional path to a cache file for the aggregated configuration
Implementing class MUST define the __invoke() method to return a ConfigInterface instance.
public
abstract
__invoke() : ConfigInterface
Return values
Description
the actual configuration instance
Retrieves a configuration value by key.
public
get(
string
$key[,
mixed|null
$default = null]) : mixed
Parameters
$key
:
string
Description
the configuration key to retrieve
$default
:
mixed|null
=
null
Description
the default value if the key is not found
Return values
Description
the value of the configuration key or the default
Retrieves an iterator for traversing the configuration data.
public
getIterator() : Traversable
Return values
Description
an iterator over the configuration
Checks for existence of a configuration key.
public
has(
string
$key) : bool
Parameters
$key
:
string
Description
the configuration key to check
Return values
Description
TRUE if the key exists, FALSE otherwise
Removes a configuration key.
public
remove(
string
$key) : void
Parameters
$key
:
string
Description
the configuration key to remove
Sets configuration data.
public
set(
array<string|int, mixed>|ConfigInterface|string
$key[,
mixed|null
$value = null]) : void
Parameters
Description
the key or set of keys/values to set
$value
:
mixed|null
=
null
Description
the value to set if a single key is provided
Exports the entire configuration to an array.
public
toArray() : array<string|int, mixed>
Return values
Description
the configuration as an associative array
Selects visible child directories when recursive discovery is enabled.
private
discoverChildDirectories(
string
$directory) : array<int, string>
Parameters
$directory
:
string
Description
the parent directory path
Return values
Yields directory paths and their canonical identities in depth-then-path order.
private
discoverDirectories() : Generator<string, string>
Return values
Discovers files in depth-then-path order without following directory symlinks.
private
discoverFiles() : array<int, string>
Return values
Escapes only the directory, leaving the library's filename pattern intact.
private
escapeDirectory(
string
$directory) : string
Parameters
$directory
:
string
Description
the literal directory path
Return values
Retrieves or initializes the configuration instance.
private
getConfig() : ConfigInterface
Return values
Description
the lazily-loaded configuration object
Checks a candidate's canonical parent against the selected literal directory.
private
isWithinDirectory(
string
$file,
string
$directory) : bool
Parameters
$file
:
string
Description
the candidate path
$directory
:
string
Description
the canonical selected directory
Return values
Matches the configured pattern inside a literal directory and resolves each file.
private
matchFiles(
string
$directory,
string
$realDirectory) : Generator<int, string>
Parameters
$directory
:
string
Description
the discovered directory path
$realDirectory
:
string
Description
its canonical identity
Return values
Skips children that become inaccessible between discovery and opening.
private
openDirectory(
string
$directory) : DirectoryIterator|null
Parameters
$directory
:
string
Description
the discovered directory path
Description
for root failures or unrelated directory-opening errors
Return values
Includes discovered PHP files only when the aggregator resolves this provider.
private
provideConfigs() : Generator