本文整理汇总了PHP中Doctrine\Common\Collections\Collection::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::toArray方法的具体用法?PHP Collection::toArray怎么用?PHP Collection::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Collection
的用法示例。
在下文中一共展示了Collection::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: getRoles
/**
* Get roles
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRoles()
{
$rolesArray = $this->roles->toArray();
$stringRoles = array();
for ($i = 0; $i < sizeof($rolesArray); $i++) {
$stringRoles[$i] = $rolesArray[$i]->getRolename();
}
return $stringRoles;
}
示例3: getEntities
/**
* @return array
*/
public function getEntities($modifyValue = true)
{
// Modify the value to illustrate the difference between by value and by reference
if ($modifyValue) {
foreach ($this->entities as $entity) {
$entity->setField('Modified from getEntities getter', false);
}
}
return $this->entities->toArray();
}
示例4: getMutations
/**
* @return ClientMutation[]
*/
public function getMutations()
{
$mutations = $this->mutations->toArray();
usort($mutations, function (ClientMutation $ma, ClientMutation $mb) {
if ($ma->getId() === $mb->getId()) {
return 0;
}
return $ma->getId() > $mb->getId() ? -1 : 1;
});
return $mutations;
}
示例5: __construct
public function __construct(PageMediaCollectionAdminType $type, Collection $mediaSet)
{
parent::__construct(['media_set' => $type]);
$this->type = $type;
$this->mediaSet = $mediaSet;
$this->toDelete = $mediaSet->toArray();
}
示例6: getOptions
/**
* {@inheritdoc}
*/
public function getOptions()
{
if (!$this->hasParent()) {
return $this->options;
}
return new ArrayCollection(array_merge($this->parent->getOptions()->toArray(), $this->options->toArray()));
}
示例7: getTotalItemNumber
/**
* Return the total amount of items
* added to the Cart
*
* @return integer
*/
public function getTotalItemNumber()
{
$totalItems = array_reduce($this->cartLines->toArray(), function ($previousTotal, CartLineInterface $current) {
return $previousTotal + $current->getQuantity();
});
return is_null($totalItems) ? 0 : $totalItems;
}
示例8: serializeCollection
public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context)
{
$viewModelClass = null;
if ($this->viewModel !== null) {
$viewModelClass = get_class($this->viewModel);
}
// Only serialize to HalCollection when:
// 1. We're not rendering a view model (viewModel is NULL). So we are respecting the defined type.
// 2. We're actually rendering to Hal.
// Note that we're using the class name because other view models might inherit from HalJsonModel...
if ($viewModelClass == 'ZF\\Hal\\View\\HalJsonModel') {
return new HalCollection($collection->toArray());
}
// We change the base type, and pass through possible parameters.
$type['name'] = 'array';
return $visitor->visitArray($collection->toArray(), $type, $context);
}
示例9: getAlternateNamesArray
/**
* Get alternate names as a simple array
*
* @return string[]
*/
public function getAlternateNamesArray()
{
if (empty($this->alternateNamesArray)) {
return array_map(function (AlternateName $alternateName) {
return $alternateName->getName();
}, $this->alternateNames->toArray());
}
return $this->alternateNamesArray;
}
示例10: getRoles
public function getRoles()
{
$rolesArray = [];
foreach ($this->roles->toArray() as $role) {
if ($role instanceof Role) {
$rolesArray[] = $role->getRole();
}
}
return $rolesArray;
}
示例11: transform
/**
* Transforms a collection into an array.
*
* @param Collection $collection A collection of entities
*
* @return mixed An array of entities
*
* @throws TransformationFailedException
*/
public function transform($collection)
{
if (null === $collection) {
return array();
}
if (!$collection instanceof Collection) {
throw new TransformationFailedException('Expected a Doctrine\\Common\\Collections\\Collection object.');
}
return $collection->toArray();
}
示例12: transform
/**
* Transforms a collection into an array.
*
* @param Collection $collection A collection of entities
*
* @return mixed An array of entities
*
* @throws UnexpectedTypeException
*/
public function transform($collection)
{
if (null === $collection) {
return array();
}
if (!$collection instanceof Collection) {
throw new UnexpectedTypeException($collection, 'Doctrine\\Common\\Collections\\Collection');
}
return $collection->toArray();
}
示例13: clearContainers
/**
* Clear containers, that were not submitted
*/
protected function clearContainers()
{
if (!$this->getPresenter(FALSE) || !$this->getForm()->isSubmitted()) {
return;
// only if attached to presenter & submitted
}
foreach ($this->collection->toArray() as $entity) {
if (!$this->getMapper()->getComponent($entity)) {
$this->getMapper()->remove($entity);
}
}
}
示例14: removeElement
/**
* Removes the specified element from the collection, if it is found.
*
* @param mixed $element The element to remove.
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
function removeElement($element)
{
$this->checkType($element);
$this->initialize();
/** @var $eTerm EntityTerm */
foreach ($this->collection->toArray() as $eTerm) {
if ($eTerm->getTerm() === $element) {
$this->setDirty(true);
return $this->collection->removeElement($eTerm);
}
}
return false;
}
示例15: serializeCollection
public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context)
{
// We change the base type, and pass through possible parameters.
$type['name'] = 'array';
//don't include items that will produce null elements
$dataArray = [];
foreach ($collection->toArray() as $element) {
if (!$context->isVisiting($element)) {
$dataArray[] = $element;
}
}
return $visitor->visitArray($dataArray, $type, $context);
}