PHP Class BetterReflection\Reflection\ReflectionClass

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

Public Methods

Method Description
__clone ( )
__toString ( ) : string Get a string representation of this reflection
addMethod ( string $methodName ) Add a new method to the class.
addProperty ( string $propertyName, integer $visibility = ReflectionProperty::IS_PUBLIC, boolean $static = false ) Add a new property to the class.
createFromInstance ( object $instance ) : ReflectionClass Create a ReflectionClass from an instance, using default reflectors etc.
createFromName ( string $className ) : ReflectionClass Create a ReflectionClass by name, using default reflectors etc.
createFromNode ( BetterReflection\Reflector\Reflector $reflector, ClassLike $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $namespace = null ) : ReflectionClass Create from a Class Node.
export ( string $className = null ) : string Create a reflection and return the string representation of a named class
getAst ( ) : ClassLike Retrieve the AST node for this class
getConstant ( string $name ) : mixed | null Get the value of the specified class constant.
getConstants ( ) : mixed[] Get an array of the defined constants in this class.
getConstructor ( ) : BetterReflection\Reflection\ReflectionMethod Get the constructor method for this class.
getDefaultProperties ( )
getDocComment ( ) : string
getEndLine ( ) : integer Get the line number that this class ends on.
getFileName ( ) : string | null
getImmediateInterfaces ( ) : ReflectionClass[] Get only the interfaces that this class implements (i.e. do not search up parent classes etc.)
getImmediateMethods ( ) : BetterReflection\Reflection\ReflectionMethod[] Get only the methods that this class implements (i.e. do not search up parent classes etc.)
getInterfaceNames ( ) : string[] Gets the interface names.
getInterfaces ( ) : ReflectionClass[] Gets the interfaces.
getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
getMethod ( string $methodName ) : BetterReflection\Reflection\ReflectionMethod Get a single method with the name $methodName.
getMethods ( ) : BetterReflection\Reflection\ReflectionMethod[] Fetch an array of all methods for this class.
getModifiers ( ) : integer Get the core-reflection-compatible modifier values.
getName ( ) : string Get the "full" name of the class (e.g. for A\B\Foo, this will return "A\B\Foo").
getNamespaceName ( ) : string Get the "namespace" name of the class (e.g. for A\B\Foo, this will return "A\B").
getParentClass ( ) : ReflectionClass Get the parent class, if it is defined. If this class does not have a specified parent class, this will throw an exception.
getProperties ( ) : ReflectionProperty[] Get the properties for this class.
getProperty ( string $name ) : ReflectionProperty | null Get the property called $name.
getShortName ( ) : string Get the "short" name of the class (e.g. for A\B\Foo, this will return "Foo").
getStartLine ( ) : integer Get the line number that this class starts on.
getStaticPropertyValue ( string $propertyName ) : mixed Get the value of a static property, if it exists. Throws a PropertyDoesNotExist exception if it does not exist or is not static.
getTraitAliases ( ) : string[] Return a list of the aliases used when importing traits for this class.
getTraitNames ( ) : string[] Get the names of the traits used as an array of strings, if any are defined. If this class does not have any defined traits, this will return an empty array.
getTraits ( ) : ReflectionClass[] Get the traits used, if any are defined. If this class does not have any defined traits, this will return an empty array.
hasConstant ( string $name ) : boolean Does this class have the specified constant?
hasMethod ( string $methodName ) : boolean Does the class have the specified method method?
hasProperty ( string $name ) : boolean Does this class have the specified property?
implementsInterface ( string $interfaceName ) : boolean Checks whether this class implements the given interface.
inNamespace ( ) : boolean Decide if this class is part of a namespace. Returns false if the class is in the global namespace or does not have a specified namespace.
isAbstract ( ) : boolean Is this class an abstract class.
isCloneable ( ) : boolean Checks whether this is a reflection of a class that supports the clone operator
isFinal ( ) : boolean Is this class a final class.
isInstance ( object $object ) : boolean Checks whether the given object is an instance.
isInstantiable ( ) : boolean Checks whether this reflection is an instantiable class
isInterface ( ) : boolean Is this reflection an interface?
isInternal ( ) : boolean Is this an internal class?
isIterateable ( ) : boolean Checks if iterateable
isSubclassOf ( string $className ) : boolean Checks whether the given class string is a subclass of this class.
isTrait ( ) : boolean Is this reflection a trait?
isUserDefined ( ) : boolean Is this a user-defined function (will always return the opposite of whatever isInternal returns).
removeMethod ( string $methodName ) : boolean Remove the named method from the class.
removeProperty ( string $propertyName ) : boolean Remove a property from the class.
setFinal ( boolean $isFinal ) Set whether this class is final or not
setStaticPropertyValue ( string $propertyName, mixed $value ) : void Set the value of a static property

