add standard I/O streams and few functions

This commit is contained in:
Pekka Laiho 2020-12-25 08:38:45 +07:00
parent 9e0550736a
commit 7fd0005735
2 changed files with 19 additions and 0 deletions

View File

@ -75,6 +75,14 @@ class Core implements ILib
));
}
$env->set('php-sapi', new CoreFunc('php-sapi', 'Get the name of the PHP SAPI.', 0, 0,
fn () => php_sapi_name()
));
$env->set('php-version', new CoreFunc('php-version', 'Get the PHP version.', 0, 0,
fn () => phpversion()
));
if (!$this->safemode) {
$env->set('print', new CoreFunc('print', 'Print arguments.', 0, -1,
function (...$args) {

View File

@ -18,6 +18,13 @@ class IO implements ILib
$env->set('DIRSEP', \DIRECTORY_SEPARATOR);
$env->set('HOME', $_SERVER['HOME'] . \DIRECTORY_SEPARATOR);
if (php_sapi_name() == 'cli') {
// Define standard I/O streams
$env->set('STDIN', STDIN);
$env->set('STDOUT', STDOUT);
$env->set('STDERR', STDERR);
}
$env->set('wd', new CoreFunc('wd', 'Get the current working directory.', 0, 0,
fn () => getcwd() . \DIRECTORY_SEPARATOR
));
@ -34,6 +41,10 @@ class IO implements ILib
fn (string $dir) => is_dir($dir)
));
$env->set('tty?', new CoreFunc('tty?', 'Return true if the given file descriptor is a TTY.', 1, 1,
fn ($stream) => stream_isatty($stream)
));
$env->set('fsize', new CoreFunc('fsize', 'Return the size of a file.', 1, 1,
fn (string $file) => @filesize($file)
));