Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jd297/psr-container
Simple implementation of PSR-11 (Container Interface)
https://github.com/jd297/psr-container
container dependency-injection di psr-11
Last synced: 15 days ago
JSON representation
Simple implementation of PSR-11 (Container Interface)
- Host: GitHub
- URL: https://github.com/jd297/psr-container
- Owner: JD297
- License: bsd-2-clause
- Created: 2024-02-06T01:49:01.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-02-06T01:51:36.000Z (11 months ago)
- Last Synced: 2024-04-06T05:42:05.745Z (9 months ago)
- Topics: container, dependency-injection, di, psr-11
- Language: PHP
- Homepage: https://packagist.org/packages/jd297/psr-container
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# psr-container (PSR-11)
Simple implementation of [PSR-11 (Container Interface)](https://www.php-fig.org/psr/psr-11/).
## Requirements
The following versions of PHP are supported by this version.
* PHP ^8.1
## Usage
```php
use Acme\Service\ExampleService;
use Jd297\Psr\Clock\SystemClock;
use Jd297\Psr\Container\Container;
use Jd297\Psr\Logger\Handler\FileHandler;
use Jd297\Psr\Logger\Logger;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;$container = new Container();
$container->add('projectDir', fn () => __DIR__.'/..');
$container->add(ClockInterface::class, fn () => new SystemClock());
$container->add(LoggerInterface::class, function (Container $container) {
return new Logger(
$container->get(ClockInterface::class),
[
new FileHandler(sprintf('%s/var/log/dev.log', $container->get('projectDir')))
]
);
});/** @var ExampleService $exampleService */
$exampleService = $container->add(ExampleService::class)->get(ExampleService::class);
$exampleService->setLogger($container->get(LoggerInterface::class)); // using the LoggerAwareTrait$exampleService->execute();
```## Composer
### Scripts
Reformat code with [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer).
``` bash
$ composer reformat
```Test source code with [PHPUnit](https://github.com/sebastianbergmann/phpunit).
``` bash
$ composer unit
```Analyse files with [PHPStan](https://github.com/phpstan/phpstan) (Level 9).
``` bash
$ composer analyse
```## License
The BSD 2-Clause "Simplified" License (BSD-2-Clause). Please see [License File](https://github.com/jd297/psr-container/blob/master/LICENSE) for more information.