@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | public function select(array $data = [], array $options = []) { |
| 43 | 43 | $select = $this->db->select() |
| 44 | 44 | ->from('t', $this->tableName); |
| 45 | - if(array_key_exists('select-fields', $options) && is_array($options['select-fields'])) { |
|
| 45 | + if (array_key_exists('select-fields', $options) && is_array($options['select-fields'])) { |
|
| 46 | 46 | $select->fields($options['select-fields']); |
| 47 | 47 | } |
| 48 | - if(array_key_exists('calc-found-rows', $options)) { |
|
| 48 | + if (array_key_exists('calc-found-rows', $options)) { |
|
| 49 | 49 | $select->setCalcFoundRows($options['calc-found-rows']); |
| 50 | 50 | } |
| 51 | - if(array_key_exists('preserve-types', $options)) { |
|
| 51 | + if (array_key_exists('preserve-types', $options)) { |
|
| 52 | 52 | $select->setPreserveTypes($options['preserve-types']); |
| 53 | 53 | } |
| 54 | - if(array_key_exists('select-distinct', $options)) { |
|
| 54 | + if (array_key_exists('select-distinct', $options)) { |
|
| 55 | 55 | $select->distinct($options['select-distinct']); |
| 56 | 56 | } |
| 57 | - foreach($data as $fieldName => $value) { |
|
| 58 | - if($value instanceof DBExpr) { |
|
| 57 | + foreach ($data as $fieldName => $value) { |
|
| 58 | + if ($value instanceof DBExpr) { |
|
| 59 | 59 | $select->where($value); |
| 60 | 60 | } else { |
| 61 | 61 | $select->where(sprintf("%s=?", $this->db->quoteField($fieldName)), $value); |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | - if(array_key_exists('debug', $options)) { |
|
| 64 | + if (array_key_exists('debug', $options)) { |
|
| 65 | 65 | $select->debug($options['debug']); |
| 66 | 66 | } |
| 67 | 67 | return new SelectResult($select, $options); |
@@ -76,23 +76,23 @@ discard block |
||
| 76 | 76 | $options = array_merge($this->options, $options); |
| 77 | 77 | $insert = $this->db->insert() |
| 78 | 78 | ->into($this->tableName); |
| 79 | - if(array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 79 | + if (array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 80 | 80 | $insert->setMask(array_values($options['mask'])); |
| 81 | 81 | } |
| 82 | - if(count($this->primaryKeys) === 1) { |
|
| 82 | + if (count($this->primaryKeys) === 1) { |
|
| 83 | 83 | $insert->setKey($this->primaryKeys[0]); |
| 84 | 84 | } |
| 85 | - if(array_key_exists('defaults', $options)) { |
|
| 85 | + if (array_key_exists('defaults', $options)) { |
|
| 86 | 86 | $data = array_merge($options['defaults'], $data); |
| 87 | 87 | } |
| 88 | - if(array_key_exists('insert-defaults', $options)) { |
|
| 88 | + if (array_key_exists('insert-defaults', $options)) { |
|
| 89 | 89 | $data = array_merge($options['insert-defaults'], $data); |
| 90 | 90 | } |
| 91 | - if(array_key_exists('insert-ignore', $options)) { |
|
| 91 | + if (array_key_exists('insert-ignore', $options)) { |
|
| 92 | 92 | $insert->setIgnore($options['insert-ignore']); |
| 93 | 93 | } |
| 94 | 94 | $insert->addAll($data); |
| 95 | - if(array_key_exists('debug', $options)) { |
|
| 95 | + if (array_key_exists('debug', $options)) { |
|
| 96 | 96 | $insert->debug($options['debug']); |
| 97 | 97 | } |
| 98 | 98 | return $insert->run(); |
@@ -107,23 +107,23 @@ discard block |
||
| 107 | 107 | $options = array_merge($this->options, $options); |
| 108 | 108 | $insert = $this->db->insert() |
| 109 | 109 | ->into($this->tableName); |
| 110 | - if(array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 110 | + if (array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 111 | 111 | $insert->setMask(array_values($options['mask'])); |
| 112 | 112 | } |
| 113 | - if(count($this->primaryKeys) === 1) { |
|
| 113 | + if (count($this->primaryKeys) === 1) { |
|
| 114 | 114 | $insert->setKey($this->primaryKeys[0]); |
| 115 | 115 | } |
| 116 | - if(array_key_exists('defaults', $options)) { |
|
| 116 | + if (array_key_exists('defaults', $options)) { |
|
| 117 | 117 | $data = array_merge($options['defaults'], $data); |
| 118 | 118 | } |
| 119 | - if(array_key_exists('insert-defaults', $options)) { |
|
| 119 | + if (array_key_exists('insert-defaults', $options)) { |
|
| 120 | 120 | $data = array_merge($options['insert-defaults'], $data); |
| 121 | 121 | } |
| 122 | 122 | $keyData = array_intersect_key($data, array_combine($this->primaryKeys, $this->primaryKeys)); |
| 123 | 123 | $insert->addAll($keyData); |
| 124 | 124 | $valueData = array_diff_key($data, array_combine($this->primaryKeys, $this->primaryKeys)); |
| 125 | 125 | $insert->addOrUpdateAll($valueData); |
| 126 | - if(array_key_exists('debug', $options)) { |
|
| 126 | + if (array_key_exists('debug', $options)) { |
|
| 127 | 127 | $insert->debug($options['debug']); |
| 128 | 128 | } |
| 129 | 129 | return $insert->run(); |
@@ -138,22 +138,22 @@ discard block |
||
| 138 | 138 | $options = array_merge($this->options, $options); |
| 139 | 139 | $update = $this->db->update() |
| 140 | 140 | ->table($this->tableName); |
| 141 | - if(array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 141 | + if (array_key_exists('mask', $options) && is_array($options['mask'])) { |
|
| 142 | 142 | $update->setMask(array_values($options['mask'])); |
| 143 | 143 | } |
| 144 | - if(array_key_exists('defaults', $options)) { |
|
| 144 | + if (array_key_exists('defaults', $options)) { |
|
| 145 | 145 | $data = array_merge($options['defaults'], $data); |
| 146 | 146 | } |
| 147 | - if(array_key_exists('update-defaults', $options)) { |
|
| 147 | + if (array_key_exists('update-defaults', $options)) { |
|
| 148 | 148 | $data = array_merge($options['update-defaults'], $data); |
| 149 | 149 | } |
| 150 | 150 | $keyData = array_intersect_key($data, array_combine($this->primaryKeys, $this->primaryKeys)); |
| 151 | - foreach($keyData as $fieldName => $value) { |
|
| 151 | + foreach ($keyData as $fieldName => $value) { |
|
| 152 | 152 | $update->where(sprintf("%s=?", $this->db->quoteField($fieldName)), $value); |
| 153 | 153 | } |
| 154 | 154 | $valueData = array_diff_key($data, array_combine($this->primaryKeys, $this->primaryKeys)); |
| 155 | 155 | $update->setAll($valueData); |
| 156 | - if(array_key_exists('debug', $options)) { |
|
| 156 | + if (array_key_exists('debug', $options)) { |
|
| 157 | 157 | $update->debug($options['debug']); |
| 158 | 158 | } |
| 159 | 159 | return $update->run(); |
@@ -166,23 +166,23 @@ discard block |
||
| 166 | 166 | * @throws Exception |
| 167 | 167 | */ |
| 168 | 168 | public function delete(array $data = null, array $options = []) { |
| 169 | - if(!is_array($data)) { |
|
| 169 | + if (!is_array($data)) { |
|
| 170 | 170 | throw new Exception('Missing data parameter'); |
| 171 | 171 | } |
| 172 | 172 | $options = array_merge($this->options, $options); |
| 173 | 173 | $delete = $this->db->delete() |
| 174 | 174 | ->from($this->tableName); |
| 175 | - if(array_key_exists('delete-defaults', $options)) { |
|
| 175 | + if (array_key_exists('delete-defaults', $options)) { |
|
| 176 | 176 | $data = array_merge($options['delete-defaults'], $data); |
| 177 | 177 | } |
| 178 | 178 | $keyData = array_intersect_key($data, array_combine($this->primaryKeys, $this->primaryKeys)); |
| 179 | - if(count($keyData) !== count($this->primaryKeys) && !$options['allow-delete-all']) { |
|
| 179 | + if (count($keyData) !== count($this->primaryKeys) && !$options['allow-delete-all']) { |
|
| 180 | 180 | throw new Exception("You try to delete all data from {$this->tableName} which is not allowed by configuration"); |
| 181 | 181 | } |
| 182 | - foreach($keyData as $fieldName => $value) { |
|
| 182 | + foreach ($keyData as $fieldName => $value) { |
|
| 183 | 183 | $delete->where(sprintf("%s=?", $this->db->quoteField($fieldName)), $value); |
| 184 | 184 | } |
| 185 | - if(array_key_exists('debug', $options)) { |
|
| 185 | + if (array_key_exists('debug', $options)) { |
|
| 186 | 186 | $delete->debug($options['debug']); |
| 187 | 187 | } |
| 188 | 188 | return $delete->run(); |