我正在尝试安装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
!!
!!
!! [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
!!
!!
!! // 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, 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
!!
!!
!! 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为什么我会得到这个错误,我能做些什么来规避它?
发布于 2020-08-26 22:48:54
新闻:似乎在composer.json的conflict属性中添加这些行是可行的!
"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;和所有的朋友们! SCREENSHOT OF THE LINE
PS:如果您仍然有问题或没有建立供应商\api-platform,您只需打开composer.json并临时删除以下行:
"cache:clear": "symfony-cmd",然后再次运行该命令:
composer req api发布于 2020-08-26 16:02:24
从昨天开始我们就遇到了同样的问题!我尝试将捆绑包的版本更改为较旧的版本。但没有任何成功的结果。
当前依赖项:
"api-platform/api-pack": "^1.2"但是这个问题在GitHub上已经解决了。接受测试。https://github.com/symfony/symfony/issues/37936
更新:我们必须等待api-platform捆绑包的发布。https://github.com/api-platform/core/issues/3683
发布于 2020-08-27 15:40:06
暂时,您可以将此代码添加到composer.json:
"conflict": {
...
"doctrine/common": ">=3.0",
"doctrine/persistence": "<1.3"
}这对我很管用。https://github.com/api-platform/core/issues/3683#issuecomment-681039267
https://stackoverflow.com/questions/63576790
复制相似问题