/** * Field::setValidator() * * Set the validator which is used to validate the value of the field * * @param ValidatorInterface $validator Instance of a validator * @return static * @author Teye Heimans * @author Marien den Besten */ public function setValidator($validator = null) { if (!is_null($validator)) { //fix to enable legacy framework to work... :( if (!$validator instanceof Validator\ValidatorInterface) { $validator = FormHandler::parseValidator($validator); } if (!$validator instanceof Validator\ValidatorInterface) { trigger_error('Argument 1 passed to setValidator() must be an instance of ' . 'ValidatorInterface, ' . gettype($validator) . ' given', E_USER_WARNING); return $this; } //register form object which could be used in callable if ($validator instanceof Validator\FunctionCallable) { $validator->setFormObject($this->form_object); } $validator->setField($this); $this->validators[] = $validator; } return $this; }