Container
class Container
Inversion of control container.
Properties
protected array | $hints | Registered type hints. | |
protected array | $aliases | Aliases. | |
protected array | $instances | Singleton instances. | |
protected array | $contextualDependencies | Contextual dependencies. | |
protected array | $replacers | Instance replacers. |
Methods
Parse the hint parameter.
Register a type hint and return the same instance every time.
Register a singleton instance.
Registers a contextual dependency.
Return the name based on its alias. If no alias exists then we'll just return the value we received.
Replaces previously resolved instances.
Registers replacers.
Replaces a singleton instance.
Resolves a type hint.
Resolves a contextual dependency.
Merges the provided parameters with the reflection parameters.
Resolve a parameter.
Resolve parameters.
Checks if a class is container aware.
Creates a class instance using a factory closure.
Creates a class instance using reflection.
Returns TRUE if the class is registered in the container and FALSE if not.
Returns TRUE if there's an instance of the class in the container and FALSE if not.
Returns TRUE if a class has been registered as a singleton and FALSE if not.
Returns a class instance.
Returns a fresh class instance even if the class is registered as a singleton.
Execute a callable and inject its dependencies.
Details
at line 75
protected string
parseHint(array|string $hint)
Parse the hint parameter.
at line 94
register(array|string $hint, Closure|string $class, bool $singleton = false)
Register a type hint.
at line 105
registerSingleton(array|string $hint, Closure|string $class)
Register a type hint and return the same instance every time.
at line 116
registerInstance(array|string $hint, object $instance)
Register a singleton instance.
at line 128
registerContextualDependency(array|string $dependent, string $interface, string $implementation)
Registers a contextual dependency.
at line 144
protected string
resolveAlias(string $alias)
Return the name based on its alias. If no alias exists then we'll just return the value we received.
at line 154
protected
replaceInstances(string $hint)
Replaces previously resolved instances.
at line 174
onReplace(string $hint, callable $replacer, string|null $eventName = null)
Registers replacers.
at line 188
replace(string $hint, Closure|string $class, bool $singleton = false)
Replaces a registered type hint.
at line 213
replaceSingleton(string $hint, Closure|string $class)
Replaces a registered singleton type hint.
at line 224
replaceInstance(string $hint, object $instance)
Replaces a singleton instance.
at line 244
protected Closure|string
resolveHint(string $hint)
Resolves a type hint.
at line 256
protected string
resolveContextualDependency(string $dependent, string $interface)
Resolves a contextual dependency.
at line 268
protected array
mergeParameters(array $reflectionParameters, array $providedParameters)
Merges the provided parameters with the reflection parameters.
at line 299
protected string
getDeclaringFunction(ReflectionParameter $parameter)
Returns the name of the declaring function.
at line 324
protected mixed
resolveParameter(ReflectionParameter $parameter, ReflectionClass|null $class = null, string|null $method = null)
Resolve a parameter.
at line 382
protected array
resolveParameters(array $reflectionParameters, array $providedParameters, ReflectionClass|null $class = null, string|null $method = null)
Resolve parameters.
at line 414
protected bool
isContainerAware(object $class)
Checks if a class is container aware.
at line 428
protected object
closureFactory(Closure $factory, array $parameters)
Creates a class instance using a factory closure.
at line 442
protected object
reflectionFactory(string $class, array $parameters)
Creates a class instance using reflection.
at line 476
object
factory(Closure|string $class, array $parameters = [])
Creates a class instance.
at line 507
bool
has(string $class)
Returns TRUE if the class is registered in the container and FALSE if not.
at line 520
bool
hasInstanceOf(string $class)
Returns TRUE if there's an instance of the class in the container and FALSE if not.
at line 531
bool
isSingleton(string $class)
Returns TRUE if a class has been registered as a singleton and FALSE if not.
at line 546
object
get(string $class, array $parameters = [], bool $reuseInstance = true)
Returns a class instance.
at line 580
object
getFresh(string $class, array $parameters = [])
Returns a fresh class instance even if the class is registered as a singleton.
at line 592
mixed
call(callable $callable, array $parameters = [])
Execute a callable and inject its dependencies.