本文整理匯總了PHP中Doctrine\Common\Collections\Collection::getIterator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::getIterator方法的具體用法?PHP Collection::getIterator怎麽用?PHP Collection::getIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\Common\Collections\Collection
的用法示例。
在下文中一共展示了Collection::getIterator方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: InvalidArgumentException
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']);
}
示例2: use
function it_creates_an_article(Blog $blog, Title $title, Text $teaser, Collection $rawDisplayables, SlugifierInterface $slugifier, Slug $slug)
{
$slugifier->slugify($title)->shouldBeCalled()->willReturn($slug);
$blog->addPost(Argument::that(function ($argument) use($slug) {
return $argument instanceof Article && $argument->getSlug() === $slug->getWrappedObject();
}))->shouldBeCalled();
$rawDisplayables->getIterator()->willReturn(new \ArrayIterator([]));
$this->create($blog, $title, $teaser, $rawDisplayables)->shouldBeAnInstanceOf(Article::class);
}
示例3:
function it_normalizes_value_with_empty_collection_data(ProductValueInterface $value, AbstractAttribute $attribute, Collection $collection, \Iterator $iterator)
{
$attribute->getCode()->willReturn('code');
$attribute->isLocalizable()->willReturn(false);
$attribute->isScopable()->willReturn(false);
$collection->getIterator()->willReturn($iterator);
$value->getData()->willReturn($collection);
$value->getAttribute()->willReturn($attribute);
$this->normalize($value, 'mongodb_json', [])->shouldReturn(null);
}
示例4:
function it_adds_an_address_when_different_than_the_ones_present_on_the_customer(AddressComparatorInterface $addressComparator, CustomerInterface $customer, AddressInterface $customerAddress, AddressInterface $newAddress, Collection $addresses, \Iterator $iterator)
{
$iterator->rewind()->shouldBeCalled();
$iterator->valid()->willReturn(true);
$iterator->current()->willReturn($customerAddress);
$iterator->valid()->willReturn(false);
$addresses->getIterator()->willReturn($iterator);
$customer->getAddresses()->willReturn($addresses);
$addressComparator->equal($customerAddress, $newAddress)->willReturn(false);
$customer->addAddress($newAddress)->shouldBeCalled();
$this->add($customer, $newAddress);
}
示例5: initialize
/**
* @param Collection $worklogs
* @return void
*/
private function initialize(Collection $worklogs)
{
/** @var \Iterator $iterator */
$iterator = $worklogs->getIterator();
$iterator->rewind();
if ($iterator->valid()) {
while ($iterator->valid()) {
/** @var Worklog $worklog */
$worklog = $iterator->current();
if (!array_key_exists($worklog->getTask()->getId(), $this->elements)) {
$this->elements[$worklog->getTask()->getId()] = new Task($worklog->getTask(), $this->period);
}
/** @var Task $task */
$task = $this->elements[$worklog->getTask()->getId()];
/** @var \DateTime $date */
$date = clone $worklog->getDateStarted();
$date->setTimezone($this->timezone);
$task->addTimeSpent($date, $worklog->getTimeSpent());
$iterator->next();
}
}
}
示例6: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
$this->initialize();
return $this->coll->getIterator();
}
示例7: getIterator
/**
* (PHP 5 >= 5.0.0)<br/>
* Retrieve an external iterator
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
* @return Traversable An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*/
public function getIterator()
{
$this->initialize();
return new InnerTermIterator($this->collection->getIterator());
}
示例8: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
return $this->inner->getIterator();
}
示例9: getIterator
/**
* Allows to iterate over sub properties.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return $this->properties->getIterator();
}
示例10: sortMembersByBalance
/**
* @param Collection $players
*
* @return ArrayCollection
*/
public function sortMembersByBalance(Collection $players)
{
$iterator = $players->getIterator();
$iterator->uasort(function ($a, $b) {
return $b->getBalance() - $a->getBalance();
});
return new ArrayCollection(iterator_to_array($iterator));
}
示例11: testIterator
/**
* @dataProvider provideCollection
*/
public function testIterator(Collection $coll, array $elements)
{
$iterations = 0;
foreach ($coll->getIterator() as $key => $item) {
$this->assertSame($elements[$key], $item, "Item {$key} not match");
$iterations++;
}
$this->assertEquals(count($elements), $iterations, "Number of iterations not match");
}
示例12: sort
/**
* Sorts a doctrine collection from an array of filters
* @param Collection $collection
* @param array $filters
* @return Collection
* @author Yohann Marillet
* @deprecated this function is very slow on large sets of data
*/
public function sort(Collection $collection, array $filters)
{
if (isset($filters['sort'])) {
/** @var \ArrayIterator $it */
$it = $collection->getIterator();
$that = $this;
$it->uasort(function ($first, $second) use($filters, $that) {
$return = 0;
if ($first !== $second) {
$sortFilters = $filters['sort'];
$cur = reset($sortFilters);
while ($return == 0 && false !== $cur) {
$k = key($sortFilters);
$v1 = $that->getValueFromDQLField($first, $k);
$v2 = $that->getValueFromDQLField($second, $k);
if ($v1 != $v2) {
$return = $v1 > $v2 ? 1 : -1;
//var_dump($v1.', '.$v2.' : '.$return);
if ($cur == 'DESC') {
$return = $return * -1;
}
}
$cur = next($sortFilters);
}
}
return $return;
});
}
return $collection;
}