Download the PHP package raphhh/puppy-config without Composer
On this page you can find all versions of the php package raphhh/puppy-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raphhh/puppy-config
More information about raphhh/puppy-config
Files in raphhh/puppy-config
Package puppy-config
Short Description Config manager
License MIT
Homepage https://github.com/Raphhh/puppy-config
Informations about the package puppy-config
Puppy Config
Puppy Config is a config manager that loads your config from files according to your env.
Config basic logic:
- env config management (dev, test, prod, ...)
- multi file formats support (php, ini, json, yaml)
- dynamic config values
- visibility restriction
Installation
Run composer:
Read your config
Add the main config file
Launch the Config class:
Dynamic values
You can retrieve dynamically a previous defined value with it key.
Set new values
You can set new values on the fly, which will be available in the Config object during all the script (and not saved into a file config).
You can also use the dynamic mapping.
Visibility restriction
You can determine some namespaces in your config, and restrict the visibility of each namespace.
For example, imagine you set this config, with two namespaces: 'a' and 'b'.
With the global scope config you can access to all the values.
Now, restrict the config to the namespace 'a':
With this restricted scope config, you can only have access to the namespace 'a' values:
The original keys are not visible anymore:
But, the global scope config is still bound to your restricted scope. So, if you modify one, you modify the other.
Files format
By default, Config load 'php' files. This kind of file must return a PHP array.
But you can specify or add specific file formats.
Available formats:
- php (default)
- ini
- json
- yaml
Multi environment
Your config is the merge of the values coming from three kind of files:
type | file name | loading | overloading | usage |
---|---|---|---|---|
global config | global.php | always loaded | prod & test | |
env config | e.i. dev.php | according to the env | override global config | dev |
local config | local.php | specific for each machine | override global and env config | prod & test - dev |
When is loaded the global config?
In all the cases, Config will load the file 'global.php'. (You can easily change this default file.)
By default, this is your prod config.
When is loaded the env config?
If you specify an env in the constructor, it will load also the associated file.
For example:
The env config will override the global config. So, use it for your dev env, which will override your prod params.
How env can change dynamically?
Set an environment variable in your server virtual host configuration, and retrieve it with the php getenv() method.
In your httpd.conf or a .htaccess file of your dev Apache server, put:
In your PHP file, retrieve the env:
What is the local config?
The config will load also a local config, if the file config/local.php exists.
This config will override the global and the env configs. Be careful: this file must be NOT versioned.
So, it is an individual config, where your can put temporary or specific config. Your can also put config you do not want to version, like the passwords.