index() final public static method

final public static index ( Expression $value, Expression $index = null ) : IndexExpression
$value Expression
$index Expression
return IndexExpression
コード例 #1
0
ファイル: ComplexParserTest.php プロジェクト: timetoogo/pinq
 /**
  * @dataProvider parsers
  */
 public function testNestedVariableTraversal()
 {
     $function = function () {
         $i->field->method()['index'];
     };
     $this->assertParsedAs($function, [O\Expression::index(O\Expression::methodCall(O\Expression::field(self::variable('i'), O\Expression::value('field')), O\Expression::value('method')), O\Expression::value('index'))]);
 }
コード例 #2
0
ファイル: AST.php プロジェクト: timetoogo/pinq
 public function parseExpressionNode(Node\Expr $node)
 {
     switch (true) {
         case $mappedNode = $this->parseOperatorNode($node):
             return $mappedNode;
         case $node instanceof Node\Scalar && ($mappedNode = $this->parseScalarNode($node)):
             return $mappedNode;
         case $node instanceof Node\Expr\Variable:
             return Expression::variable($this->parseNameNode($node->name));
         case $node instanceof Node\Expr\Array_:
             return $this->parseArrayNode($node);
         case $node instanceof Node\Expr\FuncCall:
             return $this->parseFunctionCallNode($node);
         case $node instanceof Node\Expr\New_:
             return Expression::newExpression($this->parseNameNode($node->class), $this->parseNodes($node->args));
         case $node instanceof Node\Expr\MethodCall:
             return Expression::methodCall($this->parseNode($node->var), $this->parseNameNode($node->name), $this->parseNodes($node->args));
         case $node instanceof Node\Expr\PropertyFetch:
             return Expression::field($this->parseNode($node->var), $this->parseNameNode($node->name));
         case $node instanceof Node\Expr\ArrayDimFetch:
             return Expression::index($this->parseNode($node->var), $node->dim === null ? null : $this->parseNode($node->dim));
         case $node instanceof Node\Expr\ConstFetch:
             return Expression::constant($this->parseAbsoluteName($node->name));
         case $node instanceof Node\Expr\ClassConstFetch:
             return Expression::classConstant($this->parseNameNode($node->class), $node->name);
         case $node instanceof Node\Expr\StaticCall:
             return Expression::staticMethodCall($this->parseNameNode($node->class), $this->parseNameNode($node->name), $this->parseNodes($node->args));
         case $node instanceof Node\Expr\StaticPropertyFetch:
             return Expression::staticField($this->parseNameNode($node->class), $this->parseNameNode($node->name));
         case $node instanceof Node\Expr\Ternary:
             return $this->parseTernaryNode($node);
         case $node instanceof Node\Expr\Closure:
             return $this->parseClosureNode($node);
         case $node instanceof Node\Expr\Empty_:
             return Expression::emptyExpression($this->parseNode($node->expr));
         case $node instanceof Node\Expr\Isset_:
             return Expression::issetExpression($this->parseNodes($node->vars));
         default:
             throw new ASTException('Cannot parse AST with unknown expression node: %s', get_class($node));
     }
 }
コード例 #3
0
ファイル: ExpressionTest.php プロジェクト: timetoogo/pinq
 public function expressions()
 {
     return [[O\Expression::arrayExpression([])], [O\Expression::arrayItem(null, O\Expression::value(0), false)], [O\Expression::assign(O\Expression::value(0), O\Operators\Assignment::EQUAL, O\Expression::value(0))], [O\Expression::binaryOperation(O\Expression::value(0), O\Operators\Binary::ADDITION, O\Expression::value(0))], [O\Expression::unaryOperation(O\Operators\Unary::PLUS, O\Expression::value(0))], [O\Expression::cast(O\Operators\Cast::STRING, O\Expression::value(0))], [O\Expression::closure(false, false, [], [], [])], [O\Expression::closureUsedVariable('var')], [O\Expression::emptyExpression(O\Expression::value(0))], [O\Expression::field(O\Expression::value(0), O\Expression::value(0))], [O\Expression::functionCall(O\Expression::value(0))], [O\Expression::index(O\Expression::value(0), O\Expression::value(0))], [O\Expression::invocation(O\Expression::value(0))], [O\Expression::issetExpression([O\Expression::value(0)])], [O\Expression::unsetExpression([O\Expression::value(0)])], [O\Expression::methodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::newExpression(O\Expression::value(0))], [O\Expression::parameter('')], [O\Expression::argument(O\Expression::value(0))], [O\Expression::returnExpression()], [O\Expression::staticMethodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::staticField(O\Expression::value(0), O\Expression::value(0))], [O\Expression::ternary(O\Expression::value(0), null, O\Expression::value(0))], [O\Expression::throwExpression(O\Expression::value(0))], [O\Expression::value(0)], [O\Expression::variable(O\Expression::value(0))], [O\Expression::constant('foo')], [O\Expression::classConstant(O\Expression::value(0), 'foo')]];
 }
