- Minor code cleaning
This commit is contained in:
1 parent
75fb7ba155
commit
7954d83f52
1 file changed
+7
-13
+7
-13
@@ -158,26 +158,20 @@ class Repository implements RepositoryInterface
|
|||||||
throw new \Exception("Your entity class `" . get_class($entity) . "` cannot match entity type of repository `{$this->entityClass}`");
|
throw new \Exception("Your entity class `" . get_class($entity) . "` cannot match entity type of repository `{$this->entityClass}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
$primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField();
|
if ($primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField()) {
|
||||||
|
|
||||||
if ( $primaryKeyDefinition !== null ) {
|
|
||||||
$pkField = key($primaryKeyDefinition);
|
$pkField = key($primaryKeyDefinition);
|
||||||
|
|
||||||
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
||||||
|
|
||||||
return $this->deleteFromPk($entity->$pkField);
|
return $this->deleteFromPk($entity->$pkField);
|
||||||
}
|
}
|
||||||
|
elseif ($compoundKeyFields = Ulmus::resolveEntity($this->entityClass)->getCompoundKeyFields()) {
|
||||||
|
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
||||||
|
|
||||||
|
return $this->deleteFromCompoundKeys(array_combine($compoundKeyFields->column, array_map(fn($column) => $entity->$column, $compoundKeyFields->column)));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$compoundKeyFields = Ulmus::resolveEntity($this->entityClass)->getCompoundKeyFields();
|
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
||||||
|
|
||||||
if ($compoundKeyFields) {
|
|
||||||
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
|
||||||
|
|
||||||
return $this->deleteFromCompoundKeys(array_combine($compoundKeyFields->column, array_map(fn($column) => $entity->$column, $compoundKeyFields->column)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user