annotate src/Generator/Factory/FactoryGenerator.php @ 35:55d2e5c5dad9 ls_dev_2025_09

Working on the factory, it's in a semi working state but obviously not complete
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 11 Sep 2025 21:25:51 -0400
parents
children 76584181267a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
1 <?php
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
2
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
3 namespace Wizard\MagicForger\Generator\Factory;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
4
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
5 use Symfony\Component\Console\Attribute\AsCommand;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
6 use Wizard\MagicForger\Generator\BaseGenerator;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
7 use Wizard\MagicForger\Helpers\RelationshipNavigator;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
8 use Illuminate\Support\Str;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
9
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
10 #[AsCommand(name: 'mf:factory')]
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
11 class FactoryGenerator extends BaseGenerator
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
12 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
13 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
14 * The name and signature of the console command.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
15 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
16 * @var string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
17 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
18 protected $name = 'mf:factory';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
19
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
20 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
21 * The console command description.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
22 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
23 * @var string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
24 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
25 protected $description = 'Generates the Factory File for a table.';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
26
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
27 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
28 * The type of class being generated.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
29 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
30 * @var string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
31 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
32 protected $type = 'Factory';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
33
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
34 protected static $cached_snippets = [];
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
35
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
36 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
37 * Execute the console command.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
38 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
39 * @return mixed
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
40 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
41 public function handle()
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
42 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
43 // Delegate to parent handler (includes replacements and insertions)
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
44 return parent::handle();
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
45 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
46
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
47 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
48 * Get the stub file for the generator.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
49 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
50 * @return string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
51 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
52 protected function getStub()
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
53 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
54 return $this->resolveStubPath('/stubs/factory.stub');
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
55 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
56
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
57 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
58 * Resolve the fully-qualified path to the stub.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
59 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
60 * @param string $stub
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
61 * @return string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
62 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
63 protected function resolveStubPath($stub)
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
64 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
65 return is_file($customPath = $this->laravel->basePath(trim($stub, '/')))
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
66 ? $customPath
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
67 : __DIR__.$stub;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
68 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
69
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
70 protected function getClassName($name)
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
71 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
72 return $this->factory_name($name);
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
73 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
74
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
75 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
76 * Get the stub file for the generator.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
77 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
78 * @return string
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
79 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
80 protected function getPath($name = null)
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
81 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
82 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getFactoryNamespace().'/'.$this->factory_name($this->getTableInput()).'.php');
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
83 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
84
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
85 protected function gatherRelations() {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
86 $relations = RelationshipNavigator::getRelations($this->getCurrentTable());
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
87
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
88 return $relations;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
89
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
90 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
91
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
92 protected function renderColumns() {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
93 $insert = '';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
94 foreach ($this->get_columns() as $column) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
95 if (in_array($column['name'], $this->columns_to_ignore)) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
96 continue;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
97 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
98
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
99
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
100 $type = $column['type_name'];
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
101 $nullable = ($column['nullable'] ? '->optional($weight = 0.5)' : '' );
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
102 $name = $column['name'];
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
103
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
104 // Get the expected header name
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
105 $replacements = [
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
106 '{{value}}' => 'fake()' . $nullable . '->text()',
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
107 '{{column_name}}' => $name,
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
108 ];
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
109
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
110 // date
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
111 if (in_array($type, ['date'])) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
112 $replacements['{{value}}'] = 'fake()' . $nullable . '->date()';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
113 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
114 // time
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
115 if (in_array($type, ['timestamp'])) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
116 $replacements['{{value}}'] = 'fake()' . $nullable . '->timestamp()';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
117 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
118 // checkbox
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
119 if (in_array($type, ['tinyint'])) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
120 $replacements['{{value}}'] = 'fake()' . $nullable . '->boolean()';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
121 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
122 // select
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
123 elseif (in_array($type, ['bigint']) && array_key_exists($name, $selects)) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
124 $replacements['{{header}}'] = Str::headline(Str::singular($selects[$name]));
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
125 $replacements['{{value}}'] = '{{ $item->'.Str::singular($selects[$name]).'?->name ?? "" }}';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
126 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
127 // bigint, float
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
128 elseif (in_array($type, ['bigint', 'float', 'int'])) {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
129 $replacements['{{valueClass}}'] .= ' text-start';
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
130 } else {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
131 // text area
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
132 // varchar, , etc
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
133 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
134
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
135 $snippet = $this->getSnippet('index/value');
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
136 // Replace placeholders with actual values
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
137 $values[] = str_replace(
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
138 array_keys($replacements),
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
139 $replacements,
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
140 $snippet
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
141 );
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
142
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
143
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
144
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
145 $tableName = $this->getCurrentTable();
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
146 $value = 'value'; // TODO: this should be determined based on column type
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
147 $columnName = $column['name'];
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
148
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
149 // Replace placeholders with actual values
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
150 $string = str_replace(
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
151 ['{{value}}', '{{columnName}}'],
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
152 [$value, $columnName],
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
153 $snippet
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
154 );
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
155 $insert .= sprintf("%s", $string);
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
156 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
157 dd('done');
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
158
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
159 return $insert;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
160 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
161
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
162 /**
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
163 * Get available insertions including model relationships.
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
164 *
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
165 * @return array
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
166 */
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
167 public function get_available_inserts(): array
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
168 {
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
169 // Merge parent insertions (attributes, fillable, etc.)
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
170 $inserts = parent::get_available_inserts();
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
171
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
172 // Gather and render relationships for this model
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
173 $columns = $this->renderColumns();
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
174
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
175 // Assign to stub placeholders
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
176 $inserts['# {{ factoryInsertPoint }}'] = $columns;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
177
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
178 return $inserts;
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
179 }
55d2e5c5dad9 Working on the factory, it's in a semi working state but obviously not complete
Luka Sitas <sitas.luka.97@gmail.com>
parents:
diff changeset
180 }