PHP Класс 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.
Автор: Gabor de Mooij and the RedBeanPHP community
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$nesting *
$stash array
$writer RedBeanPHP\Adapter\DBAdapter

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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
Результат void

batch() публичный Метод

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
Результат array

check() публичный Метод

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
Результат void

convertToBeans() публичный Метод

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)
Результат array

count() публичный Метод

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
Результат integer

find() публичный Метод

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)
Результат array

findCollection() публичный Метод

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)
Результат redbeanphp\BeanCollection

hasListsOrObjects() защищенный Метод

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
Результат boolean

prepareEmbeddedBean() защищенный Метод

Processes an embedded bean.
protected prepareEmbeddedBean ( redbeanphp\OODBBean | redbeanphp\SimpleModel $embeddedBean ) : integer
$embeddedBean redbeanphp\OODBBean | redbeanphp\SimpleModel the bean or model
Результат integer

processEmbeddedBean() защищенный Метод

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
Результат void

processGroups() защищенный Метод

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
Результат array

processResidue() защищенный Метод

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
Результат void

processSharedAdditions() защищенный Метод

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
Результат void

processSharedResidue() защищенный Метод

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
Результат void

processSharedTrashcan() защищенный Метод

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
Результат void

processTrashcan() защищенный Метод

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
Результат void

store() публичный Метод

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
Результат integer | string

storeBeanWithLists() защищенный Метод

Stores a bean and its lists in one run.
protected storeBeanWithLists ( redbeanphp\OODBBean $bean ) : void
$bean redbeanphp\OODBBean bean to process
Результат void

tableExists() публичный Метод

Not part of the Object Database interface!
Устаревший: Use AQueryWriter::typeExists() instead.
public tableExists ( string $table ) : boolean
$table string table name
Результат boolean

trash() публичный Метод

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
Результат void

wipe() публичный Метод

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
Результат boolean

Описание свойств

$nesting защищенное свойство

*
protected $nesting

$stash защищенное свойство

protected array $stash
Результат array

$writer защищенное свойство

protected DBAdapter,RedBeanPHP\Adapter $writer
Результат RedBeanPHP\Adapter\DBAdapter