Helper.php
1.1 KB
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
<?php
namespace Lackoxygen\ExceptionPush;
use Lackoxygen\ExceptionPush\Agents\Ding;
use Lackoxygen\ExceptionPush\Agents\Wx;
use Lackoxygen\ExceptionPush\Handler\MonologHandler;
use Monolog\Logger;
if (!function_exists('closure')) {
function closure($closure): ?\Closure
{
if (is_array($closure) && 2 === count($closure)) {
[$class, $method] = $closure;
return function () use ($class, $method) {
$handler = new $class();
return call_user_func_array([$handler, $method], func_get_args());
};
}
if (is_string($closure)) {
return function () use ($closure) {
return call_user_func($closure, ...func_get_args());
};
}
return $closure instanceof \Closure ? $closure : null;
}
}
if (!function_exists('notify')) {
function notify($message, $label = 'info')
{
$log = new Logger('notify');
$log->pushHandler(new MonologHandler([Ding::class, Wx::class]));
$log->{$label}($message);
}
}