私はDoctrineでDB Iを管理するためにZend Framework 3.0に基づいたCMSに取り組んでいます。 composerでパッケージを管理するときの私の問題は何ですか?最近、すべてのパッケージを最新バージョンに更新してサーバーに送信しましたが、他のファイルでは何も変更されていません。更新後、サイトに次のエラーが表示されました。
致命的なエラー:不明なTypeError: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(Zend\M oduleManager\ModuleEvent))#4/home/p /home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php in 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/"
}
}
Doctrine\Common\Annotations
の最新バージョンが原因でこのエラーが発生しましたPHP 7.1。 void
をreturn type
として使用するのはそのためです。また、PHP 7.0。*ではサポートされていません。これは PHP 7.1の新機能です
ZF3プロジェクトでは、PHP 7.0を使用してdoctrine-orm-module 1.1
を使用します。そしてそれはうまく機能します。したがって、doctrine-orm-module
バージョンを1.1
に置き換えるだけです。
"doctrine/doctrine-orm-module": "^1.1"
Composerで使用した依存関係のバージョンを定義することをお勧めします。これは、依存関係の新しいバージョンがリリースされたときにプロジェクトが壊れないようにすることを目的としています。
この種の問題を回避するには、composer config.platform
設定を設定することをお勧めします。
"config": {
"platform": {
"php": "7.0.23"
}
}
これにより、パッケージを更新するようcomposerに通知されますが、このPHPバージョンをまだサポートしているバージョンにのみ更新されます。したがって、通常、このバージョン番号は運用サーバーのバージョンになります。
次の構成を使用してみてください。わたしにはできる。
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "2.5.6",
"doctrine/annotations": "1.4.*",
"doctrine/dbal": "2.5.4",
...
}
また、composer/packageの問題を報告するときに非常に役立つのは、composer showの出力です。私のものは次のようになります。
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/ に移動して、問題の原因となっているパッケージを検索してください。
例えばdoctrine/annotations: https://packagist.org/packages/doctrine/annotations#v1.5.
次に、(requires:php:^ 7.1)を探し、このパッケージがお使いのPHPバージョン。(PHP 7.0は一致しません)
しかし https://packagist.org/packages/doctrine/annotations#v1.4. はPHP version(requires:php:^ 5.6 || ^ 7.0)これを使用してみることができます。
プロジェクトのcomposer.lockを削除します。「ベンダー」フォルダーも同じです。
それを実行して楽しむ->
php composer.phar selfupdate
php composer.pharインストール