Container
in package
Container - DI Container with auto-wiring
- Explicit bindings: interface/class → factory (e.g. repositories, services).
- Auto-wiring: for any class not registered, the container instantiates it by resolving constructor parameters from the container (reflection).
So you only register "leaf" dependencies in config; controllers are resolved automatically when their constructor type-hints interfaces already bound.
Tags
Table of Contents
Properties
- $bindings : array<string, callable>
- $instances : array<string, object>
Methods
- get() : object
- Resolve by id: use binding if present, else auto-wire the class
- has() : bool
- True if the container can resolve this id (binding or auto-wirable class)
- set() : self
- Register a binding in the container
- resolveClass() : object
- Instantiate a class by resolving its constructor parameters from the container
Properties
$bindings
private
array<string, callable>
$bindings
= []
$instances
private
array<string, object>
$instances
= []
Resolved instances for bound ids (singleton per id)
Methods
get()
Resolve by id: use binding if present, else auto-wire the class
public
get(string $id) : object
Parameters
- $id : string
Tags
Return values
objecthas()
True if the container can resolve this id (binding or auto-wirable class)
public
has(string $id) : bool
Parameters
- $id : string
Return values
boolset()
Register a binding in the container
public
set(string $id, callable $builder) : self
Parameters
- $id : string
-
Service identifier (class or interface name)
- $builder : callable
-
Factory callable that receives the container and returns the instance
Return values
self —For method chaining
resolveClass()
Instantiate a class by resolving its constructor parameters from the container
private
resolveClass(class-string $class) : object
Parameters
- $class : class-string
-
Fully qualified class name