@@ -10,43 +10,43 @@ |
||
10 | 10 | */ |
11 | 11 | interface ISpecificationCriteria |
12 | 12 | { |
13 | - public function getCriteria(); |
|
13 | + public function getCriteria(); |
|
14 | 14 | |
15 | 15 | public function getWhere(); |
16 | 16 | |
17 | - public function getLimit(); |
|
17 | + public function getLimit(); |
|
18 | 18 | |
19 | - public function getOfset(); |
|
19 | + public function getOfset(); |
|
20 | 20 | |
21 | - public function getJoins(); |
|
21 | + public function getJoins(); |
|
22 | 22 | |
23 | - public function getOrder(); |
|
23 | + public function getOrder(); |
|
24 | 24 | |
25 | - public function getManualJoins(); |
|
25 | + public function getManualJoins(); |
|
26 | 26 | |
27 | - public function getGroup(); |
|
27 | + public function getGroup(); |
|
28 | 28 | |
29 | - public function getManualWheres(); |
|
29 | + public function getManualWheres(); |
|
30 | 30 | |
31 | - public function getWhereType(); |
|
31 | + public function getWhereType(); |
|
32 | 32 | |
33 | - public function setWhere($field,$value = false); |
|
33 | + public function setWhere($field,$value = false); |
|
34 | 34 | |
35 | - public function setLimit($limit); |
|
35 | + public function setLimit($limit); |
|
36 | 36 | |
37 | - public function setOfset($ofset); |
|
37 | + public function setOfset($ofset); |
|
38 | 38 | |
39 | - public function setJoins($joins); |
|
39 | + public function setJoins($joins); |
|
40 | 40 | |
41 | - public function setOrder($order); |
|
41 | + public function setOrder($order); |
|
42 | 42 | |
43 | - public function setManualJoins($manualJoins); |
|
43 | + public function setManualJoins($manualJoins); |
|
44 | 44 | |
45 | - public function setGroup($group); |
|
45 | + public function setGroup($group); |
|
46 | 46 | |
47 | - public function setManualWheres($manualWheres); |
|
47 | + public function setManualWheres($manualWheres); |
|
48 | 48 | |
49 | - public function setWhereType($whereType); |
|
49 | + public function setWhereType($whereType); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function getWhereType(); |
32 | 32 | |
33 | - public function setWhere($field,$value = false); |
|
33 | + public function setWhere($field, $value = false); |
|
34 | 34 | |
35 | 35 | public function setLimit($limit); |
36 | 36 |
@@ -10,15 +10,15 @@ |
||
10 | 10 | interface RepositoryInterface |
11 | 11 | { |
12 | 12 | |
13 | - public function findById($id); |
|
13 | + public function findById($id); |
|
14 | 14 | |
15 | - public function findBySpecification(ISpecificationCriteria $specification); |
|
15 | + public function findBySpecification(ISpecificationCriteria $specification); |
|
16 | 16 | |
17 | - public function findAll(); |
|
17 | + public function findAll(); |
|
18 | 18 | |
19 | - public function findAllBySpecification(ISpecificationCriteria $specification); |
|
19 | + public function findAllBySpecification(ISpecificationCriteria $specification); |
|
20 | 20 | |
21 | - public function save(EntityInterface $Entity); |
|
21 | + public function save(EntityInterface $Entity); |
|
22 | 22 | |
23 | - public function delete(EntityInterface $Entity); |
|
23 | + public function delete(EntityInterface $Entity); |
|
24 | 24 | } |
@@ -14,13 +14,13 @@ |
||
14 | 14 | */ |
15 | 15 | interface QueryBuilderInterface { |
16 | 16 | |
17 | - public function getResultQuery($table,\SimpleORM\ISpecificationCriteria $Criteria); |
|
17 | + public function getResultQuery($table, \SimpleORM\ISpecificationCriteria $Criteria); |
|
18 | 18 | |
19 | - public function update($table,array $data,$where = []); |
|
19 | + public function update($table, array $data, $where = []); |
|
20 | 20 | |
21 | - public function insert($table,array $data); |
|
21 | + public function insert($table, array $data); |
|
22 | 22 | |
23 | 23 | public function insert_id(); |
24 | 24 | |
25 | - public function delete($table,$where = []); |
|
25 | + public function delete($table, $where = []); |
|
26 | 26 | } |
@@ -8,12 +8,12 @@ |
||
8 | 8 | */ |
9 | 9 | interface EntityInterface |
10 | 10 | { |
11 | - //put your code here |
|
12 | - public function getId(); |
|
11 | + //put your code here |
|
12 | + public function getId(); |
|
13 | 13 | |
14 | - public function setId($id); |
|
14 | + public function setId($id); |
|
15 | 15 | |
16 | - public function getDeleted(); |
|
16 | + public function getDeleted(); |
|
17 | 17 | |
18 | - public function setDeleted($delete); |
|
18 | + public function setDeleted($delete); |
|
19 | 19 | } |
@@ -71,8 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | if(!$like){ |
73 | 73 | return $this->adapter->escape_str($str); |
74 | - } |
|
75 | - else{ |
|
74 | + } else{ |
|
76 | 75 | return $this->adapter->escape_like_str($str); |
77 | 76 | } |
78 | 77 | |
@@ -145,8 +144,7 @@ discard block |
||
145 | 144 | if(preg_match('~(.*?)\.(.*?)$~is',$table,$m)){ |
146 | 145 | $this->database = $m[1]; |
147 | 146 | $this->TableName = $m[2]; |
148 | - } |
|
149 | - else{ |
|
147 | + } else{ |
|
150 | 148 | $this->TableName = $table; |
151 | 149 | } |
152 | 150 | } |
@@ -66,6 +66,9 @@ discard block |
||
66 | 66 | return $this->adapter->delete($table,$where); |
67 | 67 | } |
68 | 68 | |
69 | + /** |
|
70 | + * @param string $str |
|
71 | + */ |
|
69 | 72 | protected function escape_str($str, $like = FALSE) |
70 | 73 | { |
71 | 74 | |
@@ -120,7 +123,6 @@ discard block |
||
120 | 123 | |
121 | 124 | /** |
122 | 125 | * |
123 | - * @param type $param |
|
124 | 126 | */ |
125 | 127 | public function getResultQuery($table,\SimpleORM\ISpecificationCriteria $Criteria ) { |
126 | 128 | |
@@ -156,6 +158,7 @@ discard block |
||
156 | 158 | /** |
157 | 159 | * Создает селект не только для основной таблицы но и для приджойненых таблиц |
158 | 160 | * @param type $joins |
161 | + * @param string $manualSelect |
|
159 | 162 | * @return type |
160 | 163 | */ |
161 | 164 | protected function createSelect(array $joins,$manualSelect) |
@@ -173,8 +176,8 @@ discard block |
||
173 | 176 | /** |
174 | 177 | * Получение записей по условию |
175 | 178 | * @param type $where |
176 | - * @param type $limit |
|
177 | - * @param type $offset |
|
179 | + * @param integer $limit |
|
180 | + * @param integer $offset |
|
178 | 181 | * @param type $joins |
179 | 182 | * @param type $order |
180 | 183 | * @param type $manualJoins |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | protected function escape($str) |
39 | 39 | { |
40 | 40 | if (is_string($str)) { |
41 | - $str = "'" . $this->escape_str($str) . "'"; |
|
41 | + $str = "'".$this->escape_str($str)."'"; |
|
42 | 42 | } elseif (is_bool($str)) { |
43 | - $str = ($str === FALSE) ? 0 : 1; |
|
43 | + $str = ($str===FALSE) ? 0 : 1; |
|
44 | 44 | } elseif (is_null($str)) { |
45 | 45 | $str = 'NULL'; |
46 | 46 | } |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | return $str; |
49 | 49 | } |
50 | 50 | |
51 | - public function update($table,array $data,$where = []){ |
|
52 | - return $this->adapter->update($table,$data,$where); |
|
51 | + public function update($table, array $data, $where = []) { |
|
52 | + return $this->adapter->update($table, $data, $where); |
|
53 | 53 | } |
54 | 54 | |
55 | - public function insert($table,array $data) |
|
55 | + public function insert($table, array $data) |
|
56 | 56 | { |
57 | - return $this->adapter->insert($table,$data); |
|
57 | + return $this->adapter->insert($table, $data); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function insert_id() |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | return $this->adapter->insert_id(); |
63 | 63 | } |
64 | 64 | |
65 | - public function delete($table,$where = []){ |
|
66 | - return $this->adapter->delete($table,$where); |
|
65 | + public function delete($table, $where = []) { |
|
66 | + return $this->adapter->delete($table, $where); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | protected function escape_str($str, $like = FALSE) |
70 | 70 | { |
71 | 71 | |
72 | - if(!$like){ |
|
72 | + if (!$like) { |
|
73 | 73 | return $this->adapter->escape_str($str); |
74 | 74 | } |
75 | - else{ |
|
75 | + else { |
|
76 | 76 | return $this->adapter->escape_like_str($str); |
77 | 77 | } |
78 | 78 | |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | throw new HttpException('You cannot have an empty field name.'); |
112 | 112 | } |
113 | 113 | |
114 | - if (strpos($field, '.') === false) { |
|
115 | - return $this->TableName . '.' . $field; |
|
114 | + if (strpos($field, '.')===false) { |
|
115 | + return $this->TableName.'.'.$field; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $field; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param type $param |
124 | 124 | */ |
125 | - public function getResultQuery($table,\SimpleORM\ISpecificationCriteria $Criteria ) { |
|
125 | + public function getResultQuery($table, \SimpleORM\ISpecificationCriteria $Criteria) { |
|
126 | 126 | |
127 | 127 | $this->setTable($table); |
128 | 128 | |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | return $res; |
143 | 143 | } |
144 | 144 | |
145 | - protected function setTable($table){ |
|
146 | - if(preg_match('~(.*?)\.(.*?)$~is',$table,$m)){ |
|
145 | + protected function setTable($table) { |
|
146 | + if (preg_match('~(.*?)\.(.*?)$~is', $table, $m)) { |
|
147 | 147 | $this->database = $m[1]; |
148 | 148 | $this->TableName = $m[2]; |
149 | 149 | } |
150 | - else{ |
|
150 | + else { |
|
151 | 151 | $this->TableName = $table; |
152 | 152 | } |
153 | 153 | } |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * @param type $joins |
159 | 159 | * @return type |
160 | 160 | */ |
161 | - protected function createSelect(array $joins,$manualSelect) |
|
161 | + protected function createSelect(array $joins, $manualSelect) |
|
162 | 162 | { |
163 | - $s = !empty($manualSelect) ? $manualSelect :"`" . $this->TableName . '`.*'; |
|
163 | + $s = !empty($manualSelect) ? $manualSelect : "`".$this->TableName.'`.*'; |
|
164 | 164 | |
165 | 165 | foreach ($joins as $table => $join) { |
166 | - $table = isset($join['alias']) ? "`{$join['alias']}`": $table; |
|
166 | + $table = isset($join['alias']) ? "`{$join['alias']}`" : $table; |
|
167 | 167 | $s .= ", $table.*"; |
168 | 168 | } |
169 | 169 | return $s; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function buildQuery($where = array(), $limit = 25, $offset = 0, $joins = array(), $order = array(), $manualJoins = array(), $group = null, $manualWheres = array(), $whereType = 'AND', $manualSelect = '') |
188 | 188 | { |
189 | - $table = !empty($this->database)? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
190 | - $query = 'SELECT ' . $this->createSelect($joins, $manualSelect) . " FROM `".$table."`"; |
|
189 | + $table = !empty($this->database) ? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
190 | + $query = 'SELECT '.$this->createSelect($joins, $manualSelect)." FROM `".$table."`"; |
|
191 | 191 | //$countQuery = "SELECT COUNT(*) AS cnt FROM `{$this->database}`.".$this->getTableName(); |
192 | 192 | |
193 | 193 | $wheres = array(); |
@@ -197,15 +197,15 @@ discard block |
||
197 | 197 | |
198 | 198 | if (!is_array($value)) { |
199 | 199 | $params[] = $value; |
200 | - $wheres[] = $key . ' = ?'; |
|
200 | + $wheres[] = $key.' = ?'; |
|
201 | 201 | } else { |
202 | 202 | if (isset($value['operator'])) { |
203 | 203 | if (is_array($value['value'])) { |
204 | - if ($value['operator'] == 'between') { |
|
204 | + if ($value['operator']=='between') { |
|
205 | 205 | $params[] = $value['value'][0]; |
206 | 206 | $params[] = $value['value'][1]; |
207 | - $wheres[] = $key . ' BETWEEN ? AND ?'; |
|
208 | - } elseif ($value['operator'] == 'IN') { |
|
207 | + $wheres[] = $key.' BETWEEN ? AND ?'; |
|
208 | + } elseif ($value['operator']=='IN') { |
|
209 | 209 | $in = array(); |
210 | 210 | |
211 | 211 | foreach ($value['value'] as $item) { |
@@ -213,67 +213,67 @@ discard block |
||
213 | 213 | $in[] = '?'; |
214 | 214 | } |
215 | 215 | |
216 | - $wheres[] = $key . ' IN (' . implode(', ', $in) . ') '; |
|
216 | + $wheres[] = $key.' IN ('.implode(', ', $in).') '; |
|
217 | 217 | } else { |
218 | 218 | $ors = array(); |
219 | 219 | foreach ($value['value'] as $item) { |
220 | - if ($item == 'null') { |
|
220 | + if ($item=='null') { |
|
221 | 221 | switch ($value['operator']) { |
222 | 222 | case '!=': |
223 | - $ors[] = $key . ' IS NOT NULL'; |
|
223 | + $ors[] = $key.' IS NOT NULL'; |
|
224 | 224 | break; |
225 | 225 | |
226 | 226 | case '==': |
227 | 227 | default: |
228 | - $ors[] = $key . ' IS NULL'; |
|
228 | + $ors[] = $key.' IS NULL'; |
|
229 | 229 | break; |
230 | 230 | } |
231 | 231 | } else { |
232 | 232 | $params[] = $item; |
233 | - $ors[] = $this->fieldCheck($key) . ' ' . $value['operator'] . ' ?'; |
|
233 | + $ors[] = $this->fieldCheck($key).' '.$value['operator'].' ?'; |
|
234 | 234 | } |
235 | 235 | } |
236 | - $wheres[] = '(' . implode(' OR ', $ors) . ')'; |
|
236 | + $wheres[] = '('.implode(' OR ', $ors).')'; |
|
237 | 237 | } |
238 | 238 | } else { |
239 | - if ($value['operator'] == 'like') { |
|
240 | - $params[] = '%' . $value['value'] . '%'; |
|
241 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
239 | + if ($value['operator']=='like') { |
|
240 | + $params[] = '%'.$value['value'].'%'; |
|
241 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
242 | 242 | } else { |
243 | - if ($value['value'] === 'null') { |
|
243 | + if ($value['value']==='null') { |
|
244 | 244 | switch ($value['operator']) { |
245 | 245 | case '!=': |
246 | - $wheres[] = $key . ' IS NOT NULL'; |
|
246 | + $wheres[] = $key.' IS NOT NULL'; |
|
247 | 247 | break; |
248 | 248 | |
249 | 249 | case '==': |
250 | 250 | default: |
251 | - $wheres[] = $key . ' IS NULL'; |
|
251 | + $wheres[] = $key.' IS NULL'; |
|
252 | 252 | break; |
253 | 253 | } |
254 | 254 | } else { |
255 | 255 | $params[] = $value['value']; |
256 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
256 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | } else { |
261 | - $wheres[] = $key . ' IN (' . implode(', ', array_map(array($this, 'escape'), $value)) . ')'; |
|
261 | + $wheres[] = $key.' IN ('.implode(', ', array_map(array($this, 'escape'), $value)).')'; |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | 266 | if (count($joins)) { |
267 | 267 | foreach ($joins as $table => $join) { |
268 | - $type = isset($join['type'])?$join['type']:'INNER'; |
|
269 | - $query .= ' '. $type.' JOIN `' . $table . '` as `' . $join['alias'] . '` ON ' . $join['on'] . ' '; |
|
268 | + $type = isset($join['type']) ? $join['type'] : 'INNER'; |
|
269 | + $query .= ' '.$type.' JOIN `'.$table.'` as `'.$join['alias'].'` ON '.$join['on'].' '; |
|
270 | 270 | //$countQuery .= ' '.$type.' JOIN ' . $table . ' ' . $join['alias'] . ' ON ' . $join['on'] . ' '; |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | if (count($manualJoins)) { |
275 | 275 | foreach ($manualJoins as $join) { |
276 | - $query .= ' ' . $join . ' '; |
|
276 | + $query .= ' '.$join.' '; |
|
277 | 277 | //$countQuery .= ' ' . $join . ' '; |
278 | 278 | } |
279 | 279 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $hasWhere = false; |
282 | 282 | if (count($wheres)) { |
283 | 283 | $hasWhere = true; |
284 | - $query .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
|
284 | + $query .= ' WHERE ('.implode(' '.$whereType.' ', $wheres).')'; |
|
285 | 285 | //$countQuery .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
286 | 286 | } |
287 | 287 | |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | $query .= ' WHERE '; |
293 | 293 | //$countQuery .= ' WHERE '; |
294 | 294 | } else { |
295 | - $query .= ' ' . $where['type'] . ' '; |
|
295 | + $query .= ' '.$where['type'].' '; |
|
296 | 296 | //$countQuery .= ' ' . $where['type'] . ' '; |
297 | 297 | } |
298 | 298 | |
299 | - $query .= ' ' . $where['query']; |
|
299 | + $query .= ' '.$where['query']; |
|
300 | 300 | //$countQuery .= ' ' . $where['query']; |
301 | 301 | |
302 | 302 | if (isset($where['params'])) { |
@@ -308,28 +308,28 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | if (!is_null($group)) { |
311 | - $query .= ' GROUP BY ' . $group . ' '; |
|
311 | + $query .= ' GROUP BY '.$group.' '; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | if (count($order)) { |
315 | 315 | $orders = array(); |
316 | - if (is_string($order) && $order == 'rand') { |
|
316 | + if (is_string($order) && $order=='rand') { |
|
317 | 317 | $query .= ' ORDER BY RAND() '; |
318 | 318 | } else { |
319 | 319 | foreach ($order as $key => $value) { |
320 | - $orders[] = $this->fieldCheck($key) . ' ' . $value; |
|
320 | + $orders[] = $this->fieldCheck($key).' '.$value; |
|
321 | 321 | } |
322 | 322 | |
323 | - $query .= ' ORDER BY ' . implode(', ', $orders); |
|
323 | + $query .= ' ORDER BY '.implode(', ', $orders); |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | 327 | if ($limit) { |
328 | - $query .= ' LIMIT ' . $limit; |
|
328 | + $query .= ' LIMIT '.$limit; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | if ($offset) { |
332 | - $query .= ' OFFSET ' . $offset; |
|
332 | + $query .= ' OFFSET '.$offset; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | try { |
348 | 348 | //$query = $this->compile_binds($query, $params); |
349 | 349 | |
350 | - return $this->adapter->query($query,$params); |
|
350 | + return $this->adapter->query($query, $params); |
|
351 | 351 | //ed( $this->adapter->query($query) ,1); |
352 | 352 | // if ($res = $this->adapter->getRows($query)) { |
353 | 353 | // $rtn = array(); |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | // } else { |
362 | 362 | // return false; |
363 | 363 | // } |
364 | - } catch(\PDOException $ex) { |
|
364 | + } catch (\PDOException $ex) { |
|
365 | 365 | throw $ex; |
366 | 366 | } |
367 | 367 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | protected function compile_binds($sql, $binds) |
378 | 378 | { |
379 | - if (strpos($sql, $this->bind_marker) === FALSE) { |
|
379 | + if (strpos($sql, $this->bind_marker)===FALSE) { |
|
380 | 380 | return $sql; |
381 | 381 | } |
382 | 382 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | //----------------- |
59 | 59 | $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
60 | 60 | |
61 | - $this->assertEquals($mapping_fields, $correct); |
|
61 | + $this->assertEquals($mapping_fields, $correct); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | //----------------- |
78 | 78 | $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
79 | 79 | |
80 | - $this->assertEquals($mapping_fields, $correct); |
|
80 | + $this->assertEquals($mapping_fields, $correct); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | //----------------- |
99 | 99 | $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
100 | 100 | |
101 | - $this->assertEquals($mapping_fields, $correct); |
|
101 | + $this->assertEquals($mapping_fields, $correct); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | //----------------- |
122 | 122 | $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
123 | 123 | |
124 | - $this->assertEquals($mapping_fields, $correct); |
|
124 | + $this->assertEquals($mapping_fields, $correct); |
|
125 | 125 | |
126 | 126 | $key_field = \TestHelper::getProtectedAttribute($this->object,'key'); |
127 | 127 | $this->assertEquals($key_field, 'tb_mayfield'); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | //----------------- |
148 | 148 | $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
149 | 149 | |
150 | - $this->assertEquals($mapping_fields, $correct); |
|
150 | + $this->assertEquals($mapping_fields, $correct); |
|
151 | 151 | |
152 | 152 | $soft_delete_key = \TestHelper::getProtectedAttribute($this->object,'soft_delete_key'); |
153 | 153 | $this->assertEquals($soft_delete_key, 'tb_mayfield'); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // ])//в конструктор |
29 | 29 | ->disableOriginalConstructor() |
30 | 30 | //->setMethods(null) |
31 | - ->setMethods(['setMappingFields','createEntity']) |
|
31 | + ->setMethods(['setMappingFields', 'createEntity']) |
|
32 | 32 | //->setMethods(null) //не использовать заглушки методов иначе буде возвращать NULL |
33 | 33 | ->getMock(); |
34 | 34 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @covers SimpleORM\AbstractDataMapper::AddMappingField |
47 | 47 | */ |
48 | - public function testAddMappingField_SimpleField(){ |
|
48 | + public function testAddMappingField_SimpleField() { |
|
49 | 49 | |
50 | - \TestHelper::callMethod($this->object,'addMappingField',['myfield']); |
|
50 | + \TestHelper::callMethod($this->object, 'addMappingField', ['myfield']); |
|
51 | 51 | |
52 | 52 | $correct = [ |
53 | 53 | 'myfield' => [ |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ]; |
57 | 57 | |
58 | 58 | //----------------- |
59 | - $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
59 | + $mapping_fields = \TestHelper::getProtectedAttribute($this->object, 'mapping_fields'); |
|
60 | 60 | |
61 | 61 | $this->assertEquals($mapping_fields, $correct); |
62 | 62 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @covers SimpleORM\AbstractDataMapper::AddMappingField |
66 | 66 | */ |
67 | - public function testAddMappingField_FieldAndAlias(){ |
|
67 | + public function testAddMappingField_FieldAndAlias() { |
|
68 | 68 | |
69 | - \TestHelper::callMethod($this->object,'addMappingField',['myfield','tb_mayfield']); |
|
69 | + \TestHelper::callMethod($this->object, 'addMappingField', ['myfield', 'tb_mayfield']); |
|
70 | 70 | |
71 | 71 | $correct = [ |
72 | 72 | 'myfield' => [ |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ]; |
76 | 76 | |
77 | 77 | //----------------- |
78 | - $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
78 | + $mapping_fields = \TestHelper::getProtectedAttribute($this->object, 'mapping_fields'); |
|
79 | 79 | |
80 | 80 | $this->assertEquals($mapping_fields, $correct); |
81 | 81 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @covers SimpleORM\AbstractDataMapper::AddMappingField |
85 | 85 | */ |
86 | - public function testAddMappingField_ArrayField(){ |
|
86 | + public function testAddMappingField_ArrayField() { |
|
87 | 87 | |
88 | - \TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
|
88 | + \TestHelper::callMethod($this->object, 'addMappingField', ['myfield', [ |
|
89 | 89 | 'field' => 'tb_mayfield' |
90 | 90 | ]]); |
91 | 91 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | ]; |
97 | 97 | |
98 | 98 | //----------------- |
99 | - $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
99 | + $mapping_fields = \TestHelper::getProtectedAttribute($this->object, 'mapping_fields'); |
|
100 | 100 | |
101 | 101 | $this->assertEquals($mapping_fields, $correct); |
102 | 102 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @covers SimpleORM\AbstractDataMapper::AddMappingField |
106 | 106 | */ |
107 | - public function testAddMappingField_PrimaryKey(){ |
|
107 | + public function testAddMappingField_PrimaryKey() { |
|
108 | 108 | |
109 | - \TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
|
109 | + \TestHelper::callMethod($this->object, 'addMappingField', ['myfield', [ |
|
110 | 110 | 'field' => 'tb_mayfield', |
111 | 111 | 'primary' => true |
112 | 112 | ]]); |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | ]; |
120 | 120 | |
121 | 121 | //----------------- |
122 | - $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
122 | + $mapping_fields = \TestHelper::getProtectedAttribute($this->object, 'mapping_fields'); |
|
123 | 123 | |
124 | 124 | $this->assertEquals($mapping_fields, $correct); |
125 | 125 | |
126 | - $key_field = \TestHelper::getProtectedAttribute($this->object,'key'); |
|
126 | + $key_field = \TestHelper::getProtectedAttribute($this->object, 'key'); |
|
127 | 127 | $this->assertEquals($key_field, 'tb_mayfield'); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @covers SimpleORM\AbstractDataMapper::AddMappingField |
132 | 132 | */ |
133 | - public function testAddMappingField_SoftDelete(){ |
|
133 | + public function testAddMappingField_SoftDelete() { |
|
134 | 134 | |
135 | - \TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
|
135 | + \TestHelper::callMethod($this->object, 'addMappingField', ['myfield', [ |
|
136 | 136 | 'field' => 'tb_mayfield', |
137 | 137 | 'softdelete' => true |
138 | 138 | ]]); |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | ]; |
146 | 146 | |
147 | 147 | //----------------- |
148 | - $mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
148 | + $mapping_fields = \TestHelper::getProtectedAttribute($this->object, 'mapping_fields'); |
|
149 | 149 | |
150 | 150 | $this->assertEquals($mapping_fields, $correct); |
151 | 151 | |
152 | - $soft_delete_key = \TestHelper::getProtectedAttribute($this->object,'soft_delete_key'); |
|
152 | + $soft_delete_key = \TestHelper::getProtectedAttribute($this->object, 'soft_delete_key'); |
|
153 | 153 | $this->assertEquals($soft_delete_key, 'tb_mayfield'); |
154 | 154 | } |
155 | 155 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function testGetPrimaryKey() |
160 | 160 | { |
161 | - \TestHelper::setValueprotectedProperty($this->object,'key','tst_id'); |
|
162 | - $this->assertEquals(\TestHelper::callMethod($this->object,'GetPrimaryKey'), 'tst_id'); |
|
161 | + \TestHelper::setValueprotectedProperty($this->object, 'key', 'tst_id'); |
|
162 | + $this->assertEquals(\TestHelper::callMethod($this->object, 'GetPrimaryKey'), 'tst_id'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -167,19 +167,19 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function testsetSoftDeleteKey() |
169 | 169 | { |
170 | - \TestHelper::setValueprotectedProperty($this->object,'soft_delete_key','stc_deleted'); |
|
171 | - $this->assertEquals(\TestHelper::callMethod($this->object,'setSoftDeleteKey'), 'stc_deleted'); |
|
170 | + \TestHelper::setValueprotectedProperty($this->object, 'soft_delete_key', 'stc_deleted'); |
|
171 | + $this->assertEquals(\TestHelper::callMethod($this->object, 'setSoftDeleteKey'), 'stc_deleted'); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
175 | 175 | * @covers SimpleORM\AbstractDataMapper::getFieldAlias |
176 | 176 | */ |
177 | - public function testGetFieldAlias(){ |
|
177 | + public function testGetFieldAlias() { |
|
178 | 178 | $mapping_fields_aliases = [ |
179 | 179 | 'name' => 'stc_fullname' |
180 | 180 | ]; |
181 | - \TestHelper::setValueprotectedProperty($this->object,'mapping_fields_aliases',$mapping_fields_aliases); |
|
182 | - $this->assertEquals(\TestHelper::callMethod($this->object,'getFieldAlias',['name']), 'stc_fullname'); |
|
181 | + \TestHelper::setValueprotectedProperty($this->object, 'mapping_fields_aliases', $mapping_fields_aliases); |
|
182 | + $this->assertEquals(\TestHelper::callMethod($this->object, 'getFieldAlias', ['name']), 'stc_fullname'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | $loader = require_once __DIR__.'/../vendor/autoload.php'; |
3 | 3 | |
4 | -class TestHelper{ |
|
4 | +class TestHelper { |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * получение защищенного свойства |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | |
6 | 6 | /** |
7 | 7 | * получение защищенного свойства |
8 | - * @param type $o |
|
9 | - * @param type $name |
|
8 | + * @param string $name |
|
9 | + * @param SimpleORM\AbstractDataMapper $obj |
|
10 | 10 | * @return type |
11 | 11 | */ |
12 | 12 | static public function getProtectedAttribute($obj, $name) |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Добавление значения в защищенное свойтсво |
22 | - * @param type $name |
|
23 | - * @param type $valued |
|
22 | + * @param string $name |
|
23 | + * @param type $value |
|
24 | + * @param SimpleORM\AbstractDataMapper $obj |
|
24 | 25 | */ |
25 | 26 | static public function setValueprotectedProperty($obj, $name, $value) |
26 | 27 | { |
@@ -30,6 +31,10 @@ discard block |
||
30 | 31 | $r->setValue($obj, $value); //изменяем значение |
31 | 32 | } |
32 | 33 | |
34 | + /** |
|
35 | + * @param SimpleORM\AbstractDataMapper $obj |
|
36 | + * @param string $name |
|
37 | + */ |
|
33 | 38 | static public function callMethod($obj, $name, array $args = []) { |
34 | 39 | $class = new \ReflectionClass($obj); |
35 | 40 | $method = $class->getMethod($name); |
@@ -3,38 +3,38 @@ |
||
3 | 3 | |
4 | 4 | class TestHelper{ |
5 | 5 | |
6 | - /** |
|
7 | - * получение защищенного свойства |
|
8 | - * @param type $o |
|
9 | - * @param type $name |
|
10 | - * @return type |
|
11 | - */ |
|
12 | - static public function getProtectedAttribute($obj, $name) |
|
13 | - { |
|
14 | - $reflectionClass = new \ReflectionClass($obj); //создаем reflectionClass |
|
15 | - $r = $reflectionClass->getProperty($name); //получаем свойство |
|
16 | - $r->setAccessible(true); //делаем открытым |
|
17 | - return $r->getValue($obj); |
|
18 | - } |
|
6 | + /** |
|
7 | + * получение защищенного свойства |
|
8 | + * @param type $o |
|
9 | + * @param type $name |
|
10 | + * @return type |
|
11 | + */ |
|
12 | + static public function getProtectedAttribute($obj, $name) |
|
13 | + { |
|
14 | + $reflectionClass = new \ReflectionClass($obj); //создаем reflectionClass |
|
15 | + $r = $reflectionClass->getProperty($name); //получаем свойство |
|
16 | + $r->setAccessible(true); //делаем открытым |
|
17 | + return $r->getValue($obj); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * Добавление значения в защищенное свойтсво |
|
22 | - * @param type $name |
|
23 | - * @param type $valued |
|
24 | - */ |
|
25 | - static public function setValueprotectedProperty($obj, $name, $value) |
|
26 | - { |
|
27 | - $reflectionClass = new \ReflectionClass($obj); //создаем reflectionClass |
|
28 | - $r = $reflectionClass->getProperty($name); //получаем свойство |
|
29 | - $r->setAccessible(true); //делаем открытым |
|
30 | - $r->setValue($obj, $value); //изменяем значение |
|
31 | - } |
|
20 | + /** |
|
21 | + * Добавление значения в защищенное свойтсво |
|
22 | + * @param type $name |
|
23 | + * @param type $valued |
|
24 | + */ |
|
25 | + static public function setValueprotectedProperty($obj, $name, $value) |
|
26 | + { |
|
27 | + $reflectionClass = new \ReflectionClass($obj); //создаем reflectionClass |
|
28 | + $r = $reflectionClass->getProperty($name); //получаем свойство |
|
29 | + $r->setAccessible(true); //делаем открытым |
|
30 | + $r->setValue($obj, $value); //изменяем значение |
|
31 | + } |
|
32 | 32 | |
33 | 33 | static public function callMethod($obj, $name, array $args = []) { |
34 | - $class = new \ReflectionClass($obj); |
|
35 | - $method = $class->getMethod($name); |
|
36 | - $method->setAccessible(true); |
|
37 | - return $method->invokeArgs($obj, $args); |
|
38 | - } |
|
34 | + $class = new \ReflectionClass($obj); |
|
35 | + $method = $class->getMethod($name); |
|
36 | + $method->setAccessible(true); |
|
37 | + return $method->invokeArgs($obj, $args); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
@@ -18,6 +18,10 @@ |
||
18 | 18 | |
19 | 19 | protected $title; |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $code |
|
23 | + * @param string $title |
|
24 | + */ |
|
21 | 25 | function __construct($code,$title){ |
22 | 26 | $this->setCode($code); |
23 | 27 | $this->setTitle($title); |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | protected $title; |
20 | 20 | |
21 | - function __construct($code,$title){ |
|
21 | + function __construct($code, $title) { |
|
22 | 22 | $this->setCode($code); |
23 | 23 | $this->setTitle($title); |
24 | 24 | } |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * Подготавливаем конечный вариант Сущности |
305 | 305 | * |
306 | - * @param \Core\Infrastructure\EntityInterface $Entity |
|
306 | + * @param EntityInterface $Entity |
|
307 | 307 | * @param array $row |
308 | - * @return \Core\Infrastructure\EntityInterface |
|
308 | + * @return EntityInterface |
|
309 | 309 | * @throws BadMethodCallException |
310 | 310 | */ |
311 | 311 | protected function buildEntity(EntityInterface $Entity, array $row){ |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | |
356 | 356 | /** |
357 | 357 | * из объекта формирует массив |
358 | - * @param \Core\Infrastructure\EntityInterface $Entity |
|
358 | + * @param EntityInterface $Entity |
|
359 | 359 | * @return \Core\Infrastructure\EntityInterface |
360 | 360 | * @throws BadMethodCallException |
361 | 361 | */ |
@@ -400,6 +400,7 @@ discard block |
||
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Установка поля для маппинга |
403 | + * @param string $alias |
|
403 | 404 | */ |
404 | 405 | protected function addMappingField($alias,$field = null){ |
405 | 406 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * таблица для сущности |
24 | 24 | * @var type |
25 | 25 | */ |
26 | - protected $entityTable; |
|
26 | + protected $entityTable; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * первичный ключ |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | |
99 | 99 | abstract protected function setMappingFields(); |
100 | 100 | |
101 | - public function getAdapter() { |
|
102 | - return $this->adapter; |
|
103 | - } |
|
101 | + public function getAdapter() { |
|
102 | + return $this->adapter; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | public function setAdapter(QueryBuilderInterface $adapter){ |
106 | 106 | $this->adapter = $adapter; |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | * @param type $id |
124 | 124 | * @return type |
125 | 125 | */ |
126 | - public function findById($id) |
|
127 | - { |
|
126 | + public function findById($id) |
|
127 | + { |
|
128 | 128 | $Criteria = (new Specification())->setWhere($this->key , $id); |
129 | 129 | |
130 | - return $this->findBySpecification($Criteria); |
|
131 | - } |
|
130 | + return $this->findBySpecification($Criteria); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Сохранение сущности без спобытий |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | protected function buildEntity(EntityInterface $Entity, array $row){ |
258 | 258 | |
259 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
259 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
260 | 260 | |
261 | 261 | $value = false; |
262 | 262 | |
@@ -299,9 +299,9 @@ discard block |
||
299 | 299 | if($value!==false) |
300 | 300 | $Entity->{$method_set}($value); |
301 | 301 | |
302 | - } |
|
302 | + } |
|
303 | 303 | |
304 | - return $Entity; |
|
304 | + return $Entity; |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | $row = []; |
317 | 317 | |
318 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
318 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
319 | 319 | |
320 | 320 | $field = $cfg['field']; |
321 | 321 | |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | |
346 | 346 | $row[$field] = $value; |
347 | 347 | |
348 | - } |
|
348 | + } |
|
349 | 349 | |
350 | - return $row; |
|
350 | + return $row; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | //получение записей |
432 | 432 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
433 | 433 | |
434 | - if (!$row = $res->row_array()) { |
|
435 | - return null; |
|
436 | - } |
|
434 | + if (!$row = $res->row_array()) { |
|
435 | + return null; |
|
436 | + } |
|
437 | 437 | |
438 | 438 | if($this->result_array===true){ |
439 | 439 | return $row; |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
483 | 483 | |
484 | 484 | if (!$rows = $res->result_array()) { |
485 | - return null; |
|
486 | - } |
|
485 | + return null; |
|
486 | + } |
|
487 | 487 | |
488 | 488 | if($this->result_array===true){ |
489 | 489 | return $rows; |
@@ -138,7 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | $data = $this->unbuildEntity($Entity); |
140 | 140 | |
141 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
141 | + if(method_exists($this, 'onPrepareData' )) { |
|
142 | + $this->onPrepareData( $Entity , $data ); |
|
143 | + } |
|
142 | 144 | |
143 | 145 | $id = $data[$this->getPrimaryKey()]; |
144 | 146 | unset($data[$this->getPrimaryKey()]); |
@@ -174,13 +176,17 @@ discard block |
||
174 | 176 | */ |
175 | 177 | public function save(EntityInterface $Entity) |
176 | 178 | { |
177 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
179 | + if(method_exists($this, 'onAfterSave' )) { |
|
180 | + $this->onAfterSave( $Entity ); |
|
181 | + } |
|
178 | 182 | |
179 | 183 | if(!$this->saveWithoutEvents($Entity)){ |
180 | 184 | return false; |
181 | 185 | } |
182 | 186 | |
183 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
187 | + if(method_exists($this, 'onBeforeSave' )) { |
|
188 | + $this->onBeforeSave( $Entity ); |
|
189 | + } |
|
184 | 190 | |
185 | 191 | return true; |
186 | 192 | } |
@@ -214,8 +220,7 @@ discard block |
||
214 | 220 | if(count($rel['relations'])>0){ |
215 | 221 | $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()'); |
216 | 222 | $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
217 | - } |
|
218 | - else{ |
|
223 | + } else{ |
|
219 | 224 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
220 | 225 | } |
221 | 226 | } |
@@ -295,19 +300,18 @@ discard block |
||
295 | 300 | // $value |
296 | 301 | // ]); |
297 | 302 | |
298 | - } |
|
299 | - else{ |
|
303 | + } else{ |
|
300 | 304 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
301 | 305 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
302 | 306 | } |
303 | 307 | |
304 | - } |
|
305 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
308 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
306 | 309 | $value = $row[strtolower($field)]; |
307 | 310 | } |
308 | 311 | |
309 | - if($value!==false) |
|
310 | - $Entity->{$method_set}($value); |
|
312 | + if($value!==false) { |
|
313 | + $Entity->{$method_set}($value); |
|
314 | + } |
|
311 | 315 | |
312 | 316 | } |
313 | 317 | |
@@ -345,18 +349,17 @@ discard block |
||
345 | 349 | //-------------------------------------------------------------------- |
346 | 350 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
347 | 351 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
348 | - } |
|
349 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
352 | + } elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
350 | 353 | |
351 | - if(isset($cfg['on'])) |
|
352 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
353 | - else |
|
354 | - $fkey = 'id'; |
|
354 | + if(isset($cfg['on'])) { |
|
355 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
356 | + } else { |
|
357 | + $fkey = 'id'; |
|
358 | + } |
|
355 | 359 | |
356 | 360 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
357 | 361 | |
358 | - } |
|
359 | - else{ |
|
362 | + } else{ |
|
360 | 363 | $value = $Entity->{$method_get}(); |
361 | 364 | } |
362 | 365 | |
@@ -374,8 +377,7 @@ discard block |
||
374 | 377 | |
375 | 378 | if(is_string($field)){ |
376 | 379 | $field = ['field' => $field]; |
377 | - } |
|
378 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
380 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
379 | 381 | $field['field'] = $alias; |
380 | 382 | } |
381 | 383 | |
@@ -475,8 +477,7 @@ discard block |
||
475 | 477 | $delete_key > '' && |
476 | 478 | $Entity->getId() > 0){ |
477 | 479 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
478 | - } |
|
479 | - elseif($Entity->getId() > 0){ |
|
480 | + } elseif($Entity->getId() > 0){ |
|
480 | 481 | |
481 | 482 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
482 | 483 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -527,8 +528,9 @@ discard block |
||
527 | 528 | $this->use_delete === false && |
528 | 529 | $this->setSoftDeleteKey()>'' |
529 | 530 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
530 | - ) |
|
531 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
531 | + ) { |
|
532 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
533 | + } |
|
532 | 534 | } |
533 | 535 | |
534 | 536 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | $this->setEntityTable($db_name); |
92 | 92 | |
93 | - if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){ |
|
93 | + if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') { |
|
94 | 94 | throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы'); |
95 | 95 | } |
96 | 96 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | return $this->adapter; |
103 | 103 | } |
104 | 104 | |
105 | - public function setAdapter(QueryBuilderInterface $adapter){ |
|
105 | + public function setAdapter(QueryBuilderInterface $adapter) { |
|
106 | 106 | $this->adapter = $adapter; |
107 | 107 | } |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * Уставнока таблицы |
116 | 116 | */ |
117 | 117 | protected function setEntityTable($db_name) { |
118 | - $this->entityTable = !empty($db_name)? "$db_name.".$this->table : $this->table; |
|
118 | + $this->entityTable = !empty($db_name) ? "$db_name.".$this->table : $this->table; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function findById($id) |
127 | 127 | { |
128 | - $Criteria = (new Specification())->setWhere($this->key , $id); |
|
128 | + $Criteria = (new Specification())->setWhere($this->key, $id); |
|
129 | 129 | |
130 | 130 | return $this->findBySpecification($Criteria); |
131 | 131 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | $data = $this->unbuildEntity($Entity); |
140 | 140 | |
141 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
141 | + if (method_exists($this, 'onPrepareData')) $this->onPrepareData($Entity, $data); |
|
142 | 142 | |
143 | 143 | $id = $data[$this->getPrimaryKey()]; |
144 | 144 | unset($data[$this->getPrimaryKey()]); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | unset($data[$this->setSoftDeleteKey()]); |
150 | 150 | |
151 | - $this->getAdapter()->insert($this->getEntityTable(),$data); |
|
151 | + $this->getAdapter()->insert($this->getEntityTable(), $data); |
|
152 | 152 | |
153 | 153 | if (!$id = $this->getAdapter()->insert_id()) { |
154 | 154 | return false; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | //update |
160 | 160 | else { |
161 | 161 | |
162 | - if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){ |
|
162 | + if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function save(EntityInterface $Entity) |
176 | 176 | { |
177 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
177 | + if (method_exists($this, 'onAfterSave')) $this->onAfterSave($Entity); |
|
178 | 178 | |
179 | - if(!$this->saveWithoutEvents($Entity)){ |
|
179 | + if (!$this->saveWithoutEvents($Entity)) { |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | |
183 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
183 | + if (method_exists($this, 'onBeforeSave')) $this->onBeforeSave($Entity); |
|
184 | 184 | |
185 | 185 | return true; |
186 | 186 | } |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | * получение мапперов в порядке их использования с учетом вложенности |
191 | 191 | * @return array |
192 | 192 | */ |
193 | - protected function createListRelation(){ |
|
193 | + protected function createListRelation() { |
|
194 | 194 | $rel_list = []; |
195 | 195 | |
196 | 196 | $rel_map = $this->getRelations(); |
197 | 197 | |
198 | - $this->createListRelationReq($rel_map,$rel_list); |
|
198 | + $this->createListRelationReq($rel_map, $rel_list); |
|
199 | 199 | |
200 | 200 | return $rel_list; |
201 | 201 | } |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | * @param array $rel_map |
206 | 206 | * @param type $rel_list |
207 | 207 | */ |
208 | - protected function createListRelationReq(array $rel_map,&$rel_list,$obj_parent_link = null) { |
|
208 | + protected function createListRelationReq(array $rel_map, &$rel_list, $obj_parent_link = null) { |
|
209 | 209 | |
210 | - foreach ($rel_map as $rel){ |
|
210 | + foreach ($rel_map as $rel) { |
|
211 | 211 | |
212 | 212 | $obj_link = '#'.$rel['alias'].'()'; |
213 | 213 | |
214 | - if(count($rel['relations'])>0){ |
|
215 | - $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()'); |
|
216 | - $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
|
214 | + if (count($rel['relations']) > 0) { |
|
215 | + $this->createListRelationReq($rel['relations'], $rel_list, $obj_parent_link.'get'.$rel['alias'].'()'); |
|
216 | + $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
|
217 | 217 | } |
218 | - else{ |
|
218 | + else { |
|
219 | 219 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
220 | 220 | } |
221 | 221 | } |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * получить связи |
227 | 227 | */ |
228 | - protected function getRelations(){ |
|
228 | + protected function getRelations() { |
|
229 | 229 | $rel_map = []; |
230 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
231 | - if(isset($cfg['relation'])){ |
|
230 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
231 | + if (isset($cfg['relation'])) { |
|
232 | 232 | $rels = $this->DI->get($cfg['relation'])->getRelations(); |
233 | - $rel_map []= [ |
|
233 | + $rel_map [] = [ |
|
234 | 234 | 'name' => $cfg['relation'], |
235 | 235 | 'alias' => $field, |
236 | 236 | 'relations' => $rels |
@@ -254,23 +254,23 @@ discard block |
||
254 | 254 | * @return \Core\Infrastructure\EntityInterface |
255 | 255 | * @throws BadMethodCallException |
256 | 256 | */ |
257 | - protected function buildEntity(EntityInterface $Entity, array $row){ |
|
257 | + protected function buildEntity(EntityInterface $Entity, array $row) { |
|
258 | 258 | //ed($row); |
259 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
259 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
260 | 260 | |
261 | 261 | $value = false; |
262 | 262 | |
263 | 263 | //автоопределени формата массива |
264 | 264 | $field = $cfg['field']; |
265 | 265 | |
266 | - $method_set = 'set' . ucfirst($alias); |
|
266 | + $method_set = 'set'.ucfirst($alias); |
|
267 | 267 | |
268 | - if(!method_exists($Entity, $method_set )){ |
|
268 | + if (!method_exists($Entity, $method_set)) { |
|
269 | 269 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
270 | 270 | } |
271 | 271 | |
272 | 272 | //событие на формирование поля |
273 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
273 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
274 | 274 | |
275 | 275 | // ed([ |
276 | 276 | // get_class($Entity), |
@@ -281,11 +281,11 @@ discard block |
||
281 | 281 | $value = call_user_func($cfg['build'], $row); |
282 | 282 | } |
283 | 283 | //на связь |
284 | - elseif(isset($cfg['relation'])){ |
|
284 | + elseif (isset($cfg['relation'])) { |
|
285 | 285 | |
286 | 286 | $mapper = $this->DI->get($cfg['relation']); |
287 | 287 | |
288 | - if($this->use_joins===true || empty($row[$field])){ |
|
288 | + if ($this->use_joins===true || empty($row[$field])) { |
|
289 | 289 | |
290 | 290 | $value = $mapper->createEntity($row); |
291 | 291 | |
@@ -296,17 +296,17 @@ discard block |
||
296 | 296 | // ]); |
297 | 297 | |
298 | 298 | } |
299 | - else{ |
|
300 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
299 | + else { |
|
300 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
301 | 301 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
302 | 302 | } |
303 | 303 | |
304 | 304 | } |
305 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
305 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
306 | 306 | $value = $row[strtolower($field)]; |
307 | 307 | } |
308 | 308 | |
309 | - if($value!==false) |
|
309 | + if ($value!==false) |
|
310 | 310 | $Entity->{$method_set}($value); |
311 | 311 | |
312 | 312 | } |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | * @return \Core\Infrastructure\EntityInterface |
322 | 322 | * @throws BadMethodCallException |
323 | 323 | */ |
324 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
324 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
325 | 325 | |
326 | 326 | $row = []; |
327 | 327 | |
328 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
328 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
329 | 329 | |
330 | 330 | //автоопределени формата массива |
331 | 331 | // if(isset($row[$this->key])){ |
@@ -336,19 +336,19 @@ discard block |
||
336 | 336 | // } |
337 | 337 | $field = $cfg['field']; |
338 | 338 | |
339 | - $method_get = 'get' . ucfirst($alias); |
|
339 | + $method_get = 'get'.ucfirst($alias); |
|
340 | 340 | |
341 | - if(!method_exists($Entity, $method_get )){ |
|
341 | + if (!method_exists($Entity, $method_get)) { |
|
342 | 342 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
343 | 343 | } |
344 | 344 | |
345 | 345 | //-------------------------------------------------------------------- |
346 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
347 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
346 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
347 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
348 | 348 | } |
349 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
349 | + elseif (isset($cfg['relation']) && is_object($Entity->{$method_get}())) { |
|
350 | 350 | |
351 | - if(isset($cfg['on'])) |
|
351 | + if (isset($cfg['on'])) |
|
352 | 352 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
353 | 353 | else |
354 | 354 | $fkey = 'id'; |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
357 | 357 | |
358 | 358 | } |
359 | - else{ |
|
359 | + else { |
|
360 | 360 | $value = $Entity->{$method_get}(); |
361 | 361 | } |
362 | 362 | |
@@ -370,22 +370,22 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * Установка поля для маппинга |
372 | 372 | */ |
373 | - protected function addMappingField($alias,$field = null){ |
|
373 | + protected function addMappingField($alias, $field = null) { |
|
374 | 374 | |
375 | - if(is_string($field)){ |
|
375 | + if (is_string($field)) { |
|
376 | 376 | $field = ['field' => $field]; |
377 | 377 | } |
378 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
379 | - $field['field'] = $alias; |
|
378 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
379 | + $field['field'] = $alias; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | $this->mapping_fields[$alias] = $field; |
383 | 383 | |
384 | - if(isset($field['primary']) && $field['primary']===true){ |
|
384 | + if (isset($field['primary']) && $field['primary']===true) { |
|
385 | 385 | $this->key = $field['field']; |
386 | 386 | } |
387 | 387 | |
388 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
388 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
389 | 389 | $this->soft_delete_key = $field['field']; |
390 | 390 | } |
391 | 391 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @param type $field |
417 | 417 | * @return type |
418 | 418 | */ |
419 | - public function getFieldAlias($field){ |
|
419 | + public function getFieldAlias($field) { |
|
420 | 420 | return $this->mapping_fields_aliases[$field]; |
421 | 421 | } |
422 | 422 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @param ISpecificationCriteria $specification |
437 | 437 | * @return type |
438 | 438 | */ |
439 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
439 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
440 | 440 | |
441 | 441 | //псеводо удаление |
442 | 442 | $this->setSoftDelete($specification); |
@@ -446,13 +446,13 @@ discard block |
||
446 | 446 | $specification->setLimit(1); |
447 | 447 | |
448 | 448 | //получение записей |
449 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
449 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
450 | 450 | |
451 | 451 | if (!$row = $res->row_array()) { |
452 | 452 | return null; |
453 | 453 | } |
454 | 454 | |
455 | - if($this->result_array===true){ |
|
455 | + if ($this->result_array===true) { |
|
456 | 456 | return $row; |
457 | 457 | } |
458 | 458 | |
@@ -473,13 +473,13 @@ discard block |
||
473 | 473 | |
474 | 474 | if ( |
475 | 475 | $delete_key > '' && |
476 | - $Entity->getId() > 0){ |
|
477 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
476 | + $Entity->getId() > 0) { |
|
477 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
478 | 478 | } |
479 | - elseif($Entity->getId() > 0){ |
|
479 | + elseif ($Entity->getId() > 0) { |
|
480 | 480 | |
481 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
482 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
481 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
482 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
@@ -496,17 +496,17 @@ discard block |
||
496 | 496 | |
497 | 497 | $this->setRelations($specification); |
498 | 498 | |
499 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
499 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
500 | 500 | |
501 | 501 | if (!$rows = $res->result_array()) { |
502 | 502 | return null; |
503 | 503 | } |
504 | 504 | |
505 | - if($this->result_array===true){ |
|
505 | + if ($this->result_array===true) { |
|
506 | 506 | return $rows; |
507 | 507 | } |
508 | 508 | |
509 | - foreach($rows as $k => $row){ |
|
509 | + foreach ($rows as $k => $row) { |
|
510 | 510 | $rows[$k] = $this->createEntity($row); |
511 | 511 | } |
512 | 512 | |
@@ -522,13 +522,13 @@ discard block |
||
522 | 522 | * Выборка удаленных моделей |
523 | 523 | * @param ISpecificationCriteria $specification |
524 | 524 | */ |
525 | - protected function setSoftDelete(ISpecificationCriteria $specification){ |
|
526 | - if( |
|
527 | - $this->use_delete === false && |
|
528 | - $this->setSoftDeleteKey()>'' |
|
525 | + protected function setSoftDelete(ISpecificationCriteria $specification) { |
|
526 | + if ( |
|
527 | + $this->use_delete===false && |
|
528 | + $this->setSoftDeleteKey() > '' |
|
529 | 529 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
530 | 530 | ) |
531 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
531 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -539,12 +539,12 @@ discard block |
||
539 | 539 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
540 | 540 | * has_one - один к одному |
541 | 541 | */ |
542 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
542 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
543 | 543 | |
544 | 544 | $joins = []; |
545 | 545 | |
546 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
547 | - if(isset($cfg['relation'])){ |
|
546 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
547 | + if (isset($cfg['relation'])) { |
|
548 | 548 | |
549 | 549 | $reltype = isset($cfg['reltype']) ? $cfg['reltype'] : 'belongs_to'; |
550 | 550 | |
@@ -555,18 +555,18 @@ discard block |
||
555 | 555 | |
556 | 556 | $table = $mapper->getEntityTable(); |
557 | 557 | |
558 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
558 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
559 | 559 | |
560 | 560 | $joins[$table] = [ |
561 | 561 | 'alias' => $field, |
562 | - 'type' => $reltype != 'has_many' ? 'INNER' : 'LEFT OUTER', |
|
562 | + 'type' => $reltype!='has_many' ? 'INNER' : 'LEFT OUTER', |
|
563 | 563 | 'on' => "`{$this->table}`.{$cfg['field']} = `{$field}`.{$relation_key}" |
564 | 564 | ]; |
565 | 565 | |
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | - if($this->use_joins===true){ |
|
569 | + if ($this->use_joins===true) { |
|
570 | 570 | $Specification->setJoins($joins); |
571 | 571 | } |
572 | 572 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | return $o; |
582 | 582 | } |
583 | 583 | |
584 | - public function withDelete(){ |
|
584 | + public function withDelete() { |
|
585 | 585 | $o = clone $this; |
586 | 586 | $o->use_delete = true; |
587 | 587 | return $o; |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | * Данные только в массиве |
592 | 592 | * @return \SimpleORM\AbstractDataMapper |
593 | 593 | */ |
594 | - public function resultArray(){ |
|
594 | + public function resultArray() { |
|
595 | 595 | $o = clone $this; |
596 | 596 | $o->result_array = true; |
597 | 597 | return $o; |