FinderProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace Finder;
4
5
use App;
6
use Config;
7
use Finder\Facades\Finder as FinderFacade;
8
use Finder\Services\FinderService;
9
use Illuminate\Contracts\Events\Dispatcher;
10
11
use Illuminate\Foundation\AliasLoader;
12
use Illuminate\Routing\Router;
13
use Illuminate\Support\Collection;
14
use Illuminate\Support\Facades\View;
15
use Illuminate\Support\ServiceProvider;
16
17
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;
18
19
use Log;
20
use Muleta\Traits\Providers\ConsoleTools;
21
use Route;
22
23
use MediaManager\Services\FileService;
24
25
class FinderProvider extends ServiceProvider
26
{
27
    use ConsoleTools;
28
29
    public $packageName = 'finder';
30
    const pathVendor = 'sierratecnologia/finder';
31
32
    public static $aliasProviders = [
33
        'Finder' => \Finder\Facades\Finder::class,
34
        'FileService' => FileService::class,
35
    ];
36
37
    public static $providers = [
38
39
        \Stalker\StalkerProvider::class,
40
        \Casa\CasaProvider::class,
41
        \Operador\OperadorProvider::class,
42
        \Integrations\IntegrationsProvider::class,
43
44
        /**
45
         * Externos
46
         */
47
        \SierraTecnologia\Crypto\CryptoProvider::class,
48
49
        
50
    ];
51
52
    /**
53
     * Rotas do Menu
54
     */
55
    public static $menuItens = [
56
        'Operações|150' => [
57
            [
58
                'text' => 'Finder',
59
                'icon' => 'fas fa-fw fa-search',
60
                'icon_color' => "blue",
61
                'label_color' => "success",
62
                'section' => "master",
63
                'feature' => 'finder',
64
                'order' => 1800,
65
                'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
66
                'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
67
            ],
68
            [
69
                'text'        => 'Actions',
70
                'route'       => 'rica.finder.action.actions.index',
71
                'icon'        => 'fas fa-fw fa-coffee',
72
                'icon_color'  => 'red',
73
                'label_color' => 'success',
74
                'section' => "master",
75
                'feature' => 'operador',
76
                'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
77
                // 'nivel' => \Porteiro\Models\Role::$GOOD,
78
            ],
79
            'Finder' => [
80
                [
81
                    'text'        => 'Procurar',
82
                    'icon'        => 'fas fa-fw fa-search',
83
                    'icon_color'  => 'blue',
84
                    'label_color' => 'success',
85
                    'section' => "master",
86
                    'feature' => 'finder',
87
                    'order' => 1800,
88
                    'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
89
                    'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
90
                    // 'access' => \Porteiro\Models\Role::$ADMIN
91
                ],
92
                [
93
                    'text'        => 'Track',
94
                    'icon'        => 'fas fa-fw fa-search',
95
                    'icon_color'  => 'blue',
96
                    'label_color' => 'success',
97
                    'section' => "master",
98
                    'feature' => 'finder',
99
                    'order' => 1800,
100
                    'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
101
                    'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
102
                    // 'access' => \Porteiro\Models\Role::$ADMIN
103
                ],
104
                [
105
                    'text'        => 'Url',
106
                    'route'       => 'master.finder.url.index',
107
                    'icon'        => 'fas fa-fw fa-ship',
108
                    'icon_color'  => 'blue',
109
                    'label_color' => 'success',
110
                    'section'     => "master",
111
                    'feature' => 'finder',
112
                    'order' => 1800,
113
                    'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
114
                    'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
115
                    // 'access' => \Porteiro\Models\Role::$ADMIN
116
                ],
117
                [
118
                    'text'        => 'Computer Files',
119
                    'route'       => 'master.finder.files.index',
120
                    'icon'        => 'fas fa-fw fa-ship',
121
                    'icon_color'  => 'blue',
122
                    'label_color' => 'success',
123
                    'section'   => "master",
124
                    'feature' => 'finder',
125
                    'order' => 1800,
126
                    'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
127
                    'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
128
                    // 'access' => \Porteiro\Models\Role::$ADMIN
129
                ],
130
                'Procurar' => [
131
                    [
132
                        'text'        => 'Finder Home',
133
                        'route'       => 'rica.finder.home',
134
                        'icon'        => 'fas fa-fw fa-ship',
135
                        'icon_color'  => 'blue',
136
                        'label_color' => 'success',
137
                        'section' => "master",
138
                        'feature' => 'finder',
139
                        'order' => 1800,
140
                        'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
141
                        'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
142
                        // 'access' => \Porteiro\Models\Role::$ADMIN
143
                    ],
144
                    [
145
                        'text'        => 'Finder Pessoas',
146
                        'route'       => 'rica.finder.persons',
147
                        'icon'        => 'fas fa-fw fa-group',
148
                        'icon_color'  => 'blue',
149
                        'label_color' => 'success',
150
                        'section' => "master",
151
                        'feature' => 'finder',
152
                        'order' => 1800,
153
                        'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
154
                        'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
155
                        // 'access' => \Porteiro\Models\Role::$ADMIN
156
                    ],
157
                ],
158
                'Track' => [
159
                    [
160
                        'text'        => 'Persons',
161
                        'route'       => 'rica.finder.track.person',
162
                        'icon'        => 'fas fa-fw fa-coffee',
163
                        'icon_color'  => 'red',
164
                        'label_color' => 'success',
165
                        'section' => "master",
166
                        'feature' => 'finder',
167
                        'order' => 1800,
168
                        'dev_status'  => 2, // 0 (Desabilitado), 1 (Ativo), 2 (Em Dev)
169
                        'level'       => 3, // 0 (Public), 1, 2 (Admin) , 3 (Root)
170
                        // 'nivel' => \Porteiro\Models\Role::$GOOD,
171
                    ],
172
                ],
173
            ],
174
        ],
175
    ];
176
177
    /**
178
     * Alias the services in the boot.
179
     */
180
    public function boot()
181
    {
182
        
183
        // Register configs, migrations, etc
184
        $this->registerDirectories();
185
186
        // COloquei no register pq nao tava reconhecendo as rotas para o adminlte
187
        $this->app->booted(
188
            function () {
189
                $this->routes();
190
            }
191
        );
192
193
        $this->loadLogger();
194
    }
195
196
    /**
197
     * Register the tool's routes.
198
     *
199
     * @return void
200
     */
201
    protected function routes()
202
    {
203
        if ($this->app->routesAreCached()) {
204
            return;
205
        }
206
207
        /**
208
         * Finder Routes
209
         */
210
        $this->loadRoutesForRiCa(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'routes');
211
    }
212
213
    /**
214
     * Register the services.
215
     */
216
    public function register()
217
    {
218
        $this->mergeConfigFrom($this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'sitec'.DIRECTORY_SEPARATOR.'finder.php'), 'sitec.finder');
219
        
220
221
        $this->setProviders();
222
        // $this->routes();
223
224
225
226
        // Register Migrations
227
        $this->loadMigrationsFrom(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations');
228
229
        $this->app->singleton(
230
            'finder', function () {
231
                return new FinderFacade();
232
            }
233
        );
234
        
235
        /*
236
        |--------------------------------------------------------------------------
237
        | Register the Utilities
238
        |--------------------------------------------------------------------------
239
        */
240
        /**
241
         * Singleton Finder
242
         */
243
        $this->app->singleton(
244
            FinderService::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
245
                \Log::channel('sitec-finder')->info('Singleton Finder');
246
                return new FinderService(\Illuminate\Support\Facades\Config::get('sitec.finder'));
247
            }
248
        );
249
250
        // Register commands
251
        $this->registerCommandFolders(
252
            [
253
            base_path('vendor/sierratecnologia/finder/src/Console/Commands') => '\Finder\Console\Commands',
254
            ]
255
        );
256
257
        // /**
258
        //  * Helpers
259
        //  */
260
        // Aqui noa funciona
261
        // if (!function_exists('finder_asset')) {
262
        //     function finder_asset($path, $secure = null)
263
        //     {
264
        //         return route('rica.finder.assets').'?path='.urlencode($path);
265
        //     }
266
        // }
267
    }
