https://github.com/thecodingmachine/yaco-service-provider
This package is a bridge between container-intop's service providers and YACO (the PSR-11 compliant container compiler).
https://github.com/thecodingmachine/yaco-service-provider
Last synced: 11 months ago
JSON representation
This package is a bridge between container-intop's service providers and YACO (the PSR-11 compliant container compiler).
- Host: GitHub
- URL: https://github.com/thecodingmachine/yaco-service-provider
- Owner: thecodingmachine
- Created: 2016-02-29T19:14:46.000Z (over 10 years ago)
- Default Branch: 1.0
- Last Pushed: 2016-04-11T16:26:46.000Z (about 10 years ago)
- Last Synced: 2025-07-10T11:11:33.361Z (12 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://scrutinizer-ci.com/g/thecodingmachine/yaco-service-provider/?branch=1.0)
[](https://travis-ci.org/thecodingmachine/yaco-service-provider)
[](https://coveralls.io/github/thecodingmachine/yaco-service-provider?branch=1.0)
# Bridge between container-interop's service providers and YACO
This package is a bridge between [container-interop's service providers](http://github.com/container-interop/service-provider) and [YACO, the PSR-11 compliant container compiler](http://github.com/thecodingmachine/yaco).
Using this package, you can use Yaco to generate PSR-11 compliant containers that contain the services provided by container-interop's service providers.
## Installation
```sh
composer require thecodingmachine/yaco-service-provider
```
## Loading a service provider into Yaco
```php
use TheCodingMachine\Yaco\Compiler;
use TheCodingMachine\Yaco\ServiceProvider\ServiceProviderLoader;
// Create your YACO compiler.
$compiler = new Compiler();
// Create your service provider loader
$serviceProviderLoader = new ServiceProviderLoader($compiler);
// Load service providers into Yaco:
$serviceProviderLoader->load(MyServiceProvider::class);
$serviceProviderLoader->load(MyOtherServiceProvider::class);
// Services are now available in Yaco, we just need to dump the container:
$code = $compiler->compile('MyContainer');
file_put_contents(__DIR__.'/MyContainer.php', $code);
```
## Autodiscovering service providers using Puli
If the service providers you are loading are publishing themselves on Puli, you can easily use Puli's discovery mechanism to load the services:
```php
// The discoverAndLoad function takes a Puli discovery instance in parameter.
// It will discover and load service providers automatically.
$serviceProviderLoader->discoverAndLoad($discovery)
```