本文整理汇总了PHP中RedBean_OODBBean::getMeta方法的典型用法代码示例。如果您正苦于以下问题:PHP RedBean_OODBBean::getMeta方法的具体用法?PHP RedBean_OODBBean::getMeta怎么用?PHP RedBean_OODBBean::getMeta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBean_OODBBean
的用法示例。
在下文中一共展示了RedBean_OODBBean::getMeta方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEvent
/**
* Throws an exception if information in the bean has been changed
* by another process or bean.
* @param string $event
* @param RedBean_OODBBean $item
*/
public function onEvent($event, $item)
{
$id = $item->id;
if (!(int) $id) {
$event = "open";
}
$type = $item->getMeta("type");
if ($event == "open") {
if (isset($this->stash[$id])) {
$insertid = $this->stash[$id];
unset($this->stash[$id]);
return $insertid;
}
$insertid = $this->writer->insertRecord("__log", array("action", "tbl", "itemid"), array(array(1, $type, $id)));
$item->setMeta("opened", $insertid);
//echo "<br>opened: ".print_r($item, 1);
}
if ($event == "update" || $event == "delete") {
if ($item->getMeta("opened")) {
$oldid = $item->getMeta("opened");
} else {
$oldid = 0;
}
$newid = $this->writer->checkChanges($type, $id, $oldid);
$item->setMeta("opened", $newid);
}
}
示例2: addConstraint
/**
* Ensures that given an association between
* $bean1 and $bean2,
* if one of them gets trashed the association will be
* automatically removed.
* @param RedBean_OODBBean $bean1
* @param RedBean_OODBBean $bean2
* @return boolean $addedFKS
*/
public static function addConstraint(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, $dontCache = false)
{
//Fetch the toolbox
$toolbox = RedBean_Setup::getToolBox();
RedBean_CompatManager::scanDirect($toolbox, array(RedBean_CompatManager::C_SYSTEM_MYSQL => "5"));
//Create an association manager
$association = new RedBean_AssociationManager($toolbox);
$writer = $toolbox->getWriter();
$oodb = $toolbox->getRedBean();
$adapter = $toolbox->getDatabaseAdapter();
//Frozen? Then we may not alter the schema!
if ($oodb->isFrozen()) {
return false;
}
//$adapter->getDatabase()->setDebugMode(1);
$table1 = $bean1->getMeta("type");
$table2 = $bean2->getMeta("type");
$table = $association->getTable(array($table1, $table2));
$idfield1 = $writer->getIDField($bean1->getMeta("type"));
$idfield2 = $writer->getIDField($bean2->getMeta("type"));
$bean = $oodb->dispense($table);
$property1 = $bean1->getMeta("type") . "_id";
$property2 = $bean2->getMeta("type") . "_id";
if ($property1 == $property2) {
$property2 = $bean2->getMeta("type") . "2_id";
}
$table = $adapter->escape($table);
$table1 = $adapter->escape($table1);
$table2 = $adapter->escape($table2);
$property1 = $adapter->escape($property1);
$property2 = $adapter->escape($property2);
//In Cache? Then we dont need to bother
if (isset(self::$fkcache[$table])) {
return false;
}
$db = $adapter->getCell("select database()");
$fks = $adapter->getCell("\n\t\t\tSELECT count(*)\n\t\t\tFROM information_schema.KEY_COLUMN_USAGE\n\t\t\tWHERE TABLE_SCHEMA ='{$db}' AND TABLE_NAME ='{$table}' AND\n\t\t\tCONSTRAINT_NAME <>'PRIMARY' AND REFERENCED_TABLE_NAME is not null\n\t\t");
//already foreign keys added in this association table
if ($fks > 0) {
return false;
}
//add the table to the cache, so we dont have to fire the fk query all the time.
if (!$dontCache) {
self::$fkcache[$table] = true;
}
$columns = $writer->getColumns($table);
if ($writer->code($columns[$property1]) !== RedBean_QueryWriter_MySQL::C_DATATYPE_UINT32) {
$writer->widenColumn($table, $property1, RedBean_QueryWriter_MySQL::C_DATATYPE_UINT32);
}
if ($writer->code($columns[$property2]) !== RedBean_QueryWriter_MySQL::C_DATATYPE_UINT32) {
$writer->widenColumn($table, $property2, RedBean_QueryWriter_MySQL::C_DATATYPE_UINT32);
}
$sql = "\n\t\t\tALTER TABLE " . $writer->noKW($table) . "\n\t\t\tADD FOREIGN KEY({$property1}) references {$table1}(id) ON DELETE CASCADE;\n\n\t\t";
$adapter->exec($sql);
$sql = "\n\t\t\tALTER TABLE " . $writer->noKW($table) . "\n\t\t\tADD FOREIGN KEY({$property2}) references {$table2}(id) ON DELETE CASCADE\n\t\t";
$adapter->exec($sql);
return true;
}
示例3: children
/**
*
* @param RedBean_OODBBean $parent
* @return array $childObjects
*/
public function children(RedBean_OODBBean $parent)
{
try {
$ids = $this->adapter->getCol("SELECT id FROM\n\t\t\t`" . $parent->getMeta("type") . "`\n\t\t\tWHERE `" . $this->property . "` = " . intval($parent->id) . "\n\t\t");
} catch (RedBean_Exception_SQL $e) {
return array();
}
return $this->oodb->batch($parent->getMeta("type"), $ids);
}
示例4: children
/**
* Returns all the nodes that have been attached to the specified
* parent node.
* @param RedBean_OODBBean $parent
* @return array $childObjects
*/
public function children(RedBean_OODBBean $parent)
{
$idfield = $this->writer->getIDField($parent->getMeta("type"));
try {
$ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield}));
} catch (RedBean_Exception_SQL $e) {
return array();
}
return $this->oodb->batch($parent->getMeta("type"), $ids);
}
示例5: getKeys
public static function getKeys(RedBean_OODBBean $bean, $typeName)
{
$fieldName = self::getLinkField($typeName);
$id = (int) $bean->{$fieldName};
$ids = R::getCol("select id from {$typeName} where " . $bean->getMeta("type") . "_id" . " = {$bean->id}");
return $ids;
}
示例6: 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..
}
}
示例7: getKeys
public static function getKeys(RedBean_OODBBean $bean, $typeName, $name = null)
{
$fieldName = self::getLinkField($typeName, $name);
$id = (int) $bean->{$fieldName};
$columnPrefix = self::resolveColumnPrefix($name);
$columnName = $columnPrefix . $bean->getMeta("type") . '_id';
$ids = ZurmoRedBean::getCol("select id from {$typeName} where " . $columnName . " = {$bean->id}");
return $ids;
}
示例8: check
/**
* Checks whether a bean is valid
* @param RedBean_OODBBean $bean
*/
public function check(RedBean_OODBBean $bean)
{
//Is all meta information present?
if (!isset($bean->id) || !$bean->getMeta("type")) {
throw new RedBean_Exception_Security("Bean has incomplete Meta Information");
}
//Pattern of allowed characters
$pattern = '/[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]/';
//Does the type contain invalid characters?
if (preg_match($pattern, $bean->getMeta("type"))) {
throw new RedBean_Exception_Security("Bean Type is invalid");
}
//Are the properties and values valid?
foreach ($bean as $prop => $value) {
if (is_array($value) || is_object($value) || strlen($prop) < 1 || preg_match($pattern, $prop)) {
throw new RedBean_Exception_Security("Invalid Bean: property {$prop} ");
}
}
}
示例9: 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>";
}
}
示例10: testMetaData
/**
* Test meta data methods.
*
* @return void
*/
public function testMetaData()
{
testpack('Test meta data');
$bean = new RedBean_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 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");
}
示例11: children
/**
*
* @param RedBean_OODBBean $parent
* @return array $childObjects
*/
public function children(RedBean_OODBBean $parent)
{
$idfield = $this->writer->getIDField($parent->getMeta("type"));
try {
/*
$ids = $this->adapter->getCol("SELECT `".$idfield."` FROM
`".$parent->getMeta("type")."`
WHERE `".$this->property."` = ".intval( $parent->$idfield )."
");
*/
/*
$ids = $this->adapter->getCol($this->writer->buildSimpleQuery(
"select",array($idfield),$parent->getMeta("type"),
array("name"=>$this->property,
"value"=>intval($parent->$idfield),
"operator"=>"=","structure"=>"")
));
*/
$ids = $this->writer->selectByCrit($idfield, $parent->getMeta("type"), $this->property, intval($parent->{$idfield}));
} catch (RedBean_Exception_SQL $e) {
return array();
}
return $this->oodb->batch($parent->getMeta("type"), $ids);
}
示例12: find
/**
* Loads the Bean internally
* @param integer $id
*/
public function find($id)
{
$this->bean = $this->redbean->load($this->bean->getMeta("type"), (int) $id);
}
示例13: trash
/**
* Removes a bean from the database.
* This function will remove the specified RedBean_OODBBean
* Bean Object from the database.
* @throws RedBean_Exception_Security $exception
* @param RedBean_OODBBean $bean
*/
public function trash(RedBean_OODBBean $bean)
{
$idfield = $this->writer->getIDField($bean->getMeta("type"));
$this->signal("delete", $bean);
$this->check($bean);
try {
$this->writer->deleteRecord($bean->getMeta("type"), $bean->{$idfield});
} catch (RedBean_Exception_SQL $e) {
if ($e->getSQLState() != "42S02" && $e->getSQLState() != "42S22") {
throw $e;
}
}
}
示例14: addConstraint
/**
* Adds a constraint. If one of the beans gets trashed
* the other, related bean should be removed as well.
*
* @param RedBean_OODBBean $bean1 first bean
* @param RedBean_OODBBean $bean2 second bean
* @param bool $dontCache by default we use a cache, TRUE = NO CACHING (optional)
*
* @return void
*/
public function addConstraint(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, $dontCache = false)
{
$table1 = $bean1->getMeta("type");
$table2 = $bean2->getMeta("type");
$writer = $this;
$adapter = $this->adapter;
$table = $this->getAssocTableFormat(array($table1, $table2));
$idfield1 = $writer->getIDField($bean1->getMeta("type"));
$idfield2 = $writer->getIDField($bean2->getMeta("type"));
$property1 = $bean1->getMeta("type") . "_id";
$property2 = $bean2->getMeta("type") . "_id";
if ($property1 == $property2) {
$property2 = $bean2->getMeta("type") . "2_id";
}
$table = $adapter->escape($table);
$table1 = $adapter->escape($table1);
$table2 = $adapter->escape($table2);
$property1 = $adapter->escape($property1);
$property2 = $adapter->escape($property2);
//In Cache? Then we dont need to bother
$fkCode = "fk" . md5($table . $property1 . $property2);
if (isset($this->fkcache[$fkCode])) {
return false;
}
//Dispatch to right method
try {
return $this->constrain($table, $table1, $table2, $property1, $property2, $dontCache);
} catch (RedBean_Exception_SQL $e) {
if (!$writer->sqlStateIn($e->getSQLState(), array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) {
throw $e;
}
}
return false;
}
示例15: extAssociate
public function extAssociate(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, RedBean_OODBBean $baseBean)
{
$table = $this->getTable(array($bean1->getMeta("type"), $bean2->getMeta("type")));
$baseBean->setMeta("type", $table);
return $this->associateBeans($bean1, $bean2, $baseBean);
}