I have changed the configuration of my Symfony project to use PHP attributes with Doctrine in my Entities. I was really happy about this and wanted to give it a try.
I have changed my doctrine.yaml from annotation to attribute
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
and use attributes in my entities
#[ORM\Entity(UserRepository::class)]
class User implements UserInterface
{
#[ORM\Id()]
#[ORM\GeneratedValue()]
#[ORM\Column(type: "integer")]
private ?int $id;
#[ORM\Column(type: "string", length: 180, unique: true)]
private ?string $email;
#[ORM\Column(type: "json")]
private array $roles = [];
}
With this configuration my php bin/console do:sc:up -f works well.
But when I try to generate a new entity with php bin/console make:entity I get this error:
[ERROR] Only annotation mapping is supported by make:entity, but the App\Entity\Toto class uses a different format. If you would like this command to generate the properties & getter/setter methods, add your mapping
configuration, and then re-run this command with the --regenerate flag.
It seems like it's not possible yet to use maker to generate entity with attribute. Does anyone have found a way to fix this issue or do we just have to wait a new release?
For now I'm using:
"doctrine/annotations": "1.13.1"
"doctrine/doctrine-bundle": "2.4.2",
"doctrine/orm": "2.9.3"
"symfony/maker-bundle": "1.31.1",