@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | private bool $full = false; |
| 15 | 15 | private ?string $clause = null; |
| 16 | 16 | |
| 17 | - private array $where = [''=> ["1",'=',"1"] ]; |
|
| 17 | + private array $where = [''=> ["1", '=', "1"]]; |
|
| 18 | 18 | |
| 19 | 19 | private function mountTable_Field(string $field, $value = null) |
| 20 | 20 | { |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | $type = $value; |
| 27 | 27 | $maxlength = null; |
| 28 | 28 | |
| 29 | - if(strpos($value,'(')){ |
|
| 30 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type; |
|
| 31 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type; |
|
| 32 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type; |
|
| 29 | + if (strpos($value, '(')) { |
|
| 30 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type; |
|
| 31 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type; |
|
| 32 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - $maxlength = (in_array( $type , ['string','float','int'])) ? substr($value,(strpos($value,'(')+1),-1) : $maxlength; |
|
| 36 | - $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength; |
|
| 37 | - $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength; |
|
| 38 | - $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength; |
|
| 35 | + $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($value, (strpos($value, '(') + 1), -1) : $maxlength; |
|
| 36 | + $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength; |
|
| 37 | + $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength; |
|
| 38 | + $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength; |
|
| 39 | 39 | |
| 40 | 40 | $this->$field = ['maxlength' => $maxlength]; |
| 41 | 41 | $this->$field = ['type' => $type]; |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | public function check_where_array(array $where) |
| 80 | 80 | { |
| 81 | - if(count($where) != 3){ |
|
| 82 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$where)); |
|
| 81 | + if (count($where) != 3) { |
|
| 82 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $where)); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if(!array_key_exists($where[0],$this->data) && $this->full){ |
|
| 85 | + if (!array_key_exists($where[0], $this->data) && $this->full) { |
|
| 86 | 86 | throw new Exception("{$where[0]} field does not exist in the table {$this->table}."); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | private function mountRemove(): array |
| 91 | 91 | { |
| 92 | 92 | $return = ['data' => [], 'where' => '']; |
| 93 | - foreach($this->where as $clause => $condition){ |
|
| 94 | - if(strlen($clause) === 0){ |
|
| 93 | + foreach ($this->where as $clause => $condition) { |
|
| 94 | + if (strlen($clause) === 0) { |
|
| 95 | 95 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
| 96 | 96 | $return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - foreach($condition as $value){ |
|
| 100 | + foreach ($condition as $value) { |
|
| 101 | 101 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
| 102 | 102 | $return['data'] .= "q_{$value[0]}={$value[2]}&"; |
| 103 | 103 | } |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | $return = ['data' => []]; |
| 111 | 111 | |
| 112 | 112 | foreach ($this->data as $key => $value) { |
| 113 | - if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){ |
|
| 113 | + if (strstr($this->data[$key]['extra'], 'auto_increment') && $key !== $this->primary) { |
|
| 114 | 114 | continue; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){ |
|
| 117 | + if (($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key) { |
|
| 118 | 118 | $return['data'][$key] = $this->data[$key]['value']; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $this->transaction('begin'); |
| 128 | 128 | |
| 129 | - try{ |
|
| 129 | + try { |
|
| 130 | 130 | $this->update( |
| 131 | 131 | $this->mountSave()['data'], |
| 132 | 132 | "{$this->primary}=:{$this->primary}", |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $this->check_fail(); |
| 137 | 137 | |
| 138 | 138 | $this->transaction('commit'); |
| 139 | - }catch(Exception $er){ |
|
| 139 | + } catch (Exception $er) { |
|
| 140 | 140 | $this->transaction('rollback'); |
| 141 | 141 | throw $er; |
| 142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | $key = (!$key) ? '' : " {$key} "; |
| 154 | 154 | |
| 155 | - if(is_array($value[0])){ |
|
| 155 | + if (is_array($value[0])) { |
|
| 156 | 156 | |
| 157 | 157 | foreach ($value as $k => $v) { |
| 158 | 158 | $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
@@ -171,21 +171,21 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | private function mountSelect() |
| 173 | 173 | { |
| 174 | - $select = implode(',',array_keys($this->select)); |
|
| 174 | + $select = implode(',', array_keys($this->select)); |
|
| 175 | 175 | |
| 176 | - $this->query = str_replace('*', $select,$this->query); |
|
| 176 | + $this->query = str_replace('*', $select, $this->query); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | private function mountLimit() |
| 180 | 180 | { |
| 181 | - if(!is_null($this->limit)){ |
|
| 181 | + if (!is_null($this->limit)) { |
|
| 182 | 182 | $this->query .= " LIMIT {$this->limit}"; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | private function mountOffset() |
| 187 | 187 | { |
| 188 | - if(!is_null($this->offset)){ |
|
| 188 | + if (!is_null($this->offset)) { |
|
| 189 | 189 | $this->query .= " OFFSET {$this->offset}"; |
| 190 | 190 | } |
| 191 | 191 | } |