1 | <?php |
||
8 | class Finder extends BaseFinder |
||
9 | { |
||
10 | /** |
||
11 | * @param \Clusterpoint\Instance\Service $collection |
||
12 | */ |
||
13 | protected function setLimit($collection) |
||
14 | { |
||
15 | if ($this->queryConfiguration->limit !== null) { |
||
16 | $collection->limit($this->queryConfiguration->limit); |
||
17 | } |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @param \Clusterpoint\Instance\Service $collection |
||
22 | */ |
||
23 | protected function setOffset($collection) |
||
24 | { |
||
25 | if ($this->queryConfiguration->offset !== null) { |
||
26 | $collection->offset($this->queryConfiguration->offset); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param \Clusterpoint\Instance\Service $collection |
||
32 | */ |
||
33 | protected function setOrderBy($collection) |
||
34 | { |
||
35 | foreach ($this->queryConfiguration->orderBy as $orderBy) { |
||
36 | $collection->orderBy(key($orderBy), current($orderBy)); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param \Clusterpoint\Instance\Service $collection |
||
42 | */ |
||
43 | protected function setSelect($collection) |
||
44 | { |
||
45 | if ($this->queryConfiguration->select !== '*') { |
||
46 | $collection->select($this->queryConfiguration->select); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param \Clusterpoint\Instance\Service $collection |
||
52 | */ |
||
53 | protected function setWhere($collection) |
||
54 | { |
||
55 | if (!empty($this->queryConfiguration->where)) { |
||
56 | $this->parseWhere($collection, $this->queryConfiguration->where, $this->mainLogical); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param \Clusterpoint\Instance\Service $collection |
||
62 | */ |
||
63 | protected function configQuery($collection) |
||
64 | { |
||
65 | $this->setLimit($collection); |
||
66 | $this->setOffset($collection); |
||
67 | $this->setOrderBy($collection); |
||
68 | $this->setSelect($collection); |
||
69 | $this->setWhere($collection); |
||
70 | } |
||
71 | |||
72 | public function get() |
||
73 | { |
||
74 | if (!($this->client instanceof Client)) { |
||
75 | throw new RestException( |
||
76 | 'Clusterpoint Finder can be used with Clusterpoint Client only', |
||
77 | ['type' => get_class($this->client)] |
||
78 | ); |
||
79 | } |
||
80 | $collection = $this->client->database( |
||
81 | $this->queryConfiguration->databaseName . |
||
82 | '.' . |
||
83 | $this->queryConfiguration->from |
||
84 | ); |
||
85 | $this->configQuery($collection); |
||
86 | $items = json_decode(json_encode($collection->get()->toArray())); |
||
87 | $count = count($items); |
||
88 | for ($idx = 0; $idx < $count; $idx++) { |
||
89 | $this->resultSet[] = $items[$idx]; |
||
90 | } |
||
91 | return $this; |
||
92 | } |
||
93 | |||
94 | protected function createClient() |
||
95 | { |
||
96 | $this->client = new Client; |
||
97 | return $this; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param \Clusterpoint\Instance\Service $collection |
||
102 | * @param array $conditions @param string $logical |
||
103 | * @return \Closure |
||
104 | */ |
||
105 | protected function addWhereGroup($collection, $conditions, $logical) |
||
115 | |||
116 | /** |
||
117 | * @param string $logical |
||
118 | * @param \Clusterpoint\Instance\Service $collection |
||
119 | * @param array $condition |
||
120 | * @param string $nextLogical |
||
121 | */ |
||
122 | protected function parseWhereGroup($logical, $collection, $condition, $nextLogical) |
||
123 | { |
||
131 | |||
132 | /** |
||
133 | * @param \Clusterpoint\Instance\Service $collection |
||
134 | * @param array $conditions |
||
135 | * @param string $logical |
||
136 | */ |
||
137 | private function parseWhere($collection, $conditions, $logical) |
||
153 | } |
||
154 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.