Skip to content

Commit fcb5437

Browse files
committed
add option to disable shutdown message, move globals to config
1 parent e1003ce commit fcb5437

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

defaults/config.ini.default

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ description = "The Unity Web Portal is a lightweight HPC cluster front-end" ; D
1313
logo = "logo.png" ; path to logo file, in the webroot/assets/branding folder
1414
terms_of_service_url = "https://github.com" ; this can be external or a portal page created with "content management"
1515
account_policy_url = "https://github.com" ; this can be external or a portal page created with "content management"
16+
allow_die = true ; internal use only
17+
enable_verbose_error_log = true ; internal use only
18+
enable_shutdown_msg = true ; internal use only
1619

1720
[ldap]
1821
uri = "ldap://identity" ; URI of remote LDAP server
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[ldap]
22
custom_user_mappings_dir = "test/custom_user_mappings"
3+
4+
[site]
5+
allow_die = false
6+
enable_verbose_error_log = false
7+
enable_shutdown_message = false

resources/lib/UnityConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class UnityConfig
66
{
77
public static function getConfig($def_config_loc, $deploy_loc)
88
{
9-
$CONFIG = parse_ini_file($def_config_loc . "/config.ini.default", true);
9+
$CONFIG = parse_ini_file($def_config_loc . "/config.ini.default", true, INI_SCANNER_TYPED);
1010
$CONFIG = self::pullConfig($CONFIG, $deploy_loc);
1111
if (array_key_exists("HTTP_HOST", $_SERVER)) {
1212
$cur_url = $_SERVER['HTTP_HOST'];
@@ -22,7 +22,7 @@ private static function pullConfig($CONFIG, $loc)
2222
{
2323
$file_loc = $loc . "/config/config.ini";
2424
if (file_exists(($file_loc))) {
25-
$CONFIG_override = parse_ini_file($file_loc, true);
25+
$CONFIG_override = parse_ini_file($file_loc, true, INI_SCANNER_TYPED);
2626
return array_replace_recursive($CONFIG, $CONFIG_override);
2727
} else {
2828
return $CONFIG;

resources/lib/UnitySite.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class UnitySite
99
{
1010
public static function die($x = null, $show_user = false)
1111
{
12-
if (isset($GLOBALS["PHPUNIT_NO_DIE_PLEASE"]) && $GLOBALS["PHPUNIT_NO_DIE_PLEASE"] == true) {
12+
if (CONFIG["site"]["allow_die"] == false) {
1313
if (is_null($x)) {
1414
throw new PhpUnitNoDieException();
1515
} else {
@@ -39,7 +39,7 @@ private static function headerResponseCode(int $code, string $reason)
3939

4040
public static function errorLog(string $title, string $message)
4141
{
42-
if (@$GLOBALS["PHPUNIT_SIMPLE_ERROR_LOG_PLEASE"] == true) {
42+
if (CONFIG["site"]["enable_verbose_error_log"] == false) {
4343
error_log("$title: $message");
4444
return;
4545
}
@@ -74,6 +74,9 @@ public static function forbidden($message)
7474
// https://www.php.net/manual/en/function.register-shutdown-function.php
7575
public static function shutdown()
7676
{
77+
if (CONFIG["site"]["enable_shutdown_msg"] == false) {
78+
return;
79+
}
7780
if (!is_null($e = error_get_last())) {
7881
if (!headers_sent()) {
7982
self::headerResponseCode(500, "internal server error");

test/phpunit-bootstrap.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
3-
require_once __DIR__ . "/../vendor/autoload.php";
4-
52
// submodule
63
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
74
require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
@@ -14,14 +11,15 @@
1411
require_once __DIR__ . "/../resources/lib/UnityMailer.php";
1512
require_once __DIR__ . "/../resources/lib/UnitySSO.php";
1613
require_once __DIR__ . "/../resources/lib/UnitySite.php";
14+
require_once __DIR__ . "/../resources/lib/UnityConfig.php";
1715
require_once __DIR__ . "/../resources/lib/UnityWebhook.php";
1816
require_once __DIR__ . "/../resources/lib/UnityRedis.php";
1917
require_once __DIR__ . "/../resources/lib/UnityGithub.php";
2018
require_once __DIR__ . "/../resources/lib/exceptions/PhpUnitNoDieException.php";
2119
require_once __DIR__ . "/../resources/lib/exceptions/SSOException.php";
2220

23-
$GLOBALS["PHPUNIT_NO_DIE_PLEASE"] = true;
24-
$GLOBALS["PHPUNIT_SIMPLE_ERROR_LOG_PLEASE"] = true;
21+
$_SERVER["HTTP_HOST"] = "phpunit"; // used for config override
22+
require_once __DIR__ . "/../resources/config.php";
2523

2624
global $HTTP_HEADER_TEST_INPUTS;
2725
$HTTP_HEADER_TEST_INPUTS = [

0 commit comments

Comments
 (0)