From 84e78b8200ed39c6a820a5f6f78f07defa947659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 4 Jan 2023 21:16:16 +0100 Subject: [PATCH] Remove deprecated methods and classes This is a follow-up for https://github.com/doctrine/orm/pull/9876 --- UPGRADE.md | 18 ++++- lib/Doctrine/ORM/Event/LifecycleEventArgs.php | 72 ------------------- lib/Doctrine/ORM/Event/OnClearEventArgs.php | 17 ----- lib/Doctrine/ORM/Event/OnFlushEventArgs.php | 19 ----- lib/Doctrine/ORM/Event/PostFlushEventArgs.php | 19 ----- lib/Doctrine/ORM/Event/PostLoadEventArgs.php | 4 ++ .../ORM/Event/PostPersistEventArgs.php | 4 ++ .../ORM/Event/PostRemoveEventArgs.php | 4 ++ .../ORM/Event/PostUpdateEventArgs.php | 4 ++ lib/Doctrine/ORM/Event/PreFlushEventArgs.php | 17 ----- .../ORM/Event/PrePersistEventArgs.php | 4 ++ lib/Doctrine/ORM/Event/PreRemoveEventArgs.php | 4 ++ lib/Doctrine/ORM/Event/PreUpdateEventArgs.php | 3 + psalm.xml | 1 - .../ORM/Functional/Ticket/DDC2996Test.php | 2 +- 15 files changed, 45 insertions(+), 147 deletions(-) delete mode 100644 lib/Doctrine/ORM/Event/LifecycleEventArgs.php diff --git a/UPGRADE.md b/UPGRADE.md index b78f85375a..7042424c55 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,21 @@ # Upgrade to 3.0 +## Removed `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs` + +Use `getObjectManager()` instead. + +## BC BREAK: Removed `Doctrine\ORM\Event\LifecycleEventArgs` class. + +Use one of the dedicated event classes instead: + +* `Doctrine\ORM\Event\PrePersistEventArgs` +* `Doctrine\ORM\Event\PreUpdateEventArgs` +* `Doctrine\ORM\Event\PreRemoveEventArgs` +* `Doctrine\ORM\Event\PostPersistEventArgs` +* `Doctrine\ORM\Event\PostUpdateEventArgs` +* `Doctrine\ORM\Event\PostRemoveEventArgs` +* `Doctrine\ORM\Event\PostLoadEventArgs` + ## BC BREAK: Removed `AttributeDriver::$entityAnnotationClasses` and `AttributeDriver::getReader()` * If you need to change the behavior of `AttributeDriver::isTransient()`, @@ -180,7 +196,7 @@ class MyStrategy implements NamingStrategy } ``` -## BC BREAK: Remove `StaticPHPDriver` and `DriverChain` +## BC BREAK: Remove `StaticPHPDriver` and `DriverChain` Use `Doctrine\Persistence\Mapping\Driver\StaticPHPDriver` and `Doctrine\Persistence\Mapping\Driver\MappingDriverChain` from diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php deleted file mode 100644 index 88327f03d3..0000000000 --- a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +++ /dev/null @@ -1,72 +0,0 @@ - - */ -class LifecycleEventArgs extends BaseLifecycleEventArgs -{ - /** @param object $object */ - public function __construct($object, EntityManagerInterface $objectManager) - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'The %s class is deprecated and will be removed in ORM 3.0. Use %s instead.', - self::class, - BaseLifecycleEventArgs::class, - ); - - parent::__construct($object, $objectManager); - } - - /** - * Retrieves associated Entity. - * - * @deprecated 2.13. Use {@see getObject} instead. - * - * @return object - */ - public function getEntity() - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObject() instead.', - __METHOD__, - ); - - return $this->getObject(); - } - - /** - * Retrieves associated EntityManager. - * - * @deprecated 2.13. Use {@see getObjectManager} instead. - * - * @return EntityManagerInterface - */ - public function getEntityManager() - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', - __METHOD__, - ); - - return $this->getObjectManager(); - } -} diff --git a/lib/Doctrine/ORM/Event/OnClearEventArgs.php b/lib/Doctrine/ORM/Event/OnClearEventArgs.php index ef6854b5c2..29a42f24aa 100644 --- a/lib/Doctrine/ORM/Event/OnClearEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnClearEventArgs.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Event; -use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs; @@ -17,20 +16,4 @@ */ class OnClearEventArgs extends BaseOnClearEventArgs { - /** - * Retrieves associated EntityManager. - * - * @deprecated 2.13. Use {@see getObjectManager} instead. - */ - public function getEntityManager(): EntityManagerInterface - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', - __METHOD__, - ); - - return $this->getObjectManager(); - } } diff --git a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php index 4a3a752517..b0594cac1b 100644 --- a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Event; -use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Event\ManagerEventArgs; @@ -17,22 +16,4 @@ */ class OnFlushEventArgs extends ManagerEventArgs { - /** - * Retrieve associated EntityManager. - * - * @deprecated 2.13. Use {@see getObjectManager} instead. - * - * @return EntityManagerInterface - */ - public function getEntityManager() - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', - __METHOD__, - ); - - return $this->getObjectManager(); - } } diff --git a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php index 8eb7d4f7b6..ca41ba8ee5 100644 --- a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Event; -use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Event\ManagerEventArgs; @@ -17,22 +16,4 @@ */ class PostFlushEventArgs extends ManagerEventArgs { - /** - * Retrieves associated EntityManager. - * - * @deprecated 2.13. Use {@see getObjectManager} instead. - * - * @return EntityManagerInterface - */ - public function getEntityManager() - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', - __METHOD__, - ); - - return $this->getObjectManager(); - } } diff --git a/lib/Doctrine/ORM/Event/PostLoadEventArgs.php b/lib/Doctrine/ORM/Event/PostLoadEventArgs.php index 6365f360db..8344e68133 100644 --- a/lib/Doctrine/ORM/Event/PostLoadEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostLoadEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PostLoadEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PostPersistEventArgs.php b/lib/Doctrine/ORM/Event/PostPersistEventArgs.php index 49773f8b79..926ac1c21c 100644 --- a/lib/Doctrine/ORM/Event/PostPersistEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostPersistEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PostPersistEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PostRemoveEventArgs.php b/lib/Doctrine/ORM/Event/PostRemoveEventArgs.php index 8e105a5743..8bf857e9fc 100644 --- a/lib/Doctrine/ORM/Event/PostRemoveEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostRemoveEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PostRemoveEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PostUpdateEventArgs.php b/lib/Doctrine/ORM/Event/PostUpdateEventArgs.php index 927f3c3487..c9ff00477d 100644 --- a/lib/Doctrine/ORM/Event/PostUpdateEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostUpdateEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PostUpdateEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php index 1424e46ab1..671535c960 100644 --- a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php @@ -4,7 +4,6 @@ namespace Doctrine\ORM\Event; -use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Event\ManagerEventArgs; @@ -17,20 +16,4 @@ */ class PreFlushEventArgs extends ManagerEventArgs { - /** - * @deprecated 2.13. Use {@see getObjectManager} instead. - * - * @return EntityManagerInterface - */ - public function getEntityManager() - { - Deprecation::trigger( - 'doctrine/orm', - 'https://github.com/doctrine/orm/issues/9875', - 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', - __METHOD__, - ); - - return $this->getObjectManager(); - } } diff --git a/lib/Doctrine/ORM/Event/PrePersistEventArgs.php b/lib/Doctrine/ORM/Event/PrePersistEventArgs.php index 5554ef3d75..e70c3cf736 100644 --- a/lib/Doctrine/ORM/Event/PrePersistEventArgs.php +++ b/lib/Doctrine/ORM/Event/PrePersistEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PrePersistEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PreRemoveEventArgs.php b/lib/Doctrine/ORM/Event/PreRemoveEventArgs.php index 042b737983..3af0d02930 100644 --- a/lib/Doctrine/ORM/Event/PreRemoveEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreRemoveEventArgs.php @@ -4,6 +4,10 @@ namespace Doctrine\ORM\Event; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\LifecycleEventArgs; + +/** @extends LifecycleEventArgs */ final class PreRemoveEventArgs extends LifecycleEventArgs { } diff --git a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php index c9f16fdbcb..32eaf65c08 100644 --- a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\PersistentCollection; +use Doctrine\Persistence\Event\LifecycleEventArgs; use InvalidArgumentException; use function get_debug_type; @@ -13,6 +14,8 @@ /** * Class that holds event arguments for a preUpdate event. + * + * @extends LifecycleEventArgs */ class PreUpdateEventArgs extends LifecycleEventArgs { diff --git a/psalm.xml b/psalm.xml index 21a82d88ef..db04a6dd84 100644 --- a/psalm.xml +++ b/psalm.xml @@ -23,7 +23,6 @@ - diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php index 543df7c89b..873393f870 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php @@ -76,7 +76,7 @@ class DDC2996UserPreference #[PreFlush] public function preFlush($event): void { - $em = $event->getEntityManager(); + $em = $event->getObjectManager(); $uow = $em->getUnitOfWork(); if ($uow->getOriginalEntityData($this->user)) {