\RedBeanPHP\PluginPoolDB

PoolDB

Represents a pool of databases that will have persisting associations with the beans they dispense. Saving a bean from a pooled database will make sure that the bean will be stored in the database it originated from instead of the currently selected database.

Summary

Methods
Properties
Constants
autoClearHistoryAfterStore()
__construct()
freeze()
isFrozen()
isChilled()
dispense()
setBeanHelper()
getBeanHelper()
check()
find()
findCollection()
tableExists()
store()
load()
trash()
batch()
convertToBeans()
count()
wipe()
getAssociationManager()
setAssociationManager()
getCurrentRepository()
clearAllFuncBindings()
bindFunc()
addEventListener()
signal()
setToolBox()
No public properties found
No constants found
unboxIfNeeded()
$chillList
$stash
$nesting
$writer
$isFrozen
$beanhelper
$assocManager
$repository
$frozenRepository
$fluidRepository
$autoClearHistoryAfterStore
N/A
No private methods found
$sqlFilters
$observers
$pool
$toolbox
$oodb
$key
$beanHelper
N/A

Properties

$chillList

$chillList : array

Type

array

$stash

$stash : array

Type

array

$nesting

$nesting : 

Type

$isFrozen

$isFrozen : boolean

Type

boolean

$autoClearHistoryAfterStore

$autoClearHistoryAfterStore : boolean

Type

boolean

$sqlFilters

$sqlFilters : array

Type

array

$observers

$observers : array

Type

array

$pool

$pool : array

Type

array

$key

$key : string

Type

string

Methods

autoClearHistoryAfterStore()

autoClearHistoryAfterStore(boolean  $autoClear = TRUE) : void

If set to TRUE, this method will call clearHistory every time the bean gets stored.

Parameters

boolean $autoClear

auto clear option

__construct()

__construct(string  $key, \RedBeanPHP\OODB  $oodb) 

Constructor

creates a new instance of the database pool.

Parameters

string $key

key

\RedBeanPHP\OODB $oodb

oodb instance

freeze()

freeze(boolean|array  $toggle) : void

Toggles fluid or frozen mode. In fluid mode the database structure is adjusted to accommodate your objects. In frozen mode this is not the case.

You can also pass an array containing a selection of frozen types. Let's call this chill mode, it's just like fluid mode except that certain types (i.e. tables) aren't touched.

Parameters

boolean|array $toggle

TRUE if you want to use OODB instance in frozen mode

isFrozen()

isFrozen() : boolean

Returns the current mode of operation of RedBean.

In fluid mode the database structure is adjusted to accommodate your objects. In frozen mode this is not the case.

Returns

boolean

isChilled()

isChilled(string  $type) : boolean

Determines whether a type is in the chill list.

If a type is 'chilled' it's frozen, so its schema cannot be changed anymore. However other bean types may still be modified. This method is a convenience method for other objects to check if the schema of a certain type is locked for modification.

Parameters

string $type

the type you wish to check

Returns

boolean

dispense()

dispense(string  $type, string  $number = 1, boolean  $alwaysReturnArray = FALSE) : \RedBeanPHP\OODBBean|array<mixed,\RedBeanPHP\OODBBean>

Dispenses a new bean from the database pool.

A bean that has been dispensed by the pool will have a special meta attribute called sys.source containing the key identifying the database in the pool it originated from.

Parameters

string $type

type of bean you want to dispense

string $number

number of beans you would like to get

boolean $alwaysReturnArray

if TRUE always returns the result as an array

Returns

\RedBeanPHP\OODBBean|array<mixed,\RedBeanPHP\OODBBean>

setBeanHelper()

setBeanHelper(\RedBeanPHP\BeanHelper  $beanhelper) : void

Sets bean helper to be given to beans.

Bean helpers assist beans in getting a reference to a toolbox.

Parameters

\RedBeanPHP\BeanHelper $beanhelper

helper

getBeanHelper()

getBeanHelper() : \RedBeanPHP\BeanHelper

Returns the bean helper of the database pool.

Bean helpers assist beans in getting a reference to a toolbox.

Returns

\RedBeanPHP\BeanHelper

check()

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.

Parameters

\RedBeanPHP\OODBBean $bean

the bean that needs to be checked

find()

find(string  $type, array  $conditions = array(), string|NULL  $sql = NULL, array  $bindings = array()) : array

Implements the find operation.

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.

Parameters

string $type

type of beans you are looking for

array $conditions

list of conditions

string|NULL $sql

SQL to be used in query

array $bindings

a list of values to bind to query parameters

Returns

array

findCollection()

findCollection(string  $type, string|NULL  $sql = NULL, array  $bindings = array()) : \RedBeanPHP\BeanCollection

Same as find() but returns a BeanCollection.

