本文整理汇总了PHP中Doctrine\Common\Collections\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: synchronizeOptions
protected function synchronizeOptions(Collection $options)
{
$this->options->map(function (VariantOptionInterface $option) use($options) {
if (false === $options->contains($option)) {
$this->options->removeElement($option);
}
});
}
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:8,代码来源:Variant.php
示例12: InvalidArgumentException
function its_normalize_method_throw_exception_when_required_field_name_key_is_not_passed($serializer, Collection $collection)
{
$collection->getIterator()->willReturn(new \ArrayIterator([4, 8, 15]));
$serializer->normalize(4, null, ['foo' => 'bar'])->willReturn('Four');
$serializer->normalize(8, null, ['foo' => 'bar'])->willReturn('Eight');
$serializer->normalize(15, null, ['foo' => 'bar'])->willReturn('Fifteen');
$this->shouldThrow(new InvalidArgumentException('Missing required "field_name" context value, got "foo"'))->duringNormalize($collection, null, ['foo' => 'bar']);
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:8,代码来源:CollectionNormalizerSpec.php
示例13: getOrderedSteps
/**
* Get steps sorted by order.
*
* @return Collection|Step[]
*/
public function getOrderedSteps()
{
$steps = $this->steps->toArray();
usort($steps, function (Step $stepOne, Step $stepTwo) {
return $stepOne->getOrder() >= $stepTwo->getOrder() ? 1 : -1;
});
return new ArrayCollection($steps);
}
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:13,代码来源:StepManager.php
示例14: extractValues
/**
* Extracts information from collection and appends it to an array of attributes
*
* @param Collection $collection
* @param array $attributes
*/
protected function extractValues(Collection $collection, &$attributes)
{
$collection->map(function (AttributeValueInterface $attributeValue) use(&$attributes) {
$attribute = $attributeValue->getAttribute();
$attributes[$attribute->getId()]['name'] = $attribute->translate()->getName();
$attributes[$attribute->getId()]['values'][$attributeValue->getId()] = $attributeValue->translate()->getName();
});
}
开发者ID:Sywooch,项目名称:WellCommerce,代码行数:14,代码来源:ProductAttributeHelper.php
示例15: syncNewAttributes
protected function syncNewAttributes(Collection $attributes)
{
$attributes->map(function (AttributeInterface $attribute) {
if (false === $this->attributes->contains($attribute)) {
$attribute->addValue($this);
}
});
}
开发者ID:WellCommerce,项目名称:AttributeBundle,代码行数:8,代码来源:AttributeValue.php
示例16: initEntitiesCollectionFromArray
/**
* @param Collection $collection
* @param array $entities
*
* @return Collection
*/
protected function initEntitiesCollectionFromArray(Collection $collection, array $entities)
{
foreach ($entities as $entity) {
$el = new EntityName($entity);
$collection->add($el);
}
return $collection;
}
开发者ID:antrampa,项目名称:crm,代码行数:14,代码来源:ChannelTest.php
示例17: synchronizeCollection
/**
* Removes all elements from old collection which have not been passed in new collection
*
* @param Collection $oldEntities
* @param Collection $newEntities
*/
protected function synchronizeCollection(Collection $oldCollection, Collection $newCollection)
{
foreach ($oldCollection as $oldEntity) {
if (!$newCollection->contains($oldEntity)) {
$newCollection->removeElement($oldEntity);
}
}
}
开发者ID:WellCommerce,项目名称:CoreBundle,代码行数:14,代码来源:CollectionToArrayTransformer.php
示例18: 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
示例19: 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
示例20: 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
注:本文中的Doctrine\Common\Collections\Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论