本文整理汇总了PHP中Phalcon\Validation::getDefaultMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::getDefaultMessage方法的具体用法?PHP Validation::getDefaultMessage怎么用?PHP Validation::getDefaultMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Validation
的用法示例。
在下文中一共展示了Validation::getDefaultMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetDefaultValidationMessageShouldReturnEmptyStringIfNoneIsSet
public function testGetDefaultValidationMessageShouldReturnEmptyStringIfNoneIsSet()
{
$this->specify("getDefaultMessage() should return empty string if none is set", function () {
$validation = new Validation();
expect($validation->getDefaultMessage('_notexistentvalidationmessage_'))->isEmpty();
});
}
示例2: validate
/**
* Executes the validation
*
* @package base-app
* @version 2.0
*
* @param object $validation Phalcon\Validation
* @param string $field field name
*
* @return boolean
*
* @throws \Phalcon\Validation\Exception
*/
public function validate(\Phalcon\Validation $validation, $field)
{
$value = $validation->getValue($field);
$model = $this->getOption("model");
$attribute = $this->getOption("attribute");
if (empty($model)) {
throw new \Phalcon\Validation\Exception("Model must be set");
}
if (empty($attribute)) {
$attribute = $field;
}
if ($except = $this->getOption('except')) {
$number = $model::count(array($attribute . "=:value: AND " . $attribute . "!= :except:", "bind" => array("value" => $value, 'except' => $except)));
} else {
$number = $model::count(array($attribute . "=:value:", "bind" => array("value" => $value)));
}
if ($number) {
$label = $this->getOption("label");
if (empty($label)) {
$label = $validation->getLabel($field);
if (empty($label)) {
$label = $field;
}
}
$message = $this->getOption("message");
$replacePairs = array(":field" => $label);
if (empty($message)) {
$message = $validation->getDefaultMessage("Uniqueness");
}
$validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uniqueness"));
return false;
}
return true;
}
示例3: validate
/**
* {@inheritdoc}
*
* @param Validation $validation
* @param string $attribute
*
* @return bool
*/
public function validate(Validation $validation, $attribute)
{
$secret = $this->getOption('secret');
$value = $validation->getValue($attribute);
$request = $validation->getDI()->get('request');
$remoteIp = $request->getClientAddress(false);
if (!empty($value)) {
$curl = curl_init(self::RECAPTCHA_URL);
curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => ['secret' => $secret, 'response' => $value, 'remoteip' => $remoteIp]]);
$response = json_decode(curl_exec($curl), true);
curl_close($curl);
}
if (empty($response['success'])) {
$label = $this->getOption('label');
if (empty($label)) {
$label = $validation->getLabel($attribute);
}
$message = $this->getOption('message');
$replacePairs = [':field', $label];
if (empty($message) && !empty($response['error-codes'])) {
$message = $this->messages[$response['error-codes']];
}
if (empty($message)) {
$message = $validation->getDefaultMessage('ReCaptcha');
}
$validation->appendMessage(new Message(strtr($message, $replacePairs), $attribute, 'ReCaptcha'));
return false;
}
return true;
}