Skip to content
This repository has been archived by the owner on Sep 8, 2019. It is now read-only.

Commit

Permalink
done some variable translations
Browse files Browse the repository at this point in the history
  • Loading branch information
spiechu committed Jun 6, 2011
1 parent afa4e1c commit ccbcbcb
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions library/Spiechu/StaticValidator/Validator.php
Expand Up @@ -112,7 +112,7 @@ protected static function extractFunction($name)
'function' => 'eqLtGt' ,
'args' => array(
'subfunc' => 'gt' ,
'warunek' => substr($name , 2)
'condition' => substr($name , 2)
));
}
elseif (stripos($name , 'lt') === 0)
Expand All @@ -121,7 +121,7 @@ protected static function extractFunction($name)
'function' => 'eqLtGt' ,
'args' => array(
'subfunc' => 'lt' ,
'warunek' => substr($name , 2)
'condition' => substr($name , 2)
));
}
elseif (stripos($name , 'eq') === 0)
Expand All @@ -130,7 +130,7 @@ protected static function extractFunction($name)
'function' => 'eqLtGt' ,
'args' => array(
'subfunc' => 'eq' ,
'warunek' => substr($name , 2)
'condition' => substr($name , 2)
));
}
elseif (stripos($name , 'between') === 0)
Expand All @@ -147,7 +147,7 @@ protected static function extractFunction($name)
'function' => 'minMaxLength' ,
'args' => array(
'subfunc' => 'min' ,
'warunek' => substr($name , 9)
'condition' => substr($name , 9)
));
}
elseif (stripos($name , 'maxlength') === 0)
Expand All @@ -156,7 +156,7 @@ protected static function extractFunction($name)
'function' => 'minMaxLength' ,
'args' => array(
'subfunc' => 'max' ,
'warunek' => substr($name , 9)
'condition' => substr($name , 9)
));
}
elseif (stripos($name , 'only') === 0)
Expand Down Expand Up @@ -187,21 +187,21 @@ protected static function eqLtGt($var , array $args)
throw new ValidatorDataTypeMismatchException("Value {$var} is string, cast it to numeric");
if (!is_numeric($var))
throw new ValidatorDataTypeMismatchException("Value {$var} is not numeric");
if (!is_numeric($args['warunek']))
throw new ValidatorDataTypeMismatchException("Condition {$args['warunek']} is not numeric");
if (!is_numeric($args['condition']))
throw new ValidatorDataTypeMismatchException("Condition {$args['condition']} is not numeric");
switch ($args['subfunc'])
{
case 'gt':
return ($var > $args['warunek']);
return ($var > $args['condition']);
break;
case 'lt':
return ($var < $args['warunek']);
return ($var < $args['condition']);
break;
case 'eq':
return ($var == $args['warunek']);
return ($var == $args['condition']);
break;
default:
throw new ValidatorException("Couldn't resolve condition (eq|lt|gt) at {$args['func']}");
throw new ValidatorException("Couldn't resolve argument (eq|lt|gt) at {$args['subfunc']}");
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ protected static function isOrNot($var , array $args)
$result = is_string($var);
break;
default:
throw new ValidatorException("Couldn't resolve argument {$funcname}");
throw new ValidatorException("Couldn't resolve argument {$args['subfunc']}");
}
return ($not === true) ? !$result : $result;
}
Expand Down Expand Up @@ -266,24 +266,24 @@ protected static function minMaxLength($var , array $args)
{
if (!is_string($var))
throw new ValidatorDataTypeMismatchException("Checked value {$var} is not a string");
if (!is_int($args['warunek']))
throw new ValidatorDataTypeMismatchException("Condition {$args['warunek']} is not integer");
switch ($args['funcname'])
if (!is_int($args['condition']))
throw new ValidatorDataTypeMismatchException("Condition {$args['condition']} is not integer");
switch ($args['subfunc'])
{
case 'min':
return (strlen($var) >= (int) $args['warunek']);
return (strlen($var) >= (int) $args['condition']);
break;
case 'max':
return (strlen($var) <= (int) $args['warunek']);
return (strlen($var) <= (int) $args['condition']);
break;
default:
throw new ValidatorException("Couldn't resolve condition {$args['func']}");
throw new ValidatorException("Couldn't resolve condition {$args['subfunc']}");
}
}

protected static function only($var , array $args)
{
switch ($args['funcname'])
switch ($args['subfunc'])
{
case 'letters':
if (function_exists('ctype_alpha'))
Expand All @@ -304,7 +304,7 @@ protected static function only($var , array $args)
$alg = '/^[A-Z0-9]{1,}$/i';
break;
default:
throw new ValidatorException("Couldn't resolve condition {$args['funcname']}");
throw new ValidatorException("Couldn't resolve condition {$args['subfunc']}");
}
if (preg_match_all($alg , $var , $match) === 1)
return true;
Expand Down

0 comments on commit ccbcbcb

Please sign in to comment.