CartServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php namespace Darryldecode\Cart;
2
3
use Illuminate\Support\ServiceProvider;
4
5
class CartServiceProvider extends ServiceProvider {
6
7
	/**
8
	 * Indicates if loading of the provider is deferred.
9
	 *
10
	 * @var bool
11
	 */
12
	protected $defer = false;
13
14
	/**
15
	 * Boot the service provider.
16
	 */
17
	public function boot()
18
	{
19
		if (function_exists('config_path')) {
20
			$this->publishes([
21
				__DIR__.'/config/config.php' => config_path('shopping_cart.php'),
22
			], 'config');
23
		}
24
	}
25
26
	/**
27
	 * Register the service provider.
28
	 *
29
	 * @return void
30
	 */
31
	public function register()
32
	{
33
		$this->mergeConfigFrom(__DIR__.'/config/config.php', 'shopping_cart');
34
35
		$this->app->singleton('cart', function($app)
36
		{
37
            $storageClass = config('shopping_cart.storage');
38
            $eventsClass = config('shopping_cart.events');
39
40
            $storage = $storageClass ? new $storageClass() : $app['session'];
41
            $events = $eventsClass ? new $eventsClass() : $app['events'];
42
			$instanceName = 'cart';
43
44
            // default session or cart identifier. This will be overridden when calling Cart::session($sessionKey)->add() etc..
45
            // like when adding a cart for a specific user name. Session Key can be string or maybe a unique identifier to bind a cart
46
            // to a specific user, this can also be a user ID
47
			$session_key = '4yTlTDKu3oJOfzD';
48
49
			return new Cart(
50
				$storage,
51
				$events,
52
				$instanceName,
53
				$session_key,
54
				config('shopping_cart')
55
			);
56
		});
57
	}
58
59
	/**
60
	 * Get the services provided by the provider.
61
	 *
62
	 * @return array
63
	 */
64
	public function provides()
65
	{
66
		return array();
67
	}
68
}
69