/**
*
* @param array $expression
* @param Call $call
* @param CompilationContext $context
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
$call->processExpectedReturn($context);
$args = $this->getParams($expression);
$func = strtolower($args[0]);
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$args = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
switch ($func) {
case 'connect':
$other_arguments = $args[1] . ',' . $args[2];
break;
default:
$args_len = count($args);
$other_arguments = "";
for ($i = 1; $i < $args_len; $i++) {
$other_arguments .= $args[$i] . ',';
}
$other_arguments = substr($other_arguments, 0, count($other_arguments) - 2);
break;
}
$cmd = 'redis_' . $func . '(' . $symbolVariable->getName() . ',' . $other_arguments . ');';
$context->codePrinter->output($cmd);
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}