@@ -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 | |
@@ -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 | } |
@@ -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); |
@@ -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 | |
@@ -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,49 +254,49 @@ 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 | |
| 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 | - if(isset($row[$this->key])){ |
|
| 264 | + if (isset($row[$this->key])) { |
|
| 265 | 265 | $field = $cfg['field']; |
| 266 | 266 | } |
| 267 | - else{ |
|
| 267 | + else { |
|
| 268 | 268 | $field = $alias; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $method_set = 'set' . ucfirst($alias); |
|
| 271 | + $method_set = 'set'.ucfirst($alias); |
|
| 272 | 272 | |
| 273 | - if(!method_exists($Entity, $method_set )){ |
|
| 273 | + if (!method_exists($Entity, $method_set)) { |
|
| 274 | 274 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | //событие на формирование поля |
| 278 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
| 278 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
| 279 | 279 | $value = call_user_func($cfg['build'], $row); |
| 280 | 280 | } |
| 281 | 281 | //на связь |
| 282 | - elseif(isset($cfg['relation'])){ |
|
| 282 | + elseif (isset($cfg['relation'])) { |
|
| 283 | 283 | |
| 284 | 284 | $mapper = $this->DI->get($cfg['relation']); |
| 285 | 285 | |
| 286 | - if($this->use_joins===true || empty($row[$field])){ |
|
| 286 | + if ($this->use_joins===true || empty($row[$field])) { |
|
| 287 | 287 | $value = $mapper->createEntity($row); |
| 288 | 288 | } |
| 289 | - else{ |
|
| 290 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
| 289 | + else { |
|
| 290 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
| 291 | 291 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | } |
| 295 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 295 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
| 296 | 296 | $value = $row[strtolower($field)]; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if($value!==false) |
|
| 299 | + if ($value!==false) |
|
| 300 | 300 | $Entity->{$method_set}($value); |
| 301 | 301 | |
| 302 | 302 | } |
@@ -311,27 +311,27 @@ discard block |
||
| 311 | 311 | * @return \Core\Infrastructure\EntityInterface |
| 312 | 312 | * @throws BadMethodCallException |
| 313 | 313 | */ |
| 314 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
| 314 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
| 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 | |
| 322 | - $method_get = 'get' . ucfirst($alias); |
|
| 322 | + $method_get = 'get'.ucfirst($alias); |
|
| 323 | 323 | |
| 324 | - if(!method_exists($Entity, $method_get )){ |
|
| 324 | + if (!method_exists($Entity, $method_get)) { |
|
| 325 | 325 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | //-------------------------------------------------------------------- |
| 329 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
| 330 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
| 329 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
| 330 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
| 331 | 331 | } |
| 332 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 332 | + elseif (isset($cfg['relation']) && is_object($Entity->{$method_get}())) { |
|
| 333 | 333 | |
| 334 | - if(isset($cfg['on'])) |
|
| 334 | + if (isset($cfg['on'])) |
|
| 335 | 335 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
| 336 | 336 | else |
| 337 | 337 | $fkey = 'id'; |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
| 340 | 340 | |
| 341 | 341 | } |
| 342 | - else{ |
|
| 342 | + else { |
|
| 343 | 343 | $value = $Entity->{$method_get}(); |
| 344 | 344 | } |
| 345 | 345 | |
@@ -353,22 +353,22 @@ discard block |
||
| 353 | 353 | /** |
| 354 | 354 | * Установка поля для маппинга |
| 355 | 355 | */ |
| 356 | - protected function addMappingField($alias,$field = null){ |
|
| 356 | + protected function addMappingField($alias, $field = null) { |
|
| 357 | 357 | |
| 358 | - if(is_string($field)){ |
|
| 358 | + if (is_string($field)) { |
|
| 359 | 359 | $field = ['field' => $field]; |
| 360 | 360 | } |
| 361 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 362 | - $field['field'] = $alias; |
|
| 361 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
| 362 | + $field['field'] = $alias; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $this->mapping_fields[$alias] = $field; |
| 366 | 366 | |
| 367 | - if(isset($field['primary']) && $field['primary']===true){ |
|
| 367 | + if (isset($field['primary']) && $field['primary']===true) { |
|
| 368 | 368 | $this->key = $field['field']; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
| 371 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
| 372 | 372 | $this->soft_delete_key = $field['field']; |
| 373 | 373 | } |
| 374 | 374 | |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @param type $field |
| 400 | 400 | * @return type |
| 401 | 401 | */ |
| 402 | - public function getFieldAlias($field){ |
|
| 402 | + public function getFieldAlias($field) { |
|
| 403 | 403 | return $this->mapping_fields_aliases[$field]; |
| 404 | 404 | } |
| 405 | 405 | |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | * @param ISpecificationCriteria $specification |
| 420 | 420 | * @return type |
| 421 | 421 | */ |
| 422 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
| 422 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
| 423 | 423 | |
| 424 | 424 | //псеводо удаление |
| 425 | 425 | $this->setSoftDelete($specification); |
@@ -429,13 +429,13 @@ discard block |
||
| 429 | 429 | $specification->setLimit(1); |
| 430 | 430 | |
| 431 | 431 | //получение записей |
| 432 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
| 432 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
| 433 | 433 | |
| 434 | 434 | if (!$row = $res->row_array()) { |
| 435 | 435 | return null; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if($this->result_array===true){ |
|
| 438 | + if ($this->result_array===true) { |
|
| 439 | 439 | return $row; |
| 440 | 440 | } |
| 441 | 441 | |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | if ( |
| 458 | 458 | $delete_key > '' && |
| 459 | - $Entity->getId() > 0){ |
|
| 460 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
| 459 | + $Entity->getId() > 0) { |
|
| 460 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
| 461 | 461 | } |
| 462 | - elseif($Entity->getId() > 0){ |
|
| 462 | + elseif ($Entity->getId() > 0) { |
|
| 463 | 463 | |
| 464 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
| 465 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
| 464 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
| 465 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
@@ -479,17 +479,17 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | $this->setRelations($specification); |
| 481 | 481 | |
| 482 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
| 482 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
| 483 | 483 | |
| 484 | 484 | if (!$rows = $res->result_array()) { |
| 485 | 485 | return null; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if($this->result_array===true){ |
|
| 488 | + if ($this->result_array===true) { |
|
| 489 | 489 | return $rows; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - foreach($rows as $k => $row){ |
|
| 492 | + foreach ($rows as $k => $row) { |
|
| 493 | 493 | $rows[$k] = $this->createEntity($row); |
| 494 | 494 | } |
| 495 | 495 | |
@@ -505,13 +505,13 @@ discard block |
||
| 505 | 505 | * Выборка удаленных моделей |
| 506 | 506 | * @param ISpecificationCriteria $specification |
| 507 | 507 | */ |
| 508 | - private function setSoftDelete(ISpecificationCriteria $specification){ |
|
| 509 | - if( |
|
| 510 | - $this->use_delete === false && |
|
| 511 | - $this->setSoftDeleteKey()>'' |
|
| 508 | + private function setSoftDelete(ISpecificationCriteria $specification) { |
|
| 509 | + if ( |
|
| 510 | + $this->use_delete===false && |
|
| 511 | + $this->setSoftDeleteKey() > '' |
|
| 512 | 512 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
| 513 | 513 | ) |
| 514 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 514 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** |
@@ -522,12 +522,12 @@ discard block |
||
| 522 | 522 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
| 523 | 523 | * has_one - один к одному |
| 524 | 524 | */ |
| 525 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
| 525 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
| 526 | 526 | |
| 527 | 527 | $joins = []; |
| 528 | 528 | |
| 529 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
| 530 | - if(isset($cfg['relation'])){ |
|
| 529 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
| 530 | + if (isset($cfg['relation'])) { |
|
| 531 | 531 | |
| 532 | 532 | $this->relations[$field] = [ |
| 533 | 533 | 'mapper' => $mapper = $this->DI->get($cfg['relation']), |
@@ -536,18 +536,18 @@ discard block |
||
| 536 | 536 | |
| 537 | 537 | $table = $mapper->getEntityTable(); |
| 538 | 538 | |
| 539 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
| 539 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
| 540 | 540 | |
| 541 | 541 | $joins[$table] = [ |
| 542 | 542 | 'alias' => $field, |
| 543 | - 'type' => $cfg['reltype'] != 'has_many' ? 'INNER' : 'LEFT OUTER', |
|
| 543 | + 'type' => $cfg['reltype']!='has_many' ? 'INNER' : 'LEFT OUTER', |
|
| 544 | 544 | 'on' => "`{$this->table}`.{$cfg['field']} = `{$field}`.{$relation_key}" |
| 545 | 545 | ]; |
| 546 | 546 | |
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - if($this->use_joins===true){ |
|
| 550 | + if ($this->use_joins===true) { |
|
| 551 | 551 | $Specification->setJoins($joins); |
| 552 | 552 | } |
| 553 | 553 | } |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | return $o; |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - public function withDelete(){ |
|
| 565 | + public function withDelete() { |
|
| 566 | 566 | $o = clone $this; |
| 567 | 567 | $o->use_delete = true; |
| 568 | 568 | return $o; |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | * Данные только в массиве |
| 573 | 573 | * @return \SimpleORM\AbstractDataMapper |
| 574 | 574 | */ |
| 575 | - public function resultArray(){ |
|
| 575 | + public function resultArray() { |
|
| 576 | 576 | $o = clone $this; |
| 577 | 577 | $o->result_array = true; |
| 578 | 578 | return $o; |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | 'primary' => true |
| 46 | 46 | ] |
| 47 | 47 | ) |
| 48 | - ->addMappingField('name','cty_name') |
|
| 48 | + ->addMappingField('name', 'cty_name') |
|
| 49 | 49 | ; |
| 50 | 50 | |
| 51 | 51 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function createEntity(array $row) { |
| 33 | 33 | $Group = $this->DI->get('UserGroupMapper')->createEntity([]); |
| 34 | - return $this->buildEntity(new User('testname','[email protected]','asdftyasdvh21267g',$Group), $row); |
|
| 34 | + return $this->buildEntity(new User('testname', '[email protected]', 'asdftyasdvh21267g', $Group), $row); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | 'primary' => true |
| 47 | 47 | ] |
| 48 | 48 | ) |
| 49 | - ->addMappingField('name','usr_name') |
|
| 49 | + ->addMappingField('name', 'usr_name') |
|
| 50 | 50 | ->addMappingField('email', 'usr_email') |
| 51 | 51 | ->addMappingField('password', 'usr_password') |
| 52 | 52 | ->addMappingField('group', [ |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @return type |
| 31 | 31 | */ |
| 32 | 32 | public function createEntity(array $row) { |
| 33 | - return $this->buildEntity(new UserGroup('admin','admin test'), $row); |
|
| 33 | + return $this->buildEntity(new UserGroup('admin', 'admin test'), $row); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | 'primary' => true |
| 46 | 46 | ] |
| 47 | 47 | ) |
| 48 | - ->addMappingField('title','grp_title') |
|
| 49 | - ->addMappingField('code','grp_code') |
|
| 48 | + ->addMappingField('title', 'grp_title') |
|
| 49 | + ->addMappingField('code', 'grp_code') |
|
| 50 | 50 | ; |
| 51 | 51 | |
| 52 | 52 | } |
@@ -24,20 +24,20 @@ |
||
| 24 | 24 | |
| 25 | 25 | $db = new \SimpleORM\Adapter\CodeigniterQueryBuilder(get_instance()->db); |
| 26 | 26 | |
| 27 | - $this->getContainer()->add('UserMapper','Test\Domain\User\UserMapper') |
|
| 27 | + $this->getContainer()->add('UserMapper', 'Test\Domain\User\UserMapper') |
|
| 28 | 28 | ->withArgument($this->getContainer()) |
| 29 | 29 | ->withArgument($db) |
| 30 | 30 | ->withArgument($__AR2['autoresource_db']); |
| 31 | 31 | |
| 32 | - $this->getContainer()->add('UserGroupMapper','Test\Domain\UserGroup\UserGroupMapper') |
|
| 32 | + $this->getContainer()->add('UserGroupMapper', 'Test\Domain\UserGroup\UserGroupMapper') |
|
| 33 | 33 | ->withArgument($this->getContainer()) |
| 34 | 34 | ->withArgument($db) |
| 35 | 35 | ->withArgument($__AR2['autoresource_db']); |
| 36 | - $this->getContainer()->add('UserAddressMapper','Test\Domain\UserAddress\UserAddressMapper') |
|
| 36 | + $this->getContainer()->add('UserAddressMapper', 'Test\Domain\UserAddress\UserAddressMapper') |
|
| 37 | 37 | ->withArgument($this->getContainer()) |
| 38 | 38 | ->withArgument($db) |
| 39 | 39 | ->withArgument($__AR2['autoresource_db']); |
| 40 | - $this->getContainer()->add('CityMapper','Test\Domain\City\CityMapper') |
|
| 40 | + $this->getContainer()->add('CityMapper', 'Test\Domain\City\CityMapper') |
|
| 41 | 41 | ->withArgument($this->getContainer()) |
| 42 | 42 | ->withArgument($db) |
| 43 | 43 | ->withArgument($__AR2['autoresource_db']); |