Methods summary
public static
string
|
#
getVersion( )
Returns the RedBeanPHP version string.
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.
Returns the RedBeanPHP version string.
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.
Returns
string
|
public static
boolean
|
#
testConnection( )
Tests the connection.
Returns TRUE if connection has been established and
FALSE otherwise.
Tests the connection.
Returns TRUE if connection has been established and
FALSE otherwise.
Returns
boolean
|
public static
RedBeanPHP\ToolBox
|
#
setup( string $dsn = NULL, string $username = NULL, string $password = NULL, boolean $frozen = FALSE )
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).
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).
Parameters
- $dsn
- Database connection string
- $username
- Username for database
- $password
- Password for database
- $frozen
- TRUE if you want to setup in frozen mode
Returns
|
public static
|
#
setNarrowFieldMode( boolean $mode )
Toggles Narrow Field Mode.
See documentation in QueryWriter.
Toggles Narrow Field Mode.
See documentation in QueryWriter.
Parameters
- $mode
- TRUE = Narrow Field Mode
|
public static
mixed
|
#
transaction( callable $callback )
Wraps a transaction around a closure or string callback.
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).
Wraps a transaction around a closure or string callback.
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);
});
Parameters
- $callback
- Closure (or other callable) with the transaction logic
Returns
mixed
|
public static
|
#
addDatabase( string $key, string $dsn, string $user = NULL, null|string $pass = NULL, boolean $frozen = FALSE )
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.
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.
Usage:
R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' );
R::selectDatabase( 'database-1' );
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.
Parameters
- $key
- ID for the database
- $dsn
- DSN for the database
- $user
- user for connection
- $pass
- password for connection
- $frozen
- whether this database is frozen or not
|
public static
boolean
|
#
hasDatabase( string $key )
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.
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.
Parameters
- $key
- the key/name of the database to check for
Returns
boolean
|
public static
boolean
|
#
selectDatabase( string $key )
Selects a different database for the Facade to work with.
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).
Selects a different database for the Facade to work with.
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).
Parameters
- $key
- Key of the database to select
Returns
boolean
|
public static
RedBeanPHP\Logger\RDefault
|
#
debug( boolean $tf = TRUE, integer $mode = 0 )
Toggles DEBUG mode.
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.
Toggles DEBUG mode.
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.
Parameters
- $tf
- debug mode (TRUE or FALSE)
- $mode
- mode of operation
Returns
Throws
|
public static
|
#
fancyDebug( boolean $toggle = TRUE )
Turns on the fancy debugger.
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.
Turns on the fancy debugger.
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.
Parameters
- $toggle
- TRUE to activate debugger and select 'fancy' mode
|
public static
array
|
#
inspect( string $type = NULL )
Inspects the database schema. If you pass the type of a bean this
method will return the fields of its table in the database.
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.
Inspects the database schema. If you pass the type of a bean this
method will return the fields of its table in the database.
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.
Parameters
- $type
- Type of bean (i.e. table) you want to inspect
Returns
array
|
public static
integer|string
|
#
store( RedBeanPHP\OODBBean |RedBeanPHP\SimpleModel $bean )
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.
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.
Parameters
Returns
integer|string
|
public static
|
#
freeze( boolean|array $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.
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.
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.
Parameters
|
public static
RedBeanPHP\OODBBean
|
#
loadMulti( string|array $types, mixed $id )
Loads multiple types of beans with the same ID.
This might look like a strange method, however it can be useful
for loading a one-to-one relation.
Loads multiple types of beans with the same ID.
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 );
Parameters
- $types
- the set of types to load at once
- $id
- the common ID
Returns
|
public static
RedBeanPHP\OODBBean
|
#
load( string $type, integer $id )
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().
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
- $type
- type of bean you want to load
- $id
- ID of the bean you want to load
Returns
|
public static
|
#
trash( string|RedBeanPHP\OODBBean |RedBeanPHP\SimpleModel $beanOrType, integer $id = NULL )
Removes a bean from the database.
This function will remove the specified OODBBean
Bean Object from the database.
Removes a bean from the database.
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.
Parameters
- $beanOrType
- $bean bean you want to remove from database
- $id
- ID if the bean to trash (optional, type-id variant only)
|
public static
array|RedBeanPHP\OODBBean
|
#
dispense( string|array $typeOrBeanArray, integer $num = 1, boolean $alwaysReturnArray = FALSE )
Dispenses a new RedBean OODB Bean for use with
the rest of the methods.
Dispenses a new RedBean OODB Bean for use with
the rest of the methods.
Parameters
- $typeOrBeanArray
- type or bean array to import
- $num
- $number number of beans to dispense
- $alwaysReturnArray
- if TRUE always returns the result as an array
Returns
|
public static
array
|
#
dispenseAll( string $order, boolean $onlyArrays = FALSE )
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.
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.
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.
Parameters
- $order
- a description of the desired dispense order using the syntax above
- $onlyArrays
- return only arrays even if amount < 2
Returns
array
|
public static
array
|
#
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.
Convience method. Tries to find beans of a certain type,
if no beans are found, it dispenses a bean of that type.
Parameters
- $type
- type of bean you are looking for
- $sql
- SQL code for finding the bean
- $bindings
- parameters to bind to SQL
Returns
array
|
public static
array
|
#
find( string $type, string $sql = NULL, array $bindings = array() )
Finds a bean using a type and a where clause (SQL).
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).
Finds a bean using a type and a where clause (SQL).
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).
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
array
|
public static
array
|
#
findAll( string $type, string $sql = NULL, array $bindings = array() )
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
array
See
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
array
|
#
findAndExport( string $type, string $sql = NULL, array $bindings = array() )
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
array
See
Facade::find
The variation also exports the beans (i.e. it returns arrays).
|
public static
RedBeanPHP\OODBBean
|
#
findOne( string $type, string $sql = NULL, array $bindings = array() )
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
See
Facade::find
This variation returns the first bean only.
|
public static
RedBeanPHP\OODBBean
|
#
findLast( string $type, string $sql = NULL, array $bindings = array() )
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
See
Facade::find
This variation returns the last bean only.
|
public static
RedBeanPHP\BeanCollection
|
#
findCollection( string $type, string $sql = NULL, array $bindings = array() )
Finds a bean collection.
Use this for large datasets.
Finds a bean collection.
Use this for large datasets.
Parameters
- $type
- the type of bean you are looking for
- $sql
- SQL query to find the desired bean, starting right after WHERE clause
- $bindings
- array of values to be bound to parameters in query
Returns
|
public static
array
|
#
findMulti( array|string $types, string|array $sql, array $bindings = array(), array $remappings = array() )
Finds multiple types of beans at once and offers additional
remapping functionality. This is a very powerful yet complex function.
For details see Finder::findMulti().
Finds multiple types of beans at once and offers additional
remapping functionality. This is a very powerful yet complex function.
For details see Finder::findMulti().
Parameters
- $types
- a list of bean types to find
- $sql
- $sqlOrArr SQL query string or result set array
- $bindings
- SQL bindings
- $remappings
- an array of remapping arrays containing closures
Returns
array
See
|
public static
array
|
#
batch( string $type, array $ids )
Returns an array of beans. Pass a type and a series of ids and
this method will bring you the corresponding beans.
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
- $type
- type of beans
- $ids
- ids to load
Returns
array
|
public static
array
|
#
loadAll( string $type, array $ids )
Parameters
- $type
- type of beans
- $ids
- ids to load
Returns
array
See
Facade::batch
Alias for batch(). Batch method is older but since we added so-called *All
methods like storeAll , RedBeanPHP\Facade::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
integer
|
#
exec( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Convenience function to execute Queries directly.
Executes SQL.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
integer
|
public static
array
|
#
getAll( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Convenience function to execute Queries directly.
Executes SQL.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
array
|
public static
string
|
#
getCell( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Convenience function to execute Queries directly.
Executes SQL.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
string
|
public static
array
|
#
getRow( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Convenience function to execute Queries directly.
Executes SQL.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
array
|
public static
array
|
#
getCol( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Convenience function to execute Queries directly.
Executes SQL.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
array
|
public static
array
|
#
getAssoc( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
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.
Convenience function to execute Queries directly.
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.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
array
|
public static
array
|
#
getAssocRow( string $sql, array $bindings = array() )
Convenience function to execute Queries directly.
Executes SQL.
Results will be returned as an associative array indexed by the first
column in the select.
Convenience function to execute Queries directly.
Executes SQL.
Results will be returned as an associative array indexed by the first
column in the select.
Parameters
- $sql
- SQL query to execute
- $bindings
- a list of values to be bound to query parameters
Returns
array
|
public static
mixed
|
#
getInsertID( )
Returns the insert ID for databases that support/require this
functionality. Alias for R::getAdapter()->getInsertID().
Returns the insert ID for databases that support/require this
functionality. Alias for R::getAdapter()->getInsertID().
Returns
mixed
|
public static
array
|
#
dup( RedBeanPHP\OODBBean $bean, array $trail = array(), boolean $pid = FALSE, array $filters = array() )
Makes a copy of a bean. This method makes a deep copy
of the bean.The copy will have the following features.
- 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.
Makes a copy of a bean. This method makes a deep copy
of the bean.The copy will have the following features.
- 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.
Deprecated
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.
Parameters
- $bean
- bean to be copied
- $trail
- for internal usage, pass array()
- $pid
- for internal usage
- $filters
- $white white list filter with bean types to duplicate
Returns
array
|
public static
array
|
#
duplicate( RedBeanPHP\OODBBean $bean, array $filters = array() )
Makes a deep copy of a bean. This method makes a deep copy
of the bean.The copy will have the following:
Makes a deep copy of a bean. This method makes a deep copy
of the bean.The copy will have the following:
- 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.
Parameters
- $bean
- bean to be copied
- $filters
- $white white list filter with bean types to duplicate
Returns
array
|
public static
array
|
#
exportAll( array|RedBeanPHP\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.
What will be exported:
Exports a collection of beans. Handy for XML/JSON exports with a
Javascript framework like Dojo or ExtJS.
What will be exported:
- contents of the bean
- all own bean lists (recursively)
- all shared beans (not THEIR own lists)
Parameters
- $beans
- beans to be exported
- $parents
- whether you want parent beans to be exported
- $filters
- whitelist of types
Returns
array
|
public static
|
#
useExportCase( string $caseStyle = 'default' )
Selects case style for export.
This will determine the case style for the keys of exported beans (see exportAll).
The following options are accepted:
Selects case style for export.
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
Parameters
- $caseStyle
- case style identifier
Warning
RedBeanPHP transforms camelCase to snake_case using a slightly different
algorithm, it also converts isACL to is_acl (not is_a_c_l) and bookID to book_id.
Due to information loss this cannot be corrected. However if you might try
DolphinCase for IDs it takes into account the exception concerning IDs.
|
public static
array
|
#
convertToBeans( string $type, array $rows, $metamask = NULL )
Converts a series of rows to beans.
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.
Converts a series of rows to beans.
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'];
Parameters
- $type
- type of beans to produce
- $rows
- must contain an array of array
- $metamask
Returns
array
|
public static
array
|
#
convertToBean( string $type, array $row, $metamask = NULL )
Just like converToBeans, but for one bean.
Just like converToBeans, but for one bean.
Parameters
- $type
- type of beans to produce
- $row
- one row from the database
- $metamask
Returns
array
See
convertToBeans for more details.
|
public static
boolean
|
#
hasTag( RedBeanPHP\OODBBean $bean, array $tags, boolean $all = FALSE )
Part of RedBeanPHP Tagging API.
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.
Part of RedBeanPHP Tagging API.
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.
Parameters
- $bean
- bean to check for tags
- $tags
- list of tags
- $all
- whether they must all match or just some
Returns
boolean
|
public static
|
#
untag( RedBeanPHP\OODBBean $bean, array $tagList )
Part of RedBeanPHP Tagging API.
Removes all specified tags from the bean. The tags specified in
the second parameter will no longer be associated with the bean.
Part of RedBeanPHP Tagging API.
Removes all specified tags from the bean. The tags specified in
the second parameter will no longer be associated with the bean.
Parameters
- $bean
- tagged bean
- $tagList
- list of tags (names)
|
public static
string
|
#
tag( RedBeanPHP\OODBBean $bean, mixed $tagList = NULL )
Part of RedBeanPHP Tagging API.
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.
Part of RedBeanPHP Tagging API.
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.
Parameters
- $bean
- bean to tag
- $tagList
- tags to attach to the specified bean
Returns
string
|
public static
|
#
addTags( RedBeanPHP\OODBBean $bean, array $tagList )
Part of RedBeanPHP Tagging API.
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.
Part of RedBeanPHP Tagging API.
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.
Parameters
- $bean
- bean to tag
- $tagList
- list of tags to add to bean
|
public static
array
|
#
tagged( string $beanType, array $tagList, string $sql = '', array $bindings = array() )
Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with one of the tags given.
Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with one of the tags given.
Parameters
- $beanType
- type of bean you are looking for
- $tagList
- list of tags to match
- $sql
- additional SQL query snippet
- $bindings
- a list of values to bind to the query parameters
Returns
array
|
public static
array
|
#
taggedAll( string $beanType, array $tagList, string $sql = '', array $bindings = array() )
Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with ALL of the tags given.
Part of RedBeanPHP Tagging API.
Returns all beans that have been tagged with ALL of the tags given.
Parameters
- $beanType
- type of bean you are looking for
- $tagList
- list of tags to match
- $sql
- additional SQL query snippet
- $bindings
- a list of values to bind to the query parameters
Returns
array
|
public static
boolean
|
#
wipe( string $beanType )
Wipes all beans of type $beanType.
Wipes all beans of type $beanType.
Parameters
- $beanType
- type of bean you want to destroy entirely
Returns
boolean
|
public static
integer
|
#
count( string $type, string $addSQL = '', array $bindings = array() )
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.
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
- $type
- type of bean we are looking for
- $addSQL
- additional SQL snippet
- $bindings
- parameters to bind to SQL
Returns
integer
|
public static
RedBeanPHP\ToolBox
|
#
configureFacadeWithToolbox( RedBeanPHP\ToolBox $tb )
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.
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.
Parameters
- $tb
- toolbox to configure facade with
Returns
|
public static
boolean
|
#
begin( )
Facade Convience method for adapter transaction system.
Begins a transaction.
Facade Convience method for adapter transaction system.
Begins a transaction.
Returns
boolean
|
public static
boolean
|
#
commit( )
Facade Convience method for adapter transaction system.
Commits a transaction.
Facade Convience method for adapter transaction system.
Commits a transaction.
Returns
boolean
|
public static
boolean
|
#
rollback( )
Facade Convience method for adapter transaction system.
Rolls back a transaction.
Facade Convience method for adapter transaction system.
Rolls back a transaction.
Returns
boolean
|
public static
array
|
#
getColumns( string $table )
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!
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!
Parameters
- $table
- name of the table (not type) you want to get columns of
Returns
array
|
public static
string
|
#
genSlots( array $array, $template = NULL )
Generates question mark slots for an array of values.
Generates question mark slots for an array of values.
Parameters
- $array
- array to generate question mark slots for
- $template
Returns
string
|
public static
array
|
#
flat( array $array, $result = array() )
Flattens a multi dimensional bindings array for use with genSlots().
Flattens a multi dimensional bindings array for use with genSlots().
Parameters
- $array
- array to flatten
- $result
Returns
array
|
public static
|
#
nuke( )
Nukes the entire database.
This will remove all schema structures from the database.
Only works in fluid mode. Be careful with this method.
Nukes the entire database.
This will remove all schema structures from the database.
Only works in fluid mode. Be careful with this method.
Warning
dangerous method, will remove all tables, columns etc.
|
public static
array
|
#
storeAll( array $beans )
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.
A loop saver.
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.
A loop saver.
Parameters
- $beans
- list of beans to be stored
Returns
array
|
public static
|
#
trashAll( array $beans )
Short hand function to trash a set of beans at once.
For information please consult the R::trash() function.
A loop saver.
Short hand function to trash a set of beans at once.
For information please consult the R::trash() function.
A loop saver.
Parameters
- $beans
- list of beans to be trashed
|
public static
|
#
useWriterCache( boolean $yesNo )
Toggles Writer Cache.
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.
Toggles Writer Cache.
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.
Parameters
- $yesNo
- TRUE to enable cache, FALSE to disable cache
|
public static
array
|
#
dispenseLabels( string $type, array $labels )
A label is a bean with only an id, type and name property.
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.
A label is a bean with only an id, type and name property.
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.
Parameters
- $type
- type of beans you would like to have
- $labels
- list of labels, names for each bean
Returns
array
|
public static
array|RedBeanPHP\OODBBean
|
#
enum( string $enum )
Generates and returns an ENUM value. This is how RedBeanPHP handles ENUMs.
Either returns a (newly created) bean respresenting the desired ENUM
value or returns a list of all enums for the type.
Generates and returns an ENUM value. This is how RedBeanPHP handles ENUMs.
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' ) );
Parameters
- $enum
- either type or type-value
Returns
|
public static
array
|
#
gatherLabels( array $beans )
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).
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).
Parameters
- $beans
- list of beans to loop
Returns
array
|
public static
|
#
close( )
Closes the database connection.
Closes the database connection.
|
public static
string
|
#
isoDate( mixed $time = NULL )
Simple convenience function, returns ISO date formatted representation
of $time.
Simple convenience function, returns ISO date formatted representation
of $time.
Parameters
Returns
string
|
public static
string
|
#
isoDateTime( mixed $time = NULL )
Simple convenience function, returns ISO date time
formatted representation
of $time.
Simple convenience function, returns ISO date time
formatted representation
of $time.
Parameters
Returns
string
|
public static
|
#
setDatabaseAdapter( RedBeanPHP\Adapter $adapter )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Parameters
- $adapter
- Database Adapter for facade to use
|
public static
|
#
setWriter( RedBeanPHP\QueryWriter $writer )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Parameters
- $writer
- Query Writer instance for facade to use
|
public static
|
#
setRedBean( RedBeanPHP\OODB $redbean )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Parameters
- $redbean
- Object Database for facade to use
|
public static
RedBeanPHP\Adapter\DBAdapter
|
#
getDatabaseAdapter( )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Returns
|
public static
null|PDO
|
#
getPDO( )
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.
This is a convenience method, it will do the same as:
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.
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.
Returns
null|PDO
|
public static
RedBeanPHP\DuplicationManager
|
#
getDuplicationManager( )
Returns the current duplication manager instance.
Returns the current duplication manager instance.
Returns
|
public static
RedBeanPHP\QueryWriter
|
#
getWriter( )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Returns
|
public static
RedBeanPHP\OODB
|
#
getRedBean( )
Optional accessor for neat code.
Sets the database adapter you want to use.
Optional accessor for neat code.
Sets the database adapter you want to use.
Returns
|
public static
RedBeanPHP\ToolBox
|
#
getToolBox( )
Returns the toolbox currently used by the facade.
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.
Returns the toolbox currently used by the facade.
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.
Returns
|
public static
|
#
renameAssociation( string|array $from, string $to = NULL )
Facade method for AQueryWriter::renameAssociation()
Facade method for AQueryWriter::renameAssociation()
Parameters
|
public static
array
|
#
beansToArray( array $beans )
Little helper method for Resty Bean Can server and others.
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.
Little helper method for Resty Bean Can server and others.
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.
Parameters
Returns
array
|
public static
array
|
#
setErrorHandlingFUSE( integer $mode, callable|null $func = NULL )
Sets the error mode for FUSE.
What to do if a FUSE model method does not exist?
You can set the following options:
Sets the error mode for FUSE.
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.
Parameters
- $mode
- mode, determines how to handle errors
- $func
- custom handler (if applicable)
Returns
array
|
public static
array
|
#
dump( RedBeanPHP\OODBBean |array $data )
Simple but effective debug function.
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.
Simple but effective debug function.
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.
Parameters
- $data
- either a bean or an array of beans
Returns
array
|
public static
|
#
bindFunc( string $mode, string $field, string $function )
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.
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.
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.
Parameters
- $mode
- mode for function: i.e. read or write
- $field
- field (table.column) to bind function to
- $function
- SQL function to bind to specified column
|
public static
|
#
aliases( array $list )
Sets global aliases.
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.
Sets global aliases.
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' );
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.
Parameters
- $list
- list of global aliases to use
|
public static
RedBeanPHP\OODBBean
|
#
findOrCreate( string $type, array $like = array() )
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.
If multiple beans match the criteria only the first one
will be returned.
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.
If multiple beans match the criteria only the first one
will be returned.
Parameters
- $type
- type of bean to search for
- $like
- criteria set describing the bean to search for
Returns
|
public static
array
|
#
findLike( string $type, array $like = array(), string $sql = '' )
Tries to find beans matching the specified type and
criteria set.
Tries to find beans matching the specified type and
criteria set.
If the optional additional SQL snippet is a condition, it will
be glued to the rest of the query using the AND operator.
Parameters
- $type
- type of bean to search for
- $like
- optional criteria set describing the bean to search for
- $sql
- optional additional SQL for sorting
Returns
array
|
public static
|
#
startLogging( )
Starts logging queries.
Use this method to start logging SQL queries being
executed by the adapter.
Starts logging queries.
Use this method to start logging SQL queries being
executed by the adapter.
Note
you cannot use R::debug and R::startLogging
at the same time because R::debug is essentially a
special kind of logging.
|
public static
|
#
stopLogging( )
Stops logging, comfortable method to stop logging of queries.
Stops logging, comfortable method to stop logging of queries.
|
public static
array
|
#
getLogs( )
Returns the log entries written after the startLogging.
Returns the log entries written after the startLogging.
Returns
array
|
public static
integer
|
#
resetQueryCount( )
Resets the Query counter.
Resets the Query counter.
Returns
integer
|
public static
integer
|
#
getQueryCount( )
Returns the number of SQL queries processed.
Returns the number of SQL queries processed.
Returns
integer
|
public static
RedBeanPHP\Logger
|
#
getLogger( )
Returns the current logger instance being used by the
database object.
Returns the current logger instance being used by the
database object.
Returns
|
public static
|
#
setAutoResolve( boolean $automatic = TRUE )
Alias for setAutoResolve() method on OODBBean.
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.
Alias for setAutoResolve() method on OODBBean.
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.
Parameters
- $automatic
- TRUE to enable automatic resolving aliased parents
|
public static
|
#
ext( string $pluginName, callable $callable )
Dynamically extends the facade with a plugin.
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.
Dynamically extends the facade with a plugin.
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();
Parameters
- $pluginName
- name of the method to call the plugin
- $callable
- a PHP callable
|
public static
mixed
|
#
__callStatic( string $pluginName, array $params )
Call static for use with dynamic plugins. This magic method will
intercept static calls and route them to the specified plugin.
Call static for use with dynamic plugins. This magic method will
intercept static calls and route them to the specified plugin.
Parameters
- $pluginName
- name of the plugin
- $params
- list of arguments to pass to plugin method
Returns
mixed
|