-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernelsentry.php
More file actions
136 lines (122 loc) · 3.22 KB
/
kernelsentry.php
File metadata and controls
136 lines (122 loc) · 3.22 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @package Kernel Sentry
* @version 1.0.0
*
* @author Kernel Data Ltd <jaz@kernel.co.uk>
* @link http://www.kernel.co.uk
* @copyright Copyright © 2020 Kernel Data Ltd All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
require_once __DIR__ . '/vendor/autoload.php';
/**
* Plugin class for Kernel Sentry
*
* @since 1.0.0
*/
class plgSystemKernelsentry extends JPlugin
{
/**
* The global exception handler registered before the plugin was instantiated
*
* @var callable
* @since 1.0.0
*/
private static $previousExceptionHandler;
/**
* Constructor.
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
*
* @since 1.0.0
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$non_plugin_settings = false;
if ($this->params['settings_file'] != '' & $this->params['settings_class'] != '')
{
$settings_file = realpath(dirname(__DIR__) . '/../../'. $this->params['settings_file']);
if (file_exists($settings_file))
{
require_once($settings_file);
$settings_class = $this->params['settings_class'];
if (class_exists($settings_class))
{
$settings_class = new $settings_class();
Sentry\init([
'dsn' => $settings_class->sentry_dsn,
'environment' => $settings_class->sentry_environment
]
);
$non_plugin_settings = true;
}
}
}
if (!$non_plugin_settings)
{
Sentry\init(
[
'dsn' => $this->params['sentry_dsn'],
'environment' => $this->params['sentry_environment'],
]
);
}
JError::setErrorHandling(E_ERROR, 'callback', array('PlgSystemKernelsentry', 'handleError'));
self::$previousExceptionHandler = set_exception_handler(array('PlgSystemKernelsentry', 'handleException'));
}
/**
* Method to handle an error condition from JError.
*
* @param JException $error The JException object to be handled.
*
* @return void
*
* @since 1.0.0
*/
public static function handleError(JException $error)
{
self::doErrorHandling($error);
}
/**
* Method to handle an uncaught exception.
*
* @param Exception|Throwable $exception The Exception or Throwable object to be handled.
*
* @return void
*
* @throws InvalidArgumentException
* @since 1.0.0
*/
public static function handleException($exception)
{
// If this isn't a Throwable then bail out
if (!($exception instanceof Throwable) && !($exception instanceof Exception))
{
throw new InvalidArgumentException(
sprintf('The error handler requires an Exception or Throwable object, a "%s" object was given instead.', get_class($exception))
);
}
self::doErrorHandling($exception);
}
/**
* Processor for all error handlers
*
* @param Exception|Throwable $error The Exception or Throwable object to be handled.
*
* @return void
*
* @since 1.0.0
*/
private static function doErrorHandling($error)
{
$app = JFactory::getApplication();
if ($app->isClient('administrator'))
{
return;
}
Sentry\captureException($error);
}
}