Skip to content

Commit 4f572f8

Browse files
committed
EntityManager::create() no longer exists in Doctrine ORM 3
1 parent 8e8728c commit 4f572f8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ parameters:
3737
-
3838
message: '#^Call to method getProperty\(\) on an unknown class PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionEnum\.$#'
3939
path: src/Rules/Gedmo/PropertiesExtension.php
40+
-
41+
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\EntityManager'' and ''create'' will always evaluate to true\.$#'
42+
path: src/Doctrine/Mapping/ClassMetadataFactory.php
43+
reportUnmatched: false

src/Doctrine/Mapping/ClassMetadataFactory.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
1313
use function class_exists;
1414
use function count;
15+
use function method_exists;
1516
use const PHP_VERSION_ID;
1617

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

50-
$em = EntityManager::create($connection, $config);
51+
if (!method_exists(EntityManager::class, 'create')) {
52+
$em = new EntityManager($connection, $config);
53+
} else {
54+
$em = EntityManager::create($connection, $config);
55+
}
56+
5157
$this->setEntityManager($em);
5258
parent::initialize();
5359

0 commit comments

Comments
 (0)