execute any function in Extension

Notice: This thread is very old.
fan2misa
Member | 6
+
0
-

Hi everybody ^^,

I want to install Doctrine 2 in Nette Framework. And I want to set Entity Namespace.
I wrote this in config.neon :

production:
    parameters:
        database:
            driver: pdo_mysql
            host: localhost
            user: root
            password:
            dbname: test

    php:
        date.timezone: Europe/Paris

...

    doctrine:
        entities:
            Backend: /App/Backend/Model
            Frontend: /App/Frontend/Model
...

And I wrote this in app/bootstrap.php :

...
$configurator->onCompile[] = function ($configurator, $compiler) {
    $compiler->addExtension('doctrine', new App\lib\Config\Doctrine());
};
...

And I have this in app/lib/Config/Doctrine :

namespace App\lib\Config;

use Nette\DI\CompilerExtension;

class Doctrine extends CompilerExtension {

    public function loadConfiguration() {
        $config = $this->getConfig();
        $this->getContainerBuilder()
                ->addDefinition($this->prefix('configuration'))
                ->setFactory('\Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration', array($config['entities'], false));
    }

}

And in this loadConfiguration() function, I need instance of \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration for execute method setEntityNamespace()

Could you help me for this problem ? Thx

Majkl578
Moderator | 1364
+
0
-

Have a look at Kdyby/Doctrine (docs), an integration of Doctrine 2 to Nette. It's probably the best solution out in the wild right now. You don't necessarily use every part of it, it is good even as just a bridge between these two frameworks.