collectNormalization example

 $collectedData['decode']);
    }

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

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

        $dataCollector->collectNormalization('traceIdOne', DateTimeNormalizer::class, 1.0);
        $dataCollector->collectNormalization('traceIdOne', DateTimeNormalizer::class, 2.0);
        $dataCollector->collectNormalization('traceIdOne', ObjectNormalizer::class, 5.0);
        $dataCollector->collectNormalization('traceIdOne', ObjectNormalizer::class, 10.0);

        $dataCollector->collectNormalization('traceIdTwo', DateTimeNormalizer::class, 1.0);
        $dataCollector->collectNormalization('traceIdTwo', DateTimeNormalizer::class, 2.0);
        $dataCollector->collectNormalization('traceIdTwo', ObjectNormalizer::class, 5.0);
        $dataCollector->collectNormalization('traceIdTwo', ObjectNormalizer::class, 10.0);

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

        
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        if (!$this->normalizer instanceof NormalizerInterface) {
            throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
        }

        $startTime = microtime(true);
        $normalized = $this->normalizer->normalize($object$format$context);
        $time = microtime(true) - $startTime;

        if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) {
            $this->dataCollector->collectNormalization($traceId$this->normalizer::class$time);
        }

        return $normalized;
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        if (!$this->normalizer instanceof NormalizerInterface) {
            return false;
        }

        
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        if (!$this->normalizer instanceof NormalizerInterface) {
            throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
        }

        $startTime = microtime(true);
        $normalized = $this->normalizer->normalize($object$format$context);
        $time = microtime(true) - $startTime;

        if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) {
            $this->dataCollector->collectNormalization($traceId$this->normalizer::class$time);
        }

        return $normalized;
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        if (!$this->normalizer instanceof NormalizerInterface) {
            return false;
        }

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