From dc8ea753fc0cec7bc655b3f09c6e6293c9622b4e Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Wed, 5 Jun 2013 23:09:10 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1471 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/Config.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/model/Config.php b/model/Config.php index 07433c92..6607f85c 100644 --- a/model/Config.php +++ b/model/Config.php @@ -115,8 +115,28 @@ class Config { 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 @@ class Config { * @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;