本文整理汇总了PHP中PHPSA\Context类的典型用法代码示例。如果您正苦于以下问题:PHP Context类的具体用法?PHP Context怎么用?PHP Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* {expr}::{expr}();
*
* @param \PhpParser\Node\Expr\StaticCall $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
if ($expr->class instanceof \PhpParser\Node\Name) {
$scope = $expr->class->parts[0];
$name = $expr->name;
if ($scope == 'self') {
if ($context->scope instanceof ClassDefinition) {
$context->notice('scall-self-not-context', sprintf('No scope. You cannot call from %s out from class scope', $name, $scope), $expr);
return new CompiledExpression();
}
/** @var ClassDefinition $classDefinition */
$classDefinition = $context->scope;
if (!$classDefinition->hasMethod($name, true)) {
$context->notice('undefined-scall', sprintf('Static method %s() does not exist in %s scope', $name, $scope), $expr);
return new CompiledExpression();
}
$method = $classDefinition->getMethod($name);
if (!$method->isStatic()) {
$context->notice('undefined-scall', sprintf('Method %s() is not static but it was called as static way', $name), $expr);
return new CompiledExpression();
}
}
return new CompiledExpression();
}
$context->debug('Unknown static function call');
return new CompiledExpression();
}
示例2: compile
/**
* @param \PhpParser\Node\Stmt\Static_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->vars as $var) {
$compiler->compile($var->default);
}
}
示例3: compile
/**
* [] array()
*
* @param \PhpParser\Node\Expr\Array_ $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$compiler = $context->getExpressionCompiler();
if ($expr->items === []) {
return new CompiledExpression(CompiledExpression::ARR, []);
}
$resultArray = [];
foreach ($expr->items as $item) {
$compiledValueResult = $compiler->compile($item->value);
if ($item->key) {
$compiledKeyResult = $compiler->compile($item->key);
switch ($compiledKeyResult->getType()) {
case CompiledExpression::INTEGER:
case CompiledExpression::DOUBLE:
case CompiledExpression::BOOLEAN:
case CompiledExpression::NULL:
case CompiledExpression::STRING:
$resultArray[$compiledKeyResult->getValue()] = $compiledValueResult->getValue();
}
} else {
$resultArray[] = $compiledValueResult->getValue();
}
}
return new CompiledExpression(CompiledExpression::ARR, $resultArray);
}
示例4: compile
/**
* @param \PhpParser\Node\Stmt\Const_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->consts as $const) {
$compiler->compile($const->value);
}
}
示例5: compile
/**
* isset({expr]})
*
* @param \PhpParser\Node\Expr\Isset_ $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$result = false;
foreach ($expr->vars as $var) {
if ($var instanceof VariableNode) {
$varName = $var->name;
if ($varName instanceof Name) {
$varName = $varName->parts[0];
}
$variable = $context->getSymbol($varName);
if ($variable) {
$variable->incUse();
if ($variable->getValue() !== null) {
$result = true;
continue;
// this variable is set, continue
}
}
return CompiledExpression::fromZvalValue(false);
// one of the vars is not set
}
}
return CompiledExpression::fromZvalValue($result);
// if all are set return true, else false
}
示例6: compile
/**
* classname->property
*
* @param \PhpParser\Node\Expr\PropertyFetch $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$compiler = $context->getExpressionCompiler();
$propertNameCE = $compiler->compile($expr->name);
$scopeExpression = $compiler->compile($expr->var);
if ($scopeExpression->isObject()) {
$scopeExpressionValue = $scopeExpression->getValue();
if ($scopeExpressionValue instanceof ClassDefinition) {
$propertyName = $propertNameCE->isString() ? $propertNameCE->getValue() : false;
if ($propertyName) {
if ($scopeExpressionValue->hasProperty($propertyName, true)) {
$property = $scopeExpressionValue->getProperty($propertyName, true);
return $compiler->compile($property);
} else {
$context->notice('language_error', sprintf('Property %s does not exist in %s scope', $propertyName, $scopeExpressionValue->getName()), $expr);
}
}
}
return new CompiledExpression();
} elseif ($scopeExpression->canBeObject()) {
return new CompiledExpression();
}
$context->notice('language_error', "It's not possible to fetch a property on a non-object", $expr, Check::CHECK_BETA);
return new CompiledExpression();
}
示例7: compile
/**
* @param \PhpParser\Node\Stmt\Catch_ $statement
* @param Context $context
*/
public function compile($statement, Context $context)
{
$context->addVariable(new Variable($statement->var, null, CompiledExpression::OBJECT));
foreach ($statement->stmts as $stmt) {
\PHPSA\nodeVisitorFactory($stmt, $context);
}
}
示例8: compile
/**
* @param \PhpParser\Node\Expr\Closure $expr
* @param Context $context
* @return mixed
*/
protected function compile($expr, Context $context)
{
$closure = new ClosureDefinition($expr);
$closure->setFilepath($context->getFilepath());
$closure->preCompile(clone $context);
return new CompiledExpression(CompiledExpression::CALLABLE_TYPE, $closure);
}
示例9: compile
/**
* @param \PhpParser\Node\Stmt\Echo_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->exprs as $expr) {
$compiler->compile($expr);
}
}
示例10: compile
/**
* Compile function to check it
*
* @param Context $context
* @return bool
*/
public function compile(Context $context)
{
if ($this->compiled) {
return true;
}
$context->setFilepath($this->filepath);
$this->compiled = true;
$context->clearSymbols();
$context->scopePointer = $this->getPointer();
$context->setScope(null);
if (count($this->statement->stmts) == 0) {
return $context->notice('not-implemented-function', sprintf('Closure %s() is not implemented', $this->name), $this->statement);
}
if (count($this->statement->params) > 0) {
/** @var Node\Param $parameter */
foreach ($this->statement->params as $parameter) {
$type = CompiledExpression::UNKNOWN;
if ($parameter->type) {
if (is_string($parameter->type)) {
$type = Types::getType($parameter->type);
} elseif ($parameter->type instanceof Node\Name) {
$type = CompiledExpression::OBJECT;
}
}
$context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef));
}
}
foreach ($this->statement->stmts as $st) {
\PHPSA\nodeVisitorFactory($st, $context);
}
return true;
}
示例11: checkCaseStatement
/**
* @param Stmt\Case_ $case
* @param Context $context
* @return bool
*/
private function checkCaseStatement(Stmt\Case_ $case, Context $context)
{
/*
* switch(…) {
* case 41:
* case 42:
* case 43:
* return 'the truth, or almost.';
* }
*/
if (!$case->stmts) {
return false;
}
foreach ($case->stmts as $node) {
// look for a break statement
if ($node instanceof Stmt\Break_) {
return false;
}
// or for a return
if ($node instanceof Stmt\Return_) {
return false;
}
}
$context->notice('missing_break_statement', 'Missing "break" statement', $case);
return true;
}
示例12: compile
/**
* yield {value}, yield {key} => {value}
*
* @param \PhpParser\Node\Expr\Yield_ $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$key = $context->getExpressionCompiler()->compile($expr->key);
$value = $context->getExpressionCompiler()->compile($expr->value);
// @TODO implement yield
return new CompiledExpression();
}
示例13: pass
/**
* @param Expr $expr
* @param Context $context
* @return bool
*/
public function pass(Expr $expr, Context $context)
{
$castType = CompiledExpression::UNKNOWN;
switch (get_class($expr)) {
case Expr\Cast\Array_::class:
$castType = CompiledExpression::ARR;
break;
case Expr\Cast\Bool_::class:
$castType = CompiledExpression::BOOLEAN;
break;
case Expr\Cast\Int_::class:
$castType = CompiledExpression::INTEGER;
break;
case Expr\Cast\Double::class:
$castType = CompiledExpression::DOUBLE;
break;
case Expr\Cast\Object_::class:
$castType = CompiledExpression::OBJECT;
break;
case Expr\Cast\String_::class:
$castType = CompiledExpression::STRING;
break;
}
$compiledExpression = $context->getExpressionCompiler()->compile($expr->expr);
$exprType = $compiledExpression->getType();
$typeName = $compiledExpression->getTypeName();
if ($castType === $exprType) {
$context->notice('stupid.cast', sprintf("You are trying to cast '%s' to '%s'", $typeName, $typeName), $expr);
return true;
} elseif (get_class($expr) == Expr\Cast\Unset_::class && $exprType === CompiledExpression::NULL) {
$context->notice('stupid.cast', "You are trying to cast 'null' to 'unset' (null)", $expr);
return true;
}
return false;
}
示例14: compile
/**
* {expr}++
*
* @param \PhpParser\Node\Expr\PostDec $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
if ($expr->var instanceof \PHPParser\Node\Expr\Variable) {
$variableName = $expr->var->name;
if ($variableName instanceof Name) {
$variableName = $variableName->parts[0];
}
$variable = $context->getSymbol($variableName);
if ($variable) {
$variable->incUse();
switch ($variable->getType()) {
case CompiledExpression::LNUMBER:
case CompiledExpression::DNUMBER:
$variable->dec();
return CompiledExpression::fromZvalValue($variable->getValue());
}
$context->notice('postdec.variable.wrong-type', 'You are trying to use post derement operator on variable $' . $variableName . ' with type: ' . $variable->getTypeName(), $expr);
} else {
$context->notice('postdec.undefined-variable', 'You are trying to use post derement operator on undefined variable: ' . $variableName, $expr);
}
return new CompiledExpression(CompiledExpression::UNKNOWN);
}
$expression = new Expression($context);
$compiledExpression = $expression->compile($expr->var);
switch ($compiledExpression->getType()) {
case CompiledExpression::LNUMBER:
case CompiledExpression::DNUMBER:
$value = $compiledExpression->getValue();
return CompiledExpression::fromZvalValue($value++);
}
return new CompiledExpression(CompiledExpression::UNKNOWN);
}
示例15: compile
/**
* @param \PhpParser\Node\Stmt\Do_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$context->getExpressionCompiler()->compile($stmt->cond);
foreach ($stmt->stmts as $statement) {
\PHPSA\nodeVisitorFactory($statement, $context);
}
}