6.1 Entity Migration
Sylius 2.0 (and Symfony 7+) fully embraces PHP 8 attributes for Doctrine ORM mapping. If your plugin still uses Doctrine annotations (e.g., @ORM\Entity, @ORM\Column), you should migrate them to attributes.
When to skip this step:
Your entities are mapped with XML or YAML files
Your entities already use PHP 8 attributes (
#[ORM\*])
When to do this step:
Your entities use Doctrine annotations (
@ORM\*) in PHP files
1. Replace Annotations with Attributes
Replace each Doctrine annotation with the corresponding PHP 8 attribute:
Basic Entity Annotations
- /**
- * @ORM\Entity
- * @ORM\Table(name="app_product")
- */
+ #[ORM\Entity]
+ #[ORM\Table(name: 'app_product')]
class ProductColumn Annotations
Relationship Annotations
Important Changes
Named arguments: Use
name:instead of justnamefor parametersClass references: Use
::classinstead of string (e.g.,Category::classnot"Category")Arrays: Use square brackets
[]instead of curly braces{}Quotes: Single quotes for string values
2. Update Use Statements
Make sure you import the ORM attributes namespace at the top of your entity files:
This allows you to use #[ORM\Entity] instead of #[Doctrine\ORM\Mapping\Entity].
3. Validate Schema
After migrating all entities, validate that Doctrine can still read your mappings:
Expected output:
Troubleshooting
If you encounter issues:
Last updated
Was this helpful?
