Encodes JSON data
@author Sander Coolen <sander@jibber.nl>
Expanded class hierarchy of JsonEncode
class JsonEncode implements EncoderInterface {
private $options;
private $lastError = JSON_ERROR_NONE;
public function __construct($bitmask = 0) {
$this->options = $bitmask;
}
/**
* Returns the last encoding error (if any)
*
* @return integer
*
* @see http://php.net/manual/en/function.json-last-error.php json_last_error
*/
public function getLastError() {
return $this->lastError;
}
/**
* Encodes PHP data to a JSON string
*
* @param mixed $data
*
* @return string
*/
public function encode($data, $format) {
$encodedJson = json_encode($data, $this->options);
$this->lastError = json_last_error();
return $encodedJson;
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
return JsonEncoder::FORMAT === $format;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonEncode:: |
private | property | ||
JsonEncode:: |
private | property | ||
JsonEncode:: |
public | function |
Encodes PHP data to a JSON string Overrides EncoderInterface:: |
|
JsonEncode:: |
public | function | Returns the last encoding error (if any) | |
JsonEncode:: |
public | function |
Checks whether the serializer can encode to given format Overrides EncoderInterface:: |
|
JsonEncode:: |
public | function |