268
269
    /**
270
     * Get the services provided by the provider.
271
     *
272
     * @return array
273
     */
274
    public function provides()
275
    {
276
        return [
277
            'finder',
278
        ];
279
    }
280
281
    /**
282
     * Register configs, migrations, etc
283
     *
284
     * @return void
285
     */
286
    public function registerDirectories()
287
    {
288
        // Publish config files
289
        $this->publishes(
290
            [
291
            // Paths
292
            $this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'sitec') => config_path('sitec'),
293
            ], ['config',  'sitec', 'sitec-config']
294
        );
295
296
        // // Publish finder css and js to public directory
297
        // $this->publishes([
298
        //     $this->getDistPath('finder') => public_path('assets/finder')
299
        // ], ['public',  'sitec', 'sitec-public']);
300
301
        $this->loadViews();
302
        $this->loadTranslations();
303
    }
304
305
    private function loadViews()
306
    {
307
        // View namespace
308
        $viewsPath = $this->getResourcesPath('views');
309
        $this->loadViewsFrom($viewsPath, 'finder');
310
        $this->publishes(
311
            [
312
            $viewsPath => base_path('resources'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'finder'),
313
            ], ['views',  'sitec', 'sitec-views']
314
        );
315
    }
316
    
317
    private function loadTranslations()
318
    {
319
        // Publish lanaguage files
320
        $this->publishes(
321
            [
322
            $this->getResourcesPath('lang') => resource_path('lang'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'finder')
323
            ], ['lang',  'sitec', 'sitec-lang', 'translations']
324
        );
325
326
        // Load translations
327
        $this->loadTranslationsFrom($this->getResourcesPath('lang'), 'finder');
328
    }
329
330
331
    /**
332
     *
333
     */
334
    private function loadLogger()
335
    {
336
        Config::set(
337
            'logging.channels.sitec-finder', [
338
            'driver' => 'single',
339
            'path' => storage_path('logs'.DIRECTORY_SEPARATOR.'sitec-finder.log'),
340
            'level' => env('APP_LOG_LEVEL', 'debug'),
341
            ]
342
        );
343
    }
344
}
345