From b9851a2c698209d18d1b4cd978b11fda5df00d5a Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Fri, 1 Mar 2019 11:39:19 +0100 Subject: [PATCH] Fix JSON --- ValidatorBundle/Validator.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ValidatorBundle/Validator.php b/ValidatorBundle/Validator.php index b22a031..b7f4ffc 100644 --- a/ValidatorBundle/Validator.php +++ b/ValidatorBundle/Validator.php @@ -82,12 +82,19 @@ class Validator public function json($code = 400, $data = []) { + $errors = []; + + foreach ($this->errors as $field => $error) + { + $errors[$field] = [ + 'error' => "validator.".$errors[0].(!is_null($this->context) ? ':'.$this->context : '') + ]; + } + $data = array_merge([ 'message' => 'Please check your input', 'error' => 'validator.form-error', - 'errors' => array_map(function ($errors) { - return "validator.".$errors[0].(!is_null($this->context) ? ':'.$this->context : ''); - }, $this->errors) + 'errors' => $errors ], $data); return new JsonResponse($data, $code);