SF.net SVN: postfixadmin:[1212] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-10-17 21:48:04
|
Revision: 1212 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1212&view=rev Author: christian_boltz Date: 2011-10-17 21:47:58 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Move the classes "Config" and "Lang" to scripts/common.php to model/ Class Lang uses exactly the same code as Class Config - therefore I replaced its code with a simple "extends Config". Modified Paths: -------------- trunk/scripts/common.php Added Paths: ----------- trunk/model/Config.php trunk/model/Lang.php Added: trunk/model/Config.php =================================================================== --- trunk/model/Config.php (rev 0) +++ trunk/model/Config.php 2011-10-17 21:47:58 UTC (rev 1212) @@ -0,0 +1,142 @@ +<?php +# $Id$ + +class Config { +/** + * Determine if $__objects cache should be wrote + * + * @var boolean + * @access private + */ + var $__cache = false; +/** + * Holds and key => value array of objects type + * + * @var array + * @access private + */ + var $__objects = array(); + +/** + * Return a singleton instance of Configure. + * + * @return Configure instance + * @access public + */ + + function &getInstance() { + static $instance = array(); + if (!$instance) { + $instance[0] = new Config(); + //$instance[0]->__loadBootstrap($boot); + } + return $instance[0]; + } +/** + * Used to write a dynamic var in the Configure instance. + * + * Usage + * Configure::write('One.key1', 'value of the Configure::One[key1]'); + * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); + * Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]'); + * Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]')); + * + * @param array $config Name of var to write + * @param mixed $value Value to set for var + * @return void + * @access public + */ + function write($config, $value = null) { + $_this =& Config::getInstance(); + + if (!is_array($config)) { + $config = array($config => $value); + } + + foreach ($config as $names => $value) { + $name = $_this->__configVarNames($names); + + switch (count($name)) { + case 3: + $_this->{$name[0]}[$name[1]][$name[2]] = $value; + break; + case 2: + $_this->{$name[0]}[$name[1]] = $value; + break; + case 1: + $_this->{$name[0]} = $value; + break; + } + } + + } + +/** + * Used to read Configure::$var + * + * Usage + * Configure::read('Name'); will return all values for Name + * Configure::read('Name.key'); will return only the value of Configure::Name[key] + * + * @param string $var Variable to obtain + * @return string value of Configure::$var + * @access public + */ + function read($var) { + $_this =& Config::getInstance(); + + if ($var === 'all') { + $return = array(); + foreach ($_this AS $key =>$var) { + $return[$key] = $var; + } + return $return; + } + + $name = $_this->__configVarNames($var); + + switch (count($name)) { + case 3: + if (isset($_this->{$name[0]}[$name[1]][$name[2]])) { + return $_this->{$name[0]}[$name[1]][$name[2]]; + } + break; + case 2: + if (isset($_this->{$name[0]}[$name[1]])) { + return $_this->{$name[0]}[$name[1]]; + } + break; + case 1: + if (isset($_this->{$name[0]})) { + return $_this->{$name[0]}; + } + break; + } + return null; + } + + + function getAll() { + $output = $this->config; + return $output; + } +/** + * Checks $name for dot notation to create dynamic Configure::$var as an array when needed. + * + * @param mixed $name Name to split + * @return array Name separated in items through dot notation + * @access private + */ + function __configVarNames($name) { + if (is_string($name)) { + if (strpos($name, ".")) { + return explode(".", $name); + } + return array($name); + } + return $name; + } + +} + +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Property changes on: trunk/model/Config.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Added: trunk/model/Lang.php =================================================================== --- trunk/model/Lang.php (rev 0) +++ trunk/model/Lang.php 2011-10-17 21:47:58 UTC (rev 1212) @@ -0,0 +1,8 @@ +<?php +# $Id$ + +class Lang extends Config { + # exactly the same code, just another name ;-) +} + +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Property changes on: trunk/model/Lang.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: trunk/scripts/common.php =================================================================== --- trunk/scripts/common.php 2011-10-16 23:41:38 UTC (rev 1211) +++ trunk/scripts/common.php 2011-10-17 21:47:58 UTC (rev 1212) @@ -110,280 +110,4 @@ -class Config { -/** - * Determine if $__objects cache should be wrote - * - * @var boolean - * @access private - */ - var $__cache = false; -/** - * Holds and key => value array of objects type - * - * @var array - * @access private - */ - var $__objects = array(); - -/** - * Return a singleton instance of Configure. - * - * @return Configure instance - * @access public - */ - - function &getInstance() { - static $instance = array(); - if (!$instance) { - $instance[0] = new Config(); - //$instance[0]->__loadBootstrap($boot); - } - return $instance[0]; - } -/** - * Used to write a dynamic var in the Configure instance. - * - * Usage - * Configure::write('One.key1', 'value of the Configure::One[key1]'); - * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); - * Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]'); - * Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]')); - * - * @param array $config Name of var to write - * @param mixed $value Value to set for var - * @return void - * @access public - */ - function write($config, $value = null) { - $_this =& Config::getInstance(); - - if (!is_array($config)) { - $config = array($config => $value); - } - - foreach ($config as $names => $value) { - $name = $_this->__configVarNames($names); - - switch (count($name)) { - case 3: - $_this->{$name[0]}[$name[1]][$name[2]] = $value; - break; - case 2: - $_this->{$name[0]}[$name[1]] = $value; - break; - case 1: - $_this->{$name[0]} = $value; - break; - } - } - - } - -/** - * Used to read Configure::$var - * - * Usage - * Configure::read('Name'); will return all values for Name - * Configure::read('Name.key'); will return only the value of Configure::Name[key] - * - * @param string $var Variable to obtain - * @return string value of Configure::$var - * @access public - */ - function read($var) { - $_this =& Config::getInstance(); - - if ($var === 'all') { - $return = array(); - foreach ($_this AS $key =>$var) { - $return[$key] = $var; - } - return $return; - } - - $name = $_this->__configVarNames($var); - - switch (count($name)) { - case 3: - if (isset($_this->{$name[0]}[$name[1]][$name[2]])) { - return $_this->{$name[0]}[$name[1]][$name[2]]; - } - break; - case 2: - if (isset($_this->{$name[0]}[$name[1]])) { - return $_this->{$name[0]}[$name[1]]; - } - break; - case 1: - if (isset($_this->{$name[0]})) { - return $_this->{$name[0]}; - } - break; - } - return null; - } - - - function getAll() { - $output = $this->config; - return $output; - } -/** - * Checks $name for dot notation to create dynamic Configure::$var as an array when needed. - * - * @param mixed $name Name to split - * @return array Name separated in items through dot notation - * @access private - */ - function __configVarNames($name) { - if (is_string($name)) { - if (strpos($name, ".")) { - return explode(".", $name); - } - return array($name); - } - return $name; - } - -} - -class Lang { -/** - * Determine if $__objects cache should be wrote - * - * @var boolean - * @access private - */ - var $__cache = false; -/** - * Holds and key => value array of objects type - * - * @var array - * @access private - */ - var $__objects = array(); - -/** - * Return a singleton instance of Configure. - * - * @return Configure instance - * @access public - */ - - function &getInstance() { - static $instance = array(); - if (!$instance) { - $instance[0] = new Config(); - //$instance[0]->__loadBootstrap($boot); - } - return $instance[0]; - } -/** - * Used to write a dynamic var in the Configure instance. - * - * Usage - * Configure::write('One.key1', 'value of the Configure::One[key1]'); - * Configure::write(array('One.key1' => 'value of the Configure::One[key1]')); - * Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]'); - * Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]')); - * - * @param array $config Name of var to write - * @param mixed $value Value to set for var - * @return void - * @access public - */ - function write($config, $value = null) { - $_this =& Config::getInstance(); - - if (!is_array($config)) { - $config = array($config => $value); - } - - foreach ($config as $names => $value) { - $name = $_this->__configVarNames($names); - - switch (count($name)) { - case 3: - $_this->{$name[0]}[$name[1]][$name[2]] = $value; - break; - case 2: - $_this->{$name[0]}[$name[1]] = $value; - break; - case 1: - $_this->{$name[0]} = $value; - break; - } - } - - } - -/** - * Used to read Configure::$var - * - * Usage - * Configure::read('Name'); will return all values for Name - * Configure::read('Name.key'); will return only the value of Configure::Name[key] - * - * @param string $var Variable to obtain - * @return string value of Configure::$var - * @access public - */ - function read($var) { - $_this =& Config::getInstance(); - - if ($var === 'all') { - $return = array(); - foreach ($_this AS $key =>$var) { - $return[$key] = $var; - } - return $return; - } - - $name = $_this->__configVarNames($var); - - switch (count($name)) { - case 3: - if (isset($_this->{$name[0]}[$name[1]][$name[2]])) { - return $_this->{$name[0]}[$name[1]][$name[2]]; - } - break; - case 2: - if (isset($_this->{$name[0]}[$name[1]])) { - return $_this->{$name[0]}[$name[1]]; - } - break; - case 1: - if (isset($_this->{$name[0]})) { - return $_this->{$name[0]}; - } - break; - } - return null; - } - - - function getAll() { - $output = $this->config; - return $output; - } -/** - * Checks $name for dot notation to create dynamic Configure::$var as an array when needed. - * - * @param mixed $name Name to split - * @return array Name separated in items through dot notation - * @access private - */ - function __configVarNames($name) { - if (is_string($name)) { - if (strpos($name, ".")) { - return explode(".", $name); - } - return array($name); - } - return $name; - } - -} - /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |