2017-07-26 40 views
10

我正在開發基於Zend Framework 3.0的CMS來管理數據庫I和Doctrine。使用Composer管理包時,我的問題是什麼?最近,我將所有軟件包更新到最新版本並將其發送到服務器,其他文件中沒有任何更改。如果需要的話Zend Framework 3中造成AnnotationRegistry registerLoader錯誤的原因2更新

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' 
       ] 
      ] 
     ] 
    ] 

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

正如我所說的這個代碼更新工作過。更新後,它顯示我的錯誤,什麼是上傳以前的版本後,錯誤仍然存​​在。我重寫了代碼,但效果相同。

作曲(無項目數據):

"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/" 
    } 
    } 
+0

哪個PHP版本和您使用的這些學說的版本?你可以發佈你的composer.json嗎? – Dado

+0

我使用PHP v7.0和最新的doctrine 2 orm模塊,所以我認爲將會是1.1.3 – Manveru

回答

22

這個錯誤造成的Doctrine\Common\Annotations使用PHP 7.1最新版本。這就是爲什麼它使用void作爲return type。它在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" 

我建議你定義你在作曲家中使用的依賴的版本。這是爲了在新版本的依賴關係發佈時使您的項目不會中斷。

7

您可以嘗試使用以下配置。這個對我有用。

"require": { 
     "php": ">=5.5.9", 
     "doctrine/doctrine-bundle": "^1.6", 
     "doctrine/orm": "2.5.6", 
     "doctrine/annotations": "1.4.*", 
     "doctrine/dbal": "2.5.4", 
     ... 
    } 

也非常有幫助,當你報告作曲家/包問題是作曲家的輸出顯示。我的是這樣:

doctrine/annotations     v1.4.0 Docblock Annotations Parser 
doctrine/cache      v1.7.0 Caching library offering an object-oriented API for many cache backends 
doctrine/collections     v1.5.0 Collections Abstraction library 
doctrine/common      v2.6.2 Common Library for Doctrine projects 
doctrine/dbal      v2.5.4 Database Abstraction Layer 
doctrine/doctrine-bundle    1.6.8 Symfony DoctrineBundle 
doctrine/doctrine-cache-bundle  1.3.0 Symfony Bundle for Doctrine Cache 
doctrine/inflector     v1.2.0 Common String Manipulations with regard to casing and singular/plural rules. 
doctrine/instantiator    1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors 
doctrine/lexer      v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. 
doctrine/orm       v2.5.6 Object-Relational-Mapper for PHP 

如果你對未來有這樣的問題,請https://packagist.org/packages/並搜索包,它會引起問題。

例如學說/註釋https://packagist.org/packages/doctrine/annotations#v1.5.0

然後看看有沒有(需要:PHP:^ 7.1),如果這個包你的PHP版本相匹配。 (在使用PHP 7.0你的情況不匹配)

https://packagist.org/packages/doctrine/annotations#v1.4.0符合你的PHP版本(需要:PHP:^ 5.6 ||^7.0),你可以嘗試使用它。

+0

這對我有效 –

7

爲了避免這種問題,一個好的做法是將作曲家config.platform設置:

"config": { 
    "platform": { 
     "php": "7.0.23" 
    } 
} 

這將告訴作曲家更新軟件包,但只對仍然支持此PHP版本的版本。所以通常情況下,此版本號將是您的生產服務器的版本。

0

只需刪除項目中的composer.lock,與「vendor」文件夾相同即可。

運行的是享受 - >

PHP composer.phar自更新

PHP composer.phar安裝