Created
June 18, 2012 17:50
-
-
Save miguelramos/2949672 to your computer and use it in GitHub Desktop.
PHP: Class Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 <[email protected]> | |
* @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