/
Component.php
106 lines (93 loc) · 3.41 KB
/
Component.php
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
<?php
/**
* Component.php
* @author Revin Roman
* @link https://rmrevin.ru
*/
namespace rmrevin\yii\rollbar;
/**
* Class Component
* @package rmrevin\yii\rollbar
*/
class Component extends \yii\base\Object
{
public $enabled = true;
public $useLogger = true;
public $setExceptionHandler = false;
public $setErrorHandler = false;
public $reportFatalErrors = true;
public $accessToken;
public $agentLogLocation = '@app/runtime/rollbar';
public $baseApiUrl = 'https://api.rollbar.com/api/1/';
public $batchSize = 50;
public $batched = true;
public $branch = 'master';
public $captureErrorStacktraces = true;
public $codeVersion;
public $environment = 'production';
public $errorSampleRates = [];
public $handler = 'blocking';
public $host;
public $includedErrno;
public $logger;
public $person;
public $personFn;
public $root = '@app';
public $scrubFields = ['passwd', 'password', 'secret', 'confirm_password', 'password_confirmation', 'auth_token', 'csrf_token'];
public $shiftFunction = true;
public $timeout = 3; // seconds
public $reportSuppressed = false;
public $useErrorReporting = false;
public $proxy;
const HANDLER_BLOCKING = 'blocking';
const HANDLER_AGENT = 'agent';
public function init()
{
$this->enabled = $this->enabled !== false;
if ($this->enabled === true) {
if (empty($this->accessToken)) {
throw new \yii\base\InvalidConfigException(sprintf('`rollbar\Component::%s` must be specified.', 'accessToken'));
}
$logger = $this->logger;
if (!($logger instanceof \iRollbarLogger) && $this->useLogger === true) {
$logger = new Logger();
}
$agentLogLocation = \Yii::getAlias($this->agentLogLocation);
if (!empty($agentLogLocation)) {
\yii\helpers\FileHelper::createDirectory($agentLogLocation);
}
$config = [
'access_token' => $this->accessToken,
'agent_log_location' => $agentLogLocation,
'base_api_url' => $this->baseApiUrl,
'batch_size' => $this->batchSize,
'batched' => $this->batched,
'branch' => $this->branch,
'capture_error_stacktraces' => $this->captureErrorStacktraces,
'code_version' => $this->codeVersion,
'environment' => $this->environment,
'error_sample_rates' => $this->errorSampleRates,
'handler' => $this->handler,
'host' => $this->host,
'included_errno' => $this->includedErrno,
'logger' => $logger,
'person' => $this->person,
'person_fn' => $this->personFn,
'root' => \Yii::getAlias($this->root),
'scrub_fields' => $this->scrubFields,
'shift_function' => $this->shiftFunction,
'timeout' => $this->timeout,
'report_suppressed' => $this->reportSuppressed,
'use_error_reporting' => $this->useErrorReporting,
'proxy' => $this->proxy,
];
\Rollbar::init(
$config,
$this->setExceptionHandler,
$this->setErrorHandler,
$this->reportFatalErrors
);
}
parent::init();
}
}