|
24 | 24 | $php_content = "<?php\n"; |
25 | 25 | $php_content .= "/**\n * GENERATED UTILITY LOADER FILE.\n * DO NOT EDIT THIS FILE MANUALLY.\n * Run 'php generate-utility-list.php' to regenerate this list.\n */\n\n"; |
26 | 26 |
|
27 | | -// Start the function definition |
28 | | -$php_content .= "function load_core_utilities()\n{\n"; |
| 27 | +// Wrap function declaration to prevent duplicate function errors |
| 28 | +$php_content .= "if (!function_exists('load_core_utilities')) {\n"; |
| 29 | +$php_content .= " function load_core_utilities()\n"; |
| 30 | +$php_content .= " {\n"; |
29 | 31 |
|
30 | 32 | // Start the array list |
31 | | -$php_content .= " \$utility_files = [\n"; |
| 33 | +$php_content .= " \$utility_files = [\n"; |
32 | 34 |
|
33 | | -// Add each file to the array list, ensuring critical files are first for safety |
34 | | -// You must manually define the critical ordering (e.g., cookies-baked.php) here. |
35 | | -// For demonstration, we'll list them alphabetically and trust dependencies are fine, |
36 | | -// but you should manually move critical files (like 'cookies-baked.php') to the top of the array if needed. |
| 35 | +// Add each file to the array list |
37 | 36 | foreach ($utility_files as $file) { |
38 | 37 | $php_content .= " '" . $file . "',\n"; |
39 | 38 | } |
40 | 39 |
|
41 | 40 | $php_content .= " ];\n\n"; |
42 | 41 |
|
43 | | -$php_content .= " \$utility_dir = __DIR__ . DIRECTORY_SEPARATOR . 'utility' . DIRECTORY_SEPARATOR;\n"; |
44 | | -$php_content .= " foreach (\$utility_files as \$file) {\n"; |
45 | | -$php_content .= " require_once \$utility_dir . \$file;\n"; |
| 42 | +$php_content .= " \$utility_dir = __DIR__ . DIRECTORY_SEPARATOR . 'utility' . DIRECTORY_SEPARATOR;\n"; |
| 43 | +$php_content .= " foreach (\$utility_files as \$file) {\n"; |
| 44 | +$php_content .= " require_once \$utility_dir . \$file;\n"; |
| 45 | +$php_content .= " }\n"; |
46 | 46 | $php_content .= " }\n"; |
47 | 47 | $php_content .= "}\n\n"; |
48 | | -$php_content .= "load_core_utilities();\n"; |
| 48 | + |
| 49 | +// Add guard to prevent calling before function is defined |
| 50 | +$php_content .= "if (!function_exists('load_core_utilities')) {\n"; |
| 51 | +$php_content .= " load_core_utilities();\n"; |
| 52 | +$php_content .= "}\n"; |
49 | 53 |
|
50 | 54 | // Write the content to the target file |
51 | 55 | if (file_put_contents($output_file, $php_content) !== false) { |
|
0 commit comments