Skip to content

ray-di/Ray.DbalModule

Repository files navigation

Ray.DbalModule

Scrutinizer Code Quality Code Coverage Build Status Build Status

Doctrine Dbal module for Ray.Di

Installation

Composer install

$ composer require ray/dbal-module

Module install

use BEAR\DbalModule\DbalModule;
use Ray\Di\AbstractModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new DbalModule('driver=pdo_sqlite&memory=true');
    }
}

for named binding

Set qualifer in 2nd parameter in DbalModule.

$this->install(new DbalModule('driver=pdo_sqlite&memory=true', 'log_db');

Use qualifer in @Inject.

/**
 * @Inject
 * @Named("log_db")
 */
public function setLogDb(Connection $logDb)
{
    $this->logDb = $logDb;
}

DI trait

  • DbalInject for Doctrine\DBAL\Driver\Connection interface

Demo

$ php docs/demo/run.php
// It works!