JsonEncode.php in Zircon Profile 8
File
vendor/symfony/serializer/Encoder/JsonEncode.php
View source
<?php
namespace Symfony\Component\Serializer\Encoder;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
class JsonEncode implements EncoderInterface {
private $options;
private $lastError = JSON_ERROR_NONE;
public function __construct($bitmask = 0) {
$this->options = $bitmask;
}
public function getLastError() {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.5 and will be removed in 3.0. Catch the exception raised by the encode() method instead to get the last JSON encoding error.', E_USER_DEPRECATED);
return $this->lastError;
}
public function encode($data, $format, array $context = array()) {
$context = $this
->resolveContext($context);
$encodedJson = json_encode($data, $context['json_encode_options']);
if (JSON_ERROR_NONE !== ($this->lastError = json_last_error())) {
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
}
return $encodedJson;
}
public function supportsEncoding($format) {
return JsonEncoder::FORMAT === $format;
}
private function resolveContext(array $context = array()) {
return array_merge(array(
'json_encode_options' => $this->options,
), $context);
}
}