为了账号安全,请及时绑定邮箱和手机立即绑定

安装 api-platform.com 后清除缓存命令出现错误

安装 api-platform.com 后清除缓存命令出现错误

PHP
摇曳的蔷薇 2023-11-03 15:13:57
我正在尝试安装 api-platform,但启动 Composer 安装后遇到问题:我按照官方文档进行安装:composer req api当我启动服务器或尝试运行时composer install出现此错误:Executing script cache:clear [KO] [KO]Script cache:clear returned with error code 255然后是一个警告:[WARNING] Some commands could not be registered:                               !!                                                                                  !!  !!  In DoctrineOrmPropertyMetadataFactory.php line 31:!!                                                                                 !!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  !!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  !!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  !!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  !!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                  !!                                                                                 !!  !!  In DoctrineOrmPropertyMetadataFactory.php line 31:!!                                                                                 !!    Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property  !!    \DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of D  !!    octrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doc  !!    trineBundle\Registry given, called in /var/www/test-api-sf/var/cache/dev/Co  !!    ntainerPA69O1T/App_KernelDevDebugContainer.php on line 1040                                                                                              为什么我会收到此错误,我可以采取什么措施来避免它?
查看完整描述

4 回答

?
侃侃无极

TA贡献2051条经验 获得超10个赞

新闻:看来在您的composer.json中的冲突属性处添加这些行是有效的!


"conflict": {

    "symfony/symfony": "*",

    "doctrine/common": ">=3.0",

    "doctrine/persistence": "<1.3"

},

所以我从今天早上就遇到了这个问题,我寻找解决方案但没有找到它,所以我制作了自己的 DIY 解决方案,它对我来说很有效然后我将分享它:


首先,您需要进入以下路径并使用代码编辑器打开其中的文件:


C:\YOUR_PROJECT\vendor\api-platform\core\src\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory.php

打开它后,您需要将第 19 行(use Doctrine\Common\Persistence\ManagerRegistry;)替换为以下行:


use Symfony\Bridge\Doctrine\ManagerRegistry;

这就是大家! 线路截图


PS:如果您仍然遇到问题或未找到 Vendor\api-platform,您只需打开composer.json并临时删除以下行:


"cache:clear": "symfony-cmd",

并再次运行命令:


composer req api


查看完整回答
反对 回复 2023-11-03
?
喵喵时光机

TA贡献1846条经验 获得超7个赞

从昨天开始我们就遇到了同样的问题!我尝试将捆绑包的版本更改为旧版本。但没有任何成功的结果。

当前依赖:

"api-platform/api-pack": "^1.2"

不过问题在GitHub上已经解决了。待测试... https://github.com/symfony/symfony/issues/37936


更新:我们必须等待 api 平台捆绑包的发布。 https://github.com/api-platform/core/issues/3683


查看完整回答
反对 回复 2023-11-03
?
qq_花开花谢_0

TA贡献1835条经验 获得超6个赞

暂时,您可以将其添加到composer.json:


"conflict": {

    ...

    "doctrine/common": ">=3.0",

    "doctrine/persistence": "<1.3"

}

这个对我有用。 https://github.com/api-platform/core/issues/3683#issuecomment-681039267


查看完整回答
反对 回复 2023-11-03
?
RISEBY

TA贡献1856条经验 获得超5个赞

我有同样的问题,但是当我添加以下行时

"conflict": { ... "doctrine/common": ">=3.0", "doctrine/persistence": "<1.3" } 在我的composer.json 文件中问题已解决


查看完整回答
反对 回复 2023-11-03
  • 4 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信