agoalofalife /
cart
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | |||
| 4 | namespace Cart\ServiceProviders; |
||
| 5 | |||
| 6 | use Cart\Contracts\ServiceProviderContract; |
||
| 7 | use Cart\Drivers\DatabaseDriver; |
||
| 8 | use Illuminate\Database\Capsule\Manager; |
||
| 9 | use Illuminate\Events\Dispatcher; |
||
| 10 | use Illuminate\Container\Container; |
||
| 11 | |||
| 12 | class DatabaseServiceProviders implements ServiceProviderContract |
||
| 13 | { |
||
| 14 | |||
| 15 | 2 | public function register(Container $container) : void |
|
| 16 | { |
||
| 17 | 2 | $capsule = new Manager; |
|
| 18 | 2 | $prefix = 'cart.drivers.database'; |
|
| 19 | |||
| 20 | 2 | $capsule->addConnection([ |
|
| 21 | 2 | 'driver' => config($prefix . '.driver'), |
|
| 22 | 2 | 'host' => config($prefix . '.host'), |
|
| 23 | 2 | 'database' => config($prefix . '.database'), |
|
| 24 | 2 | 'username' => config($prefix . '.username'), |
|
| 25 | 2 | 'password' => config($prefix . '.password'), |
|
| 26 | 2 | 'charset' => config($prefix . '.charset'), |
|
| 27 | 2 | 'collation' => config($prefix . '.collation'), |
|
| 28 | 2 | 'prefix' => config($prefix . '.prefix'), |
|
| 29 | ]); |
||
| 30 | |||
| 31 | 2 | $capsule->setEventDispatcher(new Dispatcher(app())); |
|
| 32 | 2 | $capsule->setAsGlobal(); |
|
| 33 | 2 | $capsule->bootEloquent(); |
|
| 34 | 2 | $container->bind(Manager::class, $capsule); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | |||
| 36 | 2 | $container->bind(DatabaseDriver::class, function () use ($capsule) { |
|
| 37 | 1 | return new DatabaseDriver($capsule); |
|
| 38 | 2 | }); |
|
| 39 | } |
||
| 40 | } |