1 | <?php |
||
10 | class Indexer |
||
11 | { |
||
12 | /** |
||
13 | * Operations indexed by key and operation index. |
||
14 | * |
||
15 | * @var Operation[][] |
||
16 | */ |
||
17 | protected $index = []; |
||
18 | |||
19 | /** |
||
20 | * Operations indexed by this indexer. |
||
21 | * |
||
22 | * @var Operation[] |
||
23 | */ |
||
24 | protected $operations = []; |
||
25 | |||
26 | /** |
||
27 | * The connection used by this indexer. |
||
28 | * |
||
29 | * @var Connection |
||
30 | */ |
||
31 | protected $connection; |
||
32 | |||
33 | /** |
||
34 | * Indexer constructor. |
||
35 | * |
||
36 | * @param Connection $connection |
||
37 | */ |
||
38 | 6 | public function __construct(Connection $connection) |
|
42 | |||
43 | /** |
||
44 | * Get connection. |
||
45 | * |
||
46 | * @return Connection |
||
47 | */ |
||
48 | 1 | public function getConnection() |
|
52 | |||
53 | /** |
||
54 | * Index operation. |
||
55 | * |
||
56 | * @param Operation $operation |
||
57 | * The operation to index. |
||
58 | * @param string $key |
||
59 | * (optional) The key to index under. |
||
60 | * |
||
61 | * @return Operation |
||
62 | * The operation indexed. |
||
63 | */ |
||
64 | 5 | public function index(Operation $operation, $key = null) |
|
76 | |||
77 | /** |
||
78 | * De-index operation. |
||
79 | * |
||
80 | * @param Operation $operation |
||
81 | * The operation to index. |
||
82 | * @param string $key |
||
83 | * (optional) The key to index under. |
||
84 | * |
||
85 | * @return Operation |
||
86 | * The operation de-indexed. |
||
87 | */ |
||
88 | 2 | public function deIndex(Operation $operation, $key = null) |
|
96 | |||
97 | /** |
||
98 | * Lookup operation. |
||
99 | * |
||
100 | * @param string $key |
||
101 | * The key to look up. |
||
102 | * |
||
103 | * @return Operation[] |
||
104 | * Operations keyed by operation index. |
||
105 | */ |
||
106 | 3 | public function lookup($key) |
|
110 | |||
111 | /** |
||
112 | * Lookup operation values. |
||
113 | * |
||
114 | * @param string $indexKey |
||
115 | * The index key to look up. |
||
116 | * @param string $metadataKey |
||
117 | * The metadata key to look up. |
||
118 | * |
||
119 | * @return array |
||
120 | * Values keyed by operation index. |
||
121 | */ |
||
122 | 1 | public function lookupMetadata($indexKey, $metadataKey) |
|
123 | { |
||
124 | 1 | $values = []; |
|
125 | 1 | if (isset($this->index[$indexKey])) { |
|
126 | 1 | foreach ($this->index[$indexKey] as $operation) { |
|
127 | 1 | $values[$operation->idx($this->connection)] = $operation->getMetadata($metadataKey); |
|
128 | 1 | } |
|
129 | 1 | } |
|
130 | 1 | return $values; |
|
131 | } |
||
132 | |||
133 | /** |
||
134 | * Get current indexed operations. |
||
135 | * |
||
136 | * @return Operation[] |
||
137 | */ |
||
138 | 1 | public function getOperations() |
|
142 | |||
143 | /** |
||
144 | * Get current index. |
||
145 | * |
||
146 | * @return Operation[][] |
||
147 | */ |
||
148 | 1 | public function getIndex() |
|
152 | } |
||
153 |