Download the PHP package phossa2/config without Composer
On this page you can find all versions of the php package phossa2/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phossa2/config
More information about phossa2/config
Files in phossa2/config
Package config
Short Description A simple, easy to use, yet powerful configuration management library for PHP.
License MIT
Homepage https://github.com/phossa2/config
Informations about the package config
phossa2/config [ABANDONED]
PLEASE USE phoole/config library instead
phossa2/config is a simple, easy to use, yet powerful configuration management library for PHP. The design idea was inspired by another github project mrjgreen/config but some cool features added.
It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with PSR-1, PSR-2, PSR-4.
Installation
Install via the composer utility.
or add the following lines to your composer.json
Features
-
Simple interface,
get($id, $default = null)andhas($id). -
One central place for all config files for ease of management.
-
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}. -
On demand configuration loading (lazy loading).
-
Hierachy configuration structure with dot notation like
db.auth.host. -
Array access for ease of use. e.g.
$config['db.user'] = 'www';. -
Reference lookup delegation and config chaining.
- Support
.php,.json,.ini,.xmland.serializedtype 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,-
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,
-
Configclass implementsArrayAccessinterface. So config values can be accessed just like an array.Hierachy 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.
-
Reference lookup delegation and config chaining
- Config delegation
Reference lookup delegation is similar to the delegation idea of Interop Container Delegate Lookup
-
Calls to the
get()method should only return an entry if the entry is part of the config registry. If the entry is not part of the registry, aNULLwill be returned as described inConfigInterface. -
Calls to the
has()method should only return true if the entry is part of the config registry. If the entry is not part of the registry, false should be returned. -
If the fetched entry has dependencies (references), instead of performing the reference lookup in this config registry, the lookup is performed on the delegator.
- Important By default, the lookup SHOULD be performed on the delegator only, not on the config registry itself.
Delegatorclass implements theConfigInterfaceandArrayAccessinterfaces, thus can be used just like a normal config.- Config chaining
Config chaining can be achieved via multiple-level delegations. For example,
APIs
-
get(string $id, $default = null): mixed
$defaultis used if no config value is found.The return value might be a
string,arrayor evenobject.has(string $id): bool
Test if
$idexists or not. Returns abooleanvalue. -
set(string $id, mixed $value): bool
Set the configuration manually in this session. The value will NOT be reflected in any config files unless you modify config file manually.
$valuemay be astring,arrayorobject.This feature can be disabled by
setWritable(bool $writable): bool
Enable or disable the
set()functionality. Returnstrueon success.isWritable(): bool
Test to see if current config writable or not.
-
setReferencePattern(string $start, string $end): $this
Reset the reference start chars and ending chars. The default are
'${'and'}'hasReference(string $string): bool
Test to see if there are references in the
$stringdeReference(string $string): mixed
Dereference all the references in the
$string. The result might bestring,arrayor evenobject.deReferenceArray(mixed &$data): $this
Recursively dereference everything in the
$data.$datamight bestringorarray. Other data type will be ignored and untouched. -
addConfig(ConfigInterface $config): $this
Added one
Phossa2\Config\Interfaces\ConfigInterfaceinstance to the delegator. -
setErrorType(int $type): $this
Set either
Config::ERROR_IGNORE,Config::ERROR_WARNINGorConfig::ERROR_EXCEPTIONfor the config.
Change log
Please see CHANGELOG from more information.
Testing
Contributing
Please see CONTRIBUTE for more information.
Dependencies
-
PHP >= 5.4.0
- phossa2/shared >= 2.0.21
