apache
wp-content
mu-plugins
plugins
activitypub
audioigniter
authldap
companion-auto-update
gitium
gp-premium
jetpack-protect
menu-icons
simple-local-avatars
smtp-mailer
two-factor
w3-total-cache
wp-piwik
wp-webauthn
blocks
css
js
languages
vendor
beberlei
brick
composer
fgrosse
league
nyholm
php-http
psr
ramsey
spomky-labs
symfony
thecodingmachine
safe
deprecated
generated
Exceptions
apache.php
apcu.php
array.php
bzip2.php
calendar.php
classobj.php
com.php
cubrid.php
curl.php
datetime.php
dir.php
eio.php
errorfunc.php
exec.php
fileinfo.php
filesystem.php
filter.php
fpm.php
ftp.php
funchand.php
functionsList.php
gmp.php
gnupg.php
hash.php
ibase.php
ibmDb2.php
iconv.php
image.php
imap.php
info.php
ingres-ii.php
inotify.php
json.php
ldap.php
libxml.php
lzf.php
mailparse.php
mbstring.php
misc.php
msql.php
mysql.php
mysqli.php
mysqlndMs.php
mysqlndQc.php
network.php
oci8.php
opcache.php
openssl.php
outcontrol.php
password.php
pcntl.php
pcre.php
pdf.php
pgsql.php
posix.php
ps.php
pspell.php
readline.php
rpminfo.php
rrd.php
sem.php
session.php
shmop.php
simplexml.php
sockets.php
sodium.php
solr.php
spl.php
sqlsrv.php
ssdeep.php
ssh2.php
stream.php
strings.php
swoole.php
uodbc.php
uopz.php
url.php
var.php
xdiff.php
xml.php
xmlrpc.php
yaml.php
yaz.php
zip.php
zlib.php
lib
LICENSE
README.md
composer.json
rector-migrate-0.7.php
web-auth
web-token
autoload.php
LICENSE
readme.txt
wp-webauthn.php
wwa-admin-content.php
wwa-ajax.php
wwa-compatibility.php
wwa-functions.php
wwa-menus.php
wwa-profile-content.php
wwa-shortcodes.php
wwa-version.php
index.php
themes
upgrade-temp-backup
w3tc-config
index.php
.dbsetup
.gitignore
htaccess
php.ini
158 lines
3.7 KiB
PHP
158 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Safe;
|
|
|
|
use Safe\Exceptions\ReadlineException;
|
|
|
|
/**
|
|
* This function adds a line to the command line history.
|
|
*
|
|
* @param string $line The line to be added in the history.
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_add_history(string $line): void
|
|
{
|
|
error_clear_last();
|
|
$result = \readline_add_history($line);
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Sets up a readline callback interface then prints
|
|
* prompt and immediately returns.
|
|
* Calling this function twice without removing the previous
|
|
* callback interface will automatically and conveniently overwrite the old
|
|
* interface.
|
|
*
|
|
* The callback feature is useful when combined with
|
|
* stream_select as it allows interleaving of IO and
|
|
* user input, unlike readline.
|
|
*
|
|
*
|
|
* Readline Callback Interface Example
|
|
*
|
|
* 10) {
|
|
* $prompting = false;
|
|
* readline_callback_handler_remove();
|
|
* } else {
|
|
* readline_callback_handler_install("[$c] Enter something: ", 'rl_callback');
|
|
* }
|
|
* }
|
|
*
|
|
* $c = 1;
|
|
* $prompting = true;
|
|
*
|
|
* readline_callback_handler_install("[$c] Enter something: ", 'rl_callback');
|
|
*
|
|
* while ($prompting) {
|
|
* $w = NULL;
|
|
* $e = NULL;
|
|
* $n = stream_select($r = array(STDIN), $w, $e, null);
|
|
* if ($n && in_array(STDIN, $r)) {
|
|
* // read a character, will call the callback when a newline is entered
|
|
* readline_callback_read_char();
|
|
* }
|
|
* }
|
|
*
|
|
* echo "Prompting disabled. All done.\n";
|
|
* ?>
|
|
* ]]>
|
|
*
|
|
*
|
|
*
|
|
* @param string $prompt The prompt message.
|
|
* @param callable $callback The callback function takes one parameter; the
|
|
* user input returned.
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_callback_handler_install(string $prompt, callable $callback): void
|
|
{
|
|
error_clear_last();
|
|
$result = \readline_callback_handler_install($prompt, $callback);
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function clears the entire command line history.
|
|
*
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_clear_history(): void
|
|
{
|
|
error_clear_last();
|
|
$result = \readline_clear_history();
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function registers a completion function. This is the same kind of
|
|
* functionality you'd get if you hit your tab key while using Bash.
|
|
*
|
|
* @param callable $function You must supply the name of an existing function which accepts a
|
|
* partial command line and returns an array of possible matches.
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_completion_function(callable $function): void
|
|
{
|
|
error_clear_last();
|
|
$result = \readline_completion_function($function);
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function reads a command history from a file.
|
|
*
|
|
* @param string $filename Path to the filename containing the command history.
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_read_history(string $filename = null): void
|
|
{
|
|
error_clear_last();
|
|
if ($filename !== null) {
|
|
$result = \readline_read_history($filename);
|
|
} else {
|
|
$result = \readline_read_history();
|
|
}
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function writes the command history to a file.
|
|
*
|
|
* @param string $filename Path to the saved file.
|
|
* @throws ReadlineException
|
|
*
|
|
*/
|
|
function readline_write_history(string $filename = null): void
|
|
{
|
|
error_clear_last();
|
|
if ($filename !== null) {
|
|
$result = \readline_write_history($filename);
|
|
} else {
|
|
$result = \readline_write_history();
|
|
}
|
|
if ($result === false) {
|
|
throw ReadlineException::createFromPhpError();
|
|
}
|
|
}
|