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


PHP R::each方法代码示例

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


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

示例1: testBigIntSupport

    /**
     * Test BIG INT primary key support.
     * 
     * @return void
     */
    public function testBigIntSupport()
    {
        R::nuke();
        $createPageTableSQL = '
			CREATE TABLE 
			page 
			(
				id BIGSERIAL PRIMARY KEY, 
				book_id BIGSERIAL,
				magazine_id BIGSERIAL,
				title VARCHAR(255)
			)';
        $createBookTableSQL = '
			CREATE TABLE 
			book 
			(
				id BIGSERIAL PRIMARY KEY,
				title VARCHAR(255)
			)';
        $createPagePageTableSQL = '
			CREATE TABLE 
			page_page
			(
				id BIGSERIAL PRIMARY KEY, 
				page_id BIGSERIAL,
				page2_id BIGSERIAL
			) ';
        R::exec($createBookTableSQL);
        R::exec($createPageTableSQL);
        R::exec($createPagePageTableSQL);
        //insert some records
        $book1ID = '2223372036854775808';
        $book2ID = '2223372036854775809';
        $page1ID = '1223372036854775808';
        $page2ID = '1223372036854775809';
        $page3ID = '1223372036854775890';
        $pagePage1ID = '3223372036854775808';
        R::exec("ALTER SEQUENCE book_id_seq RESTART WITH {$book1ID}");
        R::exec("ALTER SEQUENCE page_id_seq RESTART WITH {$page1ID}");
        R::exec("ALTER SEQUENCE page_page_id_seq RESTART WITH {$pagePage1ID}");
        $insertBook1SQL = "\n\t\t\tINSERT INTO book (title) VALUES( 'book 1' );\n\t\t";
        $insertBook2SQL = "\n\t\t\tINSERT INTO book (title) VALUES( '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);
        R::each($page2->fresh(), 'book', function ($page, $book) use($page2ID, $book1ID) {
            asrt($page->id, $page2ID);
            asrt($book->id, $book1ID);
        });
    }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:83,代码来源:Bigint.php

示例2: testUUIDReadSupport

    /**
     * Test Read-support.
     * 
     * @return void
     */
    public function testUUIDReadSupport()
    {
        R::nuke();
        $createPageTableSQL = '
			CREATE TABLE 
			`page` 
			(
				id CHAR( 40 ), 
				book_id CHAR( 40 ),
				magazine_id CHAR( 40 ),
				title VARCHAR(255),
				PRIMARY KEY ( id )
			) 
			ENGINE = InnoDB DEFAULT 
			CHARSET=utf8mb4 
			COLLATE=utf8mb4_unicode_ci ';
        $createBookTableSQL = '
			CREATE TABLE 
			`book` 
			(
				id CHAR( 40 ), 
				title VARCHAR(255),
				PRIMARY KEY ( id )
			) 
			ENGINE = InnoDB DEFAULT 
			CHARSET=utf8mb4 
			COLLATE=utf8mb4_unicode_ci ';
        $createPagePageTableSQL = '
			CREATE TABLE 
			`page_page` 
			(
				id CHAR( 40 ), 
				page_id CHAR( 40 ),
				page2_id CHAR( 40 ),
				PRIMARY KEY ( id )
			) 
			ENGINE = InnoDB DEFAULT 
			CHARSET=utf8mb4 
			COLLATE=utf8mb4_unicode_ci ';
        R::exec($createBookTableSQL);
        R::exec($createPageTableSQL);
        R::exec($createPagePageTableSQL);
        //insert some records
        $book1ID = '6ccd780c-baba-1026-9564-0040f4311e21';
        $book2ID = '6ccd780c-baba-1026-9564-0040f4311e22';
        $page1ID = '6ccd780c-baba-1026-9564-0040f4311e23';
        $page2ID = '6ccd780c-baba-1026-9564-0040f4311e24';
        $page3ID = '6ccd780c-baba-1026-9564-0040f4311e25';
        $pagePage1ID = '6ccd780c-baba-1026-9564-0040f4311e26';
        $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);
        R::each($page2->fresh(), 'book', function ($page, $book) use($page2ID, $book1ID) {
            asrt($page->id, $page2ID);
            asrt($book->id, $book1ID);
        });
    }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:92,代码来源:Uuid.php

