本文整理汇总了PHP中R::inspect方法的典型用法代码示例。如果您正苦于以下问题:PHP R::inspect方法的具体用法?PHP R::inspect怎么用?PHP R::inspect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::inspect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInspect
/**
* Tests the R::inspect() method on the Facade.
*
* @return void
*/
public function testInspect()
{
testpack('Test R::inspect() ');
R::nuke();
R::store(R::graph(array('type' => 'book', 'title' => 'book')));
$info = R::inspect();
asrt(count($info), 1);
asrt(strtolower($info[0]), 'book');
$info = R::inspect('book');
asrt(count($info), 2);
$keys = array_keys($info);
sort($keys);
asrt(strtolower($keys[0]), 'id');
asrt(strtolower($keys[1]), 'title');
}
示例2: updateEntityWithArray
/**
* @param String Entity name 'territory', 'building', 'person', etc.
* @param Numeric Id of entity to compare against in db
* @param Array Array of form data. Single item, not nested.
* @return Object RedBean entity
*/
function updateEntityWithArray($type, $id, $array)
{
// New up the entity
$entity = R::load($type, $id);
// Get changed data only
$differences = array_diff_assoc($array, $entity->export());
// get valid field names
$fieldnames = R::inspect($type);
// find the valid fields from updaed values and valid fieldnames
$valid_fields = array_intersect_key($fieldnames, $differences);
// only iterate over valid fields that are also updated.
foreach ($valid_fields as $key => $value) {
$entity[$key] = trim($array[$key]);
}
return $entity;
}
示例3: testGetAllCols
public static function testGetAllCols()
{
return $fields = R::inspect('user');
}
示例4: testUpdatingParentBeansWithAliases
/**
* Tests whether we can update or unset a parent bean
* with an alias without having to use fetchAs and
* without loading the aliased bean causing table-not-found
* errors.
*/
public function testUpdatingParentBeansWithAliases()
{
testpack('Test updating parent beans with aliases');
R::nuke();
$trans = R::dispense('transaction');
$seller = R::dispense('user');
$trans->seller = $seller;
$id = R::store($trans);
R::freeze(true);
$trans = R::load('transaction', $id);
//should not try to load seller, should not require fetchAs().
try {
$trans->seller = R::dispense('user');
pass();
} catch (Exception $e) {
fail();
}
$trans = R::load('transaction', $id);
//same for unset...
try {
unset($trans->seller);
pass();
} catch (Exception $e) {
fail();
}
R::freeze(false);
$account = R::dispense('user');
asrt(count($account->alias('seller')->ownTransaction), 0);
$account->alias('seller')->ownTransaction = R::dispense('transaction', 10);
$account->alias('boo');
//try to trick me...
$id = R::store($account);
R::freeze(true);
$account = R::load('user', $id);
asrt(count($account->alias('seller')->ownTransaction), 10);
//you cannot unset a list
unset($account->alias('seller')->ownTransaction);
$id = R::store($account);
$account = R::load('user', $id);
asrt(count($account->alias('seller')->ownTransaction), 10);
$account->alias('seller')->ownTransaction = array();
$id = R::store($account);
$account = R::load('user', $id);
asrt(count($account->alias('seller')->ownTransaction), 0);
asrt(count($account->ownTransaction), 0);
R::freeze(false);
//but also make sure we don't cause extra column issue #335
R::nuke();
$building = R::dispense('building');
$village = R::dispense('village');
$building->village = $village;
R::store($building);
$building = $building->fresh();
$building->village = NULL;
R::store($building);
$building = $building->fresh();
$columns = R::inspect('building');
asrt(isset($columns['village']), false);
asrt(isset($building->village), false);
R::nuke();
$building = R::dispense('building');
$village = R::dispense('village');
$building->village = $village;
R::store($building);
$building = $building->fresh();
unset($building->village);
R::store($building);
$building = $building->fresh();
$columns = R::inspect('building');
asrt(isset($columns['village']), false);
asrt(isset($building->village), false);
$building = R::dispense('building');
$village = R::dispense('village');
$building->village = $village;
R::store($building);
$building = $building->fresh();
$building->village = false;
R::store($building);
$building = $building->fresh();
$columns = R::inspect('building');
asrt(isset($columns['village']), false);
asrt(isset($building->village), false);
}
示例5: filter
public static function filter($table, $info)
{
if (false !== ($list = R::inspect($type))) {
$fields = array();
foreach ($list as $key => $record) {
$fields[] = $key;
}
return array_values(array_intersect($fields, array_keys($info)));
}
return array();
}
示例6: tableExists
public function tableExists($table)
{
try {
\R::inspect($table);
return true;
} catch (\exception $e) {
return false;
}
}
示例7:
<?php
require_once 'rb.phar';
$path = __DIR__;
$phpfile = '';
$asfile = '';
R::setup('mysql:host=localhost;port=3306;dbname=test', 'root', '');
$table = 'users';
$cols = R::inspect($table);
$phpfilename = $path . '/users.php';
echo '<?php ', "\r\n\r\n";
$phpfile .= '<?php ' . "\r\n\r\n";
echo 'class Users {', "\r\n";
$phpfile .= 'class Users {' . "\r\n";
foreach ($cols as $key => $value) {
echo "\t\t\t\t", 'public $' . $key, ";\r\n";
$phpfile .= "\t" . 'public $' . $key . ";\r\n";
}
echo " } \r\n\r\n ?>\r\n\r\n";
$phpfile .= " } \r\n\r\n ?>\r\n\r\n";
file_put_contents($phpfilename, $phpfile);
$asfilename = $path . '/Users.as';
echo "package vo\r\n";
$asfile .= "package vo\r\n";
echo "{\r\n";
$asfile .= "{\r\n";
echo ' [RemoteClass(alias="Users")]', "\r\n";
$asfile .= ' [RemoteClass(alias="Users")]' . "\r\n";
echo " [Bindable]\r\n";
$asfile .= " [Bindable]\r\n";
echo " public class Users\r\n";