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


PHP Collection::clear方法代码示例

本文整理汇总了PHP中Collection::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::clear方法的具体用法?PHP Collection::clear怎么用?PHP Collection::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: reverseTransform

 /**
  * @param array $ids
  * @param Collection $collection
  */
 public function reverseTransform($ids, $collection)
 {
     if (count($ids) == 0) {
         // don't check for collection count, a straight clear doesnt initialize the collection
         $collection->clear();
         return $collection;
     }
     $em = $this->getOption('em');
     $metadata = $em->getClassMetadata($this->getOption('className'));
     $reflField = $metadata->getReflectionProperty($metadata->identifier[0]);
     foreach ($collection as $object) {
         $key = array_search($reflField->getValue($object), $ids);
         if (false === $key) {
             $collection->removeElement($object);
         } else {
             unset($ids[$key]);
         }
     }
     // @todo: This can be greatly optimized into a single SELECT .. WHERE id IN () query.
     foreach ($ids as $id) {
         $entity = $em->find($this->getOption('className'), $id);
         if (!$entity) {
             throw new TransformationFailedException("Selected entity of type '" . $this->getOption('className') . "' by id '" . $id . "' which is not present in the database.");
         }
         $collection->add($entity);
     }
     return $collection;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:32,代码来源:CollectionToChoiceTransformer.php

示例2: clear

 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->mapping !== null && isset($this->mapping['embedded'])) {
         foreach ($this->coll as $element) {
             $this->dm->getUnitOfWork()->scheduleOrphanRemoval($element);
         }
     }
     $this->coll->clear();
     $this->changed();
     $this->dm->getUnitOfWork()->scheduleCollectionDeletion($this);
     $this->takeSnapshot();
 }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:18,代码来源:PersistentCollection.php

示例3: clear

 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->mapping !== null && isset($this->mapping['embedded'])) {
         foreach ($this->coll as $element) {
             $this->uow->scheduleOrphanRemoval($element);
         }
     }
     $this->mongoData = array();
     $this->coll->clear();
     if ($this->mapping['isOwningSide']) {
         $this->changed();
         $this->uow->scheduleCollectionDeletion($this);
         $this->takeSnapshot();
     }
 }
开发者ID:richardmiller,项目名称:mongodb-odm,代码行数:21,代码来源:PersistentCollection.php

示例4: testIsEmptyClear

 public function testIsEmptyClear()
 {
     $this->assertEquals(false, $this->collection->isEmpty());
     $this->collection->clear();
     $this->assertEquals(true, $this->collection->isEmpty());
 }
开发者ID:dtkahl,项目名称:php-array-tools,代码行数:6,代码来源:CollectionTest.php

示例5: clear

 /**
  * Removes all of the elements from this collection.
  * @return void
  * @throws NotSupportedException
  */
 public function clear()
 {
     parent::clear();
     $this->loaded = false;
 }
开发者ID:matak,项目名称:dbrecord,代码行数:10,代码来源:LazyCollection.php

示例6: clear

 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     $this->_initialize();
     $result = $this->_coll->clear();
     if ($this->_association->isOwningSide) {
         $this->_changed();
         $this->_em->getUnitOfWork()->scheduleCollectionDeletion($this);
     }
     return $result;
 }
开发者ID:andreia,项目名称:doctrine,代码行数:13,代码来源:PersistentCollection.php


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