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(string|array $hint)
Parse the hint parameter.
at line 94
register(string|array $hint, string|Closure $class, bool $singleton = false)
Register a type hint.
at line 105
registerSingleton(string|array $hint, string|Closure $class)
Register a type hint and return the same instance every time.
at line 116
registerInstance(string|array $hint, object $instance)
Register a singleton instance.
at line 128
registerContextualDependency(string $class, string $interface, string $implementation)
Registers a contextual dependency.
at line 139
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 149
protected
replaceInstances(string $hint)
Replaces previously resolved instances.
at line 169
onReplace(string $hint, callable $replacer, string|null $eventName = null)
Registers replacers.
at line 183
replace(string $hint, string|Closure $class, bool $singleton = false)
Replaces a registered type hint.
at line 208
replaceSingleton(string $hint, string|Closure $class)
Replaces a registered singleton type hint.
at line 219
replaceInstance(string $hint, object $instance)
Replaces a singleton instance.
at line 239
protected string|Closure
resolveHint(string $hint)
Resolves a type hint.
at line 251
protected string
resolveContextualDependency(string $class, string $interface)
Resolves a contextual dependency.
at line 263
protected array
mergeParameters(array $reflectionParameters, array $providedParameters)
Merges the provided parameters with the reflection parameters.
at line 294
protected string
getDeclaringFunction(ReflectionParameter $parameter)
Returns the name of the declaring function.
at line 318
protected mixed
resolveParameter(ReflectionParameter $parameter, ReflectionClass|null $class = null)
Resolve a parameter.
at line 373
protected array
resolveParameters(array $reflectionParameters, array $providedParameters, ReflectionClass|null $class = null)
Resolve parameters.
at line 405
protected bool
isContainerAware(object $class)
Checks if a class is container aware.
at line 419
protected object
closureFactory(Closure $factory, array $parameters)
Creates a class instance using a factory closure.
at line 433
protected object
reflectionFactory(string $class, array $parameters)
Creates a class instance using reflection.
at line 467
object
factory(string|Closure $class, array $parameters = [])
Creates a class instance.
at line 498
bool
has(string $class)
Returns TRUE if the class is registered in the container and FALSE if not.
at line 511
bool
hasInstanceOf(string $class)
Returns TRUE if there's an instance of the class in the container and FALSE if not.
at line 522
bool
isSingleton(string $class)
Returns TRUE if a class has been registered as a singleton and FALSE if not.
at line 537
object
get(string $class, array $parameters = [], bool $reuseInstance = true)
Returns a class instance.
at line 571
object
getFresh(string $class, array $parameters = [])
Returns a fresh class instance even if the class is registered as a singleton.
at line 583
mixed
call(callable $callable, array $parameters = [])
Execute a callable and inject its dependencies.