Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove EntityManager::create() #10172

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Upgrade to 3.0

## BC BREAK: Removed `EntityManager::create()`

The constructor of `EntityManager` is now public and must be used instead of the `create()` method.
However, the constructor expects a `Connection` while `create()` accepted an array with connection parameters.
You can pass that array to DBAL's `Doctrine\DBAL\DriverManager::getConnection()` method to bootstrap the
connection.

## BC BREAK: Removed `QueryBuilder` methods and constants.

The following `QueryBuilder` constants and methods have been removed:
Expand Down
64 changes: 0 additions & 64 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
use Doctrine\Common\EventManager;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Exception\EntityManagerClosed;
use Doctrine\ORM\Exception\InvalidHydrationMode;
use Doctrine\ORM\Exception\ManagerException;
use Doctrine\ORM\Exception\MismatchedEventManager;
use Doctrine\ORM\Exception\MissingIdentifierField;
use Doctrine\ORM\Exception\MissingMappingDriverImplementation;
use Doctrine\ORM\Exception\ORMException;
Expand Down Expand Up @@ -638,65 +633,6 @@ public function initializeObject(object $obj): void
$this->unitOfWork->initializeObject($obj);
}

/**
* Factory method to create EntityManager instances.
*
* @deprecated Use {@see DriverManager::getConnection()} to bootstrap the connection and call the constructor.
*
* @param mixed[]|Connection $connection An array with the connection parameters or an existing Connection instance.
* @psalm-param array<string, mixed>|Connection $connection
*
* @throws DBALException
* @throws ManagerException
*/
public static function create(array|Connection $connection, Configuration $config, EventManager|null $eventManager = null): EntityManager
{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9961',
'%s() is deprecated. To boostrap a DBAL connection, call %s::getConnection() instead. Use the constructor to create an instance of %s.',
__METHOD__,
DriverManager::class,
self::class,
);

$connection = static::createConnection($connection, $config, $eventManager);

return new EntityManager($connection, $config);
}

/**
* Factory method to create Connection instances.
*
* @deprecated Use {@see DriverManager::getConnection()} to bootstrap the connection.
*
* @param mixed[]|Connection $connection An array with the connection parameters or an existing Connection instance.
* @psalm-param array<string, mixed>|Connection $connection
*
* @throws DBALException
* @throws ManagerException
*/
protected static function createConnection(array|Connection $connection, Configuration $config, EventManager|null $eventManager = null): Connection
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9961',
'%s() is deprecated, call %s::getConnection() instead.',
__METHOD__,
DriverManager::class,
);

if (is_array($connection)) {
return DriverManager::getConnection($connection, $config, $eventManager ?? new EventManager());
}

if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
throw MismatchedEventManager::create();
}

return $connection;
}

public function getFilters(): FilterCollection
{
return $this->filterCollection ??= new FilterCollection($this);
Expand Down
17 changes: 0 additions & 17 deletions lib/Doctrine/ORM/Exception/MismatchedEventManager.php

This file was deleted.

8 changes: 0 additions & 8 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ parameters:
path: lib/Doctrine/ORM/Tools/SchemaTool.php

# FIXME
-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Connection\\:\\:getEventManager\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php
-
message: "#^Static method Doctrine\\\\DBAL\\\\DriverManager\\:\\:getConnection\\(\\) invoked with 3 parameters, 1\\-2 required\\.$#"
count: 1
path: lib/Doctrine/ORM/EntityManager.php
-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Schema\\\\SchemaDiff\\:\\:toSaveSql\\(\\)\\.$#"
count: 1
Expand Down
7 changes: 4 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
</DeprecatedClass>
<DeprecatedMethod>
<errorLevel type="suppress">
<!-- Remove on 3.0.x -->
<!-- Compatibility with DBAL 3 -->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<!-- Remove on 3.0.x -->
<referencedMethod name="Doctrine\DBAL\Schema\Schema::visit"/>
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSaveSql"/>
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSql"/>
<referencedMethod name="Doctrine\ORM\EntityManager::createConnection"/>
<referencedMethod name="Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver"/>
</errorLevel>
</DeprecatedMethod>
Expand Down Expand Up @@ -150,8 +150,9 @@
</UndefinedClass>
<UndefinedMethod>
<errorLevel type="suppress">
<!-- FIXME -->
<!-- Compatibility with DBAL 3 -->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<!-- FIXME -->
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSaveSql"/>
</errorLevel>
</UndefinedMethod>
Expand Down
11 changes: 0 additions & 11 deletions tests/Doctrine/Tests/Mocks/EntityManagerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\Mocks;

use BadMethodCallException;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
Expand All @@ -13,8 +12,6 @@
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\UnitOfWork;

use function sprintf;

/**
* Special EntityManager mock used for testing purposes.
*/
Expand Down Expand Up @@ -59,12 +56,4 @@ public function getProxyFactory(): ProxyFactory
{
return $this->_proxyFactoryMock ?? parent::getProxyFactory();
}

/**
* {@inheritdoc}
*/
public static function create($connection, Configuration|null $config, EventManager|null $eventManager = null): self
{
throw new BadMethodCallException(sprintf('Call to deprecated method %s().', __METHOD__));
}
}