當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dog::write方法代碼示例

本文整理匯總了PHP中Dog::write方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dog::write方法的具體用法?PHP Dog::write怎麽用?PHP Dog::write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dog的用法示例。


在下文中一共展示了Dog::write方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCallback_ManyConditions_CalledBack

 /**
  * @throws \ValidationException
  * @throws null
  */
 public function testCallback_ManyConditions_CalledBack()
 {
     $dog = new Dog();
     $dog->Name = 'Johnny';
     $owner1 = new Human();
     $owner1->Name = 'Bob';
     $owner2 = new Human();
     $owner2->Name = 'Wot';
     $cat = new Cat();
     $cat->Name = 'Agnis';
     $afterExists = new \OnAfterExists(function () use($dog) {
         $dog->write();
     });
     $afterExists->addCondition($owner1, function ($owner) use($dog) {
         $dog->Name .= ' ' . $owner->Name;
         $dog->OwnerID = $owner->ID;
     });
     $afterExists->addCondition($owner2, function ($owner) use($dog) {
         $dog->Name .= ' ' . $owner->Name;
         $dog->OwnerID = $owner->ID;
     });
     $afterExists->addCondition($cat, function ($cat) use($dog) {
         $dog->Name .= ' ' . $cat->Name;
     });
     $owner1->write();
     $this->assertFalse($dog->exists());
     $owner2->write();
     $this->assertFalse($dog->exists());
     $cat->write();
     $this->assertTrue($dog->exists());
     $this->assertEquals($owner2->ID, $dog->OwnerID);
     $this->assertEquals('Johnny Bob Wot Agnis', $dog->Name);
 }
開發者ID:helpfulrobot,項目名稱:littlegiant-silverstripe-batchwrite,代碼行數:37,代碼來源:OnAfterExistsTest.php

示例2: testBranchDeleteIDs_DeleteManyIDs_ObjectsDeleted

 /**
  * @throws \ValidationException
  * @throws null
  */
 public function testBranchDeleteIDs_DeleteManyIDs_ObjectsDeleted()
 {
     $className = '';
     $ids = array();
     for ($i = 0; $i < 100; $i++) {
         $dog = new Dog();
         $dog->Name = 'Pup ' . $i;
         $dog->Color = 'Fifty Shade No. ' . $i;
         $dog->write();
         $className = $dog->ClassName;
         $ids[] = $dog->ID;
     }
     $batch = new \Batch();
     $batch->deleteIDs($className, $ids);
     $this->assertEquals(0, Dog::get()->Count());
 }
開發者ID:helpfulrobot,項目名稱:littlegiant-silverstripe-batchwrite,代碼行數:20,代碼來源:BatchDeleteTest.php

示例3: testBatchWrite_ObjectExists_UpdatesObject

 /**
  * @throws \ValidationException
  * @throws null
  */
 public function testBatchWrite_ObjectExists_UpdatesObject()
 {
     $dog = new Dog();
     $dog->Name = 'Harry';
     $dog->Type = 'Trotter';
     $dog->Color = 'Red';
     $dog->write();
     $dog->Name = 'Jimmy';
     $dog->Color = 'Brown';
     $batch = new \Batch();
     $batch->write(array($dog));
     $dog = Dog::get()->byID($dog->ID);
     $this->assertEquals('Jimmy', $dog->Name);
     $this->assertEquals('Trotter', $dog->Type);
     $this->assertEquals('Brown', $dog->Color);
 }
開發者ID:helpfulrobot,項目名稱:littlegiant-silverstripe-batchwrite,代碼行數:20,代碼來源:BatchWriteTest.php

示例4: testCallback_SetOnAfterExistsCallback_CallbackCalled

 /**
  * @throws \ValidationException
  * @throws null
  */
 public function testCallback_SetOnAfterExistsCallback_CallbackCalled()
 {
     $dog1 = new Dog();
     $dog1->Name = 'Jim bob';
     $dog2 = new Dog();
     $dog2->Name = 'Super Dog';
     $owner = new Human();
     $owner->Name = 'Hilly Stewart';
     $owner->write();
     $owner->onAfterExistsCallback(function ($owner) use($dog1) {
         $dog1->OwnerID = $owner->ID;
         $dog1->write();
     });
     $owner->write();
     $owner->onAfterExistsCallback(function ($owner) use($dog2) {
         $dog2->OwnerID = $owner->ID;
         $dog2->write();
     });
     $this->assertTrue($owner->exists());
     $this->assertTrue($dog1->exists());
     $this->assertTrue($dog2->exists());
     $this->assertEquals(1, Human::get()->Count());
     $this->assertEquals(2, Dog::get()->Count());
     $this->assertEquals($owner->ID, $dog1->OwnerID);
     $this->assertEquals($owner->ID, $dog2->OwnerID);
 }
開發者ID:helpfulrobot,項目名稱:littlegiant-silverstripe-batchwrite,代碼行數:30,代碼來源:WriteCallbackTest.php


注:本文中的Dog::write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。