所以我有Symfony 6.2 API, PHP 8.2代码库。
在尝试运行composer install/update时,显示以下错误,我想知道如何清除它:
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".
如果我注释掉学说中的映射部分。yaml文件(如下)编写器运行成功,但是所有对api的POST请求将导致以下错误:
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)
挠头想知道怎么解决。我觉得这可能是教条。与yaml相关,但我可能大错特错。
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'
您缺少doctrine/annotations
依赖项。尝试在您的composer.json
文件中添加:
"doctrine/annotations": "^1.0",
执行命令composer update
。或者直接输入:
composer require doctrine/annotations
这将不是你的问题的确切答案,但我的建议是移动PHP 8.1属性而不是教条注释。
试图安装doctrine/annotations
,这将需要版本2.0给了我冲突与其他工具需要版本1.x。
设置你的Symfony DoctrinBundle映射类型为attribute
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
form:
...
mappings:
App:
is_bundle: false
type: attribute
关于属性设置的更多信息可以在这里找到:
https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/attributes-reference.html
您应该使用PHP 8属性来路由注释,而不是使用已弃用的doctrine/annotations
包,如其弃用通知:https://www.doctrine-project.org/projects/doctrine-annotations/en/2.0/index.html#deprecation-notice
PHP 8 introduced attributes, which are a native replacement for annotations.
As such, this library is considered feature complete,
and should receive exclusively bugfixes and security fixes.
我已经更正了错误,添加:
composer require doctrine/annotations