@@ -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охранение сущности |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | protected function buildEntity(EntityInterface $Entity, array $row){ |
| 201 | 201 | |
| 202 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 202 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 203 | 203 | |
| 204 | 204 | $value = false; |
| 205 | 205 | |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | if($value!==false) |
| 237 | 237 | $Entity->{$method_set}($value); |
| 238 | 238 | |
| 239 | - } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - return $Entity; |
|
| 241 | + return $Entity; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $row = []; |
| 254 | 254 | |
| 255 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 255 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 256 | 256 | |
| 257 | 257 | $field = $cfg['field']; |
| 258 | 258 | |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | $row[$field] = $value; |
| 284 | 284 | |
| 285 | - } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - return $row; |
|
| 287 | + return $row; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -356,10 +356,10 @@ discard block |
||
| 356 | 356 | //получение записей |
| 357 | 357 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
| 358 | 358 | |
| 359 | - if (!$row = $res->row_array()) { |
|
| 360 | - return null; |
|
| 361 | - } |
|
| 362 | - return $this->createEntity($row); |
|
| 359 | + if (!$row = $res->row_array()) { |
|
| 360 | + return null; |
|
| 361 | + } |
|
| 362 | + return $this->createEntity($row); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
| 402 | 402 | |
| 403 | 403 | if (!$rows = $res->result_array()) { |
| 404 | - return null; |
|
| 405 | - } |
|
| 404 | + return null; |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | 407 | foreach($rows as $k => $row){ |
| 408 | 408 | $rows[$k] = $this->createEntity($row); |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | - * Построение join-ов |
|
| 434 | - */ |
|
| 433 | + * Построение join-ов |
|
| 434 | + */ |
|
| 435 | 435 | protected function setRelations(ISpecificationCriteria $Specification){ |
| 436 | 436 | |
| 437 | 437 | $joins = []; |
@@ -222,19 +222,18 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | if($this->use_joins===true){ |
| 224 | 224 | $value = $mapper->createEntity($row); |
| 225 | - } |
|
| 226 | - else{ |
|
| 225 | + } else{ |
|
| 227 | 226 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
| 228 | 227 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
| 229 | 228 | } |
| 230 | 229 | |
| 231 | - } |
|
| 232 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 230 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 233 | 231 | $value = $row[strtolower($field)]; |
| 234 | 232 | } |
| 235 | 233 | |
| 236 | - if($value!==false) |
|
| 237 | - $Entity->{$method_set}($value); |
|
| 234 | + if($value!==false) { |
|
| 235 | + $Entity->{$method_set}($value); |
|
| 236 | + } |
|
| 238 | 237 | |
| 239 | 238 | } |
| 240 | 239 | |
@@ -265,18 +264,17 @@ discard block |
||
| 265 | 264 | //-------------------------------------------------------------------- |
| 266 | 265 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
| 267 | 266 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
| 268 | - } |
|
| 269 | - elseif(isset($cfg['relation'])){ |
|
| 267 | + } elseif(isset($cfg['relation'])){ |
|
| 270 | 268 | |
| 271 | - if(isset($cfg['on'])) |
|
| 272 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 273 | - else |
|
| 274 | - $fkey = 'id'; |
|
| 269 | + if(isset($cfg['on'])) { |
|
| 270 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 271 | + } else { |
|
| 272 | + $fkey = 'id'; |
|
| 273 | + } |
|
| 275 | 274 | |
| 276 | 275 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
| 277 | 276 | |
| 278 | - } |
|
| 279 | - else{ |
|
| 277 | + } else{ |
|
| 280 | 278 | $value = $Entity->{$method_get}(); |
| 281 | 279 | } |
| 282 | 280 | |
@@ -294,8 +292,7 @@ discard block |
||
| 294 | 292 | |
| 295 | 293 | if(is_string($field)){ |
| 296 | 294 | $field = ['field' => $field]; |
| 297 | - } |
|
| 298 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 295 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 299 | 296 | $field['field'] = $alias; |
| 300 | 297 | } |
| 301 | 298 | |
@@ -377,8 +374,7 @@ discard block |
||
| 377 | 374 | $delete_key > '' && |
| 378 | 375 | $Entity->getId() > 0){ |
| 379 | 376 | $result = $this->db->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
| 380 | - } |
|
| 381 | - elseif($Entity->getId() > 0){ |
|
| 377 | + } elseif($Entity->getId() > 0){ |
|
| 382 | 378 | |
| 383 | 379 | if($result = $this->db->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
| 384 | 380 | if(method_exists($this, 'onDeleteSuccess' )){ $result = $this->onDeleteSuccess( $Entity );} |
@@ -425,8 +421,9 @@ discard block |
||
| 425 | 421 | $this->use_delete === false && |
| 426 | 422 | $this->setSoftDeleteKey()>'' |
| 427 | 423 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
| 428 | - ) |
|
| 429 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 424 | + ) { |
|
| 425 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 426 | + } |
|
| 430 | 427 | } |
| 431 | 428 | |
| 432 | 429 | /** |
@@ -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 | } |
@@ -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'); |
@@ -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 | } |