public function delete($arg)
{
$this->events->invokeCallbacks(Events::EVENT_BEFORE_DELETE, $arg);
if ($arg instanceof Entity) {
$this->checkEntityType($arg);
if ($arg->isDetached()) {
throw new InvalidStateException('Cannot delete detached entity.');
}
}
$result = $this->deleteFromDatabase($arg);
if ($arg instanceof Entity) {
$arg->detach();
}
$this->events->invokeCallbacks(Events::EVENT_AFTER_DELETE, $arg);
return $result;
}