예제 #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;
     }
 }
예제 #2
0
 public function _refresh()
 {
     $pk = $this->_t->pk;
     $id = $this->{$pk};
     _object_cache::forget(get_class($this), $id);
     $this->__virtmembers = array();
     $this->__members = array();
     $x = $this->_t->find_first($id);
     # this will give us a freshly created duplicate
     foreach ($this->_t->columns as $f => $c) {
         # copy all the fields from the dup to this
         $this->{$f} = $x->{$f};
     }
     _object_cache::forget(get_class($this), $id);
     # forget the singleton dup
     _object_cache::store(get_class($this), $id, $this);
     # store this
 }