Zend_Validate_Callback覆盖self :: INVALID_VALUE消息

I wrote this piece of code, which works perfectly. The only thing I don't manage to change is the default callback error message "const INVALID_VALUE = 'callbackValue';" in Zend_Validate_Callback.

$validators['ip'][] = array('Ip');
$validators['ip'][] = array('Callback', array('callback' => array($this->_ip, 'ipUnique')));
$filters = array('*' => 'StringTrim');
$input = new Zend_Filter_Input($filters, $validators, $_POST);
$input->setOptions(array('presence' => 'required')); 

if($input->isValid()){
    // all okay
}
else{
    return $input->getMessages();
}

Any ideas?

The class looks like this, you can only change the const value from the source code. If you want to change this then find Zend_Validate_Callback and change it in the code.

class Zend_Validate_Callback extends Zend_Validate_Abstract implements Zend_Validate_Interface{
/* Constants */

const INVALID_CALLBACK="callbackInvalid"; <-- here you change the value
const INVALID_VALUE="callbackValue"; <-- here you change the value
/* Public methods defined in class */

public function __construct (string|array $callback=null)
public function getCallback ( )
public function setCallback (string|array $callback)
public function getOptions ( )
public function setOptions (mixed $options)
public function isValid (mixed $value)
/* Public methods inherited from class Zend_Validate_Abstract */

public function getMessages ( )
public function getMessageVariables ( )
public function getMessageTemplates ( )
public function setMessage (string $messageString, string $messageKey=null)
public function setMessages (Array $messages)
public function __get (string $property)
public function getErrors ( )
public function setObscureValue (bool $flag)
public function getObscureValue ( )
public function setTranslator (Zend_Translate|Zend_Translate_Adapter|null $translator=null)
public function getTranslator ( )
public function hasTranslator ( )
public static function setDefaultTranslator (Zend_Translate|Zend_Translate_Adapter|null $translator=null)
public static function getDefaultTranslator ( )
public static function hasDefaultTranslator ( )
public function setDisableTranslator (bool $flag)
public function translatorIsDisabled ( )
public static function getMessageLength ( )
public static function setMessageLength (integer $length=-1)
}

Read more here http://zfdoc.hafees.com/class/Zend_Validate_Callback.html#class,Zend_Validate_Callback

Found the answer to my question after looking into the ZF source code, you can't overwrite its message in an array based structure, the option "messages" got lost in the constructor of Zend_Validate_Callback. Zend_Validate_Abstract has a public method "setMessages" which works nicely to overwrite the callback error message.

Final code:

$callbackValidator = new Zend_Validate_Callback(array($this->_ip, 'ipUnique'));
$callbackValidator->setMessages(array(Zend_Validate_Callback::INVALID_VALUE => "'%value%' is not a unique IP address"));

$validators['ip'][] = array('Ip');
$validators['ip'][] = $callbackValidator;
$filters = array('*' => 'StringTrim');
$input = new Zend_Filter_Input($filters, $validators, $_POST);
$input->setOptions(array('presence' => 'required')); 

if($input->isValid()){
    // all okay
}
else{
    return $input->getMessages();
}