Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
CRAP
94.74% covered (success)
94.74%
18 / 19
ExternalUsersProvider
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
8.01
94.74% covered (success)
94.74%
18 / 19
 register
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
10 / 10
 boot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 addKeyToAuthConfig
0.00% covered (danger)
0.00%
0 / 1
4.07
83.33% covered (success)
83.33%
5 / 6
1<?php
2namespace Qmp\Laravel\ExternalUsers\Providers;
3
4use Illuminate\Contracts\Foundation\CachesConfiguration;
5use Illuminate\Support\ServiceProvider;
6use Qmp\Laravel\MicroService\DbConnection\DbConnection;
7
8class ExternalUsersProvider extends ServiceProvider
9{
10    public function register()
11    {
12        if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
13            $config = $this->app->make('config');
14
15            $auth = $config->get('auth');
16            $externalUserAuthConfig = require realpath(__DIR__.'/../../config/auth.php');
17            
18            $this->addKeyToAuthConfig($auth, $externalUserAuthConfig, 'guards');
19            $this->addKeyToAuthConfig($auth, $externalUserAuthConfig, 'providers');
20            $this->addKeyToAuthConfig($auth, $externalUserAuthConfig, 'passwords');
21
22            $config->set('auth', $auth);
23        }
24
25        DbConnection::mergeFromFile(realpath(__DIR__.'/../../config/connection.php'));
26    }
27    
28    /**
29     * Boot the service provider.
30     *
31     * @return void
32     */
33    public function boot()
34    {
35        $this->loadViewsFrom(realpath(__DIR__.'/../Views'), 'emails_external');
36        
37        $this->loadMigrationsFrom(__DIR__.'/../database/migrations/');
38    }
39
40    protected function addKeyToAuthConfig(array &$auth, array $externalUserAuthConfig, string $keyToAdd)
41    {
42        if (isset($externalUserAuthConfig[$keyToAdd])) {
43            if (!isset($auth[$keyToAdd])) {
44                $auth[$keyToAdd] = [];
45            }
46
47            foreach($externalUserAuthConfig[$keyToAdd] as $key => $item) {
48                $auth[$keyToAdd][$key] = $item;
49            }
50        }
51    }
52}