Mercurial > packages > magicforger
comparison src/Replacer/TableReplacer.php @ 31:8dd668020310 codex
started converting too bootstrap, also better support for casts
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Tue, 19 Aug 2025 20:34:53 -0400 |
| parents | 827efbf4d73c |
| children | b5c6ebd33547 |
comparison
equal
deleted
inserted
replaced
| 30:21439512ba69 | 31:8dd668020310 |
|---|---|
| 34 { | 34 { |
| 35 $insert = ''; | 35 $insert = ''; |
| 36 foreach ($this->get_columns() as $column) { | 36 foreach ($this->get_columns() as $column) { |
| 37 $column_name = $column['name']; | 37 $column_name = $column['name']; |
| 38 $insert .= sprintf('$item->%s = $validated["%s"] ?? NULL;', $column_name, $column_name)."\n"; | 38 $insert .= sprintf('$item->%s = $validated["%s"] ?? NULL;', $column_name, $column_name)."\n"; |
| 39 } | |
| 40 | |
| 41 return $insert; | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Get a string representation of table attributes. | |
| 46 */ | |
| 47 protected function getCasts(): string | |
| 48 { | |
| 49 $insert = ''; | |
| 50 foreach ($this->get_columns() as $column) { | |
| 51 if (in_array($column['name'], $this->columns_to_ignore)) { | |
| 52 continue; | |
| 53 } | |
| 54 $type = $column['type_name']; | |
| 55 //date | |
| 56 if(in_array($type, ['date'])) { | |
| 57 $insert .= sprintf("'%s' => 'date:Y-m-d',", $column['name'])."\n"; | |
| 58 } | |
| 59 //time | |
| 60 if(in_array($type, ['timestamp'])) { | |
| 61 $insert .= sprintf("'%s' => 'date:Y-m-d H:i',", $column['name'])."\n"; | |
| 62 } | |
| 39 } | 63 } |
| 40 | 64 |
| 41 return $insert; | 65 return $insert; |
| 42 } | 66 } |
| 43 | 67 |
| 110 public function get_available_inserts(): array | 134 public function get_available_inserts(): array |
| 111 { | 135 { |
| 112 return [ | 136 return [ |
| 113 '// {{ valuesForCreation }}' => $this->getValuesForCreation(), | 137 '// {{ valuesForCreation }}' => $this->getValuesForCreation(), |
| 114 '# {{ attributeInsertPoint }}' => $this->getAttributes(), | 138 '# {{ attributeInsertPoint }}' => $this->getAttributes(), |
| 139 '# {{ castInsertPoint }}' => $this->getCasts(), | |
| 115 '# {{ fillableInsertPoint }}' => $this->getFillable(), | 140 '# {{ fillableInsertPoint }}' => $this->getFillable(), |
| 116 '// {{ valuesForValidation }}' => $this->getValuesForValidation(), | 141 '// {{ valuesForValidation }}' => $this->getValuesForValidation(), |
| 117 ]; | 142 ]; |
| 118 } | 143 } |
| 119 } | 144 } |
