PHP Classes

Lawondyss PHP Config Class: Base class for creating configuration objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-11-13 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 56 All time: 10,477 This week: 108Up
Version License PHP version Categories
lawondyss-config 1.0.1MIT/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

Documentation

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


  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
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 phpcs.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  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 UndefinedOption.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 ConfigTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:56
This week:0
All time:10,477
This week:108Up