Parameters

string $type

type of beans you are looking for

string|NULL $sql

SQL to be used in query

array $bindings

a list of values to bind to query parameters

Returns

\RedBeanPHP\BeanCollection

tableExists()

tableExists(string  $table) : boolean

Checks whether the specified table already exists in the database.

Not part of the Object Database interface!

Parameters

string $table

table name

Returns

boolean

store()

store(\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel  $bean) : integer|string

Stores the specified bean in the database in the pool it originated from by looking up the sys.source attribute.

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).

Parameters

\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel $bean

bean to store

Returns

integer|string

load()

load(string  $type, integer  $id) : \RedBeanPHP\OODBBean

Loads a bean from the object database.

It searches for a OODBBean Bean Object in the database. It does not matter how this bean has been stored. RedBean uses the primary key ID $id and the string $type to find the bean. The $type specifies what kind of bean you are looking for; this is the same type as used with the dispense() function. If RedBean finds the bean it will return the OODB Bean object; if it cannot find the bean RedBean will return a new bean of type $type and with primary key ID 0. In the latter case it acts basically the same as dispense().

Important note: If the bean cannot be found in the database a new bean of the specified type will be generated and returned.

Parameters

string $type

type of bean you want to load

integer $id

ID of the bean you want to load

Returns

\RedBeanPHP\OODBBean

trash()

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.

Parameters

\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel $bean

bean you want to remove from database

Returns

integer

batch()

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.

Parameters

string $type

type of beans

array $ids

ids to load

Returns

array

convertToBeans()

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.

Parameters

string $type

type of beans you would like to have

array $rows

rows from the database result

string $mask

mask to apply for meta data

Returns

array

count()

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.

Parameters

string $type

type of bean we are looking for

string $addSQL

additional SQL snippet

array $bindings

parameters to bind to SQL

Returns

integer

wipe()

wipe(string  $type) : boolean

Trash all beans of a given type. Wipes an entire type of bean.

Parameters

string $type

type of bean you wish to delete all instances of

Returns

boolean

getAssociationManager()

getAssociationManager() : \RedBeanPHP\AssociationManager

Returns an Association Manager for use with OODB.

A simple getter function to obtain a reference to the association manager used for storage and more.

Returns

\RedBeanPHP\AssociationManager

setAssociationManager()

setAssociationManager(\RedBeanPHP\AssociationManager  $assocManager) : void

Sets the association manager instance to be used by this OODB.

A simple setter function to set the association manager to be used for storage and more.

Parameters

\RedBeanPHP\AssociationManager $assocManager

sets the association manager to be used

getCurrentRepository()

getCurrentRepository() : \RedBeanPHP\Repository

Returns the currently used repository instance.

For testing purposes only.

Returns

\RedBeanPHP\Repository

clearAllFuncBindings()

clearAllFuncBindings() : void

Clears all function bindings.

bindFunc()

bindFunc(string  $mode, string  $field, string|NULL  $function, boolean  $isTemplate = FALSE) : void

Binds an SQL function to a column.

This method can be used to setup a decode/encode scheme or perform UUID insertion. This method is especially useful for handling MySQL spatial columns, because they need to be processed first using the asText/GeomFromText functions.

Parameters

string $mode

mode to set function for, i.e. read or write

string $field

field (table.column) to bind SQL function to

string|NULL $function

SQL function to bind to field

boolean $isTemplate

TRUE if $function is an SQL string, FALSE for just a function name

addEventListener()

addEventListener(string  $eventname, \RedBeanPHP\Observer  $observer) : void

Implementation of the Observer Pattern.

Adds an event listener to the observable object. First argument should be the name of the event you wish to listen for. Second argument should be the object that wants to be notified in case the event occurs.

Parameters

string $eventname

event identifier

\RedBeanPHP\Observer $observer

observer instance

signal()

signal(string  $eventname, mixed  $info) : void

Notifies listeners.

Sends the signal $eventname, the event identifier and a message object to all observers that have been registered to receive notification for this event. Part of the observer pattern implementation in RedBeanPHP.

Parameters

string $eventname

event you want signal

mixed $info

message object to send along

setToolBox()

setToolBox(\RedBeanPHP\ToolBox  $toolbox) : void

Sets the toolbox to be used by the database pool.

Parameters

\RedBeanPHP\ToolBox $toolbox

toolbox

unboxIfNeeded()

unboxIfNeeded(\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel  $bean) : \RedBeanPHP\OODBBean

Unboxes a bean from a FUSE model if needed and checks whether the bean is an instance of OODBBean.

Parameters

\RedBeanPHP\OODBBean|\RedBeanPHP\SimpleModel $bean

bean you wish to unbox

Returns

\RedBeanPHP\OODBBean