public function str_indexof($left, $right) { // throw new NotImplementedException('indexof method not implemented'); $expr = $this->expr(); // $leftParam = $this->getParamProcessed($left, 'strIndxOfLeftOp'); // $rightParam = $this->getParamProcessed($right, 'strIndxOfRightOp'); $leftParam = $this->getParamProcessed($left, 'left'); $rightParam = $this->getParamProcessed($right, 'right'); $callback = function (&$left, &$right, $function) use($rightParam, $expr) { $args = $left->getArguments(); $args[1] = $right + 1; $left = new Expr\Func($left->getName(), $args); return $expr->{$function}($left, $rightParam); }; // return $this->onComparison(new Expr\Func('SUBSTRING', array($leftParam, 0, $expr->length($rightParam))), $callback); return $this->onComparison($expr->substring($leftParam, 0, $expr->length($rightParam)), $callback); // return new Expr\Func('INSTR', array($params['left'], $params['right'])); }
/** * @group DDC-1686 */ public function testExpressionGetter() { // Andx $andx = new Expr\Andx(array('1 = 1', '2 = 2')); $this->assertEquals(array('1 = 1', '2 = 2'), $andx->getParts()); // Comparison $comparison = new Expr\Comparison('foo', Expr\Comparison::EQ, 'bar'); $this->assertEquals('foo', $comparison->getLeftExpr()); $this->assertEquals('bar', $comparison->getRightExpr()); $this->assertEquals(Expr\Comparison::EQ, $comparison->getOperator()); // From $from = new Expr\From('Foo', 'f', 'f.id'); $this->assertEquals('f', $from->getAlias()); $this->assertEquals('Foo', $from->getFrom()); $this->assertEquals('f.id', $from->getIndexBy()); // Func $func = new Expr\Func('MAX', array('f.id')); $this->assertEquals('MAX', $func->getName()); $this->assertEquals(array('f.id'), $func->getArguments()); // GroupBy $group = new Expr\GroupBy(array('foo DESC', 'bar ASC')); $this->assertEquals(array('foo DESC', 'bar ASC'), $group->getParts()); // Join $join = new Expr\Join(Expr\Join::INNER_JOIN, 'f.bar', 'b', Expr\Join::ON, 'b.bar_id = 1', 'b.bar_id'); $this->assertEquals(Expr\Join::INNER_JOIN, $join->getJoinType()); $this->assertEquals(Expr\Join::ON, $join->getConditionType()); $this->assertEquals('b.bar_id = 1', $join->getCondition()); $this->assertEquals('b.bar_id', $join->getIndexBy()); $this->assertEquals('f.bar', $join->getJoin()); $this->assertEquals('b', $join->getAlias()); // Literal $literal = new Expr\Literal(array('foo')); $this->assertEquals(array('foo'), $literal->getParts()); // Math $math = new Expr\Math(10, '+', 20); $this->assertEquals(10, $math->getLeftExpr()); $this->assertEquals(20, $math->getRightExpr()); $this->assertEquals('+', $math->getOperator()); // OrderBy $order = new Expr\OrderBy('foo', 'DESC'); $this->assertEquals(array('foo DESC'), $order->getParts()); // Andx $orx = new Expr\Orx(array('foo = 1', 'bar = 2')); $this->assertEquals(array('foo = 1', 'bar = 2'), $orx->getParts()); // Select $select = new Expr\Select(array('foo', 'bar')); $this->assertEquals(array('foo', 'bar'), $select->getParts()); }
/** * @param \Xiag\Rql\Parser\Node\Query\AbstractLogicalOperatorNode $node * * @return mixed * @throws \AndreasGlaser\DoctrineRql\Visitor\VisitorException * @author Andreas Glaser */ protected function visitLogic(AbstractLogicalOperatorNode $node) { if (!($class = ArrayHelper::get($this->logicMap, get_class($node)))) { throw new VisitorException(sprintf('Unsupported node "%s"', get_class($node))); } $expr = new $class(); foreach ($node->getQueries() as $query) { $expr->add($this->walkNodes($query)); } // Notx workaround if ($node instanceof Node\Query\LogicalOperator\NotNode) { $expr = new Expr\Func('NOT', $expr->getParts()); } return $expr; }