\Omega\Container ContainerInterface

Interface for a dependency injection container.

The Container interface provides a contract for managing class instances and their dependencies. It allows for binding classes to specific aliases, resolving dependencies, and retrieving instances.

This interface extends the PSR-11 ContainerInterface and adds additional methods for enhanced functionality, including the ability to remove bindings, clear all bindings, and retrieve the current set of bindings.

Implementations of this interface should ensure proper handling of dependency resolution, enabling efficient and flexible management of service instances within an application.

Summary

Methods
Constants
has()
get()
alias()
resolve()
call()
remove()
clear()
getBindings()
No public constants found

Methods

has()

has(string  $alias) : bool

Determine if the container has a binding for the given alias.

Parameters

string $alias

The class alias or key to check.

Returns

bool —

Returns true if the alias exists in the container bindings, false otherwise.

get()

get(string  $alias) : mixed

Retrieve an instance from the container by alias.

Parameters

string $alias

The class alias or key.

Throws

\Omega\Container\Exception\KeyNotFoundException

if the alias is not found in the container.

Returns

mixed —

The resolved class instance.

alias()

alias(string  $alias, callable  $factory) : $this

Bind the class.

Parameters

string $alias

Holds the class alias or key.

callable $factory

Holds a closure that defines how to create the class instance.

Returns

$this —

resolve()

resolve(string  $alias) : mixed

Resolve the container.

Parameters

string $alias

Holds the class alias or key.

Throws

\Omega\Container\Exception\KeyNotFoundException

if the key is not bound.

Returns

mixed —

Return the resolved class instance.

call()

call(callable|array{0: object|string, 1: string}  $callable, array  $parameters = []) : mixed

Call a callable with dependency injection.

Parameters

callable|array{0: object|string, 1: string} $callable

Holds the callable function or method.

array $parameters

Holds an associative array of additional parameters to pass.

Throws

\ReflectionException

if the callable cannot be reflected.

\Omega\Container\Exception\DependencyResolutionException

if a dependency cannot be resolved.

\InvalidArgumentException

if the callable is not invocable.

Returns

mixed —

Return the result of the callable.

remove()

remove(string  $alias) : bool

Remove the binding for the given alias.

Parameters

string $alias

The class alias or key to remove.

Returns

bool —

Returns true if the alias was found and removed, false otherwise.

clear()

clear() : void

Clear all bindings from the container.

This method removes all registered aliases and resolved instances.

Returns

void —

getBindings()

getBindings() : array<string,callable>

Get all bindings from the container.

Returns

array

Returns an array of all registered bindings.