当前位置: 首页>>代码示例>>PHP>>正文


PHP Facade::dispenseAll方法代码示例

本文整理汇总了PHP中RedBeanPHP\Facade::dispenseAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::dispenseAll方法的具体用法?PHP Facade::dispenseAll怎么用?PHP Facade::dispenseAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedBeanPHP\Facade的用法示例。


在下文中一共展示了Facade::dispenseAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDuplicateFK

 /**
  * Test whether we can't add more than one FK.
  */
 public function testDuplicateFK()
 {
     R::nuke();
     list($book, $page) = R::dispenseAll('book,page');
     $book->sharedPage[] = $page;
     R::store($page);
     R::store($book);
     $added = R::getWriter()->addConstraintForTypes('page', 'book');
     asrt($added, FALSE);
 }
开发者ID:cesium147,项目名称:redbean,代码行数:13,代码来源:Relations.php

示例2: testDuplicateFK

 /**
  * Test whether we can't add more than one FK.
  */
 public function testDuplicateFK()
 {
     R::nuke();
     list($book, $page) = R::dispenseAll('book,page');
     $book->sharedPage[] = $page;
     R::store($page);
     R::store($book);
     $writer = R::getWriter();
     $added1 = $writer->addFK('book_page', 'book', 'book_id', 'id', TRUE);
     $added2 = $writer->addFK('book_page', 'page', 'page_id', 'id', TRUE);
     $added = $added1 && $added2;
     asrt($added, FALSE);
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:16,代码来源:Relations.php

示例3: testAutoResolver

 /**
  * Tests automatic resolvement of parent beans
  * without fetchAs() using inferFetchType (foreign keys).
  *
  * @return void
  */
 public function testAutoResolver()
 {
     R::nuke();
     list($project, $teacher, $student) = R::dispenseAll('project,person,person');
     $teacher->name = 'teacher';
     $student->name = 'student';
     $project->teacher = $teacher;
     $project->student = $student;
     R::store($project);
     $project = $project->fresh();
     asrt($project->teacher instanceof OODBBean, TRUE);
     asrt($project->student instanceof OODBBean, TRUE);
     asrt($project->teacher->name, 'teacher');
     asrt($project->student->name, 'student');
     $project2 = R::dispense('project');
     $teacher2 = R::dispense('person');
     $teacher2->name = 'teacher2';
     $project2->teacher = $teacher2;
     R::store($project2);
     $project2 = $project2->fresh();
     asrt($project2->teacher instanceof OODBBean, TRUE);
     asrt($project2->teacher->name, 'teacher2');
     asrt(is_null($project2->student), TRUE);
     $project = $project->fresh();
     asrt($project->fetchAs('person')->teacher instanceof OODBBean, TRUE);
     asrt($project->fetchAs('person')->student instanceof OODBBean, TRUE);
     asrt($project->fetchAs('person')->teacher->name, 'teacher');
     asrt($project->fetchAs('person')->student->name, 'student');
     $project = $project->fresh();
     $export = R::exportAll(array($project), TRUE);
     asrt(isset($export[0]['teacher']['name']), TRUE);
     asrt(isset($export[0]['student']['name']), TRUE);
     asrt($export[0]['teacher']['name'], 'teacher');
     asrt($export[0]['student']['name'], 'student');
     //Also test the default implementation...
     $nullWriter = new \NullWriter(R::getDatabaseAdapter());
     asrt(is_null($nullWriter->inferFetchType('test', 'test')), TRUE);
     //Realteacher should take precedence over fetchAs-teacher, name conventions first!
     //also: ensure we do not use autoresolv for anything except when truly necessary! (performance)
     $realTeacher = R::dispense('teacher');
     $realTeacher->name = 'real';
     R::store($realTeacher);
     //ID must be same
     asrt($realTeacher->id, $teacher->id);
     $project = $project->fresh();
     asrt($project->teacher->name, 'real');
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:53,代码来源:Aliasing.php

示例4: testDispenseAll

 /**
  * Tests the facade-only dispenseAll method.
  *
  * @return void
  */
 public function testDispenseAll()
 {
     list($book, $page) = Facade::dispenseAll('book,page');
     asrt($book instanceof OODBBean, TRUE);
     asrt($page instanceof OODBBean, TRUE);
     asrt($book->getMeta('type'), 'book');
     asrt($page->getMeta('type'), 'page');
     list($book, $page, $texts, $mark) = R::dispenseAll('book,page,text*2,mark');
     asrt($book instanceof OODBBean, TRUE);
     asrt($page instanceof OODBBean, TRUE);
     asrt(is_array($texts), TRUE);
     asrt($mark instanceof OODBBean, TRUE);
     asrt($book->getMeta('type'), 'book');
     asrt($page->getMeta('type'), 'page');
     asrt($mark->getMeta('type'), 'mark');
     asrt($texts[0]->getMeta('type'), 'text');
     asrt($texts[1]->getMeta('type'), 'text');
     list($eggs, $milk, $butter) = R::dispenseAll('eggs*3,milk*1,butter*9');
     asrt(count($eggs), 3);
     asrt($milk instanceof OODBBean, TRUE);
     asrt(count($butter), 9);
     list($eggs, $milk, $butter) = R::dispenseAll('eggs*3,milk*1,butter*9', TRUE);
     asrt(count($eggs), 3);
     asrt(count($milk), 1);
     asrt(count($eggs), 3);
     list($beer) = R::dispenseAll('beer*0', TRUE);
     asrt(is_array($beer), TRUE);
     asrt(count($beer), 0);
     list($beer) = R::dispenseAll('beer*0', FALSE);
     asrt(is_array($beer), FALSE);
     asrt(is_null($beer), TRUE);
     asrt(count($beer), 0);
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:38,代码来源:Dispense.php

示例5: 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);
//.........这里部分代码省略.........
开发者ID:gabordemooij,项目名称:redbean,代码行数:101,代码来源:Uuid.php

示例6: testBeanTainting

 /**
  * Only fire update query if the bean really contains different
  * values. But make sure beans several 'parents' away still get
  * saved.
  *
  * @return void
  */
 public function testBeanTainting()
 {
     $logger = R::getDatabaseAdapter()->getDatabase()->getLogger();
     list($i, $k, $c, $s) = R::dispenseAll('invoice,customer,city,state');
     $i->customer = $k;
     $i->status = 0;
     $k->city = $c;
     $c->state = $s;
     $s->name = 'x';
     R::store($i);
     $i = $i->fresh();
     asrt($i->customer->city->state->name, 'x');
     $i->status = 1;
     R::freeze(true);
     $logger = R::debug(1, 1);
     //do we properly skip unmodified but tainted parent beans?
     R::store($i);
     $numberOfUpdateQueries = $logger->grep('UPDATE');
     asrt(count($numberOfUpdateQueries), 1);
     //does cascade update still work?
     $i = $i->fresh();
     $i->customer->city->state->name = 'y';
     R::store($i);
     $i = $i->fresh();
     asrt($i->customer->city->state->name, 'y');
     $i = $i->fresh();
     $differentCity = R::dispense('city');
     R::store($differentCity);
     $i->customer->city = $differentCity;
     R::store($i);
     $i = $i->fresh();
     asrt($i->customer->city->id != $c->id, TRUE);
     asrt(is_null($i->customer->city->state), TRUE);
     $i->customer->city = NULL;
     R::store($i);
     $i = $i->fresh();
     asrt(is_null($i->customer->city), TRUE);
     $i->customer = $k;
     $i->status = 0;
     $k->city = $c;
     $c->state = $s;
     $s->name = 'x';
     R::store($i);
     R::freeze(FALSE);
     $i = $i->fresh();
     //can we still change remote parent?
     $i->customer->city->name = 'q';
     $logger->clear();
     R::store($i);
     $numberOfUpdateQueries = $logger->grep('UPDATE');
     //print_r($logger->getLogs());
     asrt(count($numberOfUpdateQueries), 1);
     $i = $i->fresh();
     asrt($i->customer->city->name, 'q');
     //do we properly skip unmodified but tainted parent beans?
     $i->status = 3;
     $logger->clear();
     R::store($i);
     $numberOfUpdateQueries = $logger->grep('UPDATE');
     asrt(count($numberOfUpdateQueries), 1);
 }
开发者ID:gabordemooij,项目名称:redbean,代码行数:68,代码来源:Bean.php

示例7: testErrorHandling

 public function testErrorHandling()
 {
     R::nuke();
     list($book, $page) = R::dispenseAll('book,page');
     $book->sharedPage[] = $page;
     R::store($page);
     $redbean = R::getRedBean();
     $am = $redbean->getAssociationManager();
     //SQLite and CUBRID do not comply with ANSI SQLState codes.
     $catchAll = $this->currentlyActiveDriverID == 'sqlite' || $this->currentlyActiveDriverID === 'CUBRID';
     try {
         $am->related($book, 'page', 'invalid SQL');
         if ($catchAll) {
             pass();
         } else {
             fail();
         }
     } catch (SQL $e) {
         if ($catchAll) {
             fail();
         } else {
             pass();
         }
     }
     try {
         $am->related($book, 'cover');
         pass();
     } catch (SQL $e) {
         fail();
     }
     try {
         $am->related(R::dispense('cover'), 'book');
         pass();
     } catch (SQL $e) {
         fail();
     }
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:37,代码来源:Association.php

示例8: testFindLike2

 /**
  * Test findLike.
  *
  * @return void
  */
 public function testFindLike2()
 {
     list($flowers, $shop) = R::dispenseAll('flower*4,shop');
     $flowers[0]->color = 'red';
     $flowers[1]->color = 'yellow';
     $flowers[2]->color = 'blue';
     $flowers[3]->color = 'purple';
     $flowers[0]->price = 10;
     $flowers[1]->price = 15;
     $flowers[2]->price = 20;
     $flowers[3]->price = 25;
     $shop->xownFlowerList = $flowers;
     R::store($shop);
     asrt($this->getColors(R::findLike('flower', array('color' => array('red', 'yellow')), ' price < 20')), 'red,yellow');
     asrt($this->getColors(R::findLike('flower', array('color' => array()), '')), 'blue,purple,red,yellow');
     asrt($this->getColors(R::findLike('flower', array('color' => array()))), 'blue,purple,red,yellow');
     asrt($this->getColors(R::findLike('flower', array('color' => array('blue')), ' OR price = 25')), 'blue,purple');
     asrt($this->getColors(R::findLike('flower', array('color' => array()), ' price < 25')), 'blue,red,yellow');
     asrt($this->getColors(R::findLike('flower', array('color' => array()), ' price < 20')), 'red,yellow');
     asrt($this->getColors(R::findLike('flower', array('color' => array()), ' ORDER BY color DESC'), TRUE), 'yellow,red,purple,blue');
     asrt($this->getColors(R::findLike('flower', array('color' => array()), ' ORDER BY color LIMIT 1')), 'blue');
     asrt($this->getColors(R::findLike('flower', array('color' => array('yellow', 'blue')), ' ORDER BY color ASC  LIMIT 1')), 'blue');
 }
开发者ID:gabordemooij,项目名称:redbean,代码行数:28,代码来源:Finding.php


注:本文中的RedBeanPHP\Facade::dispenseAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。