Neuron-PHP

IContainer

PSR-11 compatible dependency injection container interface

Provides dependency injection with auto-wiring capabilities. Compatible with PSR-11 Container Interface standard.

Table of Contents

Methods

bind()  : void
Bind an abstract type to a concrete implementation
get()  : mixed
Finds an entry of the container by its identifier and returns it.
has()  : bool
Returns true if the container can return an entry for the given identifier.
instance()  : void
Register an existing instance as a singleton
make()  : object
Resolve and instantiate a class with automatic dependency injection
singleton()  : void
Register a singleton (shared instance) in the container

Methods

bind()

Bind an abstract type to a concrete implementation

public bind(string $abstract, string $concrete) : void
Parameters
$abstract : string

Interface or abstract class name

$concrete : string

Concrete class name

get()

Finds an entry of the container by its identifier and returns it.

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

Identifier of the entry to look for (typically a class name or interface)

Tags
throws
NotFoundException

No entry was found for this identifier.

throws
ContainerException

Error while retrieving the entry.

Return values
mixed

Entry.

has()

Returns true if the container can return an entry for the given identifier.

public has(string $id) : bool

Returns false otherwise.

Parameters
$id : string

Identifier of the entry to look for.

Return values
bool

instance()

Register an existing instance as a singleton

public instance(string $abstract, object $instance) : void
Parameters
$abstract : string

Interface or class name

$instance : object

The instance to register

make()

Resolve and instantiate a class with automatic dependency injection

public make(string $class[, array<string|int, mixed> $parameters = [] ]) : object

Uses reflection to analyze constructor parameters and automatically resolves dependencies from the container.

Parameters
$class : string

Fully qualified class name

$parameters : array<string|int, mixed> = []

Optional parameters to override auto-wiring

Tags
throws
ContainerException

If the class cannot be instantiated

Return values
object

Instance of the requested class

singleton()

Register a singleton (shared instance) in the container

public singleton(string $abstract, callable $factory) : void
Parameters
$abstract : string

Interface or class name

$factory : callable

Factory function that creates the instance


        
On this page

Search results