public static function resolveConcreteType(Endpoint $endpoint, PolymorphicDefinitionInterface $definition, $object)
    {
        //if discriminator map is set is used to get the value type
        if ($map = $definition->getDiscriminatorMap()) {
            //get concrete type based on property
            if ($definition->getDiscriminatorProperty()) {
                $property = $definition->getDiscriminatorProperty();
                $accessor = new PropertyAccessor();
                $propValue = $accessor->getValue($object, $property);
                $resolvedType = $map[$propValue] ?? null;
            }

            //get concrete type based on class
            if (!$resolvedType) {
                $class = DoctrineClassUtils::getClass($object);
                $resolvedType = $map[$class] ?? null;
            }
        }

        //final solution in case of not mapping is guess type based on class
        if (!$resolvedType && $definition instanceof InterfaceDefinition) {
            foreach ($definition->getImplementors() as $implementor) {
                $implementorDef = $endpoint->getType($implementor);
                if ($implementorDef instanceof ClassAwareDefinitionInterface
                    && $implementorDef->getClass() === DoctrineClassUtils::getClass($object)) {
                    $resolvedType = $implementorDef->getName();
                }
            }
        }

        if ($endpoint->hasType($resolvedType)) {
            $resolvedTypeDefinition = $endpoint->getType($resolvedType);
            if ($resolvedTypeDefinition instanceof PolymorphicDefinitionInterface) {
                $resolvedType = self::resolveConcreteType($endpoint, $resolvedTypeDefinition, $object);
            }
        }

        return $resolvedType;
    }
public static function resolveConcreteType(Endpoint $endpoint, PolymorphicDefinitionInterface $definition, $object)
    {
        //if discriminator map is set is used to get the value type
        if ($map = $definition->getDiscriminatorMap()) {
            //get concrete type based on property
            if ($definition->getDiscriminatorProperty()) {
                $property = $definition->getDiscriminatorProperty();
                $accessor = new PropertyAccessor();
                $propValue = $accessor->getValue($object, $property);
                $resolvedType = $map[$propValue] ?? null;
            }

            //get concrete type based on class
            if (!$resolvedType) {
                $class = DoctrineClassUtils::getClass($object);
                $resolvedType = $map[$class] ?? null;
            }
        }

        //final solution in case of not mapping is guess type based on class
        if (!$resolvedType && $definition instanceof InterfaceDefinition) {
            foreach ($definition->getImplementors() as $implementor) {
                $implementorDef = $endpoint->getType($implementor);
                if ($implementorDef instanceof ClassAwareDefinitionInterface
                    && $implementorDef->getClass() === DoctrineClassUtils::getClass($object)) {
                    $resolvedType = $implementorDef->getName();
                }
            }
        }

        if ($endpoint->hasType($resolvedType)) {
            $resolvedTypeDefinition = $endpoint->getType($resolvedType);
            if ($resolvedTypeDefinition instanceof PolymorphicDefinitionInterface) {
                $resolvedType = self::resolveConcreteType($endpoint, $resolvedTypeDefinition, $object);
            }
        }

        return $resolvedType;
    }
public static function resolveConcreteType ( Endpoint $ endpoint , PolymorphicDefinitionInterface $ definition , $ object ) { //if discriminator map is set is used to get the value type if ( $ map = $ definition -> getDiscriminatorMap ( ) ) { //get concrete type based on property if ( $ definition -> getDiscriminatorProperty ( ) ) { $ property = $ definition -> getDiscriminatorProperty ( ) ; $ accessor = new PropertyAccessor ( ) ; $ propValue = $ accessor -> getValue ( $ object , $ property ) ; $ resolvedType = $ map [ $ propValue ] ?? null ; } //get concrete type based on class if ( ! $ resolvedType ) { $ class = DoctrineClassUtils :: getClass ( $ object ) ; $ resolvedType = $ map [ $ class ] ?? null ; } } //final solution in case of not mapping is guess type based on class if ( ! $ resolvedType && $ definition instanceof InterfaceDefinition ) { foreach ( $ definition -> getImplementors ( ) as $ implementor ) { $ implementorDef = $ endpoint -> getType ( $ implementor ) ; if ( $ implementorDef instanceof ClassAwareDefinitionInterface && $ implementorDef -> getClass ( ) === DoctrineClassUtils :: getClass ( $ object ) ) { $ resolvedType = $ implementorDef -> getName ( ) ; } } } if ( $ endpoint -> hasType ( $ resolvedType ) ) { $ resolvedTypeDefinition = $ endpoint -> getType ( $ resolvedType ) ; if ( $ resolvedTypeDefinition instanceof PolymorphicDefinitionInterface ) { $ resolvedType = self :: resolveConcreteType ( $ endpoint , $ resolvedTypeDefinition , $ object ) ; } } return $ resolvedType ; }
Resolve the object type for given object instance when object use polymorphic definitions

@param Endpoint                       $endpoint
@param PolymorphicDefinitionInterface $definition
@param mixed                          $object

@return null|string
Resolve the object type for given object instance when object use polymorphic definitions