forked from Goldinteractive/craft-bugsnag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBugsnagPlugin.php
More file actions
57 lines (45 loc) · 1.33 KB
/
BugsnagPlugin.php
File metadata and controls
57 lines (45 loc) · 1.33 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
<?php namespace Craft;
use Yii;
class BugsnagPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Bugsnag');
}
public function getVersion()
{
return '1.0';
}
public function getDeveloper()
{
return 'Gold Interactive';
}
public function getDeveloperUrl()
{
return 'https://github.com/Goldinteractive/craft-bugsnag';
}
public function init()
{
// Make sure the class is not loaded elsewhere.
if (!class_exists('Bugsnag_Client')) {
require CRAFT_PLUGINS_PATH . '/bugsnag/vendor/autoload.php';
}
$this->listen();
}
private function listen()
{
$service = craft()->bugsnag;
Yii::app()->onException = function ($exceptionEvent) use ($service) {
foreach (craft()->plugins->call('discardBugsnagExceptionEvent', array($exceptionEvent)) as $shouldDiscard) {
if ($shouldDiscard) {
return;
}
}
$service->logException($exceptionEvent->exception);
};
Yii::app()->onError = function ($errorEvent) use ($service) {
$service->logError($errorEvent->code, $errorEvent->message,
['file' => $errorEvent->file, 'line' => $errorEvent->line]);
};
}
}