Private Methods

Method Description
__construct ( )
getCurrentClassImplementedInterfacesIndexedByName ( ) : ReflectionClass[]
getFqsenFromNamedNode ( Name $node ) : string Given an AST Node\Name, try to resolve the type into a fully qualified structural element name (FQSEN).
getInheritanceClassHierarchy ( ) : ReflectionClass[]
getInterfacesHierarchy ( ) : ReflectionClass[] This method allows us to retrieve all interfaces parent of the this interface. Do not use on class nodes!
getMethodsIndexedByName ( ) : BetterReflection\Reflection\ReflectionMethod[]
reflectClassForNamedNode ( Name $node ) : ReflectionClass Given an AST Node\Name, create a new ReflectionClass for the element.
scanMethods ( ) : BetterReflection\Reflection\ReflectionMethod[] Construct a flat list of methods that are available. This will search up all parent classes/traits/interfaces/current scope for methods.

Method Details

__clone() public method

public __clone ( )

__toString() public method

Get a string representation of this reflection
See also: https://github.com/Roave/BetterReflection/issues/94
public __toString ( ) : string
return string

addMethod() public method

Add a new method to the class.
public addMethod ( string $methodName )
$methodName string

addProperty() public method

Visibility defaults to \ReflectionProperty::IS_PUBLIC, or can be ::IS_PROTECTED or ::IS_PRIVATE.
public addProperty ( string $propertyName, integer $visibility = ReflectionProperty::IS_PUBLIC, boolean $static = false )
$propertyName string
$visibility integer
$static boolean

createFromInstance() public static method

This is simply a helper method that calls ReflectionObject::createFromInstance().
See also: ReflectionObject::createFromInstance
public static createFromInstance ( object $instance ) : ReflectionClass
$instance object
return ReflectionClass

createFromName() public static method

Create a ReflectionClass by name, using default reflectors etc.
public static createFromName ( string $className ) : ReflectionClass
$className string
return ReflectionClass

createFromNode() public static method

Create from a Class Node.
public static createFromNode ( BetterReflection\Reflector\Reflector $reflector, ClassLike $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $namespace = null ) : ReflectionClass
$reflector BetterReflection\Reflector\Reflector
$node PhpParser\Node\Stmt\ClassLike
$locatedSource BetterReflection\SourceLocator\Located\LocatedSource
$namespace PhpParser\Node\Stmt\Namespace_ optional - if omitted, we assume it is global namespaced class
return ReflectionClass

export() public static method

Create a reflection and return the string representation of a named class
public static export ( string $className = null ) : string
$className string
return string

getAst() public method

Retrieve the AST node for this class
public getAst ( ) : ClassLike
return PhpParser\Node\Stmt\ClassLike

getConstant() public method

Returns null if not specified.
public getConstant ( string $name ) : mixed | null
$name string
return mixed | null

getConstants() public method

Get an array of the defined constants in this class.
public getConstants ( ) : mixed[]
return mixed[]

getConstructor() public method

Get the constructor method for this class.
public getConstructor ( ) : BetterReflection\Reflection\ReflectionMethod
return BetterReflection\Reflection\ReflectionMethod

getDefaultProperties() public method

getDocComment() public method

public getDocComment ( ) : string
return string

getEndLine() public method

Get the line number that this class ends on.
public getEndLine ( ) : integer
return integer

getFileName() public method

public getFileName ( ) : string | null
return string | null

getImmediateInterfaces() public method

Get only the interfaces that this class implements (i.e. do not search up parent classes etc.)
public getImmediateInterfaces ( ) : ReflectionClass[]
return ReflectionClass[]

getImmediateMethods() public method

Get only the methods that this class implements (i.e. do not search up parent classes etc.)
public getImmediateMethods ( ) : BetterReflection\Reflection\ReflectionMethod[]
return BetterReflection\Reflection\ReflectionMethod[]

getInterfaceNames() public method

Gets the interface names.
public getInterfaceNames ( ) : string[]
return string[] A numerical array with interface names as the values.

getInterfaces() public method

Gets the interfaces.
public getInterfaces ( ) : ReflectionClass[]
return ReflectionClass[] An associative array of interfaces, with keys as interface names and the array values as {@see \ReflectionClass} objects.

getLocatedSource() public method

public getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
return BetterReflection\SourceLocator\Located\LocatedSource

