Skip to content

Commit

Permalink
Updating README
Browse files Browse the repository at this point in the history
- Additional information on installation, contribution, license and usage example
  • Loading branch information
carloscarucce committed Jun 26, 2024
1 parent 88e8901 commit 96c0951
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,73 @@
# Yadic
# Yet another dependency injection container for PHP

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

Yet another dependency injection container for PHP
This is a simple to use, yet powerful service container that provides a seamless way to automate dependency injection
with auto-wiring.

```bash
composer require webdevcave/yadic
```

Alternatively, you can clone the repository or download the source files directly and include them in your project.

```php
<?php

require_once __DIR__.'/vendor/autoload.php';

use Webdevcave\Yadic\Annotations\Provides;
use Webdevcave\Yadic\Annotations\Singleton;
use Webdevcave\Yadic\ServiceContainer;

interface StorageInterface
{
public function store(mixed $data): bool;
}

#[Provides(StorageInterface::class)]
#[Singleton]
class Storage implements StorageInterface
{
public function store(mixed $data): bool
{
//store data...

return true;
}
}

class MyController
{
public function __construct(
private StorageInterface $storage
) {
}

public function save(): bool
{
return $this->storage->store('my data...');
}
}

$container = new ServiceContainer();

//No need to do this in a real world application:
$container->addAlias(StorageInterface::class, Storage::class);

//Use this instead:
//$container->loadDefinitionsFromDirectory($directory, $namespace); //Loads annotations from classes declared in a PSR4 directory

var_dump($container->get(MyController::class)->save()); //bool(true)
```

## Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements,
please open an issue or a pull request on GitHub.

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 comments on commit 96c0951

Please sign in to comment.