Skip to content

Commit c11d2c2

Browse files
committed
Fix #32 Undefined Index check
1 parent 9d97a9d commit c11d2c2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Subscriber/DoctrineSubscriber.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function postRemove(LifecycleEventArgs $args)
7777
{
7878
$identity = $this->getToBeDeletedId($args->getEntity());
7979

80-
if ($identity) {
80+
if (null !== $identity) {
8181
$this->container->get('event_dispatcher')->dispatch(DoctrineEvents::ENTITY_DELETED,
8282
new DoctrineEntityEvent($args, $identity)
8383
);
@@ -86,11 +86,11 @@ public function postRemove(LifecycleEventArgs $args)
8686

8787
private function getToBeDeletedId($entity)
8888
{
89-
try{
89+
if($this->isScheduledForDelete($entity)) {
9090
return $this->toBeDeleted[ClassUtils::getClass($entity)][spl_object_hash($entity)];
91-
}catch (\Exception $exception) {
92-
return false;
9391
}
92+
93+
return null;
9494
}
9595

9696
/**
@@ -225,4 +225,15 @@ protected function getIdentity(LifecycleEventArgs $args, $className)
225225
{
226226
return $args->getEntityManager()->getClassMetadata($className)->getIdentifierValues($args->getEntity());
227227
}
228+
229+
/**
230+
* @param $entity
231+
* @return boolean
232+
*/
233+
private function isScheduledForDelete($entity)
234+
{
235+
$originalClassName = ClassUtils::getClass($entity);
236+
237+
return isset($this->toBeDeleted[$originalClassName]) && isset($this->toBeDeleted[$originalClassName][spl_object_hash($entity)]);
238+
}
228239
}

0 commit comments

Comments
 (0)