1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lenius\LaravelEcommerce; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Route; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Lenius\LaravelEcommerce\Identifier\LaravelCookie; |
8
|
|
|
use Lenius\LaravelEcommerce\Storage\LaravelSession; |
9
|
|
|
|
10
|
|
|
class EcommerceServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Bootstrap the application services. |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
4 |
|
public function boot(): void |
18
|
|
|
{ |
19
|
4 |
|
if ($this->app->runningInConsole()) { |
20
|
4 |
|
$this->publishes([ |
21
|
4 |
|
__DIR__.'/../config/ecommerce.php' => config_path('ecommerce.php'), |
22
|
4 |
|
], 'config'); |
23
|
|
|
|
24
|
4 |
|
$this->publishes([ |
25
|
4 |
|
__DIR__.'/../resources/views' => resource_path('views/vendor/ecommerce'), |
26
|
4 |
|
], 'views'); |
27
|
|
|
|
28
|
4 |
|
$this->publishes([ |
29
|
4 |
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/ecommerce'), |
30
|
4 |
|
], 'lang'); |
31
|
|
|
}; |
32
|
|
|
|
33
|
4 |
|
$this->loadMigrationsFrom(__DIR__.'/../databases/migrations'); |
34
|
4 |
|
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'ecommerce'); |
35
|
4 |
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'ecommerce'); |
36
|
|
|
|
37
|
4 |
|
if ($this->mustLoadRoute()) { |
38
|
4 |
|
Route::group($this->routeConfiguration(), function () { |
39
|
4 |
|
$this->loadRoutesFrom(__DIR__.'/routes.php'); |
40
|
4 |
|
}); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
4 |
|
protected function mustLoadRoute(): bool |
45
|
|
|
{ |
46
|
4 |
|
return ! config('ecommerce.disable_default_route', false); |
47
|
|
|
} |
48
|
|
|
|
49
|
4 |
|
protected function routeConfiguration(): array |
50
|
|
|
{ |
51
|
4 |
|
return [ |
52
|
4 |
|
'prefix' => config('ecommerce.prefix', 'ecommerce'), |
53
|
4 |
|
'middleware' => config('ecommerce.middleware', 'web'), |
54
|
4 |
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Register the application services. |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
4 |
|
public function register(): void |
63
|
|
|
{ |
64
|
4 |
|
$this->app->singleton('cart', function () { |
65
|
4 |
|
return new Cart(new LaravelSession(), new LaravelCookie(), resolve('events')); |
66
|
4 |
|
}); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|