InventoryServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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