安装api-platform.com后,清除缓存命令得到一个错误错误

问题描述

我正在尝试安装api平台,但是在启动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,called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.PHP on line 1040                  
!!                                                                                 
!!                                                                                  
!!   [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,called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.PHP on line 1040                  
!!                                                                                 
!!  
!!   // Clearing the cache for the dev environment with debug                       
!!   // true                                                                        
!!  
!!  
!!  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,called in /var/www/test-api-sf/var/cache/dev/Co  
!!    ntainerPA69O1T/App_KernelDevDebugContainer.PHP on line 1040                  
!!                                                                                 
!!  
!!  cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
!!  
!!  2020-08-25T12:06:30+02:00 [critical] Uncaught Error: Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry,instance of Doctrine\Bundle\DoctrineBundle\Registry given,called in /var/www/test-api-sf/var/cache/dev/ContainerPA69O1T/App_KernelDevDebugContainer.PHP on line 1040

为什么会出现此错误,该如何解决

解决方法

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

"conflict": {
    "symfony/symfony": "*","doctrine/common": ">=3.0","doctrine/persistence": "<1.3"
},

所以从今天早上开始我就遇到了这个问题,我一直在寻找解决方案,却没有找到解决方案,所以我自己制作了自己的DIY解决方案,它正在起作用。 strong>

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

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

打开后,您需要替换第19行使用Doctrine \ Common \ Persistence \ ManagerRegistry; ),并添加以下内容:

use Symfony\Bridge\Doctrine\ManagerRegistry;

这就是一切! SCREENSHOT OF THE LINE

PS::如果仍然有问题或找不到Vendor \ api平台,则只需打开 composer.json 并临时删除以下内容行:

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

并再次运行命令:

composer req api
,

自昨天以来,我们遇到了同样的问题! 我试图将捆绑软件的版本更改为旧版本。但是没有任何成功的结果。

当前依赖项:

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

但是问题已在GitHub上解决。待测试... https://github.com/symfony/symfony/issues/37936


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

,

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

"conflict": {
    ...
    "doctrine/common": ">=3.0","doctrine/persistence": "<1.3"
}

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

,

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

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