PHP Class RedBeanPHP\Repository

OODB manages two repositories, a fluid one that adjust the database schema on-the-fly to accomodate 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.
Author: Gabor de Mooij and the RedBeanPHP community
Datei anzeigen Open project: gabordemooij/redbean Class Usage Examples

Protected Properties

Property Type Description
$nesting *
$stash array
$writer RedBeanPHP\Adapter\DBAdapter

Public Methods

Method Description
__construct ( redbeanphp\OODB $oodb, RedBeanPHP\QueryWriter $writer ) : void Constructor, requires a query writer.
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.
check ( redbeanphp\OODBBean $bean ) : void Checks whether a OODBBean bean is valid.
convertToBeans ( string $type, array $rows, string $mask = NULL ) : 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.
count ( string $type, string $addSQL = '', array $bindings = [] ) : integer Counts the number of beans of type $type.
find ( string $type, array $conditions = [], $sql = NULL, array $bindings = [] ) : 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.
findCollection ( string $type, string $sql, array $bindings = [] ) : redbeanphp\BeanCollection Finds a BeanCollection.
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.
tableExists ( string $table ) : boolean Checks whether the specified table already exists in the database.
trash ( redbeanphp\OODBBean | redbeanphp\SimpleModel $bean ) : void Removes a bean from the database.
wipe ( string $type ) : boolean Trash all beans of a given type. Wipes an entire type of bean.

Protected Methods

Method Description
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.
prepareEmbeddedBean ( redbeanphp\OODBBean | redbeanphp\SimpleModel $embeddedBean ) : integer Processes an embedded bean.
processEmbeddedBean ( array &$embeddedBeans, redbeanphp\OODBBean $bean, string $property, redbeanphp\OODBBean $value ) : void Converts an embedded bean to an ID, removed the bean property and stores the bean in the embedded beans array.
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).
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.
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.
processSharedResidue ( redbeanphp\OODBBean $bean, array $sharedresidue ) : void Stores all the beans in the residue group.
processSharedTrashcan ( redbeanphp\OODBBean $bean, array $sharedTrashcan ) : void Unassociates the list items in the trashcan.
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.
storeBeanWithLists ( redbeanphp\OODBBean $bean ) : void Stores a bean and its lists in one run.

Method Details

__construct() public method

Creates a new instance of the bean respository class.
public __construct ( redbeanphp\OODB $oodb, RedBeanPHP\QueryWriter $writer ) : void
$oodb redbeanphp\OODB
$writer RedBeanPHP\QueryWriter the Query Writer to use for this repository
return void

batch() public method

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.
public batch ( string $type, array $ids ) : array
$type string type of beans
$ids array ids to load
return array

check() public method

If the type is not valid or the ID is not valid it will throw an exception: Security.
public check ( redbeanphp\OODBBean $bean ) : void
$bean redbeanphp\OODBBean the bean that needs to be checked
return void

convertToBeans() public method

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 whos name starts with $mask will be transferred to the meta section of the bean under key 'data.bundle'.
public convertToBeans ( string $type, array $rows, string $mask = NULL ) : array
$type string type of beans you would like to have
$rows array rows from the database result
$mask string meta mask to apply (optional)
return array

count() public method

This method accepts a second argument to modify the count-query. A third argument can be used to provide bindings for the SQL snippet.
public count ( string $type, string $addSQL = '', array $bindings = [] ) : integer
$type string type of bean we are looking for
$addSQL string additional SQL snippet
$bindings array parameters to bind to SQL
return integer

find() public method

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.
public find ( string $type, array $conditions = [], $sql = NULL, array $bindings = [] ) : array
$type string type of beans you are looking for
$conditions array list of conditions
$bindings array whether you prefer to use a WHERE clause or not (TRUE = not)
return array

findCollection() public method

Finds a BeanCollection.
public findCollection ( string $type, string $sql, array $bindings = [] ) : redbeanphp\BeanCollection
$type string type of beans you are looking for
$sql string SQL to be used in query
$bindings array whether you prefer to use a WHERE clause or not (TRUE = not)
return redbeanphp\BeanCollection

