PHP Class BetterReflection\Reflection\ReflectionFunctionAbstract

Inheritance: implements Reflector
Afficher le fichier Open project: roave/better-reflection Class Usage Examples

Méthodes publiques

Méthode Description
__clone ( )
addParameter ( string $parameterName ) Add a new parameter to the method/function.
export ( )
getAst ( ) : ClassMethod | Function_ Fetch the AST for this method or function.
getBodyAst ( ) : PhpParser\Node[] Retrieves the body of this function as AST nodes
getBodyCode ( PrettyPrinterAbstract $printer = null ) : string Retrieves the body of this function as code.
getDocBlockReturnTypes ( ) : phpDocumentor\Reflection\Type[] Get the return types defined in the DocBlocks. This returns an array because the parameter may have multiple (compound) types specified (for example when you type hint pipe-separated "string|null", in which case this would return an array of Type objects, one for string, one for null.
getDocComment ( ) : string
getEndLine ( ) : integer Get the line number that this function ends on.
getFileName ( ) : string
getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
getName ( ) : string Get the "full" name of the function (e.g. for A\B\foo, this will return "A\B\foo").
getNamespaceName ( ) : string Get the "namespace" name of the function (e.g. for A\B\foo, this will return "A\B").
getNumberOfParameters ( ) : integer Get the number of parameters for this class.
getNumberOfRequiredParameters ( ) : integer Get the number of required parameters for this method.
getParameter ( string $parameterName ) : ReflectionParameter | null Get a single parameter by name. Returns null if parameter not found for the function.
getParameters ( ) : ReflectionParameter[] Get an array list of the parameters for this method signature, as an array of ReflectionParameter instances.
getReturnStatementsAst ( ) : PhpParser\Node\Stmt\Return_[] Fetch an array of all return statements found within this function.
getReturnType ( ) : ReflectionType | null Get the return type declaration (only for PHP 7+ code)
getShortName ( ) : string Get the "short" name of the function (e.g. for A\B\foo, this will return "foo").
getStartLine ( ) : integer Get the line number that this function starts on.
hasReturnType ( ) : boolean Do we have a return type declaration (only for PHP 7+ code)
inNamespace ( ) : boolean Decide if this function is part of a namespace. Returns false if the class is in the global namespace or does not have a specified namespace.
isClosure ( ) : boolean Is this function a closure?
isDeprecated ( ) : boolean Is this function deprecated?
isGenerator ( ) : boolean Check if this function can be used as a generator (i.e. contains the "yield" keyword).
isInternal ( ) : boolean Is this an internal function?
isUserDefined ( ) : boolean Is this a user-defined function (will always return the opposite of whatever isInternal returns).
isVariadic ( ) : boolean Check if the function has a variadic parameter.
removeParameter ( string $parameterName ) : void Remove a parameter from the method/function.
removeReturnType ( ) Remove the return type declaration completely.
returnsReference ( ) : boolean Is this function declared as a reference.
setBodyFromAst ( array $nodes ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setBodyFromClosure ( Closure $newBody ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setBodyFromString ( string $newBody ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setReturnType ( phpDocumentor\Reflection\Type $newReturnType ) Set the return type declaration.

Méthodes protégées

Méthode Description
__construct ( )
getNode ( ) : ClassMethod | Function_ Get the AST node from which this function was created
populateFunctionAbstract ( BetterReflection\Reflector\Reflector $reflector, PhpParser\Node $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $declaringNamespace = null ) Populate the common elements of the function abstract.

Private Methods

Méthode Description
nodeIsOrContainsYield ( PhpParser\Node $node ) : boolean Recursively search an array of statements (PhpParser nodes) to find if a yield expression exists anywhere (thus indicating this is a generator).
setNodeOptionalFlag ( ) We must determine if params are optional or not ahead of time, but we must do it in reverse.

Method Details

__clone() public méthode

public __clone ( )

__construct() protected méthode

protected __construct ( )

addParameter() public méthode

Add a new parameter to the method/function.
public addParameter ( string $parameterName )
$parameterName string

export() public static méthode

public static export ( )

getAst() public méthode

Fetch the AST for this method or function.
public getAst ( ) : ClassMethod | Function_
Résultat PhpParser\Node\Stmt\ClassMethod | PhpParser\Node\Stmt\Function_

getBodyAst() public méthode

Retrieves the body of this function as AST nodes
public getBodyAst ( ) : PhpParser\Node[]
Résultat PhpParser\Node[]

getBodyCode() public méthode

If a PrettyPrinter is provided as a paramter, it will be used, otherwise a default will be used. Note that the formatting of the code may not be the same as the original function. If specific formatting is required, you should provide your own implementation of a PrettyPrinter to unparse the AST.
public getBodyCode ( PrettyPrinterAbstract $printer = null ) : string
$printer PhpParser\PrettyPrinterAbstract
Résultat string

getDocBlockReturnTypes() public méthode

Get the return types defined in the DocBlocks. This returns an array because the parameter may have multiple (compound) types specified (for example when you type hint pipe-separated "string|null", in which case this would return an array of Type objects, one for string, one for null.
public getDocBlockReturnTypes ( ) : phpDocumentor\Reflection\Type[]
Résultat phpDocumentor\Reflection\Type[]

getDocComment() public méthode

public getDocComment ( ) : string
Résultat string

getEndLine() public méthode

Get the line number that this function ends on.
public getEndLine ( ) : integer
Résultat integer

getFileName() public méthode

public getFileName ( ) : string
Résultat string

getLocatedSource() public méthode

public getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
Résultat BetterReflection\SourceLocator\Located\LocatedSource

getName() public méthode

Get the "full" name of the function (e.g. for A\B\foo, this will return "A\B\foo").
public getName ( ) : string
Résultat string

getNamespaceName() public méthode

Get the "namespace" name of the function (e.g. for A\B\foo, this will return "A\B").
public getNamespaceName ( ) : string
Résultat string

getNode() protected méthode

Get the AST node from which this function was created
protected getNode ( ) : ClassMethod | Function_
Résultat PhpParser\Node\Stmt\ClassMethod | PhpParser\Node\Stmt\Function_

getNumberOfParameters() public méthode

Get the number of parameters for this class.
public getNumberOfParameters ( ) : integer
Résultat integer

getNumberOfRequiredParameters() public méthode

Get the number of required parameters for this method.

getParameter() public méthode

Get a single parameter by name. Returns null if parameter not found for the function.
public getParameter ( string $parameterName ) : ReflectionParameter | null
$parameterName string
Résultat ReflectionParameter | null

getParameters() public méthode

Get an array list of the parameters for this method signature, as an array of ReflectionParameter instances.
public getParameters ( ) : ReflectionParameter[]
Résultat ReflectionParameter[]

getReturnStatementsAst() public méthode

Note that return statements within smaller scopes contained (e.g. anonymous classes, closures) are not returned here as they are not within the immediate scope.
public getReturnStatementsAst ( ) : PhpParser\Node\Stmt\Return_[]
Résultat PhpParser\Node\Stmt\Return_[]

getReturnType() public méthode

Get the return type declaration (only for PHP 7+ code)
public getReturnType ( ) : ReflectionType | null
Résultat ReflectionType | null

getShortName() public méthode

Get the "short" name of the function (e.g. for A\B\foo, this will return "foo").
public getShortName ( ) : string
Résultat string

getStartLine() public méthode

Get the line number that this function starts on.
public getStartLine ( ) : integer
Résultat integer

hasReturnType() public méthode

Do we have a return type declaration (only for PHP 7+ code)
public hasReturnType ( ) : boolean
Résultat boolean

inNamespace() public méthode

Decide if this function is part of a namespace. Returns false if the class is in the global namespace or does not have a specified namespace.
public inNamespace ( ) : boolean
Résultat boolean

isClosure() public méthode

Is this function a closure?
public isClosure ( ) : boolean
Résultat boolean

isDeprecated() public méthode

Note - we cannot reflect on internal functions (as there is no PHP source code we can access. This means, at present, we can only EVER return false from this function.
See also: https://github.com/Roave/BetterReflection/issues/38
public isDeprecated ( ) : boolean
Résultat boolean

isGenerator() public méthode

Check if this function can be used as a generator (i.e. contains the "yield" keyword).
public isGenerator ( ) : boolean
Résultat boolean

isInternal() public méthode

Note - we cannot reflect on internal functions (as there is no PHP source code we can access. This means, at present, we can only EVER return false from this function.
See also: https://github.com/Roave/BetterReflection/issues/38
public isInternal ( ) : boolean
Résultat boolean

isUserDefined() public méthode

Is this a user-defined function (will always return the opposite of whatever isInternal returns).
public isUserDefined ( ) : boolean
Résultat boolean

isVariadic() public méthode

Check if the function has a variadic parameter.
public isVariadic ( ) : boolean
Résultat boolean

populateFunctionAbstract() protected méthode

Populate the common elements of the function abstract.
protected populateFunctionAbstract ( BetterReflection\Reflector\Reflector $reflector, PhpParser\Node $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $declaringNamespace = null )
$reflector BetterReflection\Reflector\Reflector
$node PhpParser\Node
$locatedSource BetterReflection\SourceLocator\Located\LocatedSource
$declaringNamespace PhpParser\Node\Stmt\Namespace_

removeParameter() public méthode

Remove a parameter from the method/function.
public removeParameter ( string $parameterName ) : void
$parameterName string
Résultat void

removeReturnType() public méthode

Remove the return type declaration completely.
public removeReturnType ( )

returnsReference() public méthode

Is this function declared as a reference.
public returnsReference ( ) : boolean
Résultat boolean

setBodyFromAst() public méthode

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromAst ( array $nodes )
$nodes array

setBodyFromClosure() public méthode

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromClosure ( Closure $newBody )
$newBody Closure

setBodyFromString() public méthode

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromString ( string $newBody )
$newBody string

setReturnType() public méthode

You must use the phpDocumentor reflection type classes as the parameter.
public setReturnType ( phpDocumentor\Reflection\Type $newReturnType )
$newReturnType phpDocumentor\Reflection\Type