Skip to content

Commit

Permalink
Merge pull request #5788 from morozov/remove-event-manager
Browse files Browse the repository at this point in the history
Remove extension via Doctrine Event Manager
  • Loading branch information
morozov authored Oct 22, 2022
2 parents 340a882 + a478111 commit 0c4f7ea
Show file tree
Hide file tree
Showing 43 changed files with 95 additions and 2,015 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"php": "^8.1",
"composer-runtime-api": "^2",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1|^2",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
Expand Down
65 changes: 0 additions & 65 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,15 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaAlterTableEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaCreateTableEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaDropTableEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\TransactionEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\TransactionBeginEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\TransactionCommitEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\TransactionRollBackEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\ConnectionEventArgs"/>
<referencedClass name="Doctrine\DBAL\Event\Listeners\OracleSessionInit"/>
<referencedClass name="Doctrine\DBAL\Event\Listeners\SQLSessionInit"/>
<referencedClass name="Doctrine\DBAL\Event\Listeners\SQLiteSessionInit"/>
<referencedClass name="Doctrine\DBAL\Events"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedConstant>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<file name="src/Connection.php"/>
<file name="src/Connections/PrimaryReadReplicaConnection.php"/>
<file name="src/Event/Listeners/OracleSessionInit.php"/>
<file name="src/Event/Listeners/SQLSessionInit.php"/>
<file name="src/Event/Listeners/SQLiteSessionInit.php"/>
<file name="src/Platforms/AbstractPlatform.php"/>
<file name="src/Schema/AbstractSchemaManager.php"/>
<file name="tests/ConnectionTest.php"/>
<file name="tests/Events/OracleSessionInitTest.php"/>
<file name="tests/Events/SQLSessionInitTest.php"/>
<file name="tests/Functional/Schema/SchemaManagerFunctionalTestCase.php"/>
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
</errorLevel>
</DeprecatedConstant>
<DeprecatedMethod>
<errorLevel type="suppress">
<!--
This suppression should be removed after 2022
See https://github.com/doctrine/dbal/pull/4317
-->
<file name="tests/Functional/LegacyAPITest.php"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::getConnection"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::setEventManager"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedProperty name="Doctrine\DBAL\Connection::$_eventManager"/>
<referencedProperty name="Doctrine\DBAL\Platforms\AbstractPlatform::$_eventManager"/>
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!--
Expand Down
97 changes: 7 additions & 90 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\DBAL;

use Closure;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\ArrayResult;
use Doctrine\DBAL\Cache\CacheException;
use Doctrine\DBAL\Cache\Exception\NoResultDriverConfigured;
Expand All @@ -14,9 +13,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Event\TransactionBeginEventArgs;
use Doctrine\DBAL\Event\TransactionCommitEventArgs;
use Doctrine\DBAL\Event\TransactionRollBackEventArgs;
use Doctrine\DBAL\Exception\CommitFailedRollbackOnly;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\DriverException;
Expand All @@ -43,7 +39,7 @@
use function sprintf;

/**
* A database abstraction-level connection that implements features like events, transaction isolation levels,
* A database abstraction-level connection that implements features like transaction isolation levels,
* configuration, emulated transaction nesting, lazy connecting and more.
*
* @psalm-import-type Params from DriverManager
Expand Down Expand Up @@ -73,9 +69,6 @@ class Connection implements ServerVersionProvider

protected Configuration $_config;

/** @deprecated */
protected EventManager $_eventManager;

/**
* The current auto-commit mode of this connection.
*/
Expand Down Expand Up @@ -117,23 +110,20 @@ class Connection implements ServerVersionProvider
*
* @internal The connection can be only instantiated by the driver manager.
*
* @param array<string, mixed> $params The connection parameters.
* @param Driver $driver The driver to use.
* @param Configuration|null $config The configuration, optional.
* @param EventManager|null $eventManager The event manager, optional.
* @param array<string, mixed> $params The connection parameters.
* @param Driver $driver The driver to use.
* @param Configuration|null $config The configuration, optional.
* @psalm-param Params $params
* @phpstan-param array<string,mixed> $params
*/
public function __construct(
array $params,
protected Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null,
) {
$this->_config = $config ?? new Configuration();
$this->_eventManager = $eventManager ?? new EventManager();
$this->params = $params;
$this->autoCommit = $this->_config->getAutoCommit();
$this->_config = $config ?? new Configuration();
$this->params = $params;
$this->autoCommit = $this->_config->getAutoCommit();
}

/**
Expand Down Expand Up @@ -185,23 +175,6 @@ public function getConfiguration(): Configuration
return $this->_config;
}

/**
* Gets the EventManager used by the Connection.
*
* @deprecated
*/
public function getEventManager(): EventManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'%s is deprecated.',
__METHOD__,
);

return $this->_eventManager;
}

