Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Created January 10, 2020 23:56
Show Gist options
  • Save DarkGhostHunter/3d6ac23429ebe3e64fdffe9ab6f43162 to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/3d6ac23429ebe3e64fdffe9ab6f43162 to your computer and use it in GitHub Desktop.
Registration of a Single Manager using a Service Provider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Managers\Transport\TransportManager;
use App\Managers\Transport\TransportContract;
class TransportServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// This will bind a single instance of our Manager to the Service Container
$this->app->singleton('transport', function ($app) {
return new TransportManager($app);
});
// This singleton allows to retrieve the driver set has default from the manager
$this->app->singleton('transport.driver', function ($app) {
return $app['transport']->driver();
});
// This allows us to get the driver set as default with pointing the Transport Contract
$this->app->alias('transport.driver', TransportContract::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment