X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSystem.php;h=10fc5c7d4e335e6cdc725affb1672f93c572ea8d;hb=f6167b4cfd36ca4d7a44d501509627ca8989f6b1;hp=de0c80b3de7f96530bdbf59ae34214f2305745db;hpb=ff83c170a64fab2aa1d25a4b6a45786539dd397e;p=friendica.git diff --git a/src/Core/System.php b/src/Core/System.php index de0c80b3de..10fc5c7d4e 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -295,7 +295,7 @@ class System DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml)); DI::page()->exit(DI::apiResponse()->generate()); - exit(); + self::exit(); } /** @@ -306,25 +306,42 @@ class System * @param string $content Response body. Optional. * @throws \Exception */ - public static function httpExit($val, $message = '', $content = '') + public static function httpError($httpCode, $message = '', $content = '') { - if ($val >= 400) { - Logger::debug('Exit with error', ['code' => $val, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + if ($httpCode >= 400) { + Logger::debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); } - DI::apiResponse()->setStatus($val, $message); + DI::apiResponse()->setStatus($httpCode, $message); DI::apiResponse()->addContent($content); DI::page()->exit(DI::apiResponse()->generate()); - exit(); + self::exit(); } - public static function jsonError($httpCode, $data, $content_type = 'application/json') + /** + * This function adds the content and a content-teype HTTP header to the output. + * After finishing the process is getting killed. + * + * @param string $content + * @param [type] $responce + * @param string|null $content_type + * @return void + */ + public static function httpExit(string $content, string $responce = Response::TYPE_HTML, ?string $content_type = null) { + DI::apiResponse()->setType($responce, $content_type); + DI::apiResponse()->addContent($content); + DI::page()->exit(DI::apiResponse()->generate()); + + self::exit(); + } + + public static function jsonError($httpCode, $content, $content_type = 'application/json') { if ($httpCode >= 400) { Logger::debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); } DI::apiResponse()->setStatus($httpCode); - self::jsonExit($data, $content_type); + self::jsonExit($content, $content_type); } /** @@ -334,14 +351,25 @@ class System * and adds an application/json HTTP header to the output. * After finishing the process is getting killed. * - * @param mixed $x The input content. - * @param string $content_type Type of the input (Default: 'application/json'). - * @param integer $options JSON options + * @param mixed $content The input content + * @param string $content_type Type of the input (Default: 'application/json') + * @param integer $options JSON options + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function jsonExit($x, $content_type = 'application/json', int $options = 0) { + public static function jsonExit($content, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) { DI::apiResponse()->setType(Response::TYPE_JSON, $content_type); - DI::apiResponse()->addContent(json_encode($x, $options)); + DI::apiResponse()->addContent(json_encode($content, $options)); DI::page()->exit(DI::apiResponse()->generate()); + + self::exit(); + } + + /** + * Exit the program execution. + */ + public static function exit() + { + DI::page()->logRuntime(); exit(); } @@ -431,8 +459,7 @@ class System case 307: throw new TemporaryRedirectException(); } - - exit(); + self::exit(); } /** @@ -505,7 +532,7 @@ class System echo str_replace("\t", " ", $o); echo ""; echo "\r\n"; - exit(); + self::exit(); } /**