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


PHP Collection::clear方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:zend-modules,项目名称:zfc-user-rbac-doctrine-orm,代码行数:11,代码来源:User.php

示例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;
 }
开发者ID:alex-patterson-webdev,项目名称:arp-user,代码行数:17,代码来源:UserGroupAwareTrait.php

示例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;
 }
开发者ID:bamper,项目名称:symfony-ecommerce,代码行数:17,代码来源:Product.php

示例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;
 }
开发者ID:alex-patterson-webdev,项目名称:arp-user,代码行数:21,代码来源:UserCollectionAwareTrait.php

示例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;
 }
开发者ID:air-php,项目名称:mapper,代码行数:21,代码来源:Mapper.php

示例6: setTranslations

 /**
  * @param TranslationInterface[]|Collection $translations
  */
 public function setTranslations($translations)
 {
     $this->translations->clear();
     foreach ($translations as $translation) {
         $this->addTranslation($translation);
     }
 }
开发者ID:php-lug,项目名称:lug,代码行数:10,代码来源:TranslatableTrait.php

示例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();
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:28,代码来源:PersistentCollectionTrait.php

示例8: testClear

 public function testClear()
 {
     $this->_coll[] = 'one';
     $this->_coll[] = 'two';
     $this->_coll->clear();
     $this->assertEquals($this->_coll->isEmpty(), true);
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:7,代码来源:CollectionTest.php

示例9: setVariants

 /**
  * {@inheritdoc}
  */
 public function setVariants(Collection $variants)
 {
     $this->variants->clear();
     foreach ($variants as $variant) {
         $this->addVariant($variant);
     }
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:10,代码来源:Product.php

示例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;
 }
开发者ID:VictorMateo,项目名称:elcodi,代码行数:34,代码来源:Variant.php

示例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;
 }
开发者ID:Maksold,项目名称:platform,代码行数:16,代码来源:BasePerson.php

示例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;
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:15,代码来源:Locale.php

示例13: clear

 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     $this->coll->clear();
     $this->changed();
     $this->takeSnapshot();
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:12,代码来源:PersistentCollection.php

示例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;
 }
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:13,代码来源:PersistentCollection.php

示例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])];
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:13,代码来源:IdentityWrapper.php


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