Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Lawondyss/Config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

Config

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

About

Better way to work with configuration.

Topics

Resources

License

Stars

Watchers

Forks

Languages

AltStyle によって変換されたページ (->オリジナル) /