-
Notifications
You must be signed in to change notification settings - Fork 6
/
ErrorHandler.php
75 lines (69 loc) · 1.4 KB
/
ErrorHandler.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* vipnytt/RobotsTxtParser
*
* @link https://github.com/VIPnytt/RobotsTxtParser
* @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT)
*/
namespace vipnytt\RobotsTxtParser\Handler;
/**
* Class ErrorHandler
*
* @package vipnytt\RobotsTxtParser\Handler
*/
class ErrorHandler
{
/**
* Error log
* @var string[]
*/
protected $log = [];
/**
* ErrorHandler constructor.
*/
public function __construct()
{
}
/**
* Callback
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return bool
*/
public function callback($errno, $errstr, $errfile = '', $errline = 0, $errcontext = [])
{
$this->log[(string)microtime(true)] = [
'no' => $errno,
'str' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext,
];
return $this->handle();
}
/**
* Handle
*
* @return bool
*/
private function handle()
{
return !in_array(end($this->log)['no'], [
E_ERROR,
E_USER_ERROR,
]);
}
/**
* Last error as string
*
* @return array|false
*/
public function getLast()
{
return end($this->log);
}
}