Changeset View
Changeset View
Standalone View
Standalone View
create_generated_used.php
Show All 31 Lines | |||||
32 | function extract_from_json($json_dir, $json_file) | 32 | function extract_from_json($json_dir, $json_file) | ||
33 | { | 33 | { | ||
34 | $json_content = file_get_contents($json_dir."/".$json_file); | 34 | $json_content = file_get_contents($json_dir."/".$json_file); | ||
35 | $json_array = json_decode($json_content, true); | 35 | $json_array = json_decode($json_content, true); | ||
36 | $array_string = var_export($json_array, true); | 36 | $array_string = var_export($json_array, true); | ||
37 | # full length, without the prefix (with code), without the suffix (.json) | 37 | # full length, without the prefix (with code), without the suffix (.json) | ||
38 | $var_name_len = strlen($json_file) - (strlen(JSONFILE_PREFIX) + 3) - 5; | 38 | $var_name_len = strlen($json_file) - (strlen(JSONFILE_PREFIX) + 3) - 5; | ||
39 | $var_name = substr($json_file, strlen(JSONFILE_PREFIX)+3, $var_name_len); | 39 | $var_name = substr($json_file, strlen(JSONFILE_PREFIX)+3, $var_name_len); | ||
40 | echo "\$$var_name = $array_string;\n"; | 40 | echo " const $var_name = $array_string;\n"; | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | function convert_files($json_dir) | 43 | function convert_files($json_dir) | ||
44 | { | 44 | { | ||
45 | $all_files = scandir($json_dir); | 45 | $all_files = scandir($json_dir); | ||
46 | echo "<?php\n"; | 46 | echo "<?php\n"; | ||
47 | echo "namespace App\Data;\n"; | ||||
48 | echo "class GeneratedData {\n"; | ||||
47 | foreach ($all_files as $afile) { | 49 | foreach ($all_files as $afile) { | ||
48 | if (substr($afile, 0, strlen(JSONFILE_PREFIX)) === JSONFILE_PREFIX) { | 50 | if (substr($afile, 0, strlen(JSONFILE_PREFIX)) === JSONFILE_PREFIX) { | ||
49 | extract_from_json($json_dir, $afile); | 51 | extract_from_json($json_dir, $afile); | ||
50 | } | 52 | } | ||
51 | } | 53 | } | ||
52 | echo "?>\n"; | 54 | echo "}?>\n"; | ||
53 | } | 55 | } | ||
54 | 56 | | |||
55 | $json_files_dir = "."; | 57 | $json_files_dir = "."; | ||
56 | if (count($argv) > 1) { | 58 | if (count($argv) > 1) { | ||
57 | $json_files_dir = $argv[1]; | 59 | $json_files_dir = $argv[1]; | ||
58 | } | 60 | } | ||
59 | convert_files($json_files_dir); | 61 | convert_files($json_files_dir); | ||
60 | ?> | 62 | ?> |