This commit is contained in:
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Support\ManagedCredentialFiles;
|
||||
use App\Support\ManagedPhpRedisConnector;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Redis\RedisManager;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use RuntimeException;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -15,7 +20,30 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
$config = $this->app['config'];
|
||||
if ($config->get('database.managed_credentials') !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($config->get('database.default') !== 'mysql'
|
||||
|| $config->get('database.redis.client') !== 'phpredis'
|
||||
|| $config->get('database.connections.mysql.url')
|
||||
|| $config->get('database.redis.default.url')
|
||||
|| $config->get('database.redis.cache.url')) {
|
||||
throw new RuntimeException('Managed credentials require the supported MySQL and standalone PhpRedis connections.');
|
||||
}
|
||||
|
||||
$this->callAfterResolving('db', function (DatabaseManager $manager): void {
|
||||
$manager->extend('mysql', function (array $connection, string $name) {
|
||||
$connection['password'] = ManagedCredentialFiles::databasePassword();
|
||||
|
||||
return $this->app['db.factory']->make($connection, $name);
|
||||
});
|
||||
});
|
||||
|
||||
$this->callAfterResolving('redis', function (RedisManager $manager): void {
|
||||
$manager->extend('phpredis', fn () => new ManagedPhpRedisConnector);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user