本文整理汇总了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);
}
示例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]]];
}
示例3: addPermissions
public function addPermissions(Collection $permissions)
{
foreach ($permissions as $permission) {
$this->permissions->add($permission);
}
}
示例4: addTournament
/**
* @param TournamentPlayer $tournament
* @return User
*/
public function addTournament(TournamentPlayer $tournament) : User
{
$this->tournaments->add($tournament);
}
示例5: addChild
/**
* Add a child.
*
* @param RoleInterface|string $child
* @return RoleInterface
*/
public function addChild($child)
{
$this->children->add($child);
return $this;
}