2017 © Pedro Peláez
 

library phpconfigure

Simple PHP configure library that adds a key=>value relationship for configuration data callable via variables.

image

zqueal/phpconfigure

Simple PHP configure library that adds a key=>value relationship for configuration data callable via variables.

  • Sunday, January 3, 2016
  • by Xanza
  • Repository
  • 1 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

About

A simple configuration script to store values in an array, and return them using public static functions!, (*1)

Got an email recently about this repository--its all but defunct and no longer necessary. A better approach would be to use .env variables. Check out this project here--and be sure to include .env to your .gitignore., (*2)

Index

Usage

Ensure you have at least PHP version 5.4;, (*3)

Require or include the class file:, (*4)

require 'vendor/Config.php';

Create your configuration array:, (*5)

Config::init([
    'username' => 'user',
    'password' => 'password',
    'hostname' => 'localhost',
    'dbname'   => 'test',
    'database' => [
        'hostname' => 'localhost',
        'username' => 'username',
        'password' => 'test',
        'port' => 3306
    ]
]);

Then do stuff with your values:, (*6)

Config::get('username'); // contains 'user'

Or for multidimensional (init) arrays:, (*7)

Config::$instance->database{'password'}; // contains 'password'

Classes

There are 5 classes of note, they are: set, get, ret, init, and update., (*8)


Set

public static function set($key, $val) {
  self::$config[$key] = $val;
}

Enables you to set a single key value pair., (*9)

Config::set('username', 'zQueal');

Get

public static function get($key) {
    self::$config[$key];
}

Enables you to 'test' a single key pair value. Config::get() will not longer return a value. See Config::ret()., (*10)

if(Config::get('username') == $value){
    doStuff();
}

Return

public static function ret($key) {
  print self::$config[$key];
}

Returns (print) a single key pair value., (*11)

Config::ret('username'); // returns stored value

Init

public static function init($a) {
  self::$config = $a;
  self::$instance = new Config();
}

Enables you to set multiple key value pairs in a single function, and create multidimensional values., (*12)

Config::init([
    'username' => 'username',
    'password' => 'password',
    'directory' => '/home/zqueal',
    'about' => [
        'name' => 'Zach Q',
        'email' => 'zach.queal@gmail.com',
        'color' = 'blue'
    ]
]);

Once your function call has been executed, all the variables will be able to be used in the rest of your script / application. To call a single (top nested) key value pair, use the Config::get('directory'); // contains /home/zqueal static function call. If you're trying to access a nested key value pair, then you need to use the static object method Config::$instance->about{'name'} // returns 'Zach Q'., (*13)


Update

public static function update($a) {
    self::$config = array_merge(self::$config, $a);
}

A function to update already created values., (*14)

Config::set('name', 'Zach Q');
Config::ret('name'); // returns 'Zach Q'
Config::update('name', 'Other Name');
Config::ret('name'); // returns 'Other Name'

Pulls and Support

I do not maintain this repository. If you have an improvement I'm open to pull requests, but I do not offer support., (*15)

The Versions

03/01 2016

dev-master

9999999-dev https://github.com/zQueal/php-configure.git

Simple PHP configure library that adds a key=>value relationship for configuration data callable via variables.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

by Zach Queal

php configure

28/07 2015

v1.0

1.0.0.0 https://github.com/zQueal/php-configure.git

Simple PHP configure library that adds a key=>value relationship for configuration data callable via variables.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

by Zach Queal

php configure