Created
October 4, 2009 16:16
-
-
Save codejoust/201455 to your computer and use it in GitHub Desktop.
PHP5 Config Class.
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 | |
class Config{ | |
private static $_data; | |
private static $_instance; | |
public function __construct() { } | |
public static function getInstance(){ | |
if (!self::$_instance){ | |
self::$_instance = new Config(); | |
} | |
return self::$_instance; | |
} | |
public static function __set($name,$value){ | |
self::$_data[$name] = $value; | |
} | |
public static function __get($name){ | |
return self::$_data[$name]; | |
} | |
public static function set($k, $v) | |
{ | |
return self::$_data[$k] = $v; | |
} | |
public static function get($k) | |
{ | |
return self::$_data[$k]; | |
} | |
} | |
/*-- Usage: | |
$cfg = new Config(); | |
$cfg->test = 'sweet'; | |
$cfg->test; (returns sweet) | |
If the class can't be accessed as a global: | |
Config::get('test') (returns sweet) | |
You also can create more than one instance, however, that data is carried over. | |
$config = new Config(); | |
$config->test (returns sweet) | |
--*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment