annotate src/Generator/Factory/FactoryGenerator.php @ 36:76584181267a ls_dev_2025_09

Got factories working in a basic way, not sure how complex tables will handle it though
author Luka Sitas <sitas.luka.97@gmail.com>
date Sat, 20 Sep 2025 17:14:29 -0400
parents 55d2e5c5dad9
children b5c6ebd33547
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 = '';
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
94 $values = [];
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
95 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
96 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
97 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
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)' : '' );
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
102 $value = 'fake()' . $nullable;
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
103 $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
104
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 // 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
106 $replacements = [
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
107 '{{value}}' => $value . '->text()',
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
108 '{{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
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
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 // 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 if (in_array($type, ['date'])) {
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
113 $replacements['{{value}}'] = $value . '->date()';
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
114 }
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 // 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
116 if (in_array($type, ['timestamp'])) {
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
117 $replacements['{{value}}'] = $value . '->timestamp()';
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
118 }
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 // 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
120 if (in_array($type, ['tinyint'])) {
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
121 $replacements['{{value}}'] = $value . '->boolean()';
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
122 }
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 // 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
124 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
125 $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
126 $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
127 }
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 // bigint, float
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
129 elseif (in_array($type, ['bigint', 'int'])) {
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
130 $replacements['{{value}}'] = $value . '->randomNumber()';
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
131 }
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
132 elseif (in_array($type, ['float'])) {
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
133 $replacements['{{value}}'] = $value . '->randomFloat()';
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
134 } 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
135 // 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
136 // 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
137 }
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
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
139 $snippet = $this->getSnippet('value');
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
140 // 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
141 $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
142 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
143 $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
144 $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
145 );
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
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 // 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
148 }
36
76584181267a Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents: 35
diff changeset
149 $insert = implode("\n", $values);
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
150
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 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
152 }
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
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 * 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
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 * @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
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 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
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 // 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
162 $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
163
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 // 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
165 $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
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 // 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
168 $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
169
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 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
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 }