AttributeBasedAutowiring
in package
implements
DefinitionSource, Autowiring
Provides DI definitions by reading PHP 8 attributes such as #[Inject] and #[Injectable].
This source automatically includes the reflection source.
Tags
Table of Contents
Interfaces
- DefinitionSource
- Source of definitions for entries of the container.
- Autowiring
- Source of definitions for entries of the container.
Methods
- autowire() : ObjectDefinition|null
- Autowire the given definition.
- getDefinition() : ObjectDefinition|null
- Returns the DI definition for the entry name.
- getDefinitions() : array<string, Definition>
- Autowiring cannot guess all existing definitions.
- getMethodInjection() : MethodInjection|null
- getMethodParameter() : string|null
- readInjectableAttribute() : void
- readMethods() : void
- Browse the object's methods looking for annotated methods.
- readProperties() : void
- Browse the class properties looking for annotated properties.
- readProperty() : void
Methods
autowire()
Autowire the given definition.
public
autowire(string $name[, ObjectDefinition|null $definition = null ]) : ObjectDefinition|null
Parameters
- $name : string
- $definition : ObjectDefinition|null = null
Tags
Return values
ObjectDefinition|nullgetDefinition()
Returns the DI definition for the entry name.
public
getDefinition(string $name) : ObjectDefinition|null
Parameters
- $name : string
Tags
Return values
ObjectDefinition|nullgetDefinitions()
Autowiring cannot guess all existing definitions.
public
getDefinitions() : array<string, Definition>
Return values
array<string, Definition> —Definitions indexed by their name.
getMethodInjection()
private
getMethodInjection(ReflectionMethod $method) : MethodInjection|null
Parameters
- $method : ReflectionMethod
Return values
MethodInjection|nullgetMethodParameter()
private
getMethodParameter(int $parameterIndex, ReflectionParameter $parameter, array<string|int, mixed> $annotationParameters) : string|null
Parameters
- $parameterIndex : int
- $parameter : ReflectionParameter
- $annotationParameters : array<string|int, mixed>
Return values
string|null —Entry name or null if not found.
readInjectableAttribute()
private
readInjectableAttribute(ReflectionClass $class, ObjectDefinition $definition) : void
Parameters
- $class : ReflectionClass
- $definition : ObjectDefinition
Tags
readMethods()
Browse the object's methods looking for annotated methods.
private
readMethods(ReflectionClass $class, ObjectDefinition $objectDefinition) : void
Parameters
- $class : ReflectionClass
- $objectDefinition : ObjectDefinition
readProperties()
Browse the class properties looking for annotated properties.
private
readProperties(ReflectionClass $class, ObjectDefinition $definition) : void
Parameters
- $class : ReflectionClass
- $definition : ObjectDefinition
readProperty()
private
readProperty(ReflectionProperty $property, ObjectDefinition $definition[, string|null $classname = null ]) : void
Parameters
- $property : ReflectionProperty
- $definition : ObjectDefinition
- $classname : string|null = null