本文整理汇总了PHP中RedBeanPHP\Facade::debug方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::debug方法的具体用法?PHP Facade::debug怎么用?PHP Facade::debug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::debug方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExplicitCacheFlush
/**
* Test explicit flush.
*
* @return void
*/
public function testExplicitCacheFlush()
{
testpack('Test cache flush (explicit)');
R::debug(true, 1);
$logger = R::getDatabaseAdapter()->getDatabase()->getLogger();
$bean = R::dispense('bean');
$bean->title = 'abc';
$id1 = R::store($bean);
$logger->clear();
$bean = R::load('bean', $id1);
asrt($bean->title, 'abc');
asrt(count($logger->grep('SELECT *')), 1);
$bean = R::load('bean', $id1);
asrt(count($logger->grep('SELECT *')), 1);
R::getWriter()->flushCache();
$bean = R::load('bean', $id1);
asrt(count($logger->grep('SELECT *')), 2);
R::getWriter()->flushCache();
R::getWriter()->setUseCache(FALSE);
}
示例2: testFullSupport
/**
* Test Full fluid UUID support.
*
*/
public function testFullSupport()
{
//Rewire objects to support UUIDs.
$oldToolBox = R::getToolBox();
$oldAdapter = $oldToolBox->getDatabaseAdapter();
$uuidWriter = new \UUIDWriterPostgres($oldAdapter);
$newRedBean = new OODB($uuidWriter);
$newToolBox = new ToolBox($newRedBean, $oldAdapter, $uuidWriter);
R::configureFacadeWithToolbox($newToolBox);
list($mansion, $rooms, $ghosts, $key) = R::dispenseAll('mansion,room*3,ghost*4,key');
$mansion->name = 'Haunted Mansion';
$mansion->xownRoomList = $rooms;
$rooms[0]->name = 'Green Room';
$rooms[1]->name = 'Red Room';
$rooms[2]->name = 'Blue Room';
$ghosts[0]->name = 'zero';
$ghosts[1]->name = 'one';
$ghosts[2]->name = 'two';
$ghosts[3]->name = 'three';
$rooms[0]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[1]);
$rooms[1]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[2]);
$rooms[2]->noLoad()->sharedGhostList = array($ghosts[1], $ghosts[3], $ghosts[2]);
$rooms[2]->xownKey = array($key);
//Can we store a bean hierachy with UUIDs?
R::debug(1);
$id = R::store($mansion);
//exit;
asrt(is_string($id), TRUE);
asrt(strlen($id), 36);
$haunted = R::load('mansion', $id);
asrt($haunted->name, 'Haunted Mansion');
asrt(is_string($haunted->id), TRUE);
asrt(strlen($haunted->id), 36);
asrt(is_array($haunted->xownRoomList), TRUE);
asrt(count($haunted->ownRoom), 3);
$rooms = $haunted->xownRoomList;
//Do some counting...
$greenRoom = NULL;
foreach ($rooms as $room) {
if ($room->name === 'Green Room') {
$greenRoom = $room;
break;
}
}
asrt(!is_null($greenRoom), TRUE);
asrt(is_array($greenRoom->with(' ORDER BY id ')->sharedGhostList), TRUE);
asrt(count($greenRoom->sharedGhostList), 2);
$names = array();
foreach ($greenRoom->sharedGhost as $ghost) {
$names[] = $ghost->name;
}
sort($names);
$names = implode(',', $names);
asrt($names, 'one,zero');
$rooms = $haunted->xownRoomList;
$blueRoom = NULL;
foreach ($rooms as $room) {
if ($room->name === 'Blue Room') {
$blueRoom = $room;
break;
}
}
asrt(!is_null($blueRoom), TRUE);
asrt(is_array($blueRoom->sharedGhostList), TRUE);
asrt(count($blueRoom->sharedGhostList), 3);
$names = array();
foreach ($blueRoom->sharedGhost as $ghost) {
$names[] = $ghost->name;
}
sort($names);
$names = implode(',', $names);
asrt($names, 'one,three,two');
$rooms = $haunted->xownRoomList;
$redRoom = NULL;
foreach ($rooms as $room) {
if ($room->name === 'Red Room') {
$redRoom = $room;
break;
}
}
$names = array();
foreach ($redRoom->sharedGhost as $ghost) {
$names[] = $ghost->name;
}
sort($names);
$names = implode(',', $names);
asrt($names, 'two,zero');
asrt(!is_null($redRoom), TRUE);
asrt(is_array($redRoom->sharedGhostList), TRUE);
asrt(count($redRoom->sharedGhostList), 2);
//Can we repaint a room?
$redRoom->name = 'Yellow Room';
$id = R::store($redRoom);
$yellowRoom = R::load('room', $id);
asrt($yellowRoom->name, 'Yellow Room');
asrt(!is_null($yellowRoom), TRUE);
//.........这里部分代码省略.........
示例3: prepare
/**
* Prepare test pack (mostly: nuke the entire database)
*/
public function prepare()
{
R::freeze(FALSE);
R::debug(FALSE);
R::nuke();
}
示例4: testTransactionInFacade
/**
* Test Facade transactions.
*
* @return void
*
* @throws\Exception
*/
public function testTransactionInFacade()
{
testpack('Test transaction in facade');
$bean = R::dispense('bean');
$bean->name = 'a';
R::store($bean);
R::trash($bean);
R::freeze(TRUE);
$bean = R::dispense('bean');
$bean->name = 'a';
R::store($bean);
asrt(R::count('bean'), 1);
R::trash($bean);
asrt(R::count('bean'), 0);
$bean = R::dispense('bean');
$bean->name = 'a';
$id = R::transaction(function () use(&$bean) {
return R::transaction(function () use(&$bean) {
return R::store($bean);
});
});
asrt((int) $id, (int) $bean->id);
R::trash($bean);
$bean = R::dispense('bean');
$bean->name = 'a';
$id = R::transaction(function () use(&$bean) {
return R::store($bean);
});
asrt((int) $id, (int) $bean->id);
R::trash($bean);
$bean = R::dispense('bean');
$bean->name = 'a';
try {
R::transaction(function () use($bean) {
R::store($bean);
R::transaction(function () {
throw new \Exception();
});
});
} catch (\Exception $e) {
pass();
}
asrt(R::count('bean'), 0);
$bean = R::dispense('bean');
$bean->name = 'a';
try {
R::transaction(function () use($bean) {
R::transaction(function () use($bean) {
R::store($bean);
throw new \Exception();
});
});
} catch (\Exception $e) {
pass();
}
asrt(R::count('bean'), 0);
$bean = R::dispense('bean');
$bean->name = 'a';
try {
R::transaction(function () use($bean) {
R::transaction(function () use($bean) {
R::store($bean);
});
});
} catch (\Exception $e) {
pass();
}
asrt(R::count('bean'), 1);
R::freeze(FALSE);
try {
R::transaction('nope');
fail();
} catch (\Exception $e) {
pass();
}
testpack('Test Camelcase 2 underscore');
$names = array('oneACLRoute' => 'one_acl_route', 'ALLUPPERCASE' => 'alluppercase', 'clientServerArchitecture' => 'client_server_architecture', 'camelCase' => 'camel_case', 'peer2peer' => 'peer2peer', 'fromUs4You' => 'from_us4_you', 'lowercase' => 'lowercase', 'a1A2b' => 'a1a2b');
$bean = R::dispense('bean');
foreach ($names as $name => $becomes) {
$bean->{$name} = 1;
asrt(isset($bean->{$becomes}), TRUE);
}
testpack('Misc Tests');
R::debug(1);
flush();
ob_start();
R::exec('SELECT 123');
$out = ob_get_contents();
ob_end_clean();
flush();
pass();
asrt(strpos($out, 'SELECT 123') !== FALSE, TRUE);
R::debug(0);
//.........这里部分代码省略.........
示例5: testUpdateQueries
/**
* Test whether the number of update queries
* executed is limited to the ones that are absolutely
* necessary to sync the database.
*
* @return void
*/
public function testUpdateQueries()
{
$book = R::dispense('book');
$book->title = 'Eye of Wight';
$book->xownPageList = R::dispense('page', 10);
$book->sharedCategoryList = R::dispense('category', 2);
$n = 1;
foreach ($book->xownPageList as $page) {
$page->number = $n++;
}
$book->sharedCategory[0]->name = 'adventure';
$book->sharedCategory[1]->name = 'puzzle';
$book->author = R::dispense('author');
$book->author->name = 'John';
$book->map = R::dispense('map');
$book->map->name = 'Wight';
$book->map->xownLocationList = R::dispense('location', 3);
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), TRUE);
R::store($book);
asrt($book->getMeta('tainted'), FALSE);
asrt($book->getMeta('changed'), FALSE);
$logger = R::debug(1, 1);
$book = $book->fresh();
asrt($book->getMeta('tainted'), FALSE);
asrt($book->getMeta('changed'), FALSE);
$book->author;
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
$logger->clear();
R::store($book);
//read only, no updates
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$book->title = 'Spirit of the Stones';
R::store($book);
//changed title, 1 update
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 1);
$logger->clear();
//store again, no changes, no updates
R::store($book);
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$logger->clear();
$book = $book->fresh();
$book->xownPageList;
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
R::store($book);
//access only, no update
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$logger->clear();
$book = $book->fresh();
$book->sharedCategoryList;
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
R::store($book);
//access only, no update
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$logger->clear();
$book = $book->fresh();
unset($book->xownPageList[5]);
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
R::store($book);
//remove only, no update, just 1 delete
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$numberOfUpdateQueries = $logger->grep('DELETE');
asrt(count($numberOfUpdateQueries), 1);
$book = $book->fresh();
asrt(count($book->xownPageList), 9);
$logger->clear();
$book = $book->fresh();
$book->xownPageList[] = R::dispense('page');
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
R::store($book);
//no update, 1 insert, just adding
$numberOfUpdateQueries = $logger->grep('UPDATE');
asrt(count($numberOfUpdateQueries), 0);
$numberOfUpdateQueries = $logger->grep('INSERT');
asrt(count($numberOfUpdateQueries), 1);
$book = $book->fresh();
asrt(count($book->xownPageList), 10);
$logger->clear();
$book = $book->fresh();
$book->map->xownLocationList[1]->name = 'Horshoe Bay';
asrt($book->getMeta('tainted'), TRUE);
asrt($book->getMeta('changed'), FALSE);
//.........这里部分代码省略.........
示例6: testScenarios
//.........这里部分代码省略.........
asrt(count($book3->ownPage), 0);
$book3 = R::load('book', $idb3);
/**
* Why do I need to do this ---> why does trash() not set id -> 0?
* Because you unset() so trash is done on origin not bean
*/
$page1->id = 0;
$page2->id = 0;
$page3->id = 0;
$book3->ownPage[] = $page1;
$book3->ownPage[] = $page2;
$book3->ownPage[] = $page3;
$book3 = R::load('book', R::store($book3));
asrt(intval(R::getCell("select count(*) from page where book_id = {$idb3} ")), 3);
asrt(count($book3->ownPage), 3);
unset($book3->ownPage[$page2->id]);
$book3->ownPage[] = $page3;
$book3->ownPage['try_to_trick_ya'] = $page3;
$book3 = R::load('book', R::store($book3));
asrt(intval(R::getCell("select count(*) from page where book_id = {$idb3} ")), 2);
asrt(count($book3->ownPage), 2);
// Delete and re-add
$book3 = R::load('book', $idb3);
unset($book3->ownPage[10]);
$book3->ownPage[] = $page1;
$book3 = R::load('book', R::store($book3));
asrt(count($book3->ownPage), 2);
$book3 = R::load('book', $idb3);
unset($book3->sharedTopic[1]);
$book3->sharedTopic[] = $topic1;
$book3 = R::load('book', R::store($book3));
asrt(count($book3->sharedTopic), 1);
// Test performance
$logger = R::debug(true, 1);
$book = R::load('book', 1);
$book->sharedTopic = array();
R::store($book);
// No more than 1 update
asrt(count($logger->grep('UPDATE')), 1);
$book = R::load('book', 1);
$logger->clear();
print_r($book->sharedTopic, 1);
// No more than 1 select
asrt(count($logger->grep('SELECT')), 1);
$logger->clear();
$book->sharedTopic[] = $topic1;
$book->sharedTopic[] = $topic2;
asrt(count($logger->grep('SELECT')), 0);
R::store($book);
$book->sharedTopic[] = $topic3;
// Now do NOT clear all and then add one, just add the one
$logger->clear();
R::store($book);
$book = R::load('book', 1);
asrt(count($book->sharedTopic), 3);
// No deletes
asrt(count($logger->grep("DELETE FROM")), 0);
$book->sharedTopic['a'] = $topic3;
unset($book->sharedTopic['a']);
R::store($book);
$book = R::load('book', 1);
asrt(count($book->sharedTopic), 3);
// No deletes
asrt(count($logger->grep("DELETE FROM")), 0);
$book->ownPage = array();
R::store($book);
示例7: DupAndCache
/**
* Test duplication and caching.
*
* @return void
*/
public function DupAndCache()
{
testpack('Dup() and Cache');
$can = R::dispense('can')->setAttr('size', 3);
$can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black');
$can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool');
$can = R::load('can', R::store($can));
$d = new DuplicationManager(R::getToolBox());
$d->setCacheTables(TRUE);
ob_start();
R::debug(1);
$x = $d->dup($can);
$queries = ob_get_contents();
R::debug(0);
ob_end_clean();
$len1 = strlen($queries);
asrt($len1 > 40, TRUE);
asrt(isset($x->ownCoffee), TRUE);
asrt(count($x->ownCoffee), 1);
asrt(isset($x->sharedTag), TRUE);
asrt(count($x->sharedTag), 1);
$cache = $d->getSchema();
R::nuke();
$can = R::dispense('can')->setAttr('size', 3);
$can->ownCoffee[] = R::dispense('coffee')->setAttr('color', 'black');
$can->sharedTag[] = R::dispense('tag')->setAttr('name', 'cool');
$can = R::load('can', R::store($can));
$d = new DuplicationManager(R::getToolBox());
/**
* $cache = '{"book": {
* "id": "INTEGER",
* "title": "TEXT"
* }, "bean": {
* "id": "INTEGER",
* "prop": "INTEGER"
* }, "pessoa": {
* "id": "INTEGER",
* "nome": "TEXT",
* "nome_meio": "TEXT",
* "sobrenome": "TEXT",
* "nascimento": "NUMERIC",
* "reg_owner": "TEXT"
* }, "documento": {
* "id": "INTEGER",
* "nome_documento": "TEXT",
* "numero_documento": "TEXT",
* "reg_owner": "TEXT",
* "ownPessoa_id": "INTEGER"
* }, "can": {
* "id": "INTEGER",
* "size": "INTEGER"
* }, "coffee": {
* "id": "INTEGER",
* "color": "TEXT",
* "can_id": "INTEGER"
* }, "tag": {
* "id": "INTEGER",
* "name": "TEXT"
* }, "can_tag": {
* "id": "INTEGER",
* "tag_id": "INTEGER",
* "can_id": "INTEGER"
* }}'
*/
$d->setTables($cache);
ob_start();
R::debug(1);
$x = $d->dup($can);
$queries = ob_get_contents();
ob_end_clean();
R::debug(0);
$len2 = strlen($queries);
asrt(isset($x->ownCoffee), TRUE);
asrt(count($x->ownCoffee), 1);
asrt(isset($x->sharedTag), TRUE);
asrt(count($x->sharedTag), 1);
asrt(json_encode($cache), json_encode($d->getSchema()));
asrt($len1 > $len2, TRUE);
}
示例8: testFreezer
/**
* Tests freezing the database.
* After freezing the database, schema modifications are no longer
* allowed and referring to missing columns will now cause exceptions.
*
* @return void
*/
public function testFreezer()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$a = new AssociationManager($toolbox);
$post = $redbean->dispense('post');
$post->title = 'title';
$redbean->store($post);
$page = $redbean->dispense('page');
$page->name = 'title';
$redbean->store($page);
$page = $redbean->dispense("page");
$page->name = "John's page";
$idpage = $redbean->store($page);
$page2 = $redbean->dispense("page");
$page2->name = "John's second page";
$idpage2 = $redbean->store($page2);
$a->associate($page, $page2);
$redbean->freeze(TRUE);
$page = $redbean->dispense("page");
$page->sections = 10;
$page->name = "half a page";
try {
$id = $redbean->store($page);
fail();
} catch (SQL $e) {
pass();
}
$post = $redbean->dispense("post");
$post->title = "existing table";
try {
$id = $redbean->store($post);
pass();
} catch (SQL $e) {
fail();
}
asrt(in_array("name", array_keys($writer->getColumns("page"))), TRUE);
asrt(in_array("sections", array_keys($writer->getColumns("page"))), FALSE);
$newtype = $redbean->dispense("newtype");
$newtype->property = 1;
try {
$id = $redbean->store($newtype);
fail();
} catch (SQL $e) {
pass();
}
$logger = R::debug(true, 1);
// Now log and make sure no 'describe SQL' happens
$page = $redbean->dispense("page");
$page->name = "just another page that has been frozen...";
$id = $redbean->store($page);
$page = $redbean->load("page", $id);
$page->name = "just a frozen page...";
$redbean->store($page);
$page2 = $redbean->dispense("page");
$page2->name = "an associated frozen page";
$a->associate($page, $page2);
$a->related($page, "page");
$a->unassociate($page, $page2);
$a->clearRelations($page, "page");
$items = $redbean->find("page", array(), array("1"));
$redbean->trash($page);
$redbean->freeze(FALSE);
asrt(count($logger->grep("SELECT")) > 0, TRUE);
asrt(count($logger->grep("describe")) < 1, TRUE);
asrt(is_array($logger->getLogs()), TRUE);
R::debug(false);
}
示例9: ConfigSetup
public static function ConfigSetup($arrconfig = null)
{
if (is_array($arrconfig) && !empty($arrconfig)) {
if ($arrconfig['server']) {
self::$server = $arrconfig['server'];
}
if ($arrconfig['databasename']) {
self::$databasename = $arrconfig['databasename'];
}
if ($arrconfig['username']) {
self::$username = $arrconfig['username'];
}
if ($arrconfig['password']) {
self::$password = $arrconfig['password'];
}
if ($arrconfig['port']) {
self::$port = $arrconfig['port'];
}
}
self::$connection = new PDO('mysql:host=' . self::$server . ';port=' . self::$port . ';dbname=' . self::$databasename . ';', self::$username, self::$password);
self::$connection->query('SET NAMES utf8');
R::setup(self::$connection);
R::freeze(true);
self::$logsrv = new \RedBeanPHP\Plugin\SystemlogsService();
R::debug(true, 1);
}
示例10: testFindOneLimitOne
/**
* Test whether findOne gets a LIMIT 1
* clause.
*
* @return void
*/
public function testFindOneLimitOne()
{
R::nuke();
list($book1, $book2) = R::dispense('book', 2);
$book1->title = 'a';
$book2->title = 'b';
R::storeAll(array($book1, $book2));
$logger = R::debug(1, 1);
$logger->clear();
$found = R::findOne('book');
asrt(count($logger->grep('LIMIT 1')), 1);
asrt($found instanceof \RedBeanPHP\OODBBean, TRUE);
$logger->clear();
$found = R::findOne('book', ' title = ? ', array('a'));
asrt(count($logger->grep('LIMIT 1')), 1);
asrt($found instanceof \RedBeanPHP\OODBBean, TRUE);
$logger->clear();
$found = R::findOne('book', ' title = ? LIMIT 1', array('b'));
asrt(count($logger->grep('LIMIT 1')), 1);
$logger->clear();
$found = R::findOne('book', ' title = ? limit 1', array('b'));
asrt(count($logger->grep('LIMIT 1')), 0);
asrt(count($logger->grep('limit 1')), 1);
asrt($found instanceof \RedBeanPHP\OODBBean, TRUE);
$found = R::findOne('book', ' title = ? LIMIT 2', array('b'));
asrt(count($logger->grep('LIMIT 2')), 1);
asrt($found instanceof \RedBeanPHP\OODBBean, TRUE);
}