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


PHP RedBeanPHP\OODBBean类代码示例

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


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

示例1: associateBeans

 /**
  * Associates a pair of beans. This method associates two beans, no matter
  * what types. Accepts a base bean that contains data for the linking record.
  * This method is used by associate. This method also accepts a base bean to be used
  * as the template for the link record in the database.
  *
  * @param OODBBean $bean1 first bean
  * @param OODBBean $bean2 second bean
  * @param OODBBean $bean  base bean (association record)
  *
  * @return mixed
  */
 protected function associateBeans(OODBBean $bean1, OODBBean $bean2, OODBBean $bean)
 {
     $type = $bean->getMeta('type');
     $property1 = $bean1->getMeta('type') . '_id';
     $property2 = $bean2->getMeta('type') . '_id';
     if ($property1 == $property2) {
         $property2 = $bean2->getMeta('type') . '2_id';
     }
     $this->oodb->store($bean1);
     $this->oodb->store($bean2);
     $bean->setMeta("cast.{$property1}", "id");
     $bean->setMeta("cast.{$property2}", "id");
     $bean->setMeta('sys.buildcommand.unique', array($property1, $property2));
     $bean->{$property1} = $bean1->id;
     $bean->{$property2} = $bean2->id;
     $results = array();
     try {
         $id = $this->oodb->store($bean);
         $results[] = $id;
     } catch (SQLException $exception) {
         if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION))) {
             throw $exception;
         }
     }
     return $results;
 }
开发者ID:wozzup,项目名称:redbean,代码行数:38,代码来源:AssociationManager.php

示例2: getModelForBean

 /**
  * @see BeanHelper::getModelForBean
  */
 public function getModelForBean(OODBBean $bean)
 {
     $model = $bean->getMeta('type');
     $prefix = defined('REDBEAN_MODEL_PREFIX') ? REDBEAN_MODEL_PREFIX : '\\Model_';
     if (strpos($model, '_') !== FALSE) {
         $modelParts = explode('_', $model);
         $modelName = '';
         foreach ($modelParts as $part) {
             $modelName .= ucfirst($part);
         }
         $modelName = $prefix . $modelName;
         if (!class_exists($modelName)) {
             //second try
             $modelName = $prefix . ucfirst($model);
             if (!class_exists($modelName)) {
                 return NULL;
             }
         }
     } else {
         $modelName = $prefix . ucfirst($model);
         if (!class_exists($modelName)) {
             return NULL;
         }
     }
     $obj = self::factory($modelName);
     $obj->loadBean($bean);
     return $obj;
 }
开发者ID:cesium147,项目名称:redbean,代码行数:31,代码来源:SimpleFacadeBeanHelper.php

示例3: getModelForBean

 public function getModelForBean(OODBBean $bean)
 {
     $model = $bean->getMeta("type");
     $prefix = $this->defaultNamespace;
     $typeMap = $this->typeMap;
     if (isset($typeMap[$model])) {
         $modelName = $typeMap[$model];
     } else {
         if (strpos($model, '_') !== FALSE) {
             $modelParts = explode('_', $model);
             $modelName = '';
             foreach ($modelParts as $part) {
                 $modelName .= ucfirst($part);
             }
             $modelName = $prefix . $modelName;
             if (!class_exists($modelName)) {
                 //second try
                 $modelName = $prefix . ucfirst($model);
                 if (!class_exists($modelName)) {
                     return NULL;
                 }
             }
         } else {
             $modelName = $prefix . ucfirst($model);
             if (!class_exists($modelName)) {
                 return NULL;
             }
         }
     }
     $obj = self::factory($modelName);
     $obj->loadBean($bean);
     return $obj;
 }
开发者ID:MhmdLab,项目名称:redbean-slim,代码行数:33,代码来源:RedBeanHelper.php

示例4: 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;
 }
开发者ID:kanellov,项目名称:gredu_labs,代码行数:8,代码来源:ApplicationFormService.php

示例5: testGetIDShouldNeverPrintNotice

 /**
  * Tests whether getID never produces a notice.
  * 
  * @return void
  */
 public function testGetIDShouldNeverPrintNotice()
 {
     set_error_handler(function ($err, $errStr) {
         die('>>>>FAIL :' . $err . ' ' . $errStr);
     });
     $bean = new OODBBean();
     $bean->getID();
     restore_error_handler();
     pass();
 }
开发者ID:skullyframework,项目名称:skully,代码行数:15,代码来源:Misc.php

