ReflectionExtractor
in package
implements
PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface, PropertyInitializableExtractorInterface, PropertyReadInfoExtractorInterface, PropertyWriteInfoExtractorInterface, ConstructorArgumentTypeExtractorInterface
Extracts data using the reflection API.
Tags
Table of Contents
Interfaces
- PropertyListExtractorInterface
- Extracts the list of properties available for the given class.
- PropertyTypeExtractorInterface
- Type Extractor Interface.
- PropertyAccessExtractorInterface
- Guesses if the property can be accessed or mutated.
- PropertyInitializableExtractorInterface
- Guesses if the property can be initialized through the constructor.
- PropertyReadInfoExtractorInterface
- Extract read information for the property of a class.
- PropertyWriteInfoExtractorInterface
- Extract write information for the property of a class.
- ConstructorArgumentTypeExtractorInterface
- Infers the constructor argument type.
Constants
- ALLOW_MAGIC_CALL = 1 << 2
- ALLOW_MAGIC_GET = 1 << 0
- ALLOW_MAGIC_SET = 1 << 1
- ALLOW_PRIVATE = 1
- ALLOW_PROTECTED = 2
- ALLOW_PUBLIC = 4
- DISALLOW_MAGIC_METHODS = 0
- MAP_TYPES = ['integer' => \Symfony\Component\TypeInfo\TypeIdentifier::INT->value, 'boolean' => \Symfony\Component\TypeInfo\TypeIdentifier::BOOL->value, 'double' => \Symfony\Component\TypeInfo\TypeIdentifier::FLOAT->value]
Properties
- $accessorPrefixes : array<string|int, mixed>
- $arrayMutatorPrefixes : array<string|int, mixed>
- $arrayMutatorPrefixesFirst : array<string|int, mixed>
- $arrayMutatorPrefixesLast : array<string|int, mixed>
- $enableConstructorExtraction : bool
- $inflector : InflectorInterface
- $magicMethodsFlags : int
- $methodReflectionFlags : int
- $mutatorPrefixes : array<string|int, mixed>
- $propertyReflectionFlags : int
- $typeResolver : TypeResolverInterface
Methods
- __construct() : mixed
- getProperties() : array<string|int, string>|null
- Gets the list of properties available for the given class.
- getReadInfo() : PropertyReadInfo|null
- Get read information object for a given property of a class.
- getType() : Type|null
- getTypeFromConstructor() : Type|null
- Gets type of an argument from constructor.
- getTypes() : array<string|int, Type>|null
- Gets types of a property.
- getTypesFromConstructor() : array<string|int, Type>|null
- Gets types of an argument from constructor.
- getWriteInfo() : PropertyWriteInfo|null
- Get write information object for a given property of a class.
- isInitializable() : bool|null
- Is the property initializable? Returns true if a constructor's parameter matches the given property name.
- isReadable() : bool|null
- Is the property readable?
- isWritable() : bool|null
- Is the property writable?
- camelize() : string
- Camelizes a given string.
- extractFromAccessor() : array<string|int, Type>|null
- Tries to extract type information from accessors.
- extractFromConstructor() : array<string|int, Type>|null
- Tries to extract type information from constructor.
- extractFromMutator() : array<string|int, Type>|null
- extractFromPropertyDeclaration() : array<string|int, mixed>|null
- extractFromReflectionType() : array<string|int, mixed>
- extractTypeFromConstructor() : Type|null
- findAdderAndRemover() : array<string|int, mixed>
- Searches for add and remove methods.
- getAccessorMethod() : array<string|int, mixed>|null
- Gets the accessor method.
- getMethodsFlags() : int
- Return allowed reflection method flags.
- getMutatorMethod() : array<string|int, mixed>|null
- Returns an array with an instance of \ReflectionMethod as the first key and the prefix of the method as the second, or null if not found.
- getPropertyFlags() : int
- Return allowed reflection property flags.
- getPropertyName() : string|null
- getReadVisibilityForMethod() : string
- getReadVisibilityForProperty() : string
- getReflectionParameterFromConstructor() : ReflectionParameter|null
- getWriteVisibilityForMethod() : string
- getWriteVisibilityForProperty() : string
- isAllowedProperty() : bool
- isMethodAccessible() : array<string|int, mixed>
- Returns whether a method is public and has the number of required parameters and errors.
- isNullableProperty() : bool
- resolveTypeName() : string
Constants
ALLOW_MAGIC_CALL
public
int
ALLOW_MAGIC_CALL
= 1 << 2
Allow magic __call methods
ALLOW_MAGIC_GET
public
int
ALLOW_MAGIC_GET
= 1 << 0
Allow magic __get methods
ALLOW_MAGIC_SET
public
int
ALLOW_MAGIC_SET
= 1 << 1
Allow magic __set methods
ALLOW_PRIVATE
public
mixed
ALLOW_PRIVATE
= 1
ALLOW_PROTECTED
public
mixed
ALLOW_PROTECTED
= 2
ALLOW_PUBLIC
public
mixed
ALLOW_PUBLIC
= 4
DISALLOW_MAGIC_METHODS
public
int
DISALLOW_MAGIC_METHODS
= 0
Allow none of the magic methods
MAP_TYPES
private
mixed
MAP_TYPES
= ['integer' => \Symfony\Component\TypeInfo\TypeIdentifier::INT->value, 'boolean' => \Symfony\Component\TypeInfo\TypeIdentifier::BOOL->value, 'double' => \Symfony\Component\TypeInfo\TypeIdentifier::FLOAT->value]
Properties
$accessorPrefixes
private
array<string|int, mixed>
$accessorPrefixes
$arrayMutatorPrefixes
private
array<string|int, mixed>
$arrayMutatorPrefixes
$arrayMutatorPrefixesFirst
private
array<string|int, mixed>
$arrayMutatorPrefixesFirst
$arrayMutatorPrefixesLast
private
array<string|int, mixed>
$arrayMutatorPrefixesLast
$enableConstructorExtraction
private
bool
$enableConstructorExtraction
= true
$inflector
private
InflectorInterface
$inflector
$magicMethodsFlags
private
int
$magicMethodsFlags
= self::ALLOW_MAGIC_GET | self::ALLOW_MAGIC_SET
$methodReflectionFlags
private
int
$methodReflectionFlags
$mutatorPrefixes
private
array<string|int, mixed>
$mutatorPrefixes
$propertyReflectionFlags
private
int
$propertyReflectionFlags
$typeResolver
private
TypeResolverInterface
$typeResolver
Methods
__construct()
public
__construct([array<string|int, string>|null $mutatorPrefixes = null ][, array<string|int, string>|null $accessorPrefixes = null ][, array<string|int, string>|null $arrayMutatorPrefixes = null ][, bool $enableConstructorExtraction = true ][, int $accessFlags = self::ALLOW_PUBLIC ][, InflectorInterface|null $inflector = null ][, int $magicMethodsFlags = self::ALLOW_MAGIC_GET | self::ALLOW_MAGIC_SET ]) : mixed
Parameters
- $mutatorPrefixes : array<string|int, string>|null = null
- $accessorPrefixes : array<string|int, string>|null = null
- $arrayMutatorPrefixes : array<string|int, string>|null = null
- $enableConstructorExtraction : bool = true
- $accessFlags : int = self::ALLOW_PUBLIC
- $inflector : InflectorInterface|null = null
- $magicMethodsFlags : int = self::ALLOW_MAGIC_GET | self::ALLOW_MAGIC_SET
getProperties()
Gets the list of properties available for the given class.
public
getProperties(string $class[, array<string|int, mixed> $context = [] ]) : array<string|int, string>|null
Parameters
- $class : string
- $context : array<string|int, mixed> = []
Return values
array<string|int, string>|nullgetReadInfo()
Get read information object for a given property of a class.
public
getReadInfo(string $class, string $property[, array<string|int, mixed> $context = [] ]) : PropertyReadInfo|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
PropertyReadInfo|nullgetType()
public
getType(string $class, string $property[, array<string|int, mixed> $context = [] ]) : Type|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
Type|nullgetTypeFromConstructor()
Gets type of an argument from constructor.
public
getTypeFromConstructor(string $class, string $property) : Type|null
Parameters
- $class : string
- $property : string
Return values
Type|nullgetTypes()
Gets types of a property.
public
getTypes(string $class, string $property[, array<string|int, mixed> $context = [] ]) : array<string|int, Type>|null
since Symfony 7.3, use "getType" instead
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
array<string|int, Type>|nullgetTypesFromConstructor()
Gets types of an argument from constructor.
public
getTypesFromConstructor(string $class, string $property) : array<string|int, Type>|null
since Symfony 7.3, use "getTypeFromConstructor" instead
Parameters
- $class : string
- $property : string
Return values
array<string|int, Type>|nullgetWriteInfo()
Get write information object for a given property of a class.
public
getWriteInfo(string $class, string $property[, array<string|int, mixed> $context = [] ]) : PropertyWriteInfo|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
PropertyWriteInfo|nullisInitializable()
Is the property initializable? Returns true if a constructor's parameter matches the given property name.
public
isInitializable(string $class, string $property[, array<string|int, mixed> $context = [] ]) : bool|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
bool|nullisReadable()
Is the property readable?
public
isReadable(string $class, string $property[, array<string|int, mixed> $context = [] ]) : bool|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
bool|nullisWritable()
Is the property writable?
public
isWritable(string $class, string $property[, array<string|int, mixed> $context = [] ]) : bool|null
Parameters
- $class : string
- $property : string
- $context : array<string|int, mixed> = []
Return values
bool|nullcamelize()
Camelizes a given string.
private
camelize(string $string) : string
Parameters
- $string : string
Return values
stringextractFromAccessor()
Tries to extract type information from accessors.
private
extractFromAccessor(string $class, string $property) : array<string|int, Type>|null
Parameters
- $class : string
- $property : string
Return values
array<string|int, Type>|nullextractFromConstructor()
Tries to extract type information from constructor.
private
extractFromConstructor(string $class, string $property) : array<string|int, Type>|null
Parameters
- $class : string
- $property : string
Return values
array<string|int, Type>|nullextractFromMutator()
private
extractFromMutator(string $class, string $property) : array<string|int, Type>|null
Parameters
- $class : string
- $property : string
Return values
array<string|int, Type>|nullextractFromPropertyDeclaration()
private
extractFromPropertyDeclaration(string $class, string $property) : array<string|int, mixed>|null
Parameters
- $class : string
- $property : string
Return values
array<string|int, mixed>|nullextractFromReflectionType()
private
extractFromReflectionType(ReflectionType $reflectionType, ReflectionClass $declaringClass) : array<string|int, mixed>
Parameters
- $reflectionType : ReflectionType
- $declaringClass : ReflectionClass
Return values
array<string|int, mixed>extractTypeFromConstructor()
private
extractTypeFromConstructor(ReflectionClass $reflectionClass, string $property) : Type|null
Parameters
- $reflectionClass : ReflectionClass
- $property : string
Return values
Type|nullfindAdderAndRemover()
Searches for add and remove methods.
private
findAdderAndRemover(ReflectionClass $reflClass, array<string|int, mixed> $singulars) : array<string|int, mixed>
Parameters
- $reflClass : ReflectionClass
-
The reflection class for the given object
- $singulars : array<string|int, mixed>
-
The singular form of the property name or null
Return values
array<string|int, mixed> —An array containing the adder and remover when found and errors
getAccessorMethod()
Gets the accessor method.
private
getAccessorMethod(string $class, string $property) : array<string|int, mixed>|null
Returns an array with an instance of \ReflectionMethod as the first key and the prefix of the method as the second, or null if not found.
Parameters
- $class : string
- $property : string
Return values
array<string|int, mixed>|nullgetMethodsFlags()
Return allowed reflection method flags.
private
getMethodsFlags(int $accessFlags) : int
Parameters
- $accessFlags : int
Return values
intgetMutatorMethod()
Returns an array with an instance of \ReflectionMethod as the first key and the prefix of the method as the second, or null if not found.
private
getMutatorMethod(string $class, string $property) : array<string|int, mixed>|null
Parameters
- $class : string
- $property : string
Return values
array<string|int, mixed>|nullgetPropertyFlags()
Return allowed reflection property flags.
private
getPropertyFlags(int $accessFlags) : int
Parameters
- $accessFlags : int
Return values
intgetPropertyName()
private
getPropertyName(string $methodName, array<string|int, mixed> $reflectionProperties) : string|null
Parameters
- $methodName : string
- $reflectionProperties : array<string|int, mixed>
Return values
string|nullgetReadVisibilityForMethod()
private
getReadVisibilityForMethod(ReflectionMethod $reflectionMethod) : string
Parameters
- $reflectionMethod : ReflectionMethod
Return values
stringgetReadVisibilityForProperty()
private
getReadVisibilityForProperty(ReflectionProperty $reflectionProperty) : string
Parameters
- $reflectionProperty : ReflectionProperty
Return values
stringgetReflectionParameterFromConstructor()
private
getReflectionParameterFromConstructor(string $property, ReflectionMethod $reflectionConstructor) : ReflectionParameter|null
Parameters
- $property : string
- $reflectionConstructor : ReflectionMethod
Return values
ReflectionParameter|nullgetWriteVisibilityForMethod()
private
getWriteVisibilityForMethod(ReflectionMethod $reflectionMethod) : string
Parameters
- $reflectionMethod : ReflectionMethod
Return values
stringgetWriteVisibilityForProperty()
private
getWriteVisibilityForProperty(ReflectionProperty $reflectionProperty) : string
Parameters
- $reflectionProperty : ReflectionProperty
Return values
stringisAllowedProperty()
private
isAllowedProperty(string $class, string $property[, bool $writeAccessRequired = false ]) : bool
Parameters
- $class : string
- $property : string
- $writeAccessRequired : bool = false
Return values
boolisMethodAccessible()
Returns whether a method is public and has the number of required parameters and errors.
private
isMethodAccessible(ReflectionClass $class, string $methodName, int $parameters) : array<string|int, mixed>
Parameters
- $class : ReflectionClass
- $methodName : string
- $parameters : int
Return values
array<string|int, mixed>isNullableProperty()
private
isNullableProperty(string $class, string $property) : bool
Parameters
- $class : string
- $property : string
Return values
boolresolveTypeName()
private
resolveTypeName(string $name, ReflectionClass $declaringClass) : string
Parameters
- $name : string
- $declaringClass : ReflectionClass