diff --git a/composer.json b/composer.json index 130d9ef8da..162145fc9e 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "doctrine/dbal": "^2.13.1 || ^3.2", "doctrine/doctrine-bundle": "^2.3", "doctrine/mongodb-odm": "^2.3", - "doctrine/orm": "^2.10.2", + "doctrine/orm": "^2.14.0", "friendsofphp/php-cs-fixer": "^3.4.0 <3.10", "nesbot/carbon": "^2.55", "phpstan/phpstan": "^1.10.2", diff --git a/doc/annotations.md b/doc/annotations.md index eef18f9d6e..49c9014aa9 100644 --- a/doc/annotations.md +++ b/doc/annotations.md @@ -149,7 +149,7 @@ $evm->addEventSubscriber($sortableListener); // mysql set names UTF-8 if required $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit()); // DBAL connection -$connection = array( +$driverParams = array( 'driver' => 'pdo_mysql', 'host' => '127.0.0.1', 'dbname' => 'test', @@ -157,7 +157,8 @@ $connection = array( 'password' => '' ); // Finally, create entity manager -$em = Doctrine\ORM\EntityManager::create($connection, $config, $evm); +$connection = DriverManager::getConnection($driverParams, $config); +$em = new EntityManager($connection, $config, $evm); ``` **Note:** that Symfony StofDoctrineExtensionsBundle does it automatically this diff --git a/example/em.php b/example/em.php index 3bc8863652..d0cf1bafda 100644 --- a/example/em.php +++ b/example/em.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; @@ -154,4 +155,5 @@ $config->setResultCache($cache); // Finally, we create the entity manager -return EntityManager::create($connection, $config, $eventManager); +$connection = DriverManager::getConnection($connection, $config); +$em = new EntityManager($connection, $config, $eventManager); diff --git a/tests/Gedmo/Mapping/LoggableORMMappingTest.php b/tests/Gedmo/Mapping/LoggableORMMappingTest.php index 1fce3b345e..e6ddb83c3b 100644 --- a/tests/Gedmo/Mapping/LoggableORMMappingTest.php +++ b/tests/Gedmo/Mapping/LoggableORMMappingTest.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -66,7 +67,8 @@ protected function setUp(): void $loggableListener = new LoggableListener(); $loggableListener->setCacheItemPool($this->cache); $evm->addEventSubscriber($loggableListener); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } public function testLoggableMapping(): void diff --git a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php index d3851ad8cf..32383397de 100644 --- a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php +++ b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory; @@ -44,7 +45,8 @@ protected function setUp(): void 'memory' => true, ]; - $this->em = EntityManager::create($conn, $config, new EventManager()); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, new EventManager()); } public function testGetMetadataFactoryCacheFromDoctrineForSluggable(): void diff --git a/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php b/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php index ed864b4e07..d89b4d282d 100644 --- a/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php +++ b/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Mapping\MetadataFactory; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; @@ -55,7 +56,8 @@ protected function setUp(): void $this->timestampable = new TimestampableListener(); $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); $evm->addEventSubscriber($this->timestampable); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); $schemaTool = new SchemaTool($this->em); $schemaTool->dropSchema([]); diff --git a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php index 751792d153..543f3361f3 100644 --- a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php +++ b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Mapping\MetadataFactory; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; @@ -60,7 +61,8 @@ protected function setUp(): void $this->timestampable = new TimestampableListener(); $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); $evm->addEventSubscriber($this->timestampable); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } public function testShouldWork(): void diff --git a/tests/Gedmo/Mapping/SluggableMappingTest.php b/tests/Gedmo/Mapping/SluggableMappingTest.php index ffad7a04c0..4ee2a2faa2 100644 --- a/tests/Gedmo/Mapping/SluggableMappingTest.php +++ b/tests/Gedmo/Mapping/SluggableMappingTest.php @@ -13,6 +13,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -65,7 +66,8 @@ protected function setUp(): void $listener = new SluggableListener(); $listener->setCacheItemPool($this->cache); $evm->addEventSubscriber($listener); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } public function testShouldBeAbleToMapSluggableUsingYamlDriver(): void diff --git a/tests/Gedmo/Mapping/TimestampableMappingTest.php b/tests/Gedmo/Mapping/TimestampableMappingTest.php index c05e3871ca..5be367328a 100644 --- a/tests/Gedmo/Mapping/TimestampableMappingTest.php +++ b/tests/Gedmo/Mapping/TimestampableMappingTest.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Mapping; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -54,7 +55,8 @@ protected function setUp(): void $listener = new TimestampableListener(); $listener->setCacheItemPool($this->cache); $evm->addEventSubscriber($listener); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } public function testYamlMapping(): void diff --git a/tests/Gedmo/Mapping/TranslatableMappingTest.php b/tests/Gedmo/Mapping/TranslatableMappingTest.php index 2d525893e7..4e4696c71d 100644 --- a/tests/Gedmo/Mapping/TranslatableMappingTest.php +++ b/tests/Gedmo/Mapping/TranslatableMappingTest.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Mapping; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -62,7 +63,8 @@ protected function setUp(): void $this->translatableListener->setCacheItemPool($this->cache); $this->translatableListener->setTranslatableLocale('en_us'); $evm->addEventSubscriber($this->translatableListener); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } public function testYamlMapping(): void diff --git a/tests/Gedmo/Mapping/TreeMappingTest.php b/tests/Gedmo/Mapping/TreeMappingTest.php index f5ea51c986..6a9d04260d 100644 --- a/tests/Gedmo/Mapping/TreeMappingTest.php +++ b/tests/Gedmo/Mapping/TreeMappingTest.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Mapping; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -72,7 +73,8 @@ protected function setUp(): void $this->listener->setCacheItemPool($this->cache); $evm = new EventManager(); $evm->addEventSubscriber($this->listener); - $this->em = EntityManager::create($conn, $config, $evm); + $connection = DriverManager::getConnection($conn, $config); + $this->em = new EntityManager($connection, $config, $evm); } /** diff --git a/tests/Gedmo/Tool/BaseTestCaseOM.php b/tests/Gedmo/Tool/BaseTestCaseOM.php index ed99401378..be0a9d22cf 100644 --- a/tests/Gedmo/Tool/BaseTestCaseOM.php +++ b/tests/Gedmo/Tool/BaseTestCaseOM.php @@ -12,12 +12,14 @@ namespace Gedmo\Tests\Tool; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DriverManager; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver as AnnotationDriverODM; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; @@ -25,7 +27,6 @@ use Doctrine\ORM\Mapping\Driver\AttributeDriver as AttributeDriverORM; use Doctrine\ORM\Repository\DefaultRepositoryFactory as DefaultRepositoryFactoryORM; use Doctrine\ORM\Tools\SchemaTool; -use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Gedmo\Loggable\LoggableListener; use Gedmo\Sluggable\SluggableListener; @@ -128,7 +129,8 @@ protected function getDefaultMockSqliteEntityManager(array $fixtures, ?MappingDr ]; $config = $this->getMockORMConfig($mappingDriver); - $em = EntityManager::create($conn, $config, $this->getEventManager()); + $connection = DriverManager::getConnection($conn, $config); + $em = new EntityManager($connection, $config, $this->getEventManager()); $schema = array_map(static function (string $class) use ($em): ClassMetadata { assert(class_exists($class)); diff --git a/tests/Gedmo/Tool/BaseTestCaseORM.php b/tests/Gedmo/Tool/BaseTestCaseORM.php index a1d534b4d8..aef4a48ab6 100644 --- a/tests/Gedmo/Tool/BaseTestCaseORM.php +++ b/tests/Gedmo/Tool/BaseTestCaseORM.php @@ -13,6 +13,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\Middleware; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; @@ -73,7 +74,8 @@ protected function getDefaultMockSqliteEntityManager(?EventManager $evm = null, ]; $config = $config ?? $this->getDefaultConfiguration(); - $em = EntityManager::create($conn, $config, $evm ?? $this->getEventManager()); + $connection = DriverManager::getConnection($conn, $config); + $em = new EntityManager($connection, $config, $evm ?? $this->getEventManager()); $schema = array_map(static function (string $class) use ($em): ClassMetadata { return $em->getClassMetadata($class);