getMethod() public method

Get a single method with the name $methodName.
public getMethod ( string $methodName ) : BetterReflection\Reflection\ReflectionMethod
$methodName string
return BetterReflection\Reflection\ReflectionMethod

getMethods() public method

Fetch an array of all methods for this class.
public getMethods ( ) : BetterReflection\Reflection\ReflectionMethod[]
return BetterReflection\Reflection\ReflectionMethod[]

getModifiers() public method

Get the core-reflection-compatible modifier values.
public getModifiers ( ) : integer
return integer

getName() public method

Get the "full" name of the class (e.g. for A\B\Foo, this will return "A\B\Foo").
public getName ( ) : string
return string

getNamespaceName() public method

Get the "namespace" name of the class (e.g. for A\B\Foo, this will return "A\B").
public getNamespaceName ( ) : string
return string

getParentClass() public method

You may optionally specify a source locator that will be used to locate the parent class. If no source locator is given, a default will be used.
public getParentClass ( ) : ReflectionClass
return ReflectionClass

getProperties() public method

Get the properties for this class.
public getProperties ( ) : ReflectionProperty[]
return ReflectionProperty[]

getProperty() public method

Returns null if property does not exist.
public getProperty ( string $name ) : ReflectionProperty | null
$name string
return ReflectionProperty | null

getShortName() public method

Get the "short" name of the class (e.g. for A\B\Foo, this will return "Foo").
public getShortName ( ) : string
return string

getStartLine() public method

Get the line number that this class starts on.
public getStartLine ( ) : integer
return integer

getStaticPropertyValue() public method

(note, differs very slightly from internal reflection behaviour)
public getStaticPropertyValue ( string $propertyName ) : mixed
$propertyName string
return mixed

getTraitAliases() public method

The returned array is in key/value pair in this format:. 'aliasedMethodName' => 'ActualClass::actualMethod'
public getTraitAliases ( ) : string[]
return string[]

getTraitNames() public method

You may optionally specify a source locator that will be used to locate the traits. If no source locator is given, a default will be used.
public getTraitNames ( ) : string[]
return string[]

getTraits() public method

You may optionally specify a source locator that will be used to locate the traits. If no source locator is given, a default will be used.
public getTraits ( ) : ReflectionClass[]
return ReflectionClass[]

hasConstant() public method

Does this class have the specified constant?
public hasConstant ( string $name ) : boolean
$name string
return boolean

hasMethod() public method

Does the class have the specified method method?
public hasMethod ( string $methodName ) : boolean
$methodName string
return boolean

hasProperty() public method

Does this class have the specified property?
public hasProperty ( string $name ) : boolean
$name string
return boolean

implementsInterface() public method

Checks whether this class implements the given interface.
public implementsInterface ( string $interfaceName ) : boolean
$interfaceName string
return boolean

inNamespace() public method

Decide if this class 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
return boolean

isAbstract() public method

Is this class an abstract class.
public isAbstract ( ) : boolean
return boolean

isCloneable() public method

Checks whether this is a reflection of a class that supports the clone operator
public isCloneable ( ) : boolean
return boolean

isFinal() public method

Is this class a final class.
public isFinal ( ) : boolean
return boolean

isInstance() public method

Checks whether the given object is an instance.
public isInstance ( object $object ) : boolean
$object object
return boolean

isInstantiable() public method

Checks whether this reflection is an instantiable class
public isInstantiable ( ) : boolean
return boolean

isInterface() public method

Is this reflection an interface?
public isInterface ( ) : boolean
return boolean

isInternal() public method

Is this an internal class?
public isInternal ( ) : boolean
return boolean

isIterateable() public method

Checks if iterateable
public isIterateable ( ) : boolean
return boolean

isSubclassOf() public method

Checks whether the given class string is a subclass of this class.
public isSubclassOf ( string $className ) : boolean
$className string
return boolean

isTrait() public method

Is this reflection a trait?
public isTrait ( ) : boolean
return boolean

isUserDefined() public method

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

removeMethod() public method

Returns true if method was successfully removed. Returns false if method was not found, or could not be removed.
public removeMethod ( string $methodName ) : boolean
$methodName string
return boolean

removeProperty() public method

Remove a property from the class.
public removeProperty ( string $propertyName ) : boolean
$propertyName string
return boolean

setFinal() public method

Set whether this class is final or not
public setFinal ( boolean $isFinal )
$isFinal boolean

setStaticPropertyValue() public method

Set the value of a static property
public setStaticPropertyValue ( string $propertyName, mixed $value ) : void
$propertyName string
$value mixed
return void