Created
January 10, 2020 23:56
-
-
Save DarkGhostHunter/3d6ac23429ebe3e64fdffe9ab6f43162 to your computer and use it in GitHub Desktop.
Registration of a Single Manager using a Service Provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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