Container
in package

Dependency Injection Container

Simple container implementation that supports singleton and non-singleton services. Services are registered as closures that receive the container instance for dependency resolution.

Tags
since
4.0.0

Table of Contents

Properties

$registry  : array<string, AbstractResolver>
Registry of service resolvers.

Methods

get()  : mixed
Retrieve a service from the container.
has()  : bool
Check if a service is registered.
register()  : void
Register a service in the container.

Properties

Methods

get()

Retrieve a service from the container.

public get(string $id) : mixed
Parameters
$id : string

Service identifier.

Tags
throws
Exception

If the service is not registered.

Return values
mixed

The resolved service instance.

has()

Check if a service is registered.

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

Service identifier.

Return values
bool

True if the service is registered, false otherwise.

register()

Register a service in the container.

public register(string $id, mixed $value[, bool $singleton = true ]) : void
Parameters
$id : string

Service identifier (typically the class name).

$value : mixed

Either a closure that returns the service instance, or the instance itself.

$singleton : bool = true

Whether the service should be a singleton (default: true).


        
On this page

Search results