hsntngr / config-loader
Load configuration files with ease
v1.2
2020-06-20 23:28 UTC
Requires
- symfony/yaml: ^3.4
This package is auto-updated.
Last update: 2024-05-21 20:19:12 UTC
README
Basic Usage
database.php
return [ 'user' => 'hsntngr', 'password' => 'secret' ... ];
echo config("database.user"); // hsntngr
Insallation
composer require hsntngr/config-loader
Create a Config File
yaml example
driver: mysql host: 127.0.0.1 dbname: example port: 3306 user: name: hsntngr password: secret
php example
return [ "driver" => "mysql", "host" => "127.0.0.1", "dbname" => "example", "port" => "3306", "user" => [ "name" => "example", "password" => "secret", ] ];
Register Config Loader
use Hsntngr\Config\Config; use Hsntngr\Config\ArrayLoader; $path = "/path/to/config/directory/"; $config = Config::create(new ArrayLoader($path)); // use YamlLoader for yaml files $config->load(); // loading single file $path = "/path/to/config.php"; $config->loadFromFile($path);
Basic Usage
get a config value with helper method
config('auth.session.provider'); // database
get a config value with Config class
$config = Config::getInstance(); $config->get('auth.session.provider');
store a config value at runtime
config("auth.api.token", "sample-token") print_r(config("auth.api")) // [ // "driver" => "driver", // "endpoint" => "v1/users", // "token" => "sample-token" // ]