Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Created January 28, 2020 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMorel/14f91b4dbd21bf805c0a8c27c413a67b to your computer and use it in GitHub Desktop.
Save BenMorel/14f91b4dbd21bf805c0a8c27c413a67b to your computer and use it in GitHub Desktop.
A Symfony compiler pass to set the default transaction isolation level on Doctrine\DBAL\Connection
<?php
declare(strict_types=1);
namespace App;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\TransactionIsolationLevel;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class DoctrineCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$container
->getDefinition('doctrine.dbal.default_connection')
->setConfigurator([self::class, 'setDefaultTransactionIsolationLevel']);
}
public static function setDefaultTransactionIsolationLevel(Connection $connection) : void
{
$connection->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment