From 90f6c8df16c16772e0e7029061cefd7d88772679 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 8 Jun 2019 13:07:16 +1000 Subject: [PATCH] Slimplify functions down as per Tim's review comments --- CRM/Utils/System.php | 3 +-- CRM/Utils/System/Base.php | 7 ++----- CRM/Utils/System/WordPress.php | 11 ++--------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 96bec632d6..d52e3d5ef4 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1867,8 +1867,7 @@ class CRM_Utils_System { * @param \Psr\Http\Message\ResponseInterface $response */ public static function sendResponse(\Psr\Http\Message\ResponseInterface $response) { - $config = CRM_Core_Config::singleton(); - $config->userSystem->sendResponse($response); + $config = CRM_Core_Config::singleton()->userSystem->sendResponse($response); } } diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 6bc5290ac9..e913fee17c 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -955,12 +955,9 @@ abstract class CRM_Utils_System_Base { // PHP 5.4+ http_response_code($response->getStatusCode()); } - else { - // @todo should we remove this given we are no longer supporting < PHP 5.6 however keeping - // in for the moment for compatability with the original AssetBuilder code. - header('X-PHP-Response-Code: ' . $response->getStatusCode(), TRUE, $reponse->getStatusCode()); + foreach ($response->getHeaders() as $name => $values) { + CRM_Utils_System::setHttpHeader($name, implode(', ', (array) $values)); } - CRM_Utils_System::setHttpHeader('Content-Type', $response->getHeaderLine('Content-Type')); echo $response->getBody(); CRM_Utils_System::civiExit(); } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 31ce2eccc9..a74e1e3de0 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -871,16 +871,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { public function sendResponse(\Psr\Http\Message\ResponseInterface $response) { // use WordPress function status_header to ensure 404 response is sent status_header($response->getStatusCode()); - if (function_exists('http_response_code')) { - // PHP 5.4+ - http_response_code($response->getStatusCode()); + foreach ($response->getHeaders() as $name => $values) { + CRM_Utils_System::setHttpHeader($name, implode(', ', (array) $values)); } - else { - // @todo should we remove this given we are no longer supporting < PHP 5.6 however keeping - // in for the moment for compatability with the original AssetBuilder code. - header('X-PHP-Response-Code: ' . $response->getStatusCode(), TRUE, $response->getStatusCode()); - } - CRM_Utils_System::setHttpHeader('Content-Type', $response->getHeaderLine('Content-Type')); echo $response->getBody(); CRM_Utils_System::civiExit(); } -- 2.25.1