From e7dd96b5d9c43c57285797b12b8e40e566070587 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 20 Jan 2025 20:27:03 +0900 Subject: [PATCH] Further fixes for PHP 8.4 --- .../AAASetupData/requests/http_requests.php | 4 +- .../CoreLibsUrlRequestsCurlTest.php | 87 +++++++++++++------ www/admin/UrlRequests.target.php | 4 +- www/configs/config.master.php | 4 +- www/lib/CoreLibs/Admin/EditBase.php | 2 +- www/lib/CoreLibs/DB/IO.php | 2 +- 6 files changed, 68 insertions(+), 35 deletions(-) diff --git a/4dev/tests/AAASetupData/requests/http_requests.php b/4dev/tests/AAASetupData/requests/http_requests.php index 912d715f..9523a60d 100644 --- a/4dev/tests/AAASetupData/requests/http_requests.php +++ b/4dev/tests/AAASetupData/requests/http_requests.php @@ -48,7 +48,7 @@ header("Content-Type: application/json; charset=UTF-8"); if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) { header("HTTP/1.1 401 Unauthorized"); print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}'); - exit; + exit(1); } // if server request type is get set file_get to null -> no body @@ -57,7 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { } elseif (($file_get = file_get_contents('php://input')) === false) { header("HTTP/1.1 404 Not Found"); print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}'); - exit; + exit(1); } print buildContent($http_headers, $file_get); diff --git a/4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php b/4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php index 276b2ef6..77077b71 100644 --- a/4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php +++ b/4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php @@ -969,44 +969,77 @@ final class CoreLibsUrlRequestsCurlTest extends TestCase "query" => ["foo-get" => "bar"] ]); $this->assertEquals("200", $response["code"], "multi call: get response code not matching"); - $this->assertEquals( - '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' - . '"HTTP_FIRST_CALL":"get","HTTP_ACCEPT":"*\/*",' - . '"HTTP_HOST":"soba.egplusww.jp"},' - . '"REQUEST_TYPE":"GET",' - . '"PARAMS":{"foo-get":"bar"},"BODY":null}', - $response['content'], - 'multi call: get content not matching' - ); + print "PHP: " . PHP_VERSION_ID . "\n"; + if (PHP_VERSION_ID >= 80400) { + $this->assertEquals( + '{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",' + . '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1","HTTP_FIRST_CALL":"get",' + . '"HTTP_ACCEPT":"*\/*"},"REQUEST_TYPE":"GET","PARAMS":{"foo-get":"bar"},"BODY":null}', + $response['content'], + 'multi call: get content not matching' + ); + } else { + $this->assertEquals( + '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' + . '"HTTP_FIRST_CALL":"get","HTTP_ACCEPT":"*\/*",' + . '"HTTP_HOST":"soba.egplusww.jp"},' + . '"REQUEST_TYPE":"GET",' + . '"PARAMS":{"foo-get":"bar"},"BODY":null}', + $response['content'], + 'multi call: get content not matching' + ); + } // post $response = $curl->post($this->url_basic, [ "headers" => ["second-call" => "post"], "body" => ["foo-post" => "baz"] ]); $this->assertEquals("200", $response["code"], "multi call: post response code not matching"); - $this->assertEquals( - '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' - . '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*",' - . '"HTTP_HOST":"soba.egplusww.jp"},' - . '"REQUEST_TYPE":"POST",' - . '"PARAMS":[],"BODY":{"foo-post":"baz"}}', - $response['content'], - 'multi call: post content not matching' - ); + if (PHP_VERSION_ID >= 80400) { + $this->assertEquals( + '{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",' + . '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' + . '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*"},' + . '"REQUEST_TYPE":"POST","PARAMS":[],"BODY":{"foo-post":"baz"}}', + $response['content'], + 'multi call: post content not matching' + ); + } else { + $this->assertEquals( + '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' + . '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*",' + . '"HTTP_HOST":"soba.egplusww.jp"},' + . '"REQUEST_TYPE":"POST",' + . '"PARAMS":[],"BODY":{"foo-post":"baz"}}', + $response['content'], + 'multi call: post content not matching' + ); + } // delete $response = $curl->delete($this->url_basic, [ "headers" => ["third-call" => "delete"], ]); $this->assertEquals("200", $response["code"], "multi call: delete response code not matching"); - $this->assertEquals( - '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' - . '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*",' - . '"HTTP_HOST":"soba.egplusww.jp"},' - . '"REQUEST_TYPE":"DELETE",' - . '"PARAMS":[],"BODY":[]}', - $response['content'], - 'multi call: delete content not matching' - ); + if (PHP_VERSION_ID >= 80400) { + $this->assertEquals( + '{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",' + . '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' + . '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*"},' + . '"REQUEST_TYPE":"DELETE","PARAMS":[],"BODY":[]}', + $response['content'], + 'multi call: delete content not matching' + ); + } else { + $this->assertEquals( + '{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",' + . '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*",' + . '"HTTP_HOST":"soba.egplusww.jp"},' + . '"REQUEST_TYPE":"DELETE",' + . '"PARAMS":[],"BODY":[]}', + $response['content'], + 'multi call: delete content not matching' + ); + } } // MARK: auth header set via config diff --git a/www/admin/UrlRequests.target.php b/www/admin/UrlRequests.target.php index 3d310ff4..d74e32e8 100644 --- a/www/admin/UrlRequests.target.php +++ b/www/admin/UrlRequests.target.php @@ -52,7 +52,7 @@ header("Content-Type: application/json; charset=UTF-8"); if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) { header("HTTP/1.1 401 Unauthorized"); print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}'); - exit; + exit(1); } // if server request type is get set file_get to null -> no body @@ -61,7 +61,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { } elseif (($file_get = file_get_contents('php://input')) === false) { header("HTTP/1.1 404 Not Found"); print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}'); - exit; + exit(1); } // str_replace('\"', '"', trim($file_get, '"')); diff --git a/www/configs/config.master.php b/www/configs/config.master.php index 9d5b9985..c30e86b0 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -184,7 +184,7 @@ define('HOST_NAME', $HOST_NAME); // BAIL ON MISSING MASTER SITE CONFIG if (!isset($SITE_CONFIG[HOST_NAME]['location'])) { echo 'Missing SITE_CONFIG entry for: "' . HOST_NAME . '". Contact Administrator'; - exit; + exit(1); } // BAIL ON MISSING DB CONFIG: // we have either no db selction for this host but have db config entries @@ -201,7 +201,7 @@ if ( ) ) { echo 'No matching DB config found for: "' . HOST_NAME . '". Contact Administrator'; - exit; + exit(1); } // set SSL on $is_secure = false; diff --git a/www/lib/CoreLibs/Admin/EditBase.php b/www/lib/CoreLibs/Admin/EditBase.php index 20312b52..754c33b5 100644 --- a/www/lib/CoreLibs/Admin/EditBase.php +++ b/www/lib/CoreLibs/Admin/EditBase.php @@ -76,7 +76,7 @@ class EditBase ); if ($this->form->mobile_phone) { echo "I am sorry, but this page cannot be viewed by a mobile phone"; - exit; + exit(1); } // $this->log->debug('POST', $this->log->prAr($_POST)); } diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 038f32d8..85a4e897 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -500,7 +500,7 @@ class IO die(''); } // write to internal one, once OK - $this->db_functions = $db_functions; + $this->db_functions = $db_functions; /** @phan-suppress-current-line PhanPossiblyNullTypeMismatchProperty */ // connect to DB if (!$this->__connectToDB()) {