maker-bundle
maker-bundle copied to clipboard
`make:entity` and enums
It seems entity generator is unable to handle enums. On an existing entity class
#[ORM\Entity]
class MyEntity
{
// ...
#[ORM\Column(nullable: false)]
protected MyEntityType $type;
// ...
make:entity --regenerate outputs enum's backed type (or is it getting it from mapped field type actually?):
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
Also, when running make:entity as a command-line wizard, while creating a property there is no option for enum type.
Quick browse of maker-bundle's code showed almost nothing about enums. Is it really unsupported yet? Can it be fixed to generate a proper param/return type hint at least?
Howdy @klkvsk! Enums are not currently supported in make:entity - but they could be with a PR ;)
I'm not completely sure at the moment, but from what I've observed in the source code, it seems to handle Doctrine types. However, enums aren't recognized as native Doctrine types; they're treated as strings with an additional option labeled enumType.
How should we address this in more detail? Currently, all types are well-defined, and an enum could potentially be its own class, residing in a specific directory such as /src/Enum or /src/MySpecialEnums, right?
If we decide to integrate this, how should we proceed?
Inclusion of Enums: Add enums to the *validTypesList.
Type Verification: Verify if the specified *type is an enum (possibly using enum_exists()). However, it's unclear where this check should occur or if a default location for the specified enumType should be requested.
Placeholder Enums: Consider creating a placeholder enum in src/Enum.
Property and Option Association: When creating the property, associate it with the enum class and add the option enumType: EnumClass.
Getter/Setter Generation: Generate getters and setters that return and accept the Enum class.
Migration Inclusion: Consider how this integration could be reflected in migrations.
As someone new here (Im just a symfony programmer for many years ^^), I'm eager to contribute and am relying on community support to navigate these enhancements. I'm open to feedback and additional ideas on how to improve enum support in the MakerBundle.