1
0
mirror of https://github.com/php/php-src.git synced 2026-04-15 20:11:02 +02:00
Files
archived-php-src/ext/session/tests/save_handler.inc
Peter Kokot 03f3b8479b Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:51:01 +02:00

103 lines
3.0 KiB
PHP

<?php
DEFINE("SESSION_FILE_PREFIX" ,"session_test_");
function open($save_path, $session_name) {
global $session_save_path, $name;
$session_save_path = $save_path;
$name = $session_name;
echo "Open [${session_save_path},${session_name}]\n";
return true;
}
function close() {
global $session_save_path, $name;
echo "Close [${session_save_path},${name}]\n";
return true;
}
function read($id) {
global $session_save_path, $name, $session_id;
$session_id = $id;
echo "Read [${session_save_path},${id}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
// read MUST create file. Otherwise, strict mode will not work
touch($session_file);
return (string) @file_get_contents($session_file);
}
function write($id, $session_data) {
global $session_save_path, $name, $session_id;
$session_id = $id;
echo "Write [${session_save_path},${id},${session_data}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
if ($fp = fopen($session_file, "w")) {
$return = fwrite($fp, $session_data);
fclose($fp);
return $return === FALSE ? FALSE : TRUE;
}
return false;
}
function destroy($id) {
global $session_save_path, $name;
echo "Destroy [${session_save_path},${id}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
unlink($session_file);
return true;
}
function gc($maxlifetime) {
global $session_save_path, $name;
$directory = opendir($session_save_path."/");
$length = strlen(SESSION_FILE_PREFIX);
while (($file = readdir($directory)) !== FALSE) {
$qualified = ($session_save_path."/".$file);
if (is_file($qualified) === TRUE) {
if (substr($file, 0, $length) === SESSION_FILE_PREFIX && (filemtime($qualified) + $maxlifetime <= time() )) {
unlink($qualified);
}
}
}
closedir($directory);
return true;
}
function create_sid() {
$id = ('PHPT-'.time());
echo "CreateID [${id}]\n";
return $id;
}
function validate_sid($id) {
global $session_save_path, $name;
echo "ValidateID [${session_save_path},${id}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
$ret = file_exists($session_file);
return $ret;
}
function update($id, $session_data) {
global $session_save_path, $name;
echo "Update [${session_save_path},${id}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
$ret = touch($session_file);
return $ret;
}
function feature() {
/* NOT IMPLEMENTED YET */
/* TYPES: gc, create_sid, use_strict_mode, minizie_lock, lazy_write
/* VALUES: 0=unknown, 1=supported, 2=partially supported, 3=unsupported */
return array('gc'=>0,
'create_sid'=>1,
'use_strict_mode'=>2,
'minimize_lock'=>3,
'lazy_write'=>4,
'invalid'=>5,
'another invalid'=>6
);
}
?>