So I have a Symfony 6.2 API, PHP 8.2 codebase.
While trying to run composer install/update the following error is displaying and I’m wondering how to clear it:
In CheckExceptionOnInvalidReferenceBehaviorPass.php line 83:
The service "doctrine.orm.default_annotation_metadata_driver" has a dependency
on a non-existent service "doctrine.orm.metadata.annotation_reader".
If I comment out the mappings section in doctrine.yaml file (below) composer runs successfully, however all POST requests to the api will then result in the following error:
Could not find the entity manager for class AppEntityToken.
Check your Doctrine configuration to make sure it is configured
to load this entity’s metadata. (500 Internal Server Error)
Scratching my head here to understand how to resolve it. I’ve a feeling it may be doctrine.yaml related but I could be miles off the mark.
composer.json:
"require": {
"php": ">=8.2",
...
"doctrine/doctrine-bundle": "^2.8",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.14",
...
},
doctrine.yaml:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
3
Answers
You are missing the
doctrine/annotations
dependency. Try to add in yourcomposer.json
file:Then run
composer update
. Or just run:It will not be the exact answer to your question, but my advice is to move PHP 8.1 attributes instead of doctrine annotations.
Trying to install
doctrine/annotations
, which will require version 2.0 gave me conflicts with other tools that required version 1.x.Set your Symfony DoctrinBundle mapping type to
attribute
More info about the attribute settings can be found here:
https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/attributes-reference.html
You should use PHP 8 attributes for routing annotations instead of use deprecated
doctrine/annotations
package as noted in their deprecation notice : https://www.doctrine-project.org/projects/doctrine-annotations/en/2.0/index.html#deprecation-notice