Skip to content

Commit

Permalink
improve DBAL 4 detection for EventManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Oct 22, 2023
1 parent 81a6bde commit 9ed091a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

use function array_merge;
use function class_exists;
use function interface_exists;
use function is_subclass_of;
use function method_exists;
use function trigger_deprecation;

use const PHP_EOL;
Expand Down Expand Up @@ -69,8 +69,8 @@ public function __construct(array $typesConfig, ?DsnParser $dsnParser = null)
*/
public function createConnection(array $params, ?Configuration $config = null, ?EventManager $eventManager = null, array $mappingTypes = [])
{
if (interface_exists(DBALException::class) && $eventManager !== null) {
throw new InvalidArgumentException('Passing an EventManager instance is not supported with DBAL 4');
if (! method_exists(Connection::class, 'getEventManager') && $eventManager !== null) {
throw new InvalidArgumentException('Passing an EventManager instance is not supported with DBAL > 3');
}

if (! $this->initialized) {
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Schema\LegacySchemaManagerFactory;
use Doctrine\ORM\Configuration as OrmConfiguration;
use Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -274,7 +273,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
$options,
new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
// event manager is only supported on DBAL < 4
class_exists(DBALException::class) ? new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)) : null,
method_exists(Connection::class, 'getEventManager') ? new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)) : null,
$connection['mapping_types'],
]);

Expand Down

0 comments on commit 9ed091a

Please sign in to comment.