Author: Elliot Levin (elliotlevin@hotmail.com)
Inheritance: implements pinq\ITraversable, implements Pinq\Interfaces\IOrderedTraversable
Exemplo n.º 1
0
 public function __construct($values = [], IIteratorScheme $scheme = null, Collection $source = null)
 {
     parent::__construct($values, $scheme, $source);
     if ($source === null) {
         $this->toOrderedMap();
     }
 }
Exemplo n.º 2
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 public function count()
 {
     if ($this->elements instanceof \Countable) {
         return $this->elements->count();
     }
     $count = 0;
     foreach ($this->elements as $value) {
         $count++;
     }
     return $count;
 }
Exemplo n.º 4
0
 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');
     }
 }
Exemplo n.º 5
0
 protected function buildQueryResultCollection()
 {
     return new Utilities\QueryResultCollection(Traversable::factory($this->buildIteratorScheme()));
 }
Exemplo n.º 6
0
 /**
  * @dataProvider interpreters
  */
 public function testAliasedTypeHintClass()
 {
     $valueSet = [[Traversable::from([])]];
     $this->assertRecompilesCorrectly(function (AliasedTraversable $traversable) {
         return $traversable;
     }, $valueSet);
 }
Exemplo n.º 7
0
 public function __construct(callable $traversableFactory = null)
 {
     $this->storage = new \SplObjectStorage();
     $this->traversableFactory = $traversableFactory ?: Traversable::factory();
 }
Exemplo n.º 8
0
 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());
 }
Exemplo n.º 9
0
 /**
  * @expectedException \Pinq\PinqException
  */
 public function testCompiledRequestQueryHasherThrowsExceptionForQueryableWithoutDSLProvider()
 {
     $hasher = ParameterHasher::compiledRequestQuery();
     $hasher->hash((new \Pinq\Providers\Traversable\Provider(Traversable::from([])))->createQueryable());
 }