__call($ruleName, $arguments); } public static function buildRule($ruleSpec, $arguments=array()) { if ($ruleSpec instanceof Validatable) return $ruleSpec; try { $validatorFqn = 'Respect\\Validation\\Rules\\' . ucfirst($ruleSpec); $validatorClass = new ReflectionClass($validatorFqn); $validatorInstance = $validatorClass->newInstanceArgs( $arguments ); return $validatorInstance; } catch (ReflectionException $e) { throw new ComponentException($e->getMessage()); } } public function __call($method, $arguments) { $this->addRule(static::buildRule($method, $arguments)); return $this; } public function reportError($input, array $extraParams=array()) { $exception = new AllOfException; $input = AllOfException::stringify($input); $name = $this->getName() ? : "\"$input\""; $params = array_merge( $extraParams, get_object_vars($this), get_class_vars(__CLASS__) ); $exception->configure($name, $params); if (!is_null($this->template)) $exception->setTemplate($this->template); return $exception; } /** * Create instance validator * * @static * @return \Respect\Validation\Validator */ public static function create() { $ref = new ReflectionClass(__CLASS__); return $ref->newInstanceArgs(func_get_args()); } }