diff --git a/output.yaml b/output.yaml index 7425985..b118d33 100644 --- a/output.yaml +++ b/output.yaml @@ -24,7 +24,6 @@ classes: intersection: false class: false collection: false - simpleObject: false test2: attributes: { } name: test2 @@ -39,7 +38,6 @@ classes: intersection: false class: false collection: false - simpleObject: false type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -50,28 +48,6 @@ classes: intersection: false class: true collection: false - simpleObject: false - DateTime: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \DateTime - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false PBaszak\DedicatedMapper\Tests\assets\ItemDTO: classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType reflection: @@ -101,7 +77,6 @@ classes: intersection: false class: false collection: false - simpleObject: false name: attributes: - @@ -121,7 +96,6 @@ classes: intersection: false class: false collection: false - simpleObject: false description: attributes: { } name: description @@ -136,7 +110,6 @@ classes: intersection: false class: false collection: false - simpleObject: false price: attributes: { } name: price @@ -151,7 +124,6 @@ classes: intersection: false class: false collection: false - simpleObject: false currency: attributes: - @@ -174,7 +146,6 @@ classes: intersection: false class: false collection: false - simpleObject: false quantity: attributes: { } name: quantity @@ -189,7 +160,6 @@ classes: intersection: false class: false collection: false - simpleObject: false type: attributes: { } name: type @@ -204,7 +174,6 @@ classes: intersection: false class: false collection: false - simpleObject: false category: attributes: { } name: category @@ -219,7 +188,6 @@ classes: intersection: false class: false collection: false - simpleObject: false vat: attributes: { } name: vat @@ -234,76 +202,19 @@ classes: intersection: false class: false collection: false - simpleObject: false metadata: attributes: { } name: metadata options: { } type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - test: - attributes: { } - name: test - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - test2: - attributes: { } - name: test2 - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - float - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false + '@link': PBaszak\DedicatedMapper\Tests\assets\MetadataDTO created_at: attributes: { } name: created_at options: { } type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } + classType: PBaszak\DedicatedMapper\Reflection\Type\SimpleObjectType + simpleObject: null type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -314,21 +225,13 @@ classes: intersection: false class: true collection: false - simpleObject: false updated_at: attributes: { } name: updated_at options: { } type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } + classType: PBaszak\DedicatedMapper\Reflection\Type\SimpleObjectType + simpleObject: null type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -339,7 +242,6 @@ classes: intersection: false class: true collection: false - simpleObject: false availableActions: attributes: - @@ -360,7 +262,6 @@ classes: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: - array - - array innerType: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -372,13 +273,11 @@ classes: intersection: false class: false collection: false - simpleObject: false nullable: false union: false intersection: false class: false collection: true - simpleObject: false type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -390,7 +289,6 @@ classes: intersection: false class: true collection: false - simpleObject: false PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO: classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType reflection: @@ -420,7 +318,6 @@ classes: intersection: false class: false collection: false - simpleObject: false pageSize: attributes: - @@ -445,7 +342,6 @@ classes: intersection: false class: false collection: false - simpleObject: false total: attributes: - @@ -465,7 +361,6 @@ classes: intersection: false class: false collection: false - simpleObject: false items: attributes: - @@ -485,332 +380,13 @@ classes: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: - array - - array innerType: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\ItemDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - id: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: id - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - name: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: name - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - description: - attributes: { } - name: description - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - price: - attributes: { } - name: price - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - float - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - currency: - attributes: - - - class: Symfony\Component\Validator\Constraints\Choice - arguments: - choices: - - PLN - - EUR - - USD - instance: "\\Symfony\\Component\\Validator\\Constraints\\Choice::__set_state(array(\n 'payload' => NULL,\n 'choices' => \n array (\n 0 => 'PLN',\n 1 => 'EUR',\n 2 => 'USD',\n ),\n 'callback' => NULL,\n 'multiple' => false,\n 'strict' => true,\n 'min' => NULL,\n 'max' => NULL,\n 'message' => 'The value you selected is not a valid choice.',\n 'multipleMessage' => 'One or more of the given values is invalid.',\n 'minMessage' => 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.',\n 'maxMessage' => 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.',\n 'match' => true,\n))" - name: currency - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - quantity: - attributes: { } - name: quantity - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - type: - attributes: { } - name: type - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - category: - attributes: { } - name: category - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - vat: - attributes: { } - name: vat - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - metadata: - attributes: { } - name: metadata - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - test: - attributes: { } - name: test - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - test2: - attributes: { } - name: test2 - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - float - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - created_at: - attributes: { } - name: created_at - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \DateTime - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - updated_at: - attributes: { } - name: updated_at - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \DateTime - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - availableActions: - attributes: - - - class: JMS\Serializer\Annotation\Type - arguments: - - array - instance: "\\JMS\\Serializer\\Annotation\\Type::__set_state(array(\n 'name' => 'array',\n))" - - - class: JMS\Serializer\Annotation\SerializedName - arguments: - - availableActions - instance: "\\JMS\\Serializer\\Annotation\\SerializedName::__set_state(array(\n 'name' => 'availableActions',\n))" - name: availableActions - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\CollectionType - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - array - - array - innerType: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - - mixed - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - nullable: false - union: false - intersection: false - class: false - collection: true - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\ItemDTO - - mixed - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false + '@link': PBaszak\DedicatedMapper\Tests\assets\ItemDTO nullable: false union: false intersection: false class: false collection: true - simpleObject: false type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -821,7 +397,6 @@ classes: intersection: false class: true collection: false - simpleObject: false PBaszak\DedicatedMapper\Tests\assets\Dummy: classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType reflection: @@ -855,7 +430,6 @@ classes: intersection: false class: false collection: false - simpleObject: false name: attributes: - @@ -881,7 +455,6 @@ classes: intersection: false class: false collection: false - simpleObject: false description: attributes: { } name: description @@ -896,7 +469,6 @@ classes: intersection: false class: false collection: false - simpleObject: false _embedded: attributes: - @@ -911,436 +483,7 @@ classes: name: _embedded options: { } type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - page: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: page - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - pageSize: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - - - class: JMS\Serializer\Annotation\SerializedName - arguments: - - pageSize - instance: "\\JMS\\Serializer\\Annotation\\SerializedName::__set_state(array(\n 'name' => 'pageSize',\n))" - name: pageSize - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - total: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: total - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - items: - attributes: - - - class: Symfony\Component\Validator\Constraints\Valid - arguments: { } - instance: "\\Symfony\\Component\\Validator\\Constraints\\Valid::__set_state(array(\n 'payload' => NULL,\n 'traverse' => true,\n))" - - - class: JMS\Serializer\Annotation\Type - arguments: - - array - instance: "\\JMS\\Serializer\\Annotation\\Type::__set_state(array(\n 'name' => 'array',\n))" - name: items - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\CollectionType - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - array - - array - innerType: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\ItemDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - id: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: id - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - name: - attributes: - - - class: Symfony\Component\Serializer\Annotation\Groups - arguments: - - test - instance: "\\Symfony\\Component\\Serializer\\Annotation\\Groups::__set_state(array(\n 'groups' => \n array (\n 0 => 'test',\n ),\n))" - name: name - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - description: - attributes: { } - name: description - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - price: - attributes: { } - name: price - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - float - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - currency: - attributes: - - - class: Symfony\Component\Validator\Constraints\Choice - arguments: - choices: - - PLN - - EUR - - USD - instance: "\\Symfony\\Component\\Validator\\Constraints\\Choice::__set_state(array(\n 'payload' => NULL,\n 'choices' => \n array (\n 0 => 'PLN',\n 1 => 'EUR',\n 2 => 'USD',\n ),\n 'callback' => NULL,\n 'multiple' => false,\n 'strict' => true,\n 'min' => NULL,\n 'max' => NULL,\n 'message' => 'The value you selected is not a valid choice.',\n 'multipleMessage' => 'One or more of the given values is invalid.',\n 'minMessage' => 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.',\n 'maxMessage' => 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.',\n 'match' => true,\n))" - name: currency - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - quantity: - attributes: { } - name: quantity - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - type: - attributes: { } - name: type - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - category: - attributes: { } - name: category - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - vat: - attributes: { } - name: vat - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - int - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - metadata: - attributes: { } - name: metadata - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - file: - path: /app/tests/assets/Dummy.php - hash: 24ba2ede85a4491930ed05f368b3816c - options: { } - properties: - test: - attributes: { } - name: test - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - test2: - attributes: { } - name: test2 - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - float - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\MetadataDTO - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - created_at: - attributes: { } - name: created_at - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \DateTime - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - updated_at: - attributes: { } - name: updated_at - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\ClassType - reflection: - attributes: { } - className: DateTime - file: - path: false - hash: null - options: { } - properties: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \DateTime - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - availableActions: - attributes: - - - class: JMS\Serializer\Annotation\Type - arguments: - - array - instance: "\\JMS\\Serializer\\Annotation\\Type::__set_state(array(\n 'name' => 'array',\n))" - - - class: JMS\Serializer\Annotation\SerializedName - arguments: - - availableActions - instance: "\\JMS\\Serializer\\Annotation\\SerializedName::__set_state(array(\n 'name' => 'availableActions',\n))" - name: availableActions - options: { } - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\CollectionType - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - array - - array - innerType: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - string - - mixed - innerType: null - nullable: false - union: false - intersection: false - class: false - collection: false - simpleObject: false - nullable: false - union: false - intersection: false - class: false - collection: true - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\ItemDTO - - mixed - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false - nullable: false - union: false - intersection: false - class: false - collection: true - simpleObject: false - type: - classType: PBaszak\DedicatedMapper\Reflection\Type\Type - types: - - \PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO - innerType: null - nullable: false - union: false - intersection: false - class: true - collection: false - simpleObject: false + '@link': PBaszak\DedicatedMapper\Tests\assets\EmbeddedDTO type: classType: PBaszak\DedicatedMapper\Reflection\Type\Type types: @@ -1351,4 +494,3 @@ classes: intersection: false class: true collection: false - simpleObject: false diff --git a/src/Config.php b/src/Config.php index 392abdf..6a634ef 100644 --- a/src/Config.php +++ b/src/Config.php @@ -50,7 +50,7 @@ public function export(): array return [ 'main' => $this->className, - 'classes' => array_map(fn (ClassType $class) => $class->toArray(), $this->classes), + 'classes' => array_map(fn (ClassType $class) => $class->toArray(false), $this->classes), ]; } diff --git a/src/Reflection/Type/ClassType.php b/src/Reflection/Type/ClassType.php index e61b9ea..56c7dc6 100644 --- a/src/Reflection/Type/ClassType.php +++ b/src/Reflection/Type/ClassType.php @@ -55,9 +55,11 @@ public static function create(Type $type): static return $instance; } - public function toArray(): array + public function toArray(bool $linkOnly = true): array { - return [ + return $linkOnly ? [ + '@link' => $this->reflection->getReflection()?->getName(), + ] : [ 'classType' => self::class, 'reflection' => $this->reflection?->toArray(), 'type' => $this->type->toArray(), diff --git a/src/Reflection/Type/CompoundType.php b/src/Reflection/Type/CompoundType.php index 8436889..cf5c562 100644 --- a/src/Reflection/Type/CompoundType.php +++ b/src/Reflection/Type/CompoundType.php @@ -47,4 +47,9 @@ public function toArray(): array 'type' => $this->type->toArray(), ]; } + + public function getType(): Type + { + return $this->type; + } } diff --git a/src/Reflection/Type/SimpleObjectType.php b/src/Reflection/Type/SimpleObjectType.php index a7489f7..cdce502 100644 --- a/src/Reflection/Type/SimpleObjectType.php +++ b/src/Reflection/Type/SimpleObjectType.php @@ -16,9 +16,9 @@ class SimpleObjectType implements TypeInterface public const NATIVE_SIMPLE_OBJECTS = [ \ArrayIterator::class => [], \ArrayObject::class => [], - \DateTime::class => ['staticConstructor' => NativeSimpleObject::class.'::DateTimeConstructor'], - \DateTimeImmutable::class => ['staticConstructor' => NativeSimpleObject::class.'::DateTimeConstructor'], - \DateTimeZone::class => ['staticConstructor' => NativeSimpleObject::class.'::DateTimeZoneConstructor'], + \DateTime::class => ['staticConstructor' => NativeSimpleObject::class . '::DateTimeConstructor'], + \DateTimeImmutable::class => ['staticConstructor' => NativeSimpleObject::class . '::DateTimeConstructor'], + \DateTimeZone::class => ['staticConstructor' => NativeSimpleObject::class . '::DateTimeZoneConstructor'], \DateInterval::class => [], ]; @@ -43,7 +43,10 @@ public static function supports(Type $type): bool foreach ($type->getTypes() as $t) { if (class_exists($t, false)) { - if (isset(self::NATIVE_SIMPLE_OBJECTS['\\' . ltrim($t, '\\')])) { + if ( + array_key_exists($t, self::NATIVE_SIMPLE_OBJECTS) + || array_key_exists(ltrim($t, '\\'), self::NATIVE_SIMPLE_OBJECTS) + ) { return true; } $reflection = new ReflectionClass($t); @@ -52,7 +55,7 @@ public static function supports(Type $type): bool } } } - + return $type->hasAttribute(SimpleObject::class); } @@ -74,7 +77,8 @@ public function __construct( * @var null|object{"class": string, "arguments": mixed[], "instance": ?object} $simpleObjectAttr */ protected ?object $simpleObjectAttr, - ) {} + ) { + } /** * @return Type diff --git a/src/Reflection/Type/Type.php b/src/Reflection/Type/Type.php index ecadee3..4d3973a 100644 --- a/src/Reflection/Type/Type.php +++ b/src/Reflection/Type/Type.php @@ -4,6 +4,7 @@ namespace PBaszak\DedicatedMapper\Reflection\Type; +use LogicException; use PBaszak\DedicatedMapper\Attribute\ApplyToCollectionItems; use PBaszak\DedicatedMapper\Reflection\PropertyReflection; use phpDocumentor\Reflection\Type as PhpDocumentorType; @@ -51,11 +52,6 @@ class Type implements TypeInterface */ protected bool $collection = false; - /** - * @var bool $simpleObject - */ - protected bool $simpleObject = false; - /** * @var null|ReflectionType $reflectionType */ @@ -87,10 +83,14 @@ public function toArray(): array 'intersection' => $this->intersection, 'class' => $this->class, 'collection' => $this->collection, - 'simpleObject' => $this->simpleObject, ]; } + public function getType(): self + { + throw new LogicException('Cannot get Type from Type.'); + } + /** * @return null|PropertyReflection|TypeInterface */ @@ -180,14 +180,6 @@ public function isCollection(): bool { return $this->collection; } - - /** - * @return bool - */ - public function isSimpleObject(): bool - { - return $this->simpleObject; - } /** * @return null|ReflectionType diff --git a/src/Reflection/Type/TypeFactory.php b/src/Reflection/Type/TypeFactory.php index 0cb7c4d..f1b17ac 100644 --- a/src/Reflection/Type/TypeFactory.php +++ b/src/Reflection/Type/TypeFactory.php @@ -99,7 +99,7 @@ public function createFromString(string $type, ?Reflector $reflection = null, nu if ($reflection) { $ref = new ReflectionClass(Type::class); $ref->getProperty('reflectionType')->setValue( - $instance, + $instance instanceof Type ? $instance : $instance->getType(), match (get_class($reflection)) { ReflectionProperty::class => $reflection->getType(), ReflectionType::class => $reflection, @@ -158,7 +158,7 @@ protected function createFromPhpDocumentatorType(PhpDocumentorType $type, null|P protected function combineTypes(TypeInterface ...$types): TypeInterface { $types = array_filter($types); - $types = array_map(fn(TypeInterface $type): Type => method_exists($type, 'getType') ? $type->{'getType'}() : $type, $types); + $types = array_map(fn (TypeInterface $type): Type => $type instanceof Type ? $type : $type->getType(), $types); $ref = new \ReflectionClass(Type::class); /** @var Type $instance */ $instance = $ref->newInstanceWithoutConstructor(); @@ -166,7 +166,7 @@ protected function combineTypes(TypeInterface ...$types): TypeInterface foreach ($types as $type) { $ref->getProperty('parent')->setValue($instance, $type->getParent()); $instanceTypes = $ref->getProperty('types')->isInitialized($instance) ? $ref->getProperty('types')->getValue($instance) : []; - $ref->getProperty('types')->setValue($instance, array_merge($instanceTypes, $type->getTypes())); + $ref->getProperty('types')->setValue($instance, array_unique(array_merge($instanceTypes, $type->getTypes()))); $instanceInnerType = $ref->getProperty('innerType')->getValue($instance); if (null === $instanceInnerType) { $ref->getProperty('innerType')->setValue($instance, $type->getInnerType()); @@ -178,7 +178,6 @@ protected function combineTypes(TypeInterface ...$types): TypeInterface $ref->getProperty('intersection')->setValue($instance, $type->isIntersection() || $ref->getProperty('intersection')->getValue($instance)); $ref->getProperty('collection')->setValue($instance, $type->isCollection() || $ref->getProperty('collection')->getValue($instance)); $ref->getProperty('class')->setValue($instance, $type->isClass() || $ref->getProperty('class')->getValue($instance)); - $ref->getProperty('simpleObject')->setValue($instance, $type->isSimpleObject() || $ref->getProperty('simpleObject')->getValue($instance)); $ref->getProperty('phpDocumentorReflectionType')->setValue($instance, $type->getPhpDocumentorReflectionType() ?? $ref->getProperty('phpDocumentorReflectionType')->getValue($instance)); $ref->getProperty('reflectionType')->setValue($instance, $type->getReflectionType() ?? $ref->getProperty('reflectionType')->getValue($instance)); } diff --git a/src/Reflection/Type/TypeInterface.php b/src/Reflection/Type/TypeInterface.php index ca4bec0..63a126b 100644 --- a/src/Reflection/Type/TypeInterface.php +++ b/src/Reflection/Type/TypeInterface.php @@ -7,6 +7,7 @@ interface TypeInterface { public function toArray(): array; + public function getType(): Type; public static function supports(Type $type): bool; public static function create(Type $type): TypeInterface; }