Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
40.00% covered (warning)
40.00%
2 / 5
CRAP
93.02% covered (success)
93.02%
40 / 43
AppServiceProvider
0.00% covered (danger)
0.00%
0 / 1
40.00% covered (warning)
40.00%
2 / 5
21.15
93.02% covered (success)
93.02%
40 / 43
 boot
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 register
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 setRedisConnections
0.00% covered (danger)
0.00%
0 / 1
6.03
90.91% covered (success)
90.91%
10 / 11
 setFilesystemsDisks
0.00% covered (danger)
0.00%
0 / 1
6.03
90.91% covered (success)
90.91%
10 / 11
 setLogging
0.00% covered (danger)
0.00%
0 / 1
6.03
90.91% covered (success)
90.91%
10 / 11
1<?php
2
3namespace Qmp\Laravel\MicroService\Providers;
4
5use Illuminate\Contracts\Foundation\CachesConfiguration;
6use Illuminate\Support\Facades\Schema;
7use Illuminate\Support\ServiceProvider;
8use Qmp\Laravel\MicroService\DbConnection\DbConnection;
9
10class AppServiceProvider extends ServiceProvider
11{
12    /**
13     * Bootstrap any application services.
14     *
15     * @return void
16     */
17    public function boot()
18    {
19        // Force to load assets with HTTPS prefix when passed by proxy pass in HTTP and output in HTTPS (cf: https://laracasts.com/discuss/channels/laravel/how-i-can-force-all-my-routes-to-be-https-not-http?page=1#reply=289169)
20        if(env('REDIRECT_HTTPS')) {
21            \URL::forceScheme('https');
22        }
23
24        // Set timezone to ENV APP_TZ
25        date_default_timezone_set(env('APP_TZ', 'Europe/Paris'));
26
27        // MariaDB error when key is too long when migration (cf: https://laravel-news.com/laravel-5-4-key-too-long-error)
28        //Schema::defaultStringLength(191);
29
30        $this->loadMigrationsFrom(__DIR__.'/../database/migrations/');
31    }
32
33    /**
34     * Register any application services.
35     *
36     * @return void
37     */
38    public function register()
39    {
40        $this->setRedisConnections();
41        $this->setFilesystemsDisks();
42        $this->setLogging();
43        
44        DbConnection::mergeFromFile(realpath(__DIR__.'/../../config/connection.php'));
45    }
46
47    protected function setRedisConnections()
48    {
49        if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
50            $config = $this->app->make('config');
51
52            $db = $config->get('database');
53            $redisConfig = require realpath(__DIR__.'/../../config/redis.php');
54            
55            if (is_array($redisConfig)) {
56                if (!isset($db['redis'])) {
57                    $db['redis'] = [];
58                }
59    
60                foreach($redisConfig as $key => $item) {
61                    $db['redis'][$key] = $item;
62                }
63            }
64
65            $config->set('database', $db);
66        }
67    }
68
69    protected function setFilesystemsDisks()
70    {
71        if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
72            $config = $this->app->make('config');
73
74            $disks = $config->get('filesystems');
75            $fileSystems = require realpath(__DIR__.'/../../config/filesystems.php');
76            
77            if (is_array($fileSystems)) {
78                if (!isset($disks['disks'])) {
79                    $disks['disks'] = [];
80                }
81    
82                foreach($fileSystems as $key => $item) {
83                    $disks['disks'][$key] = $item;
84                }
85            }
86
87            $config->set('filesystems', $disks);
88        }
89    }
90
91    protected function setLogging()
92    {
93        if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
94            $config = $this->app->make('config');
95
96            $logging = $config->get('logging');
97            $channels = require realpath(__DIR__.'/../../config/logging.php');
98            
99            if (is_array($channels)) {
100                if (!isset($logging['channels'])) {
101                    $logging['channels'] = [];
102                }
103    
104                foreach($channels as $key => $item) {
105                    $logging['channels'][$key] = $item;
106                }
107            }
108
109            $config->set('logging', $logging);
110        }
111    }
112}