<?php
 namespace App\Modules\Addon\MigrateWisecp\Services; use Illuminate\Database\Connection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; class WisecpSourceConnection { public const NAME = 'wisecp_src'; public static function configure(array $creds): void { Config::set('database.connections.'.self::NAME, [ 'driver' => 'mysql', 'host' => $creds['host'] ?? '127.0.0.1', 'port' => $creds['port'] ?? '3306', 'database' => $creds['database'] ?? '', 'username' => $creds['username'] ?? '', 'password' => $creds['password'] ?? '', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => false, 'options' => [\PDO::ATTR_TIMEOUT => 10], ]); DB::purge(self::NAME); } public static function connection(): Connection { return DB::connection(self::NAME); } public static function table(string $table) { return self::connection()->table($table); } public static function test(array $creds): array { try { self::configure($creds); $count = self::table('users')->where('type', 'member')->count(); return [ 'ok' => true, 'message' => 'Bağlantı başarılı — WiseCP `users` erişilebilir.', 'client_count' => $count, ]; } catch (\Throwable $e) { return [ 'ok' => false, 'message' => 'Bağlantı başarısız: '.$e->getMessage(), 'client_count' => 0, ]; } } } 