本文整理汇总了PHP中Doctrine\Common\Collections\ArrayCollection::map方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCollection::map方法的具体用法?PHP ArrayCollection::map怎么用?PHP ArrayCollection::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\ArrayCollection
的用法示例。
在下文中一共展示了ArrayCollection::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getParentPagesQuery
/**
* @param $locale
* @param null $id
* @param bool $showHome
* @param bool $showChildren
* @return \Doctrine\ORM\QueryBuilder|mixed
*/
public function getParentPagesQuery($locale, $id = null, $showHome = false, $showChildren = false)
{
$qb = $this->createQueryBuilder('p');
if (!$showHome) {
$qb->where($qb->expr()->isNull('p.isHome') . ' OR p.isHome <> 1');
}
if ($id) {
if (!$showChildren) {
/** @var $page PageInterface */
$page = $this->find($id);
$collection = new ArrayCollection($page->getAllChildren());
$childrenIds = $collection->map(function (PageInterface $p) {
return $p->getId();
});
if ($childrenIds->count()) {
$qb->andWhere($qb->expr()->notIn('p.id', $childrenIds->toArray()));
}
}
$qb->andWhere($qb->expr()->neq('p.id', $id));
}
$qb->andWhere('p.locale = :locale');
$qb->orderBy('p.path', 'ASC');
$qb->setParameter(':locale', $locale);
return $qb;
}
示例2: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
if (!$this->isEnabled()) {
return;
}
$limit = $this->container->getParameter('fixtures_product_limit');
$faker = $this->getFakerGenerator();
$names = [];
for ($i = 0; $i < $limit; $i++) {
$sentence = $faker->unique()->sentence(3);
$name = substr($sentence, 0, strlen($sentence) - 1);
$names[$name] = $name;
}
$products = new ArrayCollection();
foreach ($names as $name) {
$products->add($this->createRandomProduct($name, $manager));
}
$manager->flush();
$products->map(function (ProductInterface $product) {
$product->getCategories()->map(function (CategoryInterface $category) {
$category->setProductsCount($category->getProducts()->count());
$category->setChildrenCount($category->getChildren()->count());
});
});
$manager->flush();
}
示例3: getKnownJobs
/**
* @return ArrayCollection|string[]
*/
public function getKnownJobs()
{
$data = new ArrayCollection($this->findAll());
return $data->map(function (CronJobInterface $o) {
return $o->getCommand();
});
}
示例4: map
public function map(Closure $func)
{
if (null === $this->entries) {
$this->__load___();
}
return $this->entries->map($func);
}
示例5: __toString
/**
* Returns headers collection as string.
*
* @todo: Should implement SerializableInterface
* So we can call serializer on it. Without this freaky __toString method.
*
* This is shit. No time. Have to have working prototype.
*
* @return string
*/
public function __toString()
{
/**
* Walk through array and make it strings
*
* @var ArrayCollection
*/
$collection = $this->collection->map(function ($element) {
return $element->stringify();
});
/**
* Each header in new line, Use Stringify thingy?
*/
return implode("\n\r", $collection->toArray());
}
示例6: getVoteSum
/**
* Returns a summary of the votes up/down/total
*
* @return \stdClass
*/
public function getVoteSum()
{
$votesStats = new \stdClass();
$votesStats->up = 0;
$votesStats->down = 0;
$votesStats->total = 0;
$counter = function ($vote) use($votesStats) {
if ($vote->getValue()) {
$votesStats->up++;
} else {
$votesStats->down++;
}
$votesStats->total += $vote->getValue();
};
$this->votes->map($counter);
return $votesStats;
}
示例7: getMemberUids
/**
* @return ArrayCollection
*
* @Assert\NotBlank()
*/
public function getMemberUids()
{
return $this->memberUids->map(function ($member) {
return $member->get();
})->getValues();
}
示例8: getView
/**
* 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;
}
示例9: testReferenceMany
public function testReferenceMany()
{
$colPush = new ArrayCollection(array(new GH453ReferencedDocument(), new GH453ReferencedDocument(), new GH453ReferencedDocument()));
$colSet = $colPush->map(function ($v) {
return clone $v;
});
$colSetArray = $colPush->map(function ($v) {
return clone $v;
});
$colAddToSet = $colPush->map(function ($v) {
return clone $v;
});
$dm = $this->dm;
$colPush->forAll(function ($k, $v) use($dm) {
$dm->persist($v);
return true;
});
$colSet->forAll(function ($k, $v) use($dm) {
$dm->persist($v);
return true;
});
$colSetArray->forAll(function ($k, $v) use($dm) {
$dm->persist($v);
return true;
});
$colAddToSet->forAll(function ($k, $v) use($dm) {
$dm->persist($v);
return true;
});
$doc = new GH453Document();
$doc->referenceManyPush = $colPush;
$doc->referenceManySet = $colSet;
$doc->referenceManySetArray = $colSetArray;
$doc->referenceManyAddToSet = $colAddToSet;
$this->dm->persist($doc);
$this->dm->flush();
$this->dm->clear();
// No need to assert the value of the referenced document structure
$this->assertBsonArray($doc->id, 'referenceManyPush');
$this->assertBsonArray($doc->id, 'referenceManySet');
$this->assertBsonArray($doc->id, 'referenceManySetArray');
$this->assertBsonArray($doc->id, 'referenceManyAddToSet');
// Check that the value is changed properly
unset($colPush[1], $colSet[1], $colSetArray[1], $colAddToSet[1]);
$doc->referenceManyPush = $colPush;
$doc->referenceManySet = $colSet;
$doc->referenceManySetArray = $colSetArray;
$doc->referenceManyAddToSet = $colAddToSet;
/* Merging must be done after re-assigning the collections, as the
* referenced documents must be re-persisted through the merge cascade.
*/
$doc = $this->dm->merge($doc);
$this->dm->flush();
$this->dm->clear();
$this->assertBsonArray($doc->id, 'referenceManyPush');
$this->assertBsonObject($doc->id, 'referenceManySet');
$this->assertBsonArray($doc->id, 'referenceManySetArray');
$this->assertBsonArray($doc->id, 'referenceManyAddToSet');
}
示例10: toBatch
/**
* @param ArrayCollection $emails
*
* @return string[]
*/
protected function toBatch(ArrayCollection $emails, $deep = true)
{
return $emails->map(function ($email) use($deep) {
return array('email' => $deep ? array('email' => $email) : $email, 'email_type' => 'html');
})->toArray();
}
示例11: getGroupsCode
/**
* @param ArrayCollection $groups
*
* @return array
*/
protected function getGroupsCode(ArrayCollection $groups)
{
return $groups->map(function (GroupInterface $group) {
return $group->getCode();
})->toArray();
}
示例12: getLocaleCodes
/**
* {@inheritdoc}
*/
public function getLocaleCodes()
{
return $this->locales->map(function ($locale) {
return $locale->getCode();
})->toArray();
}
示例13: getMembers
/**
* @return array
* @Assert\Count(min="1",minMessage="member not set")
*/
public function getMembers()
{
return $this->members->map(function ($value) {
return $value->get();
})->getValues();
}
示例14: combinePasswdAndGroup
/**
* Combine the Passwd and Group collections
*
* @param object $passwd The passwd collection
* @param object $group The group collection
*
* @return object The userInfo collection
*/
private function combinePasswdAndGroup(Collection $passwd, Collection $group)
{
$userInfo = new Collection();
/**
* Iterate over all the users in the passwd collection
*/
$passwd->map(function ($user) use($group, $userInfo) {
/**
* Get the groups this user is a member of
*/
$groupItems = $group->filter(function ($group) use($user) {
if (in_array($user["username"], $group["users"])) {
return true;
}
return false;
});
/**
* Get only the group names and store them
*/
$groups = [];
foreach ($groupItems as $groupItem) {
if ($groupItem["name"] != "") {
$groups[] = $groupItem["name"];
}
}
/**
* Add the secondary groups to the user's groups array
*/
$user["groups"] = $groups;
/**
* Get the main group for the current user
*/
$mainGroup = $this->getGroupById($user["gid"])["name"];
/**
* Add the user's main group to the groups list if it isn't already
*/
if (!in_array($mainGroup, $user["groups"])) {
$user["groups"][] = $mainGroup;
}
/**
* Finally, add the user to the userInfo collection
*/
$userInfo->add($user);
});
return $userInfo;
}
示例15: map
function map(\Closure $func)
{
return $this->fields->map($func);
}