Ejemplo n.º 1
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if (!is_numeric($value)) {
         $model->errors()->add($attribute, 'numeric');
     }
     if ($this->only_integer !== NULL and !(filter_var($value, FILTER_VALIDATE_INT) !== FALSE)) {
         $model->errors()->add($attribute, 'numeric_only_integer');
     }
     if ($this->greater_than_or_equal_to !== NULL and !($value >= $this->greater_than_or_equal_to)) {
         $model->errors()->add($attribute, 'numeric_greater_than_or_equal_to', array(':greater_than_or_equal_to' => $this->greater_than_or_equal_to));
     }
     if ($this->greater_than !== NULL and !($value > $this->greater_than)) {
         $model->errors()->add($attribute, 'numeric_greater_than', array(':greater_than' => $this->greater_than));
     }
     if ($this->equal_to !== NULL and !($value == $this->equal_to)) {
         $model->errors()->add($attribute, 'numeric_equal_to', array(':equal_to' => $this->equal_to));
     }
     if ($this->less_than !== NULL and !($value < $this->less_than)) {
         $model->errors()->add($attribute, 'numeric_less_than', array(':less_than' => $this->less_than));
     }
     if ($this->less_than_or_equal_to !== NULL and !($value <= $this->less_than_or_equal_to)) {
         $model->errors()->add($attribute, 'numeric_less_than_or_equal_to', array(':less_than_or_equal_to' => $this->less_than_or_equal_to));
     }
     if ($this->between !== NULL and !($value >= $this->between[0] and $value <= $this->between[1])) {
         $model->errors()->add($attribute, 'numeric_between', array(':minimum' => $this->between[0], ':maximum' => $this->between[1]));
     }
     if ($this->odd === TRUE and !($value % 2 == 0)) {
         $model->errors()->add($attribute, 'numeric_odd', array(':odd' => $this->odd));
     }
     if ($this->even === TRUE and !($value % 2 == 1)) {
         $model->errors()->add($attribute, 'numeric_even', array(':even' => $this->even));
     }
 }
Ejemplo n.º 2
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if ($this->in !== NULL and !in_array($value, $this->in)) {
         $model->errors()->add($attribute, 'choice_in', array(':in' => join(', ', $this->in)));
     }
     if ($this->not_in !== NULL and !!in_array($value, $this->not_in)) {
         $model->errors()->add($attribute, 'choice_not_in', array(':not_in' => join(', ', $this->not_in)));
     }
 }
Ejemplo n.º 3
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     $promo_code = $this->valid_promo_code($value);
     if (!$promo_code) {
         $model->errors()->add('promo_code_text', 'invalid');
     } elseif ($promo_code->is_expired()) {
         $model->errors()->add('promo_code_text', 'expired');
     }
 }
Ejemplo n.º 4
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     $confirmation = $this->confirmation ? $this->confirmation : $attribute . '_confirmation';
     if ($model->{$confirmation} and $value !== $model->{$confirmation}) {
         $model->errors()->add($attribute, 'confirmed', array(':confirmation' => $confirmation));
     }
 }
Ejemplo n.º 5
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     $length = mb_strlen($value);
     if ($this->minimum !== NULL and !($length >= $this->minimum)) {
         $model->errors()->add($attribute, 'length_minimum', array(':minimum' => $this->minimum));
     }
     if ($this->maximum !== NULL and !($length <= $this->maximum)) {
         $model->errors()->add($attribute, 'length_maximum', array(':maximum' => $this->maximum));
     }
     if ($this->between !== NULL and !($length >= $this->between[0] and $length <= $this->between[1])) {
         $model->errors()->add($attribute, 'length_between', array(':minimum' => $this->between[0], ':maximum' => $this->between[1]));
     }
     if ($this->is !== NULL and !($length == $this->is)) {
         $model->errors()->add($attribute, 'length_is', array('is' => $this->is));
     }
 }
