Download the PHP package phlak/config without Composer
On this page you can find all versions of the php package phlak/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package config
PHP library for simple configuration management -- Created by Chris Kankiewicz (@PHLAK)
Introduction
Config is a simple PHP configuration management library supporting multiple configuration file formats and an expressive API.
Supported file formats:
- PHP
- INI
- JSON
- TOML
- YAML
- XML
Requirements
- PHP >= 7.1
Install with Composer
Initializing the Client
First, import Config:
Then instantiate the class:
Where $context
is one of the following:
- A path to a supported file type
- A directory path containing one or more supported file types
- An array of configuration options
And $prefix
is a string to be used as a key prefix for options of this Config object.
Configuration File Formats
PHP
A PHP configuration file must have the .php
file extension, be a valid PHP
file and and return a valid PHP array.
Example PHP file
INI
An INI configuration file must have the .ini
file extension and be a valid INI
file.
Example INI file
JSON
A JSON configuration file must have the .json
file extension and contain a
valid JSON object.
Example JSON file
TOML
A TOML configuration file must have the .toml
file extension and be a valid
TOML file.
Example TOML file
YAML
A YAML configuration file must have the .yaml
file extension, be a valid YAML
file.
Example YAML file
XML
A XML configuration file must have the .xml
file extension and contain valid
XML.
Example XML file
Usage
__construct
Create a new Config object.
$context
- Raw array of configuration options or path to a configuration file or directory containing one or more configuration files
$prefix
- A key under which the loaded config will be nested
Examples
Create a new Config object from a YAML file.
Create a new Config object from a directory of config files.
Create a new Config object from an array.
set
Store a config value with a specified key.
$key
- Unique configuration option key
$value
- Config item value
Example
get
Retrieve a configuration option via a provided key.
$key
- Unique configuration option key
$value
- Config item value
Examples
Define a default value to return if the option is not set.
has
Check for the existence of a configuration item.
$key
- Unique configuration option key
Example
append
Append a value onto an existing array configuration option.
$key
- Unique configuration option key
$value
- Config item value
Example
Append baz
to the tags
config item array.
prepend
Prepend a value onto an existing array configuration option.
$key
- Unique configuration option key
$value
- Config item value
Example
Prepend baz
to the tags
config item array.
unset
Unset a configuration option via a provided key.
$key
- Unique configuration option key
Example
load
Load configuration options from a file or directory.
$path
- Path to configuration file or directory
$prefix
- A key under which the loaded config will be nested
$override
- Whether or not to override existing options with values from the loaded file
Examples
Load a single additional file.
Load an additional file with a prefix.
Load an additional file without overriding existing values.
merge
Merge another Config object into this one.
$config
- Instance of Config
$override
- Whether or not to override existing options with values from the merged config object
Examples
Merge $anotherConfig into $config and override values in $config
with values
from $anotherConfig
.
Merge $anotherConfig
into $config
without overriding any values. Duplicate
values in $anotherConfig
will be lost.
split
Split a sub-array of configuration options into it's own Config object.
$key
- Unique configuration option key
Example
toArray
Return the entire configuration as an array.
Example
Troubleshooting
For general help and support join our GitHub Discussion or reach out on Twitter.
Please report bugs to the GitHub Issue Tracker.
Copyright
This project is liscensed under the MIT License.
All versions of config with dependencies
symfony/yaml Version ^5.0 || ^6.0
yosymfony/toml Version ^1.0