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\DebugCode
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;
}