Skip to content

Commit ce0532c

Browse files
committed
can show tables on cli prompt
Signed-off-by: Derek Smart <derek@grindaga.com>
1 parent fdb127a commit ce0532c

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/cli/Action.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace PHPRed\CLI;
3+
4+
class Action extends \PHPRed\PHPRed
5+
{
6+
public function __construct(\mysqli $mysqli)
7+
{
8+
parent::__construct($mysqli);
9+
}
10+
11+
public function listTables()
12+
{
13+
$tables = $this->query("SHOW TABLES");
14+
return $tables[0]['Tables_in_' . $_ENV['db_name']];
15+
}
16+
}

src/cli/CLI.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?php
22
namespace PHPRed\CLI;
33

4-
abstract class CLI extends \PHPRed\PHPRed
4+
abstract class CLI
55
{
66
private $stdout;
77
private $stderr;
88
private $stdin;
99

10-
public function __construct(\mysqli $mysqli, $stdout = '', $stderr = '', $stdin = '')
10+
public function __construct($stdout = STDOUT, $stderr = STDERR, $stdin = STDIN)
1111
{
12-
parent::__construct($mysqli);
13-
14-
$this->stdout = $stdout ? $stdout : STDOUT;
15-
$this->stderr = $stderr ? $stderr : STDERR;
16-
$this->stdin = $stdin ? $stdin : STDIN;
12+
$this->stdout = $stdout;
13+
$this->stderr = $stderr;
14+
$this->stdin = $stdin;
1715
}
1816

1917
protected function shutDown()

src/cli/Prompt.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
<?php
2-
namespace PHPREd\CLI;
2+
namespace PHPRed\CLI;
3+
4+
use PHPRed\CLI\Action;
35

46
class Prompt extends CLI
57
{
8+
private $action;
9+
610
public function __construct(\mysqli $mysqli)
711
{
8-
parent::__construct($mysqli);
12+
parent::__construct();
13+
$this->action = new Action($mysqli);
914
}
1015

1116
private function welcome()
1217
{
1318
$this->output('Welcome');
14-
$response = $this->prompt('What do you want to do? Type "yes".');
19+
$response = $this->prompt('Do you want to list tables?');
1520
if ($response != 'yes') {
1621
$this->output("ABORTING!");
1722
exit;
1823
}
19-
$this->output("Thank you, continuing");
24+
$this->output($this->action->listTables());
2025
}
2126

2227
public function run()

0 commit comments

Comments
 (0)