Multi databases support, #12
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@113 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
67
Config.php
Normal file
67
Config.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Model
|
||||
* @since 2010-02-17
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class Config extends ArrayObject
|
||||
{
|
||||
|
||||
private static $_instance = null;
|
||||
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
static public function getInstance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new Config();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
static public function get($name)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
if (! $instance->offsetExists($name)) {
|
||||
throw new Exception('Configuration variable "' . $name . '" undefined');
|
||||
}
|
||||
return $instance->offsetGet($name);
|
||||
}
|
||||
|
||||
static public function set($name, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$value = new ConfigArray($value);
|
||||
}
|
||||
self::getInstance()->offsetSet($name, $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ConfigArray extends ArrayObject
|
||||
{
|
||||
public function __construct($array)
|
||||
{
|
||||
parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
|
||||
}
|
||||
|
||||
public function offsetGet($index)
|
||||
{
|
||||
if (! $this->offsetExists($index)) {
|
||||
throw new Exception('Configuration variable "' . $index . '" undefined');
|
||||
}
|
||||
return parent::offsetGet($index);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user