Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teodoroleckie/di
⚡ Simple and fast PSR-11 dependency injection container
https://github.com/teodoroleckie/di
container dependency dependency-container dependency-injection di php php8 psr-11
Last synced: about 1 month ago
JSON representation
⚡ Simple and fast PSR-11 dependency injection container
- Host: GitHub
- URL: https://github.com/teodoroleckie/di
- Owner: teodoroleckie
- License: mit
- Created: 2021-04-14T18:06:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-11T07:20:43.000Z (over 3 years ago)
- Last Synced: 2024-12-10T07:55:53.170Z (2 months ago)
- Topics: container, dependency, dependency-container, dependency-injection, di, php, php8, psr-11
- Language: PHP
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
### Di:
[![Latest Version on Packagist](https://img.shields.io/packagist/v/tleckie/di.svg?style=flat-square)](https://packagist.org/packages/tleckie/di)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/di/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/teodoroleckie/di/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/di/badges/build.png?b=master)](https://scrutinizer-ci.com/g/teodoroleckie/di/build-status/master)
[![Total Downloads](https://img.shields.io/packagist/dt/tleckie/di.svg?style=flat-square)](https://packagist.org/packages/tleckie/di)You can install the package via composer:
```bash
composer require tleckie/di
``````php
setAdapter(new FileAdapter('conf/definition.php', $container));$container->get('stringValue');
$container->get('numericValue');
$container->get('chainValue');
$container->get('closureValue');
$container->get('closureValue'); // same instance
$container->get('closureValue'); // same instance
$container->get('closureValue'); // same instance
$container->get('arrayValue');
$container->get('lazyFactoryWithConstructArgumentsAnReturnSameInstance');
$container->get('lazyFactoryWithConstructArgumentsAndCallMethodWithArgumentsAndCreateANewInstance');```
### Definition:
conf/definition.php
```php
'Lorem ipsum dolor sit amet',
'numericValue' => 55,
'chainValue' => 'stringValue',
'closureValue' => static function () {
// each call returns the same instance
return new Project\B('String Argument');
},
'arrayValue' => [
[
[
'host' => 'localhost',
'port' => 443,
'user' => 'userValue',
'pass' => 'password',
]
]
],
// lazy loading and singleton instance
'lazyFactoryWithConstructArgumentsAnReturnSameInstance' => [
'className' => Project\A::class,
'arguments' => ['stringValue', 'closureValue'],
'newInstance' => false // each call returns the same instance
],
'lazyFactoryWithConstructArgumentsAndCallMethodWithArgumentsAndCreateANewInstance' => [
'className' => Project\A::class,
'arguments' => ['stringValue', 'closureValue'],
'newInstance' => true, // each call returns a new instance
'methods' => [
[
'methodName' => 'setValue',
'arguments' => ['changed value ']
],
[
'methodName' => 'setOtherValue',
'arguments' => ['changed other value ']
]
]
]
];
```