Ejemplo n.º 6
0
Archivo: Count.php Proyecto: Konro1/pms
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     $count = count($value);
     $params = (array) $this;
     if ($this->minimum !== NULL and !($count >= $this->minimum)) {
         $model->errors()->add($attribute, 'count_minimum', array(':minimum' => $this->minimum));
     }
     if ($this->maximum !== NULL and !($count <= $this->maximum)) {
         $model->errors()->add($attribute, 'count_maximum', array(':maximum' => $this->maximum));
     }
     if ($this->within !== NULL and !($count >= $this->within[0] and $count <= $this->within[1])) {
         $model->errors()->add($attribute, 'count_within', array(':minimum' => $this->within[0], ':maximum' => $this->within[1]));
     }
     if ($this->is !== NULL and !($count == $this->is)) {
         $model->errors()->add($attribute, 'count_is', array(':is' => $this->is));
     }
 }
Ejemplo n.º 7
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if (!$value instanceof Jam_Range) {
         throw new Kohana_Exception('Range validation rule can only be applied to range');
     }
     if (!is_numeric($value->min()) or !is_numeric($value->max())) {
         $model->errors()->add($attribute, 'range_numeric');
         return;
     }
     $min = min($value->min(), $value->max());
     $max = max($value->min(), $value->max());
     if ($this->minimum !== NULL and $min <= $this->minimum) {
         $model->errors()->add($attribute, 'range_minimum', array(':minimum' => $this->minimum));
     }
     if ($this->minimum_or_equal_to !== NULL and $min < $this->minimum_or_equal_to) {
         $model->errors()->add($attribute, 'range_minimum_or_equal_to', array(':minimum_or_equal_to' => $this->minimum_or_equal_to));
     }
     if ($this->maximum !== NULL and $max >= $this->maximum) {
         $model->errors()->add($attribute, 'range_maximum', array(':maximum' => $this->maximum));
     }
     if ($this->maximum_or_equal_to !== NULL and $max > $this->maximum_or_equal_to) {
         $model->errors()->add($attribute, 'range_maximum_or_equal_to', array(':maximum_or_equal_to' => $this->maximum_or_equal_to));
     }
     if ($this->between !== NULL and !($min >= $this->between[0] and $max <= $this->between[1])) {
         $model->errors()->add($attribute, 'range_between', array(':minimum' => $this->between[0], ':maximum' => $this->between[1]));
     }
     if ($this->consecutive !== NULL and $value->min() > $value->max()) {
         $model->errors()->add($attribute, 'range_consecutive');
     }
 }
Ejemplo n.º 8
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if ($this->regex !== NULL and !preg_match($this->regex, $value)) {
         $model->errors()->add($attribute, 'format_regex', array(':regex' => $this->regex));
     }
     if ($this->filter !== NULL and !(filter_var($value, $this->filter, $this->flag) !== FALSE)) {
         $model->errors()->add($attribute, 'format_filter', array(':filter' => $this->filter));
     }
     if ($this->ip === TRUE and !Valid::ip($value)) {
         $model->errors()->add($attribute, 'format_ip');
     }
     if ($this->url === TRUE and !Valid::url($value)) {
         $model->errors()->add($attribute, 'format_url');
     }
     if ($this->email === TRUE and !Valid::email($value)) {
         $model->errors()->add($attribute, 'format_email');
     }
     if ($this->credit_card === TRUE and !Valid::credit_card($value)) {
         $model->errors()->add($attribute, 'format_credit_card');
     }
     if ($this->date === TRUE and strtotime($value) === FALSE) {
         $model->errors()->add($attribute, 'format_date');
     }
 }
Ejemplo n.º 9
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if (Jam_Validator_Rule_Present::is_empty_value($value, $this->allow_zero) or Jam_Validator_Rule_Present::is_empty_string($value) or Jam_Validator_Rule_Present::is_empty_countable($value) or Jam_Validator_Rule_Present::is_empty_upload_file($value)) {
         $model->errors()->add($attribute, 'present');
     }
 }
