SerializationTestEncoder.php

Contains \Drupal\serialization_test\SerializationTestEncoder.

Namespace

Drupal\serialization_test

File

drupal/core/modules/serialization/tests/serialization_test/lib/Drupal/serialization_test/SerializationTestEncoder.php
View source
<?php

/**
 * @file
 * Contains \Drupal\serialization_test\SerializationTestEncoder.
 */
namespace Drupal\serialization_test;

use Symfony\Component\Serializer\Encoder\EncoderInterface;
class SerializationTestEncoder implements EncoderInterface {

  /**
   * The format that this Encoder supports.
   *
   * @var string
   */
  protected static $format = 'serialization_test';

  /**
   * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode().
   */
  public function encode($data, $format, array $context = array()) {

    // @see Drupal\serialization_test\SerializationTestNormalizer::normalize().
    return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder';
  }

  /**
   * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::supportsEncoding().
   */
  public function supportsEncoding($format) {
    return static::$format === $format;
  }

}

Classes