|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of Monolog Extensions |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @see http://github.com/graze/MonologExtensions/blob/master/LICENSE |
|
11
|
|
|
* @link http://github.com/graze/MonologExtensions |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Graze\Monolog\Processor; |
|
15
|
|
|
|
|
16
|
|
|
class DynamoDbSecondaryIndexProcessor |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
private $secondaryIndexes; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param array $secondaryIndexes |
|
25
|
|
|
*/ |
|
26
|
3 |
|
public function __construct(array $secondaryIndexes = []) |
|
27
|
|
|
{ |
|
28
|
3 |
|
$this->secondaryIndexes = $secondaryIndexes; |
|
29
|
3 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Sets up secondary indexes for dynamodb table |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $record |
|
35
|
|
|
* |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function __invoke(array $record) |
|
39
|
|
|
{ |
|
40
|
2 |
|
$foundIndexes = $this->retrieveSecondaryIndexes($record, $this->secondaryIndexes); |
|
41
|
2 |
|
return array_merge($foundIndexes, $record); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* returns an array of secondary indexes as key-value pairs that exist in $record |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $record |
|
48
|
|
|
* @param array $keys |
|
49
|
|
|
* @param array $foundKeys |
|
50
|
|
|
* |
|
51
|
|
|
* @return array $foundKeys |
|
52
|
|
|
*/ |
|
53
|
2 |
|
private function retrieveSecondaryIndexes(array $record, array $keys, array &$foundKeys = []) |
|
54
|
|
|
{ |
|
55
|
2 |
|
foreach ($record as $key => $value) { |
|
56
|
2 |
|
if (in_array($key, $keys)) { |
|
57
|
2 |
|
$foundKeys[$key] = $value; |
|
58
|
|
|
} |
|
59
|
2 |
|
if (is_array($value)) { |
|
60
|
2 |
|
$this->retrieveSecondaryIndexes($value, $keys, $foundKeys); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
2 |
|
return $foundKeys; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|