/** * 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; }
/** * Processes the relations and the localization of the arguments used in a function expression * @param zibo\library\database\manipulation\expression\FunctionExpression $expression Function expression to process * @param boolean $inCondition Flag to see whether this expression is used in a condition or else where * @return zibo\library\database\manipulation\expression\FunctionExpression Processed function expression */ private function processFunctionExpression(FunctionExpression $expression, $inCondition) { $function = new FunctionExpression($expression->getName(), $expression->getAlias()); $function->setDistinct($expression->isDistinct()); $arguments = $expression->getArguments(); foreach ($arguments as $argument) { $argument = $this->processExpression($argument, $inCondition); $function->addArgument($argument); } return $function; }