Files
majestic/Config.php

54 lines
1.5 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php namespace Majestic;
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Model
* @since 2010-02-17
*/
class Config extends Registry
{
private static $_class_name = 'Config';
/**
* Метод устанавливает параметры конфигурации
* @param mixed $param
* Имя параметра или параметры в массиве
* @param mixed $value
* Значение параметра. Не требуется, если передаются параметры в массиве
*/
static public function set($param, $value = null)
{
// Разбираю массив, если параметры переданы в массиве
if (is_array($param)) {
foreach ($param as $paramItem => $value) {
self::set($paramItem, $value);
}
return;
}
if (is_array($value)) {
$value = new ConfigArray($value);
}
self::getInstance()->offsetSet($param, $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\GeneralException('Configuration variable "' . $index . '" undefined');
}
return parent::offsetGet($index);
}
}