setup-php 2.13.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +990 -922
  3. package/lib/config.d.ts +3 -0
  4. package/lib/config.js +71 -71
  5. package/lib/config.js.map +1 -1
  6. package/lib/coverage.d.ts +5 -0
  7. package/lib/coverage.js +97 -87
  8. package/lib/coverage.js.map +1 -1
  9. package/lib/extensions.d.ts +4 -0
  10. package/lib/extensions.js +214 -200
  11. package/lib/extensions.js.map +1 -1
  12. package/lib/fetch.d.ts +1 -0
  13. package/lib/fetch.js +63 -0
  14. package/lib/fetch.js.map +1 -0
  15. package/lib/install.d.ts +2 -0
  16. package/lib/install.js +75 -81
  17. package/lib/install.js.map +1 -1
  18. package/lib/tools.d.ts +23 -0
  19. package/lib/tools.js +367 -386
  20. package/lib/tools.js.map +1 -1
  21. package/lib/utils.d.ts +21 -0
  22. package/lib/utils.js +261 -291
  23. package/lib/utils.js.map +1 -1
  24. package/package.json +67 -56
  25. package/src/config.ts +82 -82
  26. package/src/configs/brew_extensions +31 -0
  27. package/src/configs/composer.env +2 -0
  28. package/src/configs/ini/jit.ini +3 -0
  29. package/src/configs/ini/php.ini +2 -0
  30. package/src/configs/ini/xdebug.ini +1 -0
  31. package/src/configs/os_releases.csv +19 -17
  32. package/src/configs/php-versions.json +6 -5
  33. package/src/configs/php_packages +12 -0
  34. package/src/configs/{php.json → pm/php.json} +29 -29
  35. package/src/configs/{phpunit.json → pm/phpunit.json} +24 -24
  36. package/src/configs/tools.json +278 -235
  37. package/src/configs/tools_schema.json +125 -114
  38. package/src/coverage.ts +144 -142
  39. package/src/extensions.ts +367 -349
  40. package/src/fetch.ts +54 -0
  41. package/src/install.ts +66 -82
  42. package/src/scripts/darwin.sh +285 -249
  43. package/src/scripts/extensions/add_extensions.ps1 +194 -0
  44. package/src/scripts/extensions/add_extensions.sh +184 -0
  45. package/src/scripts/{ext → extensions}/blackfire.ps1 +32 -32
  46. package/src/scripts/{ext → extensions}/blackfire.sh +22 -21
  47. package/src/scripts/{ext → extensions}/couchbase.sh +43 -43
  48. package/src/scripts/{ext → extensions}/cubrid.sh +60 -60
  49. package/src/scripts/extensions/extension_map.php +132 -0
  50. package/src/scripts/{ext → extensions}/firebird.ps1 +19 -19
  51. package/src/scripts/{ext → extensions}/firebird.sh +39 -35
  52. package/src/scripts/{ext → extensions}/gearman.sh +22 -22
  53. package/src/scripts/{ext → extensions}/geos.sh +17 -17
  54. package/src/scripts/{ext → extensions}/http.ps1 +54 -54
  55. package/src/scripts/{ext → extensions}/http.sh +109 -120
  56. package/src/scripts/{ext → extensions}/intl.sh +23 -23
  57. package/src/scripts/{ext → extensions}/ioncube.ps1 +33 -32
  58. package/src/scripts/{ext → extensions}/ioncube.sh +21 -19
  59. package/src/scripts/{ext → extensions}/oci.ps1 +85 -60
  60. package/src/scripts/{ext → extensions}/oci.sh +65 -63
  61. package/src/scripts/{ext → extensions}/patches/firebird.sh +11 -11
  62. package/src/scripts/{ext → extensions}/patches/geos.sh +7 -7
  63. package/src/scripts/{ext → extensions}/patches/http.sh +11 -11
  64. package/src/scripts/{ext → extensions}/patches/pdo_oci.sh +6 -6
  65. package/src/scripts/{ext → extensions}/patches/phpize.sh +26 -26
  66. package/src/scripts/{ext → extensions}/patches/protobuf.sh +4 -4
  67. package/src/scripts/{ext → extensions}/phalcon.ps1 +54 -54
  68. package/src/scripts/{ext → extensions}/phalcon.sh +58 -58
  69. package/src/scripts/{ext → extensions}/source.sh +145 -144
  70. package/src/scripts/extensions/sqlsrv.sh +15 -0
  71. package/src/scripts/linux.sh +269 -256
  72. package/src/scripts/tools/add_tools.ps1 +239 -26
  73. package/src/scripts/tools/add_tools.sh +175 -20
  74. package/src/scripts/tools/blackfire.ps1 +19 -19
  75. package/src/scripts/tools/blackfire.sh +40 -39
  76. package/src/scripts/tools/grpc_php_plugin.ps1 +21 -21
  77. package/src/scripts/tools/grpc_php_plugin.sh +58 -58
  78. package/src/scripts/tools/ppa.sh +192 -151
  79. package/src/scripts/tools/protoc.ps1 +38 -38
  80. package/src/scripts/tools/protoc.sh +28 -28
  81. package/src/scripts/tools/symfony.ps1 +14 -0
  82. package/src/scripts/tools/symfony.sh +13 -0
  83. package/src/scripts/unix.sh +186 -0
  84. package/src/scripts/win32.ps1 +352 -494
  85. package/src/tools.ts +512 -538
  86. package/src/utils.ts +415 -500
  87. package/.eslintrc.json +0 -16
  88. package/.github/CODE_OF_CONDUCT.md +0 -76
  89. package/.github/CONTRIBUTING.md +0 -70
  90. package/.github/FUNDING.yml +0 -7
  91. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -42
  92. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -26
  93. package/.github/PULL_REQUEST_TEMPLATE.md +0 -37
  94. package/.github/SECURITY.md +0 -29
  95. package/.github/workflows/docs.yml +0 -77
  96. package/.github/workflows/node-workflow.yml +0 -51
  97. package/.github/workflows/workflow.yml +0 -78
  98. package/.idea/workspace.xml +0 -113
  99. package/.prettierrc.json +0 -12
  100. package/__tests__/config.test.ts +0 -52
  101. package/__tests__/coverage.test.ts +0 -110
  102. package/__tests__/extensions.test.ts +0 -263
  103. package/__tests__/install.test.ts +0 -175
  104. package/__tests__/tools.test.ts +0 -524
  105. package/__tests__/utils.test.ts +0 -307
  106. package/action.yml +0 -29
  107. package/dist/index.js +0 -3051
  108. package/examples/bedrock.yml +0 -32
  109. package/examples/blackfire-player.yml +0 -31
  110. package/examples/blackfire.yml +0 -31
  111. package/examples/cakephp-mysql.yml +0 -114
  112. package/examples/cakephp-postgres.yml +0 -112
  113. package/examples/cakephp.yml +0 -92
  114. package/examples/codeigniter.yml +0 -34
  115. package/examples/laravel-mysql.yml +0 -74
  116. package/examples/laravel-postgres.yml +0 -74
  117. package/examples/laravel.yml +0 -42
  118. package/examples/lumen-mysql.yml +0 -74
  119. package/examples/lumen-postgres.yml +0 -74
  120. package/examples/lumen.yml +0 -38
  121. package/examples/phalcon-mysql.yml +0 -74
  122. package/examples/phalcon-postgres.yml +0 -73
  123. package/examples/sage.yml +0 -57
  124. package/examples/slim-framework.yml +0 -34
  125. package/examples/symfony-mysql.yml +0 -57
  126. package/examples/symfony-postgres.yml +0 -55
  127. package/examples/symfony.yml +0 -39
  128. package/examples/yii2-mysql.yml +0 -73
  129. package/examples/yii2-postgres.yml +0 -71
  130. package/examples/zend-framework.yml +0 -36
  131. package/jest.config.js +0 -12
  132. package/lib/sapi.js +0 -64
  133. package/src/scripts/common.sh +0 -314
  134. package/tsconfig.json +0 -18
