Documentation

Container
in package

Container - DI Container with auto-wiring

  1. Explicit bindings: interface/class → factory (e.g. repositories, services).
  2. 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
author

BdeLive - Group 8

version
2.0.0
  • Auto-wiring

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
throws
InvalidArgumentException

When id is not bound and not auto-wirable

Return values
object

has()

True if the container can resolve this id (binding or auto-wirable class)

public has(string $id) : bool
Parameters
$id : string
Return values
bool

set()

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

Return values
object

        
On this page

Search results