public function save($entity, $silent = null)
{
try {
if ($existing = $entity->getId()) {
$creating = false;
} else {
$creating = true;
}
} catch (\Exception $e) {
$creating = $existing = false;
}
if ($silent === null) {
$event = new StorageEvent($entity, ['create' => $creating]);
$this->event()->dispatch(StorageEvents::PRE_SAVE, $event);
}
if ($existing) {
$response = $this->update($entity);
} else {
$response = $this->insert($entity);
}
if ($silent === null) {
$this->event()->dispatch(StorageEvents::POST_SAVE, $event);
}
return $response;
}