mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
feat: update CartServiceProvider to use CartManager
This commit is contained in:
@@ -1,22 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Wearepixel\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class CartServiceProvider extends ServiceProvider
|
class CartServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Indicates if loading of the provider is deferred.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $defer = false;
|
protected $defer = false;
|
||||||
|
|
||||||
/**
|
public function boot(): void
|
||||||
* Boot the service provider.
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
{
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
@@ -25,39 +19,22 @@ public function boot()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function register(): void
|
||||||
* Register the service provider.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cart');
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cart');
|
||||||
|
|
||||||
|
$this->app->singleton('cart.manager', fn($app) => new CartManager($app));
|
||||||
|
|
||||||
$this->app->singleton('cart', function ($app) {
|
$this->app->singleton('cart', function ($app) {
|
||||||
$config = config('cart');
|
$config = config('cart');
|
||||||
$events = $app['events'];
|
$events = $app['events'];
|
||||||
|
$driver = $app['cart.manager']->driver();
|
||||||
|
|
||||||
$storage = $config['driver'] === 'database'
|
return new Cart($driver, $events, 'cart', $config);
|
||||||
? new $config['storage']['database']['model']
|
|
||||||
: $app['session'];
|
|
||||||
|
|
||||||
return new Cart(
|
|
||||||
$storage,
|
|
||||||
$events,
|
|
||||||
'cart',
|
|
||||||
session()->getId(),
|
|
||||||
$config
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function provides(): array
|
||||||
* Get the services provided by the provider.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provides()
|
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user