當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。