$enforceNamingPolicy
$enforceNamingPolicy : boolean
Dispense Helper
A helper class containing a dispense utility.
setEnforceNamingPolicy(boolean $yesNo) : void
Sets the enforce naming policy flag. If set to TRUE the RedBeanPHP naming policy will be enforced.
Otherwise it will not. Use at your own risk. Setting this to FALSE is not recommended.
boolean | $yesNo | whether to enforce RB name policy |
checkType(string $type) : void
Checks whether the bean type conforms to the RedbeanPHP naming policy. This method will throw an exception if the type does not conform to the RedBeanPHP database column naming policy.
The RedBeanPHP naming policy for beans states that valid bean type names contain only:
Although there are no restrictions on length, database specific implementations may apply further restrictions regarding the length of a table which means these restrictions also apply to bean types.
The RedBeanPHP naming policy ensures that, without any configuration, the core functionalities work across many databases and operating systems, including those that are case insensitive or restricted to the ASCII character set.
Although these restrictions can be bypassed, this is not recommended.
string | $type | type of bean |
dispense(\RedBeanPHP\OODB $oodb, string|array $typeOrBeanArray, integer $num = 1, boolean $alwaysReturnArray = FALSE) : \RedBeanPHP\OODBBean|array<mixed,\RedBeanPHP\OODBBean>
Dispenses a new RedBean OODB Bean for use with the rest of the methods. RedBeanPHP thinks in beans, the bean is the primary way to interact with RedBeanPHP and the database managed by RedBeanPHP. To load, store and delete data from the database using RedBeanPHP you exchange these RedBeanPHP OODB Beans. The only exception to this rule are the raw query methods like R::getCell() or R::exec() and so on.
The dispense method is the 'preferred way' to create a new bean.
Usage:
$book = R::dispense( 'book' );
$book->title = 'My Book';
R::store( $book );
This method can also be used to create an entire bean graph at once. Given an array with keys specifying the property names of the beans and a special _type key to indicate the type of bean, one can make the Dispense Helper generate an entire hierarchy of beans, including lists. To make dispense() generate a list, simply add a key like: ownXList or sharedXList where X is the type of beans it contains and a set its value to an array filled with arrays representing the beans. Note that, although the type may have been hinted at in the list name, you still have to specify a _type key for every bean array in the list. Note that, if you specify an array to generate a bean graph, the number parameter will be ignored.
Usage:
$book = R::dispense( [
'_type' => 'book',
'title' => 'Gifted Programmers',
'author' => [ '_type' => 'author', 'name' => 'Xavier' ],
'ownPageList' => [ ['_type'=>'page', 'text' => '...'] ]
] );
\RedBeanPHP\OODB | $oodb | |
string|array | $typeOrBeanArray | type or bean array to import |
integer | $num | number of beans to dispense |
boolean | $alwaysReturnArray | if TRUE always returns the result as an array |
dispenseAll(\RedBeanPHP\OODB $oodb, string $order, boolean $onlyArrays = FALSE) : array
Takes a comma separated list of bean types and dispenses these beans. For each type in the list you can specify the number of beans to be dispensed.
Usage:
list( $book, $page, $text ) = R::dispenseAll( 'book,page,text' );
This will dispense a book, a page and a text. This way you can quickly dispense beans of various types in just one line of code.
Usage:
list($book, $pages) = R::dispenseAll('book,page*100');
This returns an array with a book bean and then another array containing 100 page beans.
\RedBeanPHP\OODB | $oodb | OODB |
string | $order | a description of the desired dispense order using the syntax above |
boolean | $onlyArrays | return only arrays even if amount < 2 |