You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library provides a straightforward way to manage service dependencies in a PHP application. It follows the Inversion of Control principle, allowing classes to specify their dependencies without being responsible for their creation.
4
+
5
+
## Features
6
+
7
+
1.**Dependency Injection**: Enables classes to declare their dependencies in the constructor, which will be automatically injected when the class is instantiated.
8
+
9
+
2.**Service Container**: The library includes a service container that manages service instances. Services are created as singletons - once a service is created, the same instance will be returned every time it is requested.
10
+
11
+
3.**Simple API**: The library provides simple and intuitive methods for registering services and retrieving them from the service container.
12
+
13
+
## Usage
14
+
15
+
Here is a simple example of how to use the library:
16
+
17
+
```php
18
+
class MyClass {
19
+
public function __construct(CommonPHP\DependencyInjection\ServiceContainer $container)
20
+
{
21
+
// The service container is injected as a dependency
22
+
}
23
+
}
24
+
25
+
$di = new CommonPHP\DependencyInjection\DependencyInjector();
26
+
$container = new CommonPHP\DependencyInjection\ServiceContainer($di);
This library is designed to prevent direct dependency on the `DependencyInjector` inside services. The `DependencyInjector` should only be used during application bootstrapping.
36
+
37
+
## Installation
38
+
39
+
This section outlines how to install the `CommonPHP Dependency Injection` library.
40
+
41
+
### Requirements
42
+
43
+
- PHP 8.1 or newer.
44
+
45
+
### With Composer
46
+
47
+
The easiest way to install the `CommonPHP Dependency Injection` library is via Composer.
48
+
49
+
If you don't have Composer installed, you can download it from [https://getcomposer.org/](https://getcomposer.org/).
50
+
51
+
Once you have Composer installed, you can install the `CommonPHP Dependency Injection` library by running the following command in your terminal:
52
+
53
+
```bash
54
+
composer require comphp/di
55
+
```
56
+
57
+
This command will add the `CommonPHP Dependency Injection` library as a dependency to your project, and Composer will automatically handle the autoloading of classes.
58
+
59
+
### Manual Installation
60
+
61
+
If you don't use Composer, you can download the latest release of the `CommonPHP Dependency Injection` library from the GitHub repository. After downloading, you will have to handle autoloading the classes manually in your application.
62
+
63
+
After the installation, you can use the library as outlined in the Usage section.
64
+
65
+
## Next Steps
66
+
67
+
After the installation, refer to the Usage section of this README to learn how to use the `CommonPHP Dependency Injection` library in your projects.
68
+
69
+
## Testing
70
+
71
+
As of version 0.0.1, we are still in the process of refining the codebase and defining the overall functionality of the CommonPHP Dependency Injection library, as well as other libraries within the CommonPHP framework. Therefore, comprehensive unit tests have not been created yet.
72
+
73
+
However, quality and reliability are paramount to us. Rest assured, we plan to incorporate robust testing in future versions as the functionality becomes more concrete. In the meantime, we encourage contributions in all areas of the project, including tests.
74
+
75
+
If you are interested in contributing to testing, or any other aspect of this project, please see the 'Contributing' section for more information.
76
+
77
+
78
+
## License
79
+
80
+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
0 commit comments