1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\Credentials; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Encryption\Encrypter; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
|
9
|
|
|
class CredentialsServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Bootstrap the application services. |
14
|
|
|
*/ |
15
|
|
|
public function boot() |
16
|
|
|
{ |
17
|
|
|
$this->publishes([ |
18
|
|
|
__DIR__ . '/../config/credentials.php' => config_path('credentials.php'), |
19
|
|
|
], 'config'); |
20
|
|
|
|
21
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/credentials.php', 'credentials'); |
22
|
|
|
|
23
|
|
|
// Update configuration strings |
24
|
|
|
if( !app()->configurationIsCached()) { |
25
|
|
|
$this->fixConfig(); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function fixConfig() |
30
|
|
|
{ |
31
|
|
|
collect(array_dot(config()->all()))->filter(function ($item) { |
32
|
|
|
return is_string($item) && starts_with($item, Credentials::CONFIG_PREFIX); |
33
|
|
|
})->map(function ($item, $key) { |
34
|
|
|
$item = str_replace_first(Credentials::CONFIG_PREFIX, '', $item); |
35
|
|
|
|
36
|
|
|
config()->set($key, credentials($item)); |
37
|
|
|
}); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the application services. |
42
|
|
|
*/ |
43
|
|
|
public function register() |
44
|
|
|
{ |
45
|
|
|
$this->app->bind(Credentials::class, function(){ |
46
|
|
|
|
47
|
|
|
// If the key starts with "base64:", we will need to decode the key before handing |
48
|
|
|
// it off to the encrypter. Keys may be base-64 encoded for presentation and we |
49
|
|
|
// want to make sure to convert them back to the raw bytes before encrypting. |
50
|
|
|
if (Str::startsWith($key = config('credentials.key'), 'base64:')) { |
51
|
|
|
$key = base64_decode(substr($key, 7)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$encrypter = new Encrypter($key, config('credentials.cipher')); |
55
|
|
|
return new Credentials($encrypter); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
$this->app->bind('command.credentials.edit', EditCredentialsCommand::class); |
59
|
|
|
|
60
|
|
|
$this->commands([ |
61
|
|
|
'command.credentials.edit' |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|