-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFMResult.php
106 lines (88 loc) · 2.69 KB
/
FMResult.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace MSDev\DoctrineFMDataAPIDriver;
use Doctrine\DBAL\Driver\Result;
class FMResult implements Result
{
private int $rowCount = 0;
public function __construct(
private readonly array $request,
private readonly array $results,
private readonly array $metadata,
) {
}
public function fetchNumeric()
{
// TODO: Implement fetchNumeric() method.
dd(__METHOD__);
}
public function fetchAssociative(): array|false
{
if(array_key_exists($this->rowCount, $this->results)) {
$row = $this->results[$this->rowCount];
$this->rowCount++;
return $this->recordToArray($row);
}
return false;
}
public function fetchOne()
{
// TODO: Implement fetchOne() method.
dd(__METHOD__);
}
public function fetchAllNumeric(): array
{
// TODO: Implement fetchAllNumeric() method.
dd(__METHOD__);
}
public function fetchAllAssociative(): array
{
// TODO: Implement fetchAllAssociative() method.
dd(__METHOD__);
}
public function fetchFirstColumn(): array
{
// TODO: Implement fetchFirstColumn() method.
dd(__METHOD__);
}
public function rowCount(): int
{
return count($this->results);
}
public function columnCount(): int
{
// TODO: Implement columnCount() method.
dd(__METHOD__);
}
public function free(): void
{
// TODO: Implement free() method.
//dd(__METHOD__);
//return;
}
private function recordToArray(array $rec): array
{
$select = $this->request['SELECT'];
if ('subquery' === $this->request['FROM'][0]['expr_type']) {
$select = $this->request['FROM'][0]['sub_tree']['FROM'][0]['sub_tree']['SELECT'];
}
$resp = [];
foreach ($select as $field) {
if ('rec_id' === $field['no_quotes']['parts'][1]) {
$resp[$field['alias']['no_quotes']['parts'][0]] = $rec['recordId'];
continue;
}
if ('mod_id' === $field['no_quotes']['parts'][1]) {
$resp[$field['alias']['no_quotes']['parts'][0]] = $rec['modId'];
continue;
}
if ('rec_meta' === $field['no_quotes']['parts'][1]) {
$resp[$field['alias']['no_quotes']['parts'][0]] = json_encode($this->metadata);
continue;
}
$data = $rec['fieldData'][$field['no_quotes']['parts'][1]];
$resp[$field['alias']['no_quotes']['parts'][0]] = $data === '' ? null : $data;
}
return $resp;
}
}