PHP Class RedBeanPHP\Facade

Version Information RedBean Version @version 4
Author: Gabor de Mooij and the RedBeanPHP Community
显示文件 Open project: gabordemooij/redbean Class Usage Examples

Public Properties

Property Type Description
$currentDB string
$f Not in use (backward compatibility SQLHelper)
$toolbox ToolBox
$toolboxes array

Public Methods

Method Description
__callStatic ( string $pluginName, array $params ) : mixed Call static for use with dynamic plugins. This magic method will intercept static calls and route them to the specified plugin.
addDatabase ( string $key, string $dsn, string $user = NULL, null | string $pass = NULL, boolean $frozen = FALSE ) : void Adds a database to the facade, afterwards you can select the database using selectDatabase($key), where $key is the name you assigned to this database.
addTags ( OODBBean $bean, array $tagList ) : void Part of RedBeanPHP Tagging API.
aliases ( array $list ) : void Sets global aliases.
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.
beansToArray ( array $beans ) : array Little helper method for Resty Bean Can server and others.
begin ( ) : boolean Facade Convience method for adapter transaction system.
bindFunc ( string $mode, string $field, string $function ) : void Binds an SQL function to a column.
close ( ) : void Closes the database connection.
commit ( ) : boolean Facade Convience method for adapter transaction system.
configureFacadeWithToolbox ( ToolBox $tb ) : ToolBox Configures the facade, want to have a new Writer? A new Object Database or a new Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new toolbox.
convertToBean ( string $type, array $row, $metamask = NULL ) : array Just like converToBeans, but for one bean.
convertToBeans ( string $type, array $rows, $metamask = NULL ) : array Converts a series of rows to beans.
count ( string $type, string $addSQL = '', array $bindings = [] ) : integer Counts the number of beans of type $type.
debug ( boolean $tf = TRUE, integer $mode ) : RDefault Toggles DEBUG mode.
dispense ( string | array $typeOrBeanArray, $num = 1, boolean $alwaysReturnArray = FALSE ) : array | OODBBean Dispenses a new RedBean OODB Bean for use with the rest of the methods.
dispenseAll ( 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.
dispenseLabels ( string $type, array $labels ) : array A label is a bean with only an id, type and name property.
dump ( OODBBean | array $data ) : array Simple but effective debug function.
dup ( OODBBean $bean, array $trail = [], boolean $pid = FALSE, $filters = [] ) : array Makes a copy of a bean. This method makes a deep copy of the bean.The copy will have the following features.
duplicate ( OODBBean $bean, $filters = [] ) : array Makes a deep copy of a bean. This method makes a deep copy of the bean.The copy will have the following:
enum ( string $enum ) : array | OODBBean Generates and returns an ENUM value. This is how RedBeanPHP handles ENUMs.
exec ( string $sql, array $bindings = [] ) : integer Convenience function to execute Queries directly.
exportAll ( array | OODBBean $beans, boolean $parents = FALSE, array $filters = [] ) : array Exports a collection of beans. Handy for XML/JSON exports with a Javascript framework like Dojo or ExtJS.
ext ( string $pluginName, callable $callable ) : void Dynamically extends the facade with a plugin.
fancyDebug ( boolean $toggle = TRUE ) : void Turns on the fancy debugger.
find ( string $type, string $sql = NULL, array $bindings = [] ) : array Finds a bean using a type and a where clause (SQL).
findAll ( string $type, string $sql = NULL, array $bindings = [] ) : array
findAndExport ( string $type, string $sql = NULL, array $bindings = [] ) : array
findCollection ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\BeanCollection Finds a bean collection.
findLast ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean
findLike ( string $type, array $like = [], string $sql = '' ) : array Tries to find beans matching the specified type and criteria set.
findMulti ( array | string $types, $sql, array $bindings = [], array $remappings = [] ) : array Finds multiple types of beans at once and offers additional remapping functionality. This is a very powerful yet complex function.
findOne ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean
findOneOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean Same as findOrDispense but returns just one element.
findOrCreate ( string $type, array $like = [] ) : OODBBean Tries to find a bean matching a certain type and criteria set. If no beans are found a new bean will be created, the criteria will be imported into this bean and the bean will be stored and returned.
findOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : array Convience method. Tries to find beans of a certain type, if no beans are found, it dispenses a bean of that type.
flat ( array $array, $result = [] ) : array Flattens a multi dimensional bindings array for use with genSlots().
freeze ( $tf = TRUE ) Toggles fluid or frozen mode. In fluid mode the database structure is adjusted to accomodate your objects. In frozen mode this is not the case.
gatherLabels ( array $beans ) : array Gathers labels from beans. This function loops through the beans, collects the values of the name properties of each individual bean and stores the names in a new array. The array then gets sorted using the default sort function of PHP (sort).
genSlots ( array $array, $template = NULL ) : string Generates question mark slots for an array of values.
getAll ( string $sql, array $bindings = [] ) : array Convenience function to execute Queries directly.
getAssoc ( string $sql, array $bindings = [] ) : array Convenience function to execute Queries directly.
getAssocRow ( string $sql, array $bindings = [] ) : array Convenience function to execute Queries directly.
getCell ( string $sql, array $bindings = [] ) : string Convenience function to execute Queries directly.
getCol ( string $sql, array $bindings = [] ) : array Convenience function to execute Queries directly.
getColumns ( string $table ) : array Returns a list of columns. Format of this array: array( fieldname => type ) Note that this method only works in fluid mode because it might be quite heavy on production servers!
getDatabaseAdapter ( ) : DBAdapter Optional accessor for neat code.
getDuplicationManager ( ) : DuplicationManager Returns the current duplication manager instance.
getExtractedToolbox ( ) : array Mostly for internal use, but might be handy for some users.
getInsertID ( ) : mixed Returns the insert ID for databases that support/require this functionality. Alias for R::getAdapter()->getInsertID().
getLogger ( ) : RedBeanPHP\Logger Returns the current logger instance being used by the database object.
getLogs ( ) : array Returns the log entries written after the startLogging.
getPDO ( ) : null | PDO In case you use PDO (which is recommended and the default but not mandatory, hence the database adapter), you can use this method to obtain the PDO object directly.
getQueryCount ( ) : integer Returns the number of SQL queries processed.
getRedBean ( ) : OODB Optional accessor for neat code.
getRow ( string $sql, array $bindings = [] ) : array Convenience function to execute Queries directly.
getToolBox ( ) : ToolBox Returns the toolbox currently used by the facade.
getVersion ( ) : string Returns the RedBeanPHP version string.
getWriter ( ) : RedBeanPHP\QueryWriter Optional accessor for neat code.
hasDatabase ( string $key ) : boolean Determines whether a database identified with the specified key has already been added to the facade. This function will return TRUE if the database indicated by the key is available and FALSE otherwise.
hasTag ( OODBBean $bean, array $tags, boolean $all = FALSE ) : boolean Part of RedBeanPHP Tagging API.
inspect ( string $type = NULL ) : array Inspects the database schema. If you pass the type of a bean this method will return the fields of its table in the database.
isoDate ( mixed $time = NULL ) : string Simple convenience function, returns ISO date formatted representation of $time.
isoDateTime ( mixed $time = NULL ) : string Simple convenience function, returns ISO date time formatted representation of $time.
load ( string $type, integer $id ) : OODBBean Loads a bean from the object database.
loadAll ( string $type, array $ids ) : array
loadMulti ( string | array $types, mixed $id ) : OODBBean Loads multiple types of beans with the same ID.
nuke ( ) : void Nukes the entire database.
renameAssociation ( string | array $from, string $to = NULL ) : void Facade method for AQueryWriter::renameAssociation()
resetQueryCount ( ) : integer Resets the Query counter.
rollback ( ) : boolean Facade Convience method for adapter transaction system.
selectDatabase ( string $key ) : boolean Selects a different database for the Facade to work with.
setAutoResolve ( boolean $automatic = TRUE ) : void Alias for setAutoResolve() method on OODBBean.
setDatabaseAdapter ( RedBeanPHP\Adapter $adapter ) : void Optional accessor for neat code.
setErrorHandlingFUSE ( integer $mode, callable | null $func = NULL ) : array Sets the error mode for FUSE.
setNarrowFieldMode ( boolean $mode ) : void Toggles Narrow Field Mode.
setRedBean ( OODB $redbean ) Optional accessor for neat code.
setWriter ( RedBeanPHP\QueryWriter $writer ) : void Optional accessor for neat code.
setup ( string $dsn = NULL, string $username = NULL, string $password = NULL, boolean $frozen = FALSE ) : ToolBox Kickstarts redbean for you. This method should be called before you start using RedBean. The Setup() method can be called without any arguments, in this case it will try to create a SQLite database in /tmp called red.db (this only works on UNIX-like systems).
startLogging ( ) : void Starts logging queries.
stopLogging ( ) : void Stops logging, comfortable method to stop logging of queries.
store ( OODBBean | 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.
storeAll ( array $beans ) : array Short hand function to store a set of beans at once, IDs will be returned as an array. For information please consult the R::store() function.
tag ( OODBBean $bean, mixed $tagList = NULL ) : string Part of RedBeanPHP Tagging API.
tagged ( string $beanType, array $tagList, string $sql = '', array $bindings = [] ) : array Part of RedBeanPHP Tagging API.
taggedAll ( string $beanType, array $tagList, string $sql = '', array $bindings = [] ) : array Part of RedBeanPHP Tagging API.
testConnection ( ) : boolean Tests the connection.
transaction ( callable $callback ) : mixed Wraps a transaction around a closure or string callback.
trash ( $beanOrType, integer $id = NULL ) : void Removes a bean from the database.
trashAll ( array $beans ) : void Short hand function to trash a set of beans at once.
untag ( OODBBean $bean, array $tagList ) : void Part of RedBeanPHP Tagging API.
useExportCase ( string $caseStyle = 'default' ) : void Selects case style for export.
useWriterCache ( boolean $yesNo ) : void Toggles Writer Cache.
wipe ( string $beanType ) : boolean Wipes all beans of type $beanType.

Private Methods

Method Description
query ( string $method, string $sql, array $bindings ) : array Internal Query function, executes the desired query. Used by all facade query functions. This keeps things DRY.

Method Details

__callStatic() public static method

Call static for use with dynamic plugins. This magic method will intercept static calls and route them to the specified plugin.
public static __callStatic ( string $pluginName, array $params ) : mixed
$pluginName string name of the plugin
$params array list of arguments to pass to plugin method
return mixed

addDatabase() public static method

Usage: R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' ); R::selectDatabase( 'database-1' ); //to select database again This method allows you to dynamically add (and select) new databases to the facade. Adding a database with the same key will cause an exception.
public static addDatabase ( string $key, string $dsn, string $user = NULL, null | string $pass = NULL, boolean $frozen = FALSE ) : void
$key string ID for the database
$dsn string DSN for the database
$user string user for connection
$pass null | string password for connection
$frozen boolean whether this database is frozen or not
return void

addTags() public static method

Adds tags to a bean. If $tagList is a comma separated list of tags all tags will be associated with the bean. You may also pass an array instead of a string.
public static addTags ( OODBBean $bean, array $tagList ) : void
$bean OODBBean bean to tag
$tagList array list of tags to add to bean
return void

aliases() public static method

Registers a batch of aliases in one go. This works the same as fetchAs and setAutoResolve but explicitly. For instance if you register the alias 'cover' for 'page' a property containing a reference to a page bean called 'cover' will correctly return the page bean and not a (non-existant) cover bean. R::aliases( array( 'cover' => 'page' ) ); $book = R::dispense( 'book' ); $page = R::dispense( 'page' ); $book->cover = $page; R::store( $book ); $book = $book->fresh(); $cover = $book->cover; echo $cover->getMeta( 'type' ); //page The format of the aliases registration array is: {alias} => {actual type} In the example above we use: cover => page From that point on, every bean reference to a cover will return a 'page' bean. Note that with autoResolve this feature along with fetchAs() is no longer very important, although relying on explicit aliases can be a bit faster.
public static aliases ( array $list ) : void
$list array list of global aliases to use
return void

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

beansToArray() public static method

Takes an array of beans and exports each bean. Unlike exportAll this method does not recurse into own lists and shared lists, the beans are exported as-is, only loaded lists are exported.
public static beansToArray ( array $beans ) : array
$beans array beans
return array

begin() public static method

Begins a transaction.
public static begin ( ) : boolean
return boolean

bindFunc() public static method

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. Example: R::bindFunc( 'read', 'location.point', 'asText' ); R::bindFunc( 'write', 'location.point', 'GeomFromText' ); Passing NULL as the function will reset (clear) the function for this column/mode.
public static bindFunc ( string $mode, string $field, string $function ) : void
$mode string mode for function: i.e. read or write
$field string field (table.column) to bind function to
$function string SQL function to bind to specified column
return void

close() public static method

Closes the database connection.
public static close ( ) : void
return void

commit() public static method

Commits a transaction.
public static commit ( ) : boolean
return boolean

configureFacadeWithToolbox() public static method

Configures the facade, want to have a new Writer? A new Object Database or a new Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new toolbox.
public static configureFacadeWithToolbox ( ToolBox $tb ) : ToolBox
$tb ToolBox toolbox to configure facade with
return ToolBox

convertToBean() public static method

Just like converToBeans, but for one bean.
See also: convertToBeans for more details.
public static convertToBean ( string $type, array $row, $metamask = NULL ) : array
$type string type of beans to produce
$row array one row from the database
return array

convertToBeans() public static method

This method converts a series of rows to beans. The type of the desired output beans can be specified in the first parameter. The second parameter is meant for the database result rows. Usage: $rows = R::getAll( 'SELECT * FROM ...' ) $beans = R::convertToBeans( $rows ); As of version 4.3.2 you can specify a meta-mask. Data from columns with names starting with the value specified in the mask will be transferred to the meta section of a bean (under data.bundle). $rows = R::getAll( 'SELECT FROM... COUNT(*) AS extra_count ...' ); $beans = R::convertToBeans( $rows ); $bean = reset( $beans ); $data = $bean->getMeta( 'data.bundle' ); $extra_count = $data['extra_count'];
public static convertToBeans ( string $type, array $rows, $metamask = NULL ) : array
$type string type of beans to produce
$rows array must contain an array of array
return array

count() public static 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 static 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

debug() public static method

In Debug mode all SQL that happens under the hood will be printed to the screen and/or logged. If no database connection has been configured using R::setup() or R::selectDatabase() this method will throw an exception. There are 2 debug styles: Classic: separate parameter bindings, explicit and complete but less readable Fancy: interpersed bindings, truncates large strings, highlighted schema changes Fancy style is more readable but sometimes incomplete. The first parameter turns debugging ON or OFF. The second parameter indicates the mode of operation: 0 Log and write to STDOUT classic style (default) 1 Log only, class style 2 Log and write to STDOUT fancy style 3 Log only, fancy style This function always returns the logger instance created to generate the debug messages.
public static debug ( boolean $tf = TRUE, integer $mode ) : RDefault
$tf boolean debug mode (TRUE or FALSE)
$mode integer mode of operation
return RedBeanPHP\Logger\RDefault

dispense() public static method

Dispenses a new RedBean OODB Bean for use with the rest of the methods.
public static dispense ( string | array $typeOrBeanArray, $num = 1, boolean $alwaysReturnArray = FALSE ) : array | OODBBean
$typeOrBeanArray string | array type or bean array to import
$alwaysReturnArray boolean if TRUE always returns the result as an array
return array | OODBBean

dispenseAll() public static method

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.
public static dispenseAll ( string $order, boolean $onlyArrays = FALSE ) : array
$order string a description of the desired dispense order using the syntax above
$onlyArrays boolean return only arrays even if amount < 2
return array

dispenseLabels() public static method

This function will dispense beans for all entries in the array. The values of the array will be assigned to the name property of each individual bean.
public static dispenseLabels ( string $type, array $labels ) : array
$type string type of beans you would like to have
$labels array list of labels, names for each bean
return array

dump() public static method

Given a one or more beans this method will return an array containing first part of the string representation of each item in the array.
public static dump ( OODBBean | array $data ) : array
$data OODBBean | array either a bean or an array of beans
return array

dup() public static method

- All beans in own-lists will be duplicated as well - All references to shared beans will be copied but not the shared beans themselves - All references to parent objects (_id fields) will be copied but not the parents themselves In most cases this is the desired scenario for copying beans. This function uses a trail-array to prevent infinite recursion, if a recursive bean is found (i.e. one that already has been processed) the ID of the bean will be returned. This should not happen though. Note: This function does a reflectional database query so it may be slow.
Deprecation: This function is deprecated in favour of R::duplicate(). This function has a confusing method signature, the R::duplicate() function only accepts two arguments: bean and filters.
public static dup ( OODBBean $bean, array $trail = [], boolean $pid = FALSE, $filters = [] ) : array
$bean OODBBean bean to be copied
$trail array for internal usage, pass array()
$pid boolean for internal usage
return array

duplicate() public static method

* All beans in own-lists will be duplicated as well * All references to shared beans will be copied but not the shared beans themselves * All references to parent objects (_id fields) will be copied but not the parents themselves In most cases this is the desired scenario for copying beans. This function uses a trail-array to prevent infinite recursion, if a recursive bean is found (i.e. one that already has been processed) the ID of the bean will be returned. This should not happen though. Note: This function does a reflectional database query so it may be slow. Note: This is a simplified version of the deprecated R::dup() function.
public static duplicate ( OODBBean $bean, $filters = [] ) : array
$bean OODBBean bean to be copied
return array

enum() public static method

Either returns a (newly created) bean respresenting the desired ENUM value or returns a list of all enums for the type. To obtain (and add if necessary) an ENUM value: $tea->flavour = R::enum( 'flavour:apple' ); Returns a bean of type 'flavour' with name = apple. This will add a bean with property name (set to APPLE) to the database if it does not exist yet. To obtain all flavours: R::enum('flavour'); To get a list of all flavour names: R::gatherLabels( R::enum( 'flavour' ) );
public static enum ( string $enum ) : array | OODBBean
$enum string either type or type-value
return array | OODBBean

exec() public static method

Executes SQL.
public static exec ( string $sql, array $bindings = [] ) : integer
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return integer

exportAll() public static method

What will be exported: * contents of the bean * all own bean lists (recursively) * all shared beans (not THEIR own lists)
public static exportAll ( array | OODBBean $beans, boolean $parents = FALSE, array $filters = [] ) : array
$beans array | OODBBean beans to be exported
$parents boolean whether you want parent beans to be exported
$filters array whitelist of types
return array

ext() public static method

Using this method you can register your plugin with the facade and then use the plugin by invoking the name specified plugin name as a method on the facade. Usage: R::ext( 'makeTea', function() { ... } ); Now you can use your makeTea plugin like this: R::makeTea();
public static ext ( string $pluginName, callable $callable ) : void
$pluginName string name of the method to call the plugin
$callable callable a PHP callable
return void

fancyDebug() public static method

In 'fancy' mode the debugger will output queries with bound parameters inside the SQL itself. This method has been added to offer a convenient way to activate the fancy debugger system in one call.
public static fancyDebug ( boolean $toggle = TRUE ) : void
$toggle boolean TRUE to activate debugger and select 'fancy' mode
return void

find() public static method

As with most Query tools in RedBean you can provide values to be inserted in the SQL statement by populating the value array parameter; you can either use the question mark notation or the slot-notation (:keyname).
public static find ( string $type, string $sql = NULL, array $bindings = [] ) : array
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return array

findAll() public static method

See also: Facade::find The findAll() method differs from the find() method in that it does not assume a WHERE-clause, so this is valid: R::findAll('person',' ORDER BY name DESC '); Your SQL does not have to start with a valid WHERE-clause condition.
public static findAll ( string $type, string $sql = NULL, array $bindings = [] ) : array
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return array

findAndExport() public static method

See also: Facade::find The variation also exports the beans (i.e. it returns arrays).
public static findAndExport ( string $type, string $sql = NULL, array $bindings = [] ) : array
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return array

findCollection() public static method

Use this for large datasets.
public static findCollection ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\BeanCollection
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return redbeanphp\BeanCollection

findLast() public static method

See also: Facade::find This variation returns the last bean only.
public static findLast ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return OODBBean

findLike() public static method

If the optional additional SQL snippet is a condition, it will be glued to the rest of the query using the AND operator.
public static findLike ( string $type, array $like = [], string $sql = '' ) : array
$type string type of bean to search for
$like array optional criteria set describing the bean to search for
$sql string optional additional SQL for sorting
return array

findMulti() public static method

For details see Finder::findMulti().
See also: Finder::findMulti()
public static findMulti ( array | string $types, $sql, array $bindings = [], array $remappings = [] ) : array
$types array | string a list of bean types to find
$bindings array SQL bindings
$remappings array an array of remapping arrays containing closures
return array

findOne() public static method

See also: Facade::find This variation returns the first bean only.
public static findOne ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean
$type string the type of bean you are looking for
$sql string SQL query to find the desired bean, starting right after WHERE clause
$bindings array array of values to be bound to parameters in query
return OODBBean

findOneOrDispense() public static method

Same as findOrDispense but returns just one element.
public static findOneOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean
$type string type of bean you are looking for
$sql string SQL code for finding the bean
$bindings array parameters to bind to SQL
return OODBBean

findOrCreate() public static method

If multiple beans match the criteria only the first one will be returned.
public static findOrCreate ( string $type, array $like = [] ) : OODBBean
$type string type of bean to search for
$like array criteria set describing the bean to search for
return OODBBean

findOrDispense() public static method

Note that this function always returns an array.
public static findOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : array
$type string type of bean you are looking for
$sql string SQL code for finding the bean
$bindings array parameters to bind to SQL
return array

flat() public static method

Flattens a multi dimensional bindings array for use with genSlots().
public static flat ( array $array, $result = [] ) : array
$array array array to flatten
return array

freeze() public static method

You can also pass an array containing a selection of frozen types. Let's call this chilly mode, it's just like fluid mode except that certain types (i.e. tables) aren't touched.
public static freeze ( $tf = TRUE )

gatherLabels() public static method

Gathers labels from beans. This function loops through the beans, collects the values of the name properties of each individual bean and stores the names in a new array. The array then gets sorted using the default sort function of PHP (sort).
public static gatherLabels ( array $beans ) : array
$beans array list of beans to loop
return array

genSlots() public static method

Generates question mark slots for an array of values.
public static genSlots ( array $array, $template = NULL ) : string
$array array array to generate question mark slots for
return string

getAll() public static method

Executes SQL.
public static getAll ( string $sql, array $bindings = [] ) : array
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return array

getAssoc() public static method

Executes SQL. Results will be returned as an associative array. The first column in the select clause will be used for the keys in this array and the second column will be used for the values. If only one column is selected in the query, both key and value of the array will have the value of this field for each row.
public static getAssoc ( string $sql, array $bindings = [] ) : array
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return array

getAssocRow() public static method

Executes SQL. Results will be returned as an associative array indexed by the first column in the select.
public static getAssocRow ( string $sql, array $bindings = [] ) : array
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return array

getCell() public static method

Executes SQL.
public static getCell ( string $sql, array $bindings = [] ) : string
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return string

getCol() public static method

Executes SQL.
public static getCol ( string $sql, array $bindings = [] ) : array
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return array

getColumns() public static method

Returns a list of columns. Format of this array: array( fieldname => type ) Note that this method only works in fluid mode because it might be quite heavy on production servers!
public static getColumns ( string $table ) : array
$table string name of the table (not type) you want to get columns of
return array

getDatabaseAdapter() public static method

Sets the database adapter you want to use.
public static getDatabaseAdapter ( ) : DBAdapter
return RedBeanPHP\Adapter\DBAdapter

getDuplicationManager() public static method

Returns the current duplication manager instance.
public static getDuplicationManager ( ) : DuplicationManager
return DuplicationManager

getExtractedToolbox() public static method

This returns all the components of the currently selected toolbox. Returns the components in the following order: # OODB instance (getRedBean()) # Database Adapter # Query Writer # Toolbox itself
public static getExtractedToolbox ( ) : array
return array

getInsertID() public static method

Returns the insert ID for databases that support/require this functionality. Alias for R::getAdapter()->getInsertID().
public static getInsertID ( ) : mixed
return mixed

getLogger() public static method

Returns the current logger instance being used by the database object.
public static getLogger ( ) : RedBeanPHP\Logger
return RedBeanPHP\Logger

getLogs() public static method

Returns the log entries written after the startLogging.
public static getLogs ( ) : array
return array

getPDO() public static method

This is a convenience method, it will do the same as: R::getDatabaseAdapter()->getDatabase()->getPDO(); If the PDO object could not be found, for whatever reason, this method will return NULL instead.
public static getPDO ( ) : null | PDO
return null | PDO

getQueryCount() public static method

Returns the number of SQL queries processed.
public static getQueryCount ( ) : integer
return integer

getRedBean() public static method

Sets the database adapter you want to use.
public static getRedBean ( ) : OODB
return OODB

getRow() public static method

Executes SQL.
public static getRow ( string $sql, array $bindings = [] ) : array
$sql string SQL query to execute
$bindings array a list of values to be bound to query parameters
return array

getToolBox() public static method

To set the toolbox use R::setup() or R::configureFacadeWithToolbox(). To create a toolbox use Setup::kickstart(). Or create a manual toolbox using the ToolBox class.
public static getToolBox ( ) : ToolBox
return ToolBox

getVersion() public static method

The RedBeanPHP version string always has the same format "X.Y" where X is the major version number and Y is the minor version number. Point releases are not mentioned in the version string.
public static getVersion ( ) : string
return string

getWriter() public static method

Sets the database adapter you want to use.
public static getWriter ( ) : RedBeanPHP\QueryWriter
return RedBeanPHP\QueryWriter

hasDatabase() public static method

Determines whether a database identified with the specified key has already been added to the facade. This function will return TRUE if the database indicated by the key is available and FALSE otherwise.
public static hasDatabase ( string $key ) : boolean
$key string the key/name of the database to check for
return boolean

hasTag() public static method

Tests whether a bean has been associated with one ore more of the listed tags. If the third parameter is TRUE this method will return TRUE only if all tags that have been specified are indeed associated with the given bean, otherwise FALSE. If the third parameter is FALSE this method will return TRUE if one of the tags matches, FALSE if none match.
public static hasTag ( OODBBean $bean, array $tags, boolean $all = FALSE ) : boolean
$bean OODBBean bean to check for tags
$tags array list of tags
$all boolean whether they must all match or just some
return boolean

inspect() public static method

The keys of this array will be the field names and the values will be the column types used to store their values. If no type is passed, this method returns a list of all tables in the database.
public static inspect ( string $type = NULL ) : array
$type string Type of bean (i.e. table) you want to inspect
return array

isoDate() public static method

Simple convenience function, returns ISO date formatted representation of $time.
public static isoDate ( mixed $time = NULL ) : string
$time mixed UNIX timestamp
return string

isoDateTime() public static method

Simple convenience function, returns ISO date time formatted representation of $time.
public static isoDateTime ( mixed $time = NULL ) : string
$time mixed UNIX timestamp
return string

load() public static method

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.
public static load ( string $type, integer $id ) : OODBBean
$type string type of bean you want to load
$id integer ID of the bean you want to load
return OODBBean

loadAll() public static method

See also: Facade::batch Alias for batch(). Batch method is older but since we added so-called *All methods like storeAll, trashAll, dispenseAll and findAll it seemed logical to improve the consistency of the Facade API and also add an alias for batch() called loadAll.
public static loadAll ( string $type, array $ids ) : array
$type string type of beans
$ids array ids to load
return array

loadMulti() public static method

This might look like a strange method, however it can be useful for loading a one-to-one relation. Usage: list( $author, $bio ) = R::loadMulti( 'author, bio', $id );
public static loadMulti ( string | array $types, mixed $id ) : OODBBean
$types string | array the set of types to load at once
$id mixed the common ID
return OODBBean

nuke() public static method

This will remove all schema structures from the database. Only works in fluid mode. Be careful with this method.
public static nuke ( ) : void
return void

renameAssociation() public static method

Facade method for AQueryWriter::renameAssociation()
public static renameAssociation ( string | array $from, string $to = NULL ) : void
$from string | array
$to string
return void

resetQueryCount() public static method

Resets the Query counter.
public static resetQueryCount ( ) : integer
return integer

rollback() public static method

Rolls back a transaction.
public static rollback ( ) : boolean
return boolean

selectDatabase() public static method

If you use the R::setup() you don't need this method. This method is meant for multiple database setups. This method selects the database identified by the database ID ($key). Use addDatabase() to add a new database, which in turn can be selected using selectDatabase(). If you use R::setup(), the resulting database will be stored under key 'default', to switch (back) to this database use R::selectDatabase( 'default' ). This method returns TRUE if the database has been switched and FALSE otherwise (for instance if you already using the specified database).
public static selectDatabase ( string $key ) : boolean
$key string Key of the database to select
return boolean

setAutoResolve() public static method

Enables or disables auto-resolving fetch types. Auto-resolving aliased parent beans is convenient but can be slower and can create infinite recursion if you used aliases to break cyclic relations in your domain.
public static setAutoResolve ( boolean $automatic = TRUE ) : void
$automatic boolean TRUE to enable automatic resolving aliased parents
return void

setDatabaseAdapter() public static method

Sets the database adapter you want to use.
public static setDatabaseAdapter ( RedBeanPHP\Adapter $adapter ) : void
$adapter RedBeanPHP\Adapter Database Adapter for facade to use
return void

setErrorHandlingFUSE() public static method

What to do if a FUSE model method does not exist? You can set the following options: * OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL * OODBBean::C_ERR_LOG, logs the incident using error_log * OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE * OODBBean::C_ERR_WARN, triggers a E_USER_WARNING * OODBBean::C_ERR_EXCEPTION, throws an exception * OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function) * OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR Custom handler method signature: handler( array ( 'message' => string 'bean' => OODBBean 'method' => string ) ) This method returns the old mode and handler as an array.
public static setErrorHandlingFUSE ( integer $mode, callable | null $func = NULL ) : array
$mode integer mode, determines how to handle errors
$func callable | null custom handler (if applicable)
return array

setNarrowFieldMode() public static method

See documentation in QueryWriter.
public static setNarrowFieldMode ( boolean $mode ) : void
$mode boolean TRUE = Narrow Field Mode
return void

setRedBean() public static method

Sets the database adapter you want to use.
public static setRedBean ( OODB $redbean )
$redbean OODB Object Database for facade to use

setWriter() public static method

Sets the database adapter you want to use.
public static setWriter ( RedBeanPHP\QueryWriter $writer ) : void
$writer RedBeanPHP\QueryWriter Query Writer instance for facade to use
return void

setup() public static method

Kickstarts redbean for you. This method should be called before you start using RedBean. The Setup() method can be called without any arguments, in this case it will try to create a SQLite database in /tmp called red.db (this only works on UNIX-like systems).
public static setup ( string $dsn = NULL, string $username = NULL, string $password = NULL, boolean $frozen = FALSE ) : ToolBox
$dsn string Database connection string
$username string Username for database
$password string Password for database
$frozen boolean TRUE if you want to setup in frozen mode
return ToolBox

startLogging() public static method

Use this method to start logging SQL queries being executed by the adapter.
public static startLogging ( ) : void
return void

stopLogging() public static method

Stops logging, comfortable method to stop logging of queries.
public static stopLogging ( ) : void
return void

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

storeAll() public static method

A loop saver.
public static storeAll ( array $beans ) : array
$beans array list of beans to be stored
return array

tag() public static method

Tags a bean or returns tags associated with a bean. If $tagList is NULL or omitted this method will return a comma separated list of tags associated with the bean provided. If $tagList is a comma separated list (string) of tags all tags will be associated with the bean. You may also pass an array instead of a string.
public static tag ( OODBBean $bean, mixed $tagList = NULL ) : string
$bean OODBBean bean to tag
$tagList mixed tags to attach to the specified bean
return string

tagged() public static method

Returns all beans that have been tagged with one of the tags given.
public static tagged ( string $beanType, array $tagList, string $sql = '', array $bindings = [] ) : array
$beanType string type of bean you are looking for
$tagList array list of tags to match
$sql string additional SQL query snippet
$bindings array a list of values to bind to the query parameters
return array

taggedAll() public static method

Returns all beans that have been tagged with ALL of the tags given.
public static taggedAll ( string $beanType, array $tagList, string $sql = '', array $bindings = [] ) : array
$beanType string type of bean you are looking for
$tagList array list of tags to match
$sql string additional SQL query snippet
$bindings array a list of values to bind to the query parameters
return array

testConnection() public static method

Returns TRUE if connection has been established and FALSE otherwise.
public static testConnection ( ) : boolean
return boolean

transaction() public static method

If an Exception is thrown inside, the operation is automatically rolled back. If no Exception happens, it commits automatically. It also supports (simulated) nested transactions (that is useful when you have many methods that needs transactions but are unaware of each other). Example: $from = 1; $to = 2; $amount = 300; R::transaction(function() use($from, $to, $amount) { $accountFrom = R::load('account', $from); $accountTo = R::load('account', $to); $accountFrom->money -= $amount; $accountTo->money += $amount; R::store($accountFrom); R::store($accountTo); });
public static transaction ( callable $callback ) : mixed
$callback callable Closure (or other callable) with the transaction logic
return mixed

trash() public static method

This function will remove the specified OODBBean Bean Object from the database. This facade method also accepts a type-id combination, in the latter case this method will attempt to load the specified bean and THEN trash it.
public static trash ( $beanOrType, integer $id = NULL ) : void
$id integer ID if the bean to trash (optional, type-id variant only)
return void

trashAll() public static method

For information please consult the R::trash() function. A loop saver.
public static trashAll ( array $beans ) : void
$beans array list of beans to be trashed
return void

untag() public static method

Removes all specified tags from the bean. The tags specified in the second parameter will no longer be associated with the bean.
public static untag ( OODBBean $bean, array $tagList ) : void
$bean OODBBean tagged bean
$tagList array list of tags (names)
return void

useExportCase() public static method

This will determine the case style for the keys of exported beans (see exportAll). The following options are accepted: * 'default' RedBeanPHP by default enforces Snake Case (i.e. book_id is_valid ) * 'camel' Camel Case (i.e. bookId isValid ) * 'dolphin' Dolphin Case (i.e. bookID isValid ) Like CamelCase but ID is written all uppercase
public static useExportCase ( string $caseStyle = 'default' ) : void
$caseStyle string case style identifier
return void

useWriterCache() public static method

Turns the Writer Cache on or off. The Writer Cache is a simple query based caching system that may improve performance without the need for cache management. This caching system will cache non-modifying queries that are marked with special SQL comments. As soon as a non-marked query gets executed the cache will be flushed. Only non-modifying select queries have been marked therefore this mechanism is a rather safe way of caching, requiring no explicit flushes or reloads. Of course this does not apply if you intend to test or simulate concurrent querying.
public static useWriterCache ( boolean $yesNo ) : void
$yesNo boolean TRUE to enable cache, FALSE to disable cache
return void

wipe() public static method

Wipes all beans of type $beanType.
public static wipe ( string $beanType ) : boolean
$beanType string type of bean you want to destroy entirely
return boolean

Property Details

$currentDB public_oe static_oe property

public static string $currentDB
return string

$f public_oe static_oe property

Not in use (backward compatibility SQLHelper)
public static $f

$toolbox public_oe static_oe property

public static ToolBox $toolbox
return ToolBox

$toolboxes public_oe static_oe property

public static array $toolboxes
return array