Ejemplo n.º 10
0
 private function _add_messages_all(Jam_Validated $model, array &$messages)
 {
     foreach ($model->errors() as $attribute_name => $errors) {
         if ($model->meta()->association($attribute_name) instanceof Jam_Association_Collection) {
             foreach ($model->{$attribute_name} as $i => $item) {
                 if (!$item->is_valid()) {
                     $this->_add_messages_all($item, $messages);
                 }
             }
         } elseif ($model->meta()->association($attribute_name) and $model->{$attribute_name}) {
             $this->_add_messages_all($model->{$attribute_name}, $messages);
         } else {
             foreach ($errors as $error => $params) {
                 $model_name = UTF8::ucfirst(Inflector::humanize($model->meta()->model()));
                 $messages[] = $model_name . ': ' . Jam_Errors::message($model->meta()->errors_filename(), $attribute_name, $error, Arr::merge($params, array(':model' => $model->meta()->model(), ':attribute' => Jam_Errors::attribute_label($model->meta(), $attribute_name))));
             }
         }
     }
     return $messages;
 }
Ejemplo n.º 11
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     if ($value and !$value->is_empty() and $value->source()) {
         if ($error = $value->source()->error()) {
             $model->errors()->add($attribute, 'uploaded_native', array(':message' => $error));
         } elseif (!is_file($value->file())) {
             $model->errors()->add($attribute, 'uploaded_is_file');
         }
         if ($this->only and !in_array(strtolower(pathinfo($value->filename(), PATHINFO_EXTENSION)), $this->valid_extensions())) {
             $model->errors()->add($attribute, 'uploaded_extension', array(':extension' => join(', ', $this->valid_extensions())));
         }
         if ($this->minimum_size or $this->maximum_size or $this->exact_size) {
             $size = @filesize($value->file());
             if ($this->minimum_size and $minimum_size = Num::bytes($this->minimum_size) and (int) $size < (int) $minimum_size) {
                 $model->errors()->add($attribute, 'uploaded_minimum_size', array(':minimum_size' => $this->minimum_size));
             }
             if ($this->maximum_size and $maximum_size = Num::bytes($this->maximum_size) and (int) $size > (int) $maximum_size) {
                 $model->errors()->add($attribute, 'uploaded_maximum_size', array(':maximum_size' => $this->maximum_size));
             }
             if ($this->exact_size and $exact_size = Num::bytes($this->exact_size) and (int) $size !== (int) $exact_size) {
                 $model->errors()->add($attribute, 'uploaded_exact_size', array(':exact_size' => $this->exact_size));
             }
         }
         if ($this->minimum_width or $this->minimum_height or $this->maximum_width or $this->maximum_height or $this->exact_width or $this->exact_height) {
             $dims = @getimagesize($value->file());
             if ($dims) {
                 list($width, $height) = $dims;
                 if ($this->exact_width and (int) $width !== (int) $this->exact_width) {
                     $model->errors()->add($attribute, 'uploaded_exact_width', array(':exact_width' => $this->exact_width));
                 }
                 if ($this->exact_height and (int) $height !== (int) $this->exact_height) {
                     $model->errors()->add($attribute, 'uploaded_exact_height', array(':exact_height' => $this->exact_height));
                 }
                 if ($this->minimum_width and (int) $width < (int) $this->minimum_width) {
                     $model->errors()->add($attribute, 'uploaded_minimum_width', array(':minimum_width' => $this->minimum_width));
                 }
                 if ($this->minimum_height and (int) $height < (int) $this->minimum_height) {
                     $model->errors()->add($attribute, 'uploaded_minimum_height', array(':minimum_height' => $this->minimum_height));
                 }
                 if ($this->maximum_width and (int) $width > (int) $this->maximum_width) {
                     $model->errors()->add($attribute, 'uploaded_maximum_width', array(':maximum_width' => $this->maximum_width));
                 }
                 if ($this->maximum_height and (int) $height > (int) $this->maximum_height) {
                     $model->errors()->add($attribute, 'uploaded_maximum_height', array(':maximum_height' => $this->maximum_height));
                 }
             }
         }
     }
 }