Download the PHP package codeia/di-senpai without Composer
On this page you can find all versions of the php package codeia/di-senpai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codeia/di-senpai
More information about codeia/di-senpai
Files in codeia/di-senpai
Package di-senpai
Short Description DI framework; implements container-interop
License BSD-2-Clause
Informations about the package di-senpai
DI-senpai
Auto resolving dependency injector. Build your object graphs programmatically.
Installation
$ composer require codeia/di-senpai
Usage
Create a container:
You can also use any
Psr\Container\ContainerInterface
impl, butAutoResolve
is quite useful and is what makesSenpai
work its magic. You can wrap aContainerInterface
in anAutoResolve
r then use that.
AutoResolve
andObjectGraph
both implementContainerInterface
, so you can use them in other frameworks that can take them, likezend-expressive
.
Call your senpai:
Build your object and their privates will be populated:
Leave out the second argument to
inject()
if you only want to inject public members.
- Only the object's members are injected. The dependencies' insides are not touched.
- No method injection is done. I don't believe setter injection should be a thing.
WARNING
This ties your classes to the DI framework! AVOID THIS IF YOU CAN! This severely limits the reusability of your classes. I myself only use this on classes that I probably won't ever reuse (like controllers) and only if they have a lot of dependencies (5 is my threshold).
Other legitimate uses are in frameworks where you don't have control over the instantiation and only provides hooks for your own code. Like activities in Android. Don't know if there are any frameworks that still work like that, it seems that lambdas are all the rage these days. Although again, I only recommend it when you have 5 or more dependencies to populate.
Even so, the AutoResolve
and ObjectGraph
classes are still handy can be
used on their own.