Example #1
0
 public static function singleton($o, $id = NULL, $class = NULL)
 {
     if (!is_object($o) || !$o instanceof Model) {
         throw new Exception("trying to get singleton of non-Model instance");
     }
     if (!self::$active) {
         return $o;
     }
     if (!isset($class)) {
         $class = get_class($o);
     }
     if (!isset($id)) {
         $PK = eval('$x = ' . $class . '::$__table__; return $x->pk;');
         $id = $o->{$PK};
     }
     if ($x = _object_cache::get($class, $id)) {
         return $x;
     } else {
         _object_cache::store($class, $id, $o);
         return $o;
     }
 }