/** * 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|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, self::$exportCaseStyle); }
/** * 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 DuplicationManager(R::getToolBox()); $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 DuplicationManager(R::getToolBox()); /** * $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); 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); }