1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Sandro Keil (https://sandro-keil.de) |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/sandrokeil/arangodb-php-client for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2018-2020 Sandro Keil |
7
|
|
|
* @license http://github.com/sandrokeil/arangodb-php-client/blob/master/LICENSE.md New BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace ArangoDb\Statement; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\StreamInterface; |
15
|
|
|
|
16
|
|
|
final class SimdjsonHandler implements StreamHandler |
17
|
|
|
{ |
18
|
|
|
use SimdjsonStreamHandlerTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var mixed |
22
|
|
|
*/ |
23
|
|
|
private $data = []; |
24
|
|
|
|
25
|
2 |
|
public function __construct(StreamInterface $stream) |
26
|
|
|
{ |
27
|
2 |
|
$this->data[$this->fetches] = $stream->getContents(); |
28
|
2 |
|
$this->length = \simdjson_key_count($this->data[$this->fetches], 'result'); |
|
|
|
|
29
|
|
|
$this->batchSize = $this->length; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Return the current result row |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function current(): array |
38
|
|
|
{ |
39
|
|
|
return \simdjson_key_value( |
|
|
|
|
40
|
|
|
$this->data[$this->fetches], |
41
|
|
|
"result/" . ($this->position - ($this->batchSize * $this->fetches)), |
42
|
|
|
true |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function result(): array |
47
|
|
|
{ |
48
|
|
|
return \simdjson_key_value( |
|
|
|
|
49
|
|
|
$this->data[$this->fetches], |
50
|
|
|
"result", |
51
|
|
|
true |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function raw(): array |
56
|
|
|
{ |
57
|
|
|
return $this->data[$this->fetches]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function completeResult() |
61
|
|
|
{ |
62
|
|
|
$completeResult = [[]]; |
63
|
|
|
|
64
|
|
|
foreach ($this->data as $result) { |
65
|
|
|
$completeResult[] = \simdjson_key_value($result, 'result', true); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
return array_merge(...$completeResult); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function appendStream(StreamInterface $stream): void |
71
|
|
|
{ |
72
|
|
|
$this->data[++$this->fetches] = $stream->getContents(); |
73
|
|
|
$this->length += \simdjson_key_count($this->data[$this->fetches], 'result', true); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|