Download the PHP package phoole/config without Composer
On this page you can find all versions of the php package phoole/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phoole/config
More information about phoole/config
Files in phoole/config
Informations about the package config
config
A slim configuration loader library for PHP. It loads PHP, JSON, YAML config files, easy to use, yet powerful. It requires PHP 7.2+ and is compliant with PSR-1, PSR-4, PSR-12.
Installation
Install via the composer utility.
or add the following lines to your composer.json
Features
-
Simple interface,
get($id),has($id),with($id, $value). -
One central place for all config files for ease of management.
-
May use an environment value, such as
productionorproduction/host1for switching between different configurations. -
Use of references in configuration value is fully supported, such as
${system.tmpdir}. -
Get environment values using
$config->get('ENV.USER')or${ENV.USER} -
Hierarchy configuration structure with dot notation like
db.auth.host. - Support
.php,.json,.yml(need yaml extension installed) type of config files.
Usage
-
Usually application running environment is different on different servers. A good practice is setting environment in a
.envfile somewhere on the host, and put all configuration files in one centralconfig/directory.A sample
.envfile,In a sample
bootstrap.phpfile, -
Central config directory and configuration grouping
- Configuration grouping
Configurations are gathered into one directory and are grouped into files and subdirectories for ease of management.
For example, the
config/system.phpholdssystem.*configurationsLater,
systemrelated configs can be retrieved asOr being used in other configs as references.
- Configuration files loading order
If the environment is set to
production/host1, the config files loading order are (assume config files are*.php),-
config/config/*.php -
config/production/*.php config/production/host1/*.php
Configuration values are overwritten and replaced those from later loaded files.
-
References make your configuration easy to manage.
For example, in the
system.phpIn your
cache.phpfile,You may reset the reference start and ending matching pattern as follows,
-
Environment values can be accessed through special node
'ENV'. e.g.or in reference format,
-
Hierarchy configuration structure with dot notation like
db.auth.host.Both flat notation and array notation are supported and can co-exist at the same time.
-
After initial loading,
$configis immutable. If you want to add new conf values. You may use,where
$newconfis a new configuration object.
APIs
-
get(string $id): mixed
The return value might be a
string,array, or evenobject. Returnsnullif not found.has(string $id): bool
Test if
$idexists or not. Returns abooleanvalue.with(string $id, mixed $value): Config
Returns a new config object with
$idset. -
setReferencePattern(string $start, string $end): $this
Reset the reference start chars and ending chars. The default are
'${'and'}'
Testing
Dependencies
- PHP >= 7.2.0
