/** * Validates if the operator on the expression's parent is allowed * * @param Expr $expr * @param array $collection * @return boolean */ public static function validateParent(&$expr, &$collection) { $parent = $expr->getParent(); if ($parent instanceof OpExpr) { return in_array($parent->op(), $collection); } return false; }
/** * Constructs a parameter node. * * @param string $name Name * @param null|Expr $default Default value * @param null|string|Name $type Typehint * @param bool $byRef Whether is passed by reference * @param bool $variadic Whether this is a variadic argument * @param array $attributes Additional attributes */ public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) { parent::__construct(null, $attributes); $this->type = $type; $this->byRef = $byRef; $this->variadic = $variadic; $this->name = $name; $this->default = $default; if ($variadic && null !== $default) { throw new Error('Variadic parameter cannot have a default value', $default->getAttributes()); } }
private function _getValues($values) { $returnStr = ""; foreach ($values as $value) { $returnStr .= Expr::quoteLiteral($value) . ","; } return trim($returnStr, ","); }
public function __toString() { $leftExpr = Expr::quoteLiteral($this->_leftExpr); $rightExpr = Expr::quoteLiteral($this->_rightExpr); if ($leftExpr instanceof Math or $leftExpr instanceof QueryBuilder) { $leftExpr = '(' . $leftExpr . ')'; } if ($rightExpr instanceof Math or $rightExpr instanceof QueryBuilder) { $rightExpr = '(' . $rightExpr . ')'; } return $leftExpr . ' ' . $this->_operator . ' ' . $rightExpr; }
public function __toString() { $finalArguments = $this->_arguments; foreach ($finalArguments as &$arg) { $arg = Expr::quoteLiteral($arg); } $returnStr = $this->_name . '(' . implode(', ', $finalArguments) . ')'; if ($this->_alias != null) { $returnStr .= " as `" . $this->_alias . "`"; } return $returnStr; }
public function __toString() { // Adjusting Left Expression $leftExpr = (string) Expr::quoteLiteral($this->_leftExpr); if ($this->_leftExpr instanceof Math) { $leftExpr = '(' . $leftExpr . ')'; } // Adjusting Right Expression $rightExpr = (string) Expr::quoteLiteral($this->_rightExpr); if ($this->_rightExpr instanceof Math) { $rightExpr = '(' . $rightExpr . ')'; } return $leftExpr . ' ' . $this->_operator . ' ' . $rightExpr; }
/** * Constructor for the expression * * @param Expr $left * @param ExprOp $op * @param Expr $right */ public function __construct($left, $op, $right, $not = false) { // if left is a string, we assume we should convert it to a FieldExpr if (is_string($left)) { $left = new $left(); } // if right is not an expression, we must convert it! if (!$right instanceof Expr) { $right = new ValueExpr($right); } if ($right->isValueListExpr()) { $right->rewrite($left, $op, $right, $not); } else { // rewriting is based on the FieldExpr, and can expand a simple expression // into something a little bigger. if ($left->isFieldExpr()) { $left->rewrite($left, $op, $right, $not); } } // transformation is required to optimise the expression tree so that // the queries on the db and full text search are optimised. if (DefaultOpCollection::isBoolean($op)) { $this->transform($left, $op, $right, $not); } parent::__construct(); $left->setParent($this); $right->setParent($this); $this->left_expr =& $left; $this->op = $op; $this->right_expr =& $right; $this->not = $not; $this->has_text = false; // $this->setPoint('point'); if ($left->isSearchableText()) { $this->setHasText(); } else { if ($left->isDBExpr()) { $this->setHasDb(); } elseif ($left->isOpExpr()) { if ($left->getHasText()) { $this->setHasText(); } if ($left->getHasDb()) { $this->setHasDb(); } } } if ($right->isOpExpr()) { if ($right->getHasText()) { $this->setHasText(); } if ($right->getHasDb()) { $this->setHasDb(); } } // $this->flattened=null; // $left_op, etc indicates that $left expression is a logical expression $left_op = $left->isOpExpr() && DefaultOpCollection::isBoolean($left); $right_op = $right->isOpExpr() && DefaultOpCollection::isBoolean($right); // check which trees match $left_op_match = $left_op && $this->hasSameOpAs($left); $right_op_match = $right_op && $this->hasSameOpAs($left); $point = null; if ($left_op_match && $right_op_match) { $point = 'point'; } $left_op_match_flex = $left_op_match || $left->isOpExpr(); $right_op_match_flex = $right_op_match || $right->isOpExpr(); if ($left_op_match_flex && $right_op_match_flex) { $point = 'point'; } if (!is_null($point)) { if ($left_op_match && $left->getPoint() == 'point') { $left->setPoint(null); } if ($right_op_match && $right->getPoint() == 'point') { $right->setPoint(null); } if ($left->isMergePoint() && is_null($right->getPoint())) { $right->setPoint('point'); } if ($right->isMergePoint() && is_null($left->getPoint())) { $left->setPoint('point'); } if ($left->isMergePoint() || $right->isMergePoint()) { $point = 'merge'; if (!$left->isMergePoint()) { $left->setPoint('point'); } if (!$right->isMergePoint()) { $right->setPoint('point'); } if ($this->isDBonly() || $this->isTextOnly()) { $this->clearPoint(); $point = 'point'; } } } if ($point == 'point') { if ($this->isDBandText()) { $point = 'merge'; $left->setPoint('point'); $right->setPoint('point'); } } if (is_null($point) && !DefaultOpCollection::isBoolean($op)) { $point = 'point'; } $this->setPoint($point); }
function SCM_lambda($s, $env) { $args = $s->car; $forms = $s->cdr; return Expr::new_instance($forms, $args, $env); }
/** * Creates an instance of BETWEEN() function, with the given argument. * * @param mixed $val Valued to be inspected by range values. * @param integer $x Starting range value to be used in BETWEEN() function. * @param integer $y End point value to be used in BETWEEN() function. * @return Func A BETWEEN expression. */ public function between($val, $x, $y) { return Expr::quoteLiteral($val) . ' BETWEEN ' . Expr::quoteLiteral($x) . ' AND ' . Expr::quoteLiteral($y); }
/** * Quote an identifier and an optional alias. * * @param string|array|Expr $ident The identifier or expression. * @param string $alias An optional alias. * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option. * @param string $as The string to add between the identifier/expression and the alias. * @return string The quoted identifier and alias. */ protected function _quoteIdentifierAs($ident, $alias = null, $auto = false, $as = ' AS ') { if ($ident instanceof \Micro\Database\Expr) { $quoted = $ident->__toString(); } elseif ($ident instanceof \Micro\Database\Select) { $quoted = '(' . $ident->assemble() . ')'; } else { if (is_string($ident)) { $ident = explode('.', $ident); } if (is_array($ident)) { $segments = array(); foreach ($ident as $segment) { if ($segment instanceof \Micro\Database\Expr) { $segments[] = $segment->__toString(); } else { $segments[] = $this->_quoteIdentifier($segment, $auto); } } if ($alias !== null && end($ident) == $alias) { $alias = null; } $quoted = implode('.', $segments); } else { $quoted = $this->_quoteIdentifier($ident, $auto); } } if ($alias !== null) { $quoted .= $as . $this->_quoteIdentifier($alias, $auto); } return $quoted; }
/** * Quoting value for safety insert in to query. * ``` * 1 -> 1 * a -> 'a' * null -> '' * Expr -> Expr_value * [1, 2] -> '1, 2' * ``` * * @param int|string|Expr|array $value * * @return int|string */ public function quoteValue($value) { if ($value instanceof Expr) { return $value->get(); } if (is_int($value) || is_float($value)) { return $value; } if (is_array($value)) { foreach ($value as &$val) { $val = $this->quoteValue($val); } return implode(', ', $value); } return $this->connect()->quote($value); }