/**
* Gets the DatabasePlatform for the connection.
*
Expand All @@ -217,7 +190,6 @@ public function getDatabasePlatform(): AbstractPlatform
}

$this->platform = $this->driver->getDatabasePlatform($versionProvider);
$this->platform->setEventManager($this->_eventManager);
}

return $this->platform;
Expand Down Expand Up @@ -252,18 +224,6 @@ protected function connect(): DriverConnection
$this->beginTransaction();
}

if ($this->_eventManager->hasListeners(Events::postConnect)) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'Subscribing to %s events is deprecated. Implement a middleware instead.',
Events::postConnect,
);

$eventArgs = new Event\ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
}

return $connection;
}

Expand Down Expand Up @@ -1026,21 +986,6 @@ public function beginTransaction(): void
} else {
$this->createSavepoint($this->_getNestedTransactionSavePointName());
}

$eventManager = $this->getEventManager();

if (! $eventManager->hasListeners(Events::onTransactionBegin)) {
return;
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'Subscribing to %s events is deprecated.',
Events::onTransactionBegin,
);

$eventManager->dispatchEvent(Events::onTransactionBegin, new TransactionBeginEventArgs($this));
}

/** @throws Exception */
Expand Down Expand Up @@ -1068,19 +1013,6 @@ public function commit(): void

--$this->transactionNestingLevel;

$eventManager = $this->getEventManager();

if ($eventManager->hasListeners(Events::onTransactionCommit)) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'Subscribing to %s events is deprecated.',
Events::onTransactionCommit,
);

$eventManager->dispatchEvent(Events::onTransactionCommit, new TransactionCommitEventArgs($this));
}

if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) {
return;
}
Expand Down Expand Up @@ -1135,21 +1067,6 @@ public function rollBack(): void
$this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
--$this->transactionNestingLevel;
}

$eventManager = $this->getEventManager();

if (! $eventManager->hasListeners(Events::onTransactionRollBack)) {
return;
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'Subscribing to %s events is deprecated.',
Events::onTransactionRollBack,
);

$eventManager->dispatchEvent(Events::onTransactionRollBack, new TransactionRollBackEventArgs($this));
}

/**
Expand Down
26 changes: 3 additions & 23 deletions src/Connections/PrimaryReadReplicaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

namespace Doctrine\DBAL\Connections;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Statement;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;

use function array_rand;
Expand Down Expand Up @@ -100,12 +96,8 @@ class PrimaryReadReplicaConnection extends Connection
* @psalm-param Params $params
* @phpstan-param array<string,mixed> $params
*/
public function __construct(
array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null,
) {
public function __construct(array $params, Driver $driver, ?Configuration $config = null)
{
if (! isset($params['replica'], $params['primary'])) {
throw new InvalidArgumentException('primary or replica configuration missing');
}
Expand All @@ -124,7 +116,7 @@ public function __construct(

$this->keepReplica = ! empty($params['keepReplica']);

parent::__construct($params, $driver, $config, $eventManager);
parent::__construct($params, $driver, $config);
}

/**
Expand Down Expand Up @@ -191,18 +183,6 @@ protected function performConnect(?string $connectionName = null): DriverConnect
$this->connections['replica'] = $this->_conn = $this->connectTo($connectionName);
}

if ($this->_eventManager->hasListeners(Events::postConnect)) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'Subscribing to %s events is deprecated. Implement a middleware instead.',
Events::postConnect,
);

$eventArgs = new ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
}

return $this->_conn;
}

Expand Down
19 changes: 6 additions & 13 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\DBAL;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\OCI8;
Expand Down Expand Up @@ -133,8 +132,7 @@ private function __construct()
* <b>driverClass</b>:
* The driver class to use.
*
* @param Configuration|null $config The configuration to use.
* @param EventManager|null $eventManager The event manager to use.
* @param Configuration|null $config The configuration to use.
* @psalm-param array{
* charset?: string,
* dbname?: string,
Expand Down Expand Up @@ -162,15 +160,10 @@ private function __construct()
*
* @template T of Connection
*/
public static function getConnection(
array $params,
?Configuration $config = null,
?EventManager $eventManager = null,
): Connection {
// create default config and event manager, if not set
$config ??= new Configuration();
$eventManager ??= new EventManager();
$params = self::parseDatabaseUrl($params);
public static function getConnection(array $params, ?Configuration $config = null): Connection
{
$config ??= new Configuration();
$params = self::parseDatabaseUrl($params);

// URL support for PrimaryReplicaConnection
if (isset($params['primary'])) {
Expand Down Expand Up @@ -199,7 +192,7 @@ public static function getConnection(
$wrapperClass = $params['wrapperClass'];
}

return new $wrapperClass($params, $driver, $config, $eventManager);
return new $wrapperClass($params, $driver, $config);
}

/**
Expand Down
Loading

0 comments on commit 0c4f7ea

Please sign in to comment.