File: README.md

Recommend this page to a friend!
  Classes of Ladislav Vondracek  >  Lawondyss PHP Config Class  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Lawondyss PHP Config Class
Base class for creating configuration objects
Author: By
Last change:
Date: 2 months ago
Size: 1,378 bytes
 

Contents

Class file image Download

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 $driver;
  public $host;
  public $database;
  public $username;
  public $password;
  public $charset;
}

$dbConfig = DbConfig::fromArray([
  'driver' => 'mysqli',
  'host' => 'localhost',
  'database' => 'example',
  'username' => 'root',
  'password' => 'root',
  'charset' => 'utf8'
]);

Simple call 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 $driver = 'mysqli';
  public $host = 'localhost';
  public $database;
  public $username;
  public $password;
  public $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


For more information send a message to info at phpclasses dot org.