/**
* Removes given entity (or entity with given id) from database
*
* @param mixed $arg
* @return mixed
* @throws InvalidStateException
*/
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;
}