/** * * Constructor, requires a type name * @param string $typeName */ public function __construct($typeName) { $this->tools = RedBean_Setup::getToolBox(); $this->redbean = $this->tools->getRedBean(); $this->bean = $this->redbean->dispense($typeName); $this->associationManager = new RedBean_AssociationManager($this->tools); $this->treeManager = new RedBean_TreeManager($this->tools); }
/** * 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; }
/** * * Constructor, requires a type name * @param string $typeName */ public function __construct($typeName = false) { /** * If no typeName has been specified, * figure out the type of this model yourself. * In this case the following rule applies: * - the name of the model is the LAST part of the * namespace. * - Within that string, the name of the model is the LAST * part of the poorman's name space. * * So the model name for class: /me/him/her is: her * So the model name for class: /me/him/her_lover is: lover */ if (!$typeName) { //Fetch the bean type using the class $beanTypeName = get_class($this); //Get last part of namespace $a = explode("\\", $beanTypeName); $lastInNameSpace = array_pop($a); //Get last part of poorman's namespace (underscores) $a = explode("_", $lastInNameSpace); $lastInPoormanNameSpace = array_pop($a); $beanTypeName = $lastInPoormanNameSpace; } else { $beanTypeName = $typeName; } /* * Now do a little check to see whether this name * can be used. - Just a quick check, we will re-check later on */ if ($beanTypeName && strlen($beanTypeName) > 0) { //Fetch us a toolbox. $this->tools = RedBean_Setup::getToolBox(); $this->redbean = $this->tools->getRedBean(); //Here the bean type is checked properly. $this->bean = $this->redbean->dispense(strtolower($beanTypeName)); //Create some handy modules so you dont have to do the wiring yourself. $this->associationManager = new RedBean_AssociationManager($this->tools); $this->treeManager = new RedBean_TreeManager($this->tools); } else { throw new Exception("Invalid Domain Object TypeName"); } }
/** * 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 configureWithToolbox(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); $this->associationManager->addEventListener('delete', $this->redbean->beanhelper->helper); $this->duplicationManager = new RedBean_DuplicationManager($this->toolbox); $this->tagManager = new RedBean_TagManager($this->toolbox); $this->f = new RedBean_SQLHelper($this->adapter); $this->x = new RedBean_FindHelper($this); 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. * Creates a new instance of the Resty BeanCan Server. * If no toolbox is provided the Resty BeanCan Server object will * try to obtain the toolbox currently used by the RedBeanPHP facade. * If you use only the R-methods and not the advanced objects this should be fine. * * @param RedBean_ToolBox $toolbox (optional) */ public function __construct($toolbox = NULL) { if ($toolbox instanceof RedBean_ToolBox) { $this->toolbox = $toolbox; $this->oodb = $toolbox->getRedBean(); } else { $this->toolbox = RedBean_Facade::getToolBox(); $this->oodb = RedBean_Facade::getRedBean(); } }
/** * Constructor. * The Finder requires a toolbox. * * @param RedBean_ToolBox $toolbox */ public function __construct(RedBean_ToolBox $toolbox) { $this->toolbox = $toolbox; $this->redbean = $toolbox->getRedBean(); }
/** * 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); }