2
votes

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
Out of curiosity, why are you unable to use Composer? There are ways to get this to work without it, but maybe we could help you figure that out and then this wouldn't be an issue?Colin M
You'll need to add all the Doctrine namespaces correctly into the autoloader. So at least Doctrine, DoctrineModule and DoctrineORMModuleSam
Where do I need to add them (what file?) I DO have added the namespace of the module to the config and added the lines to the module.config.phpFloris
Can you explain how is it possible to be unable to use the Composer?emix

3 Answers

5
votes

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.

0
votes

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.

0
votes

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.