Skip to content

Commit

Permalink
Added an identificator to the Validation options so for each new opti…
Browse files Browse the repository at this point in the history
…on a counter adds and then you will know wich control is with each validation.
  • Loading branch information
alrik11es committed Sep 6, 2012
1 parent e990588 commit b997b93
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions sPHPf/vendors/coldstarstudios/validation/Validation.php
Expand Up @@ -13,6 +13,7 @@ class Validation {

public $isValid = true;
public $errors = array();
private $count = 0;

// Temporary condition for generic checks.
public $condition;
Expand All @@ -23,9 +24,10 @@ class Validation {
* @param string $message
*/
function isEmpty($param, $message){
$this->count++;
if(empty($param)){
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -35,14 +37,15 @@ function isEmpty($param, $message){
* @param boolean $condition
*/
function generic($message, $condition = null){
$this->count++;
if($condition != null)
$condition = $condition;
else
$condition = $this->condition;

if($condition){
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -55,15 +58,16 @@ function generic($message, $condition = null){
* @param string $message_mime
*/
function file($param, $mime, $size, $message_size, $message_mime){
$this->count++;
if(!empty($param['tmp_name'])){
if($param['size'] > $size) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message_size));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message_size));
}

if(!\coldstarstudios\uploads\Upload::validateMimeType($param['type'], $mime)) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message_mime));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message_mime));
}
}
}
Expand All @@ -75,9 +79,10 @@ function file($param, $mime, $size, $message_size, $message_mime){
* @param type $message
*/
function equal($param1, $param2, $message){
$this->count++;
if($param1 != $param2) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -88,9 +93,10 @@ function equal($param1, $param2, $message){
* @param string $message
*/
function minLength($param, $length, $message){
$this->count++;
if(strlen($param) < $length) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -101,20 +107,23 @@ function minLength($param, $length, $message){
* @param string $message
*/
function maxLength($param, $length, $message){
$this->count++;
if(strlen($param) > $length) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

function dateRange($param1, $param2, $message){
$this->count++;

}

function numericRange($param, $max, $min, $message){
$this->count++;
if($param > $max || $param < $min) {
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -124,9 +133,10 @@ function numericRange($param, $max, $min, $message){
* @param type $message
*/
function email($param, $message){
$this->count++;
if(!empty($param) && !Email::validate($param)){
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}

Expand All @@ -136,11 +146,12 @@ function email($param, $message){
* @param type $message
*/
function telephone($param, $message){
$this->count++;
$match = '/^((\+)?(\d{2})[-])?(([\(])?((\d){3,5})([\)])?[-])|(\d{3,5})(\d{5,8}){1}?$/';
$answer = preg_match($match, $param);
if(!empty($param) && !$answer){
$this->isValid = false;
array_push($this->errors, array('message'=>$message));
array_push($this->errors, array('id'=>$this->count, 'message'=>$message));
}
}
}
Expand Down

0 comments on commit b997b93

Please sign in to comment.