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


PHP Batch::write方法代码示例

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


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

示例1: testWriteManyMany_CreateParentAndChildren_WritesManyMany

 /**
  *
  */
 public function testWriteManyMany_CreateParentAndChildren_WritesManyMany()
 {
     $parent = new Batman();
     $parent->Name = 'Bruce Wayne';
     $parent->Car = 'Bat mobile';
     $children = array();
     for ($i = 0; $i < 5; $i++) {
         $child = new Child();
         $child->Name = 'Soldier #' . $i;
         $children[] = $child;
     }
     $batch = new \Batch();
     $batch->write(array($parent));
     $batch->write($children);
     $sets = array();
     foreach ($children as $child) {
         $sets[] = array($parent, 'Children', $child);
     }
     $batch->writeManyMany($sets);
     $parent = Human::get()->first();
     $this->assertEquals(5, $parent->Children()->Count());
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-batchwrite,代码行数:25,代码来源:BatchWriteManyManyTest.php

示例2: testBatchWrite_DifferentClasses_WritesObjects

 /**
  *
  */
 public function testBatchWrite_DifferentClasses_WritesObjects()
 {
     $dog = new Dog();
     $dog->Name = 'Snuffins';
     $dog->Color = 'Red';
     $cat = new Cat();
     $cat->Name = 'Puff daddy';
     $cat->HasClaws = true;
     $batch = new \Batch();
     $batch->write(array($dog, $cat));
     $this->assertTrue($dog->exists());
     $this->assertTrue($cat->exists());
     $dog = Dog::get()->first();
     $this->assertEquals('Snuffins', $dog->Name);
     $this->assertEquals('Red', $dog->Color);
     $cat = Cat::get()->first();
     $this->assertEquals('Puff daddy', $cat->Name);
     $this->assertEquals(1, $cat->HasClaws);
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-batchwrite,代码行数:22,代码来源:BatchWriteTest.php

示例3: testOnAfterExists_ArrayCondition_CalledBack

 /**
  *
  */
 public function testOnAfterExists_ArrayCondition_CalledBack()
 {
     $parent = new Human();
     $parent->Name = 'Bob';
     $children = array();
     for ($i = 0; $i < 5; $i++) {
         $child = new Child();
         $child->Name = 'Soldier #' . $i;
         $children[] = $child;
     }
     $batch = new \Batch();
     $afterExists = new \OnAfterExists(function () use($batch, $parent, $children) {
         $sets = array();
         foreach ($children as $child) {
             $sets[] = array($parent, 'Children', $child);
         }
         $batch->writeManyMany($sets);
     });
     $afterExists->addCondition($parent);
     $afterExists->addCondition($children);
     $batch->write(array($parent));
     $batch->write($children);
     $parent = Human::get()->first();
     $this->assertEquals(5, $parent->Children()->Count());
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-batchwrite,代码行数:28,代码来源:OnAfterExistsTest.php


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