作者:rrmodi8
项目:DoctrineModul
/**
* 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;
}
作者:zend-module
项目:zfc-user-rbac-doctrine-or
/**
* Set the list of roles
* @param Collection $roles
*/
public function setRoles(Collection $roles)
{
$this->roles->clear();
foreach ($roles as $role) {
$this->roles[] = $role;
}
}
作者:xamin12
项目:platfor
/**
* @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));
}
}
作者:liverboo
项目:dos-theme-bundl
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);
}
作者:alexisfroge
项目:pim-community-de
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]);
}
作者:staspi
项目:rest-bundl
/**
* @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());
}
作者:WellCommerc
项目:CategoryBundl
private function addCategoryParent(CategoryInterface $category = null, Collection $collection)
{
if (null !== $category) {
$collection->add($category);
$this->addCategoryParent($category->getParent(), $collection);
}
}
作者:antimatt
项目:twitter-marketplac
/**
* 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;
}
作者:pgus
项目:WellCommerc
/**
* {@inheritdoc}
*/
public function processConfiguration(Collection $collection)
{
$config = [];
$collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) {
$config[$configuration->getName()] = $configuration->getValue();
});
return $config;
}
作者:pgus
项目:WellCommerc
/**
* Resets previous photo collection
*
* @param Collection $collection
*/
protected function clearPreviousCollection(Collection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
作者:wellcommerc
项目:wellcommerc
protected function synchronizeOptions(Collection $options)
{
$this->options->map(function (VariantOptionInterface $option) use($options) {
if (false === $options->contains($option)) {
$this->options->removeElement($option);
}
});
}
作者:abdeldaye
项目:pim-community-de
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']);
}
作者:ashutosh-srija
项目:findit_akene
/**
* 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);
}
作者:Sywooc
项目:WellCommerc
/**
* 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();
});
}
作者:WellCommerc
项目:AttributeBundl
protected function syncNewAttributes(Collection $attributes)
{
$attributes->map(function (AttributeInterface $attribute) {
if (false === $this->attributes->contains($attribute)) {
$attribute->addValue($this);
}
});
}
作者:antramp
项目:cr
/**
* @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;
}
作者:WellCommerc
项目:CoreBundl
/**
* 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);
}
}
}
作者:bixlab
项目:concepto-sise
/**
* @param Empresa $empresa
*/
public function removeEmpresa($empresa)
{
if ($this->empresas->contains($empresa)) {
$empresa->setDirector(null);
$this->empresas->removeElement($empresa);
}
}
作者:superdes
项目:web-publishe
/**
* 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);
}
}
作者:warhuh
项目:log-blo
/**
* 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;
}