_validator instanceof AbstractValidate) { throw new \InvalidArgumentException("A validator has not been initialized."); } return $this->_validator; } /** * * set validator object * * @param \Cube\Validate\AbstractValidate $validator * * @return $this */ public function setValidator(AbstractValidate $validator) { $this->_validator = $validator; return $this; } /** * * direct method, callable from within the view to return the helper * * @return $this */ public function validate(AbstractValidate $validator = null) { if ($validator instanceof AbstractValidate) { $this->setValidator($validator); } return $this; } /** * * call validator is valid method * * @param mixed $value * * @return bool */ public function isValid($value) { $validator = $this->getValidator(); $validator->setValue($value); return @$validator->isValid(); } /** * * call magic method, calls validators and runs them directly * * @param string $name * @param array $arguments * * @return bool */ public function __call($name, $arguments) { $className = '\\Cube\\Validate\\' . ucfirst($name); /** @var \Cube\Validate\AbstractValidate $validator */ if (class_exists($className)) { $this->setValidator( new $className()); } if (count($arguments) == 1) { $arguments = $arguments[0]; } return $this->isValid($arguments); } }