$stash
$stash : array
Abstract Repository.
OODB manages two repositories, a fluid one that adjust the database schema on-the-fly to accommodate for new bean types (tables) and new properties (columns) and a frozen one for use in a production environment. OODB allows you to swap the repository instances using the freeze() method.
$writer : \RedBeanPHP\QueryWriter
usePartialBeans(boolean|array $yesNoBeans) : boolean|array
Toggles 'partial bean mode'. If this mode has been selected the repository will only update the fields of a bean that have been changed rather than the entire bean.
Pass the value TRUE to select 'partial mode' for all beans. Pass the value FALSE to disable 'partial mode'. Pass an array of bean types if you wish to use partial mode only for some types. This method will return the previous value.
boolean|array | $yesNoBeans | List of type names or 'all' |
__construct(\RedBeanPHP\OODB $oodb, \RedBeanPHP\QueryWriter $writer) : void
Constructor, requires a query writer and OODB.
Creates a new instance of the bean respository class.
\RedBeanPHP\OODB | $oodb | instance of object database |
\RedBeanPHP\QueryWriter | $writer | the Query Writer to use for this repository |
check(\RedBeanPHP\OODBBean $bean) : void
Checks whether a OODBBean bean is valid.
If the type is not valid or the ID is not valid it will throw an exception: Security. To be valid a bean must abide to the following rules:
\RedBeanPHP\OODBBean | $bean | the bean that needs to be checked |
dispense(string $type, integer $number = 1, boolean $alwaysReturnArray = FALSE) : \RedBeanPHP\OODBBean|array<mixed,\RedBeanPHP\OODBBean>
Dispenses a new bean (a OODBBean Bean Object) of the specified type. Always use this function to get an empty bean object. Never instantiate a OODBBean yourself because it needs to be configured before you can use it with RedBean. This function applies the appropriate initialization / configuration for you.
To use a different class for beans (instead of OODBBean) set: REDBEAN_OODBBEAN_CLASS to the name of the class to be used.
string | $type | type of bean you want to dispense |
integer | $number | number of beans you would like to get |
boolean | $alwaysReturnArray | if TRUE always returns the result as an array |
find(string $type, array $conditions = array(), string $sql = NULL, array $bindings = array()) : array
Searches the database for a bean that matches conditions $conditions and sql $addSQL and returns an array containing all the beans that have been found.
Conditions need to take form:
array(
'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' )
'PROPERTY' => array( POSSIBLE VALUES... )
);
All conditions are glued together using the AND-operator, while all value lists are glued using IN-operators thus acting as OR-conditions.
Note that you can use property names; the columns will be extracted using the appropriate bean formatter.
string | $type | type of beans you are looking for |
array | $conditions | list of conditions |
string | $sql | SQL to be used in query |
array | $bindings | whether you prefer to use a WHERE clause or not (TRUE = not) |
findCollection(string $type, string $sql, array $bindings = array()) : \RedBeanPHP\BeanCollection
Finds a BeanCollection.
Given a type, an SQL snippet and optionally some parameter bindings this methods returns a BeanCollection for your query.
The BeanCollection represents a collection of beans and makes it possible to use database cursors. The BeanCollection has a method next() to obtain the first, next and last bean in the collection. The BeanCollection does not implement the array interface nor does it try to act like an array because it cannot go backward or rewind itself.
string | $type | type of beans you are looking for |
string | $sql | SQL to be used in query |
array | $bindings | whether you prefer to use a WHERE clause or not (TRUE = not) |
store(\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel $bean) : integer|string
Stores a bean in the database. This method takes a OODBBean Bean Object $bean and stores it in the database. If the database schema is not compatible with this bean and RedBean runs in fluid mode the schema will be altered to store the bean correctly.
If the database schema is not compatible with this bean and RedBean runs in frozen mode it will throw an exception. This function returns the primary key ID of the inserted bean.
The return value is an integer if possible. If it is not possible to represent the value as an integer a string will be returned. We use explicit casts instead of functions to preserve performance (0.13 vs 0.28 for 10000 iterations on Core i3).
\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel | $bean | bean to store |
batch(string $type, array $ids) : array
Returns an array of beans. Pass a type and a series of ids and this method will bring you the corresponding beans.
important note: Because this method loads beans using the load() function (but faster) it will return empty beans with ID 0 for every bean that could not be located. The resulting beans will have the passed IDs as their keys.
string | $type | type of beans |
array | $ids | ids to load |
convertToBeans(string $type, array $rows, string $mask = '__meta') : array
This is a convenience method; it converts database rows (arrays) into beans. Given a type and a set of rows this method will return an array of beans of the specified type loaded with the data fields provided by the result set from the database.
New in 4.3.2: meta mask. The meta mask is a special mask to send data from raw result rows to the meta store of the bean. This is useful for bundling additional information with custom queries. Values of every column who's name starts with $mask will be transferred to the meta section of the bean under key 'data.bundle'.
string | $type | type of beans you would like to have |
array | $rows | rows from the database result |
string | $mask | meta mask to apply (optional) |
count(string $type, string $addSQL = '', array $bindings = array()) : integer
Counts the number of beans of type $type.
This method accepts a second argument to modify the count-query. A third argument can be used to provide bindings for the SQL snippet.
string | $type | type of bean we are looking for |
string | $addSQL | additional SQL snippet |
array | $bindings | parameters to bind to SQL |
trash(\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel $bean) : integer
Removes a bean from the database.
This function will remove the specified OODBBean Bean Object from the database.
\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel | $bean | bean you want to remove from database |
wipe(string $type) : boolean
Trash all beans of a given type.
Wipes an entire type of bean. After this operation there will be no beans left of the specified type. This method will ignore exceptions caused by database tables that do not exist.
string | $type | type of bean you wish to delete all instances of |
None found |
storeBeanWithLists(\RedBeanPHP\OODBBean $bean) : void
Fully processes a bean and updates the associated records in the database.
First the bean properties will be grouped as 'embedded' bean, addition, deleted 'trash can' or residue. Next, the different groups of beans will be processed accordingly and the reference bean (i.e. the one that was passed to the method as an argument) will be stored. Each type of list (own/shared) has 3 bean processors:
This method first groups the beans and then calls the internal processing methods.
\RedBeanPHP\OODBBean | $bean | bean to process |
None found |
processGroups(array $originals, array $current, array $additions, array $trashcan, array $residue) : array
Process groups. Internal function. Processes different kind of groups for storage function. Given a list of original beans and a list of current beans, this function calculates which beans remain in the list (residue), which have been deleted (are in the trashcan) and which beans have been added (additions).
array | $originals | originals |
array | $current | the current beans |
array | $additions | beans that have been added |
array | $trashcan | beans that have been deleted |
array | $residue | beans that have been left untouched |
None found |
processSharedAdditions(\RedBeanPHP\OODBBean $bean, array $sharedAdditions) : void
Processes a list of beans from a bean.
A bean may contain lists. This method handles shared addition lists; i.e. the $bean->sharedObject properties. Shared beans will be associated with each other using the Association Manager.
\RedBeanPHP\OODBBean | $bean | the bean |
array | $sharedAdditions | list with shared additions |
None found |
processResidue(array $ownresidue) : void
Processes a list of beans from a bean.
A bean may contain lists. This method handles own lists; i.e. the $bean->ownObject properties. A residue is a bean in an own-list that stays where it is. This method checks if there have been any modification to this bean, in that case the bean is stored once again, otherwise the bean will be left untouched.
array | $ownresidue | list to process |
None found |
processTrashcan(\RedBeanPHP\OODBBean $bean, array $ownTrashcan) : void
Processes a list of beans from a bean. A bean may contain lists. This method handles own lists; i.e. the $bean->ownObject properties.
A trash can bean is a bean in an own-list that has been removed (when checked with the shadow). This method checks if the bean is also in the dependency list. If it is the bean will be removed. If not, the connection between the bean and the owner bean will be broken by setting the ID to NULL.
\RedBeanPHP\OODBBean | $bean | bean to process |
array | $ownTrashcan | list to process |
None found |
processSharedTrashcan(\RedBeanPHP\OODBBean $bean, array $sharedTrashcan) : void
Unassociates the list items in the trashcan.
This bean processor processes the beans in the shared trash can. This group of beans has been deleted from a shared list. The affected beans will no longer be associated with the bean that contains the shared list.
\RedBeanPHP\OODBBean | $bean | bean to process |
array | $sharedTrashcan | list to process |
None found |
processSharedResidue(\RedBeanPHP\OODBBean $bean, array $sharedresidue) : void
Stores all the beans in the residue group.
This bean processor processes the beans in the shared residue group. This group of beans 'remains' in the list but might need to be updated or synced. The affected beans will be stored to perform the required database queries.
\RedBeanPHP\OODBBean | $bean | bean to process |
array | $sharedresidue | list to process |
None found |
hasListsOrObjects(\RedBeanPHP\OODBBean $bean) : boolean
Determines whether the bean has 'loaded lists' or 'loaded embedded beans' that need to be processed by the store() method.
\RedBeanPHP\OODBBean | $bean | bean to be examined |
None found |
processEmbeddedBean(array $embeddedBeans, \RedBeanPHP\OODBBean $bean, string $property, \RedBeanPHP\OODBBean $value) : void
Converts an embedded bean to an ID, removes the bean property and stores the bean in the embedded beans array. The id will be assigned to the link field property, i.e. 'bean_id'.
array | $embeddedBeans | destination array for embedded bean |
\RedBeanPHP\OODBBean | $bean | target bean to process |
string | $property | property that contains the embedded bean |
\RedBeanPHP\OODBBean | $value | embedded bean itself |
None found |