https://github.com/seeren/container
🛍️ Autowire and configure dependencies
https://github.com/seeren/container
autowiring psr-11 service
Last synced: about 2 months ago
JSON representation
🛍️ Autowire and configure dependencies
- Host: GitHub
- URL: https://github.com/seeren/container
- Owner: seeren
- License: mit
- Created: 2016-10-17T19:40:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T14:22:18.000Z (almost 3 years ago)
- Last Synced: 2025-02-11T23:53:51.713Z (2 months ago)
- Topics: autowiring, psr-11, service
- Language: PHP
- Homepage:
- Size: 139 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Seeren\\Container
[](https://app.travis-ci.com/seeren/container)
[](https://packagist.org/packages/seeren/container)
[](https://coveralls.io/github/seeren/container?branch=master)
[](https://packagist.org/packages/seeren/container/stats)
[](https://www.codacy.com/gh/seeren/container/dashboard?utm_source=github.com&utm_medium=referral&utm_content=seeren/container&utm_campaign=Badge_Grade)
[](https://packagist.org/packages/seeren/container)Autowire and configure dependencies
* * *
## Installation
Seeren\\Container is a [PSR-11 container interfaces](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) implementation
```bash
composer require seeren/container
```
* * *## Seeren\\Container\\Container
The container create, build, store and share instances
```php
use Seeren\Container\Container;$container = new Container();
$foo = $container->get('Dummy\Foo');
```### Autowiring
Dependencies are resolved using type declaration
```php
namespace Dummy;class Foo
{
public function __construct(Bar $bar){}
}class Bar
{
public function __construct(Baz $baz){}
}class Baz {}
```### Interfaces
```php
namespace Dummy;class Foo {
public function __construct(BarInterface $bar){}
}
```Interfaces are resolved using configuration file by default in `/config/services.json`
```json
{
"parameters": {},
"services": {
"Dummy\\Foo": {
"Dummy\\BarInterface": "Dummy\\Bar"
}
}
}
```Include path can be specified at construction
```bash
project/
└─ config/
└─ services.json
```### Parameters
Parameters and primitives are resolved using configuration file
```php
namespace Dummy;class Foo
{
public function __construct(string $bar){}
}
``````json
{
"parameters": {
"message": "Hello"
},
"services": {
"Dummy\\Foo": {
"bar": ":message"
}
}
}
```### Methods
Methods can use autowiring
```php
namespace Dummy;class Foo
{public function __construct(BarInterface $bar){}
public function action(int $id, Baz $baz)
{
return 'Hello';
}}
``````php
use Seeren\Container\Container;$container = new Container();
$message = $container->call('Dummy\Foo', 'action', [7]);
echo $message; // Hello
```* * *
## License
This project is licensed under the [MIT](./LICENSE) License