IntegrationsProvider::routes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace Integrations;
4
5
use App;
6
use Config;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use Illuminate\Foundation\AliasLoader;
9
use Illuminate\Routing\Router;
10
11
use Illuminate\Support\Collection;
12
use Illuminate\Support\Facades\View;
13
use Illuminate\Support\ServiceProvider;
14
use Integrations\Facades\Integrations as IntegrationsFacade;
15
use Integrations\Services\IntegrationsService;
16
17
use Log;
18
19
use Muleta\Traits\Providers\ConsoleTools;
20
use Route;
21
22
class IntegrationsProvider extends ServiceProvider
23
{
24
    use ConsoleTools;
25
26
    public $packageName = 'integrations';
27
    const pathVendor = 'sierratecnologia/integrations';
28
29
    public static $aliasProviders = [
30
        'Integrations' => \Integrations\Facades\Integrations::class,
31
    ];
32
33
    public static $providers = [
34
35
        // \Support\SupportProviderService::class,
36
37
        
38
    ];
39
40
    /**
41
     * Rotas do Menu
42
     */
43
    public static $menuItens = [
44
        // 'Config|425' => [
45
            [
46
                'text' => 'Integrações',
47
                'icon' => 'fas fa-fw fa-search',
48
                'icon_color' => "blue",
49
                'label_color' => "success",
50
                'section'     => 'admin',
51
                'feature' => 'integrations',
52
                'order' => 2200,
53
                'level'       => 2, // 0 (Public), 1, 2 (Admin) , 3 (Root)
54
            ],
55
            'Integrações' => [
56
                [
57
                    'text'        => 'Tokens',
58
                    'route'       => 'admin.integrations.tokens.index',
59
                    'icon'        => 'fas fa-fw fa-search',
60
                    'icon_color'  => 'blue',
61
                    'label_color' => 'success',
62
                    'section'     => 'admin',
63
                    'feature' => 'integrations',
64
                    'order' => 2250,
65
                    'level'       => 2, // 0 (Public), 1, 2 (Admin) , 3 (Root)
66
                    // 'access' => \Porteiro\Models\Role::$ADMIN
67
                ],
68
            ],
69
        // ],
70
    ];
71
72
    /**
73
     * Alias the services in the boot.
74
     */
75
    public function boot()
76
    {
77
        
78
        // Register configs, migrations, etc
79
        $this->registerDirectories();
80
81
        // COloquei no register pq nao tava reconhecendo as rotas para o adminlte
82
        $this->app->booted(
83
            function () {
84
                $this->routes();
85
            }
86
        );
87
88
        $this->loadLogger();
89
    }
90
91
    /**
92
     * Register the tool's routes.
93
     *
94
     * @return void
95
     */
96
    protected function routes()
97
    {
98
        if ($this->app->routesAreCached()) {
99
            return;
100
        }
101
102
        /**
103
         * Transmissor; Routes
104
         */
105
        $this->loadRoutesForRiCa(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'routes');
106
        // Route::group(
107
        //     [
108
        //         'namespace' => '\Integrations\Http\Controllers',
109
        //         'prefix' => \Illuminate\Support\Facades\Config::get('application.routes.main', ''),
110
        //         'as' => 'rica.',
111
        //         // 'middleware' => 'rica',
112
        //     ], function ($router) {
113
        //         include __DIR__.'/../routes/web.php';
114
        //     }
115
        // );
116
    }
117
118
119
    /**
120
     * Register the services.
121
     */
122
    public function register()
123
    {
124
        // Register Configs
125
        $this->mergeConfigFrom(
126
            $this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'integrations.php'),
127
            'integrations'
128
        );
129
        $this->mergeConfigFrom(
130
            $this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'services.php'),
131
            'services'
132
        );
133
        
134
135
        $this->setProviders();
136
        // $this->routes();
137
138
139
140
        // Register Migrations
141
        $this->loadMigrationsFrom(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations');
142
143
        $this->app->singleton(
144
            'integrations', function () {
145
                return new Integrations();
146
            }
147
        );
148
        
149
        /*
150
        |--------------------------------------------------------------------------
151
        | Register the Utilities
152
        |--------------------------------------------------------------------------
153
        */
154
        /**
155
         * Singleton Integrations;
156
         */
157
        $this->app->singleton(
158
            IntegrationsService::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...
159
                Log::channel('sitec-integrations')->info('Singleton Integrations;');
160
                return new IntegrationsService(\Illuminate\Support\Facades\Config::get('sitec.integrations'));
161
            }
162
        );
163
164
        // Register commands
165
        $this->registerCommandFolders(
166
            [
167
            base_path('vendor/sierratecnologia/integrations/src/Console/Commands') => '\Integrations\Console\Commands',
168
            ]
169
        );
170
171
        // /**
172
        //  * Helpers
173
        //  */
174
        // Aqui noa funciona
175
        // if (!function_exists('integrations_asset')) {
176
        //     function integrations_asset($path, $secure = null)
177
        //     {
178
        //         return route('rica.integrations.assets').'?path='.urlencode($path);
179
        //     }
180
        // }
181
    }
182
183
    /**
184
     * Get the services provided by the provider.
185
     *
186
     * @return array
187
     */
188
    public function provides()
189
    {
190
        return [
191
            'integrations',
192
        ];
193
    }
194
195
    /**
196
     * Register configs, migrations, etc
197
     *
198
     * @return void
199
     */
200
    public function registerDirectories()
201
    {
202
        // Publish config files
203
        $this->publishes(
204
            [
205
                $this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'integrations.php') => config_path('integrations.php'),
206
                $this->getPublishesPath('config'.DIRECTORY_SEPARATOR.'services.php') => config_path('services.php'),
207
            ], ['config',  'sitec', 'sitec-config', 'integrations', 'integrations-config']
208
        );
209
210
        // // Publish integrations css and js to public directory
211
        // $this->publishes([
212
        //     $this->getDistPath('integrations') => public_path('assets/integrations')
213
        // ], ['public',  'sitec', 'sitec-public']);
214
215
        $this->loadViews();
216
        $this->loadTranslations();
217
    }
218
219
    private function loadViews()
220
    {
221
        // View namespace
222
        $viewsPath = $this->getResourcesPath('views');
223
        $this->loadViewsFrom($viewsPath, 'integrations');
224
        $this->publishes(
225
            [
226
            $viewsPath => base_path('resources'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'integrations'),
227
            ], ['views',  'sitec', 'sitec-views']
228
        );
229
    }
230
    
231
    private function loadTranslations()
232
    {
233
        // Publish lanaguage files
234
        $this->publishes(
235
            [
236
            $this->getResourcesPath('lang') => resource_path('lang'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'integrations')
237
            ], ['lang',  'sitec', 'sitec-lang', 'translations']
238
        );
239
240
        // Load translations
241
        $this->loadTranslationsFrom($this->getResourcesPath('lang'), 'integrations');
242
    }
243
244
245
    /**
246
     *
247
     */
248
    private function loadLogger()
249
    {
250
        Config::set(
251
            'logging.channels.sitec-integrations', [
252
            'driver' => 'single',
253
            'path' => storage_path('logs'.DIRECTORY_SEPARATOR.'sitec-integrations.log'),
254
            'level' => env('APP_LOG_LEVEL', 'debug'),
255
            ]
256
        );
257
    }
258
}
259