getById() public method

public getById ( $id )
Example #1
0
 public function getById($id)
 {
     if ($id === NULL) {
         return NULL;
     } elseif ($id instanceof IEntity) {
         $id = $id->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) {
         return NULL;
     } elseif ($entity instanceof IEntity) {
         return $entity;
     }
     $entity = $this->findAll()->getBy(['id' => $id]);
     if ($entity === NULL) {
         $this->identityMap->remove($id);
     }
     return $entity;
 }