fre5h / DoctrineEnumBundle

📦 Provides support of ENUM type for Doctrine in Symfony applications.
https://github.com/fre5h/DoctrineEnumBundle
MIT License
460 stars 75 forks source link

Cant use enum as annotation #213

Closed Gemorroj closed 2 years ago

Gemorroj commented 2 years ago

Hi. release v7.5.0

 php /bin/console make:entity

In AnnotationException.php line 39:

  [Semantical Error] The class "Fresh\DoctrineEnumBundle\Validator\Constraints\Enum" is not annotated with @Annotatio
  n.
  Are you sure this class can be used as annotation?
  If so, then you need to add @Annotation to the _class_ doc comment of "Fresh\DoctrineEnumBundle\Validator\Constrain
  ts\Enum".
  If it is indeed no annotation, then you need to add @IgnoreAnnotation("DoctrineAssert\Enum") to the _class_ doc com
  ment of property App\Entity\BillingFeature::$code.

make:entity [-a|--api-resource] [-b|--broadcast] [--regenerate] [--overwrite] [--] [<name>]
<?php

use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;

/**
 * @ORM\Entity(repositoryClass=BillingFeatureRepository::class)
 */
class BillingFeature
{
    /**
     * @var string
     * @ORM\Column(type="feature", length=255, nullable=false)
     * @DoctrineAssert\Enum(entity="App\DBAL\Types\FeatureType")
     */
    private $code;

but there is no such error in release v7.4.0

fre5h commented 2 years ago

@Gemorroj Two possible solutions. Use 7.4.0 because it is the last version which supports annotations. Version 7.5.0 uses attributes, so you can change it to

    /**
     * @var string
     * @ORM\Column(type="feature", length=255, nullable=false)
     */
     #[DoctrineAssert\Enum(entity: FeatureType::class)]
    private $code;
Gemorroj commented 2 years ago

I think we should support both variants (attribute/annotation) in current branches. If we remove support annotation, we should make new major branch. Like 9.x

fre5h commented 2 years ago

OK, I will rethink about it

craigh commented 2 years ago

I think we should support both variants (attribute/annotation) in current branches. If we remove support annotation, we should make new major branch. Like 9.x

I agree. Changing major dependency requirements (e.g. php7 vs. php 8+) should require a major version change in your library.

fre5h commented 2 years ago

I was thinking about correct restoring. So in 7.5 and 8.1 Enum constraint as annotation will be restored, but will be removed in 9.0. Enum as attribute will be kept in both branches but renamed into EnumType. So you can still use old variant

@DoctrineAssert\Enum(entity="App\DBAL\Types\BasketballPositionType")

or switch to the new one

#[DoctrineAssert\EnumType(entity: BasketballPositionType::class)]

Two classes were introduced because it would be hard and dirty to support annotation and attribute processing in one file. They have different syntax.

7.5.1 and 8.1.1 releases will include this fix