$toolbox
$toolbox : \RedBeanPHP\ToolBox
Duplication Manager The Duplication Manager creates deep copies from beans, this means it can duplicate an entire bean hierarchy. You can use this feature to implement versioning for instance. Because duplication and exporting are closely related this class is also used to export beans recursively (i.e. we make a duplicate and then convert to array). This class allows you to tune the duplication process by specifying filters determining which relations to take into account and by specifying tables (in which case no reflective queries have to be issued thus improving performance). This class also hosts the Camelfy function used to reformat the keys of an array, this method is publicly available and used internally by exportAll().
$toolbox : \RedBeanPHP\ToolBox
$associationManager : \RedBeanPHP\AssociationManager
$redbean : \RedBeanPHP\OODB
__construct(\RedBeanPHP\ToolBox $toolbox)
Constructor, creates a new instance of DupManager.
\RedBeanPHP\ToolBox | $toolbox |
setTables(array $tables) : void
For better performance you can pass the tables in an array to this method.
If the tables are available the duplication manager will not query them so this might be beneficial for performance.
This method allows two array formats:
array( TABLE1, TABLE2 ... )
or
array( TABLE1 => array( COLUMN1, COLUMN2 ... ) ... )
array | $tables | a table cache array |
setCacheTables(boolean $yesNo) : void
Indicates whether you want the duplication manager to cache the database schema.
If this flag is set to TRUE the duplication manager will query the database schema only once. Otherwise the duplicationmanager will, by default, query the schema every time a duplication action is performed (dup()).
boolean | $yesNo | TRUE to use caching, FALSE otherwise |
setFilters(array $filters) : void
A filter array is an array with table names.
By setting a table filter you can make the duplication manager only take into account certain bean types. Other bean types will be ignored when exporting or making a deep copy. If no filters are set all types will be taking into account, this is the default behavior.
array | $filters | list of tables to be filtered |
dup(\RedBeanPHP\OODBBean $bean, array $trail = array(), boolean $preserveIDs = FALSE) : \RedBeanPHP\OODBBean
Makes a copy of a bean. This method makes a deep copy of the bean.The copy will have the following features.
Note: This function does a reflectional database query so it may be slow.
Note: this function actually passes the arguments to a protected function called duplicate() that does all the work. This method takes care of creating a clone of the bean to avoid the bean getting tainted (triggering saving when storing it).
\RedBeanPHP\OODBBean | $bean | bean to be copied |
array | $trail | for internal usage, pass array() |
boolean | $preserveIDs | for internal usage |
exportAll(array|\RedBeanPHP\OODBBean $beans, boolean $parents = FALSE, array $filters = array(), string $caseStyle = 'snake', boolean $meta = FALSE) : array
Exports a collection of beans recursively.
This method will export an array of beans in the first argument to a set of arrays. This can be used to send JSON or XML representations of bean hierarchies to the client.
For every bean in the array this method will export:
If the second parameter is set to TRUE the parents of the beans in the array will be exported as well (but not THEIR parents).
The third parameter can be used to provide a white-list array for filtering. This is an array of strings representing type names, only the type names in the filter list will be exported.
The fourth parameter can be used to change the keys of the resulting export arrays. The default mode is 'snake case' but this leaves the keys as-is, because 'snake' is the default case style used by RedBeanPHP in the database. You can set this to 'camel' for camel cased keys or 'dolphin' (same as camelcase but id will be converted to ID instead of Id).
array|\RedBeanPHP\OODBBean | $beans | beans to be exported |
boolean | $parents | also export parents |
array | $filters | only these types (whitelist) |
string | $caseStyle | case style identifier |
boolean | $meta | export meta data as well |
duplicate(\RedBeanPHP\OODBBean $bean, array $trail = array(), boolean $preserveIDs = FALSE) : \RedBeanPHP\OODBBean
\RedBeanPHP\OODBBean | $bean | bean to be copied |
array | $trail | trail to prevent infinite loops |
boolean | $preserveIDs | preserve IDs |
copySharedBeans(\RedBeanPHP\OODBBean $copy, string $shared, array $beans) : void
Copies the shared beans in a bean, i.e. all the sharedBean-lists.
\RedBeanPHP\OODBBean | $copy | target bean to copy lists to |
string | $shared | name of the shared list |
array | $beans | array with shared beans to copy |
copyOwnBeans(\RedBeanPHP\OODBBean $copy, string $owned, array $beans, array $trail, boolean $preserveIDs) : void
Copies the own beans in a bean, i.e. all the ownBean-lists.
Each bean in the own-list belongs exclusively to its owner so we need to invoke the duplicate method again to duplicate each bean here.
\RedBeanPHP\OODBBean | $copy | target bean to copy lists to |
string | $owned | name of the own list |
array | $beans | array with shared beans to copy |
array | $trail | array with former beans to detect recursion |
boolean | $preserveIDs | TRUE means preserve IDs, for export only |
createCopy(\RedBeanPHP\OODBBean $bean) : \RedBeanPHP\OODBBean
Creates a copy of bean $bean and copies all primitive properties (not lists) and the parents beans to the newly created bean. Also sets the ID of the bean to 0.
\RedBeanPHP\OODBBean | $bean | bean to copy |
inTrailOrAdd(array $trail, \RedBeanPHP\OODBBean $bean) : boolean
Generates a key from the bean type and its ID and determines if the bean occurs in the trail, if not the bean will be added to the trail.
Returns TRUE if the bean occurs in the trail and FALSE otherwise.
array | $trail | list of former beans |
\RedBeanPHP\OODBBean | $bean | currently selected bean |
getListNames(string $typeName) : array
Given the type name of a bean this method returns the canonical names of the own-list and the shared-list properties respectively.
Returns a list with two elements: name of the own-list, and name of the shared list.
string | $typeName | bean type name |