Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/einenlum/dyc

A very simple DIC, supporting autowiring (NOT production ready)
https://github.com/einenlum/dyc

Last synced: 23 days ago
JSON representation

A very simple DIC, supporting autowiring (NOT production ready)

Awesome Lists containing this project

README

        

# Dyc

A very simple DIC, supporting autowiring. For fun only.

## Use

```php
set(\Foo\Bar::class, function(\Dyc\Dic $dic) {
return new \Foo\Bar($dic->get(\Bar\Baz::class));
});

$bar = $dic->get(\Foo\Bar::class);
```

## Autowiring

We recommend using [haydenpierce/class-finder](https://packagist.org/packages/haydenpierce/class-finder), to get a list of all FQCN in your project.

```php
autowire($classes);

$bar = $dic->get(\Foo\Bar::class);
```

If one service requires an interface or a scalar, you will need to rewrite the whole definition for this one:

```php
autowire($classes);
$dic->set(\Some\Scalar\Dependent\Service::class, function(\Dyc\Dic $dic) {
return new \Some\Scalar\Dependent\Service($dic->get(\Foo\Bar::class), 'some api key');
});

$service = $dic->get(\Some\Scalar\Dependent\Service::class);
```