当前位置: 首页>>代码示例>>PHP>>正文


PHP OODBBean::import方法代码示例

本文整理汇总了PHP中RedBeanPHP\OODBBean::import方法的典型用法代码示例。如果您正苦于以下问题:PHP OODBBean::import方法的具体用法?PHP OODBBean::import怎么用?PHP OODBBean::import使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedBeanPHP\OODBBean的用法示例。


在下文中一共展示了OODBBean::import方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
     }
 }
开发者ID:filisko,项目名称:redbean-validation-plugin,代码行数:48,代码来源:ModelValidation.php

示例2: 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);
//.........这里部分代码省略.........
开发者ID:diego-vieira,项目名称:redbean,代码行数:101,代码来源:Export.php

示例3: testImportFromAndTainted

 /**
  * Test import from and tainted.
  *
  * @return void
  */
 public function testImportFromAndTainted()
 {
     testpack('Test importFrom() and Tainted');
     $bean = R::dispense('bean');
     R::store($bean);
     $bean->name = 'abc';
     asrt($bean->getMeta('tainted'), TRUE);
     R::store($bean);
     asrt($bean->getMeta('tainted'), FALSE);
     $copy = R::dispense('bean');
     R::store($copy);
     $copy = R::load('bean', $copy->id);
     asrt($copy->getMeta('tainted'), FALSE);
     $copy->import(array('name' => 'xyz'));
     asrt($copy->getMeta('tainted'), TRUE);
     $copy->setMeta('tainted', FALSE);
     asrt($copy->getMeta('tainted'), FALSE);
     $copy->importFrom($bean);
     asrt($copy->getMeta('tainted'), TRUE);
     testpack('Test basic import() feature.');
     $bean = new OODBBean();
     $bean->import(array("a" => 1, "b" => 2));
     asrt($bean->a, 1);
     asrt($bean->b, 2);
     $bean->import(array("a" => 3, "b" => 4), "a,b");
     asrt($bean->a, 3);
     asrt($bean->b, 4);
     $bean->import(array("a" => 5, "b" => 6), " a , b ");
     asrt($bean->a, 5);
     asrt($bean->b, 6);
     $bean->import(array("a" => 1, "b" => 2));
     testpack('Test inject() feature.');
     $coffee = R::dispense('coffee');
     $coffee->id = 2;
     $coffee->liquid = 'black';
     $cup = R::dispense('cup');
     $cup->color = 'green';
     // Pour coffee in cup
     $cup->inject($coffee);
     // Do we still have our own property?
     asrt($cup->color, 'green');
     // Did we pour the liquid in the cup?
     asrt($cup->liquid, 'black');
     // Id should not be transferred
     asrt($cup->id, 0);
 }
开发者ID:cesium147,项目名称:redbean,代码行数:51,代码来源:Import.php


注:本文中的RedBeanPHP\OODBBean::import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。