-
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.
Added developer setting to show error messages in production mode
Fixes #51
- Loading branch information
1 parent
cd9e59a
commit 5841689
Showing
14 changed files
with
105 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Framework\Authentication\Auth; | ||
use Framework\Facades\DeveloperTools; | ||
use Framework\Facades\Http; | ||
use Framework\Routing\BaseController; | ||
use Framework\Routing\ControllerInterface; | ||
|
||
class DeveloperToolsController extends BaseController implements ControllerInterface | ||
{ | ||
public function execute(): void | ||
{ | ||
Auth::checkRole('Developer'); | ||
|
||
if (Http::requestMethod() === 'GET') { | ||
view('settings.devTools'); | ||
return; | ||
} | ||
|
||
if (Http::requestMethod() === 'POST') { | ||
DeveloperTools::setShowErrorMessages(Http::param('showErrorMessages') === '1'); | ||
|
||
Http::redirect('/'); | ||
} | ||
|
||
Http::redirect('/'); | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<?php | ||
|
||
use Framework\Error\ErrorHandler; | ||
use Framework\Facades\DeveloperTools; | ||
use Framework\Facades\Env; | ||
|
||
set_error_handler(fn(int $errno, string $errstr, ?string $errfile = null, ?int $errline = null, ?array $errcontext = null) => ErrorHandler::handleError($errno, $errstr, $errfile, $errline, $errcontext)); | ||
|
||
set_exception_handler(fn(Throwable $exception) => ErrorHandler::handleException($exception)); | ||
|
||
if (Env::isDev()) { | ||
if (Env::isDev() || DeveloperTools::showErrorMessages()) { | ||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Framework\Facades; | ||
|
||
use Framework\Authentication\Auth; | ||
use Framework\Authentication\Session; | ||
|
||
class DeveloperTools | ||
{ | ||
public static function showErrorMessages(): bool | ||
{ | ||
if (!Auth::hasRole('Developer')) { | ||
return false; | ||
} | ||
|
||
return Session::getValue('showErrorMessages') === 'true'; | ||
} | ||
|
||
public static function setShowErrorMessages(bool $value): void | ||
{ | ||
if (!Auth::hasRole('Developer')) { | ||
return; | ||
} | ||
|
||
if ($value) { | ||
Session::setValue('showErrorMessages', 'true'); | ||
} else { | ||
Session::setValue('showErrorMessages', null); | ||
} | ||
} | ||
} |
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
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
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
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
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?php | ||
use Framework\Authentication\Auth; | ||
use Framework\Facades\Convert; | ||
?> | ||
<?= component('layout.header') ?> | ||
|
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php use Framework\Authentication\Session; ?> | ||
<?= component('layout.header') ?> | ||
|
||
<h1><?= __('DeveloperTools') ?></h1> | ||
|
||
<form method="post"> | ||
<label> | ||
<input type="hidden" name="showErrorMessages" value="0"> | ||
<input type="checkbox" name="showErrorMessages" value="1" | ||
<?php if (Session::getValue('showErrorMessages') === 'true') { | ||
echo ' checked'; | ||
} ?>> | ||
<?= __('ShowErrorMessages') ?> | ||
</label><br> | ||
|
||
<button><?= __('Save') ?></button> | ||
</form> | ||
|
||
<?= component('layout.footer') ?> |