Skip to content

Commit 0f6f95d

Browse files
committed
Add getter methods to processors
These methods allow the data which would be added to be queried for other purposes. This helps with, for example, #20
1 parent 819667c commit 0f6f95d

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
@@ -61,6 +61,17 @@ public function __construct(array $options = [])
6161
* @return array $record
6262
*/
6363
public function __invoke(array $record)
64+
{
65+
$record['context']['user'] = array_merge($this->getUserContext(), array_get($record, 'context.user', []));
66+
return $record;
67+
}
68+
69+
/**
70+
* Get the user context array
71+
*
72+
* @return array
73+
*/
74+
public function getUserContext()
6475
{
6576
$data = ['id' => null];
6677
if ($user = $this->getUser()) {
@@ -89,9 +100,7 @@ public function __invoke(array $record)
89100
$userArray = array_only($data, $topLevel);
90101
$userArray['data'] = array_except($data, $topLevel);
91102

92-
$record['context']['user'] = array_merge($userArray, array_get($record, 'context.user', []));
93-
94-
return $record;
103+
return $userArray;
95104
}
96105

97106
/**

0 commit comments

Comments
 (0)