Skip to content

Commit 96c0951

Browse files
author
Carlos Alberto B. Carucce
committed
Updating README
- Additional information on installation, contribution, license and usage example
1 parent 88e8901 commit 96c0951

1 file changed

Lines changed: 66 additions & 2 deletions

File tree

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,73 @@
1-
# Yadic
1+
# Yet another dependency injection container for PHP
22

33
![StyleCi](https://github.styleci.io/repos/816542238/shield)
44
[![Latest Stable Version](https://poser.pugx.org/webdevcave/yadic/v/stable?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)
55
[![Latest Unstable Version](https://poser.pugx.org/webdevcave/yadic/v/unstable?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)
66
[![Total Downloads](https://poser.pugx.org/webdevcave/yadic/downloads?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)
77
[![License](https://poser.pugx.org/webdevcave/yadic/license?format=flat-square)](https://packagist.org/packages/webdevcave/yadic)
88

9-
Yet another dependency injection container for PHP
9+
This is a simple to use, yet powerful service container that provides a seamless way to automate dependency injection
10+
with auto-wiring.
11+
12+
```bash
13+
composer require webdevcave/yadic
14+
```
15+
16+
Alternatively, you can clone the repository or download the source files directly and include them in your project.
17+
18+
```php
19+
<?php
20+
21+
require_once __DIR__.'/vendor/autoload.php';
22+
23+
use Webdevcave\Yadic\Annotations\Provides;
24+
use Webdevcave\Yadic\Annotations\Singleton;
25+
use Webdevcave\Yadic\ServiceContainer;
26+
27+
interface StorageInterface
28+
{
29+
public function store(mixed $data): bool;
30+
}
31+
32+
#[Provides(StorageInterface::class)]
33+
#[Singleton]
34+
class Storage implements StorageInterface
35+
{
36+
public function store(mixed $data): bool
37+
{
38+
//store data...
39+
40+
return true;
41+
}
42+
}
43+
44+
class MyController
45+
{
46+
public function __construct(
47+
private StorageInterface $storage
48+
) {
49+
}
50+
51+
public function save(): bool
52+
{
53+
return $this->storage->store('my data...');
54+
}
55+
}
56+
57+
$container = new ServiceContainer();
58+
59+
//No need to do this in a real world application:
60+
$container->addAlias(StorageInterface::class, Storage::class);
61+
62+
//Use this instead:
63+
//$container->loadDefinitionsFromDirectory($directory, $namespace); //Loads annotations from classes declared in a PSR4 directory
64+
65+
var_dump($container->get(MyController::class)->save()); //bool(true)
66+
```
67+
68+
## Contributing
69+
Contributions are welcome! If you find any issues or have suggestions for improvements,
70+
please open an issue or a pull request on GitHub.
71+
72+
## License
73+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)