Convert error handler function to callable
This commit is contained in:
parent
c7a615143e
commit
2314e685a3
|
@ -3,4 +3,4 @@
|
|||
[![PHPStan](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml)
|
||||
[![PHPMD](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml)
|
||||
|
||||
This is a collection of generic [Classes](https://www.php.net/manual/en/language.oop5.php), [Functions](https://www.php.net/manual/en/language.functions.php) and useful [Traits](https://www.php.net/manual/en/language.oop5.traits.php) for your PHP projects.
|
||||
This is a collection of generic [Classes](https://www.php.net/manual/en/language.oop5.php) and useful [Traits](https://www.php.net/manual/en/language.oop5.traits.php) for your PHP projects.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "opencultureconsulting/basics",
|
||||
"description": "This is a collection of generic Classes, Functions and useful Traits for PHP projects.",
|
||||
"description": "This is a collection of generic Classes and useful Traits for PHP projects.",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"ArrayAccess",
|
||||
|
@ -13,7 +13,7 @@
|
|||
"StrictList",
|
||||
"StrictQueue",
|
||||
"StrictStack",
|
||||
"throwErrorException"
|
||||
"ThrowErrorException"
|
||||
],
|
||||
"homepage": "https://github.com/opencultureconsulting/php-basics",
|
||||
"readme": "README.md",
|
||||
|
@ -37,7 +37,7 @@
|
|||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpstan/phpstan-strict-rules": "^1.5",
|
||||
"friendsofphp/php-cs-fixer": "^3.38"
|
||||
"friendsofphp/php-cs-fixer": "^3.41"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -20,17 +20,22 @@
|
|||
|
||||
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 <sebastian.meyer@opencultureconsulting.com>
|
||||
* @package opencultureconsulting/basics
|
||||
*/
|
||||
class ThrowErrorException
|
||||
{
|
||||
/**
|
||||
* Converts an internal PHP error into an ErrorException.
|
||||
*
|
||||
* @param int $severity The severity of the error
|
||||
* @param string $message The error message
|
||||
|
@ -41,10 +46,11 @@ use ErrorException;
|
|||
*
|
||||
* @throws ErrorException
|
||||
*/
|
||||
function throwErrorException(int $severity = E_USER_ERROR, string $message = '', ?string $file = null, ?int $line = null): bool
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue