Class PhpFileConfig.
Description
Provides a configuration source backed by a single PHP file returning an array.
This class MUST load the configuration from the specified PHP file.
It SHALL lazily initialize and retrieve configuration data upon invocation.
If configured as persistent, mutations made via set and remove SHALL be persisted back to the file.
Interfaces
Properties
Methods
Constructs a PhpFileConfig instance.
Invokes the configuration and returns the configuration data.
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 and its associated value.
Sets configuration data.
Exports the entire configuration to an array.
Resolves relative paths against their containing directory without using include_path.
Publishes configuration atomically after revalidating the locked target.
Retrieves or initializes the configuration instance.
Recognizes the registered protocols selected by PHP's native stream lookup.
Loads the configuration from the file or default configuration.
Mutates the resolved target under an exclusive process lock.
Anchors the input location on first use and resolves its current symlink target.
private
string|null
$absoluteFile
=
null
private
ConfigInterface|null
$config
=
null
Description
holds the loaded configuration instance
private
array<string|int, mixed>|ConfigInterface|null
$defaultConfig
=
null
private
string
$file
private
bool
$persistent
=
false
Constructs a PhpFileConfig instance.
public
__construct(
string
$file[,
bool
$persistent = false][,
array<string, mixed>|ConfigInterface|null
$defaultConfig = null]) : mixed
Parameters
$file
:
string
Description
the path to the PHP configuration file
$persistent
:
bool
=
false
Description
whether changes should be saved back to the file
Description
optional default configuration when the file does not exist
Invokes the configuration and returns the configuration data.
public
__invoke() : ConfigInterface
Description
If the file exists, it MUST return a valid array. If the file does not exist but a default configuration is provided, the default configuration SHALL be used.
Return values
Description
a ConfigInterface implementation containing the configuration data
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 and its associated value.
public
remove(
string
$key) : void
Description
This method MUST update the configuration data in the file if the persistent flag is set to true.
Parameters
$key
:
string
Description
the configuration key to remove
Sets configuration data.
public
set(
array<string, mixed>|ConfigInterface|string
$key[,
mixed
$value = null]) : void
Description
This method MUST update the configuration data in the file if the persistent flag is set to true.
Parameters
Description
the configuration key or an array of key-value pairs to set
$value
:
mixed
=
null
Description
the value to set for the specified key
Exports the entire configuration to an array.
public
toArray() : array<string|int, mixed>
Return values
Description
the configuration as an associative array
Resolves relative paths against their containing directory without using include_path.
private
absolutePath(
string
$path[,
string|null
$directory = null]) : string
Parameters
$path
:
string
Description
the file or symlink target path
$directory
:
string|null
=
null
Description
the directory containing a relative symlink target
Return values
private
anchorWindowsDriveRelativePath(
string
$path) : string
Parameters
$path
:
string
Return values
private
anchorWindowsRootedPath(
string
$path,
string|null
$directory) : string
Parameters
$path
:
string
$directory
:
string|null
Return values
private
applyTemporaryMetadata(
string
$tmpFile,
array<string|int, int>|null
$existingMetadata) : void
Parameters
$tmpFile
:
string
$existingMetadata
:
array<string|int, int>|null
Publishes configuration atomically after revalidating the locked target.
private
dump(
array<string|int, mixed>
$data,
string
$targetFile) : void
Parameters
$data
:
array<string|int, mixed>
$targetFile
:
string
private
exportContent(
array<string|int, mixed>
$data) : string
Parameters
$data
:
array<string|int, mixed>
Return values
private
findSymlinkComponent(
string
$file) : array{path: string, suffix: string, linked: bool}
Parameters
$file
:
string
Return values
private
followSymlinks(
string
$file) : string
Parameters
$file
:
string
Return values
Retrieves or initializes the configuration instance.
private
getConfig() : ConfigInterface
Return values
Description
the lazily-loaded configuration object
Recognizes the registered protocols selected by PHP's native stream lookup.
private
isStreamPath(
string
$path) : bool
Parameters
$path
:
string
Return values
Loads the configuration from the file or default configuration.
private
loadConfig([
string|null
$targetFile = null]) : ConfigInterface
Parameters
$targetFile
:
string|null
=
null
Description
resolved target shared with a persistent mutation
Return values
Mutates the resolved target under an exclusive process lock.
private
mutate(
callable(ConfigInterface): void
$operation) : void
Parameters
private
mutateUnderLock(
resource
$lockFp,
string
$targetFile,
callable(ConfigInterface): void
$operation) : void
Parameters
private
prepareWritableTarget(
string
$targetFile) : string
Parameters
$targetFile
:
string
Return values
private
readExistingMetadata(
string
$targetFile) : array<string|int, int>|null
Parameters
$targetFile
:
string
Return values
Anchors the input location on first use and resolves its current symlink target.
private
resolveTargetFile() : string