This repository was archived by the owner on Aug 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlugin.php
More file actions
75 lines (65 loc) · 2.67 KB
/
Plugin.php
File metadata and controls
75 lines (65 loc) · 2.67 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
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 namespace PopcornPHP\ExceptionReport;
use Backend\Facades\BackendAuth;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
use PopcornPHP\ExceptionReport\Classes\Telegram;
use PopcornPHP\ExceptionReport\Models\Settings as ExceptionReportSettings;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'ExceptionReport',
'description' => 'Report about exceptions to Telegram',
'author' => 'Alexander Shapoval',
'icon' => 'icon-cog',
'homepage' => 'https://popcornphp.github.io',
];
}
public function boot()
{
App::error(function (Exception $exception) {
$settings = ExceptionReportSettings::instance();
if (config('app.debug') == true && $settings->disabled_in_debug == true) {
return;
}
if (BackendAuth::check() == true && $settings->disabled_for_admins == true) {
return;
}
$exception_class_name = get_class($exception);
$disabled_classes = $settings->disabled_exceptions;
if (!collect($disabled_classes)->flatten()->contains($exception_class_name)) {
$info = 'You have new exception on ' . Request::url() . "\n\n";
$class = "<b>Exception class:</b> " . $exception_class_name . "\n\n";
$date = "<b>Date and Time:</b> " . Carbon::now() . "\n\n";
$code = "<b>Code:</b> " . $exception->getCode() . "\n\n";
$file = "<b>File:</b> " . $exception->getFile() . "\n\n";
$line = "<b>Line:</b> " . $exception->getLine() . "\n\n";
$message = "<b>Error:</b> " . $exception->getMessage();
$gateway = new Telegram();
$gateway->sendMessage([
'chat_id' => $settings->telegram_chat_id,
'text' => $info . $class . $date . $code . $file . $line . $message,
'parse_mode' => 'HTML',
]);
}
});
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'Exception report',
'description' => 'Report about exceptions to Telegram',
'category' => SettingsManager::CATEGORY_NOTIFICATIONS,
'icon' => 'icon-cog',
'class' => 'PopcornPHP\ExceptionReport\Models\Settings',
'order' => 500,
],
];
}
}