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


PHP OODBBean::getMeta方法代码示例

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


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

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

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

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

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

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

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

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

示例8: set1toNAssoc

/**
 * Emulates legacy function for use with older tests.
 */
function set1toNAssoc($a, \RedBeanPHP\OODBBean $bean1, \RedBeanPHP\OODBBean $bean2)
{
    $type = $bean1->getMeta("type");
    $a->clearRelations($bean2, $type);
    $a->associate($bean1, $bean2);
    if (count($a->related($bean2, $type)) === 1) {
        // return $this;
    } else {
        throw new \RedBeanPHP\RedException\SQL("Failed to enforce 1-N Relation for {$type} ");
    }
}
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:14,代码来源:functions.php

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

示例10: 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)
  *
  * @throws\Exception|SQL
  *
  * @return mixed
  */
 protected function associateBeans(OODBBean $bean1, OODBBean $bean2, OODBBean $bean)
 {
     $property1 = $bean1->getMeta('type') . '_id';
     $property2 = $bean2->getMeta('type') . '_id';
     if ($property1 == $property2) {
         $property2 = $bean2->getMeta('type') . '2_id';
     }
     //Dont mess with other tables, only add the unique constraint if:
     //1. the table exists (otherwise we cant inspect it)
     //2. the table only contains N-M fields: ID, N-ID, M-ID.
     $unique = array($property1, $property2);
     $type = $bean->getMeta('type');
     $tables = $this->writer->getTables();
     if (in_array($type, $tables) && !$this->oodb->isChilled($type)) {
         $columns = $this->writer->getColumns($type);
         if (count($columns) === 3 && isset($columns['id']) && isset($columns[$property1]) && isset($columns[$property2])) {
             $bean->setMeta('buildcommand.unique', array($unique));
         }
     }
     //add a build command for Single Column Index (to improve performance in case unqiue cant be used)
     $indexName1 = 'index_for_' . $bean->getMeta('type') . '_' . $property1;
     $indexName2 = 'index_for_' . $bean->getMeta('type') . '_' . $property2;
     $bean->setMeta('buildcommand.indexes', array($property1 => $indexName1, $property2 => $indexName2));
     $this->oodb->store($bean1);
     $this->oodb->store($bean2);
     $bean->setMeta("cast.{$property1}", "id");
     $bean->setMeta("cast.{$property2}", "id");
     $bean->{$property1} = $bean1->id;
     $bean->{$property2} = $bean2->id;
     $results = array();
     try {
         $id = $this->oodb->store($bean);
         //On creation, add constraints....
         if (!$this->oodb->isFrozen() && $bean->getMeta('buildreport.flags.created')) {
             $bean->setMeta('buildreport.flags.created', 0);
             if (!$this->oodb->isFrozen()) {
                 $this->writer->addConstraintForTypes($bean1->getMeta('type'), $bean2->getMeta('type'));
             }
         }
         $results[] = $id;
     } catch (SQL $exception) {
         if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION))) {
             throw $exception;
         }
     }
     return $results;
 }
开发者ID:cesium147,项目名称:redbean,代码行数:61,代码来源:AssociationManager.php

示例11: check

 /**
  * Checks whether a OODBBean bean is valid.
  * If the type is not valid or the ID is not valid it will
  * throw an exception: Security.
  *
  * @param OODBBean $bean the bean that needs to be checked
  *
  * @return void
  *
  * @throws Security $exception
  */
 public function check(OODBBean $bean)
 {
     //Is all meta information present?
     if (!isset($bean->id)) {
         throw new RedException('Bean has incomplete Meta Information id ');
     }
     if (!$bean->getMeta('type')) {
         throw new RedException('Bean has incomplete Meta Information II');
     }
     //Pattern of allowed characters
     $pattern = '/[^a-z0-9_]/i';
     //Does the type contain invalid characters?
     if (preg_match($pattern, $bean->getMeta('type'))) {
         throw new RedException('Bean Type is invalid');
     }
     //Are the properties and values valid?
     foreach ($bean as $prop => $value) {
         if (is_array($value) || is_object($value)) {
             throw new RedException("Invalid Bean value: property {$prop}");
         } else {
             if (strlen($prop) < 1 || preg_match($pattern, $prop)) {
                 throw new RedException("Invalid Bean property: property {$prop}");
             }
         }
     }
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:37,代码来源:Repository.php

示例12: 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('tainted')) {
         $this->check($bean);
         $table = $bean->getMeta('type');
         $this->createTableIfNotExists($bean, $table);
         $updateValues = $this->getUpdateValues($bean);
         $this->addUniqueConstraints($bean);
         $bean->id = $this->writer->updateRecord($table, $updateValues, $bean->id);
         $bean->setMeta('tainted', FALSE);
     }
 }
开发者ID:cesium147,项目名称:redbean,代码行数:22,代码来源:Fluid.php

