Lawondyss PHP Config Class: Base class for creating configuration objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-07-16 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 37 This week: 1All time: 9,958 This week: 267Up
Version License PHP version Categories
lawondyss-config 1.0.0MIT/X Consortium ...7.1Configuration, PHP 7
Description Author

This package provides a base class for creating configuration objects.

It provides a base class that can make its object work either like arrays that contain a list of named configuration options or objects on which the variables have option values.

Applications should extend this class to define options specific to their purposes.

Picture of Ladislav Vondracek
Name: Ladislav Vondracek <contact>
Classes: 6 packages by
Country: Czech Republic Czech Republic
Age: 39
All time rank: 150614 in Czech Republic Czech Republic
Week rank: 237 Up4 in Czech Republic Czech Republic Up

Details

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

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageConfig (2 files)

  Files folder image Files  /  src  /  Config  
File Role Description
  Plain text file Config.php Class Class source
  Plain text file exceptions.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file Config.phpt Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:37
This week:1
All time:9,958
This week:267Up

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