Is it possible to combine annotations together with attributes like:
/**
* @Gedmo\Timestampable(on="create")
*/
#[ORM\Column(type: 'datetime')]
private ?DateTime $createdAt;
Is it possible to combine annotations together with attributes like:
/**
* @Gedmo\Timestampable(on="create")
*/
#[ORM\Column(type: 'datetime')]
private ?DateTime $createdAt;
The answer is yes: at least some declarations (eg. routing, security and Doctrine) work side by side in different formats. So there is no hard rule preventing this.
I'm not sure however if there aren't some edge cases where this could backfire, and if you can you should try to keep to one format. There's Rector tool that can handle converting those automatically. In my experience it's sometimes hard to find a proper rule for Rector but there is a nice playground (https://getrector.com/demo) and good support on GitHub.
In case of Doctrine, you cannot mix annotation and attribute:
https://github.com/doctrine/orm/discussions/8925
doctrine:
orm:
entity_managers:
default:
mappings:
App:
type: attribute
Some software like Sylius, add both annotation and attribute in their code:
/**
* @ORM\Entity
* @ORM\Table(name="sylius_admin_user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_admin_user')]
class AdminUser extends BaseAdminUser
{
}
© 2022 - 2024 — McMap. All rights reserved.