Skip to content

Commit 68d0f27

Browse files
authored
User context provisto de forma dinámica (#3)
* Fix `Getting unknown property: app\modules\v1\models\ApiTokens::nombre` * Se extiende uso de user en contexto
1 parent f024b2d commit 68d0f27

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/AirbrakeService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class AirbrakeService extends Component
2828
/** @var string|null Run-time environment (optional) */
2929
public $environment;
3030

31+
/** @var mixed Run-time user (optional) */
32+
public $user;
33+
3134
/** @var ParamsFilter[] Items of the array will be added as filters */
3235
public $filters;
3336

@@ -77,6 +80,7 @@ public function init()
7780
'environment' => $this->environment,
7881
'rootDirectory' => Yii::getAlias($this->rootDirectory),
7982
'host' => $this->host,
83+
'user' => $this->user,
8084
]);
8185

8286
if (is_array($this->filters)) {

src/Notifier.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
class Notifier extends AirbrakeNotifier
99
{
10+
private $user;
11+
12+
public function __construct($opt)
13+
{
14+
parent::__construct($opt);
15+
16+
$this->user = $opt['user'];
17+
}
18+
1019
public function buildNotice($exc)
1120
{
1221
$notice = parent::buildNotice($exc);
@@ -17,12 +26,10 @@ public function buildNotice($exc)
1726
$notice['context']['user']['id'] = $user->id;
1827
}
1928
if (isset($user->identity)) {
20-
$notice['context']['user']['name'] = $user->identity->nombre;
21-
$notice['context']['user']['email'] = $user->identity->email;
29+
$notice['context']['user'] = $this->user->call($this, $user->identity);
2230
}
2331
}
2432

2533
return $notice;
2634
}
27-
2835
}

0 commit comments

Comments
 (0)