protected function synchronizeOptions(Collection $options) { $this->options->map(function (VariantOptionInterface $option) use($options) { if (false === $options->contains($option)) { $this->options->removeElement($option); } }); }
public function testMap() { $this->_coll->add(1); $this->_coll->add(2); $res = $this->_coll->map(function ($e) { return $e * 2; }); $this->assertEquals(array(2, 4), $res->toArray()); }
/** * {@inheritdoc} */ public function setValues(Collection $collection) { if (null !== $this->values) { $this->values->map(function (AttributeValueInterface $value) use($collection) { if (false === $collection->contains($value)) { $this->removeValue($value); } }); } $this->values = $collection; }
/** * {@inheritdoc} */ public function setAttributes(Collection $attributes) { if ($this->attributes instanceof Collection) { $this->attributes->map(function (AttributeInterface $attribute) use($attributes) { if (false === $attributes->contains($attribute)) { $this->removeAttribute($attribute); } }); } $this->attributes = $attributes; }
/** * {@inheritDoc} */ public function map(Closure $func) { $mapped = $this->collection->map($func); // validate mapped elements array_map($this->getIdentityExtractor(), $mapped->toArray()); return new static($mapped); }
/** * 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; }
/** * Generates a tree for given children elements * * @param Collection $collection * @param Collection $children * * @return array */ protected function generateTree(Collection $collection, Collection $children) { $children->map(function (AdminMenuInterface $menuItem) use($collection, &$tree) { $tree[] = ['routeName' => $menuItem->getRouteName(), 'cssClass' => $menuItem->getCssClass(), 'name' => $menuItem->getName(), 'children' => $this->generateTree($collection, $this->filterElements($collection, $menuItem))]; }); return $tree; }
protected function getCollectionValue(Collection $collection) { $value = 0; $collection->map(function (ReportRow $row) use(&$value) { $value += $row->getValue(); }); return $value; }
/** * {@inheritdoc} */ public function processConfiguration(Collection $collection) { $config = []; $collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) { $config[$configuration->getName()] = $configuration->getValue(); }); return $config; }
/** * {@inheritdoc} */ public function getShippingCostWeight() { $weight = 0; $this->products->map(function (OrderProduct $orderProduct) use(&$weight) { $weight += $orderProduct->getQuantity() * $orderProduct->getWeight(); }); return $weight; }
/** * @return Money */ public function getTotal() : Money { $total = new Money(0); $this->lineItems->map(function (LineItem $lineItem) use(&$total) { $total = $total->add($lineItem->getPrice()); }); return $total; }
protected function syncNewAttributes(Collection $attributes) { $attributes->map(function (AttributeInterface $attribute) { if (false === $this->attributes->contains($attribute)) { $attribute->addValue($this); } }); }
/** * Get currencies * * @return array|string[] */ public function getCurrencies() { $currencies = $this->currencies->map(function (PriceListCurrency $priceListCurrency) { return $priceListCurrency->getCurrency(); })->toArray(); sort($currencies); return $currencies; }
protected function getAttributeValues(Collection $collection) { $values = []; $collection->map(function (AttributeValueInterface $value) use(&$values) { $values[] = ['id' => $value->getId(), 'name' => $value->translate()->getName()]; }); return $values; }
/** * 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(); }); }
/** * Returns product statuses * * @param int $limit * @param string $orderBy * @param string $orderDir * * @return array */ public function getProductReviewAverage(Collection $collection) { $totalRating = 0; $reviewsTotal = $collection->count(); $collection->map(function (ProductReviewInterface $review) use(&$totalRating) { $totalRating += $review->getRating(); }); return $reviewsTotal > 0 ? round($totalRating / $reviewsTotal, 2) : 0; }
public function transformOptions(Collection $collection = null) : array { if (null === $collection) { return []; } $values = []; $collection->map(function (VariantOptionInterface $variantOption) use(&$values) { $values[$variantOption->getAttribute()->getId()] = $variantOption->getAttributeValue()->getId(); }); return $values; }
/** * {@inheritdoc} */ public function setAttributes(Collection $attributes) { if (null !== $this->attributes) { $this->attributes->map(function (ProductAttributeInterface $productAttribute) use($attributes) { if (false === $attributes->contains($productAttribute)) { $this->removeAttribute($productAttribute); } }); } $this->attributes = $attributes; }
/** * Transforms values collection to identifiers * * @param PersistentCollection $collection * * @return array */ public function transformValues(Collection $collection = null) { if (null === $collection) { return []; } $values = []; $collection->map(function (AttributeValueInterface $attributeValue) use(&$values) { $values[$attributeValue->getAttribute()->getId()] = $attributeValue->getId(); }); return $values; }
/** * @param Collection $permissions * @param array $secondaryPermissions */ protected function mergePermissions(Collection $permissions, array $secondaryPermissions = []) { foreach ($secondaryPermissions as $rolePermissions) { /** @var Collection $rolePermissions */ $rolePermissions->map(function (Permission $permission) { $this->add($permission, !$permission->isAllowed()); }); } $permissions->map(function (Permission $permission) { $this->add($permission, !$permission->isAllowed()); }); }
/** * {@inheritdoc} */ public function setGroups(Collection $groups) { $this->groups->map(function (AttributeGroupInterface $group) use($groups) { if (false === $groups->contains($group)) { $group->removeAttribute($this); } }); $groups->map(function (AttributeGroupInterface $group) { if (false === $this->groups->contains($group)) { $group->addAttribute($this); } }); }
/** * Apply menu filters to Menu * * @param Collection $menuNodes Menu nodes * @param string $menuCode Menu code * @param string $stage Stage * * @return $this Self object */ private function applyModifiersToMenuNodes(Collection $menuNodes, $menuCode, $stage) { $menuNodes->map(function (NodeInterface $menuNode) use($menuCode, $stage) { $this->applyModifiersToMenuNodes($menuNode->getSubnodes(), $menuCode, $stage); $menuModifiers = $this->getElementsByMenuCodeAndStage($menuCode, $stage); /** * @var MenuModifierInterface $menuModifier */ foreach ($menuModifiers as $menuModifier) { $menuModifier->modify($menuNode); } }); return $this; }
/** * @param ConsumerContainer $consumerContainer * @param AMQPMessage $message * * @throws ConsumerContainerException * @return mixed|null */ private function invoke(ConsumerContainer $consumerContainer, AMQPMessage $message) { $payload = $this->serializer->deserialize($message->body, $consumerContainer->getMessageClass(), 'json'); try { $result = $consumerContainer->invoke($payload); } catch (Exception $e) { $containerException = new ConsumerContainerException($consumerContainer, $message, $payload, $e); if ($this->errorHandlers->isEmpty()) { throw $containerException; } $this->errorHandlers->map(function (ErrorHandlerInterface $handler) use($containerException) { $handler->handle($containerException); }); return null; } return $result; }
/** * Get view * * @return object */ public function getView() { try { $view = new ArticleView(array('number' => $this->number, 'language' => $this->language->getCode(), 'languageId' => $this->language->getId(), 'title' => $this->name, 'updated' => $this->updated, 'published' => $this->published, 'indexed' => $this->indexed, 'onFrontPage' => $this->onFrontPage, 'onSection' => $this->onSection, 'type' => $this->type, 'webcode' => $this->getWebcode(), 'publication_number' => $this->publication ? $this->publication->getId() : null, 'issue_number' => $this->issue ? $this->issue->getNumber() : null, 'section_number' => $this->section ? $this->section->getNumber() : null, 'keywords' => array_filter(explode(',', $this->keywords)))); } catch (EntityNotFoundException $e) { return new ArticleView(); } $view->authors = $this->authors->map(function ($author) { return $author->getView()->name; })->toArray(); $view->topics = $this->topics->map(function ($topic) { return $topic->getView()->name; })->toArray(); $this->addFields($view); return $view; }
/** * {@inheritdoc} */ public function map(\Closure $func) { return $this->inner->map($func); }
/** * {@inheritdoc} */ public function map(Closure $func) { $this->initialize(); return $this->coll->map($func); }
private function duplicateTranslatableEntities(Collection $entities, array $properties, LocaleInterface $targetLocale) { $entities->map(function (LocaleAwareInterface $entity) use($properties, $targetLocale) { $this->duplicateTranslatableEntity($entity, $properties, $targetLocale); }); }
/** * @param Email $email * @param AutoResponseRule[]|Collection $rules * * @return EmailModel[]|Collection */ protected function createReplyEmailModels(Email $email, Collection $rules) { return $rules->map(function (AutoResponseRule $rule) use($email) { $emailModel = $this->emailBuilder->createReplyEmailModel($email, true); $emailModel->setFrom($rule->getMailbox()->getEmail()); $emailModel->setTo([$email->getFromEmailAddress()->getEmail()]); $emailModel->setContexts(array_merge([$email], $emailModel->getContexts())); $this->applyTemplate($emailModel, $rule->getTemplate(), $email); return $emailModel; }); }
protected function synchronizeVariants(Collection $variants) { $this->variants->map(function (VariantInterface $variant) use($variants) { if (false === $variants->contains($variant)) { $this->removeVariant($variant); } }); }
public function traverse(OrderInterface $order) { $this->visitors->map(function (OrderVisitorInterface $visitor) use($order) { $visitor->visitOrder($order); }); }