1 | <?php |
||
11 | class Mysql extends Command implements WebCommand |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $name = 'mysql'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'mysql console'; |
||
26 | |||
27 | /** |
||
28 | * $connection. |
||
29 | * |
||
30 | * @var \Illuminate\Database\DatabaseManager |
||
31 | */ |
||
32 | protected $databaseManager; |
||
33 | |||
34 | /** |
||
35 | * __construct. |
||
36 | * |
||
37 | * @param \Illuminate\Database\DatabaseManager $databaseManager |
||
38 | */ |
||
39 | 1 | public function __construct(DatabaseManager $databaseManager) |
|
40 | { |
||
41 | 1 | parent::__construct(); |
|
42 | |||
43 | 1 | $this->databaseManager = $databaseManager; |
|
44 | 1 | } |
|
45 | |||
46 | /** |
||
47 | * Handle the command. |
||
48 | * |
||
49 | * @throws \InvalidArgumentException |
||
50 | */ |
||
51 | 1 | public function handle() |
|
52 | { |
||
53 | 1 | $query = $this->option('command'); |
|
54 | 1 | if(isset(config('terminal.dbconnection')) { |
|
55 | 1 | $connection = $this->databaseManager->connection(config('terminal.dbconnection')); |
|
56 | 1 | } else { |
|
57 | 1 | $connection = $this->databaseManager->connection(); |
|
58 | 1 | } |
|
59 | $rows = json_decode(json_encode($connection->select($query)), true); |
||
60 | $headers = array_keys(Arr::get($rows, 0, [])); |
||
61 | $this->table($headers, $rows); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | 1 | * Get the console command options. |
|
66 | * |
||
67 | * @return array |
||
68 | 1 | */ |
|
69 | 1 | protected function getOptions() |
|
70 | { |
||
71 | return [ |
||
72 | ['command', null, InputOption::VALUE_OPTIONAL], |
||
76 |