-
-
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.
Convert error handler function to callable
- Loading branch information
1 parent
c7a6151
commit 2314e68
Showing
3 changed files
with
26 additions
and
20 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
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 |
---|---|---|
|
@@ -20,31 +20,37 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace OCC\Basics\Functions; | ||
namespace OCC\Basics\ErrorHandlers; | ||
|
||
use ErrorException; | ||
|
||
/** | ||
* Converts an internal PHP error into an ErrorException. | ||
* Throw internal errors as exceptions. | ||
* | ||
* Usage: set_error_handler('\\OCC\\Basics\\Functions\\throwErrorException'); | ||
* Usage: set_error_handler(new ThrowErrorException()); | ||
* | ||
* @author Sebastian Meyer <[email protected]> | ||
* @package opencultureconsulting/basics | ||
* | ||
* @param int $severity The severity of the error | ||
* @param string $message The error message | ||
* @param ?string $file The name of the file the error was raised in | ||
* @param ?int $line The line number the error was raised in | ||
* | ||
* @return bool Always returns FALSE when not throwing an exception | ||
* | ||
* @throws ErrorException | ||
*/ | ||
function throwErrorException(int $severity = E_USER_ERROR, string $message = '', ?string $file = null, ?int $line = null): bool | ||
class ThrowErrorException | ||
{ | ||
if ((error_reporting() & $severity) > 0) { | ||
throw new ErrorException($message, 0, $severity, $file, $line); | ||
/** | ||
* Converts an internal PHP error into an ErrorException. | ||
* | ||
* @param int $severity The severity of the error | ||
* @param string $message The error message | ||
* @param ?string $file The name of the file the error was raised in | ||
* @param ?int $line The line number the error was raised in | ||
* | ||
* @return bool Always returns FALSE when not throwing an exception | ||
* | ||
* @throws ErrorException | ||
*/ | ||
public function __invoke(int $severity = E_USER_ERROR, string $message = '', ?string $file = null, ?int $line = null): bool | ||
{ | ||
if ((error_reporting() & $severity) > 0) { | ||
throw new ErrorException($message, 0, $severity, $file, $line); | ||
} | ||
return false; | ||
} | ||
return false; | ||
} |