本文整理汇总了PHP中readline_write_history函数的典型用法代码示例。如果您正苦于以下问题:PHP readline_write_history函数的具体用法?PHP readline_write_history怎么用?PHP readline_write_history使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readline_write_history函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
protected function init()
{
global $swarmInstallDir;
$this->checkAtty();
$supportsReadline = function_exists('readline_add_history');
if ($supportsReadline) {
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.testswarm_eval_history" : "{$swarmInstallDir}/config/.testswarm_eval_history";
readline_read_history($historyFile);
}
while (!!($line = $this->cliInput())) {
if ($supportsReadline) {
readline_add_history($line);
readline_write_history($historyFile);
}
$ret = eval($line . ";");
if (is_null($ret)) {
echo "\n";
} elseif (is_string($ret) || is_numeric($ret)) {
echo "{$ret}\n";
} else {
var_dump($ret);
}
}
print "\n";
exit;
}
示例2: writeHistory
/**
* {@inheritDoc}
*/
public function writeHistory()
{
// We have to write history first, since it is used
// by Libedit to list history
$res = readline_write_history($this->historyFile);
if (!$res || !$this->eraseDups && !$this->historySize > 0) {
return $res;
}
$hist = $this->listHistory();
if (!$hist) {
return true;
}
if ($this->eraseDups) {
// flip-flip technique: removes duplicates, latest entries win.
$hist = array_flip(array_flip($hist));
// sort on keys to get the order back
ksort($hist);
}
if ($this->historySize > 0) {
$histsize = count($hist);
if ($histsize > $this->historySize) {
$hist = array_slice($hist, $histsize - $this->historySize);
}
}
readline_clear_history();
foreach ($hist as $line) {
readline_add_history($line);
}
return readline_write_history($this->historyFile);
}
示例3: start
public function start()
{
$histfile = '.magesh_history';
if (PHP_OS == 'Linux') {
readline_read_history($histfile);
}
do {
$input = $this->_getInput($this->_prompt);
if ($input === false) {
break;
}
$cmd = $this->_formatInput($input);
if (PHP_OS == 'Linux') {
readline_add_history($input);
readline_write_history($histfile);
}
echo "\n";
$result = null;
try {
$result = eval($cmd);
} catch (Exception $e) {
$result = $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n\n";
}
$output = $this->_formatOutput($result);
echo "Result: " . $output . "\n\n";
} while (true);
return true;
}
示例4: execute
public function execute()
{
$dbw = wfGetDB(DB_MASTER);
if ($this->hasArg()) {
$fileName = $this->getArg();
$file = fopen($fileName, 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
$newPrompt = '> ';
$prompt = $newPrompt;
while (($line = Maintenance::readconsole($prompt)) !== false) {
if (!$line) {
# User simply pressed return key
continue;
}
$done = $dbw->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
$wholeLine .= ' ';
$prompt = ' -> ';
continue;
}
if ($useReadline) {
# Delimiter is eated by streamStatementEnd, we add it
# up in the history (bug 37020)
readline_add_history($wholeLine . $dbw->getDelimiter());
readline_write_history($historyFile);
}
try {
$res = $dbw->query($wholeLine);
$this->sqlPrintResult($res, $dbw);
$prompt = $newPrompt;
$wholeLine = '';
} catch (DBQueryError $e) {
$doDie = !Maintenance::posix_isatty(0);
$this->error($e, $doDie);
}
}
}
示例5: readLine
public static function readLine($prompt, ReadlineCompleter $compl = null, callable $filter = null)
{
if ($compl) {
\readline_completion_function($compl);
}
$ret = \readline($prompt);
if (self::$history_file) {
readline_write_history(self::$history_file);
}
if ($filter) {
$ret = $filter($ret);
}
return $ret;
}
示例6: run
/**
* Runs the shell.
*/
public function run()
{
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(true);
if ($this->hasReadline) {
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
}
$this->output->writeln($this->getHeader());
$php = null;
if ($this->processIsolation) {
$finder = new PhpExecutableFinder();
$php = $finder->find();
$this->output->writeln(<<<EOF
<info>Running with process isolation, you should consider this:</info>
* each command is executed as separate process,
* commands don't support interactivity, all params must be passed explicitly,
* commands output is not colorized.
EOF
);
}
while (true) {
$command = $this->readline();
if (false === $command) {
$this->output->writeln("\n");
break;
}
if ($this->hasReadline) {
readline_add_history($command);
readline_write_history($this->history);
}
if ($this->processIsolation) {
$pb = new ProcessBuilder();
$process = $pb->add($php)->add($_SERVER['argv'][0])->add($command)->inheritEnvironmentVariables(true)->getProcess();
$output = $this->output;
$process->run(function ($type, $data) use($output) {
$output->writeln($data);
});
$ret = $process->getExitCode();
} else {
$ret = $this->application->run(new StringInput($command), $this->output);
}
if (0 !== $ret) {
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
}
}
}
示例7: __destruct
/**
* Destructor
*
* @return void
*/
public function __destruct()
{
fclose($this->input);
if ($this->options['readline']) {
readline_write_history($this->options['readline_hist']);
}
// Save config
$fp = fopen($this->rc_file, 'w');
if ($fp === false) {
return;
}
foreach ($this->options as $k => $v) {
fwrite($fp, "{$k} = \"{$v}\"\n");
}
fclose($fp);
}
示例8: init
public static function init($paths = null, $history_path = null)
{
self::$_often = get_defined_functions();
self::$_often = array_merge(self::$_often['internal'], get_declared_classes());
if (is_null($paths)) {
$paths = explode(PATH_SEPARATOR, get_include_path());
}
self::$_paths = $paths;
if (self::_supportedReadline()) {
readline_completion_function(array(__CLASS__, 'autocomplete'));
self::$__last = null;
if (is_null($history_path)) {
if ($home = getenv('HOME')) {
$history_path = $home . '/.pprompt_history';
}
}
if (self::$__history_path = $history_path) {
readline_read_history(self::$__history_path);
}
}
unset($paths);
unset($history_path);
unset($home);
while (self::$__l = self::_readline(">> ")) {
if (self::_supportedReadline()) {
if (is_null(self::$__last) or self::$__l != self::$__last) {
readline_add_history(self::$__l);
}
if (self::$__history_path) {
readline_write_history(self::$__history_path);
}
}
try {
eval(self::$__l . ";");
echo "\n";
} catch (Exception $e) {
echo $e->getMessage() . "\n";
echo $e->getTraceAsString() . "\n";
}
self::$_vars = get_defined_vars();
self::$__last = self::$__l;
}
}
示例9: execute
public function execute()
{
$dbw = wfGetDB(DB_MASTER);
if ($this->hasArg()) {
$fileName = $this->getArg();
$file = fopen($fileName, 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
while (($line = Maintenance::readconsole()) !== false) {
$done = $dbw->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
continue;
}
if ($useReadline) {
readline_add_history($wholeLine);
readline_write_history($historyFile);
}
try {
$res = $dbw->query($wholeLine);
$this->sqlPrintResult($res, $dbw);
$wholeLine = '';
} catch (DBQueryError $e) {
$this->error($e, true);
}
}
}
示例10: read_input_line
function read_input_line($prompt)
{
if (CONSOLE_INTERACTIVE) {
if (CONSOLE_READLINE) {
$line = readline($prompt);
if (trim($line) != '') {
readline_add_history($line);
if (defined('CONSOLE_HISTORY')) {
// Save often; it's easy to hit fatal errors.
readline_write_history(CONSOLE_HISTORY);
}
}
return $line;
} else {
return readline_emulation($prompt);
}
} else {
return fgets(STDIN);
}
}
示例11: run
/**
* Runs the shell.
*/
public function run()
{
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(true);
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
$this->output->writeln($this->getHeader());
while (true) {
$command = readline($this->application->getName() . ' > ');
if (false === $command) {
$this->output->writeln("\n");
break;
}
readline_add_history($command);
readline_write_history($this->history);
if (0 !== ($ret = $this->application->run(new StringInput($command), $this->output))) {
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
}
}
}
示例12: run
/**
* Runs the shell.
*/
public function run()
{
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(false);
if ($this->hasReadline) {
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
}
$this->output->writeln($this->getHeader());
while (true) {
$command = $this->readline();
if (false === $command) {
$this->output->writeln("\n");
break;
}
if ($this->hasReadline) {
readline_add_history($command);
readline_write_history($this->history);
}
$ret = $this->application->run(new StringInput($command), $this->output);
}
}
示例13: shutdown
public function shutdown($event)
{
readline_write_history($event->getSubject()->getConfigDir() . '/history');
}
示例14: tempnam
<?php
$name = tempnam('/tmp', 'readline.tmp');
readline_add_history('foo');
readline_add_history('');
readline_add_history(1);
readline_add_history(NULL);
var_dump(readline_write_history($name));
var_dump(readline_read_history($name));
var_dump(file_get_contents($name));
readline_clear_history();
readline_write_history($name);
var_dump(file_get_contents($name));
unlink($name);
示例15: execute
public function execute()
{
$wiki = $this->getOption('wikidb') ?: false;
// Get the appropriate load balancer (for this wiki)
if ($this->hasOption('cluster')) {
$lb = wfGetLBFactory()->getExternalLB($this->getOption('cluster'), $wiki);
} else {
$lb = wfGetLB($wiki);
}
// Figure out which server to use
if ($this->hasOption('slave')) {
$server = $this->getOption('slave');
if ($server === 'any') {
$index = DB_SLAVE;
} else {
$index = null;
for ($i = 0; $i < $lb->getServerCount(); ++$i) {
if ($lb->getServerName($i) === $server) {
$index = $i;
break;
}
}
if ($index === null) {
$this->error("No slave server configured with the name '{$server}'.", 1);
}
}
} else {
$index = DB_MASTER;
}
// Get a DB handle (with this wiki's DB selected) from the appropriate load balancer
$db = $lb->getConnection($index, array(), $wiki);
if ($this->hasOption('slave') && $db->getLBInfo('master') !== null) {
$this->error("The server selected ({$db->getServer()}) is not a slave.", 1);
}
if ($this->hasArg(0)) {
$file = fopen($this->getArg(0), 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $db->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
$newPrompt = '> ';
$prompt = $newPrompt;
while (($line = Maintenance::readconsole($prompt)) !== false) {
if (!$line) {
# User simply pressed return key
continue;
}
$done = $db->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
$wholeLine .= ' ';
$prompt = ' -> ';
continue;
}
if ($useReadline) {
# Delimiter is eated by streamStatementEnd, we add it
# up in the history (bug 37020)
readline_add_history($wholeLine . $db->getDelimiter());
readline_write_history($historyFile);
}
try {
$res = $db->query($wholeLine);
$this->sqlPrintResult($res, $db);
$prompt = $newPrompt;
$wholeLine = '';
} catch (DBQueryError $e) {
$doDie = !Maintenance::posix_isatty(0);
$this->error($e, $doDie);
}
}
wfWaitForSlaves();
}