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 76
protected string
parseHint(string|array $hint)
Parse the hint parameter.
at line 95
register(string|array $hint, string|Closure $class, bool $singleton = false)
Register a type hint.
at line 106
registerSingleton(string|array $hint, string|Closure $class)
Register a type hint and return the same instance every time.
at line 117
registerInstance(string|array $hint, object $instance)
Register a singleton instance.
at line 129
registerContextualDependency(string $class, string $interface, string $implementation)
Registers a contextual dependency.
at line 140
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 150
protected
replaceInstances(string $hint)
Replaces previously resolved instances.
at line 170
onReplace(string $hint, callable $replacer, string|null $eventName = null)
Registers replacers.
at line 184
replace(string $hint, string|Closure $class, bool $singleton = false)
Replaces a registered type hint.
at line 209
replaceSingleton(string $hint, string|Closure $class)
Replaces a registered singleton type hint.
at line 220
replaceInstance(string $hint, object $instance)
Replaces a singleton instance.
at line 240
protected string|Closure
resolveHint(string $hint)
Resolves a type hint.
at line 252
protected string
resolveContextualDependency(string $class, string $interface)
Resolves a contextual dependency.
at line 264
protected array
mergeParameters(array $reflectionParameters, array $providedParameters)
Merges the provided parameters with the reflection parameters.
at line 295
protected string
getDeclaringFunction(ReflectionParameter $parameter)
Returns the name of the declaring function.
at line 319
protected mixed
resolveParameter(ReflectionParameter $parameter, ReflectionClass|null $class = null)
Resolve a parameter.
at line 376
protected array
resolveParameters(array $reflectionParameters, array $providedParameters, ReflectionClass|null $class = null)
Resolve parameters.
at line 408
protected bool
isContainerAware(object $class)
Checks if a class is container aware.
at line 422
protected object
closureFactory(Closure $factory, array $parameters)
Creates a class instance using a factory closure.
at line 436
protected object
reflectionFactory(string $class, array $parameters)
Creates a class instance using reflection.
at line 470
object
factory(string|Closure $class, array $parameters = [])
Creates a class instance.
at line 501
bool
has(string $class)
Returns TRUE if the class is registered in the container and FALSE if not.
at line 514
bool
hasInstanceOf(string $class)
Returns TRUE if there's an instance of the class in the container and FALSE if not.
at line 525
bool
isSingleton(string $class)
Returns TRUE if a class has been registered as a singleton and FALSE if not.
at line 540
object
get(string $class, array $parameters = [], bool $reuseInstance = true)
Returns a class instance.
at line 574
object
getFresh(string $class, array $parameters = [])
Returns a fresh class instance even if the class is registered as a singleton.
at line 586
mixed
call(callable $callable, array $parameters = [])
Execute a callable and inject its dependencies.