Mercurial > packages > magicforger
comparison src/Generator/Model/ModelGenerator.php @ 26:555bfaa500ac codex
Big update for view creation based on the column type.
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Thu, 15 May 2025 21:50:38 -0400 |
| parents | 31109c61ce02 |
| children | f88d2d5dee30 |
comparison
equal
deleted
inserted
replaced
| 25:1a717c7b211f | 26:555bfaa500ac |
|---|---|
| 82 * @return string | 82 * @return string |
| 83 */ | 83 */ |
| 84 protected function getPath($name = null) | 84 protected function getPath($name = null) |
| 85 { | 85 { |
| 86 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getModelNamespace().'/'.$this->model_name($this->getTableInput()).'.php'); | 86 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getModelNamespace().'/'.$this->model_name($this->getTableInput()).'.php'); |
| 87 } | |
| 88 | |
| 89 protected function getSnippet($snippet_name) | |
| 90 { | |
| 91 // Cache snippet contents to avoid re-reading files | |
| 92 if (! isset(self::$cached_snippets[$snippet_name])) { | |
| 93 self::$cached_snippets[$snippet_name] = $this->files->get( | |
| 94 $this->resolveStubPath("/snippets/$snippet_name.stub")); | |
| 95 } | |
| 96 | |
| 97 return self::$cached_snippets[$snippet_name]; | |
| 98 } | 87 } |
| 99 | 88 |
| 100 protected function gatherRelations() { | 89 protected function gatherRelations() { |
| 101 $relations = RelationshipNavigator::getRelations($this->getCurrentTable()); | 90 $relations = RelationshipNavigator::getRelations($this->getCurrentTable()); |
| 102 | 91 |
| 203 // Build code blocks for each relation type | 192 // Build code blocks for each relation type |
| 204 $belongs = !empty($rendered['belongsTo']) ? implode("\n ", $rendered['belongsTo']) : ''; | 193 $belongs = !empty($rendered['belongsTo']) ? implode("\n ", $rendered['belongsTo']) : ''; |
| 205 $hasMany = !empty($rendered['hasMany']) ? implode("\n ", $rendered['hasMany']) : ''; | 194 $hasMany = !empty($rendered['hasMany']) ? implode("\n ", $rendered['hasMany']) : ''; |
| 206 $belongsMany = !empty($rendered['belongsToMany']) ? implode("\n ", $rendered['belongsToMany']) : ''; | 195 $belongsMany = !empty($rendered['belongsToMany']) ? implode("\n ", $rendered['belongsToMany']) : ''; |
| 207 | 196 |
| 197 // Default relations are based on the belongsTo relationship | |
| 198 $default_relations = implode(", \n", array_map(function ($rel) {return '\'' . Str::singular($rel['table']) . '\''; }, $relations['belongsTo'])); | |
| 199 | |
| 208 // Assign to stub placeholders | 200 // Assign to stub placeholders |
| 209 $inserts['# {{ belongs_to_relationships }}'] = $belongs; | 201 $inserts['# {{ belongs_to_relationships }}'] = $belongs; |
| 210 $inserts['# {{ has_many_relationships }}'] = $hasMany; | 202 $inserts['# {{ has_many_relationships }}'] = $hasMany; |
| 211 $inserts['# {{ has_many_through_relationships }}'] = $belongsMany; | 203 $inserts['# {{ has_many_through_relationships }}'] = $belongsMany; |
| 204 $inserts['# {{ defaultRelationsInsertPoint }}'] = $default_relations; | |
| 212 | 205 |
| 213 return $inserts; | 206 return $inserts; |
| 214 } | 207 } |
| 215 } | 208 } |
