Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make:entity and enums #1440

Closed
klkvsk opened this issue Feb 6, 2024 · 2 comments · Fixed by #1534
Closed

make:entity and enums #1440

klkvsk opened this issue Feb 6, 2024 · 2 comments · Fixed by #1534
Labels
Feature New Feature HasPR

Comments

@klkvsk
Copy link

klkvsk commented Feb 6, 2024

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?

@jrushlow jrushlow added the Feature New Feature label Feb 16, 2024
@jrushlow
Copy link
Collaborator

Howdy @klkvsk! Enums are not currently supported in make:entity - but they could be with a PR ;)

@tschmidtdev
Copy link

tschmidtdev commented Mar 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature HasPR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants