Simple PHP DI Container.
composer require amber/container
use Amber\Container\Container;
$container = new Container();
bind(string $key, mixed $value) : boolean
param string $key The unique item's key.
param mixed $value The value of the item.
return bool True on success. False if key already exists.
Bind an Service to the container by a unique key.
$container->bind($key, $value);
Or bind a class like this.
$container->bind($class);
get(string $key): mixed
param string $key *The unique item's key.
return mixed The value of the item.
$container->get($key);
has(string $key): bool param string $key *The unique item's key. return bool
$container->has($key);
unbind(string $key): bool
param string $key *The unique item's key.
return bool true on success, false on failure.
$container->unbind($key);
$container->bindMultiple([$key => $value]);
$container->getMultiple($keys);
$container->unbindMultiple($keys);
make(string $class): mixed
param string $class The item's class.
return mixed The value of the item.
$container->make($class);
register(string $class, string $alias = null): ServiceClass
param string $class The item's class.
param string $alias The item's alias.
return ServiceClass
$container->register($class);
singleton(string $class, string $alias = null): ServiceClass
param string $class The item's class.
param string $alias The item's alias.
return ServiceClass
$container->singleton($class);
getClosureFor(string $class, string $method, array $binds = []): Closure
param string $class The class to instantiate.
param string $method The class method to call.
param array $binds The arguments for the service.
return Closure
$container->getClosureFor($class, $method);
More coming soon...