Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Encoder/JsonDecode.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\Serializer\Encoder; | 12 namespace Symfony\Component\Serializer\Encoder; |
13 | 13 |
14 use Symfony\Component\Serializer\Exception\UnexpectedValueException; | 14 use Symfony\Component\Serializer\Exception\NotEncodableValueException; |
15 | 15 |
16 /** | 16 /** |
17 * Decodes JSON data. | 17 * Decodes JSON data. |
18 * | 18 * |
19 * @author Sander Coolen <sander@jibber.nl> | 19 * @author Sander Coolen <sander@jibber.nl> |
20 */ | 20 */ |
21 class JsonDecode implements DecoderInterface | 21 class JsonDecode implements DecoderInterface |
22 { | 22 { |
23 /** | 23 protected $serializer; |
24 * Specifies if the returned result should be an associative array or a nested stdClass object hierarchy. | 24 |
25 * | |
26 * @var bool | |
27 */ | |
28 private $associative; | 25 private $associative; |
29 | |
30 /** | |
31 * Specifies the recursion depth. | |
32 * | |
33 * @var int | |
34 */ | |
35 private $recursionDepth; | 26 private $recursionDepth; |
36 | |
37 private $lastError = JSON_ERROR_NONE; | |
38 | |
39 protected $serializer; | |
40 | 27 |
41 /** | 28 /** |
42 * Constructs a new JsonDecode instance. | 29 * Constructs a new JsonDecode instance. |
43 * | 30 * |
44 * @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy | 31 * @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy |
71 * json_decode_options: integer | 58 * json_decode_options: integer |
72 * Specifies additional options as per documentation for json_decode. Only supported with PHP 5.4.0 and higher | 59 * Specifies additional options as per documentation for json_decode. Only supported with PHP 5.4.0 and higher |
73 * | 60 * |
74 * @return mixed | 61 * @return mixed |
75 * | 62 * |
76 * @throws UnexpectedValueException | 63 * @throws NotEncodableValueException |
77 * | 64 * |
78 * @see http://php.net/json_decode json_decode | 65 * @see http://php.net/json_decode json_decode |
79 */ | 66 */ |
80 public function decode($data, $format, array $context = array()) | 67 public function decode($data, $format, array $context = array()) |
81 { | 68 { |
85 $recursionDepth = $context['json_decode_recursion_depth']; | 72 $recursionDepth = $context['json_decode_recursion_depth']; |
86 $options = $context['json_decode_options']; | 73 $options = $context['json_decode_options']; |
87 | 74 |
88 $decodedData = json_decode($data, $associative, $recursionDepth, $options); | 75 $decodedData = json_decode($data, $associative, $recursionDepth, $options); |
89 | 76 |
90 if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) { | 77 if (JSON_ERROR_NONE !== json_last_error()) { |
91 throw new UnexpectedValueException(json_last_error_msg()); | 78 throw new NotEncodableValueException(json_last_error_msg()); |
92 } | 79 } |
93 | 80 |
94 return $decodedData; | 81 return $decodedData; |
95 } | 82 } |
96 | 83 |
103 } | 90 } |
104 | 91 |
105 /** | 92 /** |
106 * Merges the default options of the Json Decoder with the passed context. | 93 * Merges the default options of the Json Decoder with the passed context. |
107 * | 94 * |
108 * @param array $context | |
109 * | |
110 * @return array | 95 * @return array |
111 */ | 96 */ |
112 private function resolveContext(array $context) | 97 private function resolveContext(array $context) |
113 { | 98 { |
114 $defaultOptions = array( | 99 $defaultOptions = array( |