Skip to content

Commit

Permalink
[doctrineGH-6855] Prevent unsupported lifecycle callback mapping on e…
Browse files Browse the repository at this point in the history
…mbedded classes.
  • Loading branch information
beberlei committed Dec 7, 2020
1 parent 242cf1a commit aee9efa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
}

0 comments on commit aee9efa

Please sign in to comment.