Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/kikimarik/strict-di-container
- Owner: kikimarik
- Created: 2022-09-14T15:03:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T14:52:34.000Z (over 2 years ago)
- Last Synced: 2024-11-20T14:49:53.627Z (about 2 months ago)
- Topics: dependency-injection, php8, psr-11
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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`