diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 3a6615e646..059061ba0d 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -35,6 +35,8 @@ use Symfony\Bundle\MakerBundle\Doctrine\RelationOneToMany; use Symfony\Bundle\MakerBundle\Doctrine\RelationOneToOne; use Symfony\Bundle\MakerBundle\Str; +use Symfony\Component\Uid\Ulid; +use Symfony\Component\Uid\Uuid; /** * @internal @@ -94,6 +96,8 @@ public function addEntityField(string $propertyName, array $columnOptions, array $defaultValue = null; if ('array' === $typeHint) { $defaultValue = new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]); + } elseif (\in_array($typeHint, [Uuid::class, Ulid::class], true)) { + $typeHint = $this->addUseStatementIfNecessary($typeHint); } $this->addProperty( @@ -1030,6 +1034,8 @@ private function getEntityTypeHint(string $doctrineType): ?string 'datetime_immutable', 'datetimetz_immutable', 'date_immutable', 'time_immutable' => '\\'.\DateTimeImmutable::class, 'dateinterval' => '\\'.\DateInterval::class, 'object' => 'object', + 'uuid' => Uuid::class, + 'ulid' => Ulid::class, default => null, }; } diff --git a/tests/Util/ClassSourceManipulatorTest.php b/tests/Util/ClassSourceManipulatorTest.php index a3efdd6219..48b6108044 100644 --- a/tests/Util/ClassSourceManipulatorTest.php +++ b/tests/Util/ClassSourceManipulatorTest.php @@ -279,6 +279,24 @@ public function getAddEntityFieldTests(): \Generator ], 'User_simple_object.php', ]; + + yield 'entity_add_uuid' => [ + 'User_simple.php', + 'uuid', + [ + 'type' => 'uuid', + ], + 'User_simple_uuid.php', + ]; + + yield 'entity_add_ulid' => [ + 'User_simple.php', + 'ulid', + [ + 'type' => 'ulid', + ], + 'User_simple_ulid.php', + ]; } /** diff --git a/tests/Util/fixtures/add_entity_field/User_simple_ulid.php b/tests/Util/fixtures/add_entity_field/User_simple_ulid.php new file mode 100644 index 0000000000..eb06c931a0 --- /dev/null +++ b/tests/Util/fixtures/add_entity_field/User_simple_ulid.php @@ -0,0 +1,35 @@ +id; + } + + public function getUlid(): ?Ulid + { + return $this->ulid; + } + + public function setUlid(Ulid $ulid): self + { + $this->ulid = $ulid; + + return $this; + } +} diff --git a/tests/Util/fixtures/add_entity_field/User_simple_uuid.php b/tests/Util/fixtures/add_entity_field/User_simple_uuid.php new file mode 100644 index 0000000000..33a2f8e4eb --- /dev/null +++ b/tests/Util/fixtures/add_entity_field/User_simple_uuid.php @@ -0,0 +1,35 @@ +id; + } + + public function getUuid(): ?Uuid + { + return $this->uuid; + } + + public function setUuid(Uuid $uuid): self + { + $this->uuid = $uuid; + + return $this; + } +}