Smart.Framework Logo

final class \SmartModExtLib\DbOrmRedbean\ORM
extends \RedBeanPHP\Facade
{ } ::

Class: \SmartModExtLib\DbOrmRedbean\ORM - provides a general ORM Database Adapter using ReadBean ORM as a module for Smart.Framework that supports the following drivers such as: SQlite, MySQLi, PostgreSQL and PDO(SQLite, MySQL, PostgreSQL).
If you wish to use an ORM in your projects instead of the direct ones supported directly by Smart.Framework this is a good solution.


class Methods

public static function setup ( string|\PDO|NULL $dsn = null, string|NULL $username = null, string|NULL $password = null, boolean|string[] $frozen = true, boolean|string[] $partialBeans = false, $pdo_options = [] ) {} :: TOOLBOX
reimplemented  over \RedBeanPHP\Facade
@return: {ToolBox}
@param: {string|\PDO|NULL} $dsn: Database connection string
@param: {string|NULL} $username: Username for database
@param: {string|NULL} $password: Password for database
@param: {boolean|string[]} $frozen: TRUE if you want to setup in frozen mode
@param: {boolean|string[]} $partialBeans: TRUE to enable partial bean updates
@param: {array} $options: Additional (PDO) options to pass
Kickstarts redbean for you. This method should be called before you start using
RedBeanPHP. 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).
Usage:
You can replace 'mysql:' with the name of the database you want to use.
Possible values are:
- pgsql (PostgreSQL database)
- sqlite (SQLite database)
- mysql (MySQL database)
- mysql (also for Maria database)
- sqlsrv (MS SQL Server - community supported experimental driver)
- CUBRID (CUBRID driver - basic support provided by Plugin)
Note that setup() will not immediately establish a connection to the database.
Instead, it will prepare the connection and connect 'lazily', i.e. the moment
a connection is really required, for instance when attempting to load
a bean.
Sample code: PHP
<?php R::setup( 'mysql:host=localhost;dbname=mydatabase', 'dba', 'dbapassword' ); // #end php code
public static function setAllowHybridMode ( boolean $hybrid ) {} :: BOOL
inherited from \RedBeanPHP\Facade
@return: {bool}
@param: {boolean} $hybrid
Sets allow hybrid mode flag. In Hybrid mode (default off),
store/storeAll take an extra argument to switch to fluid
mode in case of an exception. You can use this to speed up
fluid mode. This method returns the previous value of the
flag.
public static function getVersion ( ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {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.
public static function getDatabaseServerVersion ( ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {string}
Returns the version string from the database server.
public static function testConnection ( ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
Tests the database connection.
Returns TRUE if connection has been established and
FALSE otherwise. Suppresses any warnings that may
occur during the testing process and catches all
exceptions that might be thrown during the test.
public static function setNarrowFieldMode ( $mode ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $narrowField: TRUE = Narrow Field FALSE = Wide Field
Toggles 'Narrow Field Mode'.
In Narrow Field mode the queryRecord method will
narrow its selection field to
instead of
This is a better way of querying because it allows
more flexibility (for instance joins). However if you need
the wide selector for backward compatibility; use this method
to turn OFF Narrow Field Mode by passing FALSE.
Default is TRUE.
Sample code: PHP
<?php SELECT {table}.* SELECT * // #end php code
public static function setAllowFluidTransactions ( boolean $mode ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $mode: allow fluid transaction mode
Toggles fluid transactions. By default fluid transactions
are not active. Starting, committing or rolling back a transaction
through the facade in fluid mode will have no effect. If you wish
to replace this standard portable behavior with behavior depending
on how the used database platform handles fluid (DDL) transactions
set this flag to TRUE.
public static function useISNULLConditions ( $mode ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {boolean} $flag: TRUE or FALSE
Toggles support for IS-NULL-conditions.
If IS-NULL-conditions are enabled condition arrays
for functions including findLike() are treated so that
'field' => NULL will be interpreted as field IS NULL
instead of being skipped. Returns the previous
value of the flag.
public static function transaction ( callable $callback ) {} :: MIXED
inherited from \RedBeanPHP\Facade
@return: {mixed}
@param: {callable} $callback: Closure (or other callable) with the transaction logic
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:
Sample code: PHP
<?php $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); }); // #end php code
public static function addDatabase ( string $key, string|\PDO $dsn, string|NULL $user = null, string|NULL $pass = null, bool|string[] $frozen = false, bool|string[] $partialBeans = false, array $options = [], BeanHelper|NULL $beanHelper = null ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $key: ID for the database
@param: {string|\PDO} $dsn: DSN for the database
@param: {string|NULL} $user: user for connection
@param: {string|NULL} $pass: password for connection
@param: {bool|string[]} $frozen: whether this database is frozen or not
@param: {bool|string[]} $partialBeans: should we load partial beans?
@param: {array} $options: additional options for the query writer
@param: {BeanHelper|NULL} $beanHelper: Beanhelper to use (use this for DB specific model prefixes)
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:
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.
Sample code: PHP
<?php R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' ); R::selectDatabase( 'database-1' ); //to select database again // #end php code
public static function createToolbox ( string|\PDO $dsn, string $username = null, string $password = null, boolean|string[] $frozen = false, boolean|string[] $partialBeans = false, array $options = [] ) {} :: TOOLBOX
inherited from \RedBeanPHP\Facade
@return: {ToolBox}
@param: {string|\PDO} $dsn: Database connection string
@param: {string} $username: Username for database
@param: {string} $password: Password for database
@param: {boolean|string[]} $frozen: TRUE if you want to setup in frozen mode
@param: {boolean|string[]} $partialBeans: TRUE to enable partial bean updates
@param: {array} $options
Creates a toolbox. This method can be called if you want to use redbean non-static.
It has the same interface as R::setup(). The createToolbox() 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).
Usage:
You can replace 'mysql:' with the name of the database you want to use.
Possible values are:
- pgsql (PostgreSQL database)
- sqlite (SQLite database)
- mysql (MySQL database)
- mysql (also for Maria database)
- sqlsrv (MS SQL Server - community supported experimental driver)
- CUBRID (CUBRID driver - basic support provided by Plugin)
Note that createToolbox() will not immediately establish a connection to the database.
Instead, it will prepare the connection and connect 'lazily', i.e. the moment
a connection is really required, for instance when attempting to load a bean.
Sample code: PHP
<?php R::createToolbox( 'mysql:host=localhost;dbname=mydatabase', 'dba', 'dbapassword' ); // #end php code
public static function hasDatabase ( string $key ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {string} $key: the key/name of the database to check for
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 function selectDatabase ( string $key, bool $force = false ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {string} $key: Key of the database to select
@param: {bool} $force
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).
public static function debug ( boolean $tf = true, integer $mode = 0 ) {} :: RDEFAULT
inherited from \RedBeanPHP\Facade
@throws: {RedException}
@return: {RDefault}
@param: {boolean} $tf: debug mode (TRUE or FALSE)
@param: {integer} $mode: mode of operation
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: interspersed 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 function fancyDebug ( boolean $toggle = true ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $toggle: TRUE to activate debugger and select 'fancy' mode
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.
public static function inspect ( string|NULL $type = null ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {string|NULL} $type: Type of bean (i.e. table) you want to inspect, or NULL for a list of all tables
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.
public static function store ( OODBBean|SimpleModel $bean, boolean $unfreezeIfNeeded = false ) {} :: INTEGER|STRING
inherited from \RedBeanPHP\Facade
@return: {integer|string}
@param: {OODBBean|SimpleModel} $bean: bean to store
@param: {boolean} $unfreezeIfNeeded: retries in fluid mode in hybrid mode
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.
Usage:
In the example above, we create a new bean of type 'post'.
We then set the title of the bean to 'my post' and we
store the bean. The store() method will return the primary
key ID $id assigned by the database. We can now use this
ID to load the bean from the database again and delete it.
If the second parameter is set to TRUE and
Hybrid mode is allowed (default OFF for novice), then RedBeanPHP
will automatically temporarily switch to fluid mode to attempt to store the
bean in case of an SQLException.
Sample code: PHP
<?php $post = R::dispense('post'); $post->title = 'my post'; $id = R::store( $post ); $post = R::load( 'post', $id ); R::trash( $post ); // #end php code
public static function freeze ( boolean|string[] $tf = true ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean|string[]} $tf: mode of operation (TRUE means frozen)
Toggles fluid or frozen mode. In fluid mode the database
structure is adjusted to accommodate your objects. In frozen mode
this is not the case.
You can also pass an array containing a selection of frozen types.
Let's call this chilly mode, it's just like fluid mode except that
certain types (i.e. tables) aren't touched.
public static function loadMulti ( string|string[] $types, int $id ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string|string[]} $types: the set of types to load at once
@param: {int} $id: the common 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. In a typical 1-1 relation,
you have two records sharing the same primary key.
RedBeanPHP has only limited support for 1-1 relations.
In general it is recommended to use 1-N for this.
Usage:
Sample code: PHP
<?php list( $author, $bio ) = R::loadMulti( 'author, bio', $id ); // #end php code
public static function load ( string $type, integer $id, string|NULL $snippet = null ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {string} $type: type of bean you want to load
@param: {integer} $id: ID of the bean you want to load
@param: {string|NULL} $snippet: string to use after select (optional)
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.
Usage:
In the example above, we create a new bean of type 'post'.
We then set the title of the bean to 'my post' and we
store the bean. The store() method will return the primary
key ID $id assigned by the database. We can now use this
ID to load the bean from the database again and delete it.
Sample code: PHP
<?php $post = R::dispense('post'); $post->title = 'my post'; $id = R::store( $post ); $post = R::load( 'post', $id ); R::trash( $post ); // #end php code
public static function loadForUpdate ( string $type, integer $id ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {string} $type: type of bean you want to load
@param: {integer} $id: ID of the bean you want to load
Same as load, but selects the bean for update, thus locking the bean.
This equals an SQL query like 'SELECT ... FROM ... FOR UPDATE'.
Use this method if you want to load a bean you intend to UPDATE.
This method should be used to 'LOCK a bean'.
Usage:
Sample code: PHP
<?php $bean = R::loadForUpdate( 'bean', $id ); ...update... R::store( $bean ); // #end php code
public static function findForUpdate ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: array of values to be bound to parameters in query
Same as find(), but selects the beans for update, thus locking the beans.
This equals an SQL query like 'SELECT ... FROM ... FOR UPDATE'.
Use this method if you want to load a bean you intend to UPDATE.
This method should be used to 'LOCK a bean'.
Usage:
Sample code: PHP
<?php $bean = R::findForUpdate( 'bean', ' title LIKE ? ', array('title') ); ...update... R::store( $bean ); // #end php code
public static function findOneForUpdate ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN|NULL
inherited from \RedBeanPHP\Facade
@return: {OODBBean|NULL}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: array of values to be bound to parameters in query
Convenience method.
Same as findForUpdate but returns just one bean and adds LIMIT-clause.
public static function trash ( string|OODBBean|SimpleModel $beanOrType, integer $id = null ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
@param: {string|OODBBean|SimpleModel} $beanOrType: bean you want to remove from database
@param: {integer} $id: ID if the bean to trash (optional, type-id variant only)
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.
Usage:
In the example above, we create a new bean of type 'post'.
We then set the title of the bean to 'my post' and we
store the bean. The store() method will return the primary
key ID $id assigned by the database. We can now use this
ID to load the bean from the database again and delete it.
Sample code: PHP
<?php $post = R::dispense('post'); $post->title = 'my post'; $id = R::store( $post ); $post = R::load( 'post', $id ); R::trash( $post ); // #end php code
public static function dispense ( string|OODBBean[] $typeOrBeanArray, integer $num = 1, boolean $alwaysReturnArray = false ) {} :: OODBBEAN|OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean|OODBBean[]}
@param: {string|OODBBean[]} $typeOrBeanArray: type or bean array to import
@param: {integer} $num: number of beans to dispense
@param: {boolean} $alwaysReturnArray: if TRUE always returns the result as an array
Dispenses a new RedBean OODB Bean for use with
the rest of the methods. RedBeanPHP thinks in beans, the bean is the
primary way to interact with RedBeanPHP and the database managed by
RedBeanPHP. To load, store and delete data from the database using RedBeanPHP
you exchange these RedBeanPHP OODB Beans. The only exception to this rule
are the raw query methods like R::getCell() or R::exec() and so on.
The dispense method is the 'preferred way' to create a new bean.
Usage:
This method can also be used to create an entire bean graph at once.
Given an array with keys specifying the property names of the beans
and a special _type key to indicate the type of bean, one can
make the Dispense Helper generate an entire hierarchy of beans, including
lists. To make dispense() generate a list, simply add a key like:
ownXList or sharedXList where X is the type of beans it contains and
a set its value to an array filled with arrays representing the beans.
Note that, although the type may have been hinted at in the list name,
you still have to specify a _type key for every bean array in the list.
Note that, if you specify an array to generate a bean graph, the number
parameter will be ignored.
Usage:
Sample code: PHP
<?php $book = R::dispense( 'book' ); $book->title = 'My Book'; R::store( $book ); $book = R::dispense( [ '_type' => 'book', 'title' => 'Gifted Programmers', 'author' => [ '_type' => 'author', 'name' => 'Xavier' ], 'ownPageList' => [ ['_type'=>'page', 'text' => '...'] ] ] ); // #end php code
public static function dispenseAll ( string $order, boolean $onlyArrays = false ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {string} $order: a description of the desired dispense order using the syntax above
@param: {boolean} $onlyArrays: return only arrays even if amount < 2
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:
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:
This returns an array with a book bean and then another array
containing 100 page beans.
Sample code: PHP
<?php list( $book, $page, $text ) = R::dispenseAll( 'book,page,text' ); list($book, $pages) = R::dispenseAll('book,page*100'); // #end php code
public static function findOrDispense ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of bean you are looking for
@param: {string|NULL} $sql: SQL code for finding the bean
@param: {array} $bindings: parameters to bind to SQL
Convenience method. Tries to find beans of a certain type,
if no beans are found, it dispenses a bean of that type.
Note that this function always returns an array.
public static function findOneOrDispense ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {string} $type: type of bean you are looking for
@param: {string|NULL} $sql: SQL code for finding the bean
@param: {array} $bindings: parameters to bind to SQL
Same as findOrDispense but returns just one element.
public static function find ( string $type, string|NULL $sql = null, array $bindings = [], string|NULL $snippet = null ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: array of values to be bound to parameters in query
@param: {string|NULL} $snippet: SQL snippet to include in query (for example: FOR UPDATE)
Finds beans using a type and optional SQL statement.
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).
Your SQL does not have to start with a WHERE-clause condition.
public static function findAll ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: array of values to be bound to parameters in query
Alias for find().
public static function findAndExport ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {string} $type: type the type of bean you are looking for
@param: {string|NULL} $sql: sql SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: values array of values to be bound to parameters in query
Like find() but also exports the beans as an array.
This method will perform a find-operation. For every bean
in the result collection this method will call the export() method.
This method returns an array containing the array representations
of every bean in the result set.
public static function findOne ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN|NULL
inherited from \RedBeanPHP\Facade
@return: {OODBBean|NULL}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: array of values to be bound to parameters in query
Like R::find() but returns the first bean only.
public static function findLast ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN|NULL
inherited from \RedBeanPHP\Facade
@return: {OODBBean|NULL}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: values array of values to be bound to parameters in query
Like find() but returns the last bean of the result array.
Opposite of Finder::findLast().
If no beans are found, this method will return NULL.
Please do not use this function, it is horribly ineffective.
Instead use a reversed ORDER BY clause and a LIMIT 1 with R::findOne().
This function should never be used and only remains for
the sake of backward compatibility.
public static function findCollection ( string $type, string|NULL $sql = null, array $bindings = [] ) {} :: BEANCOLLECTION
inherited from \RedBeanPHP\Facade
@return: {BeanCollection}
@param: {string} $type: the type of bean you are looking for
@param: {string|NULL} $sql: SQL query to find the desired bean, starting right after WHERE clause
@param: {array} $bindings: values array of values to be bound to parameters in query
Finds a BeanCollection using the repository.
A bean collection can be used to retrieve one bean at a time using
cursors - this is useful for processing large datasets. A bean collection
will not load all beans into memory all at once, just one at a time.
public static function findMulti ( string|string[] $types, string|array[]|NULL $sql, array $bindings = [], array[] $remappings = [] ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {string|string[]} $types: a list of types (either array or comma separated string)
@param: {string|array[]|NULL} $sql: an SQL query or an array of prefetched records
@param: {array} $bindings: optional, bindings for SQL query
@param: {array[]} $remappings: optional, an array of remapping arrays
Returns a hashmap with bean arrays keyed by type using an SQL
query as its resource. Given an SQL query like 'SELECT movie.*, review.* FROM movie... JOIN review'
this method will return movie and review beans.
Example:
After this operation, $stuff will contain an entry 'movie' containing all
movies and an entry named 'review' containing all reviews (all beans).
You can also pass bindings.
If you want to re-map your beans, so you can use $movie->ownReviewList without
having RedBeanPHP executing an SQL query you can use the fourth parameter to
define a selection of remapping closures.
The remapping argument (optional) should contain an array of arrays.
Each array in the remapping array should contain the following entries:
Using this mechanism you can build your own 'preloader' with tiny function
snippets (and those can be re-used and shared online of course).
Example:
this function will pre-process the query to get all the data required to find the beans.
selector starts with a SPACE. ' book.*' NOT ',book.*'. This is because
it's actually an SQL-like template SLOT, not real SQL.
Sample code: PHP
<?php $stuff = $finder->findMulti('movie,review', ' SELECT movie.*, review.* FROM movie LEFT JOIN review ON review.movie_id = movie.id'); array( 'a' => TYPE A 'b' => TYPE B 'matcher' => MATCHING FUNCTION ACCEPTING A, B and ALL BEANS 'do' => OPERATION FUNCTION ACCEPTING A, B, ALL BEANS, ALL REMAPPINGS ) array( 'a' => 'movie' //define A as movie 'b' => 'review' //define B as review 'matcher' => function( $a, $b ) { return ( $b->movie_id == $a->id ); //Perform action if review.movie_id equals movie.id } 'do' => function( $a, $b ) { $a->noLoad()->ownReviewList[] = $b; //Add the review to the movie $a->clearHistory(); //optional, act 'as if these beans have been loaded through ownReviewList'. } ) // #end php code
public static function batch ( string $type, int[] $ids ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of beans
@param: {int[]} $ids: ids to load
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.
public static function loadAll ( string $type, int[] $ids ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of beans
@param: {int[]} $ids: ids to load
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 function exec ( string $sql, array $bindings = [] ) {} :: INTEGER
inherited from \RedBeanPHP\Facade
@return: {integer}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to execute Queries directly.
Executes SQL.
public static function getAll ( string $sql, array $bindings = [] ) {} :: STRING[][]
inherited from \RedBeanPHP\Facade
@return: {string[][]}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns all rows
and all columns.
public static function getCell ( string $sql, array $bindings = [] ) {} :: STRING|NULL
inherited from \RedBeanPHP\Facade
@return: {string|NULL}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns a single cell.
public static function getCursor ( string $sql, array $bindings = [] ) {} :: CURSOR
inherited from \RedBeanPHP\Facade
@return: {Cursor}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns a PDOCursor instance.
public static function getRow ( string $sql, array $bindings = [] ) {} :: ARRAY|NULL
inherited from \RedBeanPHP\Facade
@return: {array|NULL}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns a single row.
public static function getCol ( string $sql, array $bindings = [] ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns a single column.
public static function getAssoc ( string $sql, array $bindings = [] ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
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.
public static function getAssocRow ( string $sql, array $bindings = [] ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {string} $sql: SQL query to execute
@param: {array} $bindings: a list of values to be bound to query parameters
Convenience function to fire an SQL query using the RedBeanPHP
database adapter. This method allows you to directly query the
database without having to obtain an database adapter instance first.
Executes the specified SQL query together with the specified
parameter bindings and returns an associative array.
Results will be returned as an associative array indexed by the first
column in the select.
public static function getInsertID ( ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
Returns the insert ID for databases that support/require this
functionality. Alias for R::getAdapter()->getInsertID().
public static function dup ( OODBBean $bean, OODBBean[] $trail = [], boolean $pid = false, array $filters = [] ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {OODBBean} $bean: bean to be copied
@param: {OODBBean[]} $trail: for internal usage, pass array()
@param: {boolean} $pid: for internal usage
@param: {array} $filters: white list filter with bean types to duplicate
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.
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 function duplicate ( OODBBean $bean, array $filters = [] ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {OODBBean} $bean: bean to be copied
@param: {array} $filters: white list filter with bean types to duplicate
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.
public static function exportAll ( OODBBean|OODBBean[] $beans, boolean $parents = false, array $filters = [], boolean $meta = false ) {} :: ARRAY[]
inherited from \RedBeanPHP\Facade
@return: {array[]}
@param: {OODBBean|OODBBean[]} $beans: beans to be exported
@param: {boolean} $parents: whether you want parent beans to be exported
@param: {array} $filters: whitelist of types
@param: {boolean} $meta: export meta data as well
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)
public static function useExportCase ( string $caseStyle = "default" ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $caseStyle: case style identifier
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
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 function convertToBeans ( string $type, string[][] $rows, string|array|NULL $metamask = null ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of beans to produce
@param: {string[][]} $rows: must contain an array of array
@param: {string|array|NULL} $metamask: meta mask to apply (optional)
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:
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).
New in 4.3.2: meta mask. The meta mask is a special mask to send
data from raw result rows to the meta store of the bean. This is
useful for bundling additional information with custom queries.
Values of every column who's name starts with $mask will be
transferred to the meta section of the bean under key 'data.bundle'.
Sample code: PHP
<?php $rows = R::getAll( 'SELECT * FROM ...' ) $beans = R::convertToBeans( $rows ); $rows = R::getAll( 'SELECT FROM... COUNT(*) AS extra_count ...' ); $beans = R::convertToBeans( $rows, 'extra_' ); $bean = reset( $beans ); $data = $bean->getMeta( 'data.bundle' ); $extra_count = $data['extra_count']; // #end php code
public static function convertToBean ( string $type, string[] $row, string|array|NULL $metamask = null ) {} :: OODBBEAN|NULL
inherited from \RedBeanPHP\Facade
@return: {OODBBean|NULL}
@param: {string} $type: type of bean to produce
@param: {string[]} $row: one row from the database
@param: {string|array|NULL} $metamask: metamask (see convertToBeans)
Just like convertToBeans, but for one bean.
public static function findFromSQL ( string $type, string $sql, array $bindings = [], string|array $metamask = "extra_", boolean $autoExtract = false ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {string} $type: Type of bean to produce
@param: {string} $sql: SQL query snippet to use
@param: {array} $bindings: bindings for query (optional)
@param: {string|array} $metamask: meta mask (optional, defaults to 'extra_')
@param: {boolean} $autoExtract: TRUE to return meta mask values as first item of array
Convenience function to 'find' beans from an SQL query.
Used mostly to obtain a series of beans as well as
pagination data (to paginate results) and optionally
other data as well (that should not be considered part of
a bean).
Example:
$books = R::findFromSQL('book',"
SELECT *, count(*) OVER() AS total
FROM book
WHERE {$filter}
OFFSET {$from} LIMIT {$to} ", ['total']);
This is the same as doing (example uses PostgreSQL dialect):
$rows = R::getAll("
SELECT *, count(*) OVER() AS total
FROM book
WHERE {$filter}
OFFSET {$from} LIMIT {$to}
", $params);
$books = R::convertToBeans('book', $rows, ['total']);
The additional data can be obtained using:
$book->info('total');
For further details see R::convertToBeans().
If you set $autoExtract to TRUE and meta mask is an array,
an array will be returned containing two nested arrays, the
first of those nested arrays will contain the meta values
you requested, the second array will contain the beans.
public static function hasTag ( OODBBean $bean, string|string[] $tags, boolean $all = false ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {OODBBean} $bean: bean to check for tags
@param: {string|string[]} $tags: list of tags
@param: {boolean} $all: whether they must all match or just some
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.
Tag list can be either an array with tag names or a comma separated list
of tag names.
Usage:
The example above returns TRUE if the $blog bean has been tagged
as BOTH horror and movie. If the post has only been tagged as 'movie'
or 'horror' this operation will return FALSE because the third parameter
has been set to TRUE.
Sample code: PHP
<?php R::hasTag( $blog, 'horror,movie', TRUE ); // #end php code
public static function untag ( OODBBean $bean, string|string[] $tagList ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {OODBBean} $bean: tagged bean
@param: {string|string[]} $tagList: list of tags (names)
Removes all specified tags from the bean. The tags specified in
the second parameter will no longer be associated with the bean.
Tag list can be either an array with tag names or a comma separated list
of tag names.
Usage:
In the example above, the $blog bean will no longer
be associated with the tags 'smart' and 'interesting'.
Sample code: PHP
<?php R::untag( $blog, 'smart,interesting' ); // #end php code
public static function tag ( RedBeanPHP\OODBBean $bean, string[]|NULL $tagList = null ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {OODBBean} $bean: bean to tag
@param: {string[]|NULL} $tagList: tags to attach to the specified bean
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.
Usage:
The first line in the example above will tag the $meal
as 'TexMex' and 'Mexican Cuisine'. The second line will
retrieve all tags attached to the meal object.
Sample code: PHP
<?php R::tag( $meal, "TexMex,Mexican" ); $tags = R::tag( $meal ); // #end php code
public static function addTags ( RedBeanPHP\OODBBean $bean, string|string[] $tagList ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {OODBBean} $bean: bean to tag
@param: {string|string[]} $tagList: list of tags to add to bean
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.
Usage:
The example adds the tag 'halloween' to the $blog
bean.
Sample code: PHP
<?php R::addTags( $blog, ["halloween"] ); // #end php code
public static function tagged ( string $beanType, string|string[] $tagList, string $sql = "", array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $beanType: type of bean you are looking for
@param: {string|string[]} $tagList: list of tags to match
@param: {string} $sql: additional SQL (use only for pagination)
@param: {array} $bindings: bindings
Returns all beans that have been tagged with one or more
of the specified tags.
Tag list can be either an array with tag names or a comma separated list
of tag names.
Usage:
The example uses R::tagged() to find all movies that have been
tagged as 'horror' or 'gothic', order them by title and limit
the number of movies to be returned to 10.
Sample code: PHP
<?php $watchList = R::tagged( 'movie', 'horror,gothic', ' ORDER BY movie.title DESC LIMIT ?', [ 10 ] ); // #end php code
public static function taggedAll ( string $beanType, string|string[] $tagList, string $sql = "", array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $beanType: type of bean you are looking for
@param: {string|string[]} $tagList: list of tags to match
@param: {string} $sql: additional sql snippet
@param: {array} $bindings: bindings
Returns all beans that have been tagged with ALL of the tags given.
This method works the same as R::tagged() except that this method only returns
beans that have been tagged with all the specified labels.
Tag list can be either an array with tag names or a comma separated list
of tag names.
Usage:
The example above returns at most 4 movies (due to the LIMIT clause in the SQL
Query Snippet) that have been tagged as BOTH 'short' AND 'gothic'.
Sample code: PHP
<?php $watchList = R::taggedAll( 'movie', [ 'gothic', 'short' ], ' ORDER BY movie.id DESC LIMIT ? ', [ 4 ] ); // #end php code
public static function countTaggedAll ( string $beanType, string|string[] $tagList, string $sql = "", array $bindings = [] ) {} :: INTEGER
inherited from \RedBeanPHP\Facade
@return: {integer}
@param: {string} $beanType: type of bean you are looking for
@param: {string|string[]} $tagList: list of tags to match
@param: {string} $sql: additional sql snippet
@param: {array} $bindings: bindings
Same as taggedAll() but counts beans only (does not return beans).
public static function countTagged ( string $beanType, string|string[] $tagList, string $sql = "", array $bindings = [] ) {} :: INTEGER
inherited from \RedBeanPHP\Facade
@return: {integer}
@param: {string} $beanType: type of bean you are looking for
@param: {string|string[]} $tagList: list of tags to match
@param: {string} $sql: additional sql snippet
@param: {array} $bindings: bindings
Same as tagged() but counts beans only (does not return beans).
public static function wipe ( string $beanType ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {string} $beanType: type of bean you want to destroy entirely
Wipes all beans of type $beanType.
public static function count ( string $type, string $addSQL = "", array $bindings = [] ) {} :: INTEGER
inherited from \RedBeanPHP\Facade
@return: {integer}
@param: {string} $type: type of bean we are looking for
@param: {string} $addSQL: additional SQL snippet
@param: {array} $bindings: parameters to bind to SQL
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.
public static function configureFacadeWithToolbox ( RedBeanPHP\ToolBox $tb ) {} :: TOOLBOX
inherited from \RedBeanPHP\Facade
@return: {ToolBox}
@param: {ToolBox} $tb: toolbox to configure facade with
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 function begin ( ) {} :: BOOL
inherited from \RedBeanPHP\Facade
@return: {bool}
Facade Convenience method for adapter transaction system.
Begins a transaction.
Usage:
The example above illustrates how transactions in RedBeanPHP are used.
In this example 2 beans are stored or nothing is stored at all.
It's not possible for this piece of code to store only half of the beans.
If an exception occurs, the transaction gets rolled back and the database
will be left 'untouched'.
In fluid mode transactions will be ignored and all queries will
be executed as-is because database schema changes will automatically
trigger the transaction system to commit everything in some database
systems. If you use a database that can handle DDL changes you might wish
to use setAllowFluidTransactions(TRUE). If you do this, the behavior of
this function in fluid mode will depend on the database platform used.
Sample code: PHP
<?php R::begin(); try { $bean1 = R::dispense( 'bean' ); R::store( $bean1 ); $bean2 = R::dispense( 'bean' ); R::store( $bean2 ); R::commit(); } catch( \Exception $e ) { R::rollback(); } // #end php code
public static function commit ( ) {} :: BOOL
inherited from \RedBeanPHP\Facade
@return: {bool}
Facade Convenience method for adapter transaction system.
Commits a transaction.
Usage:
The example above illustrates how transactions in RedBeanPHP are used.
In this example 2 beans are stored or nothing is stored at all.
It's not possible for this piece of code to store only half of the beans.
If an exception occurs, the transaction gets rolled back and the database
will be left 'untouched'.
In fluid mode transactions will be ignored and all queries will
be executed as-is because database schema changes will automatically
trigger the transaction system to commit everything in some database
systems. If you use a database that can handle DDL changes you might wish
to use setAllowFluidTransactions(TRUE). If you do this, the behavior of
this function in fluid mode will depend on the database platform used.
Sample code: PHP
<?php R::begin(); try { $bean1 = R::dispense( 'bean' ); R::store( $bean1 ); $bean2 = R::dispense( 'bean' ); R::store( $bean2 ); R::commit(); } catch( \Exception $e ) { R::rollback(); } // #end php code
public static function rollback ( ) {} :: BOOL
inherited from \RedBeanPHP\Facade
@return: {bool}
Facade Convenience method for adapter transaction system.
Rolls back a transaction.
Usage:
The example above illustrates how transactions in RedBeanPHP are used.
In this example 2 beans are stored or nothing is stored at all.
It's not possible for this piece of code to store only half of the beans.
If an exception occurs, the transaction gets rolled back and the database
will be left 'untouched'.
In fluid mode transactions will be ignored and all queries will
be executed as-is because database schema changes will automatically
trigger the transaction system to commit everything in some database
systems. If you use a database that can handle DDL changes you might wish
to use setAllowFluidTransactions(TRUE). If you do this, the behavior of
this function in fluid mode will depend on the database platform used.
Sample code: PHP
<?php R::begin(); try { $bean1 = R::dispense( 'bean' ); R::store( $bean1 ); $bean2 = R::dispense( 'bean' ); R::store( $bean2 ); R::commit(); } catch( \Exception $e ) { R::rollback(); } // #end php code
public static function getColumns ( string $table ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {string} $table: name of the table (not type) you want to get columns of
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 function genSlots ( array $array, string|NULL $template = null ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {string}
@param: {array} $array: array to generate question mark slots for
@param: {string|NULL} $template: template to use
Generates question mark slots for an array of values.
Given an array and an optional template string this method
will produce string containing parameter slots for use in
an SQL query string.
Usage:
The statement in the example will produce the string:
'?,?'.
Another example, using a template string:
The statement in the example will produce the string:
' IN( ?,? ) '.
Sample code: PHP
<?php R::genSlots( array( 'a', 'b' ) ); R::genSlots( array('a', 'b'), ' IN( %s ) ' ); // #end php code
public static function loadJoined ( OODBBean[] $beans, string $type, string $sqlTemplate = "SELECT %s.* FROM %s WHERE id IN (%s)" ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {OODBBean[]} $beans: a list of OODBBeans
@param: {string} $type: a type string
@param: {string} $sqlTemplate: an SQL template string for the SELECT-query
Convenience method to quickly attach parent beans.
Although usually this can also be done with findMulti(), that
approach can be a bit verbose sometimes. This convenience method
uses a default yet overridable SQL snippet to perform the
operation, leveraging the power of findMulti().
Usage:
This is an alternative for:
Sample code: PHP
<?php $users = R::find('user'); $users = R::loadJoined( $users, 'country' ); $all = R::findMulti('country', R::genSlots( $users, 'SELECT country.* FROM country WHERE id IN ( %s )' ), array_column( $users, 'country_id' ), [Finder::onmap('country', $gebruikers)] ); // #end php code
public static function flat ( array $array, array $result = [] ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {array} $array: array to flatten
@param: {array} $result: result array parameter (for recursion)
Flattens a multi dimensional bindings array for use with genSlots().
Usage:
produces an array like: [ 'a', 'b', 'c' ]
Sample code: PHP
<?php R::flat( array( 'a', array( 'b' ), 'c' ) ); // #end php code
public static function nuke ( ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
Nukes the entire database.
This will remove all schema structures from the database.
Only works in fluid mode. Be careful with this method.
public static function wipeAll ( boolean $alsoDeleteTables = false ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $alsoDeleteTables: TRUE to clear entire database.
Truncates or drops all database tables/views.
Empties the database. If the deleteTables flag is set to TRUE
this function will also remove the database structures.
The latter only works in fluid mode.
public static function storeAll ( OODBBean[] $beans, boolean $unfreezeIfNeeded = false ) {} :: INT[]
inherited from \RedBeanPHP\Facade
@return: {int[]} ids
@param: {OODBBean[]} $beans: list of beans to be stored
@param: {boolean} $unfreezeIfNeeded: retries in fluid mode in hybrid mode
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.
If the second parameter is set to TRUE and
Hybrid mode is allowed (default OFF for novice), then RedBeanPHP
will automatically temporarily switch to fluid mode to attempt to store the
bean in case of an SQLException.
public static function trashAll ( OODBBean[] $beans ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
@param: {OODBBean[]} $beans: list of beans to be trashed
Short hand function to trash a set of beans at once.
For information please consult the R::trash() function.
A loop saver.
public static function trashBatch ( string $type, int[] $ids ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $type: the bean type you wish to trash
@param: {int[]} $ids: list of bean IDs
Short hand function to trash a series of beans using
only IDs. This function combines trashAll and batch loading
in one call. Note that while this function accepts just
bean IDs, the beans will still be loaded first. This is because
the function still respects all the FUSE hooks that may have been
associated with the domain logic associated with these beans.
If you really want to delete just records from the database use
a simple DELETE-FROM SQL query instead.
public static function hunt ( string $type, string|NULL $sqlSnippet = null, array $bindings = [] ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
@param: {string} $type: bean type to look for in database
@param: {string|NULL} $sqlSnippet: an SQL query snippet
@param: {array} $bindings: SQL parameter bindings
Short hand function to find and trash beans.
This function combines trashAll and find.
Given a bean type, a query snippet and optionally some parameter
bindings, this function will search for the beans described in the
query and its parameters and then feed them to the trashAll function
to be trashed.
Note that while this function accepts just
a bean type and query snippet, the beans will still be loaded first. This is because
the function still respects all the FUSE hooks that may have been
associated with the domain logic associated with these beans.
If you really want to delete just records from the database use
a simple DELETE-FROM SQL query instead.
Returns the number of beans deleted.
public static function useWriterCache ( boolean $yesNo ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $yesNo: TRUE to enable cache, FALSE to disable cache
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.
public static function dispenseLabels ( string $type, string[] $labels ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of beans you would like to have
@param: {string[]} $labels: list of labels, names for each 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.
public static function enum ( string $enum ) {} :: OODBBEAN|OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean|OODBBean[]}
@param: {string} $enum: either type or type-value
Generates and returns an ENUM value. This is how RedBeanPHP handles ENUMs.
Either returns a (newly created) bean representing the desired ENUM
value or returns a list of all enums for the type.
To obtain (and add if necessary) an ENUM value:
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:
To get a list of all flavour names:
Sample code: PHP
<?php $tea->flavour = R::enum( 'flavour:apple' ); R::enum('flavour'); R::gatherLabels( R::enum( 'flavour' ) ); // #end php code
public static function gatherLabels ( OODBBean[] $beans ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
@param: {OODBBean[]} $beans: list of beans to loop
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 function close ( ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
Closes the database connection.
While database connections are closed automatically at the end of the PHP script,
closing database connections is generally recommended to improve performance.
Closing a database connection will immediately return the resources to PHP.
Usage:
Sample code: PHP
<?php R::setup( ... ); ... do stuff ... R::close(); // #end php code
public static function isoDate ( int|NULL $time = null ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {string}
@param: {int|NULL} $time: UNIX timestamp
Simple convenience function, returns ISO date formatted representation
of $time.
public static function isoDateTime ( int|NULL $time = null ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {string}
@param: {int|NULL} $time: UNIX timestamp
Simple convenience function, returns ISO date time
formatted representation
of $time.
public static function setDatabaseAdapter ( RedBeanPHP\Adapter $adapter ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {Adapter} $adapter: Database Adapter for facade to use
Sets the database adapter you want to use.
The database adapter manages the connection to the database
and abstracts away database driver specific interfaces.
public static function setWriter ( RedBeanPHP\QueryWriter $writer ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {QueryWriter} $writer: Query Writer instance for facade to use
Sets the Query Writer you want to use.
The Query Writer writes and executes database queries using
the database adapter. It turns RedBeanPHP 'commands' into
database 'statements'.
public static function setRedBean ( RedBeanPHP\OODB $redbean ) {} :: 
inherited from \RedBeanPHP\Facade
@param: {OODB} $redbean: Object Database for facade to use
Sets the OODB you want to use.
The RedBeanPHP Object oriented database is the main RedBeanPHP
interface that allows you to store and retrieve RedBeanPHP
objects (i.e. beans).
public static function getDatabaseAdapter ( ) {} :: ADAPTER
inherited from \RedBeanPHP\Facade
@return: {Adapter}
Optional accessor for neat code.
Sets the database adapter you want to use.
public static function getPDO ( ) {} :: NULL|\PDO
inherited from \RedBeanPHP\Facade
@return: {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.
This is a convenience method, it will do the same as:
If the PDO object could not be found, for whatever reason, this method
will return NULL instead.
Sample code: PHP
<?php R::getDatabaseAdapter()->getDatabase()->getPDO(); // #end php code
public static function getDuplicationManager ( ) {} :: DUPLICATIONMANAGER
inherited from \RedBeanPHP\Facade
@return: {DuplicationManager}
Returns the current duplication manager instance.
public static function getWriter ( ) {} :: QUERYWRITER
inherited from \RedBeanPHP\Facade
@return: {QueryWriter}
Optional accessor for neat code.
Sets the database adapter you want to use.
public static function getRedBean ( ) {} :: OODB
inherited from \RedBeanPHP\Facade
@return: {OODB}
Optional accessor for neat code.
Sets the database adapter you want to use.
public static function getToolBox ( ) {} :: TOOLBOX
inherited from \RedBeanPHP\Facade
@return: {ToolBox}
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.
public static function getExtractedToolbox ( ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
Mostly for internal use, but might be handy
for some users.
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 function renameAssociation ( string|string[] $from, string $to = null ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string|string[]} $from
@param: {string} $to
Facade method for AQueryWriter::renameAssociation()
public static function beansToArray ( OODBBean[] $beans ) {} :: ARRAY[]
inherited from \RedBeanPHP\Facade
@return: {array[]}
@param: {OODBBean[]} $beans: 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.
public static function setErrorHandlingFUSE ( integer $mode, callable|NULL $func = null ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {integer} $mode: mode, determines how to handle errors
@param: {callable|NULL} $func: custom handler (if applicable)
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
This method returns the old mode and handler as an array.
Sample code: PHP
<?php Custom handler method signature: handler( array ( 'message' => string 'bean' => OODBBean 'method' => string ) ) // #end php code
public static function dump ( OODBBean|OODBBean[] $data ) {} :: STRING|STRING[]
inherited from \RedBeanPHP\Facade
@return: {string|string[]}
@param: {OODBBean|OODBBean[]} $data: either a bean or an array of beans
Dumps bean data to array.
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.
Usage:
The example shows how to echo the result of a simple
dump. This will print the string representation of the
specified bean to the screen, limiting the output per bean
to 35 characters to improve readability. Nested beans will
also be dumped.
Sample code: PHP
<?php echo R::dump( $bean ); // #end php code
public static function bindFunc ( string $mode, string $field, string $function, boolean $isTemplate = false ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $mode: mode for function: i.e. read or write
@param: {string} $field: field (table.column) to bind function to
@param: {string} $function: SQL function to bind to specified column
@param: {boolean} $isTemplate: TRUE if $function is an SQL string, FALSE for just a function name
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:
Passing NULL as the function will reset (clear) the function
for this column/mode.
Sample code: PHP
<?php R::bindFunc( 'read', 'location.point', 'asText' ); R::bindFunc( 'write', 'location.point', 'GeomFromText' ); // #end php code
public static function aliases ( string[] $list ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string[]} $list: list of global aliases to use
Sets global aliases.
Registers a batch of aliases in one go. This works the same as
fetchAs 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-existent) cover bean.
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.
Sample code: PHP
<?php 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 // #end php code
public static function findOrCreate ( string $type, array $like = [], $sql = "", $hasBeenCreated = false ) {} :: OODBBEAN
inherited from \RedBeanPHP\Facade
@return: {OODBBean}
@param: {string} $type: type of bean to search for
@param: {array} $like: criteria set describing the bean to search for
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.
public static function findLike ( string $type, array $like = [], string $sql = "", array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {string} $type: type of bean to search for
@param: {array} $like: optional criteria set describing the bean to search for
@param: {string} $sql: optional additional SQL for sorting
@param: {array} $bindings: bindings
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.
public static function startLogging ( ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
Starts logging queries.
Use this method to start logging SQL queries being
executed by the adapter. Logging queries will not
print them on the screen. Use R::getLogs() to
retrieve the logs.
Usage:
In the example above we start a logging session during
which we store an empty bean of type book. To inspect the
logs we invoke R::getLogs() after stopping the logging.
at the same time because R::debug is essentially a
special kind of logging.
Sample code: PHP
<?php R::startLogging(); R::store( R::dispense( 'book' ) ); R::find('book', 'id > ?',[0]); $logs = R::getLogs(); $count = count( $logs ); print_r( $logs ); R::stopLogging(); // #end php code
public static function stopLogging ( ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
Stops logging and flushes the logs,
convenient method to stop logging of queries.
Use this method to stop logging SQL queries being
executed by the adapter. Logging queries will not
print them on the screen. Use R::getLogs() to
retrieve the logs.
In the example above we start a logging session during
which we store an empty bean of type book. To inspect the
logs we invoke R::getLogs() after stopping the logging.
at the same time because R::debug is essentially a
special kind of logging.
Therefore, only stop logging AFTER you have obtained the
query logs using R::getLogs()
Sample code: PHP
<?php R::startLogging(); R::store( R::dispense( 'book' ) ); R::find('book', 'id > ?',[0]); $logs = R::getLogs(); $count = count( $logs ); print_r( $logs ); R::stopLogging(); // #end php code
public static function getLogs ( ) {} :: STRING[]
inherited from \RedBeanPHP\Facade
@return: {string[]}
Returns the log entries written after the startLogging.
Use this method to obtain the query logs gathered
by the logging mechanisms.
Logging queries will not
print them on the screen. Use R::getLogs() to
retrieve the logs.
In the example above we start a logging session during
which we store an empty bean of type book. To inspect the
logs we invoke R::getLogs() after stopping the logging.
The logs may look like:
[1] => SELECT `book`.* FROM `book` WHERE id > ? -- keep-cache
[2] => array ( 0 => 0, )
[3] => resultset: 1 rows
Basically, element in the array is a log entry.
Parameter bindings are represented as nested arrays (see 2).
at the same time because R::debug is essentially a
special kind of logging.
Therefore, only stop logging AFTER you have obtained the
query logs using R::getLogs()
Sample code: PHP
<?php R::startLogging(); R::store( R::dispense( 'book' ) ); R::find('book', 'id > ?',[0]); $logs = R::getLogs(); $count = count( $logs ); print_r( $logs ); R::stopLogging(); // #end php code
public static function resetQueryCount ( ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
Resets the query counter.
The query counter can be used to monitor the number
of database queries that have
been processed according to the database driver. You can use this
to monitor the number of queries required to render a page.
Usage:
Sample code: PHP
<?php R::resetQueryCount(); echo R::getQueryCount() . ' queries processed.'; // #end php code
public static function getQueryCount ( ) {} :: INTEGER
inherited from \RedBeanPHP\Facade
@return: {integer}
Returns the number of SQL queries processed.
This method returns the number of database queries that have
been processed according to the database driver. You can use this
to monitor the number of queries required to render a page.
Usage:
Sample code: PHP
<?php echo R::getQueryCount() . ' queries processed.'; // #end php code
public static function getLogger ( ) {} :: LOGGER|NULL
inherited from \RedBeanPHP\Facade
@return: {Logger|NULL}
Returns the current logger instance being used by the
database object.
public static function setAutoResolve ( $automatic = true ) {} :: 
inherited from \RedBeanPHP\Facade
public static function usePartialBeans ( boolean|string[] $yesNoBeans ) {} :: BOOLEAN|STRING[]
inherited from \RedBeanPHP\Facade
@return: {boolean|string[]}
@param: {boolean|string[]} $yesNoBeans: List of type names or 'all'
Toggles 'partial bean mode'. If this mode has been
selected the repository will only update the fields of a bean that
have been changed rather than the entire bean.
Pass the value TRUE to select 'partial mode' for all beans.
Pass the value FALSE to disable 'partial mode'.
Pass an array of bean types if you wish to use partial mode only
for some types.
This method will return the previous value.
public static function csv ( string $sql = "", array $bindings = [], array $columns = null, string $path = "/tmp/redexport_%s.csv", boolean $output = true ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $sql: SQL query to expose result of
@param: {array} $bindings: parameter bindings
@param: {array} $columns: column headers for CSV file
@param: {string} $path: path to save CSV file to
@param: {boolean} $output: TRUE to output CSV directly using readfile
@param: {array} $options: delimiter, quote and escape character respectively
Exposes the result of the specified SQL query as a CSV file.
Usage:
The command above will select all cities in Denmark
and create a CSV with columns 'city' and 'population' and
populate the cells under these column headers with the
names of the cities and the population numbers respectively.
Sample code: PHP
<?php R::csv( 'SELECT `name`, population FROM city WHERE region = :region ', array( ':region' => 'Denmark' ), array( 'city', 'population' ), '/tmp/cities.csv' ); // #end php code
public static function matchUp ( string $type, string $sql, array $bindings = [], array $onFoundDo = null, array $onNotFoundDo = null, $bean = null ) {} :: BOOL|NULL
inherited from \RedBeanPHP\Facade
@return: {bool|NULL}
@param: {string} $type: type of bean you're looking for
@param: {string} $sql: SQL snippet (starting at the WHERE clause, omit WHERE-keyword)
@param: {array} $bindings: array of parameter bindings for SQL snippet
@param: {array} $onFoundDo: task list to be considered on finding the bean
@param: {array} $onNotFoundDo: task list to be considered on NOT finding the bean
MatchUp is a powerful productivity boosting method that can replace simple control
scripts with a single RedBeanPHP command. Typically, matchUp() is used to
replace login scripts, token generation scripts and password reset scripts.
The MatchUp method takes a bean type, an SQL query snippet (starting at the WHERE clause),
SQL bindings, a pair of task arrays and a bean reference.
If the first 3 parameters match a bean, the first task list will be considered,
otherwise the second one will be considered. On consideration, each task list,
an array of keys and values will be executed. Every key in the task list should
correspond to a bean property while every value can either be an expression to
be evaluated or a closure (PHP 5.3+). After applying the task list to the bean
it will be stored. If no bean has been found, a new bean will be dispensed.
This method will return TRUE if the bean was found and FALSE if not AND
there was a NOT-FOUND task list. If no bean was found AND there was also
no second task list, NULL will be returned.
To obtain the bean, pass a variable as the sixth parameter.
The function will put the matching bean in the specified variable.
public static function getLook ( ) {} :: LOOK
inherited from \RedBeanPHP\Facade
@return: {Look}
Returns an instance of the Look Helper class.
The instance will be configured with the current toolbox.
In previous versions of RedBeanPHP you had to use:
R::getLook()->look() instead of R::look(). However to improve useability of the
library the look() function can now directly be invoked from the facade.
For more details regarding the Look functionality, please consult R::look().
public static function look ( string $sql, array $bindings = [], array $keys = [0 => "selected", 1 => "id", 2 => "name"], string $template = "<option %s value=\"%s\">%s</option>", callable $filter = "trim", string $glue = "" ) {} :: STRING
inherited from \RedBeanPHP\Facade
@return: {string}
@param: {string} $sql: query to execute
@param: {array} $bindings: parameters to bind to slots mentioned in query or an empty array
@param: {array} $keys: names in result collection to map to template
@param: {string} $template: HTML template to fill with values associated with keys, use printf notation (i.e. %s)
@param: {callable} $filter: function to pass values through (for translation for instance)
@param: {string} $glue: optional glue to use when joining resulting strings
Takes an full SQL query with optional bindings, a series of keys, a template
and optionally a filter function and glue and assembles a view from all this.
This is the fastest way from SQL to view. Typically this function is used to
generate pulldown (select tag) menus with options queried from the database.
Usage:
The example above creates an HTML fragment like this:
<option value="B">BLUE</option>
<option value="R">RED</option>
to pick a color from a palette. The HTML fragment gets constructed by
an SQL query that selects all colors that do not have value 'g' - this
excludes green. Next, the bean properties 'value' and 'name' are mapped to the
HTML template string, note that the order here is important. The mapping and
the HTML template string follow vsprintf-rules. All property values are then
passed through the specified filter function 'strtoupper' which in this case
is a native PHP function to convert strings to uppercase characters only.
Finally the resulting HTML fragment strings are glued together using a
newline character specified in the last parameter for readability.
In previous versions of RedBeanPHP you had to use:
R::getLook()->look() instead of R::look(). However to improve useability of the
library the look() function can now directly be invoked from the facade.
Sample code: PHP
<?php $htmlPulldown = R::look( 'SELECT * FROM color WHERE value != ? ORDER BY value ASC', [ 'g' ], [ 'value', 'name' ], '<option value="%s">%s</option>', 'strtoupper', "\n" ); // #end php code
public static function diff ( OODBBean|OODBBean[] $bean, OODBBean|OODBBean[] $other, array $filters = [0 => "created", 1 => "modified"], string $pattern = "%s.%s.%s" ) {} :: ARRAY
inherited from \RedBeanPHP\Facade
@return: {array}
@param: {OODBBean|OODBBean[]} $bean: reference beans
@param: {OODBBean|OODBBean[]} $other: beans to compare
@param: {array} $filters: names of properties of all beans to skip
@param: {string} $pattern: the format of the key, defaults to '%s.%s.%s'
Calculates a diff between two beans (or arrays of beans).
The result of this method is an array describing the differences of the second bean compared to
the first, where the first bean is taken as reference. The array is keyed by type/property, id and property name, where
type/property is either the type (in case of the root bean) or the property of the parent bean where the type resides.
The diffs are mainly intended for logging, you cannot apply these diffs as patches to other beans.
However this functionality might be added in the future.
The keys of the array can be formatted using the $format parameter.
A key will be composed of a path (1st), id (2nd) and property (3rd).
Using printf-style notation you can determine the exact format of the key.
The default format will look like:
'book.1.title' => array( <OLDVALUE>, <NEWVALUE> )
If you only want a simple diff of one bean and you don't care about ids,
you might pass a format like: '%1$s.%3$s' which gives:
'book.1.title' => array( <OLDVALUE>, <NEWVALUE> )
The filter parameter can be used to set filters, it should be an array
of property names that have to be skipped. By default this array is filled with
two strings: 'created' and 'modified'.
public static function addToolBoxWithKey ( string $key, RedBeanPHP\ToolBox $toolbox ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $key: key to store toolbox instance under
@param: {ToolBox} $toolbox: toolbox to register
The gentleman's way to register a RedBeanPHP ToolBox instance
with the facade. Stores the toolbox in the static toolbox
registry of the facade class. This allows for a neat and
explicit way to register a toolbox.
public static function removeToolBoxByKey ( string $key ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {string} $key: identifier of the toolbox to remove
The gentleman's way to remove a RedBeanPHP ToolBox instance
from the facade. Removes the toolbox identified by
the specified key in the static toolbox
registry of the facade class. This allows for a neat and
explicit way to remove a toolbox.
Returns TRUE if the specified toolbox was found and removed.
Returns FALSE otherwise.
public static function getToolBoxByKey ( string $key ) {} :: TOOLBOX|NULL
inherited from \RedBeanPHP\Facade
@return: {ToolBox|NULL}
@param: {string} $key: key to store toolbox instance under
Returns the toolbox associated with the specified key.
public static function useJSONFeatures ( boolean $flag ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {boolean} $flag: feature flag (either TRUE or FALSE)
Toggles JSON column features.
Invoking this method with boolean TRUE causes 2 JSON features to be enabled.
Beans will automatically JSONify any array that's not in a list property and
the Query Writer (if capable) will attempt to create a JSON column for strings that
appear to contain JSON.
Feature #1:
AQueryWriter::useJSONColumns
Toggles support for automatic generation of JSON columns.
Using JSON columns means that strings containing JSON will
cause the column to be created (not modified) as a JSON column.
However it might also trigger exceptions if this means the DB attempts to
convert a non-json column to a JSON column.
Feature #2:
OODBBean::convertArraysToJSON
Toggles array to JSON conversion. If set to TRUE any array
set to a bean property that's not a list will be turned into
a JSON string. Used together with AQueryWriter::useJSONColumns this
extends the data type support for JSON columns.
So invoking this method is the same as:
Unlike the methods above, that return the previous state, this
method does not return anything (void).
Sample code: PHP
<?php AQueryWriter::useJSONColumns( $flag ); OODBBean::convertArraysToJSON( $flag ); // #end php code
public static function children ( RedBeanPHP\OODBBean $bean, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {OODBBean} $bean: bean to find children of
@param: {string|NULL} $sql: optional SQL snippet
@param: {array} $bindings: SQL snippet parameter bindings
Given a bean and an optional SQL snippet,
this method will return the bean together with all
child beans in a hierarchically structured
bean table.
at least MariaDB 10.2.2 or Postgres. This method does not include
a warning mechanism in case your database does not support this
functionality.
public static function countChildren ( RedBeanPHP\OODBBean $bean, string|NULL $sql = null, array $bindings = [], string|boolean $select = RedBeanPHP\QueryWriter::C_CTE_SELECT_COUNT ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
@param: {OODBBean} $bean: bean to find children of
@param: {string|NULL} $sql: optional SQL snippet
@param: {array} $bindings: SQL snippet parameter bindings
@param: {string|boolean} $select: select snippet to use (advanced, optional, see QueryWriter::queryRecursiveCommonTableExpression)
Given a bean and an optional SQL snippet,
this method will count all child beans in a hierarchically structured
bean table.
at least MariaDB 10.2.2 or Postgres. This method does not include
a warning mechanism in case your database does not support this
functionality.
You are allowed to use named parameter bindings as well as
numeric parameter bindings (using the question mark notation).
However, you can not mix. Also, if using named parameter bindings,
parameter binding key ':slot0' is reserved for the ID of the bean
and used in the query.
By default, if no select is given or select=TRUE this method will subtract 1 of
the total count to omit the starting bean. If you provide your own select,
this method assumes you take control of the resulting total yourself since
it cannot 'predict' what or how you are trying to 'count'.
public static function countParents ( RedBeanPHP\OODBBean $bean, string|NULL $sql = null, array $bindings = [], string|boolean $select = RedBeanPHP\QueryWriter::C_CTE_SELECT_COUNT ) {} :: INT
inherited from \RedBeanPHP\Facade
@return: {int}
@param: {OODBBean} $bean: bean to find children of
@param: {string|NULL} $sql: optional SQL snippet
@param: {array} $bindings: SQL snippet parameter bindings
@param: {string|boolean} $select: select snippet to use (advanced, optional, see QueryWriter::queryRecursiveCommonTableExpression)
Given a bean and an optional SQL snippet,
this method will count all parent beans in a hierarchically structured
bean table.
at least MariaDB 10.2.2 or Postgres. This method does not include
a warning mechanism in case your database does not support this
functionality.
You are allowed to use named parameter bindings as well as
numeric parameter bindings (using the question mark notation).
However, you can not mix. Also, if using named parameter bindings,
parameter binding key ':slot0' is reserved for the ID of the bean
and used in the query.
By default, if no select is given or select=TRUE this method will subtract 1 of
the total count to omit the starting bean. If you provide your own select,
this method assumes you take control of the resulting total yourself since
it cannot 'predict' what or how you are trying to 'count'.
public static function parents ( RedBeanPHP\OODBBean $bean, string|NULL $sql = null, array $bindings = [] ) {} :: OODBBEAN[]
inherited from \RedBeanPHP\Facade
@return: {OODBBean[]}
@param: {OODBBean} $bean: bean to find parents of
@param: {string|NULL} $sql: optional SQL snippet
@param: {array} $bindings: SQL snippet parameter bindings
Given a bean and an optional SQL snippet,
this method will return the bean along with all parent beans
in a hierarchically structured bean table.
at least MariaDB 10.2.2 or Postgres. This method does not include
a warning mechanism in case your database does not support this
functionality.
public static function noNuke ( $yesNo ) {} :: BOOLEAN
inherited from \RedBeanPHP\Facade
@return: {boolean}
@param: {boolean} $flag: TRUE or FALSE
Toggles support for nuke().
Can be used to turn off the nuke() feature for security reasons.
Returns the old flag value.
public static function camelfy ( string|array $snake, boolean $dolphin = false ) {} :: STRING|ARRAY
inherited from \RedBeanPHP\Facade
@return: {string|array}
@param: {string|array} $snake: snake_cased string to convert to camelCase
@param: {boolean} $dolphin: exception for Ids - (bookId -> bookID)
Globally available service method for RedBeanPHP.
Converts a snake cased string to a camel cased string.
If the parameter is an array, the keys will be converted.
too complicated for the human mind, only dolphins can understand this
public static function uncamelfy ( string|array $camel ) {} :: STRING|ARRAY
inherited from \RedBeanPHP\Facade
@return: {string|array}
@param: {string|array} $camel: camelCased string to convert to snake case
Globally available service method for RedBeanPHP.
Converts a camel cased string to a snake cased string.
If the parameter is an array, the keys will be converted.
public static function useFeatureSet ( string $label ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $label: label
Selects the feature set you want as specified by
the label.
Usage:
Sample code: PHP
<?php R::useFeatureSet( 'novice/latest' ); // #end php code
public static function ext ( string $pluginName, callable $callable ) {} :: VOID
inherited from \RedBeanPHP\Facade
@return: {void}
@param: {string} $pluginName: name of the method to call the plugin
@param: {callable} $callable: a PHP 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.
Usage:
Now you can use your makeTea plugin like this:
Sample code: PHP
<?php R::ext( 'makeTea', function() { ... } ); R::makeTea(); // #end php code
public static function __callStatic ( string $pluginName, array $params ) {} @ MIXED
inherited from \RedBeanPHP\Facade
@return: {mixed}
@param: {string} $pluginName: name of the plugin
@param: {array} $params: list of arguments to pass to plugin method
Call static for use with dynamic plugins. This magic method will
intercept static calls and route them to the specified plugin.

class Properties

public static $toolbox :: ToolBox
public static $f ::
Not in use (backward compatibility SQLHelper)
public static $currentDB :: string
public static $toolboxes :: ToolBox[]

class Constants

public const C_REDBEANPHP_VERSION = "5.7" ;  ::
RedBeanPHP version constant.

Sample code: PHP

<?php

use \SmartModExtLib\DbOrmRedbean\ORM as R;

 
R::setup('sqlite:tmp/redbean-dbfile.sqlite'); // use a custom sqlite database with relative path to the project folder (will be stored in {project-folder}/tmp/redbean-dbfile.sqlite)
 //R::setup('mysql:config'); // use the values from Smart.Framework config (mysqli)
 //R::setup('pgsql:config'); // use the values from Smart.Framework config (pgsql)

 
R::freeze(false); // allow schema creation if not exists
 
$book R::dispense('book');
 
$book->title 'Mr.';
 
$book->author 'Test RedBean';
 
$id R::store($book); // write to db
 
R::freeze(true); // freeze schema creations

// #end php code


documentation generated on: 2023-10-19 23:15:56 +0000


Smart.Framework © 2009-2023 unix-world.org