Created
January 28, 2020 21:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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