本文整理汇总了PHP中RedBeanPHP\Facade::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::load方法的具体用法?PHP Facade::load怎么用?PHP Facade::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDatabaseInstallation
public function testDatabaseInstallation()
{
$this->url('index.php');
//All Fields initially with empty
$this->fillFields(array('hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'phpback_test', 'adminemail' => 'admin@phpback.org', 'adminname' => 'admin', 'adminpass' => 'admin', 'adminrpass' => 'admin'));
//Submit form
$this->byName('install-form')->submit();
//Should delete first intallation files
$this->assertFileNotExists('install/index.php');
$this->assertFileNotExists('install/install1.php');
$this->assertFileNotExists('install/database_tables.sql');
//Should create configuration file
$this->assertFileExists('application/config/database.php');
include 'application/config/database.php';
$this->assertEquals($db['default']['username'], 'root');
$this->assertEquals($db['default']['password'], '');
$this->assertEquals($db['default']['database'], 'phpback_test');
$this->assertEquals($db['default']['username'], 'root');
$this->assertEquals($db['default']['dbdriver'], 'mysqli');
//Should have updated database with new tables
$this->assertEquals(RedBean::inspect(), array('_sessions', 'categories', 'comments', 'flags', 'ideas', 'logs', 'settings', 'users', 'votes'));
//Should have created the admin user
$adminUser = RedBean::load('users', 1);
$this->assertEquals($adminUser->name, 'admin');
$this->assertEquals($adminUser->email, 'admin@phpback.org');
$this->assertEquals($adminUser->isadmin, '3');
$this->assertEquals($adminUser->votes, '20');
}
示例2: testTainted
/**
* Test tainted.
*
* @return void
*/
public function testTainted()
{
testpack('Original Tainted Tests');
$redbean = R::getRedBean();
$spoon = $redbean->dispense("spoon");
asrt($spoon->getMeta("tainted"), TRUE);
$spoon->dirty = "yes";
asrt($spoon->getMeta("tainted"), TRUE);
testpack('Tainted List test');
$note = R::dispense('note');
$note->text = 'abc';
$note->ownNote[] = R::dispense('note')->setAttr('text', 'def');
$id = R::store($note);
$note = R::load('note', $id);
asrt($note->isTainted(), FALSE);
// Shouldn't affect tainted
$note->text;
asrt($note->isTainted(), FALSE);
$note->ownNote;
asrt($note->isTainted(), TRUE);
testpack('Tainted Test Old Value');
$text = $note->old('text');
asrt($text, 'abc');
asrt($note->hasChanged('text'), FALSE);
$note->text = 'xxx';
asrt($note->hasChanged('text'), TRUE);
$text = $note->old('text');
asrt($text, 'abc');
testpack('Tainted Non-exist');
asrt($note->hasChanged('text2'), FALSE);
testpack('Misc Tainted Tests');
$bean = R::dispense('bean');
$bean->hasChanged('prop');
$bean->old('prop');
}
示例3: testTypes
/**
* Test types.
* Test how RedBeanPHP OODB and OODBBean handle type and type casts.
*
* Rules:
*
* 1. before storing a bean all types are preserved except booleans (they are converted to STRINGS '0' or '1')
* 2. after store-reload all bean property values are STRINGS or NULL
* (or ARRAYS but that's only from a user perspective because these are lazy loaded)
* 3. the ID returned by store() is an INTEGER (if possible; on 32 bit systems overflowing values will be cast to STRINGS!)
*
* After loading:
* ALL VALUES EXCEPT NULL -> STRING
* NULL -> NULL
*
* @note Why not simply return bean->id in store()? Because not every driver returns the same type:
* databases without insert_id support require a separate query or a suffix returning STRINGS, not INTEGERS.
*
* @note Why not preserve types? I.e. I store integer, why do I get back a string?
* Answer: types are handled different across database platforms, would cause overhead to inspect every value for type,
* also PHP is a dynamically typed language so types should not matter that much. Another reason: due to the nature
* of RB columns in the database might change (INT -> STRING) this would cause return types to change as well which would
* cause 'cascading errors', i.e. a column gets widened and suddenly your code would break.
*
* @note Unfortunately the 32/64-bit issue cannot be tested fully. Return-strategy store() is probably the safest
* solution.
*
* @return void
*/
public function testTypes()
{
testpack('Beans can only contain STRING and NULL after reload');
R::nuke();
$bean = R::dispense('bean');
$bean->number = 123;
$bean->float = 12.3;
$bean->bool = false;
$bean->bool2 = true;
$bean->text = 'abc';
$bean->null = null;
$bean->datetime = new \DateTime('NOW', new \DateTimeZone('Europe/Amsterdam'));
$id = R::store($bean);
asrt(is_int($id), TRUE);
asrt(is_float($bean->float), TRUE);
asrt(is_integer($bean->number), TRUE);
asrt(is_string($bean->bool), TRUE);
asrt(is_string($bean->bool2), TRUE);
asrt(is_string($bean->datetime), TRUE);
asrt(is_string($bean->text), TRUE);
asrt(is_null($bean->null), TRUE);
$bean = R::load('bean', $id);
asrt(is_string($bean->id), TRUE);
asrt(is_string($bean->float), TRUE);
asrt(is_string($bean->number), TRUE);
asrt(is_string($bean->bool), TRUE);
asrt(is_string($bean->bool2), TRUE);
asrt(is_string($bean->datetime), TRUE);
asrt(is_string($bean->text), TRUE);
asrt(is_null($bean->null), TRUE);
asrt($bean->bool, '0');
asrt($bean->bool2, '1');
}
示例4: testViaAndSQL
/**
* Via specific tests.
*
* @return void
*/
public function testViaAndSQL()
{
R::nuke();
list($p1, $p2) = R::dispense('participant', 2);
list($e1, $e2) = R::dispense('employee', 2);
list($x1, $x2) = R::dispense('project', 2);
$e1->name = 'Anna';
$e2->name = 'John';
$p1->project = $x1;
$p1->employee = $e1;
$p1->arole = 'designer';
$p2->project = $x1;
$p2->employee = $e2;
$p2->arole = 'coder';
R::storeAll(array($p1, $p2));
$project = R::load('project', $x1->id);
$designers = $project->withCondition(' participant.arole = ? ', array('designer'))->via('participant')->sharedEmployeeList;
$anna = reset($designers);
asrt(count($designers), 1);
asrt($anna->name, 'Anna');
$coders = $project->withCondition(' participant.arole = ? ', array('coder'))->via('participant')->sharedEmployeeList;
$john = reset($coders);
asrt(count($coders), 1);
asrt($john->name, 'John');
}
示例5: testRebuilder
/**
* Test SQLite table rebuilding.
*
* @return void
*/
public function testRebuilder()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$book = R::dispense('book');
$page = R::dispense('page');
$book->xownPage[] = $page;
$id = R::store($book);
$book = R::load('book', $id);
asrt(count($book->xownPage), 1);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
R::trash($book);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
$book = R::dispense('book');
$page = R::dispense('page');
$book->xownPage[] = $page;
$id = R::store($book);
$book = R::load('book', $id);
asrt(count($book->xownPage), 1);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
$book->added = 2;
R::store($book);
$book->added = 'added';
R::store($book);
R::trash($book);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
}
示例6: testBasicNullHandling
/**
* Test NULL handling, setting a property to NULL must
* cause a change.
*
* @return void
*/
public function testBasicNullHandling()
{
// NULL can change bean
$bean = R::dispense('bean');
$bean->bla = 'a';
R::store($bean);
$bean = $bean->fresh();
asrt($bean->hasChanged('bla'), FALSE);
$bean->bla = NULL;
asrt($bean->hasChanged('bla'), TRUE);
// NULL test
$page = R::dispense('page');
$book = R::dispense('book');
$page->title = 'a NULL page';
$page->book = $book;
$book->title = 'Why NUll is painful..';
R::store($page);
$bookid = $page->book->id;
unset($page->book);
$id = R::store($page);
$page = R::load('page', $id);
$page->title = 'another title';
R::store($page);
pass();
$page = R::load('page', $id);
$page->title = 'another title';
$page->book_id = NULL;
R::store($page);
pass();
}
示例7: testTags
/**
* Some basic tests.
*
* @return void
*/
public function testTags()
{
list($c, $d, $e, $f) = R::dispense('coffee', 4);
R::tag($c, 'strong,black');
R::tag($d, 'black');
R::tag($e, 'strong,sweet');
R::tag($f, 'black,strong');
asrt(count(R::taggedAll('coffee', 'strong,sweet')), 1);
asrt(count(R::taggedAll('coffee', 'strong')), 3);
asrt(count(R::taggedAll('coffee', '')), 0);
asrt(count(R::taggedAll('coffee', 'sweet')), 1);
asrt(count(R::taggedAll('coffee', 'sweet,strong')), 1);
asrt(count(R::taggedAll('coffee', 'black,strong')), 2);
asrt(count(R::taggedAll('coffee', array('black', 'strong'))), 2);
asrt(count(R::taggedAll('coffee', 'salty')), 0);
$blog = R::dispense('blog');
$blog->title = 'testing';
$blog->blog = 'tesing';
R::store($blog);
$blogpost = R::load("blog", 1);
$post = R::dispense("post");
$post->message = "hello";
R::tag($post, "lousy,smart");
asrt(implode(',', R::tag($post)), "lousy,smart");
R::tag($post, "clever,smart");
$tagz = implode(',', R::tag($post));
asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
R::tag($blog, array("smart", "interesting"));
asrt(implode(',', R::tag($blog)), "smart,interesting");
try {
R::tag($blog, array("smart", "interesting", "lousy!"));
pass();
} catch (RedException $e) {
fail();
}
asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
R::untag($blog, array("smart", "interesting"));
asrt(implode(",", R::tag($blog)), "lousy!");
asrt(R::hasTag($blog, array("lousy!")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
R::tag($blog, FALSE);
asrt(count(R::tag($blog)), 0);
R::tag($blog, array("funny", "comic"));
asrt(count(R::tag($blog)), 2);
R::addTags($blog, array("halloween"));
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
R::unTag($blog, "funny");
R::addTags($blog, "horror");
asrt(count(R::tag($blog)), 3);
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
//no double tags
R::addTags($blog, "horror");
asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
asrt(R::hasTag($blog, "horror,commic,halloween", TRUE), FALSE);
asrt(count(R::tag($blog)), 3);
testpack("fetch tagged items");
}
示例8: testTwoWordsUnderscoredBean
/**
* Cant have underscored beans
* @expectedException \RedBeanPHP\RedException
*/
public function testTwoWordsUnderscoredBean()
{
R::freeze(false);
$testName = R::dispense('test_name');
$id = R::store($testName);
R::load('test_name', $id);
R::freeze($this->frozen);
}
示例9: testDisableVoteIdea
public function testDisableVoteIdea()
{
Scripts::LoginUser('newemail2@phpback.org', 'Gates123');
$this->url('home/profile/4');
$this->byLinkText('Delete votes')->click();
$voteidea = RedBean::load('ideas', 3);
$this->assertEquals($voteidea->votes, '0');
}
示例10: testUTF8
/**
* Test UTF8 handling.
*
* @return void
*/
public function testUTF8()
{
$str = '𠜎ὃ𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜';
$bean = R::dispense('bean');
$bean->bla = $str;
R::store($bean);
$bean = R::load('bean', $bean->id);
asrt($bean->bla, $str);
pass();
}
示例11: store
/**
* Store a new record.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$item_id = $request->input('item_id');
$item = R::load('item', $item_id);
$attribute = R::dispense('attribute');
$attribute->key = $request->input('key');
$attribute->value = $request->input('value');
$item->ownAttributeList[] = $attribute;
R::store($item);
echo "<pre>\n";
var_dump($attribute->export());
var_dump($item->export());
}
示例12: testIssue259
/**
* Test to make sure stash cache works with recursively opening models
* with FUSE.
*
* @return void
*/
public function testIssue259()
{
testpack('Testing Issue #259 - Stash Cache breaks model delegation in open().');
$mother = R::dispense('mother');
$mother->desc = 'I am mother';
R::store($mother);
$child = R::dispense('child');
$child->mother = $mother;
$child->desc = 'I am child';
$id = R::store($child);
R::findOne('child', ' id = ?', array($id));
R::find('child', ' id = ? ', array($id));
R::load('child', $id);
}
示例13: testExportIssue
/**
* In the past it was not possible to export beans
* like 'feed' (Model_Feed).
*
* @return void
*/
public function testExportIssue()
{
R::nuke();
$feed = R::dispense('feed');
$feed->post = array('first', 'second');
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second"]');
$feed = $feed->fresh();
asrt(is_array($feed->post), TRUE);
asrt($feed->post[0], 'first');
asrt($feed->post[1], 'second');
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second"]');
$feed = R::load('feed', $feed->id);
$feed->post[] = 'third';
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second","third"]');
$feed = $feed->fresh();
asrt(is_array($feed->post), TRUE);
asrt($feed->post[0], 'first');
asrt($feed->post[1], 'second');
asrt($feed->post[2], 'third');
//now the catch: can we use export?
//PHP Fatal error: Call to a member function export() on a non-object
$feeds = R::exportAll(R::find('feed'));
asrt(is_array($feeds), TRUE);
$feed = reset($feeds);
asrt($feed['post'][0], 'first');
asrt($feed['post'][1], 'second');
asrt($feed['post'][2], 'third');
//can we also dup()?
$feedOne = R::findOne('feed');
R::store(R::dup($feedOne));
asrt(R::count('feed'), 2);
//can we delete?
R::trash($feedOne);
asrt(R::count('feed'), 1);
$feedTwo = R::findOne('feed');
$feed = $feedTwo->export();
asrt($feed['post'][0], 'first');
asrt($feed['post'][1], 'second');
asrt($feed['post'][2], 'third');
}
示例14: 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');
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();
}
}
示例15: testBigIntSupport
/**
* Test BIG INT primary key support.
*
* @return void
*/
public function testBigIntSupport()
{
R::nuke();
$createPageTableSQL = '
CREATE TABLE
`page`
(
id BIGINT(20) UNSIGNED NOT NULL,
book_id BIGINT(20) UNSIGNED NOT NULL,
magazine_id BIGINT(20) UNSIGNED NOT NULL,
title VARCHAR(255),
PRIMARY KEY ( id )
)
ENGINE = InnoDB DEFAULT
CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
AUTO_INCREMENT = 1223372036854775808';
$createBookTableSQL = '
CREATE TABLE
`book`
(
id BIGINT(20) UNSIGNED NOT NULL,
title VARCHAR(255),
PRIMARY KEY ( id )
)
ENGINE = InnoDB DEFAULT
CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
AUTO_INCREMENT = 2223372036854775808';
$createPagePageTableSQL = '
CREATE TABLE
`page_page`
(
id BIGINT(20) UNSIGNED NOT NULL,
page_id BIGINT(20) UNSIGNED NOT NULL,
page2_id BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY ( id )
)
ENGINE = InnoDB DEFAULT
CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
AUTO_INCREMENT = 3223372036854775808';
R::exec($createBookTableSQL);
R::exec($createPageTableSQL);
R::exec($createPagePageTableSQL);
//insert some records
$book1ID = '2223372036854775808';
$book2ID = '2223372036854775809';
$page1ID = '1223372036854775808';
$page2ID = '1223372036854775809';
$page3ID = '1223372036854775890';
$pagePage1ID = '3223372036854775808';
$insertBook1SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book1ID}', 'book 1' );\n\t\t";
$insertBook2SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book2ID}', 'book 2' );\n\t\t";
$insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t";
$insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t";
$insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t";
$insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t";
R::exec($insertBook1SQL);
R::exec($insertBook2SQL);
R::exec($insertPage1SQL);
R::exec($insertPage2SQL);
R::exec($insertPage3SQL);
R::exec($insertPagePage1SQL);
//basic tour of basic functions....
$book1 = R::load('book', $book1ID);
asrt($book1->id, $book1ID);
asrt($book1->title, 'book 1');
$book2 = R::load('book', $book2ID);
asrt($book2->id, $book2ID);
asrt($book2->title, 'book 2');
asrt(count($book1->ownPage), 2);
asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1);
asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1);
asrt(count($book2->ownPage), 1);
asrt($book2->fresh()->countOwn('page'), 1);
$page1 = R::load('page', $page1ID);
asrt(count($page1->sharedPage), 0);
asrt($page1->fetchAs('book')->magazine->id, $book2ID);
$page2 = R::load('page', $page2ID);
asrt(count($page2->sharedPage), 1);
asrt($page2->fresh()->countShared('page'), 1);
$page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2'));
asrt($page3->id, $page3ID);
asrt($page3->book->id, $book2ID);
}