public function __construct($values = [], IIteratorScheme $scheme = null, Collection $source = null) { parent::__construct($values, $scheme, $source); if ($source === null) { $this->toOrderedMap(); } }
/** * @dataProvider schemes */ public function testThatArrayCompatibleIsUsedForIndexBy(IIteratorScheme $scheme) { $iterator = Traversable::from([1, 2, 3], $scheme)->indexBy(function () { return new \stdClass(); })->getIterator(); $this->assertInstanceOf(get_class($scheme->arrayCompatibleIterator(new \EmptyIterator())), $iterator); }
public function count() { if ($this->elements instanceof \Countable) { return $this->elements->count(); } $count = 0; foreach ($this->elements as $value) { $count++; } return $count; }
protected function retrieveValues(\PDOStatement $statement) { $statement->setFetchMode(\PDO::FETCH_ASSOC); switch ($this->retrievalMode) { case Values::AS_ARRAY: return $statement->fetchAll(); case Values::AS_ARRAY_COMPATIBLE_ITERATOR: return new \IteratorIterator($statement); case Values::AS_TRUE_ITERATOR: return new \IteratorIterator($statement); case Values::AS_TRAVERSABLE: return Traversable::from($statement); case Values::AS_COLLECTION: return Collection::from($statement); default: throw new PinqDemoSqlException('Unsupported value retrieval mode'); } }
protected function buildQueryResultCollection() { return new Utilities\QueryResultCollection(Traversable::factory($this->buildIteratorScheme())); }
/** * @dataProvider interpreters */ public function testAliasedTypeHintClass() { $valueSet = [[Traversable::from([])]]; $this->assertRecompilesCorrectly(function (AliasedTraversable $traversable) { return $traversable; }, $valueSet); }
public function __construct(callable $traversableFactory = null) { $this->storage = new \SplObjectStorage(); $this->traversableFactory = $traversableFactory ?: Traversable::factory(); }
public function testComputesResultsFromUsingMostApplicableParentRequest() { $sourceExpression = $this->queryable->getExpression(); $this->queryResultsCollection->saveResults($sourceExpression, \Pinq\Traversable::from([1])->select(function () { $this->assertTrue(false, 'Source expression results should not be called'); })->getIterator()); $subscopeQueryable = $this->queryable->skip(5); $this->queryResultsCollection->saveResults($subscopeQueryable->getExpression(), [5, 6, 7, 8, 0]); $subSubscopeQueryable = $subscopeQueryable->select(function ($i) { return $i * 10; })->indexBy(function ($i) { return $i / 5; }); $this->assertTrue($this->queryResultsCollection->tryComputeResults($subSubscopeQueryable->getExpression(), $results)); $this->assertInstanceOf(ITraversable::ITRAVERSABLE_TYPE, $results); /** @var $results ITraversable */ $this->assertSame([10 => 50, 12 => 60, 14 => 70, 16 => 80, 0 => 0], $results->asArray()); }
/** * @expectedException \Pinq\PinqException */ public function testCompiledRequestQueryHasherThrowsExceptionForQueryableWithoutDSLProvider() { $hasher = ParameterHasher::compiledRequestQuery(); $hasher->hash((new \Pinq\Providers\Traversable\Provider(Traversable::from([])))->createQueryable()); }