|
25 | 25 | #include "zend_hash.h"
|
26 | 26 | #include "zend_modules.h"
|
27 | 27 | #include "zend_interfaces.h"
|
| 28 | +#include "zend_smart_str.h" |
28 | 29 |
|
29 | 30 | #include "ext/reflection/php_reflection.h"
|
| 31 | +#include "ext/json/php_json.h" |
30 | 32 |
|
31 | 33 | #include "SAPI.h"
|
32 | 34 |
|
@@ -826,6 +828,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
826 | 828 | if (php_optarg) {
|
827 | 829 | if (strcmp(php_optarg, "diff") == 0) {
|
828 | 830 | context.mode = PHP_CLI_MODE_SHOW_INI_DIFF;
|
| 831 | + } else if(strcmp(php_optarg, "json") == 0) { |
| 832 | + context.mode = PHP_CLI_MODE_SHOW_INI_JSON; |
829 | 833 | } else {
|
830 | 834 | param_error = "Unknown argument for --ini\n";
|
831 | 835 | }
|
@@ -1148,6 +1152,56 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
1148 | 1152 | zend_array_destroy(sorted);
|
1149 | 1153 | break;
|
1150 | 1154 | }
|
| 1155 | + case PHP_CLI_MODE_SHOW_INI_JSON: |
| 1156 | + { |
| 1157 | + zval out; |
| 1158 | + array_init_size(&out, 4); |
| 1159 | + |
| 1160 | + add_assoc_string(&out, "path", PHP_CONFIG_FILE_PATH); |
| 1161 | + if (php_ini_opened_path) { |
| 1162 | + add_assoc_string(&out, "file", php_ini_opened_path); |
| 1163 | + } |
| 1164 | + if (php_ini_scanned_path) { |
| 1165 | + add_assoc_string(&out, "scan", php_ini_scanned_path); |
| 1166 | + } |
| 1167 | + if (php_ini_scanned_files) { |
| 1168 | + char* scanning = estrdup(php_ini_scanned_files); |
| 1169 | + char* token; |
| 1170 | + char* next = php_strtok_r(scanning, ",\n", &token); |
| 1171 | + zval scanned; |
| 1172 | + array_init(&scanned); |
| 1173 | + |
| 1174 | + while (next) { |
| 1175 | + while (*next == ' ' || *next == '\t') { |
| 1176 | + next++; |
| 1177 | + } |
| 1178 | + if (*next != '\0') { |
| 1179 | + char *end = next + strlen(next) - 1; |
| 1180 | + while (end > next && (*end == ' ' || *end == '\t')) { |
| 1181 | + *end = '\0'; |
| 1182 | + end--; |
| 1183 | + } |
| 1184 | + add_next_index_string(&scanned, next); |
| 1185 | + } |
| 1186 | + next = php_strtok_r(NULL, ",\n", &token); |
| 1187 | + } |
| 1188 | + add_assoc_zval(&out, "scanned", &scanned); |
| 1189 | + efree(scanning); |
| 1190 | + } |
| 1191 | + smart_str buf; |
| 1192 | + if (php_json_encode(&buf, &out, |
| 1193 | + PHP_JSON_PRETTY_PRINT) == SUCCESS) { |
| 1194 | + fwrite(ZSTR_VAL(buf.s), 1, ZSTR_LEN(buf.s), stdout); |
| 1195 | + fwrite("\r\n", 1, sizeof("\r\n"), stdout); |
| 1196 | + } else { |
| 1197 | + fprintf(stderr, |
| 1198 | + "An error occured while trying to encode configuration\n"); |
| 1199 | + EG(exit_status) = 1; |
| 1200 | + } |
| 1201 | + smart_str_free(&buf); |
| 1202 | + zval_dtor(&out); |
| 1203 | + break; |
| 1204 | + } |
1151 | 1205 | }
|
1152 | 1206 | } zend_end_try();
|
1153 | 1207 |
|
|
0 commit comments