getRedBean() public method

OODB is responsible for creating, storing, retrieving and deleting single beans. Other components rely on OODB for their basic functionality.
public getRedBean ( ) : RedBeanPHP\OODB
return RedBeanPHP\OODB
コード例 #1
0
ファイル: LabelMaker.php プロジェクト: cesium147/redbean
 /**
  * Returns a label or an array of labels for use as ENUMs.
  * 
  * @param string $enum ENUM specification for label
  * 
  * @return array|OODBBean
  */
 public function enum($enum)
 {
     $oodb = $this->toolbox->getRedBean();
     if (strpos($enum, ':') === FALSE) {
         $type = $enum;
         $value = FALSE;
     } else {
         list($type, $value) = explode(':', $enum);
         $value = preg_replace('/\\W+/', '_', strtoupper(trim($value)));
     }
     $values = $oodb->find($type);
     if ($value === FALSE) {
         return $values;
     }
     foreach ($values as $enumItem) {
         if ($enumItem->name === $value) {
             return $enumItem;
         }
     }
     $newEnumItems = $this->dispenseLabels($type, array($value));
     $newEnumItem = reset($newEnumItems);
     $oodb->store($newEnumItem);
     return $newEnumItem;
 }
コード例 #2
0
ファイル: Facade.php プロジェクト: up9cloud/redbean
 /**
  * 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 ToolBox $tb toolbox to configure facade with
  *
  * @return ToolBox
  */
 public static function configureFacadeWithToolbox(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 Finder(self::$toolbox);
     self::$associationManager = new AssociationManager(self::$toolbox);
     self::$redbean->setAssociationManager(self::$associationManager);
     self::$labelMaker = new LabelMaker(self::$toolbox);
     $helper = new SimpleModelHelper();
     $helper->attachEventListeners(self::$redbean);
     self::$redbean->setBeanHelper(new SimpleFacadeBeanHelper());
     self::$duplicationManager = new DuplicationManager(self::$toolbox);
     self::$tagManager = new TagManager(self::$toolbox);
     return $oldTools;
 }
コード例 #3
0
ファイル: LabelMaker.php プロジェクト: diego-vieira/redbean
 /**
  * Fetches an ENUM from the database and creates it if necessary.
  * An ENUM has the following format:
  *
  * <code>
  * ENUM:VALUE
  * </code>
  *
  * If you pass 'ENUM' only, this method will return an array of its
  * values:
  *
  * <code>
  * implode( ',', R::gatherLabels( R::enum( 'flavour' ) ) ) //'BANANA,MOCCA'
  * </code>
  *
  * If you pass 'ENUM:VALUE' this method will return the specified enum bean
  * and create it in the database if it does not exist yet:
  *
  * <code>
  * $bananaFlavour = R::enum( 'flavour:banana' );
  * $bananaFlavour->name;
  * </code>
  *
  * So you can use this method to set an ENUM value in a bean:
  *
  * <code>
  * $shake->flavour = R::enum( 'flavour:banana' );
  * </code>
  *
  * the property flavour now contains the enum bean, a parent bean.
  * In the database, flavour_id will point to the flavour record with name 'banana'.
  *
  * @param string $enum ENUM specification for label
  *
  * @return array|OODBBean
  */
 public function enum($enum)
 {
     $oodb = $this->toolbox->getRedBean();
     if (strpos($enum, ':') === FALSE) {
         $type = $enum;
         $value = FALSE;
     } else {
         list($type, $value) = explode(':', $enum);
         $value = preg_replace('/\\W+/', '_', strtoupper(trim($value)));
     }
     /**
      * We use simply find here, we could use inspect() in fluid mode etc,
      * but this would be useless. At first sight it looks clean, you could even
      * bake this into find(), however, find not only has to deal with the primary
      * search type, people can also include references in the SQL part, so avoiding
      * find failures does not matter, this is still the quickest way making use
      * of existing functionality.
      *
      * @note There seems to be a bug in XDebug v2.3.2 causing suppressed
      * exceptions like these to surface anyway, to prevent this use:
      *
      * "xdebug.default_enable = 0"
      *
      *  Also see Github Issue #464
      */
     $values = $oodb->find($type);
     if ($value === FALSE) {
         return $values;
     }
     foreach ($values as $enumItem) {
         if ($enumItem->name === $value) {
             return $enumItem;
         }
     }
     $newEnumItems = $this->dispenseLabels($type, array($value));
     $newEnumItem = reset($newEnumItems);
     $oodb->store($newEnumItem);
     return $newEnumItem;
 }
コード例 #4
0
 /**
  * Constructor
  *
  * @param ToolBox $tools toolbox
  */
 public function __construct(ToolBox $tools)
 {
     $this->oodb = $tools->getRedBean();
     $this->adapter = $tools->getDatabaseAdapter();
     $this->writer = $tools->getWriter();
     $this->toolbox = $tools;
 }
コード例 #5
0
ファイル: Finder.php プロジェクト: cesium147/redbean
 /**
  * Constructor.
  * The Finder requires a toolbox.
  *
  * @param ToolBox $toolbox
  */
 public function __construct(ToolBox $toolbox)
 {
     $this->toolbox = $toolbox;
     $this->redbean = $toolbox->getRedBean();
 }
コード例 #6
0
ファイル: TagManager.php プロジェクト: cesium147/redbean
 /**
  * Constructor.
  * The tag manager offers an easy way to quickly implement basic tagging
  * functionality.
  *
  * @param ToolBox $toolbox
  */
 public function __construct(ToolBox $toolbox)
 {
     $this->toolbox = $toolbox;
     $this->redbean = $toolbox->getRedBean();
     $this->associationManager = $this->redbean->getAssociationManager();
 }