Hi, 😃 👋
This is a minimalistic PHP project with the aim to provide simple but powerfull solution to anyone, who thinks Dipendency Injection (DI) is something usefull.
PHPDI is a DI container, allowing you to controll your dependencies throughout your whole project. Here I will not explain in details, what DI and the containers are. For more references, you can visit this site 👉 HERE
The whole disign behind the realisation is Convention over Configuration. That, does not mean that you will not need to adjust some tweeks,but nothing special.
Currently there are two versions of the project:
Beta state means, that everithing tested so far works, but there might be some small bugs.
Alpha state means, that it is still in phase of testing and might be unstable, but you can always give a try and report an issue, bug or missing feature.
Config options | Description | Object type (Injection) |
---|---|---|
className | Name of the class to inject | Object, with parameterless constructor |
isSingleton | Creates singleton object | Object, with parameterless constructor |
Config options | Description | Object type (Injection) |
---|---|---|
name | Name of the value | Value type object |
type | Type of the object (string, int and so on) | Value type object |
value | Value, desired to be returned | Value type object |
Config options | Description | Object type (Injection) |
---|---|---|
className | Name of the class to inject | Object, with constructor with parameters |
isSingleton | Creates singleton object | Object, with constructor with parameters |
params | The params for constructor | Object, with constructor with parameters |
In the params, the root node is the name of parameter in the constructor and in it the defaulValue.
See the examples in the project.
There is an AutoLoader, which loads the classes automatically when needed. Just specify the path in the LoaderConfig.php once.
You can easily switch between different configured injection configurations for development, testing and production.
Be sure that only allowed classes can create instance and use a dependency of object
Option to log all injections - where and which examples are used.
Option to log some catched exceptions - where and which examples are used.
Option to check whether all injections have and Interface, inherited by them.
All these things, can be modified in the Config.php
- Import Container in the file
- Get instance of the container (static method)
- Call the requested method with the correct parameters. (To get reference type object pass the className with the "I" prefix -> IclassName).
3.1. Example for parameter for getInjectionWithParams method -["params" => array(["name" => "url"])]);
If "value" is not given, the default from the config is used.
In progress, main feature lazy instantiation
If you have read all the things until here, congratulations 👏 and thank you for your interest 👍
The license for this is open source and free to use. I will appriciate a star or a good word if you think it deserves it.
You can raise issues and report problems or missing features. You can help with ideas and solutions too.
For contact - ivangrigorov9 at gmail.com