@@ -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,29 +10,29 @@ |
||
10 | 10 | abstract class AbstractEntity implements EntityInterface |
11 | 11 | { |
12 | 12 | |
13 | - protected $id; |
|
13 | + protected $id; |
|
14 | 14 | |
15 | 15 | protected $deleted; |
16 | 16 | |
17 | 17 | public function getId() |
18 | - { |
|
19 | - return $this->id; |
|
20 | - } |
|
18 | + { |
|
19 | + return $this->id; |
|
20 | + } |
|
21 | 21 | |
22 | - public function setId($id) |
|
23 | - { |
|
24 | - if ($this->id !== null) { |
|
25 | - throw new BadMethodCallException( |
|
26 | - "Идентификатор у сущности уже установлен"); |
|
27 | - } |
|
22 | + public function setId($id) |
|
23 | + { |
|
24 | + if ($this->id !== null) { |
|
25 | + throw new BadMethodCallException( |
|
26 | + "Идентификатор у сущности уже установлен"); |
|
27 | + } |
|
28 | 28 | |
29 | - if ($id < 1) { |
|
30 | - throw new InvalidArgumentException("Неверный индентификатор"); |
|
31 | - } |
|
29 | + if ($id < 1) { |
|
30 | + throw new InvalidArgumentException("Неверный индентификатор"); |
|
31 | + } |
|
32 | 32 | |
33 | - $this->id = $id; |
|
34 | - return $this; |
|
35 | - } |
|
33 | + $this->id = $id; |
|
34 | + return $this; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public function setDeleted($deleted){ |
38 | 38 | $this->deleted = $deleted; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function setId($id) |
23 | 23 | { |
24 | - if ($this->id !== null) { |
|
24 | + if ($this->id!==null) { |
|
25 | 25 | throw new BadMethodCallException( |
26 | 26 | "Идентификатор у сущности уже установлен"); |
27 | 27 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function setDeleted($deleted){ |
|
37 | + public function setDeleted($deleted) { |
|
38 | 38 | $this->deleted = $deleted; |
39 | 39 | } |
40 | 40 |
@@ -10,134 +10,134 @@ |
||
10 | 10 | class Specification implements ISpecificationCriteria |
11 | 11 | { |
12 | 12 | |
13 | - protected $where = []; |
|
13 | + protected $where = []; |
|
14 | 14 | |
15 | - protected $limit = 0; |
|
15 | + protected $limit = 0; |
|
16 | 16 | |
17 | - protected $ofset = 0; |
|
17 | + protected $ofset = 0; |
|
18 | 18 | |
19 | - protected $joins = []; |
|
19 | + protected $joins = []; |
|
20 | 20 | |
21 | - protected $order = []; |
|
21 | + protected $order = []; |
|
22 | 22 | |
23 | - protected $manualJoins = []; |
|
23 | + protected $manualJoins = []; |
|
24 | 24 | |
25 | - protected $group = null; |
|
25 | + protected $group = null; |
|
26 | 26 | |
27 | - protected $manualWheres = []; |
|
27 | + protected $manualWheres = []; |
|
28 | 28 | |
29 | - protected $whereType = 'AND'; |
|
29 | + protected $whereType = 'AND'; |
|
30 | 30 | |
31 | - function getWhere() |
|
32 | - { |
|
33 | - return $this->where; |
|
34 | - } |
|
35 | - |
|
36 | - function getLimit() |
|
37 | - { |
|
38 | - return $this->limit; |
|
39 | - } |
|
40 | - |
|
41 | - function getOfset() |
|
42 | - { |
|
43 | - return $this->ofset; |
|
44 | - } |
|
45 | - |
|
46 | - function getJoins() |
|
47 | - { |
|
48 | - return $this->joins; |
|
49 | - } |
|
50 | - |
|
51 | - function getOrder() |
|
52 | - { |
|
53 | - return $this->order; |
|
54 | - } |
|
55 | - |
|
56 | - function getManualJoins() |
|
57 | - { |
|
58 | - return $this->manualJoins; |
|
59 | - } |
|
60 | - |
|
61 | - function getGroup() |
|
62 | - { |
|
63 | - return $this->group; |
|
64 | - } |
|
65 | - |
|
66 | - function getManualWheres() |
|
67 | - { |
|
68 | - return $this->manualWheres; |
|
69 | - } |
|
70 | - |
|
71 | - function getWhereType() |
|
72 | - { |
|
73 | - return $this->whereType; |
|
74 | - } |
|
75 | - |
|
76 | - function setWhere($field,$value = false) |
|
77 | - { |
|
78 | - if($value!==false){ |
|
79 | - $this->where[$field] = $value; |
|
80 | - } |
|
81 | - else{ |
|
82 | - $this->where = $where; |
|
83 | - } |
|
31 | + function getWhere() |
|
32 | + { |
|
33 | + return $this->where; |
|
34 | + } |
|
35 | + |
|
36 | + function getLimit() |
|
37 | + { |
|
38 | + return $this->limit; |
|
39 | + } |
|
40 | + |
|
41 | + function getOfset() |
|
42 | + { |
|
43 | + return $this->ofset; |
|
44 | + } |
|
45 | + |
|
46 | + function getJoins() |
|
47 | + { |
|
48 | + return $this->joins; |
|
49 | + } |
|
50 | + |
|
51 | + function getOrder() |
|
52 | + { |
|
53 | + return $this->order; |
|
54 | + } |
|
55 | + |
|
56 | + function getManualJoins() |
|
57 | + { |
|
58 | + return $this->manualJoins; |
|
59 | + } |
|
60 | + |
|
61 | + function getGroup() |
|
62 | + { |
|
63 | + return $this->group; |
|
64 | + } |
|
65 | + |
|
66 | + function getManualWheres() |
|
67 | + { |
|
68 | + return $this->manualWheres; |
|
69 | + } |
|
70 | + |
|
71 | + function getWhereType() |
|
72 | + { |
|
73 | + return $this->whereType; |
|
74 | + } |
|
75 | + |
|
76 | + function setWhere($field,$value = false) |
|
77 | + { |
|
78 | + if($value!==false){ |
|
79 | + $this->where[$field] = $value; |
|
80 | + } |
|
81 | + else{ |
|
82 | + $this->where = $where; |
|
83 | + } |
|
84 | 84 | |
85 | - return $this; |
|
86 | - } |
|
87 | - |
|
88 | - function setLimit($limit) |
|
89 | - { |
|
90 | - $this->limit = $limit; |
|
91 | - return $this; |
|
92 | - } |
|
93 | - |
|
94 | - function setOfset($ofset) |
|
95 | - { |
|
96 | - $this->ofset = $ofset; |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - function setJoins($joins) |
|
101 | - { |
|
102 | - $this->joins = $joins; |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - function setOrder($order) |
|
107 | - { |
|
108 | - $this->order = $order; |
|
109 | - return $this; |
|
110 | - } |
|
111 | - |
|
112 | - function setManualJoins($manualJoins) |
|
113 | - { |
|
114 | - $this->manualJoins = $manualJoins; |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - function setGroup($group) |
|
119 | - { |
|
120 | - $this->group = $group; |
|
121 | - return $this; |
|
122 | - } |
|
123 | - |
|
124 | - function setManualWheres($manualWheres) |
|
125 | - { |
|
126 | - $this->manualWheres = $manualWheres; |
|
127 | - return $this; |
|
128 | - } |
|
129 | - |
|
130 | - function setWhereType($whereType) |
|
131 | - { |
|
132 | - $this->whereType = $whereType; |
|
133 | - return $this; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Создание критериев |
|
138 | - */ |
|
139 | - public function getCriteria() |
|
140 | - { |
|
85 | + return $this; |
|
86 | + } |
|
87 | + |
|
88 | + function setLimit($limit) |
|
89 | + { |
|
90 | + $this->limit = $limit; |
|
91 | + return $this; |
|
92 | + } |
|
93 | + |
|
94 | + function setOfset($ofset) |
|
95 | + { |
|
96 | + $this->ofset = $ofset; |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + function setJoins($joins) |
|
101 | + { |
|
102 | + $this->joins = $joins; |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + function setOrder($order) |
|
107 | + { |
|
108 | + $this->order = $order; |
|
109 | + return $this; |
|
110 | + } |
|
111 | + |
|
112 | + function setManualJoins($manualJoins) |
|
113 | + { |
|
114 | + $this->manualJoins = $manualJoins; |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + function setGroup($group) |
|
119 | + { |
|
120 | + $this->group = $group; |
|
121 | + return $this; |
|
122 | + } |
|
123 | + |
|
124 | + function setManualWheres($manualWheres) |
|
125 | + { |
|
126 | + $this->manualWheres = $manualWheres; |
|
127 | + return $this; |
|
128 | + } |
|
129 | + |
|
130 | + function setWhereType($whereType) |
|
131 | + { |
|
132 | + $this->whereType = $whereType; |
|
133 | + return $this; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Создание критериев |
|
138 | + */ |
|
139 | + public function getCriteria() |
|
140 | + { |
|
141 | 141 | |
142 | - } |
|
142 | + } |
|
143 | 143 | } |
@@ -73,12 +73,12 @@ |
||
73 | 73 | return $this->whereType; |
74 | 74 | } |
75 | 75 | |
76 | - function setWhere($field,$value = false) |
|
76 | + function setWhere($field, $value = false) |
|
77 | 77 | { |
78 | - if($value!==false){ |
|
78 | + if ($value!==false) { |
|
79 | 79 | $this->where[$field] = $value; |
80 | 80 | } |
81 | - else{ |
|
81 | + else { |
|
82 | 82 | $this->where = $where; |
83 | 83 | } |
84 | 84 |
@@ -77,8 +77,7 @@ |
||
77 | 77 | { |
78 | 78 | if($value!==false){ |
79 | 79 | $this->where[$field] = $value; |
80 | - } |
|
81 | - else{ |
|
80 | + } else{ |
|
82 | 81 | $this->where = $where; |
83 | 82 | } |
84 | 83 |
@@ -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 | } |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * Подготавливаем конечный вариант Сущности |
81 | 81 | * |
82 | - * @param \Core\Infrastructure\EntityInterface $Entity |
|
82 | + * @param EntityInterface $Entity |
|
83 | 83 | * @param array $row |
84 | - * @return \Core\Infrastructure\EntityInterface |
|
84 | + * @return EntityInterface |
|
85 | 85 | * @throws BadMethodCallException |
86 | 86 | */ |
87 | 87 | protected function buildEntity(EntityInterface $Entity, array $row){ |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | /** |
133 | 133 | * из объекта формирует массив |
134 | - * @param \Core\Infrastructure\EntityInterface $Entity |
|
134 | + * @param EntityInterface $Entity |
|
135 | 135 | * @return \Core\Infrastructure\EntityInterface |
136 | 136 | * @throws BadMethodCallException |
137 | 137 | */ |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * таблица для сущности |
20 | 20 | * @var type |
21 | 21 | */ |
22 | - protected $entityTable; |
|
22 | + protected $entityTable; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * первичный ключ |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | |
89 | 89 | abstract protected function setMappingFields(); |
90 | 90 | |
91 | - public function getAdapter() { |
|
92 | - return $this->adapter; |
|
93 | - } |
|
91 | + public function getAdapter() { |
|
92 | + return $this->adapter; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | public function setAdapter(QueryBuilderInterface $adapter){ |
96 | 96 | $this->adapter = $adapter; |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | - public function findById($id) |
|
113 | - { |
|
112 | + public function findById($id) |
|
113 | + { |
|
114 | 114 | $Criteria = (new Specification())->setWhere($this->key , $id); |
115 | 115 | |
116 | - return $this->findBySpecification($Criteria); |
|
117 | - } |
|
116 | + return $this->findBySpecification($Criteria); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Cохранение сущности |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | protected function buildEntity(EntityInterface $Entity, array $row){ |
212 | 212 | |
213 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
213 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
214 | 214 | |
215 | 215 | $value = false; |
216 | 216 | |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | if($value!==false) |
248 | 248 | $Entity->{$method_set}($value); |
249 | 249 | |
250 | - } |
|
250 | + } |
|
251 | 251 | |
252 | - return $Entity; |
|
252 | + return $Entity; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | |
264 | 264 | $row = []; |
265 | 265 | |
266 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
266 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
267 | 267 | |
268 | 268 | $field = $cfg['field']; |
269 | 269 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | $row[$field] = $value; |
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - return $row; |
|
298 | + return $row; |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | //получение записей |
368 | 368 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
369 | 369 | |
370 | - if (!$row = $res->row_array()) { |
|
371 | - return null; |
|
372 | - } |
|
373 | - return $this->createEntity($row); |
|
370 | + if (!$row = $res->row_array()) { |
|
371 | + return null; |
|
372 | + } |
|
373 | + return $this->createEntity($row); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
413 | 413 | |
414 | 414 | if (!$rows = $res->result_array()) { |
415 | - return null; |
|
416 | - } |
|
415 | + return null; |
|
416 | + } |
|
417 | 417 | |
418 | 418 | foreach($rows as $k => $row){ |
419 | 419 | $rows[$k] = $this->createEntity($row); |
@@ -126,7 +126,9 @@ discard block |
||
126 | 126 | $data = $this->unbuildEntity($Entity); |
127 | 127 | |
128 | 128 | //protected function onAfterSave(\SimpleORM\EntityInterface $Entity, &$data) |
129 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity, $data ); |
|
129 | + if(method_exists($this, 'onAfterSave' )) { |
|
130 | + $this->onAfterSave( $Entity, $data ); |
|
131 | + } |
|
130 | 132 | |
131 | 133 | $id = $data[$this->getPrimaryKey()]; |
132 | 134 | unset($data[$this->getPrimaryKey()]); |
@@ -153,7 +155,9 @@ discard block |
||
153 | 155 | |
154 | 156 | } |
155 | 157 | |
156 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
158 | + if(method_exists($this, 'onBeforeSave' )) { |
|
159 | + $this->onBeforeSave( $Entity ); |
|
160 | + } |
|
157 | 161 | |
158 | 162 | |
159 | 163 | return true; |
@@ -233,19 +237,18 @@ discard block |
||
233 | 237 | |
234 | 238 | if($this->use_joins===true){ |
235 | 239 | $value = $mapper->createEntity($row); |
236 | - } |
|
237 | - else{ |
|
240 | + } else{ |
|
238 | 241 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
239 | 242 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
240 | 243 | } |
241 | 244 | |
242 | - } |
|
243 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
245 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
244 | 246 | $value = $row[strtolower($field)]; |
245 | 247 | } |
246 | 248 | |
247 | - if($value!==false) |
|
248 | - $Entity->{$method_set}($value); |
|
249 | + if($value!==false) { |
|
250 | + $Entity->{$method_set}($value); |
|
251 | + } |
|
249 | 252 | |
250 | 253 | } |
251 | 254 | |
@@ -276,18 +279,17 @@ discard block |
||
276 | 279 | //-------------------------------------------------------------------- |
277 | 280 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
278 | 281 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
279 | - } |
|
280 | - elseif(isset($cfg['relation'])){ |
|
282 | + } elseif(isset($cfg['relation'])){ |
|
281 | 283 | |
282 | - if(isset($cfg['on'])) |
|
283 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
284 | - else |
|
285 | - $fkey = 'id'; |
|
284 | + if(isset($cfg['on'])) { |
|
285 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
286 | + } else { |
|
287 | + $fkey = 'id'; |
|
288 | + } |
|
286 | 289 | |
287 | 290 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
288 | 291 | |
289 | - } |
|
290 | - else{ |
|
292 | + } else{ |
|
291 | 293 | $value = $Entity->{$method_get}(); |
292 | 294 | } |
293 | 295 | |
@@ -305,8 +307,7 @@ discard block |
||
305 | 307 | |
306 | 308 | if(is_string($field)){ |
307 | 309 | $field = ['field' => $field]; |
308 | - } |
|
309 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
310 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
310 | 311 | $field['field'] = $alias; |
311 | 312 | } |
312 | 313 | |
@@ -388,8 +389,7 @@ discard block |
||
388 | 389 | $delete_key > '' && |
389 | 390 | $Entity->getId() > 0){ |
390 | 391 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
391 | - } |
|
392 | - elseif($Entity->getId() > 0){ |
|
392 | + } elseif($Entity->getId() > 0){ |
|
393 | 393 | |
394 | 394 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
395 | 395 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -436,8 +436,9 @@ discard block |
||
436 | 436 | $this->use_delete === false && |
437 | 437 | $this->setSoftDeleteKey()>'' |
438 | 438 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
439 | - ) |
|
440 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
439 | + ) { |
|
440 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
441 | + } |
|
441 | 442 | } |
442 | 443 | |
443 | 444 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | $this->setEntityTable($db_name); |
82 | 82 | |
83 | - if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){ |
|
83 | + if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') { |
|
84 | 84 | throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы'); |
85 | 85 | } |
86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this->adapter; |
93 | 93 | } |
94 | 94 | |
95 | - public function setAdapter(QueryBuilderInterface $adapter){ |
|
95 | + public function setAdapter(QueryBuilderInterface $adapter) { |
|
96 | 96 | $this->adapter = $adapter; |
97 | 97 | } |
98 | 98 | |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | * Уставнока таблицы |
106 | 106 | */ |
107 | 107 | protected function setEntityTable($db_name) { |
108 | - $this->entityTable = !empty($db_name)? "$db_name.".$this->table : $this->table; |
|
108 | + $this->entityTable = !empty($db_name) ? "$db_name.".$this->table : $this->table; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | 112 | public function findById($id) |
113 | 113 | { |
114 | - $Criteria = (new Specification())->setWhere($this->key , $id); |
|
114 | + $Criteria = (new Specification())->setWhere($this->key, $id); |
|
115 | 115 | |
116 | 116 | return $this->findBySpecification($Criteria); |
117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $data = $this->unbuildEntity($Entity); |
127 | 127 | |
128 | 128 | //protected function onAfterSave(\SimpleORM\EntityInterface $Entity, &$data) |
129 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity, $data ); |
|
129 | + if (method_exists($this, 'onAfterSave')) $this->onAfterSave($Entity, $data); |
|
130 | 130 | |
131 | 131 | $id = $data[$this->getPrimaryKey()]; |
132 | 132 | unset($data[$this->getPrimaryKey()]); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | unset($data[$this->setSoftDeleteKey()]); |
138 | 138 | |
139 | - $this->getAdapter()->insert($this->getEntityTable(),$data); |
|
139 | + $this->getAdapter()->insert($this->getEntityTable(), $data); |
|
140 | 140 | |
141 | 141 | if (!$id = $this->getAdapter()->insert_id()) { |
142 | 142 | return false; |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | //update |
148 | 148 | else { |
149 | 149 | |
150 | - if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){ |
|
150 | + if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
155 | 155 | |
156 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
156 | + if (method_exists($this, 'onBeforeSave')) $this->onBeforeSave($Entity); |
|
157 | 157 | |
158 | 158 | |
159 | 159 | return true; |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * На успешное сохранение |
164 | 164 | * @param \SimpleORM\EntityInterface $Entity |
165 | 165 | */ |
166 | - protected function onBeforeSave(EntityInterface $Entity){ |
|
166 | + protected function onBeforeSave(EntityInterface $Entity) { |
|
167 | 167 | |
168 | 168 | foreach ($this->relations as $alias => $mapper) { |
169 | 169 | |
170 | 170 | $SaveEntity = $Entity->{'get'.$alias}(); |
171 | 171 | |
172 | - if(!$mapper->save($SaveEntity)){ |
|
172 | + if (!$mapper->save($SaveEntity)) { |
|
173 | 173 | throw new \Autoprice\Exceptions\EntityNotSaveException('Unable to save Entity!'); |
174 | 174 | } |
175 | 175 | |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | foreach ($this->relations as $alias => $cfg) { |
188 | 188 | $mapper = $cfg['mapper']; |
189 | 189 | //если связь один к одному то удаляем сущность |
190 | - if($cgg['reltype'] == 'has_one'){ |
|
190 | + if ($cgg['reltype']=='has_one') { |
|
191 | 191 | $Entity = $Entity->{'get'.$alias}(); |
192 | - if(!$mapper->delete($Entity)){ |
|
192 | + if (!$mapper->delete($Entity)) { |
|
193 | 193 | throw new \Autoprice\Exceptions\EntityNotDeleteException('Unable to delete Entity!'); |
194 | 194 | } |
195 | 195 | } |
@@ -208,43 +208,43 @@ discard block |
||
208 | 208 | * @return \Core\Infrastructure\EntityInterface |
209 | 209 | * @throws BadMethodCallException |
210 | 210 | */ |
211 | - protected function buildEntity(EntityInterface $Entity, array $row){ |
|
211 | + protected function buildEntity(EntityInterface $Entity, array $row) { |
|
212 | 212 | |
213 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
213 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
214 | 214 | |
215 | 215 | $value = false; |
216 | 216 | |
217 | 217 | $field = $cfg['field']; |
218 | 218 | |
219 | - $method_set = 'set' . ucfirst($alias); |
|
219 | + $method_set = 'set'.ucfirst($alias); |
|
220 | 220 | |
221 | - if(!method_exists($Entity, $method_set )){ |
|
221 | + if (!method_exists($Entity, $method_set)) { |
|
222 | 222 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
223 | 223 | } |
224 | 224 | |
225 | 225 | //событие на формирование поля |
226 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
226 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
227 | 227 | $value = call_user_func($cfg['build'], $row); |
228 | 228 | } |
229 | 229 | //на связь |
230 | - elseif(isset($cfg['relation'])){ |
|
230 | + elseif (isset($cfg['relation'])) { |
|
231 | 231 | |
232 | 232 | $mapper = $this->DI->get($cfg['relation']); |
233 | 233 | |
234 | - if($this->use_joins===true || empty($row[$field])){ |
|
234 | + if ($this->use_joins===true || empty($row[$field])) { |
|
235 | 235 | $value = $mapper->createEntity($row); |
236 | 236 | } |
237 | - else{ |
|
238 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
237 | + else { |
|
238 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
239 | 239 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
240 | 240 | } |
241 | 241 | |
242 | 242 | } |
243 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
243 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
244 | 244 | $value = $row[strtolower($field)]; |
245 | 245 | } |
246 | 246 | |
247 | - if($value!==false) |
|
247 | + if ($value!==false) |
|
248 | 248 | $Entity->{$method_set}($value); |
249 | 249 | |
250 | 250 | } |
@@ -259,27 +259,27 @@ discard block |
||
259 | 259 | * @return \Core\Infrastructure\EntityInterface |
260 | 260 | * @throws BadMethodCallException |
261 | 261 | */ |
262 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
262 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
263 | 263 | |
264 | 264 | $row = []; |
265 | 265 | |
266 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
266 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
267 | 267 | |
268 | 268 | $field = $cfg['field']; |
269 | 269 | |
270 | - $method_get = 'get' . ucfirst($alias); |
|
270 | + $method_get = 'get'.ucfirst($alias); |
|
271 | 271 | |
272 | - if(!method_exists($Entity, $method_get )){ |
|
272 | + if (!method_exists($Entity, $method_get)) { |
|
273 | 273 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
274 | 274 | } |
275 | 275 | |
276 | 276 | //-------------------------------------------------------------------- |
277 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
278 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
277 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
278 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
279 | 279 | } |
280 | - elseif(isset($cfg['relation'])){ |
|
280 | + elseif (isset($cfg['relation'])) { |
|
281 | 281 | |
282 | - if(isset($cfg['on'])) |
|
282 | + if (isset($cfg['on'])) |
|
283 | 283 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
284 | 284 | else |
285 | 285 | $fkey = 'id'; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
288 | 288 | |
289 | 289 | } |
290 | - else{ |
|
290 | + else { |
|
291 | 291 | $value = $Entity->{$method_get}(); |
292 | 292 | } |
293 | 293 | |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * Установка поля для маппинга |
305 | 305 | */ |
306 | - protected function addMappingField($alias,$field = null){ |
|
306 | + protected function addMappingField($alias, $field = null) { |
|
307 | 307 | |
308 | - if(is_string($field)){ |
|
308 | + if (is_string($field)) { |
|
309 | 309 | $field = ['field' => $field]; |
310 | 310 | } |
311 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
312 | - $field['field'] = $alias; |
|
311 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
312 | + $field['field'] = $alias; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $this->mapping_fields[$alias] = $field; |
316 | 316 | |
317 | - if(isset($field['primary']) && $field['primary']===true){ |
|
317 | + if (isset($field['primary']) && $field['primary']===true) { |
|
318 | 318 | $this->key = $field['field']; |
319 | 319 | } |
320 | 320 | |
321 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
321 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
322 | 322 | $this->soft_delete_key = $field['field']; |
323 | 323 | } |
324 | 324 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | |
346 | 346 | |
347 | 347 | |
348 | - public function getFieldAlias($field){ |
|
348 | + public function getFieldAlias($field) { |
|
349 | 349 | |
350 | 350 | return $this->mapping_fields_aliases[$field]; |
351 | 351 | |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @param ISpecificationCriteria $specification |
358 | 358 | * @return type |
359 | 359 | */ |
360 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
360 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
361 | 361 | |
362 | 362 | //псеводо удаление |
363 | 363 | $this->setSoftDelete($specification); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $specification->setLimit(1); |
368 | 368 | |
369 | 369 | //получение записей |
370 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
370 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
371 | 371 | |
372 | 372 | if (!$row = $res->row_array()) { |
373 | 373 | return null; |
@@ -388,13 +388,13 @@ discard block |
||
388 | 388 | |
389 | 389 | if ( |
390 | 390 | $delete_key > '' && |
391 | - $Entity->getId() > 0){ |
|
392 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
391 | + $Entity->getId() > 0) { |
|
392 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
393 | 393 | } |
394 | - elseif($Entity->getId() > 0){ |
|
394 | + elseif ($Entity->getId() > 0) { |
|
395 | 395 | |
396 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
397 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
396 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
397 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | |
412 | 412 | $this->setRelations($specification); |
413 | 413 | |
414 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
414 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
415 | 415 | |
416 | 416 | if (!$rows = $res->result_array()) { |
417 | 417 | return null; |
418 | 418 | } |
419 | 419 | |
420 | - foreach($rows as $k => $row){ |
|
420 | + foreach ($rows as $k => $row) { |
|
421 | 421 | $rows[$k] = $this->createEntity($row); |
422 | 422 | } |
423 | 423 | |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | * Выборка удаленных моделей |
434 | 434 | * @param ISpecificationCriteria $specification |
435 | 435 | */ |
436 | - private function setSoftDelete(ISpecificationCriteria $specification){ |
|
437 | - if( |
|
438 | - $this->use_delete === false && |
|
439 | - $this->setSoftDeleteKey()>'' |
|
436 | + private function setSoftDelete(ISpecificationCriteria $specification) { |
|
437 | + if ( |
|
438 | + $this->use_delete===false && |
|
439 | + $this->setSoftDeleteKey() > '' |
|
440 | 440 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
441 | 441 | ) |
442 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
442 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -450,12 +450,12 @@ discard block |
||
450 | 450 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
451 | 451 | * has_one - один к одному |
452 | 452 | */ |
453 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
453 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
454 | 454 | |
455 | 455 | $joins = []; |
456 | 456 | |
457 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
458 | - if(isset($cfg['relation'])){ |
|
457 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
458 | + if (isset($cfg['relation'])) { |
|
459 | 459 | |
460 | 460 | $this->relations[$field] = [ |
461 | 461 | 'mapper' => $mapper = $this->DI->get($cfg['relation']), |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | $table = $mapper->getEntityTable(); |
466 | 466 | |
467 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
467 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
468 | 468 | |
469 | 469 | $joins[$table] = [ |
470 | 470 | 'alias' => $field, |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | } |
476 | 476 | } |
477 | 477 | |
478 | - if($this->use_joins===true){ |
|
478 | + if ($this->use_joins===true) { |
|
479 | 479 | $Specification->setJoins($joins); |
480 | 480 | } |
481 | 481 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | return $o; |
491 | 491 | } |
492 | 492 | |
493 | - public function withDelete(){ |
|
493 | + public function withDelete() { |
|
494 | 494 | $o = clone $this; |
495 | 495 | $o->use_delete = true; |
496 | 496 | return $o; |
@@ -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 | |
@@ -155,7 +157,7 @@ discard block |
||
155 | 157 | /** |
156 | 158 | * Создает селект не только для основной таблицы но и для приджойненых таблиц |
157 | 159 | * @param type $joins |
158 | - * @return type |
|
160 | + * @return string |
|
159 | 161 | */ |
160 | 162 | protected function createSelect($joins) |
161 | 163 | { |
@@ -171,8 +173,8 @@ discard block |
||
171 | 173 | /** |
172 | 174 | * Получение записей по условию |
173 | 175 | * @param type $where |
174 | - * @param type $limit |
|
175 | - * @param type $offset |
|
176 | + * @param integer $limit |
|
177 | + * @param integer $offset |
|
176 | 178 | * @param type $joins |
177 | 179 | * @param type $order |
178 | 180 | * @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 | |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | return $res; |
142 | 142 | } |
143 | 143 | |
144 | - protected function setTable($table){ |
|
145 | - if(preg_match('~(.*?)\.(.*?)$~is',$table,$m)){ |
|
144 | + protected function setTable($table) { |
|
145 | + if (preg_match('~(.*?)\.(.*?)$~is', $table, $m)) { |
|
146 | 146 | $this->database = $m[1]; |
147 | 147 | $this->TableName = $m[2]; |
148 | 148 | } |
149 | - else{ |
|
149 | + else { |
|
150 | 150 | $this->TableName = $table; |
151 | 151 | } |
152 | 152 | } |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | */ |
160 | 160 | protected function createSelect($joins) |
161 | 161 | { |
162 | - $s = "`" . $this->TableName . '`.*'; |
|
162 | + $s = "`".$this->TableName.'`.*'; |
|
163 | 163 | foreach ($joins as $table => $join) { |
164 | - $table = isset($join['alias']) ? "`{$join['alias']}`": $table; |
|
164 | + $table = isset($join['alias']) ? "`{$join['alias']}`" : $table; |
|
165 | 165 | $s .= ", $table.*"; |
166 | 166 | } |
167 | 167 | return $s; |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | */ |
185 | 185 | protected function buildQuery($where = array(), $limit = 25, $offset = 0, $joins = array(), $order = array(), $manualJoins = array(), $group = null, $manualWheres = array(), $whereType = 'AND') |
186 | 186 | { |
187 | - $table = !empty($this->database)? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
188 | - $query = 'SELECT ' . $this->createSelect($joins) . " FROM `".$table."`"; |
|
187 | + $table = !empty($this->database) ? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
188 | + $query = 'SELECT '.$this->createSelect($joins)." FROM `".$table."`"; |
|
189 | 189 | //$countQuery = "SELECT COUNT(*) AS cnt FROM `{$this->database}`.".$this->getTableName(); |
190 | 190 | |
191 | 191 | $wheres = array(); |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | |
196 | 196 | if (!is_array($value)) { |
197 | 197 | $params[] = $value; |
198 | - $wheres[] = $key . ' = ?'; |
|
198 | + $wheres[] = $key.' = ?'; |
|
199 | 199 | } else { |
200 | 200 | if (isset($value['operator'])) { |
201 | 201 | if (is_array($value['value'])) { |
202 | - if ($value['operator'] == 'between') { |
|
202 | + if ($value['operator']=='between') { |
|
203 | 203 | $params[] = $value['value'][0]; |
204 | 204 | $params[] = $value['value'][1]; |
205 | - $wheres[] = $key . ' BETWEEN ? AND ?'; |
|
206 | - } elseif ($value['operator'] == 'IN') { |
|
205 | + $wheres[] = $key.' BETWEEN ? AND ?'; |
|
206 | + } elseif ($value['operator']=='IN') { |
|
207 | 207 | $in = array(); |
208 | 208 | |
209 | 209 | foreach ($value['value'] as $item) { |
@@ -211,67 +211,67 @@ discard block |
||
211 | 211 | $in[] = '?'; |
212 | 212 | } |
213 | 213 | |
214 | - $wheres[] = $key . ' IN (' . implode(', ', $in) . ') '; |
|
214 | + $wheres[] = $key.' IN ('.implode(', ', $in).') '; |
|
215 | 215 | } else { |
216 | 216 | $ors = array(); |
217 | 217 | foreach ($value['value'] as $item) { |
218 | - if ($item == 'null') { |
|
218 | + if ($item=='null') { |
|
219 | 219 | switch ($value['operator']) { |
220 | 220 | case '!=': |
221 | - $ors[] = $key . ' IS NOT NULL'; |
|
221 | + $ors[] = $key.' IS NOT NULL'; |
|
222 | 222 | break; |
223 | 223 | |
224 | 224 | case '==': |
225 | 225 | default: |
226 | - $ors[] = $key . ' IS NULL'; |
|
226 | + $ors[] = $key.' IS NULL'; |
|
227 | 227 | break; |
228 | 228 | } |
229 | 229 | } else { |
230 | 230 | $params[] = $item; |
231 | - $ors[] = $this->fieldCheck($key) . ' ' . $value['operator'] . ' ?'; |
|
231 | + $ors[] = $this->fieldCheck($key).' '.$value['operator'].' ?'; |
|
232 | 232 | } |
233 | 233 | } |
234 | - $wheres[] = '(' . implode(' OR ', $ors) . ')'; |
|
234 | + $wheres[] = '('.implode(' OR ', $ors).')'; |
|
235 | 235 | } |
236 | 236 | } else { |
237 | - if ($value['operator'] == 'like') { |
|
238 | - $params[] = '%' . $value['value'] . '%'; |
|
239 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
237 | + if ($value['operator']=='like') { |
|
238 | + $params[] = '%'.$value['value'].'%'; |
|
239 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
240 | 240 | } else { |
241 | - if ($value['value'] === 'null') { |
|
241 | + if ($value['value']==='null') { |
|
242 | 242 | switch ($value['operator']) { |
243 | 243 | case '!=': |
244 | - $wheres[] = $key . ' IS NOT NULL'; |
|
244 | + $wheres[] = $key.' IS NOT NULL'; |
|
245 | 245 | break; |
246 | 246 | |
247 | 247 | case '==': |
248 | 248 | default: |
249 | - $wheres[] = $key . ' IS NULL'; |
|
249 | + $wheres[] = $key.' IS NULL'; |
|
250 | 250 | break; |
251 | 251 | } |
252 | 252 | } else { |
253 | 253 | $params[] = $value['value']; |
254 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
254 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
258 | 258 | } else { |
259 | - $wheres[] = $key . ' IN (' . implode(', ', array_map(array($this, 'escape'), $value)) . ')'; |
|
259 | + $wheres[] = $key.' IN ('.implode(', ', array_map(array($this, 'escape'), $value)).')'; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | 264 | if (count($joins)) { |
265 | 265 | foreach ($joins as $table => $join) { |
266 | - $type = isset($join['type'])?$join['type']:'INNER'; |
|
267 | - $query .= ' '. $type.' JOIN `' . $table . '` as `' . $join['alias'] . '` ON ' . $join['on'] . ' '; |
|
266 | + $type = isset($join['type']) ? $join['type'] : 'INNER'; |
|
267 | + $query .= ' '.$type.' JOIN `'.$table.'` as `'.$join['alias'].'` ON '.$join['on'].' '; |
|
268 | 268 | //$countQuery .= ' '.$type.' JOIN ' . $table . ' ' . $join['alias'] . ' ON ' . $join['on'] . ' '; |
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | 272 | if (count($manualJoins)) { |
273 | 273 | foreach ($manualJoins as $join) { |
274 | - $query .= ' ' . $join . ' '; |
|
274 | + $query .= ' '.$join.' '; |
|
275 | 275 | //$countQuery .= ' ' . $join . ' '; |
276 | 276 | } |
277 | 277 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $hasWhere = false; |
280 | 280 | if (count($wheres)) { |
281 | 281 | $hasWhere = true; |
282 | - $query .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
|
282 | + $query .= ' WHERE ('.implode(' '.$whereType.' ', $wheres).')'; |
|
283 | 283 | //$countQuery .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
284 | 284 | } |
285 | 285 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | $query .= ' WHERE '; |
291 | 291 | //$countQuery .= ' WHERE '; |
292 | 292 | } else { |
293 | - $query .= ' ' . $where['type'] . ' '; |
|
293 | + $query .= ' '.$where['type'].' '; |
|
294 | 294 | //$countQuery .= ' ' . $where['type'] . ' '; |
295 | 295 | } |
296 | 296 | |
297 | - $query .= ' ' . $where['query']; |
|
297 | + $query .= ' '.$where['query']; |
|
298 | 298 | //$countQuery .= ' ' . $where['query']; |
299 | 299 | |
300 | 300 | if (isset($where['params'])) { |
@@ -306,28 +306,28 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | if (!is_null($group)) { |
309 | - $query .= ' GROUP BY ' . $group . ' '; |
|
309 | + $query .= ' GROUP BY '.$group.' '; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | if (count($order)) { |
313 | 313 | $orders = array(); |
314 | - if (is_string($order) && $order == 'rand') { |
|
314 | + if (is_string($order) && $order=='rand') { |
|
315 | 315 | $query .= ' ORDER BY RAND() '; |
316 | 316 | } else { |
317 | 317 | foreach ($order as $key => $value) { |
318 | - $orders[] = $this->fieldCheck($key) . ' ' . $value; |
|
318 | + $orders[] = $this->fieldCheck($key).' '.$value; |
|
319 | 319 | } |
320 | 320 | |
321 | - $query .= ' ORDER BY ' . implode(', ', $orders); |
|
321 | + $query .= ' ORDER BY '.implode(', ', $orders); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | 325 | if ($limit) { |
326 | - $query .= ' LIMIT ' . $limit; |
|
326 | + $query .= ' LIMIT '.$limit; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | if ($offset) { |
330 | - $query .= ' OFFSET ' . $offset; |
|
330 | + $query .= ' OFFSET '.$offset; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | try { |
346 | 346 | //$query = $this->compile_binds($query, $params); |
347 | 347 | |
348 | - return $this->adapter->query($query,$params); |
|
348 | + return $this->adapter->query($query, $params); |
|
349 | 349 | //ed( $this->adapter->query($query) ,1); |
350 | 350 | // if ($res = $this->adapter->getRows($query)) { |
351 | 351 | // $rtn = array(); |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | // } else { |
360 | 360 | // return false; |
361 | 361 | // } |
362 | - } catch(\PDOException $ex) { |
|
362 | + } catch (\PDOException $ex) { |
|
363 | 363 | throw $ex; |
364 | 364 | } |
365 | 365 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | protected function compile_binds($sql, $binds) |
376 | 376 | { |
377 | - if (strpos($sql, $this->bind_marker) === FALSE) { |
|
377 | + if (strpos($sql, $this->bind_marker)===FALSE) { |
|
378 | 378 | return $sql; |
379 | 379 | } |
380 | 380 |
@@ -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 | } |
@@ -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) |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Добавление значения в защищенное свойтсво |
22 | 22 | * @param type $name |
23 | - * @param type $valued |
|
23 | + * @param type $value |
|
24 | 24 | */ |
25 | 25 | private function setValueprotectedProperty($name, $value) |
26 | 26 | { |
@@ -30,6 +30,10 @@ discard block |
||
30 | 30 | $r->setValue($this->object, $value); //изменяем значение |
31 | 31 | } |
32 | 32 | |
33 | + /** |
|
34 | + * @param SimpleORM\AbstractDataMapper $obj |
|
35 | + * @param string $name |
|
36 | + */ |
|
33 | 37 | static public function callMethod($obj, $name, array $args) { |
34 | 38 | $class = new \ReflectionClass($obj); |
35 | 39 | $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 | - private function setValueprotectedProperty($name, $value) |
|
26 | - { |
|
27 | - $reflectionClass = new \ReflectionClass($this->object); //создаем reflectionClass |
|
28 | - $r = $reflectionClass->getProperty($name); //получаем свойство |
|
29 | - $r->setAccessible(true); //делаем открытым |
|
30 | - $r->setValue($this->object, $value); //изменяем значение |
|
31 | - } |
|
20 | + /** |
|
21 | + * Добавление значения в защищенное свойтсво |
|
22 | + * @param type $name |
|
23 | + * @param type $valued |
|
24 | + */ |
|
25 | + private function setValueprotectedProperty($name, $value) |
|
26 | + { |
|
27 | + $reflectionClass = new \ReflectionClass($this->object); //создаем reflectionClass |
|
28 | + $r = $reflectionClass->getProperty($name); //получаем свойство |
|
29 | + $r->setAccessible(true); //делаем открытым |
|
30 | + $r->setValue($this->object, $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 | } |
@@ -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 | * получение защищенного свойства |