本文整理汇总了PHP中Method::fromNode方法的典型用法代码示例。如果您正苦于以下问题:PHP Method::fromNode方法的具体用法?PHP Method::fromNode怎么用?PHP Method::fromNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method::fromNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visitClosure
/**
* Visit a node with kind `\ast\AST_CLOSURE`
*
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitClosure(Node $node) : Context
{
$closure_fqsen = FullyQualifiedFunctionName::fromClosureInContext($this->context);
$method = Method::fromNode($this->context, $this->code_base, $node);
// Override the FQSEN with the found alternate ID
$method->setFQSEN($closure_fqsen);
// Make the closure reachable by FQSEN from anywhere
$this->code_base->addMethod($method);
// If we have a 'this' variable in our current scope,
// pass it down into the closure
$context = $this->context->withScope(new Scope());
if ($context->getScope()->hasVariableWithName('this')) {
$context = $context->addScopeVariable($this->context->getScope()->getVariableWithName('this'));
}
if (!empty($node->children['uses']) && $node->children['uses']->kind == \ast\AST_CLOSURE_USES) {
$uses = $node->children['uses'];
foreach ($uses->children as $use) {
if ($use->kind != \ast\AST_CLOSURE_VAR) {
Log::err(Log::EVAR, "You can only have variables in a closure use() clause", $this->context->getFile(), $node->lineno);
continue;
}
$variable_name = AST::variableName($use->children['name']);
if (empty($variable_name)) {
continue;
}
$variable = null;
// Check to see if the variable exists in this scope
if (!$this->context->getScope()->hasVariableWithName($variable_name)) {
// If this is not pass-by-reference variable we
// have a problem
if (!($use->flags & \ast\flags\PARAM_REF)) {
Log::err(Log::EVAR, "Variable \${$variable_name} is not defined", $this->context->getFile(), $node->lineno);
continue;
} else {
// If the variable doesn't exist, but its
// a pass-by-reference variable, we can
// just create it
$variable = Variable::fromNodeInContext($use, $this->context, $this->code_base, false);
}
} else {
$variable = $this->context->getScope()->getVariableWithName($variable_name);
// If this isn't a pass-by-reference variable, we
// clone the variable so state within this scope
// doesn't update the outer scope
if (!($use->flags & \ast\flags\PARAM_REF)) {
$variable = clone $variable;
}
}
// Pass the variable into a new scope
$context = $context->withScopeVariable($variable);
}
}
// Add all parameters to the scope
if (!empty($node->children['params']) && $node->children['params']->kind == \ast\AST_PARAM_LIST) {
$params = $node->children['params'];
foreach ($params->children as $param) {
// Read the parameter
$parameter = Parameter::fromNode($this->context, $this->code_base, $param);
// Add it to the scope
$context = $context->withScopeVariable($parameter);
}
}
return $context->withClosureFQSEN($closure_fqsen);
}
示例2: visitFuncDecl
/**
* Visit a node with kind `\ast\AST_FUNC_DECL`
*
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitFuncDecl(Node $node) : Context
{
$function_name = $node->name;
// Hunt for an un-taken alternate ID
$alternate_id = 0;
$function_fqsen = null;
do {
$function_fqsen = FullyQualifiedFunctionName::fromStringInContext($function_name, $this->context)->withNamespace($this->context->getNamespace())->withAlternateId($alternate_id++);
} while ($this->code_base->hasMethod($function_fqsen));
$method = Method::fromNode($this->context->withLineNumberStart($node->lineno ?? 0)->withLineNumberEnd($node->endLineno ?? 0), $this->code_base, $node);
$method->setFQSEN($function_fqsen);
$this->code_base->addMethod($method);
// Send the context into the method
$context = $this->context->withMethodFQSEN($function_fqsen);
// Add each method parameter to the scope. We clone it
// so that changes to the variable don't alter the
// parameter definition
foreach ($method->getParameterList() as $parameter) {
$context->addScopeVariable(clone $parameter);
}
return $context;
}