Completed
Push — master ( 53c498...930ea9 )
by Manu
02:45
created

CurriculumServiceProvider::defineRoutes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
crap 6
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\Curriculum\ScoolCurriculum;
7
use Scool\Curriculum\Stats\CacheableStatsRepository;
8
use Scool\Curriculum\Stats\Contracts\StatsRepository as StatsRepositoryInterface;
9
use Scool\Curriculum\Stats\StatsRepository;
10
/**
11
 * Class CurriculumServiceProvider.
12
 *
13
 * @package Scool\Curriculum\Providers
14
 */
15
class CurriculumServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Register package services.
19
     */
20
    public function register()
21
    {
22
        if (!defined('SCOOL_CURRICULUM_PATH')) {
23
            define('SCOOL_CURRICULUM_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\Curriculum\Repositories\StudyRepository::class,
39
            \Scool\Curriculum\Repositories\StudyRepositoryEloquent::class);
40
        $this->app->bind(\Scool\Curriculum\Repositories\TodoRepository::class, \Scool\Curriculum\Repositories\TodoRepositoryEloquent::class);
41
        $this->app->bind(\Scool\Curriculum\Repositories\ShitRepository::class, \Scool\Curriculum\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\Curriculum\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_CURRICULUM_PATH . '/resources/views', 'curriculum');
92
    }
93
    /**
94
     * Load migrations.
95
     */
96
    private function loadMigrations()
97
    {
98
        $this->loadMigrationsFrom(SCOOL_CURRICULUM_PATH . '/database/migrations');
99
    }
100
    /**
101
     * Publish factories.
102
     */
103
    private function publishFactories()
104
    {
105
        $this->publishes(
106
            ScoolCurriculum::factories(),"scool_curriculum"
107
        );
108
    }
109
    /**
110
     * Publish config.
111
     */
112
    private function publishConfig() {
113
        $this->publishes(
114
            ScoolCurriculum::configs(),"scool_curriculum"
115
        );
116
        $this->mergeConfigFrom(
117
            SCOOL_CURRICULUM_PATH . '/config/curriculum.php', 'scool_curriculum'
118
        );
119
    }
120
    /**
121
     * Publich tests.
122
     */
123
    private function publishTests()
124
    {
125
        $this->publishes(
126
            [SCOOL_CURRICULUM_PATH .'/tests/CurriculumTest.php' => 'tests/CurriculumTest.php'] ,
127
            'scool_curriculum'
128
        );
129
    }
130
}
131
132
133
134