Skip to content

Commit d91c66c

Browse files
committed
replace INI setting php_sapi_name
1 parent 45646a5 commit d91c66c

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

defaults/config.ini.default

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ terms_of_service_url = "https://github.com" ; this can be external or a portal p
1515
account_policy_url = "https://github.com" ; this can be external or a portal page created with "content management"
1616
allow_die = true ; internal use only
1717
enable_verbose_error_log = true ; internal use only
18-
enable_error_to_user = true ; internal use only
1918
enable_exception_handler = true ; internal use only
2019
enable_error_handler = true ; internal use only
2120

deployment/overrides/phpunit/config/config.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ custom_user_mappings_dir = "test/custom_user_mappings"
44
[site]
55
allow_die = false
66
enable_verbose_error_log = false
7-
enable_error_to_user = false
87
enable_exception_handler = false
98
enable_error_handler = false
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
[site]
2-
enable_error_to_user = false

resources/lib/UnityHTTPD.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ public static function die(mixed $x = null, bool $show_user = false): never
3535
}
3636
}
3737

38+
/*
39+
send HTTP heaer, set HTTP response code,
40+
print a message just in case the browser fails to redirect if PHP is not being run from the CLI,
41+
and then die
42+
*/
3843
public static function redirect(?string $dest = null): never
3944
{
4045
$dest ??= pathJoin(CONFIG["site"]["prefix"], $_SERVER["REQUEST_URI"]);
4146
$dest = htmlspecialchars($dest);
4247
header("Location: $dest");
4348
http_response_code(302);
44-
if (CONFIG["site"]["enable_error_to_user"]) {
49+
if (php_sapi_name() !== "cli") {
4550
echo "If you're reading this message, then your browser has failed to redirect you " .
4651
"to the proper destination. click <a href='$dest'>here</a> to continue.";
4752
}
@@ -62,10 +67,13 @@ public static function errorID(?\Throwable $e = null): string
6267

6368
/*
6469
generates a unique error ID, writes to error log, and then:
65-
if the user is doing an HTTP POST:
70+
if PHP is being run in the CLI:
71+
prints a message to stdout and dies
72+
else, if the user is doing an HTTP POST:
6673
registers a message in the user's session and issues a redirect to display that message
6774
else:
68-
prints a message to stdout, sets an HTTP response code, and dies
75+
prints an HTML message to stdout, sets an HTTP response code, and dies
76+
we don't want HTML formatted output in the CLI
6977
we can't always do a redirect or else we could risk an infinite loop.
7078
*/
7179
public static function gracefulDie(
@@ -89,7 +97,9 @@ public static function gracefulDie(
8997
$user_message_body .= " $suffix";
9098
}
9199
self::errorLog($log_title, $log_message, data: $data, error: $error, errorid: $errorid);
92-
if ($_SERVER["REQUEST_METHOD"] ?? "" == "POST") {
100+
if (php_sapi_name() == "cli") {
101+
self::die("$user_message_title -- $user_message_body");
102+
} elseif ($_SERVER["REQUEST_METHOD"] ?? "" == "POST") {
93103
self::messageError($user_message_title, $user_message_body);
94104
self::redirect();
95105
} else {

0 commit comments

Comments
 (0)