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.
Checks if a class is registered in the container.
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 74
protected string
parseHint(string|array $hint)
Parse the hint parameter.
at line 93
register(string|array $hint, string|Closure $class, bool $singleton = false)
Register a type hint.
at line 104
registerSingleton(string|array $hint, string|Closure $class)
Register a type hint and return the same instance every time.
at line 115
registerInstance(string|array $hint, object $instance)
Register a singleton instance.
at line 127
registerContextualDependency(string $class, string $interface, string $implementation)
Registers a contextual dependency.
at line 138
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 148
protected
replaceInstances(string $hint)
Replaces previously resolved instances.
at line 168
onReplace(string $hint, callable $replacer, string $eventName = null)
Registers replacers.
at line 182
replace(string $hint, string|Closure $class, bool $singleton = false)
Replaces a registered type hint.
at line 207
replaceSingleton(string $hint, string|Closure $class)
Replaces a registered singleton type hint.
at line 218
replaceInstance(string $hint, object $instance)
Replaces a singleton instance.
at line 238
protected string|Closure
resolveHint(string $hint)
Resolves a type hint.
at line 250
protected string
resolveContextualDependency(string $class, string $interface)
Resolves a contextual dependency.
at line 262
protected array
mergeParameters(array $reflectionParameters, array $providedParameters)
Merges the provided parameters with the reflection parameters.
at line 300
protected string
getDeclaringFunction(ReflectionParameter $parameter)
Returns the name of the declaring function.
at line 324
protected mixed
resolveParameter(ReflectionParameter $parameter, ReflectionClass $class = null)
Resolve a parameter.
at line 360
protected array
resolveParameters(array $reflectionParameters, array $providedParameters, ReflectionClass $class = null)
Resolve parameters.
at line 392
protected bool
isContainerAware(object $class)
Checks if a class is container aware.
at line 406
protected object
closureFactory(Closure $factory, array $parameters)
Creates a class instance using a factory closure.
at line 429
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)
Checks if a class is registered in the container.
at line 511
bool
isSingleton(string $class)
Returns TRUE if a class has been registered as a singleton and FALSE if not.
at line 526
object
get(string $class, array $parameters = [], bool $reuseInstance = true)
Returns a class instance.
at line 560
object
getFresh(string $class, array $parameters = [])
Returns a fresh class instance even if the class is registered as a singleton.
at line 572
object
call(callable $callable, array $parameters = [])
Execute a callable and inject its dependencies.