1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @filesource common-cli.php |
4
|
|
|
* @created 24.10.2019 |
5
|
|
|
* @author smiley <[email protected]> |
6
|
|
|
* @copyright 2019 smiley |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace codemasher\WildstarDBCLI; |
11
|
|
|
|
12
|
|
|
use chillerlan\Database\{Database, DatabaseOptions, Drivers\MySQLiDrv}; |
13
|
|
|
use chillerlan\DotEnv\DotEnv; |
14
|
|
|
use chillerlan\SimpleCache\MemoryCache; |
15
|
|
|
use Psr\Log\AbstractLogger; |
16
|
|
|
|
17
|
|
|
use function date, mb_internal_encoding, sprintf, substr, trim; |
18
|
|
|
|
19
|
|
|
mb_internal_encoding('UTF-8'); |
20
|
|
|
|
21
|
|
|
require_once __DIR__.'/../vendor/autoload.php'; |
22
|
|
|
|
23
|
|
|
$wildstar_path = '/wildstar'; |
24
|
|
|
|
25
|
|
|
$env = (new DotEnv(__DIR__.'/../config', '.env', false))->load(); |
26
|
|
|
|
27
|
|
|
$o = [ |
28
|
|
|
// DatabaseOptions |
29
|
|
|
'driver' => MySQLiDrv::class, |
30
|
|
|
'host' => $env->DB_HOST, |
31
|
|
|
'port' => $env->DB_PORT, |
32
|
|
|
'socket' => $env->DB_SOCKET, |
33
|
|
|
'database' => $env->DB_DATABASE, |
34
|
|
|
'username' => $env->DB_USERNAME, |
35
|
|
|
'password' => $env->DB_PASSWORD, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
$logger = new class() extends AbstractLogger{ |
39
|
|
|
|
40
|
|
|
public function log($level, $message, array $context = []){ |
41
|
|
|
echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n"; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
$db = new Database(new DatabaseOptions($o), new MemoryCache, $logger); |
47
|
|
|
|