This repository was archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.php
More file actions
71 lines (58 loc) · 1.27 KB
/
Console.php
File metadata and controls
71 lines (58 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require_once(dirname(__FILE__).'/Core.php');
class ConsoleController extends Controller
{
public $user_vars = array();
public function exec()
{
// term terminal
// make c
// make t
$this->console();
}
public function vars_completion($input, $index) {
if(empty($input))
{
return array();
}
$matches = array();
$keys = array_keys($this->user_vars);
$functions = get_defined_functions();
$keys = array_merge($keys, array_values($functions['internal']), array_values(get_declared_classes()));
foreach ($keys as $key) {
if(strpos($key, $input) === 0)
{
$matches[] = $key;
}
}
return $matches;
}
private function console()
{
readline_completion_function(array($this, 'vars_completion'));
while(1)
{
$_line = readline('>>> ');
if(empty($_line))
{
continue;
}
readline_add_history($_line);
extract($this->user_vars, EXTR_SKIP);
$_code = 'return '.trim($_line, ';').';';
echo '<<< ' . var_export(@eval($_code), true) . PHP_EOL;
$this->user_vars = array();
$_vars = get_defined_vars();
foreach ($_vars as $_key => $_value)
{
if(strpos($_key, '_') === 0)
{
continue;
}
$this->user_vars[$_key] = $_value;
}
echo PHP_EOL;
}
}
}
dispatchAction('ConsoleController');