diff --git a/src/Lib/Core.php b/src/Lib/Core.php index ba1ec74..1d160eb 100644 --- a/src/Lib/Core.php +++ b/src/Lib/Core.php @@ -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) { diff --git a/src/Lib/IO.php b/src/Lib/IO.php index 47d1641..0e99259 100644 --- a/src/Lib/IO.php +++ b/src/Lib/IO.php @@ -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) ));