Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TraceableEncoder.php

function TraceableEncoder::encode

Overrides EncoderInterface::encode

File

vendor/symfony/serializer/Debug/TraceableEncoder.php, line 37

Class

TraceableEncoder
Collects some data about encoding.

Namespace

Symfony\Component\Serializer\Debug

Code

public function encode(mixed $data, string $format, array $context = []) : string {
    if (!$this->encoder instanceof EncoderInterface) {
        throw new \BadMethodCallException(\sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, EncoderInterface::class));
    }
    $startTime = microtime(true);
    $encoded = $this->encoder
        ->encode($data, $format, $context);
    $time = microtime(true) - $startTime;
    if ($traceId = $context[TraceableSerializer::DEBUG_TRACE_ID] ?? null) {
        $this->dataCollector
            ->collectEncoding($traceId, $this->encoder::class, $time, $this->serializerName);
    }
    return $encoded;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal