CoRex IoC
, (*1)
This is a simple container helping managing class dependencies and performing dependency injection., (*2)
Methods.
- getInstance() - Get instance of container.
- clear() - Clear container for all bindings and instances.
- getBindings() - Get bindings.
- getBinding() - Get specific binding.
- has() - Check if class or interface has been bound.
- hasInstance() - Check if class or interface has been instantiated.
- isShared() - Check if class or interface is shared/is a singleton.
- isSingleton() - Check if class or interface is shared/is a singleton.
- forget() - Forget specified binding and instance.
- bind() - Bind class or instance.
- singleton() - Bind class or instance as shared/singleton.
- instance() - Set instance on existing binding.
- make() - Make instance of class or interface.
Create a container.
// Create new container.
$container = new Container();
// Create/use existing container.
$container = Container::getInstance();
Make a class without binding.
$myClass = Container::getInstance()->make(MyClass::class);
Make a class with binding and parameters.
$container = Container::getInstance();
$container->bind(MyClassInterface::class, MyClass::class);
$myClass = $container->make(MyClass::class, [
'test' => 'my.value'
]);
- When making a class via bound interface, the instance class will be checked if it implements the bound interface.
- When making a class via bound base-class, the instance class will be checked if it extends the bound base class.