collectDecode example

public function decode(string $data, string $format, array $context = []): mixed
    {
        $context[self::DEBUG_TRACE_ID] = $traceId = uniqid();

        $startTime = microtime(true);
        $result = $this->serializer->decode($data$format$context);
        $time = microtime(true) - $startTime;

        $caller = $this->getCaller(__FUNCTION__, DecoderInterface::class);

        $this->dataCollector->collectDecode($traceId$data$format$context$time$caller);

        return $result;
    }

    public function getSupportedTypes(?string $format): array
    {
        // @deprecated remove condition in 7.0         if (!method_exists($this->serializer, 'getSupportedTypes')) {
            return ['*' => $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod()];
        }

        
'encoding' => [],
            'caller' => $caller,
        ]]$collectedData['denormalize']);
    }

    public function testCollectEncode()
    {
        $dataCollector = new SerializerDataCollector();

        $caller = ['name' => 'Foo.php', 'file' => 'src/Foo.php', 'line' => 123];
        $dataCollector->collectEncode('traceIdOne', 'data', 'format', ['foo' => 'bar'], 1.0, $caller);
        $dataCollector->collectDecode('traceIdTwo', 'data', 'format', ['foo' => 'bar'], 1.0, $caller);

        $dataCollector->lateCollect();
        $collectedData = $this->castCollectedData($dataCollector->getData());

        $this->assertSame([[
            'data' => 'data',
            'dataType' => 'string',
            'type' => null,
            'format' => 'format',
            'time' => 1.0,
            'context' => ['foo' => 'bar'],
            
public function decode(string $data, string $format, array $context = []): mixed
    {
        $context[self::DEBUG_TRACE_ID] = $traceId = uniqid();

        $startTime = microtime(true);
        $result = $this->serializer->decode($data$format$context);
        $time = microtime(true) - $startTime;

        $caller = $this->getCaller(__FUNCTION__, DecoderInterface::class);

        $this->dataCollector->collectDecode($traceId$data$format$context$time$caller);

        return $result;
    }

    public function getSupportedTypes(?string $format): array
    {
        // @deprecated remove condition in 7.0         if (!method_exists($this->serializer, 'getSupportedTypes')) {
            return ['*' => $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod()];
        }

        
Home | Imprint | This part of the site doesn't use cookies.