1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Manticoresearch\Response; |
4
|
|
|
|
5
|
|
|
use Manticoresearch\Response; |
6
|
|
|
|
7
|
|
|
class SqlToArray extends Response |
8
|
|
|
{ |
9
|
|
|
public function getResponse() |
10
|
|
|
{ |
11
|
|
|
$response = parent::getResponse(); |
12
|
|
|
// workaround for the change in Manticore Search made in 4.2.1, after |
13
|
|
|
// which any query in mode=raw returns an array |
14
|
|
|
if (is_array($response) |
15
|
|
|
and count($response) === 1 |
16
|
|
|
and isset($response[0]['total'], $response[0]['error'], $response[0]['warning'])) { |
17
|
|
|
foreach ($response[0] as $k => $v) { |
18
|
|
|
$response[$k] = $v; |
19
|
|
|
} |
20
|
|
|
unset($response[0]); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if (isset($response['columns'], $response['data'])) { |
24
|
|
|
$data = []; |
25
|
|
|
array_walk($response['columns'], static function (&$value, $key) { |
|
|
|
|
26
|
|
|
$value = array_keys($value)[0]; |
27
|
|
|
}); |
28
|
|
|
$id = -1; |
29
|
|
|
foreach ($response['data'] as $property) { |
30
|
|
|
if (isset($property['id'])) { |
31
|
|
|
$id = $property['id']; |
32
|
|
|
if (count($property) > 1) { |
33
|
|
|
unset($property['id']); |
34
|
|
|
} |
35
|
|
|
} elseif (isset($this->params['customMapping']) and $this->params['customMapping']) { |
36
|
|
|
if (isset($property['Field'])) { |
37
|
|
|
$id = $property['Field']; |
38
|
|
|
if (count($property) > 1) { |
39
|
|
|
unset($property['Field']); |
40
|
|
|
} |
41
|
|
|
} elseif (isset($property['Variable_name'])) { |
42
|
|
|
$id = $property['Variable_name']; |
43
|
|
|
if (count($property) > 1) { |
44
|
|
|
unset($property['Variable_name']); |
45
|
|
|
} |
46
|
|
|
} elseif (isset($property['Index'])) { |
47
|
|
|
$id = $property['Index']; |
48
|
|
|
if (count($property) > 1) { |
49
|
|
|
unset($property['Index']); |
50
|
|
|
} |
51
|
|
|
} elseif (isset($property['Counter'])) { |
52
|
|
|
$id = $property['Counter']; |
53
|
|
|
if (count($property) > 1) { |
54
|
|
|
unset($property['Counter']); |
55
|
|
|
} |
56
|
|
|
} elseif (isset($property['Key'])) { |
57
|
|
|
$id = $property['Key']; |
58
|
|
|
if (count($property) > 1) { |
59
|
|
|
unset($property['Key']); |
60
|
|
|
} |
61
|
|
|
} elseif (isset($property['command'])) { |
62
|
|
|
$id = $property['command']; |
63
|
|
|
if (count($property) > 1) { |
64
|
|
|
unset($property['command']); |
65
|
|
|
} |
66
|
|
|
} elseif (isset($property['suggest'])) { |
67
|
|
|
$id = $property['suggest']; |
68
|
|
|
if (count($property) > 1) { |
69
|
|
|
unset($property['suggest']); |
70
|
|
|
} |
71
|
|
|
} elseif (isset($property['Variable'])) { |
72
|
|
|
$id = $property['Variable']; |
73
|
|
|
if (count($property) > 1) { |
74
|
|
|
unset($property['Variable']); |
75
|
|
|
} |
76
|
|
|
} else { |
77
|
|
|
$id++; |
78
|
|
|
} |
79
|
|
|
} else { |
80
|
|
|
$id++; |
81
|
|
|
} |
82
|
|
|
$data[$id] = (count($property) == 1)?array_shift($property):$property; |
83
|
|
|
} |
84
|
|
|
return (count($data) > 0) ? $data : []; |
85
|
|
|
} |
86
|
|
|
return $response; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.