我正在开发基于 Zend Framework 3.0 的 CMS,以使用 Doctrine 管理 DB I.使用 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:
致命错误:未捕获的类型错误:DoctrineCommonAnnotationsAnnotationRegistry::registerLoader() 的返回值必须是 DoctrineCommonAnnotationsvoid 的一个实例,在/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): DoctrineCommonAnnotationsAnnotationRegistry::registerLoader(Object(Closure)) #1/home/platne/serwer18346/vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php(33): DoctrineModuleModule->init(Object(ZendModuleManagerModuleManager)) #2/home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): ZendModuleManagerListenerInitTrigger->__invoke(Object(ZendModuleManager)ModuleEvent)) #3/home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(171): ZendEventManagerEventManager->triggerListeners(Object(Zen)dModuleManagerModuleEvent)) #4/home/p in/home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php 117 行
Fatal error: Uncaught TypeError: Return value of DoctrineCommonAnnotationsAnnotationRegistry::registerLoader() must be an instance of DoctrineCommonAnnotationsvoid, 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): DoctrineCommonAnnotationsAnnotationRegistry::registerLoader(Object(Closure)) #1 /home/platne/serwer18346/vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php(33): DoctrineModuleModule->init(Object(ZendModuleManagerModuleManager)) #2 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): ZendModuleManagerListenerInitTrigger->__invoke(Object(ZendModuleManagerModuleEvent)) #3 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(171): ZendEventManagerEventManager->triggerListeners(Object(ZendModuleManagerModuleEvent)) #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 [
'ZendRouter',
'ZendValidator',
'DoctrineModule',
'DoctrineORMModule',
'Core',
];
development.local(开发者模式已激活):
development.local(developer mode is active):
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => DoctrineDBALDriverPDOMySqlDriver::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 'CoreControllerIndexController': $controllerInstance = $this->_invokeIndex($container); break;
case 'CoreControllerPagesController': $controllerInstance = $this->_invokePages($container); break;
}
return $controllerInstance;
}
protected function _invokeIndex(ContainerInterface $container)
{
return new ControllerIndexController(
$container->get('doctrine.entitymanager.orm_default')
);
}
protected function _invokePages(ContainerInterface $container)
{
return new ControllerPagesController(
$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/"
}
}
这个错误是由最新版本的DoctrineCommonAnnotations
使用PHP 7.1引起的.这就是为什么它使用 void
作为 return type
.并且它在 PHP 7.0.* 上不受支持.这是PHP 7.1 中的新功能一个>
This error caused by the latest version of DoctrineCommonAnnotations
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"
我建议你定义你在 composer.json 中使用的依赖版本.这是为了让你的项目在新版本的依赖发布时不会被破坏.
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.
这篇关于Doctrine2 更新导致 Zend Framework 3 中的 AnnotationRegistry registerLoader 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!