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


PHP PersistentCollection::add方法代碼示例

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


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

示例1: addPost

 public function addPost(Post $post)
 {
     if ($post->getAuthor() !== $this) {
         throw new DomainException('Author is not allowed');
     }
     if ($this->hasPost($post)) {
         throw new DomainException('Post already added');
     }
     $this->posts->add($post);
 }
開發者ID:nebuchar,項目名稱:ddd-blog,代碼行數:10,代碼來源:User.php

示例2: postSetDataProvider

 /**
  * @return array
  */
 public function postSetDataProvider()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $meta = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $existing = (object) ['$existing' => true];
     $removed = (object) ['$removed' => true];
     $added = (object) ['$added' => true];
     $collectionWithElements = new ArrayCollection([$added]);
     $cleanCollection = new PersistentCollection($em, $meta, new ArrayCollection());
     $dirtyCollection = new PersistentCollection($em, $meta, new ArrayCollection([$existing, $removed]));
     $dirtyCollection->takeSnapshot();
     $dirtyCollection->removeElement($removed);
     $dirtyCollection->add($added);
     return ['Initialization with empty value should not be broken' => ['$data' => null, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Empty collection given should set nothing' => ['$data' => new ArrayCollection(), '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Array collection with elements given, should be set to added' => ['$data' => $collectionWithElements, '$expectedAddedData' => [$added], '$expectedRemovedData' => []], 'Clean persistent collection given, should set nothing' => ['$data' => $cleanCollection, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Persistent collection given, should set from diffs' => ['$data' => $dirtyCollection, '$expectedAddedData' => [$added], '$expectedRemovedData' => [$removed]]];
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:18,代碼來源:MultipleEntitySubscriberTest.php

示例3: addPermissions

 public function addPermissions(Collection $permissions)
 {
     foreach ($permissions as $permission) {
         $this->permissions->add($permission);
     }
 }
開發者ID:LeCoyote,項目名稱:epeires2,代碼行數:6,代碼來源:Role.php

示例4: addTournament

 /**
  * @param TournamentPlayer $tournament
  * @return User
  */
 public function addTournament(TournamentPlayer $tournament) : User
 {
     $this->tournaments->add($tournament);
 }
開發者ID:StasPiv,項目名稱:playzone,代碼行數:8,代碼來源:User.php

示例5: addChild

 /**
  * Add a child.
  *
  * @param  RoleInterface|string $child
  * @return RoleInterface
  */
 public function addChild($child)
 {
     $this->children->add($child);
     return $this;
 }
開發者ID:saoke,項目名稱:RbacUserDoctrineOrm,代碼行數:11,代碼來源:Role.php


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