示例13: inTrailOrAdd

 /**
  * Generates a key from the bean type and its ID and determines if the bean
  * occurs in the trail, if not the bean will be added to the trail.
  * Returns TRUE if the bean occurs in the trail and FALSE otherwise.
  *
  * @param array    $trail list of former beans
  * @param OODBBean $bean  currently selected bean
  *
  * @return boolean
  */
 private function inTrailOrAdd(&$trail, OODBBean $bean)
 {
     $type = $bean->getMeta('type');
     $key = $type . $bean->getID();
     if (isset($trail[$key])) {
         return TRUE;
     }
     $trail[$key] = $bean;
     return FALSE;
 }
开发者ID:up9cloud,项目名称:redbean,代码行数:20,代码来源:DuplicationManager.php

示例14: processAdditions

 /**
  * Part of the store() functionality.
  * Handles all new additions after the bean has been saved.
  * Stores addition bean in own-list, extracts the id and
  * adds a foreign key. Also adds a constraint in case the type is
  * in the dependent list.
  *
  * @param OODBBean $bean         bean
  * @param array            $ownAdditions list of addition beans in own-list
  *
  * @return void
  *
  * @throws Security
  */
 protected function processAdditions($bean, $ownAdditions)
 {
     $beanType = $bean->getMeta('type');
     $cachedIndex = array();
     foreach ($ownAdditions as $addition) {
         if ($addition instanceof OODBBean) {
             $myFieldLink = $beanType . '_id';
             $alias = $bean->getMeta('sys.alias.' . $addition->getMeta('type'));
             if ($alias) {
                 $myFieldLink = $alias . '_id';
             }
             $addition->{$myFieldLink} = $bean->id;
             $addition->setMeta('cast.' . $myFieldLink, 'id');
             $this->store($addition);
         } else {
             throw new RedException('Array may only contain OODBBeans');
         }
     }
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:33,代码来源:Frozen.php

示例15: saveBean

 /**
  * Insert or Update a bean
  *
  * @param OODBBean $bean
  * @param $data array
  * @return Result
  */
 private function saveBean($bean, $data)
 {
     // Handle File Field that may not in the $data, because Filename always go into $_FILES.
     foreach ($_FILES as $fieldName => $file) {
         $data[$fieldName] = $file["name"];
     }
     // Store Showing fields only
     $fields = $this->getShowFields();
     foreach ($fields as $field) {
         // Check is unique
         if ($field->isUnique()) {
             // Try to find duplicate beans
             $fieldName = $field->getName();
             $duplicateBeans = R::find($bean->getMeta('type'), " {$fieldName} = ? ", [$data[$field->getName()]]);
             if (count($duplicateBeans) > 0) {
                 $validateResult = "Email 已存在!";
             }
         }
         if ($field->getFieldRelation() == Field::MANY_TO_MANY) {
             // 1. Many to many
             // http://www.redbeanphp.com/many_to_many
             $keyName = "shared" . ucfirst($field->getName()) . "List";
             // Clear the current list (tableB_tableA)
             try {
                 $tableName = $this->getTableName() . "_" . $field->getName();
                 $idName = $this->getTableName() . "_id";
                 R::exec("DELETE FROM {$tableName} WHERE {$idName} = ?", [$bean->id]);
             } catch (\Exception $ex) {
             }
             // Clear the current list (tableA_tableB)
             try {
                 $tableName = $field->getName() . "_" . $this->getTableName();
                 $idName = $this->getTableName() . "_id";
                 R::exec("DELETE FROM {$tableName} WHERE {$idName} = ?", [$bean->id]);
             } catch (\Exception $ex) {
             }
             // If User have checked a value in checkbox
             if (isset($data[$field->getName()])) {
                 $valueList = $data[$field->getName()];
                 $slots = R::genSlots($valueList);
                 $relatedBeans = R::find($field->getName(), " id IN ({$slots})", $valueList);
                 foreach ($relatedBeans as $relatedBean) {
                     $bean->{$keyName}[] = $relatedBean;
                 }
             }
         } else {
             if ($field->getFieldRelation() == Field::ONE_TO_MANY) {
                 // TODO One to many
             } else {
                 if (!$field->isStorable()) {
                     // 2. If not storable, skip
                     continue;
                 } elseif ($field->getFieldRelation() == Field::NORMAL) {
                     // 3.Normal data field
                     $value = $field->getStoreValue($data);
                     if ($value == LouisCRUD::NULL) {
                         $value = null;
                     }
                     // Validate the value
                     if ($field->isStorable()) {
                         $validateResult = $field->validate($value, $data);
                     } else {
                         // TODO: check non-storable?
                         $validateResult = true;
                     }
                     // If validate failed, return result object.
                     if ($validateResult !== true) {
                         $result = new Result();
                         $result->id = @$bean->id;
                         $result->msg = $validateResult;
                         $result->fieldName = $field->getName();
                         $result->class = "callout-danger";
                         return $result;
                     }
                     // Set the value to the current bean directly
                     $bean->{$field->getName()} = $value;
                 }
             }
         }
     }
     // Store
     // TODO: Return result object
     $id = R::store($bean);
     $result = new Result();
     $result->id = $id;
     return $result;
 }
开发者ID:louislam,项目名称:louislam-crud,代码行数:94,代码来源:LouisCRUD.php


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