Skip to content

Properly handle Laravel model for "person_fn". #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/MonologHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
class MonologHandler extends RollbarHandler
{
protected $app;

public function setApp($app)
{
$this->app = $app;
}

protected function write(array $record)
{
$record['context'] = $this->addContext($record['context']);
Expand All @@ -30,23 +30,34 @@ protected function addContext(array $context = [])
if ($session = $this->app->session->all()) {
$config = $this->rollbarLogger->extend([]);

if (empty($config['person']) or ! is_array($config['person'])) {
if (empty($config['person']) || ! is_array($config['person'])) {
$person = [];
} else {
$person = $config['person'];
}

// Merge person context.
if (isset($context['person']) and is_array($context['person'])) {
if (isset($context['person']) && is_array($context['person'])) {
$person = $context['person'];
unset($context['person']);
} else {
if (isset($config['person_fn']) && is_callable($config['person_fn'])) {
$data = @call_user_func($config['person_fn']);
if (isset($data['id'])) {
$person = call_user_func($config['person_fn']);
} elseif (isset($config['person_fn']) && is_callable($config['person_fn'])) {
$data = @call_user_func($config['person_fn']);
if (! empty($data)) {
if (is_object($data)) {
if (isset($data->id)) {
$person['id'] = $data->id;
if (isset($data->username)) {
$person['username'] = $data->username;
}
if (isset($data->email)) {
$person['email'] = $data->email;
}
}
} elseif (is_array($data) && isset($data['id'])) {
$person = $data;
}
}
unset($data);
}

// Add user session information.
Expand All @@ -60,7 +71,7 @@ protected function addContext(array $context = [])
if (! isset($person['id'])) {
$person['id'] = $this->app->session->getId();
}

$this->rollbarLogger->configure(['person' => $person]);
}

Expand Down