, (*1)
PHP simple config
This is a simple config handler class with dot-syntax for PHP., (*2)
Dependencies
Installation
Install with Composer:, (*3)
composer require dtkahl/php-simple-config
Usage
Refer namespace:, (*4)
use Dtkahl\SimpleConfig\Config;
Create new Config instance:, (*5)
$config = new Config([
"database" => [
"host" => "localhost",
"port" => 1337,
"username" => "developer",> 1337,
38
"usernam
"password" => "secret",
],
"debug" => true,
// ...
);
you can also load Config from file:, (*6)
$config = new Config(require("./config.php"));
Example config.php
:, (*7)
<?php
return [
"database" => [
"host" => "localhost",
"port" => 1337,
"username" => "developer",
"password" => "secret",
],
"debug" => true,
// ...
]
Methods
has($path)
Determine if config entry exists on given path., (*8)
get($path, $default = null)
Returns config entry exists on given path or returns $default
if path does not exist in config., (*9)
set($path, $value, $force = false)
Set config entry on given path (override if existing). Set parameter $force
if given path dosn't exist.
Returns config instance., (*10)
remove($path)
Remove config entry on given path if existing. Returns config instance., (*11)
setAlias($alias, $path)
Add an alias for a given path. Alias should not contain a dot for obvious reason., (*12)