Zend Framework 3中Doctrine2更新导致AnnotationRegistry registerLoader错误 [英] Doctrine2 Update Caused AnnotationRegistry registerLoader Error in Zend Framework 3

查看:148
本文介绍了Zend Framework 3中Doctrine2更新导致AnnotationRegistry registerLoader错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于Zend Framework 3.0的CMS上使用Doctrine管理DBI.使用composer管理软件包时,我有什么问题?最近,我将所有软件包更新为最新版本,并将其发送到服务器,其他文件中未进行任何更改.更新后,我的网站显示以下错误:

I'm working on a CMS based on Zend Framework 3.0 to manage a DB I with Doctrine. What is my problem when managing packages with composer? Recently, I updated all the packages to newest versions and sent it to server, nothing was changed in other files. After the update my site displayed the following error:

致命错误:未捕获的类型错误:Doctrine \ Common \ Annotations \ AnnotationRegistry :: registerLoader()的返回值必须是Doctrine \ Common \ Annotations \ void的实例,在/home/platne/serwer18346/vendor/doctrine中均未返回/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:117堆栈跟踪:#0/home/platne/serwer18346/vendor/doctrine/doctrine-module/src/DoctrineModule/Module.php(57):Doctrine \ Common \ Annotations \ AnnotationRegistry :: registerLoader(Object(Closure))#1/home/platne/serwer18346/vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php(33):DoctrineModule \ Module-> init(Object( Zend \ ModuleManager \ ModuleManager))#2/home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(322):Zend \ ModuleManager \ Listener \ InitTrigger-> __ invoke(Object(Zend \ ModuleManager \ ModuleEvent))#3/home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(171):Zend \ EventManager \ EventManager-> triggerListeners(Object(Zen d \ ModuleManager \ ModuleEvent))#4/home/p在117行上的/home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php中

Fatal error: Uncaught TypeError: Return value of Doctrine\Common\Annotations\AnnotationRegistry::registerLoader() must be an instance of Doctrine\Common\Annotations\void, none returned in /home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:117 Stack trace: #0 /home/platne/serwer18346/vendor/doctrine/doctrine-module/src/DoctrineModule/Module.php(57): Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(Object(Closure)) #1 /home/platne/serwer18346/vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php(33): DoctrineModule\Module->init(Object(Zend\ModuleManager\ModuleManager)) #2 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\ModuleManager\Listener\InitTrigger->__invoke(Object(Zend\ModuleManager\ModuleEvent)) #3 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(171): Zend\EventManager\EventManager->triggerListeners(Object(Zend\ModuleManager\ModuleEvent)) #4 /home/p in /home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 117

一些需要的应用程序代码:
模块:

Some application code if needed:
modules:

return [
    'Zend\Router',
    'Zend\Validator',
    'DoctrineModule',
    'DoctrineORMModule',
    'Core',
];

development.local(开发人员模式处于活动状态):

development.local(developer mode is active):

'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' => Doctrine\DBAL\Driver\PDOMySql\Driver::class,
                'params' => [
                    'host' => '******',
                    'user' => '*******',
                    'password' => '******',
                    'dbname' => '*******',
                    'charset' => 'utf8'
                ]
            ]
        ]
    ]

module.config:

module.config:

'doctrine' => [
        'driver' => [
            __NAMESPACE__ . '_driver' => [
                'class' => AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [__DIR__.'/../src/Model']
            ],
            'orm_default' => [
                'drivers' => [
                    __NAMESPACE__ . '\Model' => __NAMESPACE__ . '_driver'
                ]
            ]
        ]
    ]

控制器工厂:

public function __invoke(ContainerInterface $container,$requestedName, array $options = null)
{
    $controllerInstance = null;
    switch($requestedName){
        case 'Core\Controller\IndexController': $controllerInstance = $this->_invokeIndex($container); break;
        case 'Core\Controller\PagesController': $controllerInstance = $this->_invokePages($container); break;
    }
    return $controllerInstance;
}

protected function _invokeIndex(ContainerInterface $container)
{
    return new Controller\IndexController(
        $container->get('doctrine.entitymanager.orm_default')
    );
}

protected function _invokePages(ContainerInterface $container)
{
    return new Controller\PagesController(
        $container->get('doctrine.entitymanager.orm_default')
    );
}

控制器父级:

 protected $_entityManager;

    /**
     * AppController constructor.
     * @param EntityManager $entityManager
     */
    public function __construct(EntityManager $entityManager)
    {
        $this->_entityManager = $entityManager;
    }

    /**
     * @return EntityManager
     */
    public function getEntityManager()
    {
        return $this->_entityManager;
    }

正如我所说,此代码在更新之前有效.更新后,它会向我显示该错误,而在上传以前的版本后,错误仍然存​​在.我尝试重写代码,但效果相同.

As I said this code worked before update. After update it show me that error, what is more after uploading previous versions the error remains. I triead rewriting code but with the same effect.

作曲家(无项目数据):

Composer(without project data):

"require": {
    "zendframework/zend-mvc": "*",
    "zendframework/zend-developer-tools": "*",
    "zendframework/zend-session": "*",
    "zendframework/zend-authentication": "*",
    "zfcampus/zf-development-mode": "*",
    "doctrine/doctrine-orm-module": "*"
  },
  "autoload": {
    "psr-4": {
      "Core\\": "module/Core/src/"
    }
  }

推荐答案

此错误是由Doctrine\Common\Annotations的最新版本引起的,请使用 PHP 7.1 .这就是为什么它将void用作return type的原因.并且它在PHP 7.0.*上不受支持.这是 PHP 7.1中的新功能

This error caused by the latest version of Doctrine\Common\Annotations use PHP 7.1. That's why it use void as return type. And it is not supported on PHP 7.0.*. This is new feature in PHP 7.1

我在使用PHP 7.0的ZF3项目中使用doctrine-orm-module 1.1.而且效果很好.因此,只需将您的doctrine-orm-module版本替换为1.1.

I use doctrine-orm-module 1.1 in my ZF3 project using PHP 7.0. And it work well. So, just replace your doctrine-orm-module version to 1.1.

"doctrine/doctrine-orm-module": "^1.1"

我建议您定义在作曲家中使用的依赖项的版本.这样做的目的是使您的项目在发布新版本的依赖项时不会损坏.

I suggest you to define the version of dependencies you used in composer. This is purposed to make your project not broken when new version of dependencies released.

这篇关于Zend Framework 3中Doctrine2更新导致AnnotationRegistry registerLoader错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