lawondyss / config
Base class for creating own class of configuration. Better than a associative array :-)
Installs: 2 307
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- nette/tester: ^2.5
- slevomat/coding-standard: ^8.14
- squizlabs/php_codesniffer: ^3.7
- tracy/tracy: ^2.10
This package is auto-updated.
Last update: 2024-12-12 13:51:11 UTC
README
Base class for creating own class of configuration. Better than a associative array :-)
Install
Over Composer
composer require lawondyss/config
Usage
class DbConfig extend Lawondyss\Config { public string $driver; public string $host; public string $database; public string $username; public string $password; public string $charset; } $dbConfig = DbConfig::fromArray([ 'driver' => 'mysqli', 'host' => 'localhost', 'database' => 'example', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8' ]);
Simple get and set individual option.
$charset = $dbConfig->charset; $dbConfig->charset = 'latin1';
Is implemented array access.
$pass = $dbConfig['password']; $dbConfig['password'] = '*****';
If you want default values, then defined in class.
class DbConfig extend Lawondyss\Config { public string $driver = 'mysqli'; public string $host = 'localhost'; public string $database; public string $username; public string $password; public string $charset = 'utf8'; } $defaultConfig = new DbConfig;
Is possible "merge" with a customized options.
$lipsumDbConfig = $defaultConfig->withOptions([ 'database' => 'lipsum', 'username' => 'lorem', 'password' => 'ipsum', ]);
If another code use options as associative array:
$dibi = new Dibi\Connection($lipsumDbConfig->toArray());
License
MIT