本文整理汇总了PHP中Zend_Validate::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate::getErrors方法的具体用法?PHP Zend_Validate::getErrors怎么用?PHP Zend_Validate::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate
的用法示例。
在下文中一共展示了Zend_Validate::getErrors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTrue
/**
* Ensures expected behavior from a validator known to succeed
*
* @return void
*/
public function testTrue()
{
$this->_validator->addValidator(new ValidatorTrue());
$this->assertTrue($this->_validator->isValid(null));
$this->assertEquals(array(), $this->_validator->getMessages());
$this->assertEquals(array(), $this->_validator->getErrors());
}
示例2: testBreakChainOnFailure
/**
* Ensures that a validator may break the chain
*
* @return void
*/
public function testBreakChainOnFailure()
{
$this->_validator->addValidator(new Zend_ValidateTest_False(), true)->addValidator(new Zend_ValidateTest_False());
$this->assertFalse($this->_validator->isValid(null));
$this->assertEquals(array('validation failed'), $this->_validator->getMessages());
$this->assertEquals(array('error'), $this->_validator->getErrors());
}
示例3: getErrors
/**
* Defined by Zend_Validate_Interface
*
* Returns array of validation failure message codes
*
* @return array
*/
public function getErrors()
{
$zendErrors = parent::getErrors();
$rmErrors = array();
foreach ($zendErrors as $error) {
$rmErrors[] = $this->_errorPrefix . ucfirst($error);
}
return $rmErrors;
}
示例4: _validateRule
/**
* @param array $validatorRule
* @return void
*/
protected function _validateRule(array $validatorRule)
{
/**
* Get one or more data values from input, and check for missing fields.
* Apply defaults if fields are missing.
*/
$data = array();
foreach ((array) $validatorRule[self::FIELDS] as $key => $field) {
if (array_key_exists($field, $this->_data)) {
$data[$field] = $this->_data[$field];
} else {
if (isset($validatorRule[self::DEFAULT_VALUE])) {
/** @todo according to this code default value can't be an array. It has to be reviewed */
if (!is_array($validatorRule[self::DEFAULT_VALUE])) {
// Default value is a scalar
$data[$field] = $validatorRule[self::DEFAULT_VALUE];
} else {
// Default value is an array. Search for corresponding key
if (isset($validatorRule[self::DEFAULT_VALUE][$key])) {
$data[$field] = $validatorRule[self::DEFAULT_VALUE][$key];
} else {
if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
// Default value array is provided, but it doesn't have an entry for current field
// and presence is required
$this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
}
}
}
} else {
if ($validatorRule[self::PRESENCE] == self::PRESENCE_REQUIRED) {
$this->_missingFields[$validatorRule[self::RULE]][] = $this->_getMissingMessage($validatorRule[self::RULE], $field);
}
}
}
}
/**
* If any required fields are missing, break the loop.
*/
if (isset($this->_missingFields[$validatorRule[self::RULE]]) && count($this->_missingFields[$validatorRule[self::RULE]]) > 0) {
return;
}
/**
* Evaluate the inputs against the validator chain.
*/
if (count((array) $validatorRule[self::FIELDS]) > 1) {
if (!$validatorRule[self::ALLOW_EMPTY]) {
$emptyFieldsFound = false;
$errorsList = array();
$messages = array();
foreach ($data as $fieldKey => $field) {
// if there is no Zend_Validate_NotEmpty instance in the rules, we will use the default
if (!($notEmptyValidator = $this->_getNotEmptyValidatorInstance($validatorRule))) {
$notEmptyValidator = $this->_getValidator('NotEmpty');
$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldKey));
}
if (!$notEmptyValidator->isValid($field)) {
foreach ($notEmptyValidator->getMessages() as $messageKey => $message) {
if (!isset($messages[$messageKey])) {
$messages[$messageKey] = $message;
} else {
$messages[] = $message;
}
}
$errorsList[] = $notEmptyValidator->getErrors();
$emptyFieldsFound = true;
}
}
if ($emptyFieldsFound) {
$this->_invalidMessages[$validatorRule[self::RULE]] = $messages;
$this->_invalidErrors[$validatorRule[self::RULE]] = array_unique(call_user_func_array('array_merge', $errorsList));
return;
}
}
if (!$validatorRule[self::VALIDATOR_CHAIN]->isValid($data)) {
$this->_invalidMessages[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getMessages();
$this->_invalidErrors[$validatorRule[self::RULE]] = $validatorRule[self::VALIDATOR_CHAIN]->getErrors();
return;
}
} else {
if (count($data) > 0) {
// $data is actually a one element array
$fieldNames = array_keys($data);
$fieldName = reset($fieldNames);
$field = reset($data);
$failed = false;
if (!is_array($field)) {
$field = array($field);
}
// if there is no Zend_Validate_NotEmpty instance in the rules, we will use the default
if (!($notEmptyValidator = $this->_getNotEmptyValidatorInstance($validatorRule))) {
$notEmptyValidator = $this->_getValidator('NotEmpty');
$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE], $fieldName));
}
if ($validatorRule[self::ALLOW_EMPTY]) {
$validatorChain = $validatorRule[self::VALIDATOR_CHAIN];
} else {
//.........这里部分代码省略.........
示例5: _validateFile
/**
* Validate file
*
* @throws Mage_Core_Exception
* @param array $optionValue
* @return Mage_Catalog_Model_Product_Option_Type_Default
*/
protected function _validateFile($optionValue)
{
$option = $this->getOption();
/**
* @see Mage_Catalog_Model_Product_Option_Type_File::_validateUploadFile()
* There setUserValue() sets correct fileFullPath only for
* quote_path. So we must form both full paths manually and
* check them.
*/
$checkPaths = array();
if (isset($optionValue['quote_path'])) {
$checkPaths[] = Mage::getBaseDir() . $optionValue['quote_path'];
}
if (isset($optionValue['order_path']) && !$this->getUseQuotePath()) {
$checkPaths[] = Mage::getBaseDir() . $optionValue['order_path'];
}
$fileFullPath = null;
foreach ($checkPaths as $path) {
if (!$this->_filesystem->isFile($path)) {
if (!Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFileToFilesystem($fileFullPath)) {
continue;
}
}
$fileFullPath = $path;
break;
}
if ($fileFullPath === null) {
return false;
}
$validatorChain = new Zend_Validate();
$_dimentions = array();
if ($option->getImageSizeX() > 0) {
$_dimentions['maxwidth'] = $option->getImageSizeX();
}
if ($option->getImageSizeY() > 0) {
$_dimentions['maxheight'] = $option->getImageSizeY();
}
if (count($_dimentions) > 0 && !$this->_isImage($fileFullPath)) {
return false;
}
if (count($_dimentions) > 0) {
$validatorChain->addValidator(new Zend_Validate_File_ImageSize($_dimentions));
}
// File extension
$_allowed = $this->_parseExtensionsString($option->getFileExtension());
if ($_allowed !== null) {
$validatorChain->addValidator(new Zend_Validate_File_Extension($_allowed));
} else {
$_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
if ($_forbidden !== null) {
$validatorChain->addValidator(new Zend_Validate_File_ExcludeExtension($_forbidden));
}
}
// Maximum file size
$maxFileSize = $this->getFileSizeService()->getMaxFileSize();
$validatorChain->addValidator(new Zend_Validate_File_FilesSize(array('max' => $maxFileSize)));
if ($validatorChain->isValid($fileFullPath)) {
$ok = $this->_filesystem->isReadable($fileFullPath) && isset($optionValue['secret_key']) && substr(md5($this->_filesystem->read($fileFullPath)), 0, 20) == $optionValue['secret_key'];
return $ok;
} elseif ($validatorChain->getErrors()) {
$errors = $this->_getValidatorErrors($validatorChain->getErrors(), $optionValue);
if (count($errors) > 0) {
$this->setIsValid(false);
Mage::throwException(implode("\n", $errors));
}
} else {
$this->setIsValid(false);
Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Please specify the product required option(s)'));
}
}