Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/console/plugin/errorlog/DarkConsoleErrorLogPluginAPI.php
13409 views
1
<?php
2
3
final class DarkConsoleErrorLogPluginAPI extends Phobject {
4
5
private static $errors = array();
6
7
private static $discardMode = false;
8
9
public static function registerErrorHandler() {
10
// NOTE: This forces PhutilReadableSerializer to load, so that we are
11
// able to handle errors which fire from inside autoloaders (PHP will not
12
// reenter autoloaders).
13
PhutilReadableSerializer::printableValue(null);
14
PhutilErrorHandler::setErrorListener(
15
array(__CLASS__, 'handleErrors'));
16
}
17
18
public static function enableDiscardMode() {
19
self::$discardMode = true;
20
}
21
22
public static function disableDiscardMode() {
23
self::$discardMode = false;
24
}
25
26
public static function getErrors() {
27
return self::$errors;
28
}
29
30
public static function handleErrors($event, $value, $metadata) {
31
if (self::$discardMode) {
32
return;
33
}
34
35
switch ($event) {
36
case PhutilErrorHandler::EXCEPTION:
37
// $value is of type Exception
38
self::$errors[] = array(
39
'details' => $value->getMessage(),
40
'event' => $event,
41
'file' => $value->getFile(),
42
'line' => $value->getLine(),
43
'str' => $value->getMessage(),
44
'trace' => $metadata['trace'],
45
);
46
break;
47
case PhutilErrorHandler::ERROR:
48
// $value is a simple string
49
self::$errors[] = array(
50
'details' => $value,
51
'event' => $event,
52
'file' => $metadata['file'],
53
'line' => $metadata['line'],
54
'str' => $value,
55
'trace' => $metadata['trace'],
56
);
57
break;
58
case PhutilErrorHandler::PHLOG:
59
// $value can be anything
60
self::$errors[] = array(
61
'details' => PhutilReadableSerializer::printShallow($value, 3),
62
'event' => $event,
63
'file' => $metadata['file'],
64
'line' => $metadata['line'],
65
'str' => PhutilReadableSerializer::printShort($value),
66
'trace' => $metadata['trace'],
67
);
68
break;
69
default:
70
error_log(pht('Unknown event: %s', $event));
71
break;
72
}
73
}
74
75
}
76
77