問題描述
我正在開發基于 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模板網!