class JsonEncode

Encodes JSON data

@author Sander Coolen <sander@jibber.nl>

Hierarchy

Expanded class hierarchy of JsonEncode

File

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

Namespace

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

}

Members

Namesort descending Modifiers Type Description Overrides
JsonEncode::$lastError private property
JsonEncode::$options private property
JsonEncode::encode public function Encodes PHP data to a JSON string Overrides EncoderInterface::encode
JsonEncode::getLastError public function Returns the last encoding error (if any)
JsonEncode::supportsEncoding public function Checks whether the serializer can encode to given format Overrides EncoderInterface::supportsEncoding
JsonEncode::__construct public function