public function addValidator($validator, $message = null)
    {
        try {
            $msg = $message;
            if (is_array($message)) {
                $msg = array_shift($message);
                $this->context = $message;
            }
            $validator = StaticValidator::create($validator, $msg);
            $this->getValidationChain()
                ->add($validator);
            if ($validator instanceof NotEmpty) {
                $this->setRequired(true);
            }
        } catch (ValidatorException $caught) {
            throw new InvalidArgumentException(
                $caught->getMessage(),
                0,
                $caught
            );
        }
        return $this;
    }
public function addValidator($validator, $message = null)
    {
        try {
            $msg = $message;
            if (is_array($message)) {
                $msg = array_shift($message);
                $this->context = $message;
            }
            $validator = StaticValidator::create($validator, $msg);
            $this->getValidationChain()
                ->add($validator);
            if ($validator instanceof NotEmpty) {
                $this->setRequired(true);
            }
        } catch (ValidatorException $caught) {
            throw new InvalidArgumentException(
                $caught->getMessage(),
                0,
                $caught
            );
        }
        return $this;
    }
public function addValidator ( $ validator , $ message = null ) { try { $ msg = $ message ; if ( is_array ( $ message ) ) { $ msg = array_shift ( $ message ) ; $ this -> context = $ message ; } $ validator = StaticValidator :: create ( $ validator , $ msg ) ; $ this -> getValidationChain ( ) -> add ( $ validator ) ; if ( $ validator instanceof NotEmpty ) { $ this -> setRequired ( true ) ; } } catch ( ValidatorException $ caught ) { throw new InvalidArgumentException ( $ caught -> getMessage ( ) , 0 , $ caught ) ; } return $ this ; }
Adds a validator to the validation chain

The validator param could be a known validator alias, a FQ
ValidatorInterface class name or an object implementing
ValidatorInterface.

@param string|ValidatorInterface $validator
@param string|array $message Error message and possible contexts
variables.

@return self|$this|ValidationAwareInterface|ElementInterface

@throws InvalidArgumentException If the provided validator is an unknown
validator alias or not a valid class name or the object passed
does not implement the ValidatorInterface interface.
Adds a validator to the validation chain