123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php namespace System;
- class Validator {
-
- public $attributes;
-
- public $errors;
-
- public $rules = array();
-
- public function __construct($target = null)
- {
- $this->errors = new Validation\Error_Collector;
- if (is_null($target))
- {
- $target = Input::get();
- }
-
-
-
-
- $this->attributes = ($target instanceof DB\Eloquent) ? $target->attributes : (array) $target;
- }
-
- public static function make($target = null)
- {
- return new static($target);
- }
-
- public function is_valid()
- {
- $this->errors->messages = array();
- foreach ($this->rules as $rule)
- {
-
-
-
-
- $rule->validate($this->attributes, $this->errors);
- }
- return count($this->errors->messages) == 0;
- }
-
- public function __call($method, $parameters)
- {
-
-
-
-
- if (file_exists(SYS_PATH.'validation/rules/'.$method.EXT))
- {
- $rule = '\\System\\Validation\\Rules\\'.$method;
- return $this->rules[] = new $rule($parameters);
- }
- throw new \Exception("Method [$method] does not exist on Validator class.");
- }
- }
|