package/src/utils.ts CHANGED
@@ -1,500 +1,415 @@
1
- import {IncomingMessage, OutgoingHttpHeaders} from 'http';
2
- import * as fs from 'fs';
3
- import * as https from 'https';
4
- import * as path from 'path';
5
- import * as url from 'url';
6
- import * as core from '@actions/core';
7
-
8
- /**
9
- * Function to read environment variable and return a string value.
10
- *
11
- * @param property
12
- */
13
- export async function readEnv(property: string): Promise<string> {
14
- const property_lc: string = property.toLowerCase();
15
- const property_uc: string = property.toUpperCase();
16
- return (
17
- process.env[property] ||
18
- process.env[property_lc] ||
19
- process.env[property_uc] ||
20
- process.env[property_lc.replace('_', '-')] ||
21
- process.env[property_uc.replace('_', '-')] ||
22
- ''
23
- );
24
- }
25
-
26
- /**
27
- * Function to get inputs from both with and env annotations.
28
- *
29
- * @param name
30
- * @param mandatory
31
- */
32
- export async function getInput(
33
- name: string,
34
- mandatory: boolean
35
- ): Promise<string> {
36
- const input = core.getInput(name);
37
- const env_input = await readEnv(name);
38
- switch (true) {
39
- case input != '':
40
- return input;
41
- case input == '' && env_input != '':
42
- return env_input;
43
- case input == '' && env_input == '' && mandatory:
44
- throw new Error(`Input required and not supplied: ${name}`);
45
- default:
46
- return '';
47
- }
48
- }
49
-
50
- /**
51
- * Function to fetch an URL
52
- *
53
- * @param input_url
54
- * @param auth_token
55
- */
56
- export async function fetch(
57
- input_url: string,
58
- auth_token?: string
59
- ): Promise<Record<string, string>> {
60
- const fetch_promise: Promise<Record<string, string>> = new Promise(
61
- resolve => {
62
- const url_object: url.UrlObject = new url.URL(input_url);
63
- const headers: OutgoingHttpHeaders = {
64
- 'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php`
65
- };
66
- if (auth_token) {
67
- headers.authorization = 'Bearer ' + auth_token;
68
- }
69
- const options: https.RequestOptions = {
70
- hostname: url_object.hostname,
71
- path: url_object.pathname,
72
- headers: headers
73
- };
74
- const req = https.get(options, (res: IncomingMessage) => {
75
- if (res.statusCode != 200) {
76
- resolve({error: `${res.statusCode}: ${res.statusMessage}`});
77
- } else {
78
- let body = '';
79
- res.setEncoding('utf8');
80
- res.on('data', chunk => (body += chunk));
81
- res.on('end', () => resolve({data: `${body}`}));
82
- }
83
- });
84
- req.end();
85
- }
86
- );
87
- return await fetch_promise;
88
- }
89
-
90
- /** Function to get manifest URL
91
- *
92
- */
93
- export async function getManifestURL(): Promise<string> {
94
- return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
95
- }
96
-
97
- /**
98
- * Function to parse PHP version.
99
- *
100
- * @param version
101
- */
102
- export async function parseVersion(version: string): Promise<string> {
103
- const manifest = await getManifestURL();
104
- switch (true) {
105
- case /^(latest|\d+\.x)$/.test(version):
106
- return JSON.parse((await fetch(manifest))['data'])[version];
107
- default:
108
- switch (true) {
109
- case version.length > 1:
110
- return version.slice(0, 3);
111
- default:
112
- return version + '.0';
113
- }
114
- }
115
- }
116
-
117
- /**
118
- * Async foreach loop
119
- *
120
- * @author https://github.com/Atinux
121
- * @param array
122
- * @param callback
123
- */
124
- export async function asyncForEach(
125
- array: Array<string>,
126
- callback: (
127
- element: string,
128
- index: number,
129
- array: Array<string>
130
- ) => Promise<void>
131
- ): Promise<void> {
132
- for (let index = 0; index < array.length; index++) {
133
- await callback(array[index], index, array);
134
- }
135
- }
136
-
137
- /**
138
- * Get color index
139
- *
140
- * @param type
141
- */
142
- export async function color(type: string): Promise<string> {
143
- switch (type) {
144
- case 'error':
145
- return '31';
146
- default:
147
- case 'success':
148
- return '32';
149
- case 'warning':
150
- return '33';
151
- }
152
- }
153
-
154
- /**
155
- * Log to console
156
- *
157
- * @param message
158
- * @param os_version
159
- * @param log_type
160
- */
161
- export async function log(
162
- message: string,
163
- os_version: string,
164
- log_type: string
165
- ): Promise<string> {
166
- switch (os_version) {
167
- case 'win32':
168
- return (
169
- 'printf "\\033[' +
170
- (await color(log_type)) +
171
- ';1m' +
172
- message +
173
- ' \\033[0m"'
174
- );
175
-
176
- case 'linux':
177
- case 'darwin':
178
- default:
179
- return (
180
- 'echo "\\033[' + (await color(log_type)) + ';1m' + message + '\\033[0m"'
181
- );
182
- }
183
- }
184
-
185
- /**
186
- * Function to log a step
187
- *
188
- * @param message
189
- * @param os_version
190
- */
191
- export async function stepLog(
192
- message: string,
193
- os_version: string
194
- ): Promise<string> {
195
- switch (os_version) {
196
- case 'win32':
197
- return 'Step-Log "' + message + '"';
198
- case 'linux':
199
- case 'darwin':
200
- return 'step_log "' + message + '"';
201
- default:
202
- return await log(
203
- 'Platform ' + os_version + ' is not supported',
204
- os_version,
205
- 'error'
206
- );
207
- }
208
- }
209
-
210
- /**
211
- * Function to log a result
212
- * @param mark
213
- * @param subject
214
- * @param message
215
- * @param os_version
216
- */
217
- export async function addLog(
218
- mark: string,
219
- subject: string,
220
- message: string,
221
- os_version: string
222
- ): Promise<string> {
223
- switch (os_version) {
224
- case 'win32':
225
- return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
226
- case 'linux':
227
- case 'darwin':
228
- return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
229
- default:
230
- return await log(
231
- 'Platform ' + os_version + ' is not supported',
232
- os_version,
233
- 'error'
234
- );
235
- }
236
- }
237
-
238
- /**
239
- * Read the scripts
240
- *
241
- * @param filename
242
- * @param directory
243
- */
244
- export async function readFile(
245
- filename: string,
246
- directory: string
247
- ): Promise<string> {
248
- return fs.readFileSync(
249
- path.join(__dirname, '../' + directory, filename),
250
- 'utf8'
251
- );
252
- }
253
-
254
- /**
255
- * Write final script which runs
256
- *
257
- * @param filename
258
- * @param script
259
- */
260
- export async function writeScript(
261
- filename: string,
262
- script: string
263
- ): Promise<string> {
264
- const runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false);
265
- const script_path: string = path.join(runner_dir, filename);
266
- fs.writeFileSync(script_path, script, {mode: 0o755});
267
- return script_path;
268
- }
269
-
270
- /**
271
- * Function to break extension csv into an array
272
- *
273
- * @param extension_csv
274
- */
275
- export async function extensionArray(
276
- extension_csv: string
277
- ): Promise<Array<string>> {
278
- switch (extension_csv) {
279
- case '':
280
- case ' ':
281
- return [];
282
- default:
283
- return extension_csv
284
- .split(',')
285
- .map(function (extension: string) {
286
- if (/.+-.+\/.+@.+/.test(extension)) {
287
- return extension;
288
- }
289
- return extension
290
- .trim()
291
- .toLowerCase()
292
- .replace(/^php[-_]/, '');
293
- })
294
- .filter(Boolean);
295
- }
296
- }
297
-
298
- /**
299
- * Function to break csv into an array
300
- *
301
- * @param values_csv
302
- * @constructor
303
- */
304
- export async function CSVArray(values_csv: string): Promise<Array<string>> {
305
- switch (values_csv) {
306
- case '':
307
- case ' ':
308
- return [];
309
- default:
310
- return values_csv
311
- .split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
312
- .map(function (value) {
313
- return value
314
- .trim()
315
- .replace(/^["']|["']$|(?<==)["']/g, '')
316
- .replace(/=(((?!E_).)*[?{}|&~![()^]+((?!E_).)+)/, "='$1'");
317
- })
318
- .filter(Boolean);
319
- }
320
- }
321
-
322
- /**
323
- * Function to get prefix required to load an extension.
324
- *
325
- * @param extension
326
- */
327
- export async function getExtensionPrefix(extension: string): Promise<string> {
328
- switch (true) {
329
- default:
330
- return 'extension';
331
- case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension):
332
- return 'zend_extension';
333
- }
334
- }
335
-
336
- /**
337
- * Function to get the suffix to suppress console output
338
- *
339
- * @param os_version
340
- */
341
- export async function suppressOutput(os_version: string): Promise<string> {
342
- switch (os_version) {
343
- case 'win32':
344
- return ' >$null 2>&1';
345
- case 'linux':
346
- case 'darwin':
347
- return ' >/dev/null 2>&1';
348
- default:
349
- return await log(
350
- 'Platform ' + os_version + ' is not supported',
351
- os_version,
352
- 'error'
353
- );
354
- }
355
- }
356
-
357
- /**
358
- * Function to get script to log unsupported extensions.
359
- *
360
- * @param extension
361
- * @param version
362
- * @param os_version
363
- */
364
- export async function getUnsupportedLog(
365
- extension: string,
366
- version: string,
367
- os_version: string
368
- ): Promise<string> {
369
- return (
370
- '\n' +
371
- (await addLog(
372
- '$cross',
373
- extension,
374
- [extension, 'is not supported on PHP', version].join(' '),
375
- os_version
376
- )) +
377
- '\n'
378
- );
379
- }
380
-
381
- /**
382
- * Function to get command to setup tools
383
- *
384
- * @param os_version
385
- * @param suffix
386
- */
387
- export async function getCommand(
388
- os_version: string,
389
- suffix: string
390
- ): Promise<string> {
391
- switch (os_version) {
392
- case 'linux':
393
- case 'darwin':
394
- return 'add_' + suffix + ' ';
395
- case 'win32':
396
- return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
397
- default:
398
- return await log(
399
- 'Platform ' + os_version + ' is not supported',
400
- os_version,
401
- 'error'
402
- );
403
- }
404
- }
405
-
406
- /**
407
- * Function to join strings with space
408
- *
409
- * @param str
410
- */
411
- export async function joins(...str: string[]): Promise<string> {
412
- return [...str].join(' ');
413
- }
414
-
415
- /**
416
- * Function to get script extensions
417
- *
418
- * @param os_version
419
- */
420
- export async function scriptExtension(os_version: string): Promise<string> {
421
- switch (os_version) {
422
- case 'win32':
423
- return '.ps1';
424
- case 'linux':
425
- case 'darwin':
426
- return '.sh';
427
- default:
428
- return await log(
429
- 'Platform ' + os_version + ' is not supported',
430
- os_version,
431
- 'error'
432
- );
433
- }
434
- }
435
-
436
- /**
437
- * Function to get script tool
438
- *
439
- * @param os_version
440
- */
441
- export async function scriptTool(os_version: string): Promise<string> {
442
- switch (os_version) {
443
- case 'win32':
444
- return 'pwsh';
445
- case 'linux':
446
- case 'darwin':
447
- return 'bash';
448
- default:
449
- return await log(
450
- 'Platform ' + os_version + ' is not supported',
451
- os_version,
452
- 'error'
453
- );
454
- }
455
- }
456
-
457
- /**
458
- * Function to get script to add tools with custom support.
459
- *
460
- * @param pkg
461
- * @param type
462
- * @param version
463
- * @param os_version
464
- */
465
- export async function customPackage(
466
- pkg: string,
467
- type: string,
468
- version: string,
469
- os_version: string
470
- ): Promise<string> {
471
- const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
472
- const script_extension: string = await scriptExtension(os_version);
473
- const script: string = path.join(
474
- __dirname,
475
- '../src/scripts/' + type + '/' + pkg_name + script_extension
476
- );
477
- const command: string = await getCommand(os_version, pkg_name);
478
- return '\n. ' + script + '\n' + command + version;
479
- }
480
-
481
- /**
482
- * Function to extension input for installation from source.
483
- *
484
- * @param extension
485
- * @param prefix
486
- */
487
- export async function parseExtensionSource(
488
- extension: string,
489
- prefix: string
490
- ): Promise<string> {
491
- // Groups: extension, domain url, org, repo, release
492
- const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/;
493
- const matches = regex.exec(extension) as RegExpExecArray;
494
- matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com';
495
- return await joins(
496
- '\nadd_extension_from_source',
497
- ...matches.splice(1, matches.length),
498
- prefix
499
- );
500
- }
1
+ import * as path from 'path';
2
+ import * as core from '@actions/core';
3
+ import * as fetch from './fetch';
4
+
5
+ /**
6
+ * Function to read environment variable and return a string value.
7
+ *
8
+ * @param property
9
+ */
10
+ export async function readEnv(property: string): Promise<string> {
11
+ const property_lc: string = property.toLowerCase();
12
+ const property_uc: string = property.toUpperCase();
13
+ return (
14
+ process.env[property] ||
15
+ process.env[property_lc] ||
16
+ process.env[property_uc] ||
17
+ process.env[property_lc.replace('_', '-')] ||
18
+ process.env[property_uc.replace('_', '-')] ||
19
+ ''
20
+ );
21
+ }
22
+
23
+ /**
24
+ * Function to get inputs from both with and env annotations.
25
+ *
26
+ * @param name
27
+ * @param mandatory
28
+ */
29
+ export async function getInput(
30
+ name: string,
31
+ mandatory: boolean
32
+ ): Promise<string> {
33
+ const input = core.getInput(name);
34
+ const env_input = await readEnv(name);
35
+ switch (true) {
36
+ case input != '':
37
+ return input;
38
+ case input == '' && env_input != '':
39
+ return env_input;
40
+ case input == '' && env_input == '' && mandatory:
41
+ throw new Error(`Input required and not supplied: ${name}`);
42
+ default:
43
+ return '';
44
+ }
45
+ }
46
+
47
+ /** Function to get manifest URL
48
+ *
49
+ */
50
+ export async function getManifestURL(): Promise<string> {
51
+ return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
52
+ }
53
+
54
+ /**
55
+ * Function to parse PHP version.
56
+ *
57
+ * @param version
58
+ */
59
+ export async function parseVersion(version: string): Promise<string> {
60
+ const manifest = await getManifestURL();
61
+ switch (true) {
62
+ case /^(latest|nightly|\d+\.x)$/.test(version):
63
+ return JSON.parse((await fetch.fetch(manifest))['data'])[version];
64
+ default:
65
+ switch (true) {
66
+ case version.length > 1:
67
+ return version.slice(0, 3);
68
+ default:
69
+ return version + '.0';
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Function to parse ini file.
76
+ *
77
+ * @param ini_file
78
+ */
79
+ export async function parseIniFile(ini_file: string): Promise<string> {
80
+ switch (true) {
81
+ case /^(production|development|none)$/.test(ini_file):
82
+ return ini_file;
83
+ case /php\.ini-(production|development)$/.test(ini_file):
84
+ return ini_file.split('-')[1];
85
+ default:
86
+ return 'production';
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Async foreach loop
92
+ *
93
+ * @author https://github.com/Atinux
94
+ * @param array
95
+ * @param callback
96
+ */
97
+ export async function asyncForEach(
98
+ array: Array<string>,
99
+ callback: (
100
+ element: string,
101
+ index: number,
102
+ array: Array<string>
103
+ ) => Promise<void>
104
+ ): Promise<void> {
105
+ for (let index = 0; index < array.length; index++) {
106
+ await callback(array[index], index, array);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Get color index
112
+ *
113
+ * @param type
114
+ */
115
+ export async function color(type: string): Promise<string> {
116
+ switch (type) {
117
+ case 'error':
118
+ return '31';
119
+ default:
120
+ case 'success':
121
+ return '32';
122
+ case 'warning':
123
+ return '33';
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Log to console
129
+ *
130
+ * @param message
131
+ * @param os
132
+ * @param log_type
133
+ */
134
+ export async function log(
135
+ message: string,
136
+ os: string,
137
+ log_type: string
138
+ ): Promise<string> {
139
+ switch (os) {
140
+ case 'win32':
141
+ return (
142
+ 'printf "\\033[' +
143
+ (await color(log_type)) +
144
+ ';1m' +
145
+ message +
146
+ ' \\033[0m"'
147
+ );
148
+
149
+ case 'linux':
150
+ case 'darwin':
151
+ default:
152
+ return (
153
+ 'echo "\\033[' + (await color(log_type)) + ';1m' + message + '\\033[0m"'
154
+ );
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Function to log a step
160
+ *
161
+ * @param message
162
+ * @param os
163
+ */
164
+ export async function stepLog(message: string, os: string): Promise<string> {
165
+ switch (os) {
166
+ case 'win32':
167
+ return 'Step-Log "' + message + '"';
168
+ case 'linux':
169
+ case 'darwin':
170
+ return 'step_log "' + message + '"';
171
+ default:
172
+ return await log('Platform ' + os + ' is not supported', os, 'error');
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Function to log a result
178
+ * @param mark
179
+ * @param subject
180
+ * @param message
181
+ * @param os
182
+ */
183
+ export async function addLog(
184
+ mark: string,
185
+ subject: string,
186
+ message: string,
187
+ os: string
188
+ ): Promise<string> {
189
+ switch (os) {
190
+ case 'win32':
191
+ return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
192
+ case 'linux':
193
+ case 'darwin':
194
+ return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
195
+ default:
196
+ return await log('Platform ' + os + ' is not supported', os, 'error');
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Function to break extension csv into an array
202
+ *
203
+ * @param extension_csv
204
+ */
205
+ export async function extensionArray(
206
+ extension_csv: string
207
+ ): Promise<Array<string>> {
208
+ switch (extension_csv) {
209
+ case '':
210
+ case ' ':
211
+ return [];
212
+ default:
213
+ return [
214
+ extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
215
+ ...extension_csv
216
+ .split(',')
217
+
218
+ .map(function (extension: string) {
219
+ if (/.+-.+\/.+@.+/.test(extension)) {
220
+ return extension;
221
+ }
222
+ return extension
223
+ .trim()
224
+ .toLowerCase()
225
+ .replace(/^(:)?(php[-_]|none|zend )|(-[^-]*)-/, '$1$3');
226
+ })
227
+ ].filter(Boolean);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Function to break csv into an array
233
+ *
234
+ * @param values_csv
235
+ * @constructor
236
+ */
237
+ export async function CSVArray(values_csv: string): Promise<Array<string>> {
238
+ switch (values_csv) {
239
+ case '':
240
+ case ' ':
241
+ return [];
242
+ default:
243
+ return values_csv
244
+ .split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
245
+ .map(function (value) {
246
+ return value
247
+ .trim()
248
+ .replace(/^["']|["']$|(?<==)["']/g, '')
249
+ .replace(/=(((?!E_).)*[?{}|&~![()^]+((?!E_).)+)/, "='$1'");
250
+ })
251
+ .filter(Boolean);
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Function to get prefix required to load an extension.
257
+ *
258
+ * @param extension
259
+ */
260
+ export async function getExtensionPrefix(extension: string): Promise<string> {
261
+ switch (true) {
262
+ default:
263
+ return 'extension';
264
+ case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension):
265
+ return 'zend_extension';
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Function to get the suffix to suppress console output
271
+ *
272
+ * @param os
273
+ */
274
+ export async function suppressOutput(os: string): Promise<string> {
275
+ switch (os) {
276
+ case 'win32':
277
+ return ' >$null 2>&1';
278
+ case 'linux':
279
+ case 'darwin':
280
+ return ' >/dev/null 2>&1';
281
+ default:
282
+ return await log('Platform ' + os + ' is not supported', os, 'error');
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Function to get script to log unsupported extensions.
288
+ *
289
+ * @param extension
290
+ * @param version
291
+ * @param os
292
+ */
293
+ export async function getUnsupportedLog(
294
+ extension: string,
295
+ version: string,
296
+ os: string
297
+ ): Promise<string> {
298
+ return (
299
+ '\n' +
300
+ (await addLog(
301
+ '$cross',
302
+ extension,
303
+ [extension, 'is not supported on PHP', version].join(' '),
304
+ os
305
+ )) +
306
+ '\n'
307
+ );
308
+ }
309
+
310
+ /**
311
+ * Function to get command to setup tools
312
+ *
313
+ * @param os
314
+ * @param suffix
315
+ */
316
+ export async function getCommand(os: string, suffix: string): Promise<string> {
317
+ switch (os) {
318
+ case 'linux':
319
+ case 'darwin':
320
+ return 'add_' + suffix + ' ';
321
+ case 'win32':
322
+ return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
323
+ default:
324
+ return await log('Platform ' + os + ' is not supported', os, 'error');
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Function to join strings with space
330
+ *
331
+ * @param str
332
+ */
333
+ export async function joins(...str: string[]): Promise<string> {
334
+ return [...str].join(' ');
335
+ }
336
+
337
+ /**
338
+ * Function to get script extensions
339
+ *
340
+ * @param os
341
+ */
342
+ export async function scriptExtension(os: string): Promise<string> {
343
+ switch (os) {
344
+ case 'win32':
345
+ return '.ps1';
346
+ case 'linux':
347
+ case 'darwin':
348
+ return '.sh';
349
+ default:
350
+ return await log('Platform ' + os + ' is not supported', os, 'error');
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Function to get script tool
356
+ *
357
+ * @param os
358
+ */
359
+ export async function scriptTool(os: string): Promise<string> {
360
+ switch (os) {
361
+ case 'win32':
362
+ return 'pwsh ';
363
+ case 'linux':
364
+ case 'darwin':
365
+ return 'bash ';
366
+ default:
367
+ return await log('Platform ' + os + ' is not supported', os, 'error');
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Function to get script to add tools with custom support.
373
+ *
374
+ * @param pkg
375
+ * @param type
376
+ * @param version
377
+ * @param os
378
+ */
379
+ export async function customPackage(
380
+ pkg: string,
381
+ type: string,
382
+ version: string,
383
+ os: string
384
+ ): Promise<string> {
385
+ const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
386
+ const script_extension: string = await scriptExtension(os);
387
+ const script: string = path.join(
388
+ __dirname,
389
+ '../src/scripts/' + type + '/' + pkg_name + script_extension
390
+ );
391
+ const command: string = await getCommand(os, pkg_name);
392
+ return '\n. ' + script + '\n' + command + version;
393
+ }
394
+
395
+ /**
396
+ * Function to extension input for installation from source.
397
+ *
398
+ * @param extension
399
+ * @param prefix
400
+ */
401
+ export async function parseExtensionSource(
402
+ extension: string,
403
+ prefix: string
404
+ ): Promise<string> {
405
+ // Groups: extension, domain url, org, repo, release
406
+ const regex =
407
+ /(\w+)-(\w+:\/\/.{1,253}(?:[.:][^:/\s]{2,63})+\/)?([\w.-]+)\/([\w.-]+)@(.+)/;
408
+ const matches = regex.exec(extension) as RegExpExecArray;
409
+ matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com';
410
+ return await joins(
411
+ '\nadd_extension_from_source',
412
+ ...matches.splice(1, matches.length),
413
+ prefix
414
+ );
415
+ }