1. Go to this page and download the library: Download ray/doctrine-orm-module library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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); // <--
}
}
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->...;
}
}
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->...;
}
}
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));
}
}
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); // <--
}
}
bash
$ php docs/demo/run.php
// It works!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.