Total Complexity | 4 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
9 | class EncryptionServiceProvider extends ServiceProvider |
||
10 | { |
||
11 | /** |
||
12 | * Register the service provider. |
||
13 | * |
||
14 | * @return void |
||
15 | */ |
||
16 | public function register() |
||
17 | { |
||
18 | $this->app->singleton('encrypter.sodium', function ($app) { |
||
19 | $config = $app->make('config')->get('app'); |
||
20 | |||
21 | if (Str::startsWith($key = $this->key($config), 'base64:')) { |
||
22 | $key = base64_decode(substr($key, 7)); |
||
23 | } |
||
24 | |||
25 | return new Encrypter($key); |
||
26 | }); |
||
27 | |||
28 | $this->app->alias('encrypter.sodium', Encrypter::class); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Extract the encryption key from the given configuration. |
||
33 | * |
||
34 | * @param array $config |
||
35 | * @return string |
||
36 | * |
||
37 | * @throws \RuntimeException |
||
38 | */ |
||
39 | protected function key(array $config) |
||
45 | ); |
||
46 | } |
||
50 |