hasListsOrObjects() protected method

Determines whether the bean has 'loaded lists' or 'loaded embedded beans' that need to be processed by the store() method.
protected hasListsOrObjects ( redbeanphp\OODBBean $bean ) : boolean
$bean redbeanphp\OODBBean bean to be examined
return boolean

prepareEmbeddedBean() protected method

Processes an embedded bean.
protected prepareEmbeddedBean ( redbeanphp\OODBBean | redbeanphp\SimpleModel $embeddedBean ) : integer
$embeddedBean redbeanphp\OODBBean | redbeanphp\SimpleModel the bean or model
return integer

processEmbeddedBean() protected method

Converts an embedded bean to an ID, removed the bean property and stores the bean in the embedded beans array.
protected processEmbeddedBean ( array &$embeddedBeans, redbeanphp\OODBBean $bean, string $property, redbeanphp\OODBBean $value ) : void
$embeddedBeans array destination array for embedded bean
$bean redbeanphp\OODBBean target bean to process
$property string property that contains the embedded bean
$value redbeanphp\OODBBean embedded bean itself
return void

processGroups() protected method

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).
protected processGroups ( array $originals, array $current, array $additions, array $trashcan, array $residue ) : array
$originals array originals
$current array the current beans
$additions array beans that have been added
$trashcan array beans that have been deleted
$residue array beans that have been left untouched
return array

processResidue() protected method

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.
protected processResidue ( array $ownresidue ) : void
$ownresidue array list to process
return void

processSharedAdditions() protected method

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.
protected processSharedAdditions ( redbeanphp\OODBBean $bean, array $sharedAdditions ) : void
$bean redbeanphp\OODBBean the bean
$sharedAdditions array list with shared additions
return void

processSharedResidue() protected method

Stores all the beans in the residue group.
protected processSharedResidue ( redbeanphp\OODBBean $bean, array $sharedresidue ) : void
$bean redbeanphp\OODBBean bean to process
$sharedresidue array list to process
return void

processSharedTrashcan() protected method

Unassociates the list items in the trashcan.
protected processSharedTrashcan ( redbeanphp\OODBBean $bean, array $sharedTrashcan ) : void
$bean redbeanphp\OODBBean bean to process
$sharedTrashcan array list to process
return void

processTrashcan() protected method

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.
protected processTrashcan ( redbeanphp\OODBBean $bean, array $ownTrashcan ) : void
$bean redbeanphp\OODBBean bean to process
$ownTrashcan array list to process
return void

store() public method

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).
public store ( redbeanphp\OODBBean | redbeanphp\SimpleModel $bean ) : integer | string
$bean redbeanphp\OODBBean | redbeanphp\SimpleModel bean to store
return integer | string

storeBeanWithLists() protected method

Stores a bean and its lists in one run.
protected storeBeanWithLists ( redbeanphp\OODBBean $bean ) : void
$bean redbeanphp\OODBBean bean to process
return void

tableExists() public method

Not part of the Object Database interface!
Deprecation: Use AQueryWriter::typeExists() instead.
public tableExists ( string $table ) : boolean
$table string table name
return boolean

trash() public method

This function will remove the specified OODBBean Bean Object from the database.
public trash ( redbeanphp\OODBBean | redbeanphp\SimpleModel $bean ) : void
$bean redbeanphp\OODBBean | redbeanphp\SimpleModel bean you want to remove from database
return void

wipe() public method

Trash all beans of a given type. Wipes an entire type of bean.
public wipe ( string $type ) : boolean
$type string type of bean you wish to delete all instances of
return boolean

Property Details

$nesting protected_oe property

*
protected $nesting

$stash protected_oe property

protected array $stash
return array

$writer protected_oe property

protected DBAdapter,RedBeanPHP\Adapter $writer
return RedBeanPHP\Adapter\DBAdapter