madewithlove/service-providers

A repository of universal service providers for service-providers compliant containers

0.3.2 2017-03-18 11:28 UTC

This package is auto-updated.

Last update: 2024-11-08 01:33:47 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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.