Thread: SF.net SVN: postfixadmin:[1236] trunk/model/Config.php
Brought to you by:
christian_boltz,
gingerdog
|
From: <Gin...@us...> - 2011-10-24 22:24:28
|
Revision: 1236
http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1236&view=rev
Author: GingerDog
Date: 2011-10-24 22:24:21 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
make Config.php a php5 compatible object; remove strict standards warnings
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2011-10-24 22:17:43 UTC (rev 1235)
+++ trunk/model/Config.php 2011-10-24 22:24:21 UTC (rev 1236)
@@ -2,140 +2,140 @@
# $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();
+ /**
+ * Determine if $__objects cache should be wrote
+ *
+ * @var boolean
+ * @access private
+ */
+ private $__cache = false;
+ /**
+ * Holds and key => value array of objects type
+ *
+ * @var array
+ * @access private
+ */
+ private $__objects = array();
-/**
- * Return a singleton instance of Configure.
- *
- * @return Configure instance
- * @access public
- */
+ private static $instance = null;
+ /**
+ * 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];
+ public static function getInstance() {
+ if(self::$instance == null) {
+ self::$instance = new self();
}
-/**
- * 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();
+ return self::$instance;
+ }
- if (!is_array($config)) {
- $config = array($config => $value);
- }
+ /**
+ * 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
+ */
+ public static function write($config, $value = null) {
+ $_this = self::getInstance();
- foreach ($config as $names => $value) {
- $name = $_this->__configVarNames($names);
+ if (!is_array($config)) {
+ $config = array($config => $value);
+ }
- 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;
- }
- }
+ 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);
+ /**
+ * 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
+ */
+ public static function read($var) {
+ $_this = self::getInstance();
- 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;
+ if ($var === 'all') {
+ $return = array();
+ foreach ($_this AS $key =>$var) {
+ $return[$key] = $var;
+ }
+ return $return;
}
-
- function getAll() {
- $output = $this->config;
- return $output;
+ $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;
}
-/**
- * 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;
+ 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
+ */
+ private function __configVarNames($name) {
+ if (is_string($name)) {
+ if (strpos($name, ".")) {
+ return explode(".", $name);
+ }
+ return array($name);
}
+ return $name;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2013-06-05 23:09:13
|
Revision: 1471
http://sourceforge.net/p/postfixadmin/code/1471
Author: christian_boltz
Date: 2013-06-05 23:09:10 +0000 (Wed, 05 Jun 2013)
Log Message:
-----------
Config.php:
- add read_f() - similar to read(), but accepts a second parameter which
is then included in the text using sprintf
- bool(): change parameter name
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2013-06-05 23:03:03 UTC (rev 1470)
+++ trunk/model/Config.php 2013-06-05 23:09:10 UTC (rev 1471)
@@ -115,8 +115,28 @@
return null;
}
+ /**
+ * read Config::$var and apply sprintf on it
+ * also checks if $var is changed by sprintf - if not, it writes a warning to error_log
+ *
+ * @param string $var Variable to obtain
+ * @param string $value Value to use as sprintf parameter
+ * @return string value of Config::$var, parsed by sprintf
+ * @access public
+ */
+ public static function read_f($var, $value) {
+ $text = self::read($var);
+
+ $newtext = sprintf($text, $value);
+
+ # check if sprintf changed something - if not, there are chances that $text didn't contain a %s
+ if ($text == $newtext) error_log("$var used via read_f, but nothing replaced (value $value)");
+
+ return $newtext;
+ }
+
/**
- * Used to read Configure::$var, converted to boolean
+ * Used to read Config::$var, converted to boolean
* (obviously only useful for settings that can be YES or NO)
*
* Usage
@@ -127,8 +147,8 @@
* @access public
*/
- public static function bool($setting) {
- $value = Config::read($setting);
+ public static function bool($var) {
+ $value = self::read($var);
if (strtoupper($value) == 'YES') { # YES
return true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2013-10-31 21:02:06
|
Revision: 1549
http://sourceforge.net/p/postfixadmin/code/1549
Author: christian_boltz
Date: 2013-10-31 21:02:04 +0000 (Thu, 31 Oct 2013)
Log Message:
-----------
model/Config.php:
- Config::read(): error_log() attemps to read undefined config options
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2013-10-31 20:52:45 UTC (rev 1548)
+++ trunk/model/Config.php 2013-10-31 21:02:04 UTC (rev 1549)
@@ -101,6 +101,8 @@
}
break;
}
+
+ error_log('Config::read(): attemp to read undefined config option "' . join('.', $name) . '", returning null');
return null;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2013-11-10 16:00:23
|
Revision: 1559
http://sourceforge.net/p/postfixadmin/code/1559
Author: christian_boltz
Date: 2013-11-10 16:00:20 +0000 (Sun, 10 Nov 2013)
Log Message:
-----------
model/Config:
- read_f(): fix error logging - $var can be an array
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2013-11-10 15:57:32 UTC (rev 1558)
+++ trunk/model/Config.php 2013-11-10 16:00:20 UTC (rev 1559)
@@ -121,7 +121,10 @@
$newtext = sprintf($text, $value);
# check if sprintf changed something - if not, there are chances that $text didn't contain a %s
- if ($text == $newtext) error_log("$var used via read_f, but nothing replaced (value $value)");
+ if ($text == $newtext) {
+ if (is_array($var)) $var = join('.', $var);
+ error_log("$var used via read_f, but nothing replaced (value $value)");
+ }
return $newtext;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gin...@us...> - 2014-02-19 11:47:19
|
Revision: 1642
http://sourceforge.net/p/postfixadmin/code/1642
Author: gingerdog
Date: 2014-02-19 11:47:17 +0000 (Wed, 19 Feb 2014)
Log Message:
-----------
typo fix
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2014-02-18 13:23:55 UTC (rev 1641)
+++ trunk/model/Config.php 2014-02-19 11:47:17 UTC (rev 1642)
@@ -102,7 +102,7 @@
break;
}
- error_log('Config::read(): attemp to read undefined config option "' . join('.', $name) . '", returning null');
+ error_log('Config::read(): attempt to read undefined config option "' . join('.', $name) . '", returning null');
return null;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2014-03-18 21:57:49
|
Revision: 1659
http://sourceforge.net/p/postfixadmin/code/1659
Author: christian_boltz
Date: 2014-03-18 21:57:47 +0000 (Tue, 18 Mar 2014)
Log Message:
-----------
Config.php:
- do not error_log() 'undefined config option' for deprecated options
Modified Paths:
--------------
trunk/model/Config.php
Modified: trunk/model/Config.php
===================================================================
--- trunk/model/Config.php 2014-03-16 21:52:26 UTC (rev 1658)
+++ trunk/model/Config.php 2014-03-18 21:57:47 UTC (rev 1659)
@@ -7,6 +7,11 @@
private static $instance = null;
+ # do not error_log() 'undefined config option' for deprecated options
+ private static $deprecated_options = array(
+ 'min_password_length',
+ );
+
/**
* Return a singleton instance of Configure.
*
@@ -102,7 +107,10 @@
break;
}
- error_log('Config::read(): attempt to read undefined config option "' . join('.', $name) . '", returning null');
+ if ( !in_array(join('.', $name), self::$deprecated_options) ) {
+ error_log('Config::read(): attempt to read undefined config option "' . join('.', $name) . '", returning null');
+ }
+
return null;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|