getSupportedTypes example

if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
                        $this->normalizerCache[$format][$type][$k] = false;
                    } elseif ($normalizer->supportsNormalization($data$format$context)) {
                        $this->normalizerCache[$format][$type][$k] = true;
                        break;
                    }

                    continue;
                }

                $supportedTypes = $normalizer->getSupportedTypes($format);

                foreach ($supportedTypes as $supportedType => $isCacheable) {
                    if (\in_array($supportedType['*', 'object'], true)
                        || $type !== $supportedType && ('object' !== $genericType || !is_subclass_of($type$supportedType))
                    ) {
                        continue;
                    }

                    if (null === $isCacheable) {
                        unset($supportedTypes['*']$supportedTypes['object']);
                    } elseif ($this->normalizerCache[$format][$type][$k] = $isCacheable && $normalizer->supportsNormalization($data$format$context)) {
                        
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()];
        }

        return $this->serializer->getSupportedTypes($format);
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        return $this->serializer->supportsNormalization($data$format$context);
    }

    public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
    {
        return $this->serializer->supportsDenormalization($data$type$format$context);
    }

    
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($normalizer));
        }
    }

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

        return $this->normalizer->getSupportedTypes($format);
    }

    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;

        
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($normalizer));
        }
    }

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

        return $this->normalizer->getSupportedTypes($format);
    }

    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;

        
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()];
        }

        return $this->serializer->getSupportedTypes($format);
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        return $this->serializer->supportsNormalization($data$format$context);
    }

    public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
    {
        return $this->serializer->supportsDenormalization($data$type$format$context);
    }

    
if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
                        $this->normalizerCache[$format][$type][$k] = false;
                    } elseif ($normalizer->supportsNormalization($data$format$context)) {
                        $this->normalizerCache[$format][$type][$k] = true;
                        break;
                    }

                    continue;
                }

                $supportedTypes = $normalizer->getSupportedTypes($format);

                foreach ($supportedTypes as $supportedType => $isCacheable) {
                    if (\in_array($supportedType['*', 'object'], true)
                        || $type !== $supportedType && ('object' !== $genericType || !is_subclass_of($type$supportedType))
                    ) {
                        continue;
                    }

                    if (null === $isCacheable) {
                        unset($supportedTypes['*']$supportedTypes['object']);
                    } elseif ($this->normalizerCache[$format][$type][$k] = $isCacheable && $normalizer->supportsNormalization($data$format$context)) {
                        
public function supportsNormalization($data, string $format = NULL, array $context = []): bool {
    // If we aren't dealing with an object or the format is not supported return     // now.     if (!is_object($data) || !$this->checkFormat($format)) {
      return FALSE;
    }

    if (property_exists($this, 'supportedInterfaceOrClass')) {
      $supported = (array) $this->supportedInterfaceOrClass;
    }
    else {
      $supported = array_keys($this->getSupportedTypes($format));
    }

    return (bool) array_filter($supportedfunction D$name) use ($data) {
      return $data instanceof $name;
    });
  }

  /** * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() * * This class doesn't implement DenormalizerInterface, but most of its child * classes do. Therefore, this method is implemented at this level to reduce * code duplication. */
$type = substr($type, 0, -2);

        foreach ($data as $key => $value) {
            $data[$key] = $serializer->denormalize($value$type$format$context);
        }

        return $data;
    }

    public function getSupportedTypes(?string $format): array
    {
        return $this->serializer->getSupportedTypes($format);
    }

    public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
    {
        return str_ends_with($type, '[]')
            && $this->serializer->supportsDenormalization($datasubstr($type, 0, -2)$format$context);
    }

    public function setSerializer(SerializerInterface $serializer): void
    {
        \assert($serializer instanceof DenormalizerInterface);
        
Home | Imprint | This part of the site doesn't use cookies.