/** * Parses the provided function call into a database function expression * @param string $function String of the function expression * @return boolean|zibo\library\database\manipulation\expression\FunctionExpression false if the * provided function expression could not be parsed, the function expression object otherwise. */ private function parseFunction($function) { if (!preg_match(self::REGEX_FUNCTION, $function, $matches)) { return false; } $name = trim($matches[1]); if (!$name) { return false; } $arguments = $matches[3]; $alias = null; if (isset($matches[6])) { $alias = $matches[6]; } $function = new FunctionExpression($name, $alias); if (strpos($arguments, 'DISTINCT ') === 0) { $function->setDistinct(true); $arguments = substr($arguments, 9); } $argumentTokens = $this->fieldTokenizer->tokenize($arguments); foreach ($argumentTokens as $argument) { $argument = $this->parseExpression($argument); $function->addArgument($argument); } return $function; }
/** * Parses and processes order strings into database order expressions * @param array $orderBy Array with order strings * @return array Array with OrderExpression objects */ private function parseOrderBy(array $orderBy) { $parsedOrderBy = array(); foreach ($orderBy as $index => $order) { $this->expressionParser->setVariables($order->getVariables()); $tokens = $this->fieldTokenizer->tokenize($order->getExpression()); foreach ($tokens as $token) { $parsedOrderBy[] = $this->parseOrder($token); } } $this->expressionParser->setVariables(null); return $parsedOrderBy; }
/** * Removes the provided fields from this query. * @return null */ public function removeFields($expression) { $this->setModelFields(); $expressions = self::$fieldTokenizer->tokenize($expression); foreach ($expressions as $expression) { foreach ($this->fields as $index => $fieldExpression) { if ($fieldExpression->getExpression() == $expression) { unset($this->fields[$index]); return; } } throw new OrmException('Provided expression ' . $expression . ' was not found in this query'); } }