コード例 #4
0
ファイル: SimpleParserTest.php プロジェクト: timetoogo/pinq
 /**
  * @dataProvider parsers
  */
 public function testIndex()
 {
     $this->assertParsedAs(function () {
         $i[0];
     }, [O\Expression::index(O\Expression::variable(O\Expression::value('i')), O\Expression::value(0))]);
     $this->assertParsedAs(function () {
         //Must use write context
         f($i[]);
     }, [O\Expression::functionCall(O\Expression::value('f'), [O\Expression::argument(O\Expression::index(O\Expression::variable(O\Expression::value('i'))))])]);
 }
コード例 #5
0
 /**
  * @backupGlobals enabled
  */
 public function testParameterCollectionCanEvaluateSuperGlobalExpression()
 {
     $this->collection->addExpression(O\Expression::index(O\Expression::variable(O\Expression::value('_POST')), O\Expression::value('var')), ParameterHasher::valueType());
     $_POST['var'] = [1, 2, 3];
     $this->assertResolvesTo([[1, 2, 3]]);
 }
コード例 #6
0
ファイル: QueryParsingTest.php プロジェクト: timetoogo/pinq
 protected function exampleFromDocsQuery()
 {
     $rowExpression = O\Expression::variable(O\Expression::value('row'));
     return $this->scopeRequest([new Q\Segments\Filter(new Q\Functions\ElementProjection($this->parameter(), self::SCOPE_TYPE, self::SCOPE_NAMESPACE, [$this->parameter() => 'this'], [O\Expression::parameter('row')], [O\Expression::returnExpression(O\Expression::binaryOperation(O\Expression::index($rowExpression, O\Expression::value('age')), O\Operators\Binary::LESS_THAN_OR_EQUAL_TO, O\Expression::value(50)))])), new Q\Segments\OrderBy([new Q\Segments\Ordering($this->indexProjection('firstName'), $this->parameter()), new Q\Segments\Ordering($this->indexProjection('lastName'), $this->parameter())]), new Q\Segments\Range($this->parameter(), $this->parameter()), new Q\Segments\IndexBy($this->indexProjection('phoneNumber')), new Q\Segments\Select(new Q\Functions\ElementProjection($this->parameter(), self::SCOPE_TYPE, self::SCOPE_NAMESPACE, [$this->parameter() => 'this'], [O\Expression::parameter('row')], [O\Expression::returnExpression(O\Expression::arrayExpression([O\Expression::arrayItem(O\Expression::value('fullName'), O\Expression::binaryOperation(O\Expression::binaryOperation(O\Expression::index($rowExpression, O\Expression::value('firstName')), O\Operators\Binary::CONCATENATION, O\Expression::value(' ')), O\Operators\Binary::CONCATENATION, O\Expression::index($rowExpression, O\Expression::value('lastName')))), O\Expression::arrayItem(O\Expression::value('address'), O\Expression::index($rowExpression, O\Expression::value('address'))), O\Expression::arrayItem(O\Expression::value('dateOfBirth'), O\Expression::index($rowExpression, O\Expression::value('dateOfBirth')))]))]))]);
 }
コード例 #7
0
ファイル: TypeSystemTest.php プロジェクト: timetoogo/pinq
 public function testCompositeType()
 {
     $compositeType = $this->typeSystem->getType(TypeId::getComposite([TypeId::getObject('ArrayAccess'), TypeId::getObject('Countable')]));
     $indexer = $compositeType->getIndex(O\Expression::index(O\Expression::value([]), O\Expression::value('s')));
     $this->assertEqualTypes($this->typeSystem->getObjectType('ArrayAccess'), $indexer->getSourceType());
     $this->assertEqualsNativeType(INativeType::TYPE_MIXED, $indexer->getReturnType());
     $method = $compositeType->getMethod(O\Expression::methodCall(O\Expression::value([]), O\Expression::value('offsetExists')));
     $this->assertEqualTypes($this->typeSystem->getObjectType('ArrayAccess'), $method->getSourceType());
     $this->assertEqualsNativeType(INativeType::TYPE_BOOL, $method->getReturnType());
     $method = $compositeType->getMethod(O\Expression::methodCall(O\Expression::value([]), O\Expression::value('count')));
     $this->assertEqualTypes($this->typeSystem->getObjectType('Countable'), $method->getSourceType());
     $this->assertEqualsNativeType(INativeType::TYPE_INT, $method->getReturnType());
 }