madewithlove / definitions
A repository of universal service providers for service-providers compliant containers
Requires
- php: >=5.6.0
- container-interop/service-provider: dev-master
Requires (Dev)
- illuminate/database: ^5.4
- illuminate/filesystem: ^5.4
- league/container: ^2.4
- league/event: ^2.1
- league/factory-muffin: ^2.1
- league/flysystem: ^1.0
- league/route: ^2.0
- league/tactician: ^1.0
- madewithlove/php-cs-fixer-config: ^1.2
- maximebf/debugbar: ^1.13
- mockery/mockery: ^0.9.9
- monolog/monolog: ^1.22
- phpunit/phpunit: ^6.0
- relay/relay: ^1.1
- symfony/console: ^3.2
- twig/twig: ^2.2
- zendframework/zend-diactoros: ^1.3
This package is not auto-updated.
Last update: 2024-11-09 19:40:34 UTC
README
A repository of universal service providers for [service-providers] compliant containers
Install
Via Composer
$ composer require madewithlove/service-providers
This repository does not ship with any third party package, you will need to install them yourself. If per example you need the FlysystemServiceProvider
you would install Flysystem alongside this package.
Usage
Service providers
If the container you're using is already compatible with service-provider then register it like you simply would normally.
Otherwise you can use a decorator or bridge, you can find some on Packagist, and this package ships with some as well, per example for league/container:
use League\Flysystem\FilesystemInterface; use League\League\Container; use Madewithlove\ServiceProviders\Bridges\LeagueContainerDecorator; use Madewithlove\ServiceProviders\Filesystem\FlysystemServiceProvider; $container = new LeagueContainerDecorator(new Container()); $container->addServiceProvider(new FlysystemServiceProvider(...))); $filesystem = $container->get(FilesystemInterface::class);
For providers with configuration, you can pass it as constructor argument. See the provider's signature for what options they take:
$provider = new EloquentServiceProvider([ 'local' => [ 'driver' => 'sqlite', 'etc' => 'etc, ], 'production' => [ 'driver' => 'mysql', 'etc' => 'etc, ], ]);
Utilities
This package also ships with some utilities to write your own service providers:
Alias: An alias to an existing value in the container:
public function getServices() { return ['my_alias' => new Alias('to_something_else')]; }
Parameter: A plain value to store in the container:
public function getServices() { return ['views_path' => new Parameter(__DIR__.'/views)]; }
ParametersServiceProvider: A blank service provider to quickly set multiple values in the container:
new ParametersServiceProvider([ 'foo' => 'bar', 'bar' => 'baz', ]); $container->get('foo'); // (string) "bar"
PrefixedProvider: A decorator to prefix a provider's services with a given string:
new PrefixedProvider('config', new ParametersServiceProvider([ 'foo' => 'bar', ])); $container->get('config.foo'); // (string) "bar"
Available service providers
├── Bridges
│ └── LeagueContainerDecorator.php
├── CommandBus
│ └── TacticianServiceProvider.php
├── Console
│ └── SymfonyConsoleServiceProvider.php
├── Database
│ ├── EloquentServiceProvider.php
│ └── FactoryMuffinServiceProvider.php
├── Development
│ ├── DebugbarServiceProvider.php
│ └── MonologServiceProvider.php
├── Events
│ └── LeagueEventsServiceProvider.php
├── Filesystem
│ └── FlysystemServiceProvider.php
├── Http
│ ├── LeagueRouteServiceProvider.php
│ ├── RelayServiceProvider.php
│ └── ZendDiactorosServiceProvider.php
├── Templating
│ └── TwigServiceProvider.php
└── Utilities
├── Alias.php
├── Parameter.php
├── ParametersServiceProvider.php
└── PrefixedProvider.php
See the constructor arguments of each for the options they take. Contributions welcome!
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email heroes@madewithlove.be instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.