Beispiel #1
0
 /**
  * Returns the persistent object of class $class with id $id or null.
  *
  * This method is equivalent to {@link load()} except that it returns null
  * instead of throwing an exception, if the desired object does not exist.
  * A null value will not be recorded in the identity map, so a second
  * attempt to load the object of $class with $id will result in another
  * database query.
  *
  * @param string $class
  * @param int $id
  *
  * @return ezcPersistentObject|null
  */
 public function loadIfExists($class, $id)
 {
     $idMap = $this->properties['identityMap'];
     if (!$this->properties['options']->refetch) {
         $identity = $idMap->getIdentity($class, $id);
         if ($identity !== null) {
             return $identity;
         }
     }
     $identity = $this->session->loadIfExists($class, $id);
     if ($identity !== null) {
         $idMap->setIdentity($identity);
     }
     return $identity;
 }