Zephir\Call::getResolvedParams PHP Метод

getResolvedParams() публичный Метод

Resolve parameters getting aware that the target function/method could retain or change the parameters
public getResolvedParams ( array $parameters, zephir\CompilationContext $compilationContext, array $expression, array $calleeDefinition = null ) : array
$parameters array
$compilationContext zephir\CompilationContext
$expression array
$calleeDefinition array
Результат array
    public function getResolvedParams($parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null)
    {
        $codePrinter = $compilationContext->codePrinter;
        $exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression);
        /**
         * Static typed parameters in final/private methods are promotable to read only parameters
         * Recursive calls with static typed methods also also promotable
         */
        $isFinal = false;
        $readOnlyParameters = array();
        if (is_object($calleeDefinition)) {
            if ($calleeDefinition instanceof ClassMethod) {
                if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod == $calleeDefinition) {
                    $isFinal = true;
                    foreach ($calleeDefinition->getParameters() as $position => $parameter) {
                        if (isset($parameter['data-type'])) {
                            switch ($parameter['data-type']) {
                                case 'int':
                                case 'uint':
                                case 'double':
                                case 'long':
                                case 'char':
                                case 'uchar':
                                case 'boolean':
                                case 'bool':
                                    $readOnlyParameters[$position] = true;
                                    break;
                            }
                        }
                    }
                }
            }
        }
        $params = array();
        $types = array();
        $dynamicTypes = array();
        $mustCheck = array();
        foreach ($exprParams as $position => $compiledExpression) {
            $expression = $compiledExpression->getOriginal();
            switch ($compiledExpression->getType()) {
                case 'null':
                    $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $compilationContext->backend->assignNull($parameterVariable, $compilationContext);
                    $this->_temporalVariables[] = $parameterVariable;
                    $types[] = $compiledExpression->getType();
                    $dynamicTypes[] = $compiledExpression->getType();
                    break;
                case 'int':
                case 'uint':
                case 'long':
                    $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $compilationContext->backend->assignLong($parameterVariable, $compiledExpression->getCode(), $compilationContext);
                    $this->_temporalVariables[] = $parameterVariable;
                    $types[] = $compiledExpression->getType();
                    $dynamicTypes[] = $compiledExpression->getType();
                    break;
                case 'double':
                    $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $compilationContext->backend->assignDouble($parameterVariable, $compiledExpression->getCode(), $compilationContext);
                    $this->_temporalVariables[] = $parameterVariable;
                    $types[] = $compiledExpression->getType();
                    break;
                case 'bool':
                    $value = $compiledExpression->getCode();
                    if ($value == 'true') {
                        $value = '1';
                    } else {
                        if ($value == 'false') {
                            $value = '0';
                        }
                    }
                    $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $compilationContext->backend->assignBool($parameterVariable, $value, $compilationContext);
                    $this->_temporalVariables[] = $parameterVariable;
                    $types[] = $compiledExpression->getType();
                    $dynamicTypes[] = $compiledExpression->getType();
                    break;
                case 'ulong':
                case 'string':
                case 'istring':
                    $parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
                    $compilationContext->backend->assignString($parameterVariable, Utils::addSlashes($compiledExpression->getCode()), $compilationContext, true, 'ZEPHIR_TEMP_PARAM_COPY');
                    $this->_temporalVariables[] = $parameterVariable;
                    /* ZE3 copies strings */
                    if ($compilationContext->backend->getName() == 'ZendEngine2') {
                        $mustCheck[] = $parameterVariable->getName();
                    }
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $types[] = $compiledExpression->getType();
                    $dynamicTypes[] = $compiledExpression->getType();
                    break;
                case 'array':
                    $parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
                    $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                    $types[] = $compiledExpression->getType();
                    $dynamicTypes[] = $compiledExpression->getType();
                    break;
                case 'variable':
                    $parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
                    switch ($parameterVariable->getType()) {
                        case 'int':
                        case 'uint':
                        case 'long':
                            /* ulong must be stored in string */
                        /* ulong must be stored in string */
                        case 'ulong':
                            $parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                            $params[] = $compilationContext->backend->getVariableCode($parameterTempVariable);
                            $compilationContext->backend->assignLong($parameterTempVariable, $parameterVariable, $compilationContext);
                            $this->_temporalVariables[] = $parameterTempVariable;
                            $types[] = $parameterVariable->getType();
                            $dynamicTypes[] = $parameterVariable->getType();
                            break;
                        case 'double':
                            $parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                            $compilationContext->backend->assignDouble($parameterTempVariable, $parameterVariable, $compilationContext);
                            $params[] = $compilationContext->backend->getVariableCode($parameterTempVariable);
                            $this->_temporalVariables[] = $parameterTempVariable;
                            $types[] = $parameterVariable->getType();
                            $dynamicTypes[] = $parameterVariable->getType();
                            break;
                        case 'bool':
                            $tempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
                            $codePrinter->output('if (' . $parameterVariable->getName() . ') {');
                            $codePrinter->increaseLevel();
                            $compilationContext->backend->assignBool($tempVariable, '1', $compilationContext);
                            $codePrinter->decreaseLevel();
                            $codePrinter->output('} else {');
                            $codePrinter->increaseLevel();
                            $compilationContext->backend->assignBool($tempVariable, '0', $compilationContext);
                            $codePrinter->decreaseLevel();
                            $codePrinter->output('}');
                            $params[] = $compilationContext->backend->getVariableCode($tempVariable);
                            $types[] = $parameterVariable->getType();
                            $dynamicTypes[] = $parameterVariable->getType();
                            break;
                        case 'string':
                        case 'array':
                            $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                            $types[] = $parameterVariable->getType();
                            $dynamicTypes[] = $parameterVariable->getType();
                            break;
                        case 'variable':
                            $params[] = $compilationContext->backend->getVariableCode($parameterVariable);
                            $types[] = $parameterVariable->getType();
                            $dynamicTypes[] = $parameterVariable->getDynamicTypes();
                            break;
                        default:
                            throw new CompilerException("Cannot use variable type: " . $parameterVariable->getType() . " as parameter", $expression);
                    }
                    break;
                default:
                    throw new CompilerException("Cannot use value type: " . $compiledExpression->getType() . " as parameter", $expression);
            }
        }
        $this->_resolvedTypes = $types;
        $this->_resolvedDynamicTypes = $dynamicTypes;
        $this->_mustCheckForCopy = $mustCheck;
        return $params;
    }

Usage Example

Пример #1
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 1) {
         throw new CompilerException("phalcon_get_uri only accepts three parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $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);
     }
     $context->headersManager->add('phalcon/mvc/url/utils', HeadersManager::POSITION_LAST);
     $resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('phalcon_get_uri(' . $symbol . ', ' . $resolvedParams[0] . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
All Usage Examples Of Zephir\Call::getResolvedParams