wilkques / container
v4.0.0
2024-09-25 05:37 UTC
Requires
- php: >=5.3
README
How to use
composer require wilkques/container
require '<project path>/vendor/Container/src/helpers.php'; require '<project path>/vendor/Container/src/Container.php';
Method
-
register
container()->register( '<your class name>', new '<your class name>' ); // or container()->register([ [ '<your class name1>', new '<your class name1>' ], [ '<your class name2>', new '<your class name2>' ], ... ]);
-
bind
$abstract = new \Your\Class\Name; container()->bind('<your class name>', function () use ($abstract) { return $abstract; });
-
singleton
The singleton method binds a class or interface into the container that should only be resolved one time. Once a singleton binding is resolved, the same object instance will be returned on subsequent calls into the container:$abstract = new \Your\Class\Name; container()->singleton('<your class name>', function () use ($abstract) { return $abstract; });
-
scoped
$abstract = new \Your\Class\Name; container()->scoped('<your class name>', function () use ($abstract) { return $abstract; });
-
get
container()->get('<your class name>');
-
make
container('<your class name>'); // or container()->make('<your class name>');
-
call
container()->call(['<your class name>', '<your class method name>'], ['<your class method vars name>' => '<your class method vars value>']); // or container()->call([new '<your class name>', '<your class method name>'], ['<your class method vars name>' => '<your class method vars value>']); // or container()->call(function (\Your\Class\Name $abstract) { // do something });
-
forgetScopedInstances
Clear all of the scoped instances from the container. -
forgetInstance
container()->forgetInstance('<your class name>');
-
forgetInstances
Clear all of the instances from the container. -
flush
Flush the container of all bindings and resolved instances.