本文整理汇总了PHP中Zephir\Expression::getExpression方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::getExpression方法的具体用法?PHP Expression::getExpression怎么用?PHP Expression::getExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Expression
的用法示例。
在下文中一共展示了Expression::getExpression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Compiles a static method call
*
* @param array $expr
* @param CompilationContext $compilationContext
*/
public function compile(Expression $expr, CompilationContext $compilationContext)
{
$expression = $expr->getExpression();
$methodName = strtolower($expression['name']);
if (isset($expression['dynamic'])) {
$dynamicMethod = $expression['dynamic'];
} else {
$dynamicMethod = false;
}
$symbolVariable = null;
/**
* Create temporary variable if needed
*/
$mustInit = false;
$isExpecting = $expr->isExpectingReturn();
if ($isExpecting) {
$symbolVariable = $expr->getExpectingVariable();
if (is_object($symbolVariable)) {
$readDetector = new ReadDetector($expression);
if ($readDetector->detect($symbolVariable->getName(), $expression)) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
} else {
$mustInit = true;
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
}
}
/**
* Method calls only return zvals so we need to validate the target variable is also a zval
*/
if ($isExpecting) {
/**
* At this point, we don't know the exact dynamic type returned by the static method call
*/
$symbolVariable->setDynamicTypes('undefined');
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
}
/**
* Include fcall header
*/
$compilationContext->headersManager->add('kernel/fcall');
$compiler = $compilationContext->compiler;
$dynamicClass = $expression['dynamic-class'];
if (!$dynamicClass) {
$className = $expression['class'];
$classDefinition = false;
if ($className != 'self' && $className != 'parent') {
if (is_string($className)) {
$className = $compilationContext->getFullName($className);
if ($compiler->isClass($className)) {
$classDefinition = $compiler->getClassDefinition($className);
} else {
if ($compiler->isInternalClass($className)) {
$classDefinition = $compiler->getInternalClassDefinition($className);
} else {
throw new CompilerException("Class name: " . $className . " does not exist", $expression);
}
}
} else {
foreach ($className as $singleClass) {
$className = $compilationContext->getFullName($singleClass);
if ($compiler->isClass($singleClass)) {
$classDefinition = $compiler->getClassDefinition($singleClass);
} else {
throw new CompilerException("Class name: " . $className . " does not exist", $expression);
}
}
}
} else {
if ($className == 'self') {
$classDefinition = $compilationContext->classDefinition;
} else {
if ($className == 'parent') {
$classDefinition = $compilationContext->classDefinition;
$extendsClass = $classDefinition->getExtendsClass();
if (!$extendsClass) {
throw new CompilerException('Cannot call method "' . $methodName . '" on parent because class ' . $classDefinition->getCompleteName() . ' does not extend any class', $expression);
}
$currentClassDefinition = $classDefinition;
$classDefinition = $classDefinition->getExtendsClassDefinition();
}
}
}
}
/**
* Check if the class implements the method
*/
if (!$dynamicMethod && !$dynamicClass) {
if (!$classDefinition->hasMethod($methodName)) {
throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not implement static method: '" . $expression['name'] . "'", $expression);
} else {
//.........这里部分代码省略.........
示例2: compile
/**
* Compiles a method call
*
* @param Expression $expr
* @param CompilationContext $compilationContext
*/
public function compile(Expression $expr, CompilationContext $compilationContext)
{
$expression = $expr->getExpression();
$exprVariable = new Expression($expression['variable']);
$exprVariable->setReadOnly(true);
$exprCompiledVariable = $exprVariable->compile($compilationContext);
$builtInType = false;
switch ($exprCompiledVariable->getType()) {
case 'variable':
$variableVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression);
switch ($variableVariable->getType()) {
case 'variable':
$caller = $variableVariable;
break;
default:
/* Check if there is a built-in type optimizer available */
$builtInTypeClass = 'Zephir\\Types\\' . ucfirst($variableVariable->getType()) . 'Type';
if (class_exists($builtInTypeClass)) {
/**
* @var $builtInType \Zephir\Types\AbstractType
*/
$builtInType = new $builtInTypeClass();
$caller = $exprCompiledVariable;
} else {
throw new CompilerException("Methods cannot be called on variable type: " . $variableVariable->getType(), $expression);
}
}
break;
default:
/* Check if there is a built-in type optimizer available */
$builtInTypeClass = 'Zephir\\Types\\' . ucfirst($exprCompiledVariable->getType()) . 'Type';
if (class_exists($builtInTypeClass)) {
$builtInType = new $builtInTypeClass();
$caller = $exprCompiledVariable;
} else {
throw new CompilerException("Cannot use expression: " . $exprCompiledVariable->getType() . " as method caller", $expression['variable']);
}
}
$codePrinter = $compilationContext->codePrinter;
$type = $expression['call-type'];
/**
* In normal method calls and dynamic string method calls we just use the name given by the user
*/
if ($type == self::CALL_NORMAL || $type == self::CALL_DYNAMIC_STRING) {
$methodName = strtolower($expression['name']);
} else {
$variableMethod = $compilationContext->symbolTable->getVariableForRead($expression['name'], $compilationContext, $expression);
if (is_object($builtInType)) {
throw new CompilerException("Dynamic method invocation for type: " . $variableMethod->getType() . " is not supported", $expression);
}
if ($variableMethod->isNotVariableAndString()) {
throw new CompilerException("Cannot use variable type: " . $variableMethod->getType() . " as dynamic method name", $expression);
}
}
$symbolVariable = null;
/**
* Create temporary variable if needed
*/
$mustInit = false;
$isExpecting = $expr->isExpectingReturn();
if ($isExpecting) {
$symbolVariable = $expr->getExpectingVariable();
if (is_object($symbolVariable)) {
$readDetector = new ReadDetector($expression);
if ($caller == $symbolVariable || $readDetector->detect($symbolVariable->getName(), $expression)) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
} else {
$mustInit = true;
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
}
}
/**
* Method calls only return zvals so we need to validate the target variable is also a zval
*/
if (!$builtInType) {
if ($isExpecting) {
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
/**
* At this point, we don't know the exact dynamic type returned by the method call
*/
$symbolVariable->setDynamicTypes('undefined');
}
} else {
return $builtInType->invokeMethod($methodName, $caller, $compilationContext, $this, $expression);
}
$check = true;
if (isset($expression['check'])) {
$check = $expression['check'];
}
/**
//.........这里部分代码省略.........
示例3: compile
/**
* Compiles a function
*
* @param Expression $expr
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(Expression $expr, CompilationContext $compilationContext)
{
$this->_expression = $expr;
$expression = $expr->getExpression();
switch ($expression['call-type']) {
case self::CALL_NORMAL:
return $this->_callNormal($expression, $compilationContext);
case self::CALL_DYNAMIC:
return $this->_callDynamic($expression, $compilationContext);
}
return new CompiledExpression('null', null, $expression);
}