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

Breadcrumb

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

class CompiledClassMetadataFactory

@author Fabien Bourigault <bourigaultfabien@gmail.com>

Hierarchy

  • class \Symfony\Component\Serializer\Mapping\Factory\CompiledClassMetadataFactory implements \Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface

Expanded class hierarchy of CompiledClassMetadataFactory

File

vendor/symfony/serializer/Mapping/Factory/CompiledClassMetadataFactory.php, line 22

Namespace

Symfony\Component\Serializer\Mapping\Factory
View source
final class CompiledClassMetadataFactory implements ClassMetadataFactoryInterface {
    private array $compiledClassMetadata = [];
    private array $loadedClasses = [];
    public function __construct(string $compiledClassMetadataFile, ClassMetadataFactoryInterface $classMetadataFactory) {
        if (!file_exists($compiledClassMetadataFile)) {
            throw new \RuntimeException("File \"{$compiledClassMetadataFile}\" could not be found.");
        }
        $compiledClassMetadata = (require $compiledClassMetadataFile);
        if (!\is_array($compiledClassMetadata)) {
            throw new \RuntimeException(\sprintf('Compiled metadata must be of the type array, %s given.', \gettype($compiledClassMetadata)));
        }
        $this->compiledClassMetadata = $compiledClassMetadata;
    }
    public function getMetadataFor(string|object $value) : ClassMetadataInterface {
        $className = \is_object($value) ? $value::class : $value;
        if (!isset($this->compiledClassMetadata[$className])) {
            return $this->classMetadataFactory
                ->getMetadataFor($value);
        }
        if (!isset($this->loadedClasses[$className])) {
            $classMetadata = new ClassMetadata($className);
            foreach ($this->compiledClassMetadata[$className][0] as $name => $compiledAttributesMetadata) {
                $classMetadata->attributesMetadata[$name] = $attributeMetadata = new AttributeMetadata($name);
                [
                    $attributeMetadata->groups,
                    $attributeMetadata->maxDepth,
                    $attributeMetadata->serializedName,
                ] = $compiledAttributesMetadata;
            }
            $classMetadata->classDiscriminatorMapping = $this->compiledClassMetadata[$className][1] ? new ClassDiscriminatorMapping(...$this->compiledClassMetadata[$className][1]) : null;
            $this->loadedClasses[$className] = $classMetadata;
        }
        return $this->loadedClasses[$className];
    }
    public function hasMetadataFor(mixed $value) : bool {
        $className = \is_object($value) ? $value::class : $value;
        return isset($this->compiledClassMetadata[$className]) || $this->classMetadataFactory
            ->hasMetadataFor($value);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CompiledClassMetadataFactory::$compiledClassMetadata private property
CompiledClassMetadataFactory::$loadedClasses private property
CompiledClassMetadataFactory::getMetadataFor public function If the method was called with the same class name (or an object of that
class) before, the same metadata instance is returned.
Overrides ClassMetadataFactoryInterface::getMetadataFor
CompiledClassMetadataFactory::hasMetadataFor public function Checks if class has metadata. Overrides ClassMetadataFactoryInterface::hasMetadataFor
CompiledClassMetadataFactory::__construct public function
RSS feed
Powered by Drupal