示例3: testPreloadingVariationsAndCache2

 /**
  * Test variations and cache 2.
  * 
  * @return void
  */
 public function testPreloadingVariationsAndCache2()
 {
     R::$writer->setUseCache(FALSE);
     $villages = R::dispense('village', 3);
     foreach ($villages as $v) {
         $v->ownBuilding = R::dispense('building', 3);
     }
     foreach ($villages as $v) {
         foreach ($v->ownBuilding as $b) {
             $b->ownFurniture = R::dispense('furniture', 2);
         }
     }
     $armies = R::dispense('army', 3);
     $villages[0]->sharedArmy = array($armies[1], $armies[2]);
     $villages[1]->sharedArmy = array($armies[0], $armies[1]);
     $villages[2]->sharedArmy = array($armies[2]);
     $soldiers = R::dispense('soldier', 4);
     $armies[0]->sharedSoldier = array($soldiers[0], $soldiers[1], $soldiers[2]);
     $armies[1]->sharedSoldier = array($soldiers[2], $soldiers[1]);
     $armies[2]->sharedSoldier = array($soldiers[2]);
     $counter = 0;
     foreach ($villages as $v) {
         $v->name = $counter++;
     }
     $counter = 0;
     foreach ($armies as $a) {
         $a->name = $counter++;
     }
     $counter = 0;
     foreach ($soldiers as $s) {
         $s->name = $counter++;
     }
     $buildings = R::dispense('building', 4);
     $villages[0]->ownBuilding = array($buildings[0]);
     $villages[1]->ownBuilding = array($buildings[1], $buildings[2]);
     $villages[2]->ownBuilding = array($buildings[3]);
     $counter = 0;
     foreach ($buildings as $b) {
         $b->name = $counter++;
     }
     $books = R::dispense('book', 5);
     $counter = 0;
     foreach ($books as $b) {
         $b->name = $counter++;
     }
     $buildings[0]->ownBook = array($books[0], $books[1]);
     $buildings[1]->ownBook = array($books[2]);
     $buildings[2]->ownBook = array($books[3], $books[4]);
     $world = R::dispense('world');
     $world->name = 'w1';
     $villages[1]->world = $world;
     R::storeAll($villages);
     $towns = R::find('village');
     $counter = 0;
     R::each($towns, array('sharedArmy' => 'army', 'sharedArmy.sharedSoldier' => array('soldier', array(' ORDER BY soldier.name DESC ', array())), 'ownBuilding' => array('building', array(' ORDER BY building.name DESC ', array())), 'ownBuilding.ownBook' => 'book', 'world'), function ($t, $a, $s, $b, $x, $w) use(&$counter) {
         if ($counter === 0) {
             asrt($w, NULL);
             asrt((string) $t->name, '0');
             asrt(count($t->sharedArmy), 2);
             $list = array();
             foreach ($a as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '1,2');
             $list = array();
             foreach ($s as $item) {
                 $list[] = $item->name;
             }
             asrt(implode(',', $list), '2,1');
             $list = array();
             foreach ($b as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0');
             $list = array();
             foreach ($x as $item) {
                 $list[] = $item->name;
             }
             sort($list);
             asrt(implode(',', $list), '0,1');
             $first = reset($a);
             asrt($first->getMeta('type'), 'army');
             $first = reset($s);
             asrt($first->getMeta('type'), 'soldier');
             $first = reset($b);
             asrt($first->getMeta('type'), 'building');
             $first = reset($x);
             asrt($first->getMeta('type'), 'book');
         } elseif ($counter === 1) {
             asrt($w->name, 'w1');
             asrt((string) $t->name, '1');
             asrt(count($t->sharedArmy), 2);
             $list = array();
//.........这里部分代码省略.........
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:101,代码来源:Preloading.php


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