Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Serializer\Encoder; Chris@0: Chris@0: /** Chris@0: * Encodes JSON data. Chris@0: * Chris@0: * @author Jordi Boggiano Chris@0: */ Chris@0: class JsonEncoder implements EncoderInterface, DecoderInterface Chris@0: { Chris@0: const FORMAT = 'json'; Chris@0: Chris@0: protected $encodingImpl; Chris@0: protected $decodingImpl; Chris@0: Chris@0: public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodingImpl = null) Chris@0: { Chris@0: $this->encodingImpl = $encodingImpl ?: new JsonEncode(); Chris@0: $this->decodingImpl = $decodingImpl ?: new JsonDecode(true); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@17: public function encode($data, $format, array $context = []) Chris@0: { Chris@0: return $this->encodingImpl->encode($data, self::FORMAT, $context); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@17: public function decode($data, $format, array $context = []) Chris@0: { Chris@0: return $this->decodingImpl->decode($data, self::FORMAT, $context); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supportsEncoding($format) Chris@0: { Chris@0: return self::FORMAT === $format; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supportsDecoding($format) Chris@0: { Chris@0: return self::FORMAT === $format; Chris@0: } Chris@0: }