class JsonEncoder

Encodes JSON data

@author Jordi Boggiano <j.boggiano@seld.be>

Hierarchy

Expanded class hierarchy of JsonEncoder

4 files declare their use of JsonEncoder
JsonEncoder.php in drupal/core/modules/serialization/lib/Drupal/serialization/Encoder/JsonEncoder.php
Contains \Drupal\serialization\Encoder\JsonEncoder.
JsonEncoder.php in drupal/core/modules/hal/lib/Drupal/hal/Encoder/JsonEncoder.php
Contains \Drupal\hal\JsonEncoder.
JsonEncoderTest.php in drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php
SerializerTest.php in drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Tests/SerializerTest.php

File

drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Encoder/JsonEncoder.php, line 19

Namespace

Symfony\Component\Serializer\Encoder
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsonEncoder::$decodingImpl protected property
JsonEncoder::$encodingImpl protected property
JsonEncoder::decode public function Decodes a string into PHP data. Overrides DecoderInterface::decode
JsonEncoder::encode public function Encodes data into the given format Overrides EncoderInterface::encode
JsonEncoder::FORMAT constant
JsonEncoder::getLastDecodingError public function Returns the last decoding error (if any)
JsonEncoder::getLastEncodingError public function Returns the last encoding error (if any)
JsonEncoder::supportsDecoding public function Checks whether the deserializer can decode from given format. Overrides DecoderInterface::supportsDecoding 1
JsonEncoder::supportsEncoding public function Checks whether the serializer can encode to given format Overrides EncoderInterface::supportsEncoding 2
JsonEncoder::__construct public function