comparison vendor/symfony/http-foundation/JsonResponse.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
143 // HHVM does not trigger any warnings and let exceptions 143 // HHVM does not trigger any warnings and let exceptions
144 // thrown from a JsonSerializable object pass through. 144 // thrown from a JsonSerializable object pass through.
145 // If only PHP did the same... 145 // If only PHP did the same...
146 $data = json_encode($data, $this->encodingOptions); 146 $data = json_encode($data, $this->encodingOptions);
147 } else { 147 } else {
148 try { 148 if (!interface_exists('JsonSerializable', false)) {
149 // PHP 5.4 and up wrap exceptions thrown by JsonSerializable 149 set_error_handler(function () { return false; });
150 // objects in a new exception that needs to be removed. 150 try {
151 // Fortunately, PHP 5.5 and up do not trigger any warning anymore. 151 $data = @json_encode($data, $this->encodingOptions);
152 $data = json_encode($data, $this->encodingOptions); 152 } finally {
153 } catch (\Exception $e) { 153 restore_error_handler();
154 if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
155 throw $e->getPrevious() ?: $e;
156 } 154 }
157 throw $e; 155 } else {
156 try {
157 $data = json_encode($data, $this->encodingOptions);
158 } catch (\Exception $e) {
159 if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
160 throw $e->getPrevious() ?: $e;
161 }
162 throw $e;
163 }
158 } 164 }
159 } 165 }
160 166
161 if (JSON_ERROR_NONE !== json_last_error()) { 167 if (JSON_ERROR_NONE !== json_last_error()) {
162 throw new \InvalidArgumentException(json_last_error_msg()); 168 throw new \InvalidArgumentException(json_last_error_msg());