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


PHP Collections\Collection类代码示例

本文整理汇总了PHP中Doctrine\Common\Collections\Collection的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: intersectUnion

 /**
  * This function performs a kind of "intersection union" operation, and is useful especially when dealing
  * with dynamic forms. For instance, if a collection contains existing elements and a form remove one of those
  * elements, this function will return a Collection that contains all the elements from $collection1, minus ones
  * that are not present in $collection2. This is used internally in the DoctrineModule hydrator, so that the
  * work is done for you automatically
  *
  * @param  Collection $collection1
  * @param  Collection $collection2
  * @return Collection
  */
 public static function intersectUnion(Collection $collection1, Collection $collection2)
 {
     // Don't make the work both
     if ($collection1 === $collection2) {
         return $collection1;
     }
     $toRemove = array();
     foreach ($collection1 as $key1 => $value1) {
         $elementFound = false;
         foreach ($collection2 as $key2 => $value2) {
             if ($value1 === $value2) {
                 $elementFound = true;
                 unset($collection2[$key2]);
                 break;
             }
         }
         if (!$elementFound) {
             $toRemove[] = $key1;
         }
     }
     // Remove elements that are in $collection1 but not in $collection2
     foreach ($toRemove as $key) {
         $collection1->remove($key);
     }
     // Add elements that are in $collection2 but not in $collection1
     foreach ($collection2 as $value) {
         $collection1->add($value);
     }
     return $collection1;
 }
开发者ID:rrmodi88,项目名称:DoctrineModule,代码行数:41,代码来源:CollectionUtils.php

示例2: 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

示例3: addError

 /**
  * @param mixed $context
  * @param Collection|null $errors
  */
 protected function addError($context, Collection $errors = null)
 {
     if ($errors && $this->getMessage()) {
         $messageParameters = $this->getMessageParameters($context);
         $errors->add(array('message' => $this->getMessage(), 'parameters' => $messageParameters));
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:11,代码来源:AbstractCondition.php

示例4: let

 function let(LoaderInterface $loader, Collection $resourcesToThemes, ThemeInterface $theme)
 {
     $theme->getLogicalName()->willReturn("sylius/sample-theme");
     $resourcesToThemes->get(realpath($this->getThemeTranslationResourcePath()))->willReturn($theme);
     $resourcesToThemes->get(realpath($this->getVanillaTranslationResourcePath()))->willReturn(null);
     $this->beConstructedWith($loader, $resourcesToThemes);
 }
开发者ID:liverbool,项目名称:dos-theme-bundle,代码行数:7,代码来源:LoaderSpec.php

示例5:

 function it_applies_choice_filter_on_datasource_for_collection_value(FilterDatasourceAdapterInterface $datasource, Collection $collection, $utility)
 {
     $collection->count()->willReturn(2);
     $collection->getValues()->willReturn(['foo', 'bar']);
     $utility->applyFilter($datasource, 'data_name_key', 'IN', ['foo', 'bar'])->shouldBeCalled();
     $this->apply($datasource, ['value' => $collection, 'type' => AjaxChoiceFilterType::TYPE_CONTAINS]);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:7,代码来源:ChoiceFilterSpec.php

示例6: filterDeleted

 /**
  * @param Collection $collection
  *
  * @return ArrayCollection
  */
 private function filterDeleted(Collection $collection) : ArrayCollection
 {
     // getValues => reset keys
     return new ArrayCollection($collection->filter(function ($entity) {
         return !$entity instanceof SoftDeletableInterface || $entity->isDeleted() === false;
     })->getValues());
 }
开发者ID:staspiv,项目名称:rest-bundle,代码行数:12,代码来源:SoftDeletableTrait.php

示例7: addCategoryParent

 private function addCategoryParent(CategoryInterface $category = null, Collection $collection)
 {
     if (null !== $category) {
         $collection->add($category);
         $this->addCategoryParent($category->getParent(), $collection);
     }
 }
开发者ID:WellCommerce,项目名称:CategoryBundle,代码行数:7,代码来源:CategoryRepository.php

示例8: setDomains

 /**
  * Twitter requires domains without scheme
  *
  * @param Doctrine\Common\Collections\Collection
  */
 public function setDomains(Collection $domains)
 {
     $remap = $domains->map(function ($item) {
         return str_replace(array("https://", "http://"), '', $item);
     }, $domains);
     $this->domains = $remap;
 }
开发者ID:antimattr,项目名称:twitter-marketplace,代码行数:12,代码来源:Merchant.php

示例9: processConfiguration

 /**
  * {@inheritdoc}
  */
 public function processConfiguration(Collection $collection)
 {
     $config = [];
     $collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) {
         $config[$configuration->getName()] = $configuration->getValue();
     });
     return $config;
 }
开发者ID:pguso,项目名称:WellCommerce,代码行数:11,代码来源:AbstractPaymentProcessor.php

示例10: clearPreviousCollection

 /**
  * Resets previous photo collection
  *
  * @param Collection $collection
  */
 protected function clearPreviousCollection(Collection $collection)
 {
     if ($collection->count()) {
         foreach ($collection as $item) {
             $collection->removeElement($item);
         }
     }
 }
开发者ID:pguso,项目名称:WellCommerce,代码行数:13,代码来源:ProductPhotoCollectionToArrayTransformer.php

示例11: removeEmpresa

 /**
  * @param Empresa $empresa
  */
 public function removeEmpresa($empresa)
 {
     if ($this->empresas->contains($empresa)) {
         $empresa->setDirector(null);
         $this->empresas->removeElement($empresa);
     }
 }
开发者ID:bixlabs,项目名称:concepto-sises,代码行数:10,代码来源:Director.php

示例12: removeItem

 /**
  * Remove item.
  *
  * @param \SWP\Component\Bridge\Model\Item $item
  */
 public function removeItem(\SWP\Component\Bridge\Model\Item $item)
 {
     if ($this->items->contains($item)) {
         $this->items->removeElement($item);
         $item->setPackage(null);
     }
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:12,代码来源:Package.php

示例13: addPost

 /**
  * Adds a post top the User's authored Posts.
  *
  * Post Author needs to be updated manually.
  *
  * @param Post $addPost
  * @return User
  */
 public function addPost(Post $addPost)
 {
     if (!$this->getAuthoredPosts()->contains($addPost)) {
         $this->authoredPosts->add($addPost);
     }
     return $this;
 }
开发者ID:warhuhn,项目名称:log-blog,代码行数:15,代码来源:User.php

示例14: addParent

 /**
  * @param Role $parent
  */
 public function addParent(Role $parent)
 {
     if ($this->parents->contains($parent)) {
         throw new LogicException(sprintf("Parent role '%s' already assigned.", $parent->getId()));
     }
     $this->parents->add($parent);
 }
开发者ID:Achse,项目名称:petrhejna,代码行数:10,代码来源:Role.php

示例15: removeImage

 /**
  * {@inheritdoc}
  */
 public function removeImage(TaxonImageInterface $image)
 {
     if ($this->hasImage($image)) {
         $image->setTaxon(null);
         $this->images->removeElement($image);
     }
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:10,代码来源:Taxon.php


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