| Total Complexity | 11 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 13 | class Create extends EmulateBySql |
||
| 14 | { |
||
| 15 | use Utils; |
||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $_index; |
||
| 20 | |||
| 21 | public function setBody($params = null) |
||
| 22 | { |
||
| 23 | if (isset($this->_index)) { |
||
| 24 | $columns = []; |
||
| 25 | if(isset($params['columns'] )) { |
||
| 26 | foreach ($params['columns'] as $name => $settings) { |
||
| 27 | $column = $name . ' ' . $settings['type']; |
||
| 28 | if (isset($settings['options']) && count($settings['options']) > 0) { |
||
| 29 | $column .= ' ' . implode(' ', $settings['options']); |
||
| 30 | } |
||
| 31 | $columns[] = $column; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | $options = ""; |
||
| 35 | if(isset($params['settings'] )) { |
||
| 36 | foreach($params['settings'] as $name=>$value) { |
||
| 37 | $options.=" ".$name." = ".$value; |
||
| 38 | } |
||
| 39 | |||
| 40 | } |
||
| 41 | return parent::setBody(['query' => "CREATE TABLE ".$this->_index. |
||
| 42 | (count($columns)>0?"(".implode(",",$columns).")":" ") |
||
| 43 | .$options]); |
||
| 44 | } |
||
| 45 | throw new RuntimeException('Index name is missing.'); |
||
| 46 | } |
||
| 47 | /** |
||
| 48 | * @return mixed |
||
| 49 | */ |
||
| 50 | public function getIndex() |
||
| 51 | { |
||
| 52 | return $this->_index; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param mixed $index |
||
| 57 | */ |
||
| 58 | public function setIndex($index) |
||
| 61 | } |
||
| 62 | |||
| 63 | } |