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 Product

Column Annotations

Relationship Annotations

Important Changes

  1. Named arguments: Use name: instead of just name for parameters

  2. Class references: Use ::class instead of string (e.g., Category::class not "Category")

  3. Arrays: Use square brackets [] instead of curly braces {}

  4. 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?