* @method static array synchronizeUsers() Create CRM contacts for all existing CMS users.
* @method static appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_coreResourceList.
* @method static alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_getAssetUrl.
+ * @method static sendResponse(array $responseData) function to set HTTP status response and return specific response to client initially for assetBuilder content.
*/
class CRM_Utils_System {
return NULL;
}
+ /**
+ * Return an HTTP Response with appropriate content and status code set.
+ * @param array $responseData
+ */
+ public static function sendResponse($responseData) {
+ $config = CRM_Core_Config::singleton();
+ if (!empty($responseData['statusCode'])) {
+ $config->userSystem->setStatusCode($responseData['statusCode']);
+ }
+ if (!empty($responseData['mimeType'])) {
+ self::setHttpHeader('Content-Type', $responseData['mimeType']);
+ }
+ echo $responseData['content'];
+ self::civiExit();
+ }
+
}
return [];
}
+ /**
+ * Set the HTTP Status Code for a request
+ * @param string $statusCode
+ */
+ public function setStatusCode($statusCode) {
+ if (function_exists('http_response_code')) {
+ // PHP 5.4+
+ http_response_code($statusCode);
+ }
+ else {
+ header('X-PHP-Response-Code: ' . $statusCode, TRUE, $statusCode);
+ }
+ }
+
}
];
}
+ /**
+ * Set the HTTP Status Code for a request
+ * @param string $statusCode
+ */
+ public function setStatusCode($statusCode) {
+ status_header($statusCode);
+ if (function_exists('http_response_code')) {
+ // PHP 5.4+
+ http_response_code($statusCode);
+ }
+ else {
+ header('X-PHP-Response-Code: ' . $statusCode, TRUE, $statusCode);
+ }
+ }
+
}
public static function pageRun() {
// Beg your pardon, sir. Please may I have an HTTP response class instead?
$asset = self::pageRender($_GET);
- if (function_exists('http_response_code')) {
- // PHP 5.4+
- http_response_code($asset['statusCode']);
- }
- else {
- header('X-PHP-Response-Code: ' . $asset['statusCode'], TRUE, $asset['statusCode']);
- }
-
- header('Content-Type: ' . $asset['mimeType']);
- echo $asset['content'];
- \CRM_Utils_System::civiExit();
+ \CRM_Utils_System::sendResponse($asset);
}
/**