本文整理汇总了PHP中RedBeanPHP\OODBBean::export方法的典型用法代码示例。如果您正苦于以下问题:PHP OODBBean::export方法的具体用法?PHP OODBBean::export怎么用?PHP OODBBean::export使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\OODBBean
的用法示例。
在下文中一共展示了OODBBean::export方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportApplicationForm
private function exportApplicationForm(OODBBean $bean)
{
$appForm = $bean->export();
$appForm['items'] = array_map(function ($itemBean) {
return array_merge($itemBean->export(), ['lab' => $itemBean->lab->name, 'itemcategory' => $itemBean->itemcategory->name]);
}, $bean->ownApplicationformitemList);
return $appForm;
}
示例2: validate
public static function validate(\RedBeanPHP\OODBBean $bean)
{
$data = $bean->export();
$model = $bean->box() !== null ? $bean->box() : null;
if (!$model) {
throw new ModelValidation_Exception('This bean does not have a model!');
}
$rules = isset($model::$rules) ? $model::$rules : null;
if (!$rules) {
throw new ModelValidation_Exception('This bean does not have any established rules!');
}
$validations = [];
$filters = [];
$labels = [];
$messages = [];
foreach ($rules as $field => $rule) {
if (isset($rule['filter'])) {
$filters[$field] = $rule['filter'];
}
if (isset($rule['label'])) {
$labels[$field] = $rule['label'];
}
if (isset($rule['validation'])) {
$validations[$field] = $rule['validation'];
}
if (isset($rule['message'])) {
$field = isset($rule['label']) ? $rule['label'] : ucwords(str_replace(array('_', '-'), chr(32), $field));
$messages[$field] = $rule['message'];
}
}
$gump = new \GUMP();
if (!empty($filters)) {
$gump->filter_rules($filters);
}
if (!empty($validations)) {
$gump->validation_rules($validations);
}
if (!empty($labels)) {
$gump->set_field_names($labels);
}
$validated_data = $gump->run($data);
if ($validated_data === false) {
return self::default2custom_errors($gump->get_errors_array(), $messages);
} else {
$bean->import($validated_data);
return true;
}
}
示例3: inject
/**
* Injects the properties of another bean but keeps the original ID.
* Just like import() but keeps the original ID.
* Chainable.
*
* @param OODBBean $otherBean the bean whose properties you would like to copy
*
* @return OODBBean
*/
public function inject(OODBBean $otherBean)
{
$myID = $this->properties['id'];
$this->import($otherBean->export());
$this->id = $myID;
return $this;
}
示例4: testExportAll
/**
* ExportAll.
*
* @return void
*/
public function testExportAll()
{
testpack('Test exportAll');
$redbean = R::getRedBean();
$bean = new OODBBean();
$bean->import(array("a" => 1, "b" => 2));
$bean->setMeta("justametaproperty", "hellothere");
$arr = $bean->export();
asrt(is_array($arr), TRUE);
asrt(isset($arr["a"]), TRUE);
asrt(isset($arr["b"]), TRUE);
asrt($arr["a"], 1);
asrt($arr["b"], 2);
asrt(isset($arr["__info"]), FALSE);
$arr = $bean->export(TRUE);
asrt(isset($arr["__info"]), TRUE);
asrt($arr["a"], 1);
asrt($arr["b"], 2);
$exportBean = $redbean->dispense("abean");
$exportBean->setMeta("metaitem.bla", 1);
$exportedBean = $exportBean->export(TRUE);
asrt($exportedBean["__info"]["metaitem.bla"], 1);
asrt($exportedBean["__info"]["type"], "abean");
// Can we determine whether a bean is empty?
testpack('test $bean->isEmpty() function');
$bean = R::dispense('bean');
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = 1;
asrt($bean->isEmpty(), FALSE);
asrt(count($bean) > 0, TRUE);
$bean->property = 0;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = FALSE;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = NULL;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
unset($bean->property);
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
// Export bug I found
$bandmember = R::dispense('bandmember');
$bandmember->name = 'Duke';
$instrument = R::dispense('instrument');
$instrument->name = 'Piano';
$bandmember->ownInstrument[] = $instrument;
$a = R::exportAll($bandmember);
pass();
asrt(isset($a[0]), TRUE);
asrt((int) $a[0]['id'], 0);
asrt($a[0]['name'], 'Duke');
asrt($a[0]['ownInstrument'][0]['name'], 'Piano');
R::nuke();
$v = R::dispense('village');
$b = R::dispense('building');
$v->name = 'a';
$b->name = 'b';
$v->ownBuilding[] = $b;
$id = R::store($v);
$a = R::exportAll($v);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
$v = R::load('village', $id);
$b2 = R::dispense('building');
$b2->name = 'c';
$v->ownBuilding[] = $b2;
$a = R::exportAll($v);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
asrt(count($a[0]['ownBuilding']), 2);
list($r1, $r2) = R::dispense('army', 2);
$r1->name = '1';
$r2->name = '2';
$v->sharedArmy[] = $r2;
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
R::store($v);
$v = R::load('village', $id);
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
asrt(count($a[0]['ownBuilding']), 2);
$v->sharedArmy[] = $r1;
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 2);
$v = R::load('village', $id);
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
$v->sharedArmy[] = $r1;
R::store($v);
$v = R::load('village', $id);
//.........这里部分代码省略.........