mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Pixeldigital\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()
|
|
{
|
|
if ($this->app->runningInConsole()) {
|
|
$this->publishes([
|
|
__DIR__ . '/../config/config.php' => config_path('cart.php'),
|
|
], 'config');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cart');
|
|
|
|
$this->app->singleton('cart', function ($app) {
|
|
$storageClass = config('cart.storage');
|
|
$eventsClass = config('cart.events');
|
|
|
|
$storage = $storageClass ? new $storageClass : $app['session'];
|
|
$events = $eventsClass ? new $eventsClass : $app['events'];
|
|
$instanceName = 'cart';
|
|
|
|
// default session or cart identifier. This will be overridden when calling Cart::session($sessionKey)->add() etc..
|
|
// like when adding a cart for a specific user name. Session Key can be string or maybe a unique identifier to bind a cart
|
|
// to a specific user, this can also be a user ID
|
|
$session_key = '4yTlTDKu3oJOfzD';
|
|
|
|
return new Cart(
|
|
$storage,
|
|
$events,
|
|
$instanceName,
|
|
$session_key,
|
|
config('cart')
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the services provided by the provider.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function provides()
|
|
{
|
|
return [];
|
|
}
|
|
}
|