php - Doctrine2 更新导致 Zend Framework 3 中 AnnotationRegistry registerLoader 错误

标签 php zend-framework doctrine-orm zend-framework3

我正在开发一个基于 Zend Framework 3.0 的 CMS,以使用 Doctrine 管理 DB I。使用 Composer 管理包时遇到什么问题?最近,我将所有软件包更新到最新版本并将其发送到服务器,其他文件没有任何更改。更新后我的网站显示以下错误:

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

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

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

development.local(开发者模式处于事件状态):

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

模块配置:

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

Controller 工厂:

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')
    );
}

Controller 父级:

 protected $_entityManager;

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

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

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

Composer (没有项目数据):

"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 作为返回类型。 PHP 7.0.* 不支持它。这是new feature in PHP 7.1

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

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

我建议您定义在composer中使用的依赖项的版本。这是为了使您的项目在新版本的依赖项发布时不会被破坏。

关于php - Doctrine2 更新导致 Zend Framework 3 中 AnnotationRegistry registerLoader 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45337962/

相关文章:

javascript - 将 AngularJS 与 Phalcon 框架混合

php - 限制可见性找到的产品?

php - 如何在 Symfony 2 的 Form (Type) 类中获取实体存储库的实例?

Symfony 2 onDelete setNull

javascript - 如何根据数字的值更改数字的颜色。 (开放使用任何标签)

php - 将数据从本地服务器插入到在线服务器

php - Zend 的多个数据库

php - zend Bootstrap : for each module

php - 按关联计数订购 DQL 连接

php - 语法错误,意外的 ')',每个循环都需要 ';'