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
Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 /**
  * Constructor.
  * The Finder requires a toolbox.
  *
  * @param ToolBox $toolbox
  */
 public function __construct(ToolBox $toolbox)
 {
     $this->toolbox = $toolbox;
     $this->redbean = $toolbox->getRedBean();
 }
Ejemplo n.º 6
0
 /**
  * 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();
 }