PHP Class BetterReflection\Reflection\ReflectionClass

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

Méthodes publiques

Méthode 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

Méthode 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 méthode

public __clone ( )

__toString() public méthode

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

addMethod() public méthode

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

addProperty() public méthode

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 méthode

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

createFromName() public static méthode

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

createFromNode() public static méthode

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
Résultat ReflectionClass

export() public static méthode

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

getAst() public méthode

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

getConstant() public méthode

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

getConstants() public méthode

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

getConstructor() public méthode

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

getDefaultProperties() public méthode

getDocComment() public méthode

public getDocComment ( ) : string
Résultat string

getEndLine() public méthode

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

getFileName() public méthode

public getFileName ( ) : string | null
Résultat string | null

getImmediateInterfaces() public méthode

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

getImmediateMethods() public méthode

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

getInterfaceNames() public méthode

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

getInterfaces() public méthode

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

getLocatedSource() public méthode

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

getMethod() public méthode

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

getMethods() public méthode

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

getModifiers() public méthode

Get the core-reflection-compatible modifier values.
public getModifiers ( ) : integer
Résultat integer

getName() public méthode

Get the "full" name of the class (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 class (e.g. for A\B\Foo, this will return "A\B").
public getNamespaceName ( ) : string
Résultat string

getParentClass() public méthode

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
Résultat ReflectionClass

getProperties() public méthode

Get the properties for this class.
public getProperties ( ) : ReflectionProperty[]
Résultat ReflectionProperty[]

getProperty() public méthode

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

getShortName() public méthode

Get the "short" name of the class (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 class starts on.
public getStartLine ( ) : integer
Résultat integer

getStaticPropertyValue() public méthode

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

getTraitAliases() public méthode

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

getTraitNames() public méthode

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[]
Résultat string[]

getTraits() public méthode

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[]
Résultat ReflectionClass[]

hasConstant() public méthode

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

hasMethod() public méthode

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

hasProperty() public méthode

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

implementsInterface() public méthode

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

inNamespace() public méthode

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
Résultat boolean

isAbstract() public méthode

Is this class an abstract class.
public isAbstract ( ) : boolean
Résultat boolean

isCloneable() public méthode

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

isFinal() public méthode

Is this class a final class.
public isFinal ( ) : boolean
Résultat boolean

isInstance() public méthode

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

isInstantiable() public méthode

Checks whether this reflection is an instantiable class
public isInstantiable ( ) : boolean
Résultat boolean

isInterface() public méthode

Is this reflection an interface?
public isInterface ( ) : boolean
Résultat boolean

isInternal() public méthode

Is this an internal class?
public isInternal ( ) : boolean
Résultat boolean

isIterateable() public méthode

Checks if iterateable
public isIterateable ( ) : boolean
Résultat boolean

isSubclassOf() public méthode

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

isTrait() public méthode

Is this reflection a trait?
public isTrait ( ) : 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

removeMethod() public méthode

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
Résultat boolean

removeProperty() public méthode

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

setFinal() public méthode

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

setStaticPropertyValue() public méthode

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