2017 © Pedro Peláez
 

library doctrine-orm-module

doctrine/orm module for Ray.Di

image

ray/doctrine-orm-module

doctrine/orm module for Ray.Di

  • Thursday, September 1, 2016
  • by kawanamiyuu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 265 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Ray.DoctrineOrmModule

Scrutinizer Code Quality Code Coverage Build Status Packagist Packagist, (*1)

A Doctrine ORM Module for Ray.Di, (*2)

Installation

Composer install

$ composer require ray/doctrine-orm-module

Module install

use Ray\Di\AbstractModule;
use Ray\DoctrineOrmModule\EntityManagerModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $entityDir = '/path/to/Entity/';

        $params = [
            'driver'   => 'pdo_pgsql',
            'user'     => 'username',
            'password' => 'password',
            'host'     => '127.0.0.1'
            'port'     => '5432',
            'dbname'   => 'myapp_db'
        ];

        $this->install(new EntityManagerModule($params, $entityDir));

        //// OR ////

        $params = [
            'url' => 'postgresql://username:password@127.0.0.1:5432/myapp_db'
        ];

        $this->install(new EntityManagerModule($params, $entityDir));
    }
}

Learn more about the database connection configuration., (*3)

DI trait

Transaction management

First, install TransactionalModule., (*4)

use Ray\Di\AbstractModule;
use Ray\DoctrineOrmModule\EntityManagerModule;
use Ray\DoctrineOrmModule\TransactionalModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new EntityManagerModule($params, $entityDir));

        $this->install(new TransactionalModule); // <--
    }
}

Any method in the class marked with @Transactional is executed in a transaction., (*5)

use Ray\DoctrineOrmModule\Annotation\Transactional;
use Ray\DoctrineOrmModule\EntityManagerInject;

/**
 * @Transactional
 */
class UserService
{
    use EntityManagerInject;

    public function foo()
    {
        // transaction is active
        $this->entityManager->...;
    }

    public function bar()
    {
        // transaction is active
        $this->entityManager->...;
    }
}

The method marked with @Transactional is executed in a transaction., (*6)

use Ray\DoctrineOrmModule\Annotation\Transactional;
use Ray\DoctrineOrmModule\EntityManagerInject;

class UserService
{
    use EntityManagerInject;

    /**
     * @Transactional
     */
    public function foo()
    {
        // transaction is active
        $this->entityManager->...;
    }

    public function bar()
    {
        // transaction is not active
        $this->entityManager->...;
    }
}

Generating Proxy classes (for production)

Proxy classes improve the performance in a production environment. If you bind ProxyDir, proxy classes are automatically generated into the directory when they are used the first time., (*7)

use Ray\Di\AbstractModule;
use Ray\DoctrineOrmModule\Annotation\ProxyDir;
use Ray\DoctrineOrmModule\EntityManagerModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->bind()->annotatedWith(ProxyDir::class)->toInstance('/path/to/proxy'); // <--

        $this->install(new EntityManagerModule($params, $entityDir));
    }
}

Learn more about the Proxy Object., (*8)

Logging queries

If you want to log queries, you additionally need to bind Psr\Log\LoggerInterface and install SqlLoggerModule., (*9)

use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Ray\Di\AbstractModule;
use Ray\DoctrineOrmModule\EntityManagerModule;
use Ray\DoctrineOrmModule\SqlLoggerModule;
use Ray\DoctrineOrmModule\TransactionalModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new EntityManagerModule($params, $entityDir));
        $this->install(new TransactionalModule);

        $this->bind(LoggerInterface::class)->toInstance(new Logger('myapp')); // <--
        $this->install(new SqlLoggerModule); // <--
    }
}

Demo

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

Requirements

  • PHP 5.6+
  • hhvm

The Versions

01/09 2016

1.x-dev

1.9999999.9999999.9999999-dev

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

01/09 2016

1.5.0

1.5.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

25/08 2016

1.4.0

1.4.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

13/07 2016

1.3.0

1.3.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

30/01 2016

1.2.0

1.2.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

23/01 2016

1.1.0

1.1.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di

16/01 2016

1.0.0

1.0.0.0

doctrine/orm module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

doctrine orm ray.di