Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 2 |
1 | <?php |
||
10 | class Suggest extends EmulateBySql |
||
11 | { |
||
12 | use Utils; |
||
13 | protected $_index; |
||
14 | |||
15 | public function __construct($params = []) |
||
16 | { |
||
17 | if (isset($params['index'])) { |
||
18 | $this->setIndex($params['index']); |
||
19 | } |
||
20 | |||
21 | parent::__construct($params); |
||
22 | } |
||
23 | |||
24 | public function setBody($params = null) |
||
25 | { |
||
26 | if (isset($this->_index)) { |
||
27 | $binds =[]; |
||
28 | $binds[] = "'" . Utils::escape($params['query']) . "'"; |
||
29 | $binds[] = "'" . $this->_index . "'"; |
||
30 | if (count($params['options']) > 0) { |
||
31 | foreach ($params['options'] as $name => $value) { |
||
32 | $binds[] = "$value AS $name"; |
||
33 | } |
||
34 | } |
||
35 | $this->_body = ['query' => "CALL SUGGEST(" . implode(",", $binds) . ")"]; |
||
36 | } else { |
||
37 | throw new RuntimeException('Index name is missing.'); |
||
38 | } |
||
39 | |||
40 | } |
||
41 | /** |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function getIndex() |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param mixed $index |
||
51 | */ |
||
52 | public function setIndex($index) |
||
55 | } |
||
56 | } |
||
57 |