-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Nox
committed
Jul 9, 2022
1 parent
c9fcad3
commit 77c30ff
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,31 +10,34 @@ | |
use noxkiwi\core\Helper\WebHelper; | ||
use noxkiwi\core\Interfaces\AppInterface; | ||
use noxkiwi\core\Response\HttpResponse; | ||
use noxkiwi\core\Traits\HookTrait; | ||
use noxkiwi\core\Traits\LanguageImprovementTrait; | ||
use noxkiwi\hook\Hook; | ||
use noxkiwi\log\Traits\LogTrait; | ||
use noxkiwi\singleton\Singleton; | ||
use ReflectionClass; | ||
use function explode; | ||
use function headers_sent; | ||
use function is_string; | ||
use function ucfirst; | ||
use const E_ERROR; | ||
|
||
/** | ||
* I am the "class" everyone wants to have but won't ever have. | ||
* - pun intended | ||
* I am the main class that processes Requests. | ||
* I will >run and do everything in that call. | ||
* | ||
* @package noxkiwi\core | ||
* @author Jan Nox <[email protected]> | ||
* @license https://nox.kiwi/license | ||
* @copyright 2016 - 2021 noxkiwi | ||
* @version 1.0.15 | ||
* @copyright 2016 - 2022 noxkiwi | ||
* @version 1.0.16 | ||
* @link https://nox.kiwi/ | ||
*/ | ||
abstract class App extends Singleton implements AppInterface | ||
{ | ||
use LogTrait; | ||
use LanguageImprovementTrait; | ||
use HookTrait; | ||
|
||
/** @var string I am the called App's vendor. */ | ||
private static string $vendor; | ||
|
@@ -170,4 +173,25 @@ private static function getTemplate(): string | |
|
||
return Application::getInstance()->get('defaulttemplate', 'blank'); | ||
} | ||
|
||
/** | ||
* I will solely put the output buffer into a variable and check if the ErrorHandler | ||
* had to deal with Exceptions or Errors during the request. | ||
* If any occured, I'll send 500, if not, I'll send 200. | ||
*/ | ||
#[NoReturn] public function __destruct() | ||
{ | ||
if (headers_sent()) { | ||
return; | ||
} | ||
$output = ob_get_clean(); | ||
if (! ErrorHandler::$errorsReported) { | ||
header('HTTP/1.1 200 Okay'); | ||
echo $output; | ||
exit(WebHelper::HTTP_OKAY); | ||
} | ||
header('HTTP/1.1 500 Server Error'); | ||
echo $output; | ||
exit(WebHelper::HTTP_SERVER_ERROR); | ||
} | ||
} |