@@ -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 | |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -132,7 +132,9 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $data = $this->unbuildEntity($Entity); |
| 134 | 134 | |
| 135 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
| 135 | + if(method_exists($this, 'onPrepareData' )) { |
|
| 136 | + $this->onPrepareData( $Entity , $data ); |
|
| 137 | + } |
|
| 136 | 138 | |
| 137 | 139 | $id = $data[$this->getPrimaryKey()]; |
| 138 | 140 | unset($data[$this->getPrimaryKey()]); |
@@ -168,13 +170,17 @@ discard block |
||
| 168 | 170 | */ |
| 169 | 171 | public function save(EntityInterface $Entity) |
| 170 | 172 | { |
| 171 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
| 173 | + if(method_exists($this, 'onAfterSave' )) { |
|
| 174 | + $this->onAfterSave( $Entity ); |
|
| 175 | + } |
|
| 172 | 176 | |
| 173 | 177 | if(!$this->saveWithoutEvents($Entity)){ |
| 174 | 178 | return false; |
| 175 | 179 | } |
| 176 | 180 | |
| 177 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
| 181 | + if(method_exists($this, 'onBeforeSave' )) { |
|
| 182 | + $this->onBeforeSave( $Entity ); |
|
| 183 | + } |
|
| 178 | 184 | |
| 179 | 185 | return true; |
| 180 | 186 | } |
@@ -208,8 +214,7 @@ discard block |
||
| 208 | 214 | if(count($rel['relations'])>0){ |
| 209 | 215 | $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()'); |
| 210 | 216 | $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
| 211 | - } |
|
| 212 | - else{ |
|
| 217 | + } else{ |
|
| 213 | 218 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
| 214 | 219 | } |
| 215 | 220 | } |
@@ -273,19 +278,18 @@ discard block |
||
| 273 | 278 | |
| 274 | 279 | if($this->use_joins===true || empty($row[$field])){ |
| 275 | 280 | $value = $mapper->createEntity($row); |
| 276 | - } |
|
| 277 | - else{ |
|
| 281 | + } else{ |
|
| 278 | 282 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
| 279 | 283 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
| 280 | 284 | } |
| 281 | 285 | |
| 282 | - } |
|
| 283 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 286 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 284 | 287 | $value = $row[strtolower($field)]; |
| 285 | 288 | } |
| 286 | 289 | |
| 287 | - if($value!==false) |
|
| 288 | - $Entity->{$method_set}($value); |
|
| 290 | + if($value!==false) { |
|
| 291 | + $Entity->{$method_set}($value); |
|
| 292 | + } |
|
| 289 | 293 | |
| 290 | 294 | } |
| 291 | 295 | |
@@ -316,18 +320,17 @@ discard block |
||
| 316 | 320 | //-------------------------------------------------------------------- |
| 317 | 321 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
| 318 | 322 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
| 319 | - } |
|
| 320 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 323 | + } elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 321 | 324 | |
| 322 | - if(isset($cfg['on'])) |
|
| 323 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 324 | - else |
|
| 325 | - $fkey = 'id'; |
|
| 325 | + if(isset($cfg['on'])) { |
|
| 326 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 327 | + } else { |
|
| 328 | + $fkey = 'id'; |
|
| 329 | + } |
|
| 326 | 330 | |
| 327 | 331 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
| 328 | 332 | |
| 329 | - } |
|
| 330 | - else{ |
|
| 333 | + } else{ |
|
| 331 | 334 | $value = $Entity->{$method_get}(); |
| 332 | 335 | } |
| 333 | 336 | |
@@ -345,8 +348,7 @@ discard block |
||
| 345 | 348 | |
| 346 | 349 | if(is_string($field)){ |
| 347 | 350 | $field = ['field' => $field]; |
| 348 | - } |
|
| 349 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 351 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 350 | 352 | $field['field'] = $alias; |
| 351 | 353 | } |
| 352 | 354 | |
@@ -428,8 +430,7 @@ discard block |
||
| 428 | 430 | $delete_key > '' && |
| 429 | 431 | $Entity->getId() > 0){ |
| 430 | 432 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
| 431 | - } |
|
| 432 | - elseif($Entity->getId() > 0){ |
|
| 433 | + } elseif($Entity->getId() > 0){ |
|
| 433 | 434 | |
| 434 | 435 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
| 435 | 436 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -476,8 +477,9 @@ discard block |
||
| 476 | 477 | $this->use_delete === false && |
| 477 | 478 | $this->setSoftDeleteKey()>'' |
| 478 | 479 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
| 479 | - ) |
|
| 480 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 480 | + ) { |
|
| 481 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 482 | + } |
|
| 481 | 483 | } |
| 482 | 484 | |
| 483 | 485 | /** |
@@ -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 (empty($id)) {//$id < 1 |
|
| 30 | - throw new InvalidArgumentException("Неверный индентификатор"); |
|
| 31 | - } |
|
| 29 | + if (empty($id)) {//$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; |