getBaseEncoder example


  public function setBaseEncoder($encoder) {
    $this->baseEncoder = $encoder;
  }

  /** * {@inheritdoc} */
  public function encode($data$format, array $context = []): string {
    return $this->getBaseEncoder()->encode($data$format$context);
  }

  /** * {@inheritdoc} */
  public function supportsEncoding(string $format, array $context = []): bool {
    return in_array($formatstatic::$format);
  }

  /** * {@inheritdoc} */


  /** * @covers ::getBaseEncoder */
  public function testDefaultEncoderHasSerializer() {
    // The serializer should be set on the Drupal encoder, which should then     // set it on our default encoder.     $encoder = new XmlEncoder();
    $serializer = new Serializer([new GetSetMethodNormalizer()]);
    $encoder->setSerializer($serializer);
    $base_encoder = $encoder->getBaseEncoder();
    $this->assertInstanceOf(BaseXmlEncoder::class$base_encoder);
    // Test the encoder.     $base_encoder->encode(['a' => new TestObject()], 'xml');
  }

}

class TestObject {

  public function getA() {
    return 'A';
  }
Home | Imprint | This part of the site doesn't use cookies.