Skip to content

Commit ec026cf

Browse files
committed
Use PHP built-in console for script/console
1 parent ad1ad52 commit ec026cf

1 file changed

Lines changed: 6 additions & 40 deletions

File tree

script/console

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
11
#!/usr/bin/env php
22
<?php
33

4-
/**
5-
* Set environment
6-
*/
74
define('MAD_ENV', isset($_SERVER['MAD_ENV']) ? $_SERVER['MAD_ENV'] : 'development');
8-
require_once dirname(dirname(__FILE__)).'/config/environment.php';
95

10-
print "Loading ".MAD_ENV." environment (Mad 1.0)\n";
6+
echo "Loading ".MAD_ENV." environment\n";
117

12-
$f = fopen('php://stdin', 'r');
13-
14-
$buffer = '';
15-
while (true) {
16-
print '>> ';
17-
$input = chop(fgets($f, 1024));
18-
if ($input == 'quit' || $input == 'exit') { fclose($f); exit; }
19-
20-
// buffer the input
21-
$buffer .= " $input";
22-
23-
// @todo - use a regexp to make sure brace char is not in a string
24-
$opening = substr_count($buffer, '{');
25-
$closing = substr_count($buffer, '}');
26-
27-
// evaluate expression if we've closed all braces
28-
if ($closing >= $opening && $buffer != ' ') {
29-
try {
30-
$result = 'null';
31-
if (!strstr($buffer, '{')) {
32-
eval("\$result = $buffer");
33-
} else {
34-
eval($buffer);
35-
}
36-
// print result of expression
37-
print "=> $result\n";
38-
39-
} catch (Exception $e) {
40-
print get_class($e).": ".$e->getMessage()."\n".
41-
' from: '.$e->getFile().':'.$e->getLine()."\n";
42-
43-
}
44-
$buffer = '';
45-
}
46-
}
8+
putenv('MAD_ENV=' . MAD_ENV);
9+
pcntl_exec(PHP_BINARY, [
10+
'-d', 'auto_prepend_file=' . dirname(__DIR__) . '/config/environment.php',
11+
'-a'
12+
]);

0 commit comments

Comments
 (0)