public static createFromNode ( BetterReflection\Reflector\Reflector $reflector, |
||
$reflector | BetterReflection\Reflector\Reflector | |
$node | ||
$function | ||
$parameterIndex | integer | |
리턴 |
/** * Populate the common elements of the function abstract * * @param MethodOrFunctionNode $node * @param LocatedSource $locatedSource * @param NamespaceNode|null $declaringNamespace */ protected function populateFunctionAbstract(MethodOrFunctionNode $node, LocatedSource $locatedSource, NamespaceNode $declaringNamespace = null) { $this->node = $node; $this->name = $node->name; $this->locatedSource = $locatedSource; $this->declaringNamespace = $declaringNamespace; if ($node->hasAttribute('comments')) { /* @var \PhpParser\Comment\Doc $comment */ $comment = $node->getAttribute('comments')[0]; $this->docBlock = $comment->getReformattedText(); } // We must determine if params are optional or not ahead of time, but // we must do it in reverse... $overallOptionalFlag = true; $lastParamIndex = count($node->params) - 1; for ($i = $lastParamIndex; $i >= 0; $i--) { $hasDefault = $node->params[$i]->default !== null; // When we find the first parameter that does not have a default, // flip the flag as all params for this are no longer optional // EVEN if they have a default value if (!$hasDefault) { $overallOptionalFlag = false; } $node->params[$i]->isOptional = $overallOptionalFlag; } foreach ($node->params as $paramIndex => $paramNode) { $this->parameters[] = ReflectionParameter::createFromNode($paramNode, $this, $paramIndex); } }
/** * Get an array list of the parameters for this method signature, as an * array of ReflectionParameter instances. * * @return ReflectionParameter[] */ public function getParameters() { $parameters = []; foreach ($this->node->params as $paramIndex => $paramNode) { $parameters[] = ReflectionParameter::createFromNode($paramNode, $this, $paramIndex); } return $parameters; }