Completed
Push — master ( 15a5bf...eb9630 )
by Joao
08:35
created

baseServiceProvider::prepareResources()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 8.8571
cc 2
eloc 18
nc 2
nop 0
1
<?php namespace jlourenco\base;
2
3
use Illuminate\Support\ServiceProvider;
4
use jlourenco\base\Repositories\SettingsRepository;
5
use jlourenco\base\Repositories\UserRepository;
6
use jlourenco\base\Repositories\LogRepository;
7
use jlourenco\base\Repositories\VisitsRepository;
8
use jlourenco\base\Repositories\JobsRepository;
9
10
class baseServiceProvider extends ServiceProvider
11
{
12
13
    /**
14
     * Perform post-registration booting of services.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
21
    }
22
23
    /**
24
     * Register any package services.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $this->prepareResources();
31
        $this->registerGroups();
32
        $this->registerUsers();
33
        $this->registerSettings();
34
        $this->registerLog();
35
        $this->registerVisits();
36
        $this->registerJobs();
37
        $this->registerBase();
38
    }
39
40
    /**
41
     * Prepare the package resources.
42
     *
43
     * @return void
44
     */
45
    protected function prepareResources()
46
    {
47
        // Publish our views
48
        $this->loadViewsFrom(base_path("resources/views"), 'base');
49
        $this->publishes([
50
            __DIR__ .  '/views' => base_path("resources/views")
51
        ]);
52
53
        // Publish our lang
54
        $this->publishes([
55
            __DIR__ .  '/lang' => base_path("resources/lang")
56
        ], 'migrations');
57
58
        // Publish our migrations
59
        $this->publishes([
60
            __DIR__ .  '/migrations' => base_path("database/migrations")
61
        ], 'migrations');
62
63
        // Publish a config file
64
        $this->publishes([
65
            __DIR__ . '/config' => base_path('/config')
66
        ], 'config');
67
68
        // Publish our routes
69
        $this->publishes([
70
            __DIR__ .  '/routes.php' => base_path("app/Http/base_routes.php")
71
        ], 'routes');
72
73
        // Include the routes file
74
        if(file_exists(base_path("app/Http/base_routes.php")))
75
            include base_path("app/Http/base_routes.php");
76
    }
77
78
    /**
79
     * Registers the users.
80
     *
81
     * @return void
82
     */
83
    protected function registerUsers()
84
    {
85
        $this->app->singleton('jlourenco.user', function ($app) {
86
            $config = $app['config']->get('jlourenco.base');
87
88
            $users = array_get($config, 'models.User');
89
            $model = array_get($config, 'models.Group');
90
91
            if (class_exists($model) && method_exists($model, 'setUsersModel'))
92
                forward_static_call_array([$model, 'setUsersModel'], [$users]);
93
94
            return new UserRepository($users);
95
        });
96
    }
97
98
    /**
99
     * Registers the groups.
100
     *
101
     * @return void
102
     */
103
    protected function registerGroups()
104
    {
105
        $this->app->singleton('jlourenco.group', function ($app) {
106
            $config = $app['config']->get('jlourenco.base');
107
108
            $model = array_get($config, 'base.models.Group');
109
110
            return new IlluminateRoleRepository($model);
111
        });
112
    }
113
114
    /**
115
     * Registers the settings.
116
     *
117
     * @return void
118
     */
119
    protected function registerSettings()
120
    {
121
        $this->app->singleton('jlourenco.settings', function ($app) {
122
            $config = $app['config']->get('jlourenco.base');
123
124
            $model = array_get($config, 'models.Settings');
125
126
            return new SettingsRepository($model);
127
        });
128
    }
129
130
    /**
131
     * Registers the logger.
132
     *
133
     * @return void
134
     */
135
    protected function registerLog()
136
    {
137
        $this->app->singleton('jlourenco.log', function ($app) {
138
            $config = $app['config']->get('jlourenco.base');
139
140
            $model = array_get($config, 'models.Logs');
141
142
            return new LogRepository($model);
143
        });
144
    }
145
146
    /**
147
     * Registers the visits.
148
     *
149
     * @return void
150
     */
151
    protected function registerVisits()
152
    {
153
        $this->app->singleton('jlourenco.visits', function ($app) {
154
            $config = $app['config']->get('jlourenco.base');
155
156
            $model = array_get($config, 'models.Visits');
157
158
            return new VisitsRepository($model);
159
        });
160
    }
161
162
    /**
163
     * Registers the visits.
164
     *
165
     * @return void
166
     */
167
    protected function registerJobs()
168
    {
169
        $this->app->singleton('jlourenco.jobs', function ($app) {
170
            $config = $app['config']->get('jlourenco.base');
171
172
            $model = array_get($config, 'models.Jobs');
173
174
            return new JobsRepository($model);
175
        });
176
    }
177
178
    /**
179
     * Registers base.
180
     *
181
     * @return void
182
     */
183
    protected function registerBase()
184
    {
185
        $this->app->singleton('base', function ($app) {
186
            $base = new Base($app['jlourenco.settings'], $app['jlourenco.user'], $app['jlourenco.log'], $app['jlourenco.visits'], $app['jlourenco.jobs']);
187
188
            return $base;
189
        });
190
191
        $this->app->alias('base', 'jlourenco\base\Base');
192
    }
193
194
    /**
195
     * {@inheritDoc}
196
     */
197
    public function provides()
198
    {
199
        return [
200
            'jlourenco.user',
201
            'jlourenco.group',
202
            'jlourenco.settings',
203
            'jlourenco.log',
204
            'jlourenco.visits',
205
            'jlourenco.jobs',
206
            'base'
207
        ];
208
    }
209
210
}