cvs: pear /Validate Validate.php
| From: | Pierre-Alain Joye | Date: | Wed, 29 May 2002 14:47:09 +0000 |
| Subject: | cvs: pear /Validate Validate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4269@lists.php.net to get a copy of this message | ||
pajoye Wed May 29 10:47:09 2002 EDT
Modified files:
/pear/Validate Validate.php
Log:
Implement ::multiple methods
Index: pear/Validate/Validate.php
diff -u pear/Validate/Validate.php:1.8 pear/Validate/Validate.php:1.9
--- pear/Validate/Validate.php:1.8 Wed May 29 07:05:48 2002
+++ pear/Validate/Validate.php Wed May 29 10:47:06 2002
@@ -17,11 +17,18 @@
class Validate
{
+
+ function Validate() {
+ }
+
/**
* @param mixed $decimal The decimal char or false when decimal not allowed
*/
function number($number, $decimal = null, $dec_prec = null, $min = null, $max = null)
{
+ if ( is_array( $number ) )
+ extract($number);
+
$dec_prec = $dec_prec ? "{1,$dec_prec}" : '+';
$dec_regex = $decimal ? "[$decimal][0-9]$dec_prec" : '';
if (!preg_match("|^[-+]?\s*[0-9]+($dec_regex)?\$|", $number)) {
@@ -42,6 +49,9 @@
function email($email, $check_domain = false)
{
+ if ( is_array( $email ) )
+ extract($email);
+
if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))
@@ -63,6 +73,9 @@
*/
function string($string, $format = null, $min_lenght = 0, $max_lenght = 0)
{
+ if ( is_array( $string ) )
+ extract($string);
+
if ($format && !preg_match("|^[$format]*\$|s", $string)) {
return false;
}
@@ -75,6 +88,8 @@
return true;
}
+ // move outside
+ /*
function date($date, $format, $min_range = false, $max_range = false)
{
if (!include_once 'Date/Date.php') {
@@ -82,9 +97,13 @@
return false;
}
}
-
+ */
+
function url($url, $domain_check = false)
{
+ if ( is_array( $url ) )
+ extract($url);
+
$purl = parse_url($url);
if (preg_match('|^http$|i', @$purl['scheme']) &&
!empty($purl['host'])) {
if ($domain_check && function_exists('checkdnsrr')) {
@@ -99,9 +118,43 @@
return false;
}
- function multiple($data, $options)
- {
+
+ /*
+ To Do :
+ External calls based on commented Date methods
+
+ @param array $data Ex:
array('name'=>'toto','email'='toto@thing.info');
+ @param array $opt Contains the validation type and all parameters used in.
+ 'type' is not optional
+ others validations properties must have the same name as the function
+ parameters.
+ Ex:
array('toto'=>array('type'=>'string','format'='toto@thing.info','min_lenght'=>5));
+ @param boolean $remove if set, the invalid elements in data will be removed ( Not yet
implemented)
+
+ @return array value name => true|false the value name comes from the data key
+ */
+ function multiple( &$data, &$val_type, $remove = false ) {
+ $core_methods =
array('number','string','email','url');
+ if( !is_null($data) && !is_null($val_type) ){
+
+ $keys = array_keys( $data );
+ foreach( $keys as $var_name ) {
+ if (isset( $val_type[$var_name] ))
+ $opt = $val_type[$var_name];
+
+ if ( isset( $opt['type'] ) &&
$opt['type']!="" )
+ if ( in_array( $opt['type'], $core_methods ) ){
+ $opt[$opt['type']] = $data[$var_name];
+ $valid[$var_name] = Validate::$opt['type']($opt);
+ } else {
+ // External call
+ }
+ }
+ return $valid;
+ } else {
+ return null;
+ }
}
}
-?>
\ No newline at end of file
+?>