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


PHP RedBean_OODBBean::export方法代码示例

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


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

示例1: onEvent

 /**
  * Does an optimization cycle for each UPDATE event.
  *
  * @param string				$event event
  * @param RedBean_OODBBean $bean	 bean
  *
  * @return void
  */
 public function onEvent($event, $bean)
 {
     try {
         if ($event == "update") {
             //export the bean as an array
             $arr = $bean->export();
             //print_r($arr);
             //remove the id property
             unset($arr["id"]);
             //If we are left with an empty array we might as well return
             if (count($arr) == 0) {
                 return;
             }
             //fetch table name for this bean
             //get the column names for this table
             $table = $bean->getMeta("type");
             $columns = array_keys($arr);
             //Select a random column for optimization.
             $column = $columns[array_rand($columns)];
             //get the value to be optimized
             $value = $arr[$column];
             $this->optimize($table, $column, $value);
         }
     } catch (RedBean_Exception_SQL $e) {
     }
 }
开发者ID:ryjkov,项目名称:redbean,代码行数:34,代码来源:Optimizer.php

示例2: onEvent

 /**
  * Does an optimization cycle for each UPDATE event
  * @param string $event
  * @param RedBean_OODBBean $bean
  */
 public function onEvent($event, $bean)
 {
     try {
         if ($event == "update") {
             $arr = $bean->export();
             unset($arr["id"]);
             if (count($arr) == 0) {
                 return;
             }
             $table = $this->adapter->escape($bean->getMeta("type"));
             $columns = array_keys($arr);
             $column = $this->adapter->escape($columns[array_rand($columns)]);
             $value = $arr[$column];
             $type = $this->writer->scanType($value);
             $fields = $this->writer->getColumns($table);
             if (!in_array($column, array_keys($fields))) {
                 return;
             }
             $typeInField = $this->writer->code($fields[$column]);
             if ($type < $typeInField) {
                 $type = $this->writer->typeno_sqltype[$type];
                 $this->adapter->exec("alter table `{$table}` add __test " . $type);
                 $this->adapter->exec("update `{$table}` set __test=`{$column}`");
                 $diff = $this->adapter->getCell("select\n\t\t\t\t\t\t\tcount(*) as df from `{$table}` where\n\t\t\t\t\t\t\tstrcmp(`{$column}`,__test) != 0");
                 if (!$diff) {
                     $this->adapter->exec("alter table `{$table}` change `{$column}` `{$column}` " . $type);
                 }
                 $this->adapter->exec("alter table `{$table}` drop __test");
             }
         }
     } catch (RedBean_Exception_SQL $e) {
         //optimizer might make mistakes, dont care..
     }
 }
开发者ID:nurulimamnotes,项目名称:DewiSriDesktop,代码行数:39,代码来源:Optimizer.php

示例3: onEvent

 /**
  * Does an optimization cycle for each UPDATE event.
  * @param string $event
  * @param RedBean_OODBBean $bean
  */
 public function onEvent($event, $bean)
 {
     try {
         if ($event == "update") {
             $arr = $bean->export();
             unset($arr["id"]);
             if (count($arr) == 0) {
                 return;
             }
             $table = $this->adapter->escape($bean->getMeta("type"));
             $columns = array_keys($arr);
             //Select a random column for optimization.
             $column = $this->adapter->escape($columns[array_rand($columns)]);
             $value = $arr[$column];
             $type = $this->writer->scanType($value);
             $fields = $this->writer->getColumns($table);
             if (!in_array($column, array_keys($fields))) {
                 return;
             }
             $typeInField = $this->writer->code($fields[$column]);
             //Is the type too wide?
             if ($type < $typeInField) {
                 try {
                     @$this->adapter->exec("alter table " . $this->writer->noKW($table) . " drop __test");
                 } catch (Exception $e) {
                 }
                 //Try to re-fit the entire column; by testing it.
                 $type = $this->writer->typeno_sqltype[$type];
                 //Add a test column.
                 @$this->adapter->exec("alter table " . $this->writer->noKW($table) . " add __test " . $type);
                 //Copy the values and see if there are differences.
                 @$this->adapter->exec("update " . $this->writer->noKW($table) . " set __test=" . $this->writer->noKW($column) . "");
                 $rows = $this->adapter->get("select " . $this->writer->noKW($column) . " as a, __test as b from " . $this->writer->noKW($table));
                 $diff = 0;
                 foreach ($rows as $row) {
                     $diff += $row["a"] != $row["b"];
                 }
                 if (!$diff) {
                     //No differences; shrink column.
                     @$this->adapter->exec("alter table " . $this->writer->noKW($table) . " change " . $this->writer->noKW($column) . " " . $this->writer->noKW($column) . " " . $type);
                 }
                 //Throw away test column; we don't need it anymore!
                 @$this->adapter->exec("alter table " . $this->writer->noKW($table) . " drop __test");
             } else {
                 $this->MySQLSpecificColumns($table, $column, $fields[$column], $value);
             }
         }
     } catch (RedBean_Exception_SQL $e) {
         //optimizer might make mistakes, don't care.
         //echo $e->getMessage()."<br>";
     }
 }
