public function getById($id)
{
if ($id === null) {
return null;
} elseif ($id instanceof IEntity) {
$id = $id->getValue('id');
} elseif (!(is_scalar($id) || is_array($id))) {
throw new InvalidArgumentException('Primary key value has to be a scalar.');
}
$entity = $this->identityMap->getById($id);
if ($entity === false) {
// entity was removed
return null;
} elseif ($entity instanceof IEntity) {
return $entity;
}
$entity = $this->findAll()->getBy(['id' => $id]);
if ($entity === null) {
$this->identityMap->remove($id);
}
return $entity;
}