1
|
|
|
<?php |
2
|
|
|
namespace Scool\Inventory\Providers; |
3
|
|
|
use Acacha\Names\Providers\NamesServiceProvider; |
4
|
|
|
use Acacha\Stateful\Providers\StatefulServiceProvider; |
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Scool\Inventory\ScoolInventory; |
7
|
|
|
use Scool\Inventory\Stats\CacheableStatsRepository; |
8
|
|
|
use Scool\Inventory\Stats\Contracts\StatsRepository as StatsRepositoryInterface; |
9
|
|
|
use Scool\Inventory\Stats\StatsRepository; |
10
|
|
|
/** |
11
|
|
|
* Class InventoryServiceProvider. |
12
|
|
|
* |
13
|
|
|
* @package Scool\Inventory\Providers |
14
|
|
|
*/ |
15
|
|
|
class InventoryServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Register package services. |
19
|
|
|
*/ |
20
|
|
|
public function register() |
21
|
|
|
{ |
22
|
|
|
if (!defined('SCOOL_INVENTORY_PATH')) { |
23
|
|
|
define('SCOOL_INVENTORY_PATH', realpath(__DIR__.'/../../')); |
24
|
|
|
} |
25
|
|
|
$this->registerNamesServiceProvider(); |
26
|
|
|
$this->registerStatefulEloquentServiceProvider(); |
27
|
|
|
$this->bindRepositories(); |
28
|
|
|
$this->app->bind(StatsRepositoryInterface::class,function() { |
29
|
|
|
return new CacheableStatsRepository(new StatsRepository()); |
30
|
|
|
}); |
31
|
|
|
} |
32
|
|
|
/** |
33
|
|
|
* Bind repositories |
34
|
|
|
*/ |
35
|
|
|
protected function bindRepositories() |
36
|
|
|
{ |
37
|
|
|
$this->app->bind( |
38
|
|
|
\Scool\Inventory\Repositories\StudyRepository::class, |
39
|
|
|
\Scool\Inventory\Repositories\StudyRepositoryEloquent::class); |
40
|
|
|
$this->app->bind(\Scool\Inventory\Repositories\TodoRepository::class, \Scool\Inventory\Repositories\TodoRepositoryEloquent::class); |
41
|
|
|
$this->app->bind(\Scool\Inventory\Repositories\ShitRepository::class, \Scool\Inventory\Repositories\ShitRepositoryEloquent::class); |
42
|
|
|
//:end-bindings: |
43
|
|
|
} |
44
|
|
|
/** |
45
|
|
|
* Register acacha/stateful-eloquent Service Provider. |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
protected function registerStatefulEloquentServiceProvider() |
49
|
|
|
{ |
50
|
|
|
$this->app->register(StatefulServiceProvider::class); |
51
|
|
|
} |
52
|
|
|
/** |
53
|
|
|
* Register acacha/names Service Provider. |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
protected function registerNamesServiceProvider() |
57
|
|
|
{ |
58
|
|
|
$this->app->register(NamesServiceProvider::class); |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* Bootstrap package services. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function boot() |
66
|
|
|
{ |
67
|
|
|
$this->defineRoutes(); |
68
|
|
|
$this->loadMigrations(); |
69
|
|
|
$this->loadViews(); |
70
|
|
|
$this->publishFactories(); |
71
|
|
|
$this->publishConfig(); |
72
|
|
|
$this->publishTests(); |
73
|
|
|
} |
74
|
|
|
/** |
75
|
|
|
* Define the curriculum routes. |
76
|
|
|
*/ |
77
|
|
|
protected function defineRoutes() |
78
|
|
|
{ |
79
|
|
|
if (!$this->app->routesAreCached()) { |
80
|
|
|
$router = app('router'); |
81
|
|
|
$router->group(['namespace' => 'Scool\Inventory\Http\Controllers'], function () { |
82
|
|
|
require __DIR__.'/../Http/routes.php'; |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
/** |
87
|
|
|
* Load package views. |
88
|
|
|
*/ |
89
|
|
|
private function loadViews() |
90
|
|
|
{ |
91
|
|
|
$this->loadViewsFrom(SCOOL_INVENTORY_PATH . '/resources/views', 'inventory'); |
92
|
|
|
} |
93
|
|
|
/** |
94
|
|
|
* Load migrations. |
95
|
|
|
*/ |
96
|
|
|
private function loadMigrations() |
97
|
|
|
{ |
98
|
|
|
$this->loadMigrationsFrom(SCOOL_INVENTORY_PATH . '/database/migrations'); |
99
|
|
|
} |
100
|
|
|
/** |
101
|
|
|
* Publish factories. |
102
|
|
|
*/ |
103
|
|
|
private function publishFactories() |
104
|
|
|
{ |
105
|
|
|
$this->publishes( |
106
|
|
|
ScoolInventory::factories(),"scool_inventory" |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
/** |
110
|
|
|
* Publish config. |
111
|
|
|
*/ |
112
|
|
|
private function publishConfig() { |
113
|
|
|
$this->publishes( |
114
|
|
|
ScoolInventory::configs(),"scool_inventory" |
115
|
|
|
); |
116
|
|
|
$this->mergeConfigFrom( |
117
|
|
|
SCOOL_INVENTORY_PATH . '/config/inventory.php', 'scool_inventory' |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
/** |
121
|
|
|
* Publich tests. |
122
|
|
|
*/ |
123
|
|
|
private function publishTests() |
124
|
|
|
{ |
125
|
|
|
$this->publishes( |
126
|
|
|
[SCOOL_INVENTORY_PATH .'/tests/InventoryTest.php' => 'tests/InventoryTest.php'] , |
127
|
|
|
'scool_inventory' |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
|
134
|
|
|
|