getClassDiscriminatorMapping example


    private array $mappingForMappedObjectCache = [];

    public function __construct(
        private readonly ClassMetadataFactoryInterface $classMetadataFactory,
    ) {
    }

    public function getMappingForClass(string $class): ?ClassDiscriminatorMapping
    {
        if ($this->classMetadataFactory->hasMetadataFor($class)) {
            return $this->classMetadataFactory->getMetadataFor($class)->getClassDiscriminatorMapping();
        }

        return null;
    }

    public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping
    {
        if ($this->classMetadataFactory->hasMetadataFor($object)) {
            $metadata = $this->classMetadataFactory->getMetadataFor($object);

            if (null !== $metadata->getClassDiscriminatorMapping()) {
                
foreach ($classMetadatas as $classMetadata) {
            $attributesMetadata = [];
            foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
                $attributesMetadata[$attributeMetadata->getName()] = [
                    $attributeMetadata->getGroups(),
                    $attributeMetadata->getMaxDepth(),
                    $attributeMetadata->getSerializedName(),
                    $attributeMetadata->getSerializedPath(),
                ];
            }

            $classDiscriminatorMapping = $classMetadata->getClassDiscriminatorMapping() ? [
                $classMetadata->getClassDiscriminatorMapping()->getTypeProperty(),
                $classMetadata->getClassDiscriminatorMapping()->getTypesMapping(),
            ] : null;

            $compiled .= sprintf("\n'%s' => %s,", $classMetadata->getName(), VarExporter::export([
                $attributesMetadata,
                $classDiscriminatorMapping,
            ]));
        }

        return $compiled;
    }
foreach ($classMetadatas as $classMetadata) {
            $attributesMetadata = [];
            foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
                $attributesMetadata[$attributeMetadata->getName()] = [
                    $attributeMetadata->getGroups(),
                    $attributeMetadata->getMaxDepth(),
                    $attributeMetadata->getSerializedName(),
                    $attributeMetadata->getSerializedPath(),
                ];
            }

            $classDiscriminatorMapping = $classMetadata->getClassDiscriminatorMapping() ? [
                $classMetadata->getClassDiscriminatorMapping()->getTypeProperty(),
                $classMetadata->getClassDiscriminatorMapping()->getTypesMapping(),
            ] : null;

            $compiled .= sprintf("\n'%s' => %s,", $classMetadata->getName(), VarExporter::export([
                $attributesMetadata,
                $classDiscriminatorMapping,
            ]));
        }

        return $compiled;
    }

    private array $mappingForMappedObjectCache = [];

    public function __construct(
        private readonly ClassMetadataFactoryInterface $classMetadataFactory,
    ) {
    }

    public function getMappingForClass(string $class): ?ClassDiscriminatorMapping
    {
        if ($this->classMetadataFactory->hasMetadataFor($class)) {
            return $this->classMetadataFactory->getMetadataFor($class)->getClassDiscriminatorMapping();
        }

        return null;
    }

    public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping
    {
        if ($this->classMetadataFactory->hasMetadataFor($object)) {
            $metadata = $this->classMetadataFactory->getMetadataFor($object);

            if (null !== $metadata->getClassDiscriminatorMapping()) {
                
Home | Imprint | This part of the site doesn't use cookies.