Return to Snippet

Revision: 35375
at November 6, 2010 06:00 by sb_01


Updated Code
class Config {

	private static $instance 	= null;
	private $file_path 		= dirname(__FILE__);
	private $file_name 		= 'config';
	private $file_extention 	= 'txt';
	private $split_letter 		= ':';

	private $config;

	private function __construct() {
		$this->config = $this->parse($this->file_path . '/' . $this->file_name . '.' . $this->file_extention);
	}
	
	private function prase($file) {
		if(file_exist($file)) {
			$data = file($file);
		}
		foreach($data as $key => $value) {
			$split = explode($this->split_letter, $value);
			$config[$split[0]] = $split[1];
		}
		return $config;
	}

	public static function getInstance() {
		if (self::$instance === NULL) {
			self::$instance = new Config();
		}
		return self::$instance;
	}
	
	public function __get($var) {
		return $this->config[$var];
	}
	
	private function __clone() {}
}

// config.txt could be
// format: key:value
language:en
controller:1

Revision: 35374
at November 6, 2010 05:59 by sb_01


Initial Code
class Config {

	private static $instance 	= null;
	private $file_path 		= dirname(__FILE__);
	private $file_name 		= 'config';
	private $file_extention 	= 'txt';
	private $split_letter 		= ':';

	private $config;

	private function __construct() {
		$this->config = $this->parse($this->file_path . '/' . $this->file_name . '.' . $this->file_extention);
	}
	
	private function prase($file) {
		if(file_exist($file)) {
			$data = file($file);
		}
		foreach($data as $key => $value) {
			$split = explode($this->split_letter, $value);
			$config[$split[0]] = $split[1];
		}
		return $config;
	}

	public static function getInstance() {
		if (self::$instance === NULL) {
			self::$instance = new Config();
		}
		return self::$instance;
	}
	
	public function __get($var) {
		return $this->config[$var];
	}
	
	private function __clone() {}
}

Initial URL

                                

Initial Description

                                

Initial Title
Config Class load config.txt

Initial Tags
class, php, load

Initial Language
PHP