/
JobErrorHandler.php
46 lines (39 loc) · 1.03 KB
/
JobErrorHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Symbiote\QueuedJobs\Services;
use Exception;
use SilverStripe\Core\Injector\Injectable;
/**
* Class used to handle errors for a single job
*/
class JobErrorHandler
{
use Injectable;
public function __construct()
{
set_error_handler(array($this, 'handleError'));
}
public function clear()
{
restore_error_handler();
}
public function handleError($errno, $errstr, $errfile, $errline)
{
if (error_reporting()) {
// Don't throw E_DEPRECATED in PHP 5.3+
if (defined('E_DEPRECATED')) {
if ($errno == E_DEPRECATED || $errno == E_USER_DEPRECATED) {
return;
}
}
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
case E_STRICT:
break;
default:
throw new Exception($errstr . " in $errfile at line $errline", $errno);
break;
}
}
}
}