本文整理汇总了PHP中Doctrine\Common\Collections\Collection::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::map方法的具体用法?PHP Collection::map怎么用?PHP Collection::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Collection
的用法示例。
在下文中一共展示了Collection::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: synchronizeOptions
protected function synchronizeOptions(Collection $options)
{
$this->options->map(function (VariantOptionInterface $option) use($options) {
if (false === $options->contains($option)) {
$this->options->removeElement($option);
}
});
}
示例2: testMap
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());
}
示例3: setValues
/**
* {@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;
}
示例4: setAttributes
/**
* {@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;
}
示例5: map
/**
* {@inheritDoc}
*/
public function map(Closure $func)
{
$mapped = $this->collection->map($func);
// validate mapped elements
array_map($this->getIdentityExtractor(), $mapped->toArray());
return new static($mapped);
}
示例6: 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;
}
示例7: generateTree
/**
* 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;
}
示例8: getCollectionValue
protected function getCollectionValue(Collection $collection)
{
$value = 0;
$collection->map(function (ReportRow $row) use(&$value) {
$value += $row->getValue();
});
return $value;
}
示例9: processConfiguration
/**
* {@inheritdoc}
*/
public function processConfiguration(Collection $collection)
{
$config = [];
$collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) {
$config[$configuration->getName()] = $configuration->getValue();
});
return $config;
}
示例10: getShippingCostWeight
/**
* {@inheritdoc}
*/
public function getShippingCostWeight()
{
$weight = 0;
$this->products->map(function (OrderProduct $orderProduct) use(&$weight) {
$weight += $orderProduct->getQuantity() * $orderProduct->getWeight();
});
return $weight;
}
示例11: getTotal
/**
* @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;
}
示例12: syncNewAttributes
protected function syncNewAttributes(Collection $attributes)
{
$attributes->map(function (AttributeInterface $attribute) {
if (false === $this->attributes->contains($attribute)) {
$attribute->addValue($this);
}
});
}
示例13: getCurrencies
/**
* Get currencies
*
* @return array|string[]
*/
public function getCurrencies()
{
$currencies = $this->currencies->map(function (PriceListCurrency $priceListCurrency) {
return $priceListCurrency->getCurrency();
})->toArray();
sort($currencies);
return $currencies;
}
示例14: getAttributeValues
protected function getAttributeValues(Collection $collection)
{
$values = [];
$collection->map(function (AttributeValueInterface $value) use(&$values) {
$values[] = ['id' => $value->getId(), 'name' => $value->translate()->getName()];
});
return $values;
}
示例15: 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();
});
}