Download the PHP package mmdm/sim-container without Composer
On this page you can find all versions of the php package mmdm/sim-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mmdm/sim-container
More information about mmdm/sim-container
Files in mmdm/sim-container
Package sim-container
Short Description A simple yet nice dependency injection container
License MIT
Informations about the package sim-container
Simplicity Container
A library for dependency injection management.
Features
- Auto wiring
- Singleton construction
- Factory construction
- Method injection
- Both method and array access
Install
composer
Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.
Just add line below to autoload files:
and you are good to go.
How to use
Available functions
Container
set($abstract, $concrete = null, ?string $method_name = null, array $method_parameters = []): Container
This method store a $concrete with alias of $abstract like class name or any other name.
Version >= 1.2.0
:
Also you can pass the method to be inject as $method_name and
parameters of the method as $method_parameters. Parameters can be
the actual parameter or an abstract to get by container.
Note: You can pass $concrete as $abstract
Note: Parameters are a key value pair like below:
get($abstract, ?string $method_name = null, array $method_parameters = [])
This method return a $concrete that stored with alias of $abstract. If it was not exists, it will simply store it first and then resolve that.
Version >= 1.2.0
:
Also you can pass the method to be inject as $method_name and
parameters of the method as $method_parameters. Parameters can be
the actual parameter or an abstract to get by container.
Note: If a stored $concrete has been resolved, it will not resolve again, just return previous resolved $concrete.
Note: Parameters are a key value pair like below:
make($abstract, ?string $method_name = null, array $method_parameters = [])
This method return a $concrete that stored with alias of $abstract. If it was not exists, it will simply store it first and then resolve that.
Parameters are same as get
method
has($abstract, string $method_name = null): bool
This method check if a specific alias $abstract is stored or not. Also
you can pass the $method_name
to check if specific $abstract
's
method is registered.
unset($abstract, string $method_name = null): Container
This method remove a stored $abstract. Also you can
pass the $method_name
to remove specific $abstract
's
method.
Singleton accessing
If you need to access container in singleton manner, use
getInstance
static method.
Container Inheritance
If you want to inherit Container
(to customize maybe), you
can inherit like normal way but if you have multiple class to
inherit, then use ContainerTrait
inside your class and inherit
other class as well.
Note: After a trait using, you should type hint Container
to YourOtherClass
in closures.
Array accessing
You can use array accessing instead of method accessing:
$container[$abstract] = $concrete
instead of$container->set($abstract, $concrete, ?string $method_name = null, array $method_parameters = [])
.
Accepts $offset as below:
OR
OR
OR
$concrete = $container[$abstract]
instead of$concrete = $container->get($abstract, ?string $method_name = null, array $method_parameters = [])
.
Accepts $offset as below:
OR
OR
OR
isset($container[$abstract])
instead of$container->has($abstract, string $method_name = null)
.
Accepts $offset as below:
OR
OR
OR
unset($container[$abstract])
instead of$container->unset($abstract, string $method_name = null)
.
Accepts $offset as below:
OR
OR
OR
License
Under MIT license.
All versions of sim-container with dependencies
ext-json Version *