Completed
Push — master ( 72c774...d6d4ca )
by dima
02:46
created
src/ISpecificationCriteria.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/AbstractOptDataMapper.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * @author d.lanec
14 14
  */
15
-abstract class AbstractOptDataMapper extends AbstractDataMapper{
15
+abstract class AbstractOptDataMapper extends AbstractDataMapper {
16 16
 	
17 17
 	protected $soft_delete_key;
18 18
 	
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 	/**
37 37
 	 * Установка поля для маппинга
38 38
 	 */
39
-	protected function addMappingField($alias,$field = null){
39
+	protected function addMappingField($alias, $field = null) {
40 40
 		
41
-		if(! isset($field['field'])){
42
-			$field['field'] = is_string($field)?$field:$alias;	
41
+		if (!isset($field['field'])) {
42
+			$field['field'] = is_string($field) ? $field : $alias;	
43 43
 		}
44 44
 	
45 45
 		$this->mapping_fields[$alias] = $field;
46 46
 
47
-		if(isset($field['primary']) && $field['primary']===true){
47
+		if (isset($field['primary']) && $field['primary']===true) {
48 48
 			$this->key = $field['field'];
49 49
 		}
50 50
 		
51
-		if(isset($field['softdelete']) && $field['softdelete']===true){
51
+		if (isset($field['softdelete']) && $field['softdelete']===true) {
52 52
 			$this->soft_delete_key = $field['field'];
53 53
 		}
54 54
 		
@@ -84,43 +84,43 @@  discard block
 block discarded – undo
84 84
 	 * @return \Core\Infrastructure\EntityInterface
85 85
 	 * @throws BadMethodCallException
86 86
 	 */
87
-	protected function buildEntity(EntityInterface $Entity, array $row){
87
+	protected function buildEntity(EntityInterface $Entity, array $row) {
88 88
 		
89
-        foreach ($this->mapping_fields as $alias => $cfg ) {
89
+        foreach ($this->mapping_fields as $alias => $cfg) {
90 90
 			
91 91
 			$value = false;
92 92
 			
93 93
 			$field = $cfg['field'];
94 94
 			
95
-			$method_set = 'set' . ucfirst($alias);
95
+			$method_set = 'set'.ucfirst($alias);
96 96
 			
97
-			if(!method_exists($Entity, $method_set )){
97
+			if (!method_exists($Entity, $method_set)) {
98 98
 				throw new BadMethodCallException("Метод {$method_set}  не определен");
99 99
 			}			
100 100
 			
101 101
 			//событие на формирование поля
102
-			if( isset($cfg['build']) && is_object($cfg['build']) ){
102
+			if (isset($cfg['build']) && is_object($cfg['build'])) {
103 103
 				$value = call_user_func($cfg['build'], $row);
104 104
 			}
105 105
 			//на связь
106
-			elseif(isset($cfg['relation'])){
106
+			elseif (isset($cfg['relation'])) {
107 107
 				
108 108
 				$mapper = $this->DI->get($cfg['relation']);
109 109
 				
110
-				if($this->use_joins===true){
110
+				if ($this->use_joins===true) {
111 111
 					$value = $mapper->createEntity($row);
112 112
 				}
113
-				else{
113
+				else {
114 114
 					$fkey = $mapper->key;
115 115
 					$value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field]));
116 116
 				}				
117 117
 				
118 118
 			}
119
-			elseif(is_string($field) && isset($row[strtolower($field)])){
119
+			elseif (is_string($field) && isset($row[strtolower($field)])) {
120 120
 				$value = $row[strtolower($field)];
121 121
 			}
122 122
 			
123
-			if($value!==false)
123
+			if ($value!==false)
124 124
 				$Entity->{$method_set}($value);
125 125
 			
126 126
         }
@@ -135,30 +135,30 @@  discard block
 block discarded – undo
135 135
 	 * @return \Core\Infrastructure\EntityInterface
136 136
 	 * @throws BadMethodCallException
137 137
 	 */
138
-	protected function unbuildEntity(EntityInterface $Entity){
138
+	protected function unbuildEntity(EntityInterface $Entity) {
139 139
 		
140 140
 		$row = [];
141 141
 		
142
-        foreach ($this->mapping_fields as $alias => $cfg ) {
142
+        foreach ($this->mapping_fields as $alias => $cfg) {
143 143
 			
144 144
 			$field = $cfg['field'];
145 145
 			
146
-			$method_get = 'get' . ucfirst($alias);
146
+			$method_get = 'get'.ucfirst($alias);
147 147
 			
148
-			if(!method_exists($Entity, $method_get )){
148
+			if (!method_exists($Entity, $method_get)) {
149 149
 				throw new BadMethodCallException("Метод {$method_get}  не определен");
150 150
 			}		
151 151
 			
152 152
 			//--------------------------------------------------------------------
153
-			if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){
154
-				$value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() );
153
+			if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) {
154
+				$value = call_user_func($cfg['unbuild'], $Entity->{$method_get}());
155 155
 			}
156
-			elseif(isset($cfg['relation'])){
156
+			elseif (isset($cfg['relation'])) {
157 157
 				
158 158
 				$value = $Entity->{$method_get}()->getId();
159 159
 				
160 160
 			}			
161
-			else{
161
+			else {
162 162
 				$value = $Entity->{$method_get}();
163 163
 			}			
164 164
 			
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
 	/**
174 174
 	 * Построение join-ов
175 175
 	 */
176
-	protected function setRelations(ISpecificationCriteria $Specification){
177
-		if($this->use_joins===true){
176
+	protected function setRelations(ISpecificationCriteria $Specification) {
177
+		if ($this->use_joins===true) {
178 178
 			$joins = [];
179 179
 
180
-			foreach ($this->mapping_fields as $field => $cfg){
181
-				if(isset($cfg['relation'])){
180
+			foreach ($this->mapping_fields as $field => $cfg) {
181
+				if (isset($cfg['relation'])) {
182 182
 					$mapper = $this->DI->get($cfg['relation']);
183 183
 					
184 184
 					$table = $mapper->getEntityTable();
Please login to merge, or discard this patch.
src/AbstractDataMapper.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 	 */
23 23
 	protected $use_joins = false;
24 24
 
25
-	public function __construct( QueryBuilderInterface $adapter, $db_name = null) {// \CI_DB_mysqli_driver //DatabaseAdapterInterface
25
+	public function __construct(QueryBuilderInterface $adapter, $db_name = null) {// \CI_DB_mysqli_driver //DatabaseAdapterInterface
26 26
         $this->db = $adapter;
27 27
 		
28
-		$this->entityTable = !empty($db_name)? "$db_name.".$this->setEntityTable() : $this->setEntityTable();
28
+		$this->entityTable = !empty($db_name) ? "$db_name.".$this->setEntityTable() : $this->setEntityTable();
29 29
 		
30 30
 		//$this->key = $this->getKey();
31 31
 	
32
-		if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){
32
+		if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') {
33 33
 			throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы');
34 34
 		}
35 35
     }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
     public function findById($id)
48 48
     {
49
-		$Criteria = (new Specification())->setWhere($this->key , $id);
49
+		$Criteria = (new Specification())->setWhere($this->key, $id);
50 50
 		
51 51
         return $this->findBySpecification($Criteria);
52 52
     }	
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		//insert
67 67
 		if (empty($id)) {
68 68
 			
69
-			$this->db->insert($this->getEntityTable(),$data);
69
+			$this->db->insert($this->getEntityTable(), $data);
70 70
 			
71 71
 			if (!$id = $this->db->insert_id()) {
72 72
 				return false;
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 		//update
78 78
 		else {
79 79
 			
80
-			if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){
80
+			if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) {
81 81
 				return false;
82 82
 			}
83 83
 
84 84
 		}		
85 85
 		
86
-		if(method_exists($this, 'onSave' )){
87
-			return $this->onSave( $Entity );
86
+		if (method_exists($this, 'onSave')) {
87
+			return $this->onSave($Entity);
88 88
 		}		
89 89
 		
90 90
 		return true;
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 	 * @return \Core\Infrastructure\EntityInterface
97 97
 	 * @throws BadMethodCallException
98 98
 	 */
99
-	protected function unbuildEntity(EntityInterface $Entity){
99
+	protected function unbuildEntity(EntityInterface $Entity) {
100 100
 		
101
-		$mapfileds = array_merge([ 'id' => $this->key], $this->setMappingFields());
101
+		$mapfileds = array_merge(['id' => $this->key], $this->setMappingFields());
102 102
 
103 103
 		$row = [];
104 104
 		
105
-        foreach ($mapfileds as $propery => $field ) {
105
+        foreach ($mapfileds as $propery => $field) {
106 106
 			
107
-			$method_get = 'get' . ucfirst($propery);
107
+			$method_get = 'get'.ucfirst($propery);
108 108
 			
109
-			if(!method_exists($Entity, $method_get )){
109
+			if (!method_exists($Entity, $method_get)) {
110 110
 				throw new BadMethodCallException("Метод {$method_get}  не определен");
111 111
 			}		
112 112
 			
113
-			if(method_exists($this, 'onUnBuild'.$propery )){
114
-				$value = $this->{'onUnBuild'.$propery}(  $Entity->{$method_get}() );
113
+			if (method_exists($this, 'onUnBuild'.$propery)) {
114
+				$value = $this->{'onUnBuild'.$propery}($Entity->{$method_get}());
115 115
 			}
116
-			else{
116
+			else {
117 117
 				$value = $Entity->{$method_get}();
118 118
 			}			
119 119
 			$row[$field] = $value;
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
 	 * @return \Core\Infrastructure\EntityInterface
132 132
 	 * @throws BadMethodCallException
133 133
 	 */
134
-	protected function buildEntity(EntityInterface $Entity, array $row){
134
+	protected function buildEntity(EntityInterface $Entity, array $row) {
135 135
 		
136
-		$mapfields = array_merge([ 'id' => $this->key], $this->setMappingFields());
136
+		$mapfields = array_merge(['id' => $this->key], $this->setMappingFields());
137 137
 
138
-        foreach ($mapfields as $propery => $field ) {
138
+        foreach ($mapfields as $propery => $field) {
139 139
 			
140 140
 			$value = false;
141 141
 			
142
-			$method_set = 'set' . ucfirst($propery);
142
+			$method_set = 'set'.ucfirst($propery);
143 143
 			
144
-			if(!method_exists($Entity, $method_set )){
144
+			if (!method_exists($Entity, $method_set)) {
145 145
 				throw new BadMethodCallException("Метод {$method_set}  не определен");
146 146
 			}			
147 147
 			
148 148
 			//событие onBuildField
149
-			if(method_exists($this, 'onBuild'.$propery )){
150
-				$value = $this->{'onBuild'.$propery}($field,$row);
149
+			if (method_exists($this, 'onBuild'.$propery)) {
150
+				$value = $this->{'onBuild'.$propery}($field, $row);
151 151
 			}
152
-			elseif(is_string($field) && isset($row[strtolower($field)])){
152
+			elseif (is_string($field) && isset($row[strtolower($field)])) {
153 153
 				$value = $row[strtolower($field)];
154 154
 			}
155 155
 			
156
-			if($value!==false)
156
+			if ($value!==false)
157 157
 				$Entity->{$method_set}($value);
158 158
 			
159 159
         }
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @param \Core\Infrastructure\ISpecificationCriteria $specification
176 176
 	 * @return type
177 177
 	 */
178
-	public function findBySpecification(ISpecificationCriteria $specification){
178
+	public function findBySpecification(ISpecificationCriteria $specification) {
179 179
 
180 180
 		//псеводо удаление
181 181
 		$this->setSoftDelete($specification);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		$specification->setLimit(1);
186 186
 		
187 187
 		//получение записей
188
-		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
188
+		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification);
189 189
 
190 190
         if (!$row = $res->row_array()) {
191 191
             return null;
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 		
207 207
 		if (
208 208
 				$delete_key > '' && 
209
-				$Entity->getId() > 0){
210
-			$result = $this->db->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->setKey()} = '{$Entity->getId()}'");
209
+				$Entity->getId() > 0) {
210
+			$result = $this->db->update($this->getEntityTable(), [$delete_key => 1], "{$this->setKey()} = '{$Entity->getId()}'");
211 211
 		}
212
-		elseif($Entity->getId() > 0){
212
+		elseif ($Entity->getId() > 0) {
213 213
 			$result = $this->db->delete($this->getEntityTable(), [$this->setKey() => $Entity->getId()]);
214 214
 		}
215 215
 		
216
-		if($result===true)
216
+		if ($result===true)
217 217
 			unset($Entity);
218 218
 		
219 219
 		return $result;
@@ -229,13 +229,13 @@  discard block
 block discarded – undo
229 229
 		
230 230
 		$this->setRelations($specification);
231 231
 		
232
-		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
232
+		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification);
233 233
 		
234 234
 		if (!$rows = $res->result_array()) {
235 235
             return null;
236 236
         }	
237 237
 		
238
-		foreach($rows as $k =>  $row){
238
+		foreach ($rows as $k =>  $row) {
239 239
 			$rows[$k] = $this->createEntity($row);
240 240
 		}
241 241
 		
@@ -251,22 +251,22 @@  discard block
 block discarded – undo
251 251
 	 * Выборка удаленных моделей
252 252
 	 * @param \Core\Infrastructure\ISpecificationCriteria $specification
253 253
 	 */
254
-	private function setSoftDelete(ISpecificationCriteria $specification){
255
-		if(
256
-				$this->setSoftDeleteKey()>'' 
254
+	private function setSoftDelete(ISpecificationCriteria $specification) {
255
+		if (
256
+				$this->setSoftDeleteKey() > '' 
257 257
 				&& !isset($specification->getWhere()[$this->setSoftDeleteKey()])
258 258
 				)
259
-		$specification->setWhere($this->setSoftDeleteKey(),0);
259
+		$specification->setWhere($this->setSoftDeleteKey(), 0);
260 260
 	}
261 261
 	
262 262
 	/**
263 263
 	 * Построение join-ов
264 264
 	 */
265
-	protected function setRelations(ISpecificationCriteria $Specification){
266
-		if($this->use_joins===true){
265
+	protected function setRelations(ISpecificationCriteria $Specification) {
266
+		if ($this->use_joins===true) {
267 267
 			$joins = [];
268 268
 			
269
-			foreach($this->setJoins() as $join){
269
+			foreach ($this->setJoins() as $join) {
270 270
 				$table = (new $join['mapper']($this->getAdapter()))->setEntityTable();
271 271
 				
272 272
 				$joins[$table] = $join;
Please login to merge, or discard this patch.
src/AbstractEntity.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	
Please login to merge, or discard this patch.
src/Specification.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,12 +73,12 @@
 block discarded – undo
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
         
Please login to merge, or discard this patch.
src/QueryBuilderInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.