开发者ID:surfnjunkie,项目名称:redbean,代码行数:57,代码来源:Optimizer.php

示例4: put

 /**
  * Handles a REST PUT request.
  * Updates the bean described in the payload array in the database.
  * Returns an array formatted according to RedBeanPHP REST BeanCan
  * formatting specifications.
  *
  * Format of the payload array:
  *
  * array(
  *        'bean' => array( property => value pairs )
  * )
  *
  * @return array
  */
 private function put()
 {
     if (!isset($this->payload['bean'])) {
         return $this->resp(NULL, self::C_HTTP_BAD_REQUEST, 'Missing parameter \'bean\'.');
     }
     if (!is_array($this->payload['bean'])) {
         return $this->resp(NULL, self::C_HTTP_BAD_REQUEST, 'Parameter \'bean\' must be object/array.');
     }
     foreach ($this->payload['bean'] as $key => $value) {
         if (!is_string($key) || !is_string($value)) {
             return $this->resp(NULL, self::C_HTTP_BAD_REQUEST, 'Object "bean" invalid.');
         }
     }
     $this->bean->import($this->payload['bean']);
     $this->oodb->store($this->bean);
     $this->bean = $this->oodb->load($this->bean->getMeta('type'), $this->bean->id);
     return $this->resp($this->bean->export());
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:32,代码来源:BeanCanResty.php

示例5: inject

 /**
  * Injects the properties of another bean but keeps the original ID.
  * Just like import() but keeps the original ID.
  * Chainable.
  *
  * @param RedBean_OODBBean $otherBean the bean whose properties you would like to copy
  *
  * @return RedBean_OODBBean
  */
 public function inject(RedBean_OODBBean $otherBean)
 {
     $myID = $this->properties['id'];
     $this->import($otherBean->export());
     $this->id = $myID;
     return $this;
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:16,代码来源:OODBBean.php

示例6: inject

 /**
  * Injects the properties of another bean but keeps the original ID.
  * Just like import() but keeps the original ID.
  * Chainable.
  * 
  * @param RedBean_OODBBean $otherBean the bean whose properties you would like to copy
  * 
  * @return RedBean_OODBBean $self
  */
 public function inject(RedBean_OODBBean $otherBean)
 {
     $myID = $this->id;
     $array = $otherBean->export();
     $this->import($array);
     $this->id = $myID;
     return $this;
 }
开发者ID:chrispoupart,项目名称:BicBucStriim,代码行数:17,代码来源:rb.php

示例7: copy

 /**
  * Makes a copy of a bean. This method copies the bean and
  * adds the specified associations.
  *
  * For instance: R::copy( $book, "author,library" );
  *
  * Duplicates the $book bean and copies the association links
  * author and library as well. Note that only many-to-many
  * associations can be copied. Also note that no author or library
  * beans are copied, only the connections or references to these
  * beans.
  *
  * @param RedBean_OODBBean $bean
  * @param string $associatedBeanTypesStr
  * @return array $copiedBean
  */
 public static function copy($bean, $associatedBeanTypesStr)
 {
     $type = $bean->getMeta("type");
     $copy = R::dispense($type);
     $copy->import($bean->export());
     $copy->copyMetaFrom($bean);
     $copy->id = 0;
     R::store($copy);
     $associatedBeanTypes = explode(",", $associatedBeanTypesStr);
     foreach ($associatedBeanTypes as $associatedBeanType) {
         $assocBeans = R::related($bean, $associatedBeanType);
         foreach ($assocBeans as $assocBean) {
             R::associate($copy, $assocBean);
         }
     }
     $copy->setMeta("original", $bean);
     return $copy;
 }
开发者ID:nev3rm0re,项目名称:hondex,代码行数:34,代码来源:rb127lg.php

示例8: exportBean

 public function exportBean(RedBean_OODBBean $bean)
 {
     $bid = $bean->getMeta('type') . '-' . $bean->getID();
     if (isset($this->recurCheck[$bid])) {
         return null;
     }
     $this->recurCheck[$bid] = $bid;
     $export = $bean->export();
     foreach ($export as $key => $value) {
         if (strpos($key, '_id') !== false) {
             $sub = str_replace('_id', '', $key);
             $subBean = $bean->{$sub};
             if ($subBean) {
                 $export[$sub] = $this->export($subBean, false);
             }
         }
     }
     $type = $bean->getMeta('type');
     $linkField = $type . '_id';
     foreach ($this->tables as $table => $cols) {
         if (strpos($table, '_') === false) {
             if (in_array($linkField, array_keys($cols))) {
                 $field = 'own' . ucfirst($table);
                 $export[$field] = self::export($bean->{$field}, false);
             }
         }
     }
     foreach ($this->tables as $table => $cols) {
         if (strpos($table, '_') !== false) {
             $parts = explode('_', $table);
             if (is_array($parts) && in_array($type, $parts)) {
                 $other = $parts[0];
                 if ($other == $type) {
                     $other = $parts[1];
                 }
                 $field = 'shared' . ucfirst($other);
                 $export[$field] = self::export($bean->{$field}, false);
             }
         }
     }
     return $export;
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:42,代码来源:rb.php

示例9: ObservableMock

asrt($bean->getMeta("test.two"), "second");
testpack("UNIT TEST RedBean OODBBean: copyMeta");
$bean = new RedBean_OODBBean();
$bean->setMeta("meta.meta", "123");
$bean2 = new RedBean_OODBBean();
asrt($bean2->getMeta("meta.meta"), NULL);
$bean2->copyMetaFrom($bean);
asrt($bean2->getMeta("meta.meta"), "123");
testpack("UNIT TEST RedBean OODBBean: import");
$bean = new RedBean_OODBBean();
$bean->import(array("a" => 1, "b" => 2));
asrt($bean->a, 1);
asrt($bean->b, 2);
testpack("UNIT TEST RedBean OODBBean: export");
$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);
//Test observer
testpack("UNIT TEST Observer Mechanism ");
$observable = new ObservableMock();
$observer = new ObserverMock();
$observable->addEventListener("event1", $observer);
开发者ID:blocka,项目名称:redbean,代码行数:31,代码来源:test.php

示例10: exportBean

 /**
  * Exports a single bean
  *
  * @param RedBean_OODBBean $bean Bean to be exported
  *
  * @return array|NULL $array Array export of bean
  */
 public function exportBean(RedBean_OODBBean $bean)
 {
     $bid = $bean->getMeta('type') . '-' . $bean->getID();
     if (isset($this->recurCheck[$bid])) {
         return NULL;
     }
     $this->recurCheck[$bid] = $bid;
     $export = $bean->export();
     foreach ($export as $key => $value) {
         $this->extractParentBean($export, $bean, $key, $value);
     }
     foreach ($this->tables as $table => $cols) {
         //get all ownProperties
         $this->extractOwnList($export, $bean, $table, $cols);
     }
     foreach ($this->tables as $table => $cols) {
         //get all sharedProperties
         $this->extractSharedList($export, $bean, $table);
     }
     return $export;
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:28,代码来源:BeanExport.php

示例11: testExportAll

 /**
  * ExportAll.
  * 
  * @return void
  */
 public function testExportAll()
 {
     testpack('Test exportAll');
     $redbean = R::$redbean;
     $bean = new RedBean_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
     $object = R::graph(json_decode('{"type":"bandmember","name":"Duke","ownInstrument":[{"type":"instrument","name":"Piano"}]}', TRUE));
     $a = R::exportAll($object);
     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);
     $a = R::exportAll($v);
     asrt(count($a[0]['sharedArmy']), 2);
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:99,代码来源:Export.php


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