Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Input/Handler/Json.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Common\Input\Handler;
8
9 use eZ\Publish\Core\REST\Common\Input\Handler;
10 use eZ\Publish\Core\REST\Common\Exceptions\Parser as ParserException;
11
15 class Json extends Handler
16 {
26 public function convert($string)
27 {
28 $json = json_decode($string, true);
29 if (JSON_ERROR_NONE !== ($jsonErrorCode = json_last_error())) {
30 $message = "An error occured while decoding the JSON input:\n";
31 $message .= $this->jsonDecodeErrorMessage($jsonErrorCode);
32 $message .= "\nInput JSON:\n\n" . $string;
33 throw new ParserException($message);
34 }
35
36 return $json;
37 }
38
46 private function jsonDecodeErrorMessage($jsonErrorCode)
47 {
48 if (function_exists('json_last_error_msg')) {
49 return json_last_error_msg();
50 }
51 switch ($jsonErrorCode) {
52 case JSON_ERROR_DEPTH:
53 return 'Maximum stack depth exceeded';
54 case JSON_ERROR_STATE_MISMATCH:
55 return 'Underflow or the modes mismatch';
56 case JSON_ERROR_CTRL_CHAR:
57 return 'Unexpected control character found';
58 case JSON_ERROR_SYNTAX:
59 return 'Syntax error, malformed JSON';
60 case JSON_ERROR_UTF8:
61 return 'Malformed UTF-8 characters, possibly incorrectly encoded';
62 }
63
64 return 'Unknown JSON decode error';
65 }
66 }
eZ\Publish\Core\REST\Common\Exceptions\Parser
Exception thrown if a parser discovers an error.
Definition: REST/Common/Exceptions/Parser.php:15
eZ\Publish\Core\REST\Common\Input\Handler\Json
Input format handler base class.
Definition: Input/Handler/Json.php:16
eZ\Publish\Core\REST\Common\Input\Handler\Json\jsonDecodeErrorMessage
jsonDecodeErrorMessage($jsonErrorCode)
Returns the error message associated with the $jsonErrorCode.
Definition: Input/Handler/Json.php:46
eZ\Publish\Core\REST\Common\Input\Handler\Json\convert
convert($string)
Converts the given string to an array structure.
Definition: Input/Handler/Json.php:26
eZ\Publish\Core\REST\Common\Input\Handler
Input format handler base class.
Definition: Core/REST/Common/Input/Handler.php:13
eZ\Publish\Core\REST\Common\Input\Handler
Definition: Input/Handler/Json.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.