示例6: apply

 /**
  * {@inheritdoc}
  */
 public function apply(OODBBean $bean, $eventName, array $options)
 {
     $fields = $options['events'][$eventName];
     $parts = array();
     foreach ($fields as $name) {
         $parts[] = $bean[$name];
     }
     $fieldName = $options['options']['fieldName'];
     if ($parts) {
         $bean->setMeta(sprintf('cast.%s', $fieldName), 'string');
         $bean->{$fieldName} = $this->sluggify(join(' ', $parts));
     }
 }
开发者ID:faz-b,项目名称:redbean-silex-provider,代码行数:16,代码来源:Sluggable.php

示例7: getModelForBean

 public function getModelForBean(\RedBeanPHP\OODBBean $bean)
 {
     $prefix = '\\Model_';
     $model = $bean->getMeta('type');
     $modelName = $prefix . $this->underscoreToCamelCase($model);
     if (!class_exists($modelName)) {
         return null;
     }
     $model = new $modelName();
     if ($model instanceof \Box\InjectionAwareInterface) {
         $model->setDi($this->di);
     }
     $model->loadBean($bean);
     return $model;
 }
开发者ID:Ryan-Nolan,项目名称:boxbilling,代码行数:15,代码来源:BeanHelper.php

示例8: 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

示例9: create

 /**
  *
  * @param \RedBeanPHP\OODBBean $old_object
  * @param \RedBeanPHP\OODBBean $new_object
  * @param type $message
  */
 public static function create($old_object, $new_object, $message, $entity = false)
 {
     //Determine the current user
     $audit = R::dispense('audit');
     $audit->message = $message;
     $audit->date_logged = date('Y-m-d H:i:s');
     $audit->table = $new_object ? $new_object->getMeta('type') : null;
     $audit->entity = $entity ? $entity : $audit->table;
     $aidit->tableId = $new_object ? $new_object->id : $old_object->id;
     $audit->old_obj = serialize($old_object);
     $audit->new_obj = serialize($new_object);
     $audit->user = G()->get_user();
     R::store($audit);
     //		$user->ownAudit[] = $audit;
     //		R::store($user);
     Admin_Alert::add_message($message . ' <a href="' . ADMIN_URL . "package/audit/changes/{$audit->id}" . '">View Change</a>');
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:23,代码来源:Audit.php

示例10: insertEvent

 /** Function to insert new Event
  * @param  array $eventData containg to be inserted for event
  * @param  \RedBeanPHP\OODBBean $user user who is creating the event
  * @retrun boolean
  * **/
 public function insertEvent(array $eventData, \RedBeanPHP\OODBBean $user)
 {
     try {
         //check if event with same name is already associated with user
         $associatedRow = $user->withCondition('event_name = ? LIMIT 1', array($eventData['event_name']))->ownEventsList;
         if (!$associatedRow) {
             $event = $this->_redbeans->dispense('events');
             foreach ($eventData as $column => $data) {
                 $event->{$column} = $data;
             }
             $user->ownEventsList[] = $event;
             return $this->_redbeans->store($user);
         } else {
             throw new \Exception('Cannot insert event with same name');
         }
     } catch (\Exception $e) {
         return false;
     }
     return false;
 }
开发者ID:samiksha-singla,项目名称:Api-Framework,代码行数:25,代码来源:Events.php

示例11: testMetaData

 /**
  * Test meta data methods.
  *
  * @return void
  */
 public function testMetaData()
 {
     testpack('Test meta data');
     $bean = new OODBBean();
     $bean->setMeta("this.is.a.custom.metaproperty", "yes");
     asrt($bean->getMeta("this.is.a.custom.metaproperty"), "yes");
     asrt($bean->getMeta("nonexistant"), NULL);
     asrt($bean->getMeta("nonexistant", "abc"), "abc");
     asrt($bean->getMeta("nonexistant.nested"), NULL);
     asrt($bean->getMeta("nonexistant,nested", "abc"), "abc");
     $bean->setMeta("test.two", "second");
     asrt($bean->getMeta("test.two"), "second");
     $bean->setMeta("another.little.property", "yes");
     asrt($bean->getMeta("another.little.property"), "yes");
     asrt($bean->getMeta("test.two"), "second");
     // Copy Metadata
     $bean = new OODBBean();
     $bean->setMeta("meta.meta", "123");
     $bean2 = new OODBBean();
     asrt($bean2->getMeta("meta.meta"), NULL);
     $bean2->copyMetaFrom($bean);
     asrt($bean2->getMeta("meta.meta"), "123");
 }
开发者ID:gabordemooij,项目名称:redbean,代码行数:28,代码来源:Meta.php

示例12: testCheckDirectly

 /**
  * Normally the check() method is always called indirectly when
  * dealing with beans. This test ensures we can call check()
  * directly. Even though frozen repositories do not rely on
  * bean checking to improve performance the method should still
  * offer the same functionality when called directly.
  *
  * @return void
  */
 public function testCheckDirectly()
 {
     $bean = new OODBBean();
     $bean->id = 0;
     $bean->setMeta('type', 'book');
     R::getRedBean()->check($bean);
     $bean->setMeta('type', '.');
     try {
         R::getRedBean()->check($bean);
         fail();
     } catch (\Exception $e) {
         pass();
     }
     //check should remain the same even if frozen repo is used, method is public after all!
     //we dont want to break the API!
     R::freeze(TRUE);
     try {
         R::getRedBean()->check($bean);
         fail();
     } catch (\Exception $e) {
         pass();
     }
     R::freeze(FALSE);
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:33,代码来源:Misc.php

示例13: processLists

 /**
  * Stores a bean and its lists in one run.
  *
  * @param OODBBean $bean
  *
  * @return void
  */
 protected function processLists(OODBBean $bean)
 {
     $sharedAdditions = $sharedTrashcan = $sharedresidue = $sharedItems = $ownAdditions = $ownTrashcan = $ownresidue = $embeddedBeans = array();
     //Define groups
     foreach ($bean as $property => $value) {
         $value = $value instanceof SimpleModel ? $value->unbox() : $value;
         if ($value instanceof OODBBean) {
             $this->processEmbeddedBean($embeddedBeans, $bean, $property, $value);
         } elseif (is_array($value)) {
             $originals = $bean->getMeta('sys.shadow.' . $property, array());
             $bean->setMeta('sys.shadow.' . $property, NULL);
             //clear shadow
             if (strpos($property, 'own') === 0) {
                 list($ownAdditions, $ownTrashcan, $ownresidue) = $this->processGroups($originals, $value, $ownAdditions, $ownTrashcan, $ownresidue);
                 $listName = lcfirst(substr($property, 3));
                 if ($bean->getMeta('sys.exclusive-' . $listName)) {
                     OODBBean::setMetaAll($ownTrashcan, 'sys.garbage', TRUE);
                 }
                 unset($bean->{$property});
             } elseif (strpos($property, 'shared') === 0) {
                 list($sharedAdditions, $sharedTrashcan, $sharedresidue) = $this->processGroups($originals, $value, $sharedAdditions, $sharedTrashcan, $sharedresidue);
                 unset($bean->{$property});
             }
         }
     }
     $this->storeBean($bean);
     $this->addForeignKeysForParentBeans($bean, $embeddedBeans);
     $this->processTrashcan($bean, $ownTrashcan);
     $this->processAdditions($bean, $ownAdditions);
     $this->processResidue($ownresidue);
     $this->processSharedTrashcan($bean, $sharedTrashcan);
     $this->processSharedAdditions($bean, $sharedAdditions);
     $this->processSharedResidue($bean, $sharedresidue);
 }
开发者ID:cesium147,项目名称:redbean,代码行数:41,代码来源:Fluid.php

示例14: storeBean

 /**
  * Stores a cleaned bean; i.e. only scalar values. This is the core of the store()
  * method. When all lists and embedded beans (parent objects) have been processed and
  * removed from the original bean the bean is passed to this method to be stored
  * in the database.
  *
  * @param OODBBean $bean the clean bean
  *
  * @return void
  */
 protected function storeBean(OODBBean $bean)
 {
     if ($bean->getMeta('changed')) {
         $this->check($bean);
         $table = $bean->getMeta('type');
         $this->createTableIfNotExists($bean, $table);
         $updateValues = array();
         foreach ($bean as $property => $value) {
             if ($property !== 'id') {
                 $this->modifySchema($bean, $property, $value);
             }
             if ($property !== 'id') {
                 $updateValues[] = array('property' => $property, 'value' => $value);
             }
         }
         $bean->id = $this->writer->updateRecord($table, $updateValues, $bean->id);
         $bean->setMeta('changed', FALSE);
     }
     $bean->setMeta('tainted', FALSE);
 }
开发者ID:gabordemooij,项目名称:redbean,代码行数:30,代码来源:Fluid.php

示例15: getModelForBean

 /**
  * Returns a model for a bean based on its type.
  *
  * @param OODBBean $bean
  *
  * @return object
  */
 public function getModelForBean(\RedBeanPHP\OODBBean $bean)
 {
     if ($bean->getMeta('type') === 'meal') {
         $model = new Model_Soup();
         $model->loadBean($bean);
         return $model;
     } else {
         return parent::getModelForBean($bean);
     }
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:17,代码来源:classes.php


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