Skip to content

Commit e28c34f

Browse files
authored
Merge pull request #15 from patrickkivits/feature-multiple-tokens-per-interest
Multiple tokens per interest
2 parents 2043640 + ad278e6 commit e28c34f

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

lib/ExpoRegistrar.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ public function getInterests(array $interests): array
7979
$tokens = [];
8080

8181
foreach ($interests as $interest) {
82-
$token = $this->repository->retrieve($interest);
82+
$retrieved = $this->repository->retrieve($interest);
8383

84-
if (!is_null($token)) {
85-
$tokens[] = $token;
84+
if (!is_null($retrieved)) {
85+
if(is_string($retrieved)) {
86+
$tokens[] = $retrieved;
87+
}
88+
89+
if(is_array($retrieved)) {
90+
foreach($retrieved as $token) {
91+
if(is_string($token)) {
92+
$tokens[] = $token;
93+
}
94+
}
95+
}
8696
}
8797
}
8898

lib/ExpoRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function store($key, $value): bool;
1818
*
1919
* @param string $key
2020
*
21-
* @return string|null
21+
* @return array|string|null
2222
*/
2323
public function retrieve(string $key);
2424

lib/Repositories/ExpoFileDriver.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ public function store($key, $value): bool
3232
$storageInstance = $this->createFile();
3333
}
3434

35-
$storageInstance->{$key} = $value;
35+
// Check for existing tokens
36+
if(isset($storageInstance->{$key}))
37+
{
38+
// If there is a single token, make it an array so we can push the additional tokens in it
39+
if(!is_array($storageInstance->{$key}))
40+
{
41+
$storageInstance->{$key} = [$storageInstance->{$key}];
42+
}
43+
44+
// Add new token to existing key
45+
array_push($storageInstance->{$key}, $value);
46+
}
47+
else
48+
{
49+
// First token for this key
50+
$storageInstance->{$key} = [$value];
51+
}
3652

3753
$file = $this->updateRepository($storageInstance);
3854

@@ -44,7 +60,7 @@ public function store($key, $value): bool
4460
*
4561
* @param string $key
4662
*
47-
* @return string|null
63+
* @return array|string|null
4864
*/
4965
public function retrieve(string $key)
5066
{

0 commit comments

Comments
 (0)