PHP Class BetterReflection\Reflection\ReflectionParameter

Inheritance: implements Reflector
显示文件 Open project: roave/better-reflection Class Usage Examples

Public Methods

Method Description
__clone ( )
__toString ( ) : string Return string representation of this parameter.
allowsNull ( ) : boolean Does this method allow null for a parameter?
canBePassedByValue ( ) : boolean
createFromClassInstanceAndMethod ( object $instance, string $methodName, string $parameterName ) : ReflectionParameter Create a reflection of a parameter using an instance
createFromClassNameAndMethod ( string $className, string $methodName, string $parameterName ) : ReflectionParameter Create a reflection of a parameter using a class name
createFromNode ( BetterReflection\Reflector\Reflector $reflector, Param $node, ReflectionFunctionAbstract $function, integer $parameterIndex ) : ReflectionParameter
createFromSpec ( string[] | string | Closure $spec, string $parameterName ) : ReflectionParameter Create the parameter from the given spec. Possible $spec parameters are:
export ( )
getClass ( ) : ReflectionClass | null Gets a ReflectionClass for the type hint (returns null if not a class)
getDeclaringClass ( ) : ReflectionClass | null Get the class from the method that this parameter belongs to, if it exists.
getDeclaringFunction ( ) : ReflectionFunctionAbstract Get the function (or method) that declared this parameter.
getDefaultValue ( ) : mixed Get the default value of the parameter.
getDefaultValueAsString ( ) : string Get the default value represented as a string.
getDefaultValueConstantName ( ) : string
getDocBlockTypeStrings ( ) : string[] Get the DocBlock type hints as an array of strings.
getDocBlockTypes ( ) : phpDocumentor\Reflection\Type[] Get the 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.
getName ( ) : string Get the name of the parameter.
getPosition ( ) : integer Find the position of the parameter, left to right, starting at zero.
getType ( ) : ReflectionType | null Get the ReflectionType instance representing the type declaration for this parameter
getTypeHint ( ) : phpDocumentor\Reflection\Type Get the type hint declared for the parameter. This is the real type hint for the parameter, e.g. method(closure $someFunc) defined by the method itself, and is separate from the DocBlock type hints.
hasType ( ) : boolean Does this parameter have a type declaration?
isArray ( ) : boolean Is this parameter an array?
isCallable ( ) : boolean Is this parameter a callable?
isDefaultValueAvailable ( ) : boolean Does the parameter have a default, regardless of whether it is optional.
isDefaultValueConstant ( ) : boolean
isOptional ( ) : boolean Is the parameter optional?
isPassedByReference ( ) : boolean Is this parameter passed by reference (denoted by &$param).
isVariadic ( ) : boolean Is this parameter a variadic (denoted by .
removeType ( ) Remove the parameter type declaration completely.
setType ( phpDocumentor\Reflection\Type $newParameterType ) Set the parameter type declaration.

Private Methods

Method Description
__construct ( )
parseDefaultValueNode ( )

Method Details

__clone() public method

public __clone ( )

__toString() public method

Return string representation of this parameter.
public __toString ( ) : string
return string

allowsNull() public method

Does this method allow null for a parameter?
public allowsNull ( ) : boolean
return boolean

canBePassedByValue() public method

public canBePassedByValue ( ) : boolean
return boolean

createFromClassInstanceAndMethod() public static method

Create a reflection of a parameter using an instance
public static createFromClassInstanceAndMethod ( object $instance, string $methodName, string $parameterName ) : ReflectionParameter
$instance object
$methodName string
$parameterName string
return ReflectionParameter

createFromClassNameAndMethod() public static method

Create a reflection of a parameter using a class name
public static createFromClassNameAndMethod ( string $className, string $methodName, string $parameterName ) : ReflectionParameter
$className string
$methodName string
$parameterName string
return ReflectionParameter

createFromNode() public static method

public static createFromNode ( BetterReflection\Reflector\Reflector $reflector, Param $node, ReflectionFunctionAbstract $function, integer $parameterIndex ) : ReflectionParameter
$reflector BetterReflection\Reflector\Reflector
$node PhpParser\Node\Param
$function ReflectionFunctionAbstract
$parameterIndex integer
return ReflectionParameter

createFromSpec() public static method

- [$instance, 'method'] - ['Foo', 'bar'] - ['foo'] - [function () }]
public static createFromSpec ( string[] | string | Closure $spec, string $parameterName ) : ReflectionParameter
$spec string[] | string | Closure
$parameterName string
return ReflectionParameter

export() public static method

public static export ( )

getClass() public method

Gets a ReflectionClass for the type hint (returns null if not a class)
public getClass ( ) : ReflectionClass | null
return ReflectionClass | null

getDeclaringClass() public method

This will return null if the declaring function is not a method.
public getDeclaringClass ( ) : ReflectionClass | null
return ReflectionClass | null

getDeclaringFunction() public method

Get the function (or method) that declared this parameter.
public getDeclaringFunction ( ) : ReflectionFunctionAbstract
return ReflectionFunctionAbstract

getDefaultValue() public method

Get the default value of the parameter.
public getDefaultValue ( ) : mixed
return mixed

getDefaultValueAsString() public method

Get the default value represented as a string.
public getDefaultValueAsString ( ) : string
return string

getDefaultValueConstantName() public method

getDocBlockTypeStrings() public method

Get the DocBlock type hints as an array of strings.
public getDocBlockTypeStrings ( ) : string[]
return string[]

getDocBlockTypes() public method

Get the 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.
See also: getTypeHint()
public getDocBlockTypes ( ) : phpDocumentor\Reflection\Type[]
return phpDocumentor\Reflection\Type[]

getName() public method

Get the name of the parameter.
public getName ( ) : string
return string

getPosition() public method

Find the position of the parameter, left to right, starting at zero.
public getPosition ( ) : integer
return integer

getType() public method

(note: this has nothing to do with DocBlocks).
public getType ( ) : ReflectionType | null
return ReflectionType | null

getTypeHint() public method

Get the type hint declared for the parameter. This is the real type hint for the parameter, e.g. method(closure $someFunc) defined by the method itself, and is separate from the DocBlock type hints.
See also: getDocBlockTypes()
public getTypeHint ( ) : phpDocumentor\Reflection\Type
return phpDocumentor\Reflection\Type

hasType() public method

(note: this has nothing to do with DocBlocks).
public hasType ( ) : boolean
return boolean

isArray() public method

Is this parameter an array?
public isArray ( ) : boolean
return boolean

isCallable() public method

Is this parameter a callable?
public isCallable ( ) : boolean
return boolean

isDefaultValueAvailable() public method

Note this is distinct from "isOptional" because you can have a default value, but the parameter not be optional. In the example, the $foo parameter isOptional() == false, but isDefaultValueAvailable == true

isDefaultValueConstant() public method

public isDefaultValueConstant ( ) : boolean
return boolean

isOptional() public method

Note this is distinct from "isDefaultValueAvailable" because you can have a default value, but the parameter not be optional. In the example, the $foo parameter isOptional() == false, but isDefaultValueAvailable == true
public isOptional ( ) : boolean
return boolean

isPassedByReference() public method

Is this parameter passed by reference (denoted by &$param).
public isPassedByReference ( ) : boolean
return boolean

isVariadic() public method

..$param).
public isVariadic ( ) : boolean
return boolean

removeType() public method

Remove the parameter type declaration completely.
public removeType ( )

setType() public method

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