/** * Register a global variable called __fu_$var & also $var if requested. * * We use this so that we have vars we can rely upon (__fu_*) and optionally short * versions that the coder can use. * * Variables that have already been declared cannot be overwritten. * * @param string name of variable * @param mixed value of variable * @param bool if true will also set a global variable by the same name * @return mixed value of variable */ function &set($k, $v, $reg_global = false) { $var_name = "__fu_{$k}"; $GLOBALS[$var_name] =& $v; if ($reg_global) { $GLOBALS[$k] =& $GLOBALS[$var_name]; } return Fu_Reg::get($k); }
/** * Singleton should be used to save memory. * It keeps 1 global object that is used by BS for each type of DB object * * @param Fu_DB_Base based object * @return Fu_DB_Association object instance */ public function singleton($class) { $instance = Fu_Reg::get("association_{$class}"); if (is_null($instance)) { $instance = Fu_Reg::set("association_{$class}", new Fu_DB_Association($dbo)); } else { // as we are restoring this object from the global register, we freeze it $instance->frozen = true; } return $instance; }
public function debug($s = null, $p = array()) { if (!(isset($this) && get_class($this) == __CLASS__)) { $instance = Fu_Reg::get("fu_db_debug"); return $instance->debug($s, $p); } if ($this->debug) { if ($s) { $this->info[] = array('sql' => $s, 'params' => $p); } else { return $this->info; } } }
function __construct($options) { $this->options = $options; $this->data_dir = ROOT . '/data'; $this->page = $_GET['p'] ? $_GET['p'] : 'index.html'; $this->page_filepath = $this->data_dir . '/' . $this->page; $this->page_exists = file_exists($this->page_filepath); $this->git = new Git($this->data_dir, $options['git_bin']); $this->dsn = 'sqlite:' . $this->data_dir . '/.sqlite.db'; $this->_check_installation(); $dbh = Fu_Reg::get('dbh'); if (!$dbh) { Fu_Reg::set('dbh', new PDO($this->dsn)); } }
/** * Will return the text of the first flash message that matches the given type. * * E.g. Fu_Feedback::get_flash('warning') * * @param string type * @return string text */ function get_flash($type = 'message') { if (!(isset($this) && get_class($this) == __CLASS__)) { $instance = Fu_Reg::get("fu_feedback"); return $instance->get_flash($type); } foreach ((array) $this->flashes as $flash) { if ($flash['type'] == $type) { return $flash['text']; } } return ''; }
public static function rollback() { $depth = (int) Fu_Reg::get('Fu_DB_Transaction_Depth'); Fu_Reg::set('Fu_DB_Transaction_Depth', $depth - 1); if ($depth > 1) { return; } else { // at the root transaction $dbh = Fu_Reg::get('dbh'); $dbh->rollback(); } }