Skip to content

Commit 8067dc9

Browse files
committed
Merge pull request #22 from tremby/processor-getters
Add getter methods to processors
2 parents cb5c809 + 0f6f95d commit 8067dc9

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Processors/LocaleProcessor.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ class LocaleProcessor
1717
*/
1818
public function __invoke(array $record)
1919
{
20-
$record['extra']['tags']['locale'] = $this->getLocale();
20+
$record['extra']['tags'] = array_merge(array_get($record, 'extra.tags', []), $this->getTags());
2121
return $record;
2222
}
2323

24+
/**
25+
* Get the tags to be added
26+
*
27+
* @return array
28+
*/
29+
public function getTags()
30+
{
31+
return [
32+
'locale' => $this->getLocale(),
33+
];
34+
}
35+
2436
/**
2537
* Get the locale
2638
*

src/Processors/UserDataProcessor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ public function __construct(array $options = [])
6565
* @return array $record
6666
*/
6767
public function __invoke(array $record)
68+
{
69+
$record['context']['user'] = array_merge($this->getUserContext(), array_get($record, 'context.user', []));
70+
return $record;
71+
}
72+
73+
/**
74+
* Get the user context array
75+
*
76+
* @return array
77+
*/
78+
public function getUserContext()
6879
{
6980
$data = ['id' => null];
7081
if ($user = $this->getUser()) {
@@ -93,9 +104,7 @@ public function __invoke(array $record)
93104
$userArray = array_only($data, $topLevel);
94105
$userArray['data'] = array_except($data, $topLevel);
95106

96-
$record['context']['user'] = array_merge($userArray, array_get($record, 'context.user', []));
97-
98-
return $record;
107+
return $userArray;
99108
}
100109

101110
/**

0 commit comments

Comments
 (0)