from() public static method

Constructs a new traversable object from the supplied elements.
public static from ( array | Traversable $elements, Pinq\Iterators\IIteratorScheme $scheme = null, Traversable $source = null ) : pinq\ITraversable
$elements array | Traversable
$scheme Pinq\Iterators\IIteratorScheme
$source Traversable
return pinq\ITraversable
コード例 #1
0
ファイル: IteratorSchemeTest.php プロジェクト: timetoogo/pinq
 /**
  * @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);
 }
コード例 #2
0
ファイル: Select.php プロジェクト: timetoogo/pinq.demo.sql
 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');
     }
 }
コード例 #3
0
 /**
  * @dataProvider interpreters
  */
 public function testAliasedTypeHintClass()
 {
     $valueSet = [[Traversable::from([])]];
     $this->assertRecompilesCorrectly(function (AliasedTraversable $traversable) {
         return $traversable;
     }, $valueSet);
 }
コード例 #4
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());
 }
コード例 #5
0
 /**
  * @expectedException \Pinq\PinqException
  */
 public function testCompiledRequestQueryHasherThrowsExceptionForQueryableWithoutDSLProvider()
 {
     $hasher = ParameterHasher::compiledRequestQuery();
     $hasher->hash((new \Pinq\Providers\Traversable\Provider(Traversable::from([])))->createQueryable());
 }