From aee9efaa860d23f051a41c725e3dfaa918f828b3 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 7 Dec 2020 23:00:12 +0100 Subject: [PATCH] [GH-6855] Prevent unsupported lifecycle callback mapping on embedded classes. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 4 ++++ lib/Doctrine/ORM/Mapping/MappingException.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 9890c5956ee..46359f9d66c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2748,6 +2748,10 @@ public function getLifecycleCallbacks($event) */ public function addLifecycleCallback($callback, $event) { + if ($this->isEmbeddedClass) { + throw MappingException::embeddedClassesDontSupportLifecycleCallbacks($this->name); + } + if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) { return; } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 7044e964626..d3a041bdaf0 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -834,4 +834,12 @@ public static function illegalOverrideOfInheritedProperty($className, $propertyN ) ); } + + public static function embeddedClassesDontSupportLifecycleCallbacks(string $className): MappingException + { + return new self(sprintf( + "Lifecycle callback methods are not supported on embedded class '%s'.", + $className + )); + } }