1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* DronePHP (http://www.dronephp.com) |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/Pleets/DronePHP |
6
|
|
|
* @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) |
7
|
|
|
* @license http://www.dronephp.com/license |
8
|
|
|
* @author Darío Rivera <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Drone\Error; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ErrorHandler class |
15
|
|
|
* |
16
|
|
|
* This class handles errors with user defined functions |
17
|
|
|
*/ |
18
|
|
|
class ErrorHandler |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Handles errors and transform it to exceptions |
22
|
|
|
* |
23
|
|
|
* @param integer $errno |
24
|
|
|
* @param string $errstr |
25
|
|
|
* @param string $errfile |
26
|
|
|
* @param integer $errline |
27
|
|
|
* |
28
|
|
|
* @throws RuntimeException |
29
|
|
|
* |
30
|
|
|
* @return null|boolean |
31
|
|
|
*/ |
32
|
|
|
public static function toException($errno, $errstr, $errfile, $errline) |
33
|
|
|
{ |
34
|
|
|
if (!(error_reporting() & $errno)) { |
35
|
|
|
// This error code is not included in error_reporting, so let it fall |
36
|
|
|
// through to the standard PHP error handler |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
throw new \RuntimeException( |
41
|
|
|
"<strong>Error:</strong> $errstr in <strong>$errfile</strong> on line <strong>$errline</strong>" |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Better way to use the error-control operator @ |
47
|
|
|
* |
48
|
|
|
* By default @ operator hides Fatal errors (Ex: Maximum time execution). |
49
|
|
|
* The errorControlOperator could be setted as handler with set_error_handler($callable $e, E_ALL) |
50
|
|
|
* and it takes the same behavior of @, but it does not ignore Fatal errors. |
51
|
|
|
* |
52
|
|
|
* @param integer $errno |
53
|
|
|
* @param string $errstr |
54
|
|
|
* @param string $errfile |
55
|
|
|
* @param integer $errline |
56
|
|
|
* |
57
|
|
|
* @return null|boolean |
58
|
|
|
*/ |
59
|
12 |
|
public static function errorControlOperator($errno, $errstr, $errfile, $errline) |
|
|
|
|
60
|
|
|
{ |
61
|
12 |
|
if (!(error_reporting() & $errno)) { |
62
|
|
|
// This error code is not included in error_reporting, so let it fall |
63
|
|
|
// through to the standard PHP error handler |
64
|
2 |
|
return false; |
65
|
|
|
} |
66
|
10 |
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.