I use PHP8, Symfony 5.2 and Doctrine 3.0 in my project,
But the PHP 8 attributes, allowed since Doctrine 2.9, doesn’t seem to work.
use DoctrineORMMappingEntity;
**
* @Entity(repositoryClass="AppRepositoryMyClassRepository")
*/
class MyClass
{
works fine.
use DoctrineORMMappingEntity;
#[Entity(repositoryClass: MyClassRepository::class)]
class MyClass
{
Return [critical] Uncaught PHP Exception DoctrineORMMappingMappingException: "Class "AppEntityMyClass" is not a valid entity or mapped super class." at .../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php line 378
here is my composer.json :
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^3.0",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/proxy-manager-bridge": "5.2.*",
"symfony/yaml": "5.2.*"
2
Answers
This is because of doctrine bundle configuration. If all entities within the bundle use attributes just switch the metadata driver from "annotation" to "attribute"
If some entities within a bundles use attributes and some others annotations – than it is better either choose only one format for metadata or implement a custom metadata driver.
The solution is use a custom AnnotationDriver.
Sample fully works implementation: https://github.com/baraja-core/doctrine/blob/master/src/Orm/Mapping/AnnotationDriver.php