comparison src/ConfigHelper.php @ 23:827efbf4d73c main-dev

Huge changes to the relationships for models and more complex
author Luka Sitas <sitas.luka.97@gmail.com>
date Fri, 11 Apr 2025 20:50:20 -0400
parents 19b7a8de0019
children
comparison
equal deleted inserted replaced
22:ee8ef14e158d 23:827efbf4d73c
67 * 67 *
68 * NOTE: The only issue is when a string value has `=>\n[`, it will get converted to `=> [` 68 * NOTE: The only issue is when a string value has `=>\n[`, it will get converted to `=> [`
69 * 69 *
70 * @see https://www.php.net/manual/en/function.var-export.php 70 * @see https://www.php.net/manual/en/function.var-export.php
71 * 71 *
72 * @param bool $return 72 * @param bool $return
73 *
74 * @return string|string[]|null 73 * @return string|string[]|null
75 */ 74 */
76 public static function varexport(mixed $expression, $return = false): string|array|null 75 public static function varexport(mixed $expression, $return = false): string|array|null
77 { 76 {
78 $export = var_export($expression, true); 77 $export = var_export($expression, true);
123 122
124 // Check foreign key references from this table 123 // Check foreign key references from this table
125 $foreign_keys_list = $table_foreign_keys[$table]; 124 $foreign_keys_list = $table_foreign_keys[$table];
126 foreach ($foreign_keys_list as $fk) { 125 foreach ($foreign_keys_list as $fk) {
127 $foreign_keys[$fk->getLocalColumns()[0]] = [ 126 $foreign_keys[$fk->getLocalColumns()[0]] = [
128 'foreign_table' => $fk->getForeignTableName(), 127 'foreign_table' => $fk->getForeignTableName(),
129 'foreign_column' => $fk->getForeignColumns()[0], 128 'foreign_column' => $fk->getForeignColumns()[0],
130 ]; 129 ];
131 } 130 }
132 131
133 foreach ($table_columns as $column) { 132 foreach ($table_columns as $column) {
134 $full_class = get_class($column->getType()); 133 $full_class = get_class($column->getType());
135 $class_parts = explode('\\', $full_class); 134 $class_parts = explode('\\', $full_class);
136 $class_name = end($class_parts); 135 $class_name = end($class_parts);
137 136
138 $columns[$column->getName()] = [ 137 $columns[$column->getName()] = [
139 'type' => $class_name, 138 'type' => $class_name,
140 'should_insert' => [ 139 'should_insert' => [
141 'controller' => true, 140 'controller' => true,
142 'model' => true, 141 'model' => true,
143 'requests' => true, 142 'requests' => true,
144 'views' => true, 143 'views' => true,
145 ], 144 ],
146 ]; 145 ];
147 } 146 }
148 // Check foreign key references to this table 147 // Check foreign key references to this table
149 foreach ($tables as $other_table) { 148 foreach ($tables as $other_table) {
150 if ($other_table != $table) { 149 if ($other_table != $table) {
151 $foreign_keys_list = $table_foreign_keys[$other_table]; 150 $foreign_keys_list = $table_foreign_keys[$other_table];
152 foreach ($foreign_keys_list as $fk) { 151 foreach ($foreign_keys_list as $fk) {
153 if ($fk->getForeignTableName() == $table) { 152 if ($fk->getForeignTableName() == $table) {
154 $foreign_keys_reverse[] = [ 153 $foreign_keys_reverse[] = [
155 'table' => $other_table, 154 'table' => $other_table,
156 'column' => $fk->getLocalColumns()[0], 155 'column' => $fk->getLocalColumns()[0],
157 ]; 156 ];
158 } 157 }
159 } 158 }
160 } 159 }
161 } 160 }
162 $insert_tables[$table] = []; 161 $insert_tables[$table] = [];
172 } 171 }
173 172
174 /** 173 /**
175 * Merge two arrays and ensure priority values do not get overwritten. 174 * Merge two arrays and ensure priority values do not get overwritten.
176 * 175 *
177 * @param array $priority 176 * @param array $priority
178 * @param array $merged 177 * @param array $merged
179 */ 178 */
180 private static function merge_array_priority(&$priority, $merged): void 179 private static function merge_array_priority(&$priority, $merged): void
181 { 180 {
182 foreach ($merged as $key => $value) { 181 foreach ($merged as $key => $value) {
183 // if the priority key is not set, automatically add the merged values 182 // if the priority key is not set, automatically add the merged values
184 if (!isset($priority[$key])) { 183 if (! isset($priority[$key])) {
185 $priority[$key] = $value; 184 $priority[$key] = $value;
186 } else { 185 } else {
187 // if the value is an array recursively merge with priority 186 // if the value is an array recursively merge with priority
188 if (is_array($value) && is_array($priority[$key])) { 187 if (is_array($value) && is_array($priority[$key])) {
189 self::merge_array_priority($priority[$key], $value); 188 self::merge_array_priority($priority[$key], $value);