Skip to content

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

License

Notifications You must be signed in to change notification settings

madewithlove/service-providers

Repository files navigation

Madewithlove Service Providers

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages