ZF2 + doctrine without composer

2019-01-28 23:17发布

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.

3条回答
Summer. ? 凉城
2楼-- · 2019-01-28 23:29

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楼-- · 2019-01-28 23:35

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:

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.

查看更多
在下西门庆
4楼-- · 2019-01-28 23:36

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.

查看更多
登录 后发表回答