mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
cli: allow to change ~/.php_history with PHP_HISTFILE
Closes GH-13313
This commit is contained in:
committed by
Ilija Tovilo
parent
7151855d67
commit
3f0b204f5a
@@ -246,6 +246,9 @@ PHP 8.4 UPGRADE NOTES
|
||||
. Added constant POSIX_SC_CHILD_MAX
|
||||
. Added constant POSIX_SC_CLK_TCK
|
||||
|
||||
- Readfile:
|
||||
. Added ability to change .php_history path through PHP_HISTFILE env variable.
|
||||
|
||||
- Reflection:
|
||||
. ReflectionAttribute now contains a $name property to improve the debugging
|
||||
experience.
|
||||
|
||||
@@ -617,7 +617,12 @@ static int readline_shell_run(void) /* {{{ */
|
||||
}
|
||||
|
||||
#ifndef PHP_WIN32
|
||||
history_file = tilde_expand("~/.php_history");
|
||||
const char *histfile_env_name = "PHP_HISTFILE";
|
||||
if (getenv(histfile_env_name)) {
|
||||
spprintf(&history_file, MAXPATHLEN, "%s", getenv(histfile_env_name));
|
||||
} else {
|
||||
spprintf(&history_file, MAXPATHLEN, "%s/.php_history", getenv("HOME"));
|
||||
}
|
||||
#else
|
||||
spprintf(&history_file, MAX_PATH, "%s/.php_history", getenv("USERPROFILE"));
|
||||
#endif
|
||||
@@ -717,11 +722,7 @@ static int readline_shell_run(void) /* {{{ */
|
||||
|
||||
php_last_char = '\0';
|
||||
}
|
||||
#ifdef PHP_WIN32
|
||||
efree(history_file);
|
||||
#else
|
||||
free(history_file);
|
||||
#endif
|
||||
efree(code);
|
||||
zend_string_release_ex(prompt, 0);
|
||||
return EG(exit_status);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
CLI -a and libedit
|
||||
--EXTENSIONS--
|
||||
readline
|
||||
--ENV--
|
||||
PHP_HISTFILE=
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include "skipif.inc";
|
||||
@@ -11,9 +13,18 @@ if (readline_info('done') !== NULL) {
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
|
||||
$ini = getenv('TEST_PHP_EXTRA_ARGS');
|
||||
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
|
||||
function runReplCodes($codes) {
|
||||
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
|
||||
$ini = getenv('TEST_PHP_EXTRA_ARGS');
|
||||
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
|
||||
foreach ($codes as $key => $code) {
|
||||
echo "\n--------------\nSnippet no. $key:\n--------------\n";
|
||||
$proc = proc_open("$php $ini -a", $descriptorspec, $pipes);
|
||||
fwrite($pipes[0], $code);
|
||||
fclose($pipes[0]);
|
||||
proc_close($proc);
|
||||
}
|
||||
}
|
||||
|
||||
$codes = array();
|
||||
|
||||
@@ -52,17 +63,26 @@ function a_function_with_some_name() {
|
||||
a_function_w );
|
||||
EOT;
|
||||
|
||||
foreach ($codes as $key => $code) {
|
||||
echo "\n--------------\nSnippet no. $key:\n--------------\n";
|
||||
$proc = proc_open("$php $ini -a", $descriptorspec, $pipes);
|
||||
fwrite($pipes[0], $code);
|
||||
fclose($pipes[0]);
|
||||
proc_close($proc);
|
||||
}
|
||||
|
||||
runReplCodes($codes);
|
||||
echo "\nDone\n";
|
||||
|
||||
$dir = PHP_OS_FAMILY == 'Windows' ? getenv("USERPROFILE") : getenv("HOME");
|
||||
var_dump(file_exists($dir . '/.php_history'));
|
||||
|
||||
$php_history_tmp = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'php_history');
|
||||
putenv('PHP_HISTFILE=' . $php_history_tmp);
|
||||
var_dump(file_exists($php_history_tmp));
|
||||
|
||||
$last[6] = <<<EOT
|
||||
echo 'Hello World';
|
||||
exit
|
||||
EOT;
|
||||
runReplCodes($last);
|
||||
echo "\nDone\n";
|
||||
|
||||
$php_history_path = PHP_OS_FAMILY == 'Windows' ? getenv("USERPROFILE") : $php_history_tmp;
|
||||
var_dump(file_exists($php_history_path));
|
||||
@unlink($php_history_tmp);
|
||||
?>
|
||||
--EXPECT--
|
||||
--------------
|
||||
@@ -108,3 +128,14 @@ Parse error: Unmatched ')' in php shell code on line 1
|
||||
|
||||
Done
|
||||
bool(true)
|
||||
bool(false)
|
||||
|
||||
--------------
|
||||
Snippet no. 6:
|
||||
--------------
|
||||
Interactive shell
|
||||
|
||||
Hello World
|
||||
|
||||
Done
|
||||
bool(true)
|
||||
|
||||
Reference in New Issue
Block a user