2017 © Pedro Peláez
 

helper laravel-binder

A service container contextual binding helper for Laravel 5.

image

enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  • Thursday, September 22, 2016
  • by r3oath
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Binder

Build Status Coverage Status Scrutinizer Code Quality, (*1)

A contextual binding helper for Laravel 5., (*2)

Example

From the service provider.

use Enzyme\LaravelBinder\Binder;

// Inside the app service provider...
public function register()
{
    $binder = new Binder($this->app);

    $binder->setAlias(
        'controller.listing',
        'App\Http\Controllers\ListingController'
    );

    $binder->setAlias(
        'repos.interface',
        'Acme\Repositories\RepositoryInterface'
    );

    // Option 1 for binding, using aliases.
    $binder->setBinding(
        'repos.listing',
        'repos.interface',
        'Acme\Repositories\ListingRepository'
    );

    // Option 2 for binding, using FQNs.
    $binder->setBinding(
        'factories.listing',
        'Acme\Factories\FactoryInterface',
        'Acme\Factories\ListingFactory'
    );

    // Tell the service container that the ListingController
    // needs the ListingRepository & ListingFactory.
    $binder->setNeeds(
        'controller.listing',
        ['repos.listing', 'factories.listing']
    );

    $binder->register();
}

From the controller

// You don't need to inject the specific concrete classes, just the
// interfaces. The Binder + Service Container has taken care of it for you.
public function __construct(RepositoryInterface $repo, FactoryInterface $factory)
{
    $this->repo = $repo;
    $this->factory = $factory;
}

What's the purpose?

With your service provider(s) now being the sole authority for which classes get what implementations, if you ever need to switch those implementations, it's dead simple and in one spot!, (*3)

The Versions

22/09 2016

dev-master

9999999-dev https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual

22/09 2016

dev-bleeding

dev-bleeding https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual

03/04 2016

v1.0.0

1.0.0.0 https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual

25/03 2016

v0.2.1

0.2.1.0 https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual

25/03 2016

v0.2.0

0.2.0.0 https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual

20/01 2016

0.1.0

0.1.0.0 https://github.com/enzyme/laravel-binder

A service container contextual binding helper for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service container php binding enzyme contextual