本文整理汇总了PHP中RedBean_OODBBean类的典型用法代码示例。如果您正苦于以下问题:PHP RedBean_OODBBean类的具体用法?PHP RedBean_OODBBean怎么用?PHP RedBean_OODBBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RedBean_OODBBean类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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;
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:7,代码来源:ZurmoRedBeanLinkManager.php
示例3: onEvent
/**
* Throws an exception if information in the bean has been changed
* by another process or bean. This is actually the same as journaling
* using timestamps however with timestamps you risk race conditions
* when the measurements are not fine-grained enough; with
* auto-incremented primary key ids we dont have this risk.
* @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);
}
if ($event == "update" || $event == "delete") {
if ($item->getMeta("opened")) {
$oldid = $item->getMeta("opened");
} else {
$oldid = 0;
}
$newid = $this->checkChanges($type, $id, $oldid);
$item->setMeta("opened", $newid);
}
}
开发者ID:surfnjunkie,项目名称:redbean,代码行数:35,代码来源:ChangeLogger.php
示例4: 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
示例5: 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;
}
开发者ID:surfnjunkie,项目名称:redbean,代码行数:67,代码来源:Constraint.php
示例6: 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);
}
开发者ID:nurulimamnotes,项目名称:DewiSriDesktop,代码行数:14,代码来源:TreeManager.php
示例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;
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:9,代码来源:ZurmoRedBeanLinkManager.php
示例8: boxIfModel
private function boxIfModel(\RedBean_OODBBean $bean)
{
$model = $bean->box();
if (!$model instanceof Model) {
return $bean;
}
$model->bindApp($this->app);
return $model;
}
开发者ID:neemzy,项目名称:redbean-service-provider,代码行数:9,代码来源:Instance.php
示例9: 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);
}
开发者ID:jgosier,项目名称:ushahidi_swift,代码行数:16,代码来源:TreeManager.php
示例10: 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 RedBean_OODBBean();
$bean->getID();
restore_error_handler();
pass();
}
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:15,代码来源:Misc.php
示例11: 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
示例12: 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 RedBean_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:daviddeutsch,项目名称:redbean-adaptive,代码行数:51,代码来源:Import.php
示例13: getAlias
/**
* Returns the alias for a type
*
* @param $type aliased type
*
* @return string $type type
*/
public function getAlias($type)
{
if ($t = RedBean_OODBBean::$fetchType) {
$type = $t;
RedBean_OODBBean::$fetchType = null;
}
return $type;
}
开发者ID:ryjkov,项目名称:redbean,代码行数:15,代码来源:DefaultBeanFormatter.php
示例14: 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} ");
}
}
}
开发者ID:nurulimamnotes,项目名称:DewiSriDesktop,代码行数:23,代码来源:OODB.php
示例15: 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");
}
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:28,代码来源:Meta.php
示例16: 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);
}
开发者ID:nurulimamnotes,项目名称:DewiSriDesktop,代码行数:29,代码来源:TreeManager.php
示例17: testKeywords
/**
* Test if RedBeanPHP can properly handle keywords.
*
* @return void
*/
public function testKeywords()
{
$keywords = array('anokeyword', 'znokeyword', 'group', 'DROP', 'inner', 'JOIN', 'select', 'table', 'int', 'cascade', 'float', 'CALL', 'in', 'status', 'order', 'limit', 'having', 'else', 'if', 'while', 'distinct', 'like');
R::setStrictTyping(FALSE);
RedBean_OODBBean::setFlagBeautifulColumnNames(FALSE);
foreach ($keywords as $k) {
R::nuke();
$bean = R::dispense($k);
$bean->{$k} = $k;
$id = R::store($bean);
$bean = R::load($k, $id);
$bean2 = R::dispense('other');
$bean2->name = $k;
$bean->bean = $bean2;
$bean->ownBean[] = $bean2;
$bean->sharedBean[] = $bean2;
$id = R::store($bean);
R::trash($bean);
pass();
}
RedBean_OODBBean::setFlagBeautifulColumnNames(TRUE);
R::setStrictTyping(TRUE);
}
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:28,代码来源:Keywords.php
示例18: 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 RedBean_OODBBean $bean currently selected bean
*
* @return boolean
*/
private function inTrailOrAdd(&$trail, RedBean_OODBBean $bean)
{
$type = $bean->getMeta('type');
$key = $type . $bean->getID();
if (isset($trail[$key])) {
return TRUE;
}
$trail[$key] = $bean;
return FALSE;
}
开发者ID:abhikalotra,项目名称:Samples1,代码行数:20,代码来源:rb.php
示例19: set1toNAssoc
/**
* Creates a 1 to Many Association
* If the association fails it throws an exception.
* @throws RedBean_Exception_SQL $failedToEnforce1toN
* @param RedBean_OODBBean $bean1
* @param RedBean_OODBBean $bean2
* @return RedBean_AssociationManager $chainable
*/
public function set1toNAssoc(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2)
{
$type = $bean1->getMeta("type");
$this->clearRelations($bean2, $type);
$this->associate($bean1, $bean2);
if (count($this->related($bean2, $type)) === 1) {
return $this;
} else {
throw new RedBean_Exception_SQL("Failed to enforce 1toN Relation for {$type} ");
}
}
开发者ID:surfnjunkie,项目名称:redbean,代码行数:19,代码来源:AssociationManager.php
示例20: array
$default_config['default_sql_limit'] = array(0, 25);
$default_config['rate_limit'] = 100;
$config = array_merge($default_config, $config);
if (file_exists('config.php.default') && $config['debug'] === false) {
die('Please remove the config.php.default.');
}
require_once 'utils.php';
/* make sure admin pass has changed */
if ($config['password'] === 'admin') {
die('Change the password in config.php');
}
/* setup database */
use RedBean_Facade as R;
R::setup($config['db_conn'], $config['db_user'], $config['db_pass']);
R::$writer->setUseCache(false);
RedBean_OODBBean::setFlagBeautifulColumnNames(false);
/* app start */
if ($config['debug'] === false) {
ini_set('display_errors', '0');
}
$app = new \Slim\Slim(array('debug' => $config['debug'], 'templates.path' => 'templates'));
/* Middlewares */
$r = new Util($app);
/* load hooks */
$r->loadHooks();
function API()
{
$app = \Slim\Slim::getInstance();
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
$app->response->headers->set('Content-Type', 'application/json');
开发者ID:zulfajuniadi,项目名称:php-rest-server,代码行数:31,代码来源:index.php
注:本文中的RedBean_OODBBean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论