/** * 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. * * @param RedBean_OODBBean $bean bean to be copied * @param array $trail for internal usage, pass array() * @param boolean $pid for internal usage * * @return array $copiedBean the duplicated bean */ public static function dup($bean, $trail = array(), $pid = false) { $duplicationManager = new RedBean_DuplicationManager(self::$toolbox); return $duplicationManager->dup($bean, $trail, $pid); }
/** * 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) * * @param array|RedBean_OODBBean $beans beans to be exported * @param boolean $parents whether you want parent beans to be exported * @param array $filters whitelist of types * * @return array */ public static function exportAll($beans, $parents = FALSE, $filters = array()) { return self::$duplicationManager->exportAll($beans, $parents, $filters); }
/** * 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) * * @param array|RedBean_OODBBean $beans beans to be exported * @param boolean $parents whether you want parent beans to be exported * @param array $filters whitelist of types * * @return array */ public function exportAll($beans, $parents = FALSE, $filters = array()) { return $this->duplicationManager->exportAll($beans, $parents, $filters); }
public static function setAllowTrees($allow) { self::$trees = $allow; }
/** * 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. * * @param RedBean_OODBBean $bean bean to be copied * @param array $trail for internal usage, pass array() * @param boolean $pid for internal usage * * @return array $copiedBean the duplicated bean */ public static function dup($bean, $trail = array(), $pid = false, $filters = array()) { self::$duplicationManager->setFilters($filters); return self::$duplicationManager->dup($bean, $trail, $pid); }
/** * Test duplication and caching. * * @return void */ public function DupAndCache() { testpack('Dup() and Cache'); $can = R::dispense('can')->setAttr('size', 3); $can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black'); $can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool'); $can = R::load('can', R::store($can)); $d = new RedBean_DuplicationManager(R::$toolbox); $d->setCacheTables(TRUE); ob_start(); R::debug(1); $x = $d->dup($can); $queries = ob_get_contents(); R::debug(0); ob_end_clean(); $len1 = strlen($queries); asrt($len1 > 40, TRUE); asrt(isset($x->ownCoffee), TRUE); asrt(count($x->ownCoffee), 1); asrt(isset($x->sharedTag), TRUE); asrt(count($x->sharedTag), 1); $cache = $d->getSchema(); R::nuke(); $can = R::dispense('can')->setAttr('size', 3); $can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black'); $can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool'); $can = R::load('can', R::store($can)); $d = new RedBean_DuplicationManager(R::$toolbox); /** * $cache = '{"book": { * "id": "INTEGER", * "title": "TEXT" * }, "bean": { * "id": "INTEGER", * "prop": "INTEGER" * }, "pessoa": { * "id": "INTEGER", * "nome": "TEXT", * "nome_meio": "TEXT", * "sobrenome": "TEXT", * "nascimento": "NUMERIC", * "reg_owner": "TEXT" * }, "documento": { * "id": "INTEGER", * "nome_documento": "TEXT", * "numero_documento": "TEXT", * "reg_owner": "TEXT", * "ownPessoa_id": "INTEGER" * }, "can": { * "id": "INTEGER", * "size": "INTEGER" * }, "coffee": { * "id": "INTEGER", * "color": "TEXT", * "can_id": "INTEGER" * }, "tag": { * "id": "INTEGER", * "name": "TEXT" * }, "can_tag": { * "id": "INTEGER", * "tag_id": "INTEGER", * "can_id": "INTEGER" * }}' */ $d->setTables($cache, 1); ob_start(); R::debug(1); $x = $d->dup($can); $queries = ob_get_contents(); ob_end_clean(); R::debug(0); $len2 = strlen($queries); asrt(isset($x->ownCoffee), TRUE); asrt(count($x->ownCoffee), 1); asrt(isset($x->sharedTag), TRUE); asrt(count($x->sharedTag), 1); asrt(json_encode($cache), json_encode($d->getSchema())); asrt($len1 > $len2, TRUE); }