Example #1
0
 public function validationList(\Psc\Form\ValidatorExceptionList $list)
 {
     foreach ($list->getExceptions() as $validatorException) {
         $this->validationError($validatorException);
     }
     return $this;
 }
Example #2
0
 /**
  * Throws an ValidationResponse
  *
  * it handles the JSON case and the HTML case
  * @param ValidatorException[]
  * @param const $format im moment nur JSON oder HTML
  * @return HTTPException
  */
 public function validationResponse(\Psc\Form\ValidatorExceptionList $list, $format = ServiceResponse::JSON, MetadataGenerator $metadataGenerator = NULL)
 {
     if ($format === ServiceResponse::JSON) {
         $body = (object) array('errors' => array());
         foreach ($list->getExceptions() as $validatorException) {
             $body->errors[$validatorException->field] = $validatorException->getMessage();
         }
         return HTTPResponseException::BadRequest(json_encode($body), NULL, array('Content-Type' => 'application/json'));
     } else {
         $metadataGenerator = $metadataGenerator ?: new MetadataGenerator();
         return HTTPException::BadRequest($list->getMessage(), $list, array_merge(array('Content-Type' => 'text/html'), $metadataGenerator->validationList($list)->toHeaders()));
     }
 }