feat: update CartServiceProvider to use CartManager

This commit is contained in:
Joel Male
2026-05-27 21:08:10 +10:00
parent e0103aadaa
commit 9abf6a7a1b
+9 -32
View File
@@ -1,22 +1,16 @@
<?php
declare(strict_types=1);
namespace Wearepixel\Cart;
use Illuminate\Support\ServiceProvider;
class CartServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the service provider.
*/
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
@@ -25,39 +19,22 @@ public function boot()
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cart');
$this->app->singleton('cart.manager', fn($app) => new CartManager($app));
$this->app->singleton('cart', function ($app) {
$config = config('cart');
$events = $app['events'];
$driver = $app['cart.manager']->driver();
$storage = $config['driver'] === 'database'
? new $config['storage']['database']['model']
: $app['session'];
return new Cart(
$storage,
$events,
'cart',
session()->getId(),
$config
);
return new Cart($driver, $events, 'cart', $config);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
public function provides(): array
{
return [];
}