Skip to content

Instantly share code, notes, and snippets.

@miguelramos
Created June 18, 2012 17:50
Show Gist options
  • Save miguelramos/2949672 to your computer and use it in GitHub Desktop.
Save miguelramos/2949672 to your computer and use it in GitHub Desktop.
PHP: Class Config
<?php namespace Fig;
/**
*-------------------------------------------------------------------------------
* Config Class
*-------------------------------------------------------------------------------
* This is a simple class for config itens. The propose is to demonstrate the
* explicity of name methods and the use of conditionals.
*
* @package Fig
* @author Miguel Ramos <miguel.marques.ramos@gmail.com>
* @link https://groups.google.com/d/forum/php-standards
*/
class Config {
/**
* Stack of items with options.
* @var array
*/
private static $_items = array();
/**
* Method to set a config item.
*
* @param string $name Name of item
* @param mixed $value Value of item
*/
public static function setItem($name, $value){
self::$_items[$name] = $value;
}
/**
* Method to get an option item.
*
* @param string $name Name of item
* @return mixed Value of item
*/
public static function getItem($name){
return self::has($name) ? $self::$_items[$name] : null;
}
/**
* Conditional method to confirm the existence of an item.
*
* @param string $item Name of item
* @return boolean If exists or not
*/
public static function has($item){
return array_key_exists($item, self::$_items);
}
/**
* Conditional method to check if stack is empty.
*
* @return boolean
*/
public static function isEmpty(){
return empty(self::$_items);
}
/**
* Reset a item from stack.
*
* @param string $name Name of option
* @return void
*/
public static function reset($name){
self::has($name) ? unset(self::$_items[$name] : '';
}
/**
* Reset stack;
*
* @return void
*/
public static function clean(){
self::$_items = array();
}
/**
* Is this explicity?
*
* @param string $name
* @return mixed
*/
public static function fetchItem($name){
}
/**
* Same thing conditional no so explicity?
*
* @param string $name
* @return boolean
*/
public static function checkConfig($name){
}
}
/* @end config.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment