ZF2 + doctrine without composer

為{幸葍}努か 提交于 2020-01-28 11:11:57

问题


I have a working ZF2 (skeleton) application and want to integrate Doctrine.

I have downloaded the 2 modules (DoctrineModule and DoctrineORMModule) from github as I'm unable to use composer (so please don't answer with; "get composer").

After hours of trying to find the problem I keep getting the following error:

Fatal error: Class 'Doctrine\Common\Annotations\AnnotationRegistry' not found in doctrine/DoctrineModule/src/DoctrineModule/Module.php on line 54.

I have spend hours of searching and trying to debug but I can't find a way to fix it. Please help me.


回答1:


DoctrineORMModule does not explicitly support autoloading without composer (since it's a mess).

As of current (0.7.*) version of DoctrineORMModule, the required packages are following:

  • doctrine/common (2.3.0)
  • doctrine/dbal (2.3.2)
  • symfony/console (v2.1.7)
  • doctrine/orm (2.3.2)
  • doctrine/doctrine-module (0.7.*)
  • doctrine/doctrine-orm-module (0.7.0)

What you can do is defining all the autoloading namespaces in init_autoloader.php in your skeleton application (explaining the mess). The code to replace is the part about the autoloader factory:

Zend\Loader\AutoloaderFactory::factory(array(
    'Zend\Loader\StandardAutoloader' => array(
        'autoregister_zf' => true,
        'namespaces' => array(
            'Doctrine\Common'   => __DIR__ . '/vendor/doctrine/common',
            'Doctrine\DBAL'     => __DIR__ . '/vendor/doctrine/dbal',
            'Symfony\Console'   => __DIR__ . '/vendor/symfony/console',
            'DoctrineModule'    => __DIR__ . '/vendor/doctrine/doctrine-module',
            'DoctrineORMModule' => __DIR__ . '/vendor/doctrine/doctrine-orm-module',
        ),
    ),
));

You will have to configure the various git submodules on your own

As of version 0.8.* of the modules, the dependencies will increase quite a bit because of how doctrine/common was splitted recently, so consider finding a solution to start using composer or you will just be delaying huge problems in future.

This solution should work for now.




回答2:


Try to edit the following method in the Module.php of the Application module:

public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                'Doctrine' => //Path where your doctrine dist resides
            ),
        ),
    );
}

There is no need to define autoloading configuration for DoctrineModule and DoctrineORMModule because this are ZF2 modules and are providing autoloading configuration already.




回答3:


Form annotations require Doctrine\Common, which contains an annotation parsering engine. The simplest way to install Doctrine\Common is if you are using Composer; simply update your composer.json and add the following line to the require section:

"doctrine/common": ">=2.1", Then run php composer.phar update to install the dependency.

If you’re not using Composer, visit the Doctrine project website for more details on installation.



来源:https://stackoverflow.com/questions/14979381/zf2-doctrine-without-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!