本文整理汇总了PHP中Doctrine\Common\Collections\Collection::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::clear方法的具体用法?PHP Collection::clear怎么用?PHP Collection::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Collection
的用法示例。
在下文中一共展示了Collection::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRoles
/**
* Set the list of roles
* @param Collection $roles
*/
public function setRoles(Collection $roles)
{
$this->roles->clear();
foreach ($roles as $role) {
$this->roles[] = $role;
}
}
示例2: setGroups
/**
* setGroups
*
* Set the users groups.
*
* @param UserGroup[]|\Traversable $groups The collection of user groups to set.
*
* @return $this
*/
public function setGroups($groups)
{
$this->groups->clear();
foreach ($groups as $group) {
$this->addGroup($group);
}
return $this;
}
示例3: setTags
/**
* Set tags
*
* @param Collection $tags Tags
*
* @return Product self Object
*/
public function setTags(Collection $tags)
{
$this->tags->clear();
if (!$tags->isEmpty()) {
foreach ($tags as $tag) {
$this->addTag($tag);
}
}
return $this;
}
示例4: setUsers
/**
* setUsers
*
* Replace all current users with the provided collection.
*
* @param UserInterface[]|Collection $users The new users collection to set.
*
* @return $this
* @throws Exception\InvalidArgumentException If the collection is not an array or \Traversable instance.
*/
public function setUsers($users)
{
if (!is_array($users) && !$users instanceof \Traversable) {
throw new Exception\InvalidArgumentException(sprintf('The \'users\' argument must be an \'array\' or object of type \'%s\'; \'%s\' given in \'%s\'', \Traversable::class, is_object($users) ? get_class($users) : gettype($users), __METHOD__));
}
$this->users->clear();
foreach ($users as $user) {
$this->addUser($user);
}
return $this;
}
示例5: mapToObjects
/**
* Map a data to a collection of model objects.
*
* @param array $data An array of data.
* @param callable $callable The callable you want to call for each row of data.
* @return Collection A collection of objects.
*/
protected function mapToObjects(array $data, callable $callable = null)
{
$this->collection->clear();
if (count($data) > 0) {
foreach ($data as $row) {
if (is_callable($callable)) {
$this->collection->add(call_user_func($callable, $row));
} else {
$this->collection->add($this->instantiateObject($row));
}
}
}
return clone $this->collection;
}
示例6: setTranslations
/**
* @param TranslationInterface[]|Collection $translations
*/
public function setTranslations($translations)
{
$this->translations->clear();
foreach ($translations as $translation) {
$this->addTranslation($translation);
}
}
示例7: clear
/**
* {@inheritdoc}
*/
public function clear()
{
if ($this->initialized && $this->isEmpty()) {
return;
}
if ($this->isOrphanRemovalEnabled()) {
$this->initialize();
foreach ($this->coll as $element) {
$this->uow->scheduleOrphanRemoval($element);
}
}
$this->mongoData = array();
$this->coll->clear();
// Nothing to do for inverse-side collections
if (!$this->mapping['isOwningSide']) {
return;
}
// Nothing to do if the collection was initialized but contained no data
if ($this->initialized && empty($this->snapshot)) {
return;
}
$this->changed();
$this->uow->scheduleCollectionDeletion($this);
$this->takeSnapshot();
}
示例8: testClear
public function testClear()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->_coll->clear();
$this->assertEquals($this->_coll->isEmpty(), true);
}
示例9: setVariants
/**
* {@inheritdoc}
*/
public function setVariants(Collection $variants)
{
$this->variants->clear();
foreach ($variants as $variant) {
$this->addVariant($variant);
}
}
示例10: setOptions
/**
* Sets this variant option values.
*
* @param Collection $options
*
* @return $this Self object
*/
public function setOptions(Collection $options)
{
/*
* We want to be able to assign an empty
* ArrayCollection to variant options
*
* When the collection is not empty, each
* option in the collection will be added
* separately since it needs to update the
* parent product attribute list
*/
if ($options->isEmpty()) {
$this->options = $options;
} else {
$this->options->clear();
}
/**
* @var ValueInterface $option
*/
foreach ($options as $option) {
/*
* We need to update the parent product attribute collection
*/
$this->addOption($option);
}
return $this;
}
示例11: resetAddresses
/**
* Set addresses.
*
* This method could not be named setAddresses because of bug CRM-253.
*
* @param Collection|AbstractAddress[] $addresses
* @return BasePerson
*/
public function resetAddresses($addresses)
{
$this->addresses->clear();
foreach ($addresses as $address) {
$this->addAddress($address);
}
return $this;
}
示例12: resetLocales
/**
* Set children locales
*
* @param Collection|Locale[] $locales
*
* @return Locale
*/
public function resetLocales($locales)
{
$this->childLocales->clear();
foreach ($locales as $locale) {
$this->addChildLocale($locale);
}
return $this;
}
示例13: clear
/**
* {@inheritdoc}
*/
public function clear()
{
if ($this->initialized && $this->isEmpty()) {
return;
}
$this->coll->clear();
$this->changed();
$this->takeSnapshot();
}
示例14: clear
/**
* {@inheritdoc}
*/
public function clear()
{
$this->_initialize();
$result = $this->_coll->clear();
if ($this->_mapping->isOwningSide) {
$this->_changed();
$this->_dm->getUnitOfWork()->scheduleCollectionDeletion($this);
}
return $result;
}
示例15: partition
/**
* {@inheritDoc}
*/
public function partition(Closure $p)
{
$array = $this->toArray();
$this->collection->clear();
foreach ($array as $key => $element) {
$this->collection->set($key, $element);
}
$partitions = $this->collection->partition($p);
return [new static($partitions[0]), new static($partitions[1])];
}