Download the PHP package phossa/phossa-config without Composer
On this page you can find all versions of the php package phossa/phossa-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phossa/phossa-config
More information about phossa/phossa-config
Files in phossa/phossa-config
Package phossa-config
Short Description Configuration management libraray for PHP
License MIT
Homepage https://github.com/phossa/phossa-config
Informations about the package phossa-config
phossa-config [ABANDONED]
See new lib at phoole/config
Introduction
phossa-config is a configuration management library for PHP. The design idea
is inspired by another github project mrjgreen/config
but with lots of cool
features.
It requires PHP 5.4 and supports PHP 7.0+, HHVM. It is compliant with PSR-1, PSR-2, PSR-4.
Features
-
One central place for all config files
-
Use an environment value, e.g.
production
orproduction/host1
for switching betweendevelopment
,staging
orproduction
. -
Support
.php
,.json
,.ini
and.xml
type of configuration files. -
Reference is possible, such as
${system.tmpdir}
in configuration file and environment file. -
On demand configuration loading (lazy loading).
-
Able to load all configuration files in one shot with
$config->get(null)
-
Configuration cache.
-
Hierachy configuration structure with dot notation like
db.auth.host
. -
Both flat notation and array notation fully supported and co-exist at the same time.
- Un*x shell style environment file '.env' is supported with dereferencing
feature and magic environment values like
${__DIR__}
and${__FILE__}
Installation
Install via the composer
utility.
or add the following lines to your composer.json
Usage
-
Usually running environment is different for different servers. A good practice is setting environment in a
.env
file in the installation root and put all configuration files in theconfig/
directory.Sample
.env
file,In the
bootstrap.php
file, -
Configurations are grouped into groups, namely files. For example, the
system.php
holds allsystem.*
configurationsLater, system related configs can be retrieved as
Or being used in other configs as reference.
-
A cache pool can be passed to the config constructor to have it read all configs from the cache or save all configs to cache.
-
Pros of using caching
-
Speed up. Read from one file instead of lots of configuration files.
-
References like
${system.tmpdir}
are done already. -
Cons of using caching
-
Config data might be stale. need to using
$config->save()
to overwrite or$cache->clear()
to clear the cache. -
Need write permission to a cache directory.
- Might expose your configuration if you are not careful with cache data.
-
-
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 chars,
Or even disable the reference feature,
-
If the environment is set to
production/host1
, the precedence order is,-
config/production/host1/db.php
over -
config/production/db.php
over config/config/db.php
-
-
get($key, $default = null)
$key
is the a flat notation likedb.auth.host
orNULL
to get all of the configurations.$default
is used if no configs found.Return value might be a
string
orarray
base on the$key
.set($key, $value)
Set the configuration manually in this session. The value will NOT be reflected in any config files unless you modify config file manually.
$value
can be astring
orarray
.has($key)
Test if
$key
exists or not. Returns aboolean
value.save()
Save current full configurations into a cache.
Changes
- 1.0.6 added
setReferencePattern()
,hasReference()
anddeReference()
Dependencies
-
PHP >= 5.4.0
- phossa/phossa-shared ~1.0.10