forked from baibaratsky/yii-rollbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RollbarComponent.php
70 lines (60 loc) · 1.77 KB
/
RollbarComponent.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
<?php
use Rollbar\Rollbar;
class RollbarComponent extends CApplicationComponent
{
private $config = array();
public function __construct()
{
$this->setDefaults();
}
public function init()
{
Rollbar::init($this->config, false, false);
parent::init();
}
public function __set($key, $value)
{
$key = $this->normalizeWithCompatibility($key);
if ($key === 'root') {
$value = Yii::getPathOfAlias($value) ? Yii::getPathOfAlias($value) : $value;
}
$this->config[$key] = $value;
}
protected function setDefaults()
{
$this->root = Yii::getPathOfAlias('application');
$this->scrub_fields = array('passwd', 'password', 'secret', 'auth_token', 'YII_CSRF_TOKEN');
$this->checkIgnore = function ($isUncaught, $exception, $payload) {
if ($exception instanceof CHttpException && $exception->statusCode == 404) {
return true;
}
return false;
};
}
/**
* Converts old public properties to new key names.
*/
protected function normalizeWithCompatibility($key)
{
if ($key === 'rootAlias') {
$key = 'root';
}
if ($key !== 'checkIgnore') {
$key = $this->underscore($key);
}
return $key;
}
/**
* Converts any "CamelCased" into an "underscored_word".
*
* Taken from
* https://github.com/yiisoft/yii2/blob/6da1ec6fb2b6367cb30d8c581575d09f0072812d/framework/helpers/BaseInflector.php#L411
*
* @param string $words the word(s) to underscore
* @return string
*/
private function underscore($words)
{
return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $words));
}
}