Encodes JSON data
@author Jordi Boggiano <j.boggiano@seld.be>
Expanded class hierarchy of JsonEncoder
class JsonEncoder implements EncoderInterface, DecoderInterface {
const FORMAT = 'json';
/**
* @var JsonEncode
*/
protected $encodingImpl;
/**
* @var JsonDecode
*/
protected $decodingImpl;
public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodingImpl = null) {
$this->encodingImpl = null === $encodingImpl ? new JsonEncode() : $encodingImpl;
$this->decodingImpl = null === $decodingImpl ? new JsonDecode(true) : $decodingImpl;
}
/**
* Returns the last encoding error (if any)
*
* @return integer
*/
public function getLastEncodingError() {
return $this->encodingImpl
->getLastError();
}
/**
* Returns the last decoding error (if any)
*
* @return integer
*/
public function getLastDecodingError() {
return $this->decodingImpl
->getLastError();
}
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array()) {
return $this->encodingImpl
->encode($data, self::FORMAT, $context);
}
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = array()) {
return $this->decodingImpl
->decode($data, self::FORMAT, $context);
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
return self::FORMAT === $format;
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format) {
return self::FORMAT === $format;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonEncoder:: |
protected | property | ||
JsonEncoder:: |
protected | property | ||
JsonEncoder:: |
public | function |
Decodes a string into PHP data. Overrides DecoderInterface:: |
|
JsonEncoder:: |
public | function |
Encodes data into the given format Overrides EncoderInterface:: |
|
JsonEncoder:: |
constant | |||
JsonEncoder:: |
public | function | Returns the last decoding error (if any) | |
JsonEncoder:: |
public | function | Returns the last encoding error (if any) | |
JsonEncoder:: |
public | function |
Checks whether the deserializer can decode from given format. Overrides DecoderInterface:: |
1 |
JsonEncoder:: |
public | function |
Checks whether the serializer can encode to given format Overrides EncoderInterface:: |
2 |
JsonEncoder:: |
public | function |