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

Stop using deprecated method Connection::getEventManager #1349

Closed
wants to merge 2 commits into from
Closed
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
36 changes: 35 additions & 1 deletion lib/Doctrine/Migrations/DependencyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Doctrine\Migrations;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\Deprecations\Deprecation;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Connection\ConnectionLoader;
use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader;
Expand Down Expand Up @@ -79,18 +81,37 @@ class DependencyFactory

private ?EntityManagerLoader $emLoader = null;

private ?EventManager $eventManager = null;

/** @var callable[] */
private array $factories = [];

public static function fromConnection(
ConfigurationLoader $configurationLoader,
ConnectionLoader $connectionLoader,
EventManager|LoggerInterface|null $eventManager = null,
?LoggerInterface $logger = null
): self {
if (! $eventManager instanceof EventManager) {
Deprecation::trigger(
'doctrine/migrations',
'https://github.com/doctrine/migrations/issues/1348',
'Not passing a %s as third argument of the method %s is deprecated.',
EventManager::class,
__METHOD__,
);

$logger = $eventManager;
}

$dependencyFactory = new self($logger);
$dependencyFactory->configurationLoader = $configurationLoader;
$dependencyFactory->connectionLoader = $connectionLoader;

if ($eventManager instanceof EventManager) {
$dependencyFactory->eventManager = $eventManager;
}

return $dependencyFactory;
}

Expand Down Expand Up @@ -200,11 +221,24 @@ public function getEventDispatcher(): EventDispatcher
return $this->getDependency(EventDispatcher::class, function (): EventDispatcher {
return new EventDispatcher(
$this->getConnection(),
$this->getConnection()->getEventManager(),
$this->getEventManager(),
);
});
}

private function getEventManager(): EventManager
{
if ($this->eventManager === null) {
if ($this->hasEntityManager()) {
$this->eventManager = $this->getEntityManager()->getEventManager();
} else {
$this->eventManager = $this->getConnection()->getEventManager();
}
}

return $this->eventManager;
}

public function getClassNameGenerator(): ClassNameGenerator
{
return $this->getDependency(ClassNameGenerator::class, static function (): ClassNameGenerator {
Expand Down