/** * Scans the toolbox to determine whether the database adapter * is compatible with the current class, plugin or module. * @throws RedBean_Exception_UnsupportedDatabase $exception * @param RedBean_ToolBox $toolbox * @return bool $compatible */ public function scanToolBox(RedBean_ToolBox $toolbox) { //obtain the database system $brand = strtolower(trim($toolbox->getDatabaseAdapter()->getDatabase()->getDatabaseType())); //obtain version number $version = $toolbox->getDatabaseAdapter()->getDatabase()->getDatabaseVersion(); if (!is_numeric($version)) { $version = 999; //No version number? Ignore! } //compare database if (isset($this->supportedSystems[$brand]) && (double) $this->supportedSystems[$brand] <= (double) $version) { return true; } else { if (!self::$ignoreVersion) { $this->messageUnsupported = str_replace("##YOU##", $brand . " v" . $version, $this->messageUnsupported); $list = array(); foreach ($this->supportedSystems as $supported => $version) { $list[] = " " . $supported . " v" . $version . "+"; } $this->messageUnsupported = str_replace("##DBS##", implode(",", $list), $this->messageUnsupported); throw new RedBean_Exception_UnsupportedDatabase($this->messageUnsupported); } else { return false; } } }
/** * Constructor * * @param RedBean_ToolBox $tools toolbox */ public function __construct(RedBean_ToolBox $tools) { $this->oodb = $tools->getRedBean(); $this->adapter = $tools->getDatabaseAdapter(); $this->writer = $tools->getWriter(); $this->toolbox = $tools; }
/** * Properly untether new clone by re-configuring with a fresh toolbox * * @return void */ public function __clone() { $class = get_class($this->toolbox->getWriter()); $writer = new $class($this->toolbox->getDatabaseAdapter()); $redbean = new RedBean_OODB($writer); $toolbox = new RedBean_ToolBox($redbean, $this->toolbox->getDatabaseAdapter(), $writer); $this->configureWithToolbox($toolbox); }
/** * Constructor, requires a writer * @param RedBean_QueryWriter $writer */ public function __construct(RedBean_ToolBox $toolbox) { $this->writer = $toolbox->getWriter(); $this->adapter = $toolbox->getDatabaseAdapter(); $this->redbean = $toolbox->getRedBean(); if ($this->redbean->isFrozen()) { $this->adapter->exec("\n\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS `__log` (\n\t\t\t\t\t\t`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n\t\t\t\t\t\t`tbl` VARCHAR( 255 ) NOT NULL ,\n\t\t\t\t\t\t`action` TINYINT( 2 ) NOT NULL ,\n\t\t\t\t\t\t`itemid` INT( 11 ) NOT NULL\n\t\t\t\t\t\t) ENGINE = MYISAM ;\n\t\t\t\t"); //Must be MyISAM! else you run in trouble if you use transactions! } $maxid = $this->adapter->getCell("SELECT MAX(id) FROM __log"); $this->adapter->exec("DELETE FROM __log WHERE id < {$maxid} - 200 "); }
/** * Configures the facade, want to have a new Writer? A new Object Database or a new * Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new * toolbox. * * @param RedBean_ToolBox $tb toolbox * * @return RedBean_ToolBox */ public function configureFacadeWithToolbox(RedBean_ToolBox $tb) { $oldTools = $this->toolbox; $this->toolbox = $tb; $this->writer = $this->toolbox->getWriter(); $this->adapter = $this->toolbox->getDatabaseAdapter(); $this->redbean = $this->toolbox->getRedBean(); $this->finder = new RedBean_Finder($this->toolbox); $this->associationManager = new RedBean_AssociationManager($this->toolbox); $this->redbean->setAssociationManager($this->associationManager); $this->labelMaker = new RedBean_LabelMaker($this->toolbox); $this->extAssocManager = new RedBean_AssociationManager_ExtAssociationManager($this->toolbox); $helper = new RedBean_ModelHelper(); $helper->attachEventListeners($this->redbean); $this->associationManager->addEventListener('delete', $helper); $this->duplicationManager = new RedBean_DuplicationManager($this->toolbox); $this->tagManager = new RedBean_TagManager($this->toolbox); $this->f = new RedBean_SQLHelper($this->adapter); return $oldTools; }
/** * Configures the facade, want to have a new Writer? A new Object Database or a new * Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new * toolbox. * * @param RedBean_ToolBox $tb toolbox * * @return RedBean_ToolBox */ public static function configureFacadeWithToolbox(RedBean_ToolBox $tb) { $oldTools = self::$toolbox; self::$toolbox = $tb; self::$writer = self::$toolbox->getWriter(); self::$adapter = self::$toolbox->getDatabaseAdapter(); self::$redbean = self::$toolbox->getRedBean(); self::$finder = new RedBean_Finder(self::$toolbox); self::$associationManager = new RedBean_AssociationManager(self::$toolbox); self::$redbean->setAssociationManager(self::$associationManager); self::$labelMaker = new RedBean_LabelMaker(self::$toolbox); self::$extAssocManager = new RedBean_AssociationManager_ExtAssociationManager(self::$toolbox); $helper = new RedBean_ModelHelper(); $helper->attachEventListeners(self::$redbean); self::$associationManager->addEventListener('delete', $helper); self::$duplicationManager = new RedBean_DuplicationManager(self::$toolbox); self::$tagManager = new RedBean_TagManager(self::$toolbox); self::$f = new RedBean_SQLHelper(self::$adapter); return $oldTools; }
/** * Configures the facade, want to have a new Writer? A new Object Database or a new * Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new * toolbox. * * @static * @param RedBean_ToolBox $tb toolbox * * @return RedBean_ToolBox $tb old, rusty, previously used toolbox */ public static function configureFacadeWithToolbox(RedBean_ToolBox $tb) { $oldTools = self::$toolbox; self::$toolbox = $tb; self::$writer = self::$toolbox->getWriter(); self::$adapter = self::$toolbox->getDatabaseAdapter(); self::$redbean = self::$toolbox->getRedBean(); self::$associationManager = new RedBean_AssociationManager(self::$toolbox); self::$redbean->setAssociationManager(self::$associationManager); self::$extAssocManager = new RedBean_ExtAssociationManager(self::$toolbox); $helper = new RedBean_ModelHelper(); self::$redbean->addEventListener("update", $helper); self::$redbean->addEventListener("open", $helper); self::$redbean->addEventListener("delete", $helper); self::$associationManager->addEventListener("delete", $helper); self::$redbean->addEventListener("after_delete", $helper); self::$redbean->addEventListener("after_update", $helper); self::$redbean->addEventListener("dispense", $helper); return $oldTools; }
/** * Constructor. * This Object requires a toolbox. * * @param RedBean_ToolBox $toolbox toolbox for DB operations. */ public function __construct(RedBean_ToolBox $toolbox) { $this->writer = $toolbox->getWriter(); $this->adapter = $toolbox->getDatabaseAdapter(); }
/** * Kickstarts redbean for you. * @param string $dsn * @param string $username * @param string $password */ public static function setup($dsn = "sqlite:/tmp/red.db", $username = NULL, $password = NULL) { RedBean_Setup::kickstart($dsn, $username, $password); self::$toolbox = RedBean_Setup::getToolBox(); self::$writer = self::$toolbox->getWriter(); self::$adapter = self::$toolbox->getDatabaseAdapter(); self::$redbean = self::$toolbox->getRedBean(); self::$associationManager = new RedBean_AssociationManager(self::$toolbox); self::$treeManager = new RedBean_TreeManager(self::$toolbox); self::$linkManager = new RedBean_LinkManager(self::$toolbox); self::$extAssocManager = new RedBean_ExtAssociationManager(self::$toolbox); $helper = new RedBean_ModelHelper(); self::$redbean->addEventListener("update", $helper); self::$redbean->addEventListener("open", $helper); self::$redbean->addEventListener("delete", $helper); }