Skip to content

Commit

Permalink
Add preparation for strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Nox committed Jul 9, 2022
1 parent c9fcad3 commit 77c30ff
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions backend/class/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 77c30ff

Please sign in to comment.