Download the PHP package sugiphp/config without Composer
On this page you can find all versions of the php package sugiphp/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package config
Config
Installation
SugiPHP\Config is designed to simplify access to configuration settings. Config class natively supports reading and parsing configuration options from several file types (php, json, yaml, ini, xml) stored in one or several locations in your project. Config::get("file.key") method automatically finds configuration file, loads it, parses it and then searches for the key and returns it's value. If the file or the key is not found gracefully returns NULL or some other default value if it is provided like a second parameter.
Usage
You can use different file types to store settings:
-
PHP (with filename app.php)
-
JSON (app.json)
-
YAML (app.yml)
-
INI (app.ini)
- XML (app.xml)
To access the host option no matter wich type of configurations file you use:
FileLocator
FileLocator is used to search for a (configuration) file in one or more directories.
Loader
A loader binds a key with a corresponding value which can be found somewhere (in a file, in a database, etc.) and can be in any form (a php array, json string, xml, etc.). A simple example that explains a loader: Lets assume your application resides in a "/path/to/app", and your configuration files are in "/path/to/app/config" path. Your application needs a database connection. The host, database, user and password are described in a PHP file living in configuration directory. You can use a loader which will include a file (a $key = "database" with ".php" extension) in that folder and return the contents, like the PHP code will do:
A slightly more complicated example is when a database is described in an json format. So the loader will do something like:
Another example is if some of your app configurations are stored not in files but lets say in a NoSQL storage. So you can write your custom loader which will connect to the NoSQL DB, fetch items and return them as array. And that's really easy, and the better thing is that your existing code will not need any modification.
You can peek in Database Loader for a simple database configuration store example.