当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception::getValidationErrors方法代码示例

本文整理汇总了PHP中Exception::getValidationErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getValidationErrors方法的具体用法?PHP Exception::getValidationErrors怎么用?PHP Exception::getValidationErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getValidationErrors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _mapException

 protected function _mapException(\Exception $e, $map = null, $useKey = false)
 {
     if ($e instanceof ValidateException) {
         $errors = $e->getValidationErrors();
         if (!$map) {
             $map = $this->_mapModelToSdp;
         }
         $message = $this->_mapExceptionMessage($e, $map);
         foreach ($errors as $attr => $err) {
             if ($useKey) {
                 $new = current(array_keys($map, $attr));
             } else {
                 if (isset($map[$attr])) {
                     // Map validation error
                     $new = $map[$attr];
                 }
             }
             if (isset($new)) {
                 $errors[$new] = $err;
                 unset($errors[$attr]);
                 unset($new);
             }
         }
         return new ValidateException($message, array('validationErrors' => $errors, 'entity' => $e->getEntity()));
     }
     return $e;
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:27,代码来源:Api.php

示例2: validation

 /**
  * Renders validation errors and sends a 422 error code
  *
  * @param \Exception $error Exception instance
  * @return \Cake\Network\Response
  */
 public function validation($error)
 {
     $url = $this->controller->request->here();
     $status = $code = $error->getCode();
     try {
         $this->controller->response->statusCode($status);
     } catch (Exception $e) {
         $status = 422;
         $this->controller->response->statusCode($status);
     }
     $sets = ['code' => $code, 'url' => h($url), 'message' => $error->getMessage(), 'error' => $error, 'errorCount' => $error->getValidationErrorCount(), 'errors' => $error->getValidationErrors(), '_serialize' => ['code', 'url', 'message', 'errorCount', 'errors']];
     $this->controller->set($sets);
     return $this->_outputMessage('error400');
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:20,代码来源:ExceptionRenderer.php

示例3: createError

 public function createError(\Exception $ex)
 {
     if ($ex instanceof \Application\Exceptions\ValidateException) {
         $error = $this->_getFirstError($ex->getValidationErrors(), $field, $message);
         // Error message has a valid UNICA format?
         if ($message && !preg_match('/^Supported values are (.+)/', $message)) {
             $message = '';
         }
     } else {
         $field = '#unknownField#';
         $error = '#unknownError#';
     }
     $errorModel = new ErrorModel(array('fault' => array('code' => FaultModel::FAULT_CODE_CLIENT, 'description' => "Generic Validation fault"), 'code' => 1021, 'category' => ErrorModel::ERROR_CATEGORY_SVC, 'description' => $field ? 'Invalid parameter value: ' . $field . ". " . $message : $ex->getMessage()));
     switch ($error) {
         case \Zend_Validate_StringLength::TOO_SHORT:
         case \Zend_Validate_StringLength::TOO_LONG:
             $errorModel->description = "Invalid '" . $field . "' length." . $message;
             $errorModel->code = 1011;
             break;
         case \Zend_Validate_InArray::NOT_IN_ARRAY:
             switch ($field) {
                 case 'lifeCycleState':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", LifeCycleModel::getStatuses());
                     break;
                 case 'simType':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", array(\Application\Model\SimModel::SIM_TYPE_GLOBAL, \Application\Model\SimModel::SIM_TYPE_LOCAL));
                     break;
                 default:
                     $errorModel->description = "Invalid parameter value: {$field}";
                     break;
             }
             break;
         case 'badPeriod':
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_NotEmptyIfField::IS_EMPTY:
             $errorModel->description = "Needed parameter was not found: {$field}.";
             $errorModel->code = 1020;
             break;
     }
     return $errorModel;
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:42,代码来源:Validation.php

示例4: createError

 public function createError(\Exception $ex)
 {
     if ($ex instanceof ValidateException) {
         $error = $this->_getFirstError($ex->getValidationErrors(), $field, $message);
         // Error message has a valid UNICA format?
         $origMessage = $message;
         if ($message && !preg_match('/^Supported values are (.+)/', $message)) {
             $message = '';
         }
     } else {
         $field = '#unknownField#';
         $error = '#unknownError#';
     }
     $exMessage = preg_replace('/(.*)filter\\s*\'(\\w+)\': (.*)/', '$1parameter value: $2.', $ex->getMessage());
     $errorModel = new ErrorModel(array('fault' => array('code' => FaultModel::FAULT_CODE_CLIENT, 'description' => "Generic Validation fault"), 'code' => 1021, 'category' => ErrorModel::ERROR_CATEGORY_SVC, 'description' => $field ? 'Invalid parameter value: ' . $field . ". " . $message : $exMessage));
     switch ($error) {
         case 'customerId':
             //TODO this validation should throw a NotFoundException instead
             //of a ValidationException this is a very dirty approach to the
             //problem
             if (preg_match("/No\\sorganization\\s'(?P<customerId>[[:ascii:]]+)'\\swas\\sfound/", $origMessage, $matches)) {
                 $message = sprintf("Resource %s does not exist", $matches['customerId']);
                 $errorModel->description = $message;
                 $errorModel->code = 1006;
             }
             break;
             //[Apism2m] SVC 1020 o SVC 1021
             //According mail from apism2m list, change 1020 code to 1021.
             //            case \Zend_Validate_NotEmpty::IS_EMPTY:
             //                $errorModel->description = "Needed parameter not found: '" . $field . "' - " . $message;
             //                $errorModel->code = 1020;
             //                break;
         //[Apism2m] SVC 1020 o SVC 1021
         //According mail from apism2m list, change 1020 code to 1021.
         //            case \Zend_Validate_NotEmpty::IS_EMPTY:
         //                $errorModel->description = "Needed parameter not found: '" . $field . "' - " . $message;
         //                $errorModel->code = 1020;
         //                break;
         case \Zend_Validate_StringLength::TOO_LONG:
             if (preg_match('/is more than (?P<num>\\d+) characters long/', $origMessage, $matches)) {
                 $message = 'Length should be less than ' . $matches['num'] . ' characters';
             }
             $errorModel->description = "Invalid '" . $field . "' length. " . $message;
             $errorModel->code = 1011;
             break;
         case \Zend_Validate_InArray::NOT_IN_ARRAY:
             switch ($field) {
                 case 'lifeCycleState':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", LifeCycleModel::getStatuses());
                     break;
                 case 'simType':
                     $errorModel->description = "Invalid parameter value: {$field}. Supported values are " . implode(",", array(\Application\Model\SimModel::SIM_TYPE_GLOBAL, \Application\Model\SimModel::SIM_TYPE_LOCAL));
                     break;
                 default:
                     $errorModel->description = "Invalid parameter value: {$field}";
                     break;
             }
             break;
         case 'badPeriod':
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_Enum_Currency::CURRENCY:
             $errorModel->description = "Invalid parameter value: {$field}.";
             break;
         case \App_Validate_NotEmptyIfField::IS_EMPTY:
             $errorModel->description = "Needed parameter was not found: {$field}.";
             $errorModel->code = 1020;
             break;
         case \App_Validate_GSM0338Charset::INVALID_CHAR:
             $errorModel->code = 1012;
             break;
     }
     return $errorModel;
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:74,代码来源:Validation.php


注:本文中的Exception::getValidationErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。