Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/kikimarik/strict-di-container

Composer PSR-11 package for Dependency Injection Container
https://github.com/kikimarik/strict-di-container

dependency-injection php8 psr-11

Last synced: about 1 month ago
JSON representation

Composer PSR-11 package for Dependency Injection Container

Awesome Lists containing this project

README

        

# Strict DI container is a PSR-11 php library
## Features
***
- Object-oriented design (without static methods etc.)
- Compatible with PHP 7.4 and later, including PHP 8.1
- Compatible with PSR-11

## Why do you need it
***
The library helps you project to inject it dependencies.
It has a nice object-oriented design, and it is going to please you with its simplicity. Before testing a class that depends on that library component, it is easy to replace that dependency with a fake class.

## A Simple Example
***

```php
put(new HashClassIdentity(Foo::class, "md5"), new Foo("foo"));
$classMap->put(new HashClassIdentity(Bar::class, "md5"), new Bar("bar"));
$container = new StrictContainer(
$classMap,
new DefaultClassIdentityFactory(
HashClassIdentity::class,
[
"algo" => "md5"
]
)
);
if ($container->has(Foo::class)) {
print_r($container->get(Foo::class)); // got object from container
}
if (!$container->has(FooBar::class)) {
print_r("Container does not contain class " . FooBar::class);
}

```

## License
***
This software is distributed under the MIT license.

## Installation
***
- via composer `composer require kikimarik/strict-di-container`

## Tests
***
[Lognote tests](https://github.com/kikimarik/lognote/tree/master/tests) use the [Codeception 4.2.0](https://github.com/Codeception/Codeception/tree/4.2.0) framework.
All unit tests must be passed.

For tests running you can run the command:
`./vendor/bin/codecept run`