diff --git a/config/services.xml b/config/services.xml index 5dc8457f6..6232ad049 100644 --- a/config/services.xml +++ b/config/services.xml @@ -169,6 +169,10 @@ + + + + diff --git a/src/TypeDescriber/ArrayDescriber.php b/src/TypeDescriber/ArrayDescriber.php new file mode 100644 index 000000000..1eb6e8245 --- /dev/null +++ b/src/TypeDescriber/ArrayDescriber.php @@ -0,0 +1,61 @@ + + * + * @experimental + * + * @internal + */ +final class ArrayDescriber implements TypeDescriberInterface, TypeDescriberAwareInterface +{ + use TypeDescriberAwareTrait; + + public function describe(Type $type, Schema $schema, array $context = []): void + { + if (!$type->getCollectionKeyType() instanceof Type\CompositeTypeInterface) { + return; + } + + $collections = array_map( + fn (Type $keyType): CollectionType => TypeFactoryTrait::collection($type->getWrappedType(), $type->getCollectionValueType(), $keyType), + $type->getCollectionKeyType()->getTypes(), + ); + + if ($type->getCollectionKeyType() instanceof Type\UnionType) { + $describeType = Type::union(...$collections); + } + + if ($type->getCollectionKeyType() instanceof Type\IntersectionType) { + $describeType = Type::intersection(...$collections); + } + + if (!isset($describeType)) { + return; + } + + $this->describer->describe($describeType, $schema, $context); + } + + public function supports(Type $type, array $context = []): bool + { + return $type instanceof CollectionType + && $type->getCollectionKeyType() instanceof Type\CompositeTypeInterface; + } +} diff --git a/src/TypeDescriber/DictionaryDescriber.php b/src/TypeDescriber/DictionaryDescriber.php index 5d6c5de9e..cc63ed06c 100644 --- a/src/TypeDescriber/DictionaryDescriber.php +++ b/src/TypeDescriber/DictionaryDescriber.php @@ -40,6 +40,7 @@ public function describe(Type $type, Schema $schema, array $context = []): void public function supports(Type $type, array $context = []): bool { return $type instanceof CollectionType + && false === $type->getCollectionKeyType() instanceof Type\UnionType && $type->getCollectionKeyType()->isIdentifiedBy(TypeIdentifier::STRING); } } diff --git a/src/TypeDescriber/ListDescriber.php b/src/TypeDescriber/ListDescriber.php index d697e6982..74a94fb7e 100644 --- a/src/TypeDescriber/ListDescriber.php +++ b/src/TypeDescriber/ListDescriber.php @@ -40,6 +40,7 @@ public function describe(Type $type, Schema $schema, array $context = []): void public function supports(Type $type, array $context = []): bool { return $type instanceof CollectionType + && false === $type->getCollectionKeyType() instanceof Type\UnionType && $type->getCollectionKeyType()->isIdentifiedBy(TypeIdentifier::INT); } }