From 920a6a2b92278a4496afb3f56636955b1ef77352 Mon Sep 17 00:00:00 2001 From: zorloc Date: Tue, 28 Jan 2003 18:53:25 +0000 Subject: [PATCH] Added some more Validator subclasses to handle arrays of for which the validation criteria should be the same for all members. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2533 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- config/Tools.php | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/config/Tools.php b/config/Tools.php index 0de8a30a1..4901c9296 100644 --- a/config/Tools.php +++ b/config/Tools.php @@ -1,5 +1,5 @@ name = $params['name']; + $this->section = $params['section']; $this->defaultValue = $params['defaultValue']; $this->description = $params['description']; $this->validator = &$params['validator']; @@ -578,8 +579,106 @@ class ValidatorConstantList extends Validator { } } +/** +* Validator subclass for an array. +* @author Joby Walker +*/ +class ValidatorArray extends Validator { + + /* + * Checks to ensure that the parameter is an array then passes the + * array on to validMembers() to ensure that each member of the + * array is valid. + * @param array $array Value to check. + * @return boolean True if the value is and array and members are valid, false else. + */ + function validate($array){ + if(is_array($array)){ + return $this->validMembers($array); + } + return false + } + + /** + * Checks to ensure that the members of the array are valid. Always true here. + * @param array $array Array of members to check + * @return boolean Always true since there are no restrictions on the members. + */ + function validMembers($array){ + return true; + } +} + +/** +* Validator subclass for an array of strings. +* @author Joby Walker +*/ +class ValidatorArrayString extends Validator { + + /** + * Checks to ensure that the members of the array are valid strings. + * @param array $array Array of members to check + * @return boolean True if the members are valid strings, false else. + */ + function validMembers($array){ + foreach ($array as $member){ + if (!is_string($member)) { + return false; + } + } + return true; + } +} + +/** +* Validator subclass for an array of strings that must be in a list of +* defined values. +* @author Joby Walker +*/ +class ValidatorArrayStringList extends Validator { + + /** + * Array of potential valid values + * @var array + * @access protected + */ + var stringList; + + /** + * Constructor + * + * Saves parameter as the instance variable $stringList. + * @param array List of valid values. + */ + function ValidatorArrayStringList($stringList){ + $this->stringList = $stringList; + return; + } + + /** + * Checks to ensure that the members of the array are valid strings and + * within the defined list. + * @param array $array Array of members to check + * @return boolean True if the members are valid strings are in the defined list, + * false else. + */ + function validMembers($array){ + foreach ($array as $member){ + if(!in_array($member, $stringList, true)){ + return false; + } + } + return true; + } + +} + + //$Log: not supported by cvs2svn $ +//Revision 1.2 2003/01/28 06:31:00 zorloc +//Mostly done but ConfigArray will probably need some more helper methods. +// //Revision 1.1 2003/01/23 00:32:04 zorloc //Initial work for classes to hold configuration constants/variables. Base //ConfigValue class and subclasses for constants and variables. -- 2.45.2