1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Scool\Inventory\Providers; |
4
|
|
|
|
5
|
|
|
use Acacha\Names\Providers\NamesServiceProvider; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Acacha\Stateful\Providers\StatatefulServiceProvider; |
8
|
|
|
use Scool\Inventory\ScoolInventory; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class InventoryServiceProvider. |
12
|
|
|
*/ |
13
|
|
|
class InventoryServiceProvider extends ServiceProvider |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Register package services. |
17
|
|
|
*/ |
18
|
|
|
public function register() |
19
|
|
|
{ |
20
|
|
|
if (!defined('SCOOL_INVENTORY_PATH')) { |
21
|
|
|
define('SCOOL_INVENTORY_PATH', realpath(__DIR__.'/../../')); |
22
|
|
|
} |
23
|
|
|
$this->app->register(NamesServiceProvider::class); |
24
|
|
|
$this->app->bind(\Scool\Inventory\Repositories\StudyRepository::class, \Scool\Inventory\Repositories\StudyRepositoryEloquent::class); |
25
|
|
|
$this->app->bind(StatsRepositoryInterface::class,function() { |
26
|
|
|
return new CacheableStatsRepository(new StatsRepository()); |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
/** |
30
|
|
|
* Bootstrap package services. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function boot() |
35
|
|
|
{ |
36
|
|
|
$this->defineRoutes(); |
37
|
|
|
$this->loadMigrations(); |
38
|
|
|
$this->publishFactories(); |
39
|
|
|
$this->publishConfig(); |
40
|
|
|
$this->publishTests(); |
41
|
|
|
} |
42
|
|
|
/** |
43
|
|
|
* Load migrations. |
44
|
|
|
*/ |
45
|
|
|
private function loadMigrations() |
46
|
|
|
{ |
47
|
|
|
$this->loadMigrationsFrom(SCOOL_INVENTORY_PATH.'/database/migrations'); |
48
|
|
|
} |
49
|
|
|
/** |
50
|
|
|
* Publish factories. |
51
|
|
|
*/ |
52
|
|
|
private function publishFactories() |
53
|
|
|
{ |
54
|
|
|
$this->publishes( |
55
|
|
|
ScoolInventory::factories(), 'scool_inventory' |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* Publish config. |
60
|
|
|
*/ |
61
|
|
|
private function publishConfig() |
62
|
|
|
{ |
63
|
|
|
$this->publishes( |
64
|
|
|
ScoolInventory::configs(), 'scool_inventory' |
65
|
|
|
); |
66
|
|
|
$this->mergeConfigFrom( |
67
|
|
|
SCOOL_INVENTORY_PATH.'/config/inventory.php', 'scool_inventory' |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
private function publishTests() |
71
|
|
|
{ |
72
|
|
|
$this->publishes( |
73
|
|
|
[SCOOL_INVENTORY_PATH.'/tests/InventoryTest.php' => 'tests/InventoryTest.php'], |
74
|
|
|
<<<<<<< HEAD |
|
|
|
|
75
|
|
|
'scool_inventory' |
76
|
|
|
======= |
77
|
|
|
'scool_curriculum' |
78
|
|
|
>>>>>>> 80af1b0c8bb867379f66912ed39f99dd26f04530 |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
protected function defineRoutes() |
83
|
|
|
{ |
84
|
|
|
if (!$this->app->routesAreCached()) { |
85
|
|
|
$router = app('router'); |
86
|
|
|
$router->group(['namespace' => 'Scool\Inventory\Http\Controllers'], function () { |
87
|
|
|
require __DIR__.'/../Http/routes.php'; |
88
|
|
|
}); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function registerStatefulEloquentServiceProvider () |
93
|
|
|
{ |
94
|
|
|
$this->app->register(StatefulServiceProvider::class); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.