Skip to content

Commit

Permalink
EntityManager::create() no longer exists in Doctrine ORM 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 8, 2024
1 parent 8e8728c commit 4f572f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ parameters:
-
message: '#^Call to method getProperty\(\) on an unknown class PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionEnum\.$#'
path: src/Rules/Gedmo/PropertiesExtension.php
-
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\EntityManager'' and ''create'' will always evaluate to true\.$#'
path: src/Doctrine/Mapping/ClassMetadataFactory.php
reportUnmatched: false
8 changes: 7 additions & 1 deletion src/Doctrine/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use function class_exists;
use function count;
use function method_exists;
use const PHP_VERSION_ID;

class ClassMetadataFactory extends \Doctrine\ORM\Mapping\ClassMetadataFactory
Expand Down Expand Up @@ -47,7 +48,12 @@ protected function initialize(): void
'memory' => true,
], $config);

$em = EntityManager::create($connection, $config);
if (!method_exists(EntityManager::class, 'create')) {
$em = new EntityManager($connection, $config);
} else {
$em = EntityManager::create($connection, $config);
}

$this->setEntityManager($em);
parent::initialize();

Expand Down

0 comments on commit 4f572f8

Please sign in to comment.