public static function resolveObjectType(Endpoint $endpoint, $object): ?string
    {
        if ($object instanceof PolymorphicObjectInterface && $object->getConcreteType()) {
            return $object->getConcreteType();
        }

        $class = DoctrineClassUtils::getClass($object);
        if (!$endpoint->hasTypeForClass($class)) {
            return null;
        }

        $types = $endpoint->getTypesForClass($class);

        //if only one type for given object class return the type
        if (count($types) === 1) {
            return $types[0];
        }

        //in case of multiple types using polymorphic definitions
        foreach ($types as $type) {
            $definition = $endpoint->getType($type);
            if ($definition instanceof PolymorphicDefinitionInterface) {
                return self::resolveConcreteType($endpoint, $definition, $object);
            }
        }

        //as fallback use the first type in the list
        return $types[0];
    }
public static function resolveObjectType(Endpoint $endpoint, $object): ?string
    {
        if ($object instanceof PolymorphicObjectInterface && $object->getConcreteType()) {
            return $object->getConcreteType();
        }

        $class = DoctrineClassUtils::getClass($object);
        if (!$endpoint->hasTypeForClass($class)) {
            return null;
        }

        $types = $endpoint->getTypesForClass($class);

        //if only one type for given object class return the type
        if (count($types) === 1) {
            return $types[0];
        }

        //in case of multiple types using polymorphic definitions
        foreach ($types as $type) {
            $definition = $endpoint->getType($type);
            if ($definition instanceof PolymorphicDefinitionInterface) {
                return self::resolveConcreteType($endpoint, $definition, $object);
            }
        }

        //as fallback use the first type in the list
        return $types[0];
    }
public static function resolveObjectType ( Endpoint $ endpoint , $ object ) : ? string { if ( $ object instanceof PolymorphicObjectInterface && $ object -> getConcreteType ( ) ) { return $ object -> getConcreteType ( ) ; } $ class = DoctrineClassUtils :: getClass ( $ object ) ; if ( ! $ endpoint -> hasTypeForClass ( $ class ) ) { return null ; } $ types = $ endpoint -> getTypesForClass ( $ class ) ; //if only one type for given object class return the type if ( count ( $ types ) === 1 ) { return $ types [ 0 ] ; } //in case of multiple types using polymorphic definitions foreach ( $ types as $ type ) { $ definition = $ endpoint -> getType ( $ type ) ; if ( $ definition instanceof PolymorphicDefinitionInterface ) { return self :: resolveConcreteType ( $ endpoint , $ definition , $ object ) ; } } //as fallback use the first type in the list return $ types [ 0 ] ; }
Resolve the object type for given object instance

@param Endpoint $endpoint
@param mixed    $object

@return null|string
Resolve the object type for given object instance