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

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