本文整理汇总了PHP中Zend_Validate_Digits::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Digits::getMessages方法的具体用法?PHP Zend_Validate_Digits::getMessages怎么用?PHP Zend_Validate_Digits::getMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate_Digits
的用法示例。
在下文中一共展示了Zend_Validate_Digits::getMessages方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* @group ZF-11267
* If we pass in a validator instance that has a preset custom message, this
* message should be used.
*/
function testIfCustomMessagesOnValidatorInstancesCanBeUsed()
{
// test with a Digits validator
require_once 'Zend/Validate/Digits.php';
require_once 'Zend/Validate/NotEmpty.php';
$data = array('field1' => 'invalid data');
$customMessage = 'Hey, that\'s not a Digit!!!';
$validator = new Zend_Validate_Digits();
$validator->setMessage($customMessage, 'notDigits');
$this->assertFalse($validator->isValid('foo'), 'standalone validator thinks \'foo\' is a valid digit');
$messages = $validator->getMessages();
$this->assertSame($messages['notDigits'], $customMessage, 'stanalone validator does not have custom message');
$validators = array('field1' => $validator);
$input = new Zend_Filter_Input(null, $validators, $data);
$this->assertFalse($input->isValid(), 'invalid input is valid');
$messages = $input->getMessages();
$this->assertSame($messages['field1']['notDigits'], $customMessage, 'The custom message is not used');
// test with a NotEmpty validator
$data = array('field1' => '');
$customMessage = 'You should really supply a value...';
$validator = new Zend_Validate_NotEmpty();
$validator->setMessage($customMessage, 'isEmpty');
$this->assertFalse($validator->isValid(''), 'standalone validator thinks \'\' is not empty');
$messages = $validator->getMessages();
$this->assertSame($messages['isEmpty'], $customMessage, 'stanalone NotEmpty validator does not have custom message');
$validators = array('field1' => $validator);
$input = new Zend_Filter_Input(null, $validators, $data);
$this->assertFalse($input->isValid(), 'invalid input is valid');
$messages = $input->getMessages();
$this->assertSame($messages['field1']['isEmpty'], $customMessage, 'For the NotEmpty validator the custom message is not used');
}
示例2: testInvalidValueResultsInProperValidationFailureMessages
/**
* @return void
*/
public function testInvalidValueResultsInProperValidationFailureMessages()
{
$this->assertFalse($this->_validator->isValid('#'));
$messages = $this->_validator->getMessages();
$arrayExpected = array(Zend_Validate_Digits::NOT_DIGITS => '\'#\' contains not only digit characters');
$this->assertThat($messages, $this->identicalTo($arrayExpected));
}
示例3: _validateInputRule
/**
* Validate value by attribute input validation rule
*
* @param string $value
* @return array|true
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _validateInputRule($value)
{
// skip validate empty value
if (empty($value)) {
return true;
}
$label = $this->getAttribute()->getStoreLabel();
$validateRules = $this->getAttribute()->getValidationRules();
$inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation');
if (!is_null($inputValidation)) {
switch ($inputValidation) {
case 'alphanumeric':
$validator = new \Zend_Validate_Alnum(true);
$validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID);
$validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM);
$validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'numeric':
$validator = new \Zend_Validate_Digits();
$validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID);
$validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS);
$validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'alpha':
$validator = new \Zend_Validate_Alpha(true);
$validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID);
$validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA);
$validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'email':
/**
__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
__("Invalid type given. String expected")
__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
__("'%value%' does not match the expected structure for a DNS hostname")
__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
__("'%value%' does not appear to be a valid local network name")
__("'%value%' does not appear to be a valid URI hostname")
__("'%value%' appears to be an IP address, but IP addresses are not allowed")
__("'%value%' appears to be a local network name but local network names are not allowed")
__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
*/
$validator = new \Zend_Validate_EmailAddress();
$validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID);
$validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT);
$validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME);
$validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM);
$validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING);
$validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
$validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
$validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
$validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD);
$validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH);
$validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
$validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
$validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME);
$validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
$validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
if (!$validator->isValid($value)) {
return array_unique($validator->getMessages());
}
break;
case 'url':
$parsedUrl = parse_url($value);
if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
return [__('"%1" is not a valid URL.', $label)];
}
$validator = new \Zend_Validate_Hostname();
if (!$validator->isValid($parsedUrl['host'])) {
return [__('"%1" is not a valid URL.', $label)];
}
break;
case 'date':
$validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
$validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID);
$validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE);
$validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT);
if (!$validator->isValid($value)) {
return array_unique($validator->getMessages());
}
//.........这里部分代码省略.........
示例4: _validateInputRule
/**
* Validate value by attribute input validation rule
*
* @param string $value
* @return string
*/
protected function _validateInputRule($value)
{
// skip validate empty value
if (empty($value)) {
return true;
}
$label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
$validateRules = $this->getAttribute()->getValidateRules();
if (!empty($validateRules['input_validation'])) {
switch ($validateRules['input_validation']) {
case 'alphanumeric':
$validator = new Zend_Validate_Alnum(true);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'numeric':
$validator = new Zend_Validate_Digits();
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'alpha':
$validator = new Zend_Validate_Alpha(true);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'email':
/**
$this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
$this->__("Invalid type given. String expected")
$this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
$this->__("'%value%' does not match the expected structure for a DNS hostname")
$this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
$this->__("'%value%' does not appear to be a valid local network name")
$this->__("'%value%' does not appear to be a valid URI hostname")
$this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
$this->__("'%value%' appears to be a local network name but local network names are not allowed")
$this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
$this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
*/
$validator = new Zend_Validate_EmailAddress();
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
$validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
$validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
$validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
if (!$validator->isValid($value)) {
return array_unique($validator->getMessages());
}
break;
case 'url':
$parsedUrl = parse_url($value);
if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
}
$validator = new Zend_Validate_Hostname();
if (!$validator->isValid($parsedUrl['host'])) {
return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
}
break;
case 'date':
$validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
$validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
if (!$validator->isValid($value)) {
return array_unique($validator->getMessages());
}
break;
}
}
//.........这里部分代码省略.........
示例5: _validateInputRule
/**
* Validate value by attribute input validation rule
*
* @param string $value
* @return string
*/
protected function _validateInputRule($value)
{
// skip validate empty value
if (empty($value)) {
return true;
}
$label = $this->getAttribute()->getStoreLabel();
$validateRules = $this->getAttribute()->getValidateRules();
if (!empty($validateRules['input_validation'])) {
switch ($validateRules['input_validation']) {
case 'alphanumeric':
$validator = new Zend_Validate_Alnum(true);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'numeric':
$validator = new Zend_Validate_Digits();
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'alpha':
$validator = new Zend_Validate_Alpha(true);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
$validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
if (!$validator->isValid($value)) {
return $validator->getMessages();
}
break;
case 'email':
$validator = new Zend_Validate_EmailAddress();
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
$validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
if (!$validator->isValid($value)) {
return array_unique($validator->getMessages());
}
break;
case 'url':
$parsedUrl = parse_url($value);
if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
}
$validator = new Zend_Validate_Hostname();
if (!$validator->isValid($parsedUrl['host'])) {
return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
}
break;
case 'date':
$format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
$validator = new Zend_Validate_Date($format);
$validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
$validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
$validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
break;
}
}
return true;
}
示例6: testGetMessages
/**
* Ensures that getMessages() returns expected default value
*
* @return void
*/
public function testGetMessages()
{
$this->assertEquals(array(), $this->_validator->getMessages());
}