Beispiel #1
0
 public static function singleton($o, $id = NULL, $class = NULL)
 {
     if (!self::$active) {
         return $o;
     }
     if (!is_object($o) || !$o instanceof Model) {
         throw new Exception("trying to get singleton of non-Model instance");
     }
     if (!isset($class)) {
         $class = get_class($o);
     }
     if (Model::_has_complex_primary_key($class)) {
         return $o;
     }
     if (!isset($id)) {
         $PK = Model::_simple_primary_key($o);
         $id = $o->{$PK};
     }
     if ($x = ObjectCache::get($class, $id)) {
         return $x;
     } else {
         ObjectCache::store($class, $id, $o);
         return $o;
     }
 }
Beispiel #2
0
 /**
  * Tests loading an object that is not stored actually.
  */
 public function testGetNull()
 {
     $this->assertNull($this->cache->{self::CACHE_KEY});
     $this->assertNull(ObjectCache::get(self::CACHE_KEY));
 }