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
production
orproduction/host1
for 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
.env
file somewhere on the host, and put all configuration files in one centralconfig/
directory.A sample
.env
file,In a sample
bootstrap.php
file, -
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.php
holdssystem.*
configurationsLater,
system
related 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.php
In your
cache.php
file,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,
$config
is immutable. If you want to add new conf values. You may use,where
$newconf
is a new configuration object.
APIs
-
get(string $id): mixed
The return value might be a
string
,array
, or evenobject
. Returnsnull
if not found.has(string $id): bool
Test if
$id
exists or not. Returns aboolean
value.with(string $id, mixed $value): Config
Returns a new config object with
$id
set. -
setReferencePattern(string $start, string $end): $this
Reset the reference start chars and ending chars. The default are
'${'
and'}'
Testing
Dependencies
- PHP >= 7.2.0