@php-wasm/universal 3.1.20 → 3.1.22
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.
- package/README.md +66 -0
- package/index.cjs +10 -8
- package/index.cjs.map +1 -1
- package/index.js +528 -256
- package/index.js.map +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/legacy-php-ini.d.ts +32 -0
- package/lib/load-extension.d.ts +227 -0
- package/lib/load-php-runtime.d.ts +1 -0
- package/lib/object-pool-proxy.d.ts +5 -0
- package/lib/php-worker.d.ts +3 -1
- package/lib/proxy-file-system.d.ts +14 -2
- package/lib/supported-php-versions.d.ts +10 -0
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Y = (r) => {
|
|
2
2
|
throw TypeError(r);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var q = (r, e, t) => e.has(r) || Y("Cannot " + t);
|
|
5
|
+
var h = (r, e, t) => (q(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ? Y("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), w = (r, e, t, s) => (q(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), m = (r, e, t) => (q(r, e, "access private method"), t);
|
|
6
6
|
import { logger } from "@php-wasm/logger";
|
|
7
7
|
import { dirname, joinPaths, Semaphore, createSpawnHandler, basename, normalizePath, AcquireTimeoutError, splitShellCommand } from "@php-wasm/util";
|
|
8
8
|
import { parse, stringify } from "ini";
|
|
@@ -376,7 +376,7 @@ class PHPWorker {
|
|
|
376
376
|
/** @inheritDoc */
|
|
377
377
|
constructor(e, t) {
|
|
378
378
|
y(this, v);
|
|
379
|
-
this.absoluteUrl = "", this.documentRoot = "", this.chroot = null,
|
|
379
|
+
this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, w(this, v, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
|
|
380
380
|
monitor: t
|
|
381
381
|
}), e && this.__internal_setRequestHandler(e);
|
|
382
382
|
}
|
|
@@ -404,7 +404,7 @@ class PHPWorker {
|
|
|
404
404
|
* a warning.
|
|
405
405
|
*/
|
|
406
406
|
__internal_getRequestHandler() {
|
|
407
|
-
return
|
|
407
|
+
return this.getRequestHandler();
|
|
408
408
|
}
|
|
409
409
|
async setPrimaryPHP(e) {
|
|
410
410
|
_private.set(this, {
|
|
@@ -414,11 +414,11 @@ class PHPWorker {
|
|
|
414
414
|
}
|
|
415
415
|
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.pathToInternalUrl */
|
|
416
416
|
pathToInternalUrl(e) {
|
|
417
|
-
return
|
|
417
|
+
return this.getRequestHandler().pathToInternalUrl(e);
|
|
418
418
|
}
|
|
419
419
|
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.internalUrlToPath */
|
|
420
420
|
internalUrlToPath(e) {
|
|
421
|
-
return
|
|
421
|
+
return this.getRequestHandler().internalUrlToPath(e);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* The onDownloadProgress event listener.
|
|
@@ -437,7 +437,7 @@ class PHPWorker {
|
|
|
437
437
|
}
|
|
438
438
|
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */
|
|
439
439
|
async request(e) {
|
|
440
|
-
return await
|
|
440
|
+
return await this.getRequestHandler().request(e);
|
|
441
441
|
}
|
|
442
442
|
/**
|
|
443
443
|
* Handles a request with streaming support for large responses.
|
|
@@ -450,27 +450,33 @@ class PHPWorker {
|
|
|
450
450
|
* @param request - PHP Request data.
|
|
451
451
|
*/
|
|
452
452
|
async requestStreamed(e) {
|
|
453
|
-
return await
|
|
453
|
+
return await this.getRequestHandler().requestStreamed(e);
|
|
454
454
|
}
|
|
455
455
|
/** @inheritDoc @php-wasm/universal!/PHP.run */
|
|
456
456
|
async run(e) {
|
|
457
|
-
const
|
|
457
|
+
const t = _private.get(this), s = t.php;
|
|
458
|
+
if (!t.requestHandler && !(s != null && s.requestHandler) && s)
|
|
459
|
+
return await s.run(e);
|
|
460
|
+
const { php: n, reap: i } = await this.acquirePHPInstance();
|
|
458
461
|
try {
|
|
459
|
-
return await
|
|
462
|
+
return await n.run(e);
|
|
460
463
|
} finally {
|
|
461
|
-
|
|
464
|
+
i();
|
|
462
465
|
}
|
|
463
466
|
}
|
|
464
467
|
/** @inheritDoc @php-wasm/universal!/PHP.cli */
|
|
465
468
|
async cli(e, t) {
|
|
466
|
-
const
|
|
467
|
-
|
|
469
|
+
const s = _private.get(this), n = s.php;
|
|
470
|
+
if (!s.requestHandler && !(n != null && n.requestHandler) && n)
|
|
471
|
+
return await n.cli(e, t);
|
|
472
|
+
const { php: i, reap: o } = await this.acquirePHPInstance();
|
|
473
|
+
let a;
|
|
468
474
|
try {
|
|
469
|
-
|
|
470
|
-
} catch (
|
|
471
|
-
throw
|
|
475
|
+
a = await i.cli(e, t);
|
|
476
|
+
} catch (c) {
|
|
477
|
+
throw o(), c;
|
|
472
478
|
}
|
|
473
|
-
return
|
|
479
|
+
return a.finished.finally(o), a;
|
|
474
480
|
}
|
|
475
481
|
/** @inheritDoc @php-wasm/universal!/PHP.chdir */
|
|
476
482
|
chdir(e) {
|
|
@@ -484,7 +490,7 @@ class PHPWorker {
|
|
|
484
490
|
* @returns A PHP instance with a consistent chroot.
|
|
485
491
|
*/
|
|
486
492
|
async acquirePHPInstance() {
|
|
487
|
-
const { php: e, reap: t } = await
|
|
493
|
+
const { php: e, reap: t } = await this.getRequestHandler().instanceManager.acquirePHPInstance();
|
|
488
494
|
return this.chroot !== null && e.chdir(this.chroot), this.registerWorkerListeners(e), { php: e, reap: t };
|
|
489
495
|
}
|
|
490
496
|
/** @inheritDoc @php-wasm/universal!/PHP.setSapiName */
|
|
@@ -545,7 +551,7 @@ class PHPWorker {
|
|
|
545
551
|
}
|
|
546
552
|
/** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
|
|
547
553
|
addEventListener(e, t) {
|
|
548
|
-
|
|
554
|
+
h(this, v).has(e) || h(this, v).set(e, /* @__PURE__ */ new Set()), h(this, v).get(e).add(t);
|
|
549
555
|
}
|
|
550
556
|
/**
|
|
551
557
|
* Removes an event listener for a PHP event.
|
|
@@ -554,10 +560,10 @@ class PHPWorker {
|
|
|
554
560
|
*/
|
|
555
561
|
removeEventListener(e, t) {
|
|
556
562
|
var s;
|
|
557
|
-
(s =
|
|
563
|
+
(s = h(this, v).get(e)) == null || s.delete(t);
|
|
558
564
|
}
|
|
559
565
|
dispatchEvent(e) {
|
|
560
|
-
const t =
|
|
566
|
+
const t = h(this, v).get(e.type);
|
|
561
567
|
if (t)
|
|
562
568
|
for (const s of t)
|
|
563
569
|
s(e);
|
|
@@ -576,7 +582,17 @@ class PHPWorker {
|
|
|
576
582
|
}
|
|
577
583
|
async [Symbol.asyncDispose]() {
|
|
578
584
|
var e;
|
|
579
|
-
await ((e =
|
|
585
|
+
await ((e = this.getRequestHandler(!1)) == null ? void 0 : e[Symbol.asyncDispose]());
|
|
586
|
+
}
|
|
587
|
+
getRequestHandler(e = !0) {
|
|
588
|
+
var s;
|
|
589
|
+
const t = _private.get(this);
|
|
590
|
+
if (t.requestHandler)
|
|
591
|
+
return t.requestHandler;
|
|
592
|
+
if ((s = t.php) != null && s.requestHandler)
|
|
593
|
+
return this.__internal_setRequestHandler(t.php.requestHandler), t.php.requestHandler;
|
|
594
|
+
if (e)
|
|
595
|
+
throw new Error("PHPWorker is not connected to a request handler.");
|
|
580
596
|
}
|
|
581
597
|
}
|
|
582
598
|
v = new WeakMap();
|
|
@@ -587,14 +603,14 @@ const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map(
|
|
|
587
603
|
let lastRuntimeId = 0;
|
|
588
604
|
async function loadPHPRuntime(r, ...e) {
|
|
589
605
|
const t = Object.assign({}, ...e), [s, n, i] = makePromise(), o = r.init(currentJsRuntime, {
|
|
590
|
-
onAbort(
|
|
591
|
-
i(
|
|
606
|
+
onAbort(l) {
|
|
607
|
+
i(l), logger.error(l);
|
|
592
608
|
},
|
|
593
609
|
ENV: {},
|
|
594
610
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
595
611
|
// breaks vite dev mode. An identity `locateFile` function
|
|
596
612
|
// fixes it.
|
|
597
|
-
locateFile: (
|
|
613
|
+
locateFile: (l) => l,
|
|
598
614
|
...t,
|
|
599
615
|
noInitialRun: !0,
|
|
600
616
|
onRuntimeInitialized() {
|
|
@@ -602,10 +618,12 @@ async function loadPHPRuntime(r, ...e) {
|
|
|
602
618
|
}
|
|
603
619
|
});
|
|
604
620
|
await s;
|
|
605
|
-
const a =
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
621
|
+
const a = t.phpWasmAsyncMode ?? r.phpWasmAsyncMode;
|
|
622
|
+
a && (o.phpWasmAsyncMode = a);
|
|
623
|
+
const c = ++lastRuntimeId;
|
|
624
|
+
return o.FS, o.id = c, o.originalExit = o._exit, o._exit = function(l) {
|
|
625
|
+
return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(c), o.originalExit(l);
|
|
626
|
+
}, o[RuntimeId] = c, loadedRuntimes.set(c, o), c;
|
|
609
627
|
}
|
|
610
628
|
function popLoadedRuntime(r, {
|
|
611
629
|
dangerouslyKeepTheRuntimeInTheMap: e = !1
|
|
@@ -644,8 +662,8 @@ const currentJsRuntime = function() {
|
|
|
644
662
|
201: "Created",
|
|
645
663
|
200: "OK"
|
|
646
664
|
};
|
|
647
|
-
var
|
|
648
|
-
const
|
|
665
|
+
var O, U;
|
|
666
|
+
const W = class W {
|
|
649
667
|
constructor(e, t, s, n) {
|
|
650
668
|
/**
|
|
651
669
|
* Headers stream that doesn't get locked when the consumer
|
|
@@ -654,14 +672,14 @@ const D = class D {
|
|
|
654
672
|
* Both streams must be readable when the StreamedPHPResponse is transferred
|
|
655
673
|
* from the worker thread into the service worker.
|
|
656
674
|
*/
|
|
657
|
-
y(this,
|
|
675
|
+
y(this, O);
|
|
658
676
|
/**
|
|
659
677
|
* Headers stream reserved for internal parsing.
|
|
660
678
|
*/
|
|
661
|
-
y(this,
|
|
679
|
+
y(this, U);
|
|
662
680
|
this.cachedParsedHeaders = null, this.cachedStdoutBytes = null, this.cachedStderrText = null;
|
|
663
681
|
const [i, o] = e.tee();
|
|
664
|
-
|
|
682
|
+
w(this, O, i), w(this, U, o), this.stdout = t, this.stderr = s, this.exitCode = n;
|
|
665
683
|
}
|
|
666
684
|
/**
|
|
667
685
|
* Creates a StreamedPHPResponse from a buffered PHPResponse.
|
|
@@ -690,7 +708,7 @@ const D = class D {
|
|
|
690
708
|
), a.close();
|
|
691
709
|
}
|
|
692
710
|
});
|
|
693
|
-
return new
|
|
711
|
+
return new W(
|
|
694
712
|
i,
|
|
695
713
|
t,
|
|
696
714
|
o,
|
|
@@ -702,7 +720,7 @@ const D = class D {
|
|
|
702
720
|
* Shorthand for `StreamedPHPResponse.fromPHPResponse(PHPResponse.forHttpCode(...))`.
|
|
703
721
|
*/
|
|
704
722
|
static forHttpCode(e, t = "") {
|
|
705
|
-
return
|
|
723
|
+
return W.fromPHPResponse(
|
|
706
724
|
PHPResponse.forHttpCode(e, t)
|
|
707
725
|
);
|
|
708
726
|
}
|
|
@@ -711,7 +729,7 @@ const D = class D {
|
|
|
711
729
|
* For parsed headers, use the `headers` property instead.
|
|
712
730
|
*/
|
|
713
731
|
getHeadersStream() {
|
|
714
|
-
return
|
|
732
|
+
return h(this, O);
|
|
715
733
|
}
|
|
716
734
|
/**
|
|
717
735
|
* True if the response is successful (HTTP status code 200-399),
|
|
@@ -772,12 +790,12 @@ const D = class D {
|
|
|
772
790
|
}
|
|
773
791
|
async getParsedHeaders() {
|
|
774
792
|
return this.cachedParsedHeaders || (this.cachedParsedHeaders = parseHeadersStream(
|
|
775
|
-
|
|
793
|
+
h(this, U)
|
|
776
794
|
)), await this.cachedParsedHeaders;
|
|
777
795
|
}
|
|
778
796
|
};
|
|
779
|
-
|
|
780
|
-
let StreamedPHPResponse =
|
|
797
|
+
O = new WeakMap(), U = new WeakMap();
|
|
798
|
+
let StreamedPHPResponse = W;
|
|
781
799
|
async function parseHeadersStream(r) {
|
|
782
800
|
const e = await streamToText(r);
|
|
783
801
|
let t;
|
|
@@ -1051,7 +1069,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
1051
1069
|
}
|
|
1052
1070
|
}
|
|
1053
1071
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
|
|
1054
|
-
var
|
|
1072
|
+
var I, R, H, F, b, T, _, f, J, X, Q, K, Z, ee, te, re, z, se, V, G;
|
|
1055
1073
|
class PHP {
|
|
1056
1074
|
/**
|
|
1057
1075
|
* Initializes a PHP runtime.
|
|
@@ -1061,17 +1079,17 @@ class PHP {
|
|
|
1061
1079
|
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
1062
1080
|
*/
|
|
1063
1081
|
constructor(r) {
|
|
1064
|
-
y(this,
|
|
1065
|
-
y(this,
|
|
1082
|
+
y(this, f);
|
|
1083
|
+
y(this, I);
|
|
1066
1084
|
y(this, R, !1);
|
|
1067
|
-
y(this,
|
|
1068
|
-
y(this,
|
|
1085
|
+
y(this, H, null);
|
|
1086
|
+
y(this, F, /* @__PURE__ */ new Map([
|
|
1069
1087
|
// Listen to all events
|
|
1070
1088
|
["*", /* @__PURE__ */ new Set()]
|
|
1071
1089
|
]));
|
|
1072
|
-
y(this,
|
|
1073
|
-
y(this,
|
|
1074
|
-
y(this,
|
|
1090
|
+
y(this, b, []);
|
|
1091
|
+
y(this, T, {});
|
|
1092
|
+
y(this, _, {
|
|
1075
1093
|
enabled: !1,
|
|
1076
1094
|
recreateRuntime: () => 0,
|
|
1077
1095
|
needsRotating: !1,
|
|
@@ -1079,7 +1097,7 @@ class PHP {
|
|
|
1079
1097
|
requestsMade: 0
|
|
1080
1098
|
});
|
|
1081
1099
|
this.semaphore = new Semaphore({ concurrency: 1 }), r !== void 0 && this.initializeRuntime(r), this.addEventListener("request.error", (e) => {
|
|
1082
|
-
e.source === "php-wasm" && (
|
|
1100
|
+
e.source === "php-wasm" && (h(this, _).needsRotating = !0);
|
|
1083
1101
|
});
|
|
1084
1102
|
}
|
|
1085
1103
|
/**
|
|
@@ -1088,7 +1106,7 @@ class PHP {
|
|
|
1088
1106
|
* @param listener - The listener function to be called when the event is triggered.
|
|
1089
1107
|
*/
|
|
1090
1108
|
addEventListener(r, e) {
|
|
1091
|
-
|
|
1109
|
+
h(this, F).has(r) || h(this, F).set(r, /* @__PURE__ */ new Set()), h(this, F).get(r).add(e);
|
|
1092
1110
|
}
|
|
1093
1111
|
/**
|
|
1094
1112
|
* Removes an event listener for a PHP event.
|
|
@@ -1097,12 +1115,12 @@ class PHP {
|
|
|
1097
1115
|
*/
|
|
1098
1116
|
removeEventListener(r, e) {
|
|
1099
1117
|
var t;
|
|
1100
|
-
(t =
|
|
1118
|
+
(t = h(this, F).get(r)) == null || t.delete(e);
|
|
1101
1119
|
}
|
|
1102
1120
|
dispatchEvent(r) {
|
|
1103
1121
|
const e = [
|
|
1104
|
-
...
|
|
1105
|
-
...
|
|
1122
|
+
...h(this, F).get(r.type) || [],
|
|
1123
|
+
...h(this, F).get("*") || []
|
|
1106
1124
|
];
|
|
1107
1125
|
if (e)
|
|
1108
1126
|
for (const t of e)
|
|
@@ -1148,8 +1166,8 @@ class PHP {
|
|
|
1148
1166
|
* @param listener Callback function to handle the message.
|
|
1149
1167
|
*/
|
|
1150
1168
|
onMessage(r) {
|
|
1151
|
-
return
|
|
1152
|
-
|
|
1169
|
+
return h(this, b).push(r), async () => {
|
|
1170
|
+
w(this, b, h(this, b).filter(
|
|
1153
1171
|
(e) => e !== r
|
|
1154
1172
|
));
|
|
1155
1173
|
};
|
|
@@ -1243,13 +1261,13 @@ class PHP {
|
|
|
1243
1261
|
}
|
|
1244
1262
|
`
|
|
1245
1263
|
), e.onMessage = async (t) => {
|
|
1246
|
-
for (const s of
|
|
1264
|
+
for (const s of h(this, b)) {
|
|
1247
1265
|
const n = await s(t);
|
|
1248
1266
|
if (n)
|
|
1249
1267
|
return n;
|
|
1250
1268
|
}
|
|
1251
1269
|
return "";
|
|
1252
|
-
},
|
|
1270
|
+
}, w(this, H, improveWASMErrorReporting(e)), this.dispatchEvent({
|
|
1253
1271
|
type: "runtime.initialized"
|
|
1254
1272
|
});
|
|
1255
1273
|
}
|
|
@@ -1264,7 +1282,7 @@ class PHP {
|
|
|
1264
1282
|
throw new Error(
|
|
1265
1283
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1266
1284
|
);
|
|
1267
|
-
|
|
1285
|
+
w(this, I, r);
|
|
1268
1286
|
}
|
|
1269
1287
|
/**
|
|
1270
1288
|
* Changes the current working directory in the PHP filesystem.
|
|
@@ -1486,8 +1504,8 @@ class PHP {
|
|
|
1486
1504
|
async runStream(r) {
|
|
1487
1505
|
const e = await this.semaphore.acquire();
|
|
1488
1506
|
let t;
|
|
1489
|
-
const s = m(this,
|
|
1490
|
-
if (
|
|
1507
|
+
const s = m(this, f, G).call(this, async () => {
|
|
1508
|
+
if (h(this, R) || (await this[__private__dont__use].ccall(
|
|
1491
1509
|
"php_wasm_init",
|
|
1492
1510
|
null,
|
|
1493
1511
|
[],
|
|
@@ -1495,26 +1513,26 @@ class PHP {
|
|
|
1495
1513
|
{
|
|
1496
1514
|
isAsync: !0
|
|
1497
1515
|
}
|
|
1498
|
-
),
|
|
1516
|
+
), w(this, R, !0)), r.scriptPath && !this.fileExists(r.scriptPath))
|
|
1499
1517
|
throw new Error(
|
|
1500
1518
|
`The script path "${r.scriptPath}" does not exist.`
|
|
1501
1519
|
);
|
|
1502
|
-
m(this,
|
|
1503
|
-
const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this,
|
|
1504
|
-
if (m(this,
|
|
1505
|
-
this.writeFile("/internal/eval.php", r.code), m(this,
|
|
1520
|
+
m(this, f, X).call(this, r.relativeUri || ""), m(this, f, ee).call(this, r.method || "GET");
|
|
1521
|
+
const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, f, Z).call(this, o, r.protocol || "http");
|
|
1522
|
+
if (m(this, f, Q).call(this, o), m(this, f, K).call(this, a), m(this, f, te).call(this, i), r.body && (t = m(this, f, re).call(this, r.body)), typeof r.code == "string")
|
|
1523
|
+
this.writeFile("/internal/eval.php", r.code), m(this, f, z).call(this, "/internal/eval.php");
|
|
1506
1524
|
else if (typeof r.scriptPath == "string")
|
|
1507
|
-
m(this,
|
|
1525
|
+
m(this, f, z).call(this, r.scriptPath || "");
|
|
1508
1526
|
else
|
|
1509
1527
|
throw new TypeError(
|
|
1510
1528
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
1511
1529
|
);
|
|
1512
|
-
const c = m(this,
|
|
1513
|
-
for (const
|
|
1514
|
-
m(this,
|
|
1530
|
+
const c = m(this, f, J).call(this, r.$_SERVER, i, a);
|
|
1531
|
+
for (const u in c)
|
|
1532
|
+
m(this, f, se).call(this, u, c[u]);
|
|
1515
1533
|
const l = r.env || {};
|
|
1516
|
-
for (const
|
|
1517
|
-
m(this,
|
|
1534
|
+
for (const u in l)
|
|
1535
|
+
m(this, f, V).call(this, u, l[u]);
|
|
1518
1536
|
return await this[__private__dont__use].ccall(
|
|
1519
1537
|
"wasm_sapi_handle_request",
|
|
1520
1538
|
NUMBER,
|
|
@@ -1752,21 +1770,21 @@ class PHP {
|
|
|
1752
1770
|
* or an internal crash.
|
|
1753
1771
|
*/
|
|
1754
1772
|
enableRuntimeRotation(r) {
|
|
1755
|
-
|
|
1756
|
-
...
|
|
1773
|
+
w(this, _, {
|
|
1774
|
+
...h(this, _),
|
|
1757
1775
|
enabled: !0,
|
|
1758
1776
|
recreateRuntime: r.recreateRuntime,
|
|
1759
1777
|
maxRequests: r.maxRequests ?? 400
|
|
1760
1778
|
});
|
|
1761
1779
|
}
|
|
1762
1780
|
async rotateRuntime() {
|
|
1763
|
-
if (!
|
|
1781
|
+
if (!h(this, _).enabled)
|
|
1764
1782
|
throw new Error(
|
|
1765
1783
|
"Runtime rotation is not enabled. Call enableRuntimeRotation() first."
|
|
1766
1784
|
);
|
|
1767
1785
|
await this.hotSwapPHPRuntime(
|
|
1768
|
-
await
|
|
1769
|
-
),
|
|
1786
|
+
await h(this, _).recreateRuntime()
|
|
1787
|
+
), h(this, _).requestsMade = 0, h(this, _).needsRotating = !1;
|
|
1770
1788
|
}
|
|
1771
1789
|
/**
|
|
1772
1790
|
* Hot-swaps the PHP runtime for a new one without
|
|
@@ -1777,13 +1795,13 @@ class PHP {
|
|
|
1777
1795
|
async hotSwapPHPRuntime(r) {
|
|
1778
1796
|
const e = this[__private__dont__use].FS, t = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
|
|
1779
1797
|
e.chdir("/");
|
|
1780
|
-
const i = Object.entries(
|
|
1798
|
+
const i = Object.entries(h(this, T)).map(
|
|
1781
1799
|
([c, l]) => ({
|
|
1782
1800
|
mountHandler: l.mountHandler,
|
|
1783
1801
|
vfsPath: c
|
|
1784
1802
|
})
|
|
1785
1803
|
), o = Object.values(
|
|
1786
|
-
|
|
1804
|
+
h(this, T)
|
|
1787
1805
|
).reverse();
|
|
1788
1806
|
for (const c of o)
|
|
1789
1807
|
await c.unmount();
|
|
@@ -1791,7 +1809,7 @@ class PHP {
|
|
|
1791
1809
|
this.exit();
|
|
1792
1810
|
} catch {
|
|
1793
1811
|
}
|
|
1794
|
-
this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s),
|
|
1812
|
+
this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), h(this, I) && this.setSapiName(h(this, I));
|
|
1795
1813
|
const a = this[__private__dont__use].FS;
|
|
1796
1814
|
for (const c of t)
|
|
1797
1815
|
c && c !== "/request" && copyMEMFSNodes(e, a, c);
|
|
@@ -1823,12 +1841,14 @@ class PHP {
|
|
|
1823
1841
|
), s = {
|
|
1824
1842
|
mountHandler: e,
|
|
1825
1843
|
unmount: async () => {
|
|
1826
|
-
|
|
1844
|
+
try {
|
|
1845
|
+
await t();
|
|
1846
|
+
} finally {
|
|
1847
|
+
delete h(this, T)[r];
|
|
1848
|
+
}
|
|
1827
1849
|
}
|
|
1828
1850
|
};
|
|
1829
|
-
return
|
|
1830
|
-
s.unmount();
|
|
1831
|
-
};
|
|
1851
|
+
return h(this, T)[r] = s, () => s.unmount();
|
|
1832
1852
|
}
|
|
1833
1853
|
/**
|
|
1834
1854
|
* Starts a PHP CLI session with given arguments.
|
|
@@ -1846,12 +1866,12 @@ class PHP {
|
|
|
1846
1866
|
async cli(r, e = {}) {
|
|
1847
1867
|
if (basename(r[0] ?? "") !== "php")
|
|
1848
1868
|
return this.subProcess(r, e);
|
|
1849
|
-
|
|
1869
|
+
h(this, R) && (h(this, _).needsRotating = !0);
|
|
1850
1870
|
const t = await this.semaphore.acquire();
|
|
1851
|
-
return await m(this,
|
|
1871
|
+
return await m(this, f, G).call(this, () => {
|
|
1852
1872
|
const s = e.env || {};
|
|
1853
1873
|
for (const [n, i] of Object.entries(s))
|
|
1854
|
-
m(this,
|
|
1874
|
+
m(this, f, V).call(this, n, i);
|
|
1855
1875
|
r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
|
|
1856
1876
|
for (const n of r)
|
|
1857
1877
|
this[__private__dont__use].ccall(
|
|
@@ -1864,7 +1884,7 @@ class PHP {
|
|
|
1864
1884
|
async: !0
|
|
1865
1885
|
});
|
|
1866
1886
|
}).then((s) => (s.exitCode.finally(t), s)).finally(() => {
|
|
1867
|
-
|
|
1887
|
+
h(this, _).needsRotating = !0;
|
|
1868
1888
|
});
|
|
1869
1889
|
}
|
|
1870
1890
|
/**
|
|
@@ -1946,13 +1966,13 @@ class PHP {
|
|
|
1946
1966
|
this[__private__dont__use]._exit(r);
|
|
1947
1967
|
} catch {
|
|
1948
1968
|
}
|
|
1949
|
-
|
|
1969
|
+
w(this, R, !1), w(this, H, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
|
|
1950
1970
|
}
|
|
1951
1971
|
[Symbol.dispose]() {
|
|
1952
1972
|
this.exit(0);
|
|
1953
1973
|
}
|
|
1954
1974
|
}
|
|
1955
|
-
|
|
1975
|
+
I = new WeakMap(), R = new WeakMap(), H = new WeakMap(), F = new WeakMap(), b = new WeakMap(), T = new WeakMap(), _ = new WeakMap(), f = new WeakSet(), /**
|
|
1956
1976
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1957
1977
|
*
|
|
1958
1978
|
* @param defaults Default entries to include in $_SERVER.
|
|
@@ -1961,7 +1981,7 @@ C = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(), T =
|
|
|
1961
1981
|
* was provided.
|
|
1962
1982
|
* @returns Computed $_SERVER entries.
|
|
1963
1983
|
*/
|
|
1964
|
-
|
|
1984
|
+
J = function(r, e, t) {
|
|
1965
1985
|
const s = {
|
|
1966
1986
|
...r || {}
|
|
1967
1987
|
};
|
|
@@ -2053,7 +2073,7 @@ Y = function(r, e, t) {
|
|
|
2053
2073
|
[NUMBER],
|
|
2054
2074
|
[t]
|
|
2055
2075
|
), s;
|
|
2056
|
-
},
|
|
2076
|
+
}, z = function(r) {
|
|
2057
2077
|
this[__private__dont__use].ccall(
|
|
2058
2078
|
"wasm_set_path_translated",
|
|
2059
2079
|
null,
|
|
@@ -2067,87 +2087,87 @@ Y = function(r, e, t) {
|
|
|
2067
2087
|
[STRING, STRING],
|
|
2068
2088
|
[r, e]
|
|
2069
2089
|
);
|
|
2070
|
-
},
|
|
2090
|
+
}, V = function(r, e) {
|
|
2071
2091
|
this[__private__dont__use].ccall(
|
|
2072
2092
|
"wasm_add_ENV_entry",
|
|
2073
2093
|
null,
|
|
2074
2094
|
[STRING, STRING],
|
|
2075
2095
|
[r, e]
|
|
2076
2096
|
);
|
|
2077
|
-
},
|
|
2078
|
-
|
|
2097
|
+
}, G = async function(r) {
|
|
2098
|
+
h(this, _).enabled && h(this, _).needsRotating && await this.rotateRuntime(), ++h(this, _).requestsMade, h(this, _).requestsMade >= h(this, _).maxRequests && (h(this, _).needsRotating = !0);
|
|
2079
2099
|
const e = this[__private__dont__use], t = await createInvertedReadableStream();
|
|
2080
|
-
e.onHeaders = (
|
|
2081
|
-
a || s || t.controller.enqueue(
|
|
2100
|
+
e.onHeaders = (d) => {
|
|
2101
|
+
a || s || t.controller.enqueue(d.slice());
|
|
2082
2102
|
};
|
|
2083
2103
|
let s = !1;
|
|
2084
2104
|
const n = () => {
|
|
2085
2105
|
s || (s = !0, t.controller.close());
|
|
2086
2106
|
}, i = await createInvertedReadableStream();
|
|
2087
|
-
e.onStdout = (
|
|
2088
|
-
n(), !a && i.controller.enqueue(
|
|
2107
|
+
e.onStdout = (d) => {
|
|
2108
|
+
n(), !a && i.controller.enqueue(d.slice());
|
|
2089
2109
|
};
|
|
2090
2110
|
const o = await createInvertedReadableStream();
|
|
2091
|
-
e.onStderr = (
|
|
2092
|
-
a || o.controller.enqueue(
|
|
2111
|
+
e.onStderr = (d) => {
|
|
2112
|
+
a || o.controller.enqueue(d.slice());
|
|
2093
2113
|
};
|
|
2094
2114
|
let a = !1, c;
|
|
2095
|
-
const
|
|
2096
|
-
var
|
|
2115
|
+
const u = (async () => {
|
|
2116
|
+
var d;
|
|
2097
2117
|
try {
|
|
2098
2118
|
return await Promise.race([
|
|
2099
2119
|
r(),
|
|
2100
|
-
new Promise((
|
|
2101
|
-
var
|
|
2102
|
-
c = (
|
|
2103
|
-
isExitCode(
|
|
2104
|
-
}, (
|
|
2120
|
+
new Promise((g, S) => {
|
|
2121
|
+
var $;
|
|
2122
|
+
c = (N) => {
|
|
2123
|
+
isExitCode(N.error) || S(N.error);
|
|
2124
|
+
}, ($ = h(this, H)) == null || $.addEventListener(
|
|
2105
2125
|
"error",
|
|
2106
2126
|
c,
|
|
2107
2127
|
{ once: !0 }
|
|
2108
2128
|
);
|
|
2109
2129
|
})
|
|
2110
2130
|
]);
|
|
2111
|
-
} catch (
|
|
2112
|
-
if (isExitCode(
|
|
2113
|
-
return
|
|
2114
|
-
safeStreamError$1(i.controller,
|
|
2115
|
-
for (const
|
|
2116
|
-
typeof this[
|
|
2131
|
+
} catch (p) {
|
|
2132
|
+
if (isExitCode(p))
|
|
2133
|
+
return p.status;
|
|
2134
|
+
safeStreamError$1(i.controller, p), safeStreamError$1(o.controller, p), safeStreamError$1(t.controller, p), a = !0;
|
|
2135
|
+
for (const g in this)
|
|
2136
|
+
typeof this[g] == "function" && (this[g] = () => {
|
|
2117
2137
|
throw new Error(
|
|
2118
2138
|
"PHP runtime has crashed – see the earlier error for details."
|
|
2119
2139
|
);
|
|
2120
2140
|
});
|
|
2121
|
-
throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(),
|
|
2141
|
+
throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), p;
|
|
2122
2142
|
} finally {
|
|
2123
|
-
a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (
|
|
2143
|
+
a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (d = h(this, H)) == null || d.removeEventListener(
|
|
2124
2144
|
"error",
|
|
2125
2145
|
c
|
|
2126
2146
|
);
|
|
2127
2147
|
}
|
|
2128
2148
|
})().then(
|
|
2129
|
-
(
|
|
2149
|
+
(d) => (d !== 0 && this.dispatchEvent({
|
|
2130
2150
|
type: "request.error",
|
|
2131
2151
|
error: new Error(
|
|
2132
|
-
`PHP.run() failed with exit code ${
|
|
2152
|
+
`PHP.run() failed with exit code ${d}.`
|
|
2133
2153
|
),
|
|
2134
2154
|
// Distinguish between PHP request and PHP-wasm errors
|
|
2135
2155
|
source: "php-wasm"
|
|
2136
|
-
}),
|
|
2137
|
-
(
|
|
2138
|
-
const
|
|
2156
|
+
}), d),
|
|
2157
|
+
(d) => {
|
|
2158
|
+
const p = d.source ?? "php-wasm";
|
|
2139
2159
|
throw this.dispatchEvent({
|
|
2140
2160
|
type: "request.error",
|
|
2141
|
-
error:
|
|
2142
|
-
source:
|
|
2143
|
-
}),
|
|
2161
|
+
error: d,
|
|
2162
|
+
source: p
|
|
2163
|
+
}), d;
|
|
2144
2164
|
}
|
|
2145
2165
|
);
|
|
2146
2166
|
return new StreamedPHPResponse(
|
|
2147
2167
|
t.stream,
|
|
2148
2168
|
i.stream,
|
|
2149
2169
|
o.stream,
|
|
2150
|
-
|
|
2170
|
+
u
|
|
2151
2171
|
);
|
|
2152
2172
|
};
|
|
2153
2173
|
function normalizeHeaders(r) {
|
|
@@ -2159,7 +2179,12 @@ function normalizeHeaders(r) {
|
|
|
2159
2179
|
function copyMEMFSNodes(r, e, t) {
|
|
2160
2180
|
if (getNodeType(r, t) !== "memfs" || !["memfs", "missing"].includes(getNodeType(e, t)))
|
|
2161
2181
|
return;
|
|
2162
|
-
const s = r.lookupPath(t);
|
|
2182
|
+
const s = r.lookupPath(t, { follow: !1 });
|
|
2183
|
+
if (r.isLink(s.node.mode)) {
|
|
2184
|
+
const i = r.readlink(t);
|
|
2185
|
+
e.symlink(i, t);
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2163
2188
|
if (!r.isDir(s.node.mode)) {
|
|
2164
2189
|
e.writeFile(t, r.readFile(t));
|
|
2165
2190
|
return;
|
|
@@ -2466,7 +2491,43 @@ const SupportedPHPVersions = [
|
|
|
2466
2491
|
"8.1",
|
|
2467
2492
|
"8.0",
|
|
2468
2493
|
"7.4"
|
|
2469
|
-
], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions,
|
|
2494
|
+
], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions, LegacyPHPVersions = ["5.2"];
|
|
2495
|
+
function isLegacyPHPVersion(r) {
|
|
2496
|
+
return LegacyPHPVersions.includes(r ?? "");
|
|
2497
|
+
}
|
|
2498
|
+
const AllPHPVersions = [
|
|
2499
|
+
...SupportedPHPVersions,
|
|
2500
|
+
...LegacyPHPVersions
|
|
2501
|
+
], LEGACY_PHP_INI_PATH = "/internal/shared/php.ini", LEGACY_PHP_INI_CONTENT = [
|
|
2502
|
+
"auto_prepend_file=/internal/shared/auto_prepend_file.php",
|
|
2503
|
+
"memory_limit=256M",
|
|
2504
|
+
"ignore_repeated_errors = 1",
|
|
2505
|
+
"error_reporting = E_ALL",
|
|
2506
|
+
"display_errors = 1",
|
|
2507
|
+
"html_errors = 1",
|
|
2508
|
+
"display_startup_errors = On",
|
|
2509
|
+
"log_errors = 1",
|
|
2510
|
+
"always_populate_raw_post_data = -1",
|
|
2511
|
+
"upload_max_filesize = 2000M",
|
|
2512
|
+
"post_max_size = 2000M",
|
|
2513
|
+
"allow_url_fopen = On",
|
|
2514
|
+
"allow_url_include = Off",
|
|
2515
|
+
"session.save_path = /home/web_user",
|
|
2516
|
+
"implicit_flush = 1",
|
|
2517
|
+
"output_buffering = 0",
|
|
2518
|
+
"max_execution_time = 0",
|
|
2519
|
+
"max_input_time = -1",
|
|
2520
|
+
"disable_functions = ini_get_all",
|
|
2521
|
+
"opcache.enable = 0",
|
|
2522
|
+
"opcache.enable_cli = 0"
|
|
2523
|
+
].join(`
|
|
2524
|
+
`);
|
|
2525
|
+
function createLegacyPhpIniPreRunStep() {
|
|
2526
|
+
return (r) => {
|
|
2527
|
+
r.FS.mkdirTree("/internal/shared"), r.FS.writeFile(LEGACY_PHP_INI_PATH, LEGACY_PHP_INI_CONTENT);
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
const DEFAULT_BASE_URL = "http://example.com";
|
|
2470
2531
|
function toRelativeUrl(r) {
|
|
2471
2532
|
return r.origin === "null" ? r.toString() : r.toString().substring(r.origin.length);
|
|
2472
2533
|
}
|
|
@@ -2597,7 +2658,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2597
2658
|
xspf,
|
|
2598
2659
|
zip
|
|
2599
2660
|
};
|
|
2600
|
-
var
|
|
2661
|
+
var x, C, j, L, M, E, A, k, D, P, ne, B, ie, oe, ae;
|
|
2601
2662
|
class PHPRequestHandler {
|
|
2602
2663
|
/**
|
|
2603
2664
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2612,23 +2673,23 @@ class PHPRequestHandler {
|
|
|
2612
2673
|
*/
|
|
2613
2674
|
constructor(e) {
|
|
2614
2675
|
y(this, P);
|
|
2615
|
-
y(this,
|
|
2616
|
-
y(this,
|
|
2617
|
-
y(this,
|
|
2676
|
+
y(this, x);
|
|
2677
|
+
y(this, C);
|
|
2678
|
+
y(this, j);
|
|
2618
2679
|
y(this, L);
|
|
2619
|
-
y(this,
|
|
2680
|
+
y(this, M);
|
|
2620
2681
|
y(this, E);
|
|
2621
2682
|
y(this, A);
|
|
2622
2683
|
y(this, k);
|
|
2623
|
-
y(this,
|
|
2684
|
+
y(this, D);
|
|
2624
2685
|
const {
|
|
2625
2686
|
documentRoot: t = "/www/",
|
|
2626
2687
|
absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
|
|
2627
2688
|
rewriteRules: n = [],
|
|
2628
2689
|
pathAliases: i = [],
|
|
2629
2690
|
getFileNotFoundAction: o = () => ({ type: "404" })
|
|
2630
|
-
} = e, a = (
|
|
2631
|
-
|
|
2691
|
+
} = e, a = (u) => {
|
|
2692
|
+
u.isDir(t) || u.mkdir(t), u.chdir(t), u.requestHandler = this;
|
|
2632
2693
|
};
|
|
2633
2694
|
if (e.php)
|
|
2634
2695
|
a(e.php), this.instanceManager = new SinglePHPInstanceManager({
|
|
@@ -2636,12 +2697,12 @@ class PHPRequestHandler {
|
|
|
2636
2697
|
});
|
|
2637
2698
|
else if (e.phpFactory)
|
|
2638
2699
|
this.instanceManager = new PHPProcessManager({
|
|
2639
|
-
phpFactory: async (
|
|
2640
|
-
const
|
|
2641
|
-
...
|
|
2700
|
+
phpFactory: async (u) => {
|
|
2701
|
+
const d = await e.phpFactory({
|
|
2702
|
+
...u,
|
|
2642
2703
|
requestHandler: this
|
|
2643
2704
|
});
|
|
2644
|
-
return a(
|
|
2705
|
+
return a(d), d;
|
|
2645
2706
|
},
|
|
2646
2707
|
maxPhpInstances: e.maxPhpInstances
|
|
2647
2708
|
});
|
|
@@ -2649,18 +2710,18 @@ class PHPRequestHandler {
|
|
|
2649
2710
|
throw new Error(
|
|
2650
2711
|
"Either php or phpFactory must be provided in the configuration."
|
|
2651
2712
|
);
|
|
2652
|
-
|
|
2713
|
+
w(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, x, t);
|
|
2653
2714
|
const c = new URL(s);
|
|
2654
|
-
|
|
2655
|
-
const l =
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
l ? `:${
|
|
2659
|
-
].join("")),
|
|
2660
|
-
`${
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
].join("")), this.rewriteRules = n,
|
|
2715
|
+
w(this, j, c.hostname), w(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), w(this, C, (c.protocol || "").replace(":", ""));
|
|
2716
|
+
const l = h(this, L) !== 443 && h(this, L) !== 80;
|
|
2717
|
+
w(this, M, [
|
|
2718
|
+
h(this, j),
|
|
2719
|
+
l ? `:${h(this, L)}` : ""
|
|
2720
|
+
].join("")), w(this, E, c.pathname.replace(/\/+$/, "")), w(this, A, [
|
|
2721
|
+
`${h(this, C)}://`,
|
|
2722
|
+
h(this, M),
|
|
2723
|
+
h(this, E)
|
|
2724
|
+
].join("")), this.rewriteRules = n, w(this, D, i), this.getFileNotFoundAction = o;
|
|
2664
2725
|
}
|
|
2665
2726
|
async getPrimaryPhp() {
|
|
2666
2727
|
return await this.instanceManager.getPrimaryPhp();
|
|
@@ -2684,20 +2745,20 @@ class PHPRequestHandler {
|
|
|
2684
2745
|
*/
|
|
2685
2746
|
internalUrlToPath(e) {
|
|
2686
2747
|
const t = new URL(e, "https://playground.internal");
|
|
2687
|
-
return t.pathname.startsWith(
|
|
2748
|
+
return t.pathname.startsWith(h(this, E)) && (t.pathname = t.pathname.slice(h(this, E).length)), toRelativeUrl(t);
|
|
2688
2749
|
}
|
|
2689
2750
|
/**
|
|
2690
2751
|
* The absolute URL of this PHPRequestHandler instance.
|
|
2691
2752
|
*/
|
|
2692
2753
|
get absoluteUrl() {
|
|
2693
|
-
return
|
|
2754
|
+
return h(this, A);
|
|
2694
2755
|
}
|
|
2695
2756
|
/**
|
|
2696
2757
|
* The directory in the PHP filesystem where the server will look
|
|
2697
2758
|
* for the files to serve. Default: `/var/www`.
|
|
2698
2759
|
*/
|
|
2699
2760
|
get documentRoot() {
|
|
2700
|
-
return
|
|
2761
|
+
return h(this, x);
|
|
2701
2762
|
}
|
|
2702
2763
|
/**
|
|
2703
2764
|
* Serves the request – either by serving a static file, or by
|
|
@@ -2779,9 +2840,9 @@ class PHPRequestHandler {
|
|
|
2779
2840
|
* before using it as a filesystem path.
|
|
2780
2841
|
*/
|
|
2781
2842
|
decodeURIComponent(n.pathname),
|
|
2782
|
-
|
|
2843
|
+
h(this, E)
|
|
2783
2844
|
);
|
|
2784
|
-
let a = m(this, P,
|
|
2845
|
+
let a = m(this, P, B).call(this, o);
|
|
2785
2846
|
if (i.isDir(a)) {
|
|
2786
2847
|
if (!o.endsWith("/"))
|
|
2787
2848
|
return StreamedPHPResponse.fromPHPResponse(
|
|
@@ -2806,10 +2867,10 @@ class PHPRequestHandler {
|
|
|
2806
2867
|
let c = o;
|
|
2807
2868
|
for (; c.startsWith("/") && c !== dirname(c); ) {
|
|
2808
2869
|
c = dirname(c);
|
|
2809
|
-
const l = m(this, P,
|
|
2870
|
+
const l = m(this, P, B).call(this, c);
|
|
2810
2871
|
if (i.isFile(l) && // Only run partial path resolution for PHP files.
|
|
2811
2872
|
l.endsWith(".php")) {
|
|
2812
|
-
a = m(this, P,
|
|
2873
|
+
a = m(this, P, B).call(this, c);
|
|
2813
2874
|
break;
|
|
2814
2875
|
}
|
|
2815
2876
|
}
|
|
@@ -2824,7 +2885,7 @@ class PHPRequestHandler {
|
|
|
2824
2885
|
c.response
|
|
2825
2886
|
);
|
|
2826
2887
|
case "internal-redirect":
|
|
2827
|
-
a = joinPaths(
|
|
2888
|
+
a = joinPaths(h(this, x), c.uri);
|
|
2828
2889
|
break;
|
|
2829
2890
|
case "404":
|
|
2830
2891
|
return StreamedPHPResponse.forHttpCode(404);
|
|
@@ -2929,11 +2990,11 @@ class PHPRequestHandler {
|
|
|
2929
2990
|
prepare_$_SERVER_superglobal(e, t, s) {
|
|
2930
2991
|
const n = {
|
|
2931
2992
|
REMOTE_ADDR: "127.0.0.1",
|
|
2932
|
-
DOCUMENT_ROOT:
|
|
2933
|
-
HTTPS:
|
|
2993
|
+
DOCUMENT_ROOT: h(this, x),
|
|
2994
|
+
HTTPS: h(this, A).startsWith("https://") ? "on" : ""
|
|
2934
2995
|
};
|
|
2935
|
-
return n.REQUEST_URI = e.pathname + e.search, s.startsWith(
|
|
2936
|
-
|
|
2996
|
+
return n.REQUEST_URI = e.pathname + e.search, s.startsWith(h(this, x)) && (n.SCRIPT_NAME = s.substring(
|
|
2997
|
+
h(this, x).length
|
|
2937
2998
|
), n.PHP_SELF = t.pathname, n.REQUEST_URI.startsWith(n.SCRIPT_NAME) && (n.PATH_INFO = n.REQUEST_URI.substring(
|
|
2938
2999
|
n.SCRIPT_NAME.length
|
|
2939
3000
|
), n.PATH_INFO.includes("?") && (n.PATH_INFO = n.PATH_INFO.substring(
|
|
@@ -2945,7 +3006,7 @@ class PHPRequestHandler {
|
|
|
2945
3006
|
await this.instanceManager[Symbol.asyncDispose]();
|
|
2946
3007
|
}
|
|
2947
3008
|
}
|
|
2948
|
-
|
|
3009
|
+
x = new WeakMap(), C = new WeakMap(), j = new WeakMap(), L = new WeakMap(), M = new WeakMap(), E = new WeakMap(), A = new WeakMap(), k = new WeakMap(), D = new WeakMap(), P = new WeakSet(), /**
|
|
2949
3010
|
* Apply the rewrite rules to the original request URL.
|
|
2950
3011
|
*
|
|
2951
3012
|
* @param originalRequestUrl - The original request URL.
|
|
@@ -2954,12 +3015,12 @@ S = new WeakMap(), M = new WeakMap(), U = new WeakMap(), L = new WeakMap(), I =
|
|
|
2954
3015
|
ne = function(e) {
|
|
2955
3016
|
const t = removePathPrefix(
|
|
2956
3017
|
decodeURIComponent(e.pathname),
|
|
2957
|
-
|
|
3018
|
+
h(this, E)
|
|
2958
3019
|
), s = applyRewriteRules(
|
|
2959
3020
|
t,
|
|
2960
3021
|
this.rewriteRules
|
|
2961
3022
|
), n = new URL(
|
|
2962
|
-
joinPaths(
|
|
3023
|
+
joinPaths(h(this, E), s),
|
|
2963
3024
|
e.toString()
|
|
2964
3025
|
);
|
|
2965
3026
|
for (const [i, o] of e.searchParams.entries())
|
|
@@ -2974,13 +3035,13 @@ ne = function(e) {
|
|
|
2974
3035
|
* @param urlPath - The URL path to resolve (e.g., '/phpmyadmin/index.php')
|
|
2975
3036
|
* @returns The resolved filesystem path
|
|
2976
3037
|
*/
|
|
2977
|
-
|
|
2978
|
-
for (const t of
|
|
3038
|
+
B = function(e) {
|
|
3039
|
+
for (const t of h(this, D))
|
|
2979
3040
|
if (e === t.urlPrefix || e.startsWith(t.urlPrefix + "/")) {
|
|
2980
3041
|
const s = e.slice(t.urlPrefix.length);
|
|
2981
3042
|
return joinPaths(t.fsPath, s);
|
|
2982
3043
|
}
|
|
2983
|
-
return joinPaths(
|
|
3044
|
+
return joinPaths(h(this, x), e);
|
|
2984
3045
|
}, /**
|
|
2985
3046
|
* Serves a static file from the PHP filesystem.
|
|
2986
3047
|
*
|
|
@@ -3021,22 +3082,22 @@ ie = function(e, t) {
|
|
|
3021
3082
|
}, ae = async function(e, t, s, n, i) {
|
|
3022
3083
|
let o = "GET";
|
|
3023
3084
|
const a = {
|
|
3024
|
-
host:
|
|
3085
|
+
host: h(this, M),
|
|
3025
3086
|
...normalizeHeaders(t.headers || {})
|
|
3026
3087
|
};
|
|
3027
|
-
|
|
3088
|
+
h(this, k) && (a.cookie = h(this, k).getCookieRequestHeader());
|
|
3028
3089
|
let c = t.body;
|
|
3029
3090
|
if (typeof c == "object" && !(c instanceof Uint8Array)) {
|
|
3030
3091
|
o = "POST";
|
|
3031
|
-
const { bytes:
|
|
3032
|
-
c =
|
|
3092
|
+
const { bytes: u, contentType: d } = await encodeAsMultipart(c);
|
|
3093
|
+
c = u, a["content-type"] = d;
|
|
3033
3094
|
}
|
|
3034
3095
|
const l = await e.runStream({
|
|
3035
3096
|
relativeUri: ensurePathPrefix(
|
|
3036
3097
|
toRelativeUrl(new URL(n.toString())),
|
|
3037
|
-
|
|
3098
|
+
h(this, E)
|
|
3038
3099
|
),
|
|
3039
|
-
protocol:
|
|
3100
|
+
protocol: h(this, C),
|
|
3040
3101
|
method: t.method || o,
|
|
3041
3102
|
$_SERVER: this.prepare_$_SERVER_superglobal(
|
|
3042
3103
|
s,
|
|
@@ -3047,10 +3108,10 @@ ie = function(e, t) {
|
|
|
3047
3108
|
scriptPath: i,
|
|
3048
3109
|
headers: a
|
|
3049
3110
|
});
|
|
3050
|
-
if (
|
|
3051
|
-
const
|
|
3052
|
-
|
|
3053
|
-
|
|
3111
|
+
if (h(this, k)) {
|
|
3112
|
+
const u = await l.headers;
|
|
3113
|
+
h(this, k).rememberCookiesFromResponseHeaders(
|
|
3114
|
+
u
|
|
3054
3115
|
);
|
|
3055
3116
|
}
|
|
3056
3117
|
return l;
|
|
@@ -3091,6 +3152,200 @@ async function writeFiles(r, e, t, { rmRoot: s = !1 } = {}) {
|
|
|
3091
3152
|
await r.fileExists(dirname(o)) || await r.mkdir(dirname(o)), i instanceof Uint8Array || typeof i == "string" ? await r.writeFile(o, i) : await writeFiles(r, o, i);
|
|
3092
3153
|
}
|
|
3093
3154
|
}
|
|
3155
|
+
const PHP_EXTENSIONS_DIR = "/internal/shared/extensions";
|
|
3156
|
+
async function resolvePHPExtension(r) {
|
|
3157
|
+
const e = await resolvePHPExtensionSource(
|
|
3158
|
+
r,
|
|
3159
|
+
r.fetch ?? globalThis.fetch
|
|
3160
|
+
);
|
|
3161
|
+
return buildResolvedPHPExtension({
|
|
3162
|
+
name: r.name ?? e.name,
|
|
3163
|
+
soBytes: e.soBytes,
|
|
3164
|
+
loadWithIniDirective: r.loadWithIniDirective,
|
|
3165
|
+
iniEntries: r.iniEntries,
|
|
3166
|
+
extraFiles: r.extraFiles,
|
|
3167
|
+
env: r.env,
|
|
3168
|
+
extensionDir: r.extensionDir
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
function withResolvedPHPExtensions(r, e) {
|
|
3172
|
+
if (!e.length)
|
|
3173
|
+
return r;
|
|
3174
|
+
const t = {
|
|
3175
|
+
...r.ENV
|
|
3176
|
+
};
|
|
3177
|
+
for (const s of e) {
|
|
3178
|
+
Object.assign(t, s.env);
|
|
3179
|
+
const n = t.PHP_INI_SCAN_DIR, i = n ? n.split(":") : [];
|
|
3180
|
+
t.PHP_INI_SCAN_DIR = !n || !i.includes(s.extensionDir) ? [...i, s.extensionDir].join(":") : n;
|
|
3181
|
+
}
|
|
3182
|
+
return {
|
|
3183
|
+
...r,
|
|
3184
|
+
ENV: t,
|
|
3185
|
+
onRuntimeInitialized: (s) => {
|
|
3186
|
+
var n;
|
|
3187
|
+
(n = r.onRuntimeInitialized) == null || n.call(r, s);
|
|
3188
|
+
for (const i of e)
|
|
3189
|
+
installPHPExtensionFilesSync(s.FS, i);
|
|
3190
|
+
}
|
|
3191
|
+
};
|
|
3192
|
+
}
|
|
3193
|
+
function buildResolvedPHPExtension(r) {
|
|
3194
|
+
const e = r.extensionDir ?? PHP_EXTENSIONS_DIR, t = r.name;
|
|
3195
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(t))
|
|
3196
|
+
throw new Error(
|
|
3197
|
+
`Invalid PHP extension name ${JSON.stringify(
|
|
3198
|
+
t
|
|
3199
|
+
)}. Extension names are used to build VFS file names and ini paths, so they may only contain [a-zA-Z0-9_-].`
|
|
3200
|
+
);
|
|
3201
|
+
const s = r.loadWithIniDirective ?? "extension", n = joinPaths(e, `${t}.so`), i = joinPaths(e, `${t}.ini`), o = [
|
|
3202
|
+
`${s}=${n}`,
|
|
3203
|
+
...Object.entries(r.iniEntries ?? {}).map(
|
|
3204
|
+
([c, l]) => `${c}=${l}`
|
|
3205
|
+
)
|
|
3206
|
+
].join(`
|
|
3207
|
+
`), a = r.extraFiles ? {
|
|
3208
|
+
...r.extraFiles,
|
|
3209
|
+
targetPath: r.extraFiles.targetPath ?? joinPaths(e, `${t}-assets`)
|
|
3210
|
+
} : void 0;
|
|
3211
|
+
return {
|
|
3212
|
+
soPath: n,
|
|
3213
|
+
soBytes: toUint8Array(r.soBytes),
|
|
3214
|
+
iniPath: i,
|
|
3215
|
+
iniContent: o,
|
|
3216
|
+
extraFiles: a,
|
|
3217
|
+
env: r.env,
|
|
3218
|
+
extensionDir: e
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
function installPHPExtensionFilesSync(r, e) {
|
|
3222
|
+
const t = "soPath" in e ? e : buildResolvedPHPExtension(e);
|
|
3223
|
+
return FSHelpers.fileExists(r, t.extensionDir) || r.mkdirTree(t.extensionDir), r.writeFile(t.soPath, t.soBytes), r.writeFile(t.iniPath, t.iniContent), t.extraFiles && writeFileTreeSync(
|
|
3224
|
+
r,
|
|
3225
|
+
t.extraFiles.targetPath,
|
|
3226
|
+
t.extraFiles.files
|
|
3227
|
+
), t;
|
|
3228
|
+
}
|
|
3229
|
+
async function resolvePHPExtensionSource(r, e) {
|
|
3230
|
+
const t = r.source;
|
|
3231
|
+
if (t.format === "so") {
|
|
3232
|
+
const d = r.name ?? t.name;
|
|
3233
|
+
if (!d)
|
|
3234
|
+
throw new Error(
|
|
3235
|
+
"name is required when loading an extension from direct bytes."
|
|
3236
|
+
);
|
|
3237
|
+
return t.sha256 && await assertSha256(t.bytes, t.sha256, d), { name: d, soBytes: toUint8Array(t.bytes) };
|
|
3238
|
+
}
|
|
3239
|
+
if (t.format === "url") {
|
|
3240
|
+
let d;
|
|
3241
|
+
try {
|
|
3242
|
+
d = new URL(String(t.url));
|
|
3243
|
+
} catch {
|
|
3244
|
+
throw new Error(
|
|
3245
|
+
`source.url must be an absolute URL when loading a PHP extension from a direct URL. Received: ${String(
|
|
3246
|
+
t.url
|
|
3247
|
+
)}`
|
|
3248
|
+
);
|
|
3249
|
+
}
|
|
3250
|
+
const p = r.name ?? t.name ?? (() => {
|
|
3251
|
+
const N = d.pathname.split("/").pop() ?? "";
|
|
3252
|
+
return N.endsWith(".so") ? N.slice(0, -3) : void 0;
|
|
3253
|
+
})();
|
|
3254
|
+
if (!p)
|
|
3255
|
+
throw new Error(
|
|
3256
|
+
"name is required when loading an extension from a direct URL."
|
|
3257
|
+
);
|
|
3258
|
+
if (!e)
|
|
3259
|
+
throw new Error(
|
|
3260
|
+
"resolvePHPExtension() requires a fetch implementation."
|
|
3261
|
+
);
|
|
3262
|
+
const g = await e(d);
|
|
3263
|
+
if (!g.ok)
|
|
3264
|
+
throw new Error(
|
|
3265
|
+
`Failed to fetch ${String(d)}: ${g.status}`
|
|
3266
|
+
);
|
|
3267
|
+
const S = new Uint8Array(await g.arrayBuffer());
|
|
3268
|
+
return t.sha256 && await assertSha256(S, t.sha256, String(d)), { name: p, soBytes: S };
|
|
3269
|
+
}
|
|
3270
|
+
const s = "manifestUrl" in t ? new URL(String(t.manifestUrl)) : void 0;
|
|
3271
|
+
let n;
|
|
3272
|
+
if ("manifest" in t)
|
|
3273
|
+
n = t.manifest;
|
|
3274
|
+
else {
|
|
3275
|
+
if (!e)
|
|
3276
|
+
throw new Error(
|
|
3277
|
+
"resolvePHPExtension() requires a fetch implementation."
|
|
3278
|
+
);
|
|
3279
|
+
const d = await e(s);
|
|
3280
|
+
if (!d.ok)
|
|
3281
|
+
throw new Error(
|
|
3282
|
+
`Failed to fetch ${String(s)}: ${d.status}`
|
|
3283
|
+
);
|
|
3284
|
+
n = await d.json();
|
|
3285
|
+
}
|
|
3286
|
+
if (!n || typeof n != "object")
|
|
3287
|
+
throw new Error("Extension manifest must be an object.");
|
|
3288
|
+
const i = n;
|
|
3289
|
+
if (typeof i.name != "string" || !i.name)
|
|
3290
|
+
throw new Error("Extension manifest must include a name.");
|
|
3291
|
+
if (!Array.isArray(i.artifacts))
|
|
3292
|
+
throw new Error("Extension manifest must include an artifacts array.");
|
|
3293
|
+
for (const d of i.artifacts)
|
|
3294
|
+
if (!d || typeof d.phpVersion != "string" || d.asyncMode !== "jspi" && d.asyncMode !== "asyncify" || typeof d.file != "string")
|
|
3295
|
+
throw new Error("Extension manifest contains an invalid artifact.");
|
|
3296
|
+
const o = "baseUrl" in t && t.baseUrl ? new URL(String(t.baseUrl)) : s, a = i.artifacts.find(
|
|
3297
|
+
(d) => d.phpVersion === r.phpVersion && d.asyncMode === r.asyncMode
|
|
3298
|
+
);
|
|
3299
|
+
if (!a)
|
|
3300
|
+
throw new Error(
|
|
3301
|
+
`No extension artifact found for PHP ${r.phpVersion} ${r.asyncMode}.`
|
|
3302
|
+
);
|
|
3303
|
+
if (!o)
|
|
3304
|
+
throw new Error(
|
|
3305
|
+
"Manifest artifacts require a manifest URL or baseUrl so relative files can be resolved."
|
|
3306
|
+
);
|
|
3307
|
+
const c = new URL(a.file, o);
|
|
3308
|
+
if (!e)
|
|
3309
|
+
throw new Error(
|
|
3310
|
+
"resolvePHPExtension() requires a fetch implementation."
|
|
3311
|
+
);
|
|
3312
|
+
const l = await e(c);
|
|
3313
|
+
if (!l.ok)
|
|
3314
|
+
throw new Error(
|
|
3315
|
+
`Failed to fetch ${String(c)}: ${l.status}`
|
|
3316
|
+
);
|
|
3317
|
+
const u = new Uint8Array(await l.arrayBuffer());
|
|
3318
|
+
return a.sha256 && await assertSha256(u, a.sha256, a.file), {
|
|
3319
|
+
name: i.name,
|
|
3320
|
+
soBytes: u
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
function writeFileTreeSync(r, e, t) {
|
|
3324
|
+
FSHelpers.fileExists(r, e) || r.mkdirTree(e);
|
|
3325
|
+
for (const [s, n] of Object.entries(t)) {
|
|
3326
|
+
const i = joinPaths(e, s), o = dirname(i);
|
|
3327
|
+
FSHelpers.fileExists(r, o) || r.mkdirTree(o), n instanceof Uint8Array || typeof n == "string" ? r.writeFile(i, n) : writeFileTreeSync(r, i, n);
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
async function assertSha256(r, e, t) {
|
|
3331
|
+
var o;
|
|
3332
|
+
const s = (o = globalThis.crypto) == null ? void 0 : o.subtle;
|
|
3333
|
+
if (!s)
|
|
3334
|
+
throw new Error(
|
|
3335
|
+
`Cannot verify ${t}: crypto.subtle is not available.`
|
|
3336
|
+
);
|
|
3337
|
+
const n = await s.digest("SHA-256", toUint8Array(r));
|
|
3338
|
+
if (Array.from(new Uint8Array(n)).map((a) => a.toString(16).padStart(2, "0")).join("") !== e)
|
|
3339
|
+
throw new Error(`SHA-256 mismatch for ${t}.`);
|
|
3340
|
+
}
|
|
3341
|
+
function toUint8Array(r) {
|
|
3342
|
+
return r instanceof Uint8Array ? r : new Uint8Array(r);
|
|
3343
|
+
}
|
|
3344
|
+
function isLegacyPhpInstance(r) {
|
|
3345
|
+
var n;
|
|
3346
|
+
const e = Object.getOwnPropertySymbols(r)[0], t = r[e], s = (n = t == null ? void 0 : t.phpVersion) == null ? void 0 : n.major;
|
|
3347
|
+
return typeof s == "number" && s < 7;
|
|
3348
|
+
}
|
|
3094
3349
|
function ensureProxyFSHasMmapSupport(r) {
|
|
3095
3350
|
const e = Object.getOwnPropertySymbols(r)[0], t = r[e], s = t.PROXYFS, n = t.FS;
|
|
3096
3351
|
s.stream_ops.mmap || (s.stream_ops.mmap = function(i, o, a, c, l) {
|
|
@@ -3098,25 +3353,25 @@ function ensureProxyFSHasMmapSupport(r) {
|
|
|
3098
3353
|
throw new n.ErrnoError(19);
|
|
3099
3354
|
if (a !== 0)
|
|
3100
3355
|
throw new n.ErrnoError(22);
|
|
3101
|
-
const
|
|
3102
|
-
if (!
|
|
3356
|
+
const u = t.malloc(o);
|
|
3357
|
+
if (!u)
|
|
3103
3358
|
throw new n.ErrnoError(48);
|
|
3104
|
-
const
|
|
3105
|
-
let
|
|
3106
|
-
for (;
|
|
3107
|
-
const
|
|
3359
|
+
const d = t.HEAPU8.subarray(u, u + o);
|
|
3360
|
+
let p = 0;
|
|
3361
|
+
for (; p < o; ) {
|
|
3362
|
+
const g = i.stream_ops.read(
|
|
3108
3363
|
i,
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
o -
|
|
3112
|
-
|
|
3364
|
+
d,
|
|
3365
|
+
p,
|
|
3366
|
+
o - p,
|
|
3367
|
+
p
|
|
3113
3368
|
);
|
|
3114
|
-
if (
|
|
3115
|
-
|
|
3369
|
+
if (g <= 0) break;
|
|
3370
|
+
p += g;
|
|
3116
3371
|
}
|
|
3117
|
-
if (
|
|
3118
|
-
throw t.free(
|
|
3119
|
-
return { ptr:
|
|
3372
|
+
if (p !== o)
|
|
3373
|
+
throw t.free(u), new n.ErrnoError(5);
|
|
3374
|
+
return { ptr: u, allocated: !0 };
|
|
3120
3375
|
}, s.stream_ops.msync = function(i, o, a, c, l) {
|
|
3121
3376
|
return l & 2 || i.stream_ops.write(
|
|
3122
3377
|
i,
|
|
@@ -3129,23 +3384,23 @@ function ensureProxyFSHasMmapSupport(r) {
|
|
|
3129
3384
|
});
|
|
3130
3385
|
}
|
|
3131
3386
|
async function proxyFileSystem(r, e, t) {
|
|
3132
|
-
const s = Object.getOwnPropertySymbols(r)[0];
|
|
3133
|
-
for (const
|
|
3134
|
-
r.fileExists(
|
|
3135
|
-
ensureProxyFSHasMmapSupport(
|
|
3136
|
-
const
|
|
3137
|
-
return
|
|
3387
|
+
const s = isLegacyPhpInstance(e), n = Object.getOwnPropertySymbols(r)[0];
|
|
3388
|
+
for (const i of t)
|
|
3389
|
+
r.fileExists(i) || r.mkdir(i), e.mkdir(i), await e.mount(i, (o) => {
|
|
3390
|
+
s || ensureProxyFSHasMmapSupport(o);
|
|
3391
|
+
const a = Object.getOwnPropertySymbols(o)[0];
|
|
3392
|
+
return o[a].FS.mount(
|
|
3138
3393
|
// @ts-ignore
|
|
3139
|
-
|
|
3394
|
+
o[a].PROXYFS,
|
|
3140
3395
|
{
|
|
3141
|
-
root:
|
|
3396
|
+
root: i,
|
|
3142
3397
|
// @ts-ignore
|
|
3143
|
-
fs: r[
|
|
3398
|
+
fs: r[n].FS
|
|
3144
3399
|
},
|
|
3145
|
-
|
|
3400
|
+
i
|
|
3146
3401
|
), () => {
|
|
3147
3402
|
try {
|
|
3148
|
-
|
|
3403
|
+
o[a].FS.unmount(i);
|
|
3149
3404
|
} catch {
|
|
3150
3405
|
}
|
|
3151
3406
|
};
|
|
@@ -3324,10 +3579,10 @@ class NodeSABSyncReceiveMessageTransport {
|
|
|
3324
3579
|
), Atomics.wait(i, 0, 0, 5e3) === "timed-out")
|
|
3325
3580
|
throw new Error("Timeout waiting for response");
|
|
3326
3581
|
for (; ; ) {
|
|
3327
|
-
const
|
|
3328
|
-
if (((l =
|
|
3329
|
-
return
|
|
3330
|
-
if (!
|
|
3582
|
+
const u = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
|
|
3583
|
+
if (((l = u.message) == null ? void 0 : l.id) === o)
|
|
3584
|
+
return u.message;
|
|
3585
|
+
if (!u)
|
|
3331
3586
|
throw new Error("No response received");
|
|
3332
3587
|
}
|
|
3333
3588
|
}
|
|
@@ -3405,51 +3660,51 @@ function expose(r, e = globalThis, t = ["*"], s) {
|
|
|
3405
3660
|
path: [],
|
|
3406
3661
|
...i.data
|
|
3407
3662
|
}, l = (i.data.argumentList || []).map(fromWireValue);
|
|
3408
|
-
let
|
|
3663
|
+
let u;
|
|
3409
3664
|
try {
|
|
3410
|
-
const
|
|
3665
|
+
const d = c.slice(0, -1).reduce((g, S) => g[S], r), p = c.reduce((g, S) => g[S], r);
|
|
3411
3666
|
switch (a) {
|
|
3412
3667
|
case MessageType.GET:
|
|
3413
|
-
|
|
3668
|
+
u = p;
|
|
3414
3669
|
break;
|
|
3415
3670
|
case MessageType.SET:
|
|
3416
|
-
|
|
3671
|
+
d[c.slice(-1)[0]] = fromWireValue(
|
|
3417
3672
|
i.data.value
|
|
3418
|
-
),
|
|
3673
|
+
), u = !0;
|
|
3419
3674
|
break;
|
|
3420
3675
|
case MessageType.APPLY:
|
|
3421
|
-
|
|
3676
|
+
u = p.apply(d, l);
|
|
3422
3677
|
break;
|
|
3423
3678
|
case MessageType.CONSTRUCT:
|
|
3424
3679
|
{
|
|
3425
|
-
const
|
|
3426
|
-
|
|
3680
|
+
const g = new p(...l);
|
|
3681
|
+
u = proxy(g);
|
|
3427
3682
|
}
|
|
3428
3683
|
break;
|
|
3429
3684
|
case MessageType.ENDPOINT:
|
|
3430
3685
|
{
|
|
3431
|
-
const { port1:
|
|
3432
|
-
expose(r,
|
|
3686
|
+
const { port1: g, port2: S } = new MessageChannel();
|
|
3687
|
+
expose(r, S), u = transfer(g, [g]);
|
|
3433
3688
|
}
|
|
3434
3689
|
break;
|
|
3435
3690
|
case MessageType.RELEASE:
|
|
3436
|
-
|
|
3691
|
+
u = void 0;
|
|
3437
3692
|
break;
|
|
3438
3693
|
default:
|
|
3439
3694
|
return;
|
|
3440
3695
|
}
|
|
3441
|
-
} catch (
|
|
3442
|
-
|
|
3696
|
+
} catch (d) {
|
|
3697
|
+
u = { value: d, [throwMarker]: 0 };
|
|
3443
3698
|
}
|
|
3444
|
-
Promise.resolve(
|
|
3445
|
-
const [
|
|
3446
|
-
e.postMessage({ ...
|
|
3699
|
+
Promise.resolve(u).catch((d) => ({ value: d, [throwMarker]: 0 })).then((d) => {
|
|
3700
|
+
const [p, g] = toWireValue(d);
|
|
3701
|
+
e.postMessage({ ...p, id: o }, g), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in r && typeof r[finalizer] == "function" && r[finalizer]());
|
|
3447
3702
|
}).catch(() => {
|
|
3448
|
-
const [
|
|
3703
|
+
const [d, p] = toWireValue({
|
|
3449
3704
|
value: new TypeError("Unserializable return value"),
|
|
3450
3705
|
[throwMarker]: 0
|
|
3451
3706
|
});
|
|
3452
|
-
e.postMessage({ ...
|
|
3707
|
+
e.postMessage({ ...d, id: o }, p);
|
|
3453
3708
|
}).finally(() => {
|
|
3454
3709
|
s == null || s(i);
|
|
3455
3710
|
});
|
|
@@ -3520,16 +3775,16 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3520
3775
|
},
|
|
3521
3776
|
set(o, a, c) {
|
|
3522
3777
|
throwIfProxyReleased(n);
|
|
3523
|
-
const [l,
|
|
3778
|
+
const [l, u] = toWireValue(c);
|
|
3524
3779
|
return requestResponseMessage(
|
|
3525
3780
|
r,
|
|
3526
3781
|
e,
|
|
3527
3782
|
{
|
|
3528
3783
|
type: MessageType.SET,
|
|
3529
|
-
path: [...t, a].map((
|
|
3784
|
+
path: [...t, a].map((d) => d.toString()),
|
|
3530
3785
|
value: l
|
|
3531
3786
|
},
|
|
3532
|
-
|
|
3787
|
+
u
|
|
3533
3788
|
).then(fromWireValue);
|
|
3534
3789
|
},
|
|
3535
3790
|
apply(o, a, c) {
|
|
@@ -3541,16 +3796,16 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3541
3796
|
}).then(fromWireValue);
|
|
3542
3797
|
if (l === "bind")
|
|
3543
3798
|
return createProxy(r, e, t.slice(0, -1));
|
|
3544
|
-
const [
|
|
3799
|
+
const [u, d] = processArguments(c);
|
|
3545
3800
|
return requestResponseMessage(
|
|
3546
3801
|
r,
|
|
3547
3802
|
e,
|
|
3548
3803
|
{
|
|
3549
3804
|
type: MessageType.APPLY,
|
|
3550
|
-
path: t.map((
|
|
3551
|
-
argumentList:
|
|
3805
|
+
path: t.map((p) => p.toString()),
|
|
3806
|
+
argumentList: u
|
|
3552
3807
|
},
|
|
3553
|
-
|
|
3808
|
+
d
|
|
3554
3809
|
).then(fromWireValue);
|
|
3555
3810
|
},
|
|
3556
3811
|
construct(o, a) {
|
|
@@ -3561,7 +3816,7 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3561
3816
|
e,
|
|
3562
3817
|
{
|
|
3563
3818
|
type: MessageType.CONSTRUCT,
|
|
3564
|
-
path: t.map((
|
|
3819
|
+
path: t.map((u) => u.toString()),
|
|
3565
3820
|
argumentList: c
|
|
3566
3821
|
},
|
|
3567
3822
|
l
|
|
@@ -3761,19 +4016,19 @@ const errorProperties = [
|
|
|
3761
4016
|
useToJSON: o,
|
|
3762
4017
|
serialize: a
|
|
3763
4018
|
});
|
|
3764
|
-
for (const [l,
|
|
3765
|
-
if (
|
|
4019
|
+
for (const [l, u] of Object.entries(r)) {
|
|
4020
|
+
if (u && u instanceof Uint8Array && u.constructor.name === "Buffer") {
|
|
3766
4021
|
t[l] = "[object Buffer]";
|
|
3767
4022
|
continue;
|
|
3768
4023
|
}
|
|
3769
|
-
if (
|
|
4024
|
+
if (u !== null && typeof u == "object" && typeof u.pipe == "function") {
|
|
3770
4025
|
t[l] = "[object Stream]";
|
|
3771
4026
|
continue;
|
|
3772
4027
|
}
|
|
3773
|
-
if (typeof
|
|
3774
|
-
if (!
|
|
4028
|
+
if (typeof u != "function") {
|
|
4029
|
+
if (!u || typeof u != "object") {
|
|
3775
4030
|
try {
|
|
3776
|
-
t[l] =
|
|
4031
|
+
t[l] = u;
|
|
3777
4032
|
} catch {
|
|
3778
4033
|
}
|
|
3779
4034
|
continue;
|
|
@@ -3786,10 +4041,10 @@ const errorProperties = [
|
|
|
3786
4041
|
}
|
|
3787
4042
|
}
|
|
3788
4043
|
if (a || t instanceof Error)
|
|
3789
|
-
for (const { property: l, enumerable:
|
|
4044
|
+
for (const { property: l, enumerable: u } of errorProperties)
|
|
3790
4045
|
r[l] !== void 0 && r[l] !== null && Object.defineProperty(t, l, {
|
|
3791
4046
|
value: isErrorLike(r[l]) || Array.isArray(r[l]) ? c(r[l]) : r[l],
|
|
3792
|
-
enumerable: s ? !0 :
|
|
4047
|
+
enumerable: s ? !0 : u,
|
|
3793
4048
|
configurable: !0,
|
|
3794
4049
|
writable: !0
|
|
3795
4050
|
});
|
|
@@ -4734,18 +4989,25 @@ function createObjectPoolProxy(r) {
|
|
|
4734
4989
|
}
|
|
4735
4990
|
function i(o) {
|
|
4736
4991
|
return s().then((a) => {
|
|
4737
|
-
|
|
4992
|
+
const c = (u) => {
|
|
4993
|
+
const d = u == null ? void 0 : u.finished;
|
|
4994
|
+
return d && typeof d.then == "function" ? Promise.resolve(d).then(
|
|
4995
|
+
() => n(a),
|
|
4996
|
+
() => n(a)
|
|
4997
|
+
) : n(a), u;
|
|
4998
|
+
};
|
|
4999
|
+
let l;
|
|
4738
5000
|
try {
|
|
4739
|
-
|
|
4740
|
-
} catch (
|
|
4741
|
-
throw n(a),
|
|
5001
|
+
l = o(a);
|
|
5002
|
+
} catch (u) {
|
|
5003
|
+
throw n(a), u;
|
|
4742
5004
|
}
|
|
4743
|
-
return
|
|
4744
|
-
(
|
|
4745
|
-
(
|
|
4746
|
-
throw n(a),
|
|
5005
|
+
return l != null && typeof l.then == "function" ? l.then(
|
|
5006
|
+
(u) => c(u),
|
|
5007
|
+
(u) => {
|
|
5008
|
+
throw n(a), u;
|
|
4747
5009
|
}
|
|
4748
|
-
) : (
|
|
5010
|
+
) : c(l);
|
|
4749
5011
|
});
|
|
4750
5012
|
}
|
|
4751
5013
|
return new Proxy({}, {
|
|
@@ -4755,14 +5017,14 @@ function createObjectPoolProxy(r) {
|
|
|
4755
5017
|
if (a !== "then")
|
|
4756
5018
|
return new Proxy(function() {
|
|
4757
5019
|
}, {
|
|
4758
|
-
apply(c, l,
|
|
4759
|
-
return i((
|
|
5020
|
+
apply(c, l, u) {
|
|
5021
|
+
return i((d) => d[a](...u));
|
|
4760
5022
|
},
|
|
4761
5023
|
get(c, l) {
|
|
4762
5024
|
if (l === "then")
|
|
4763
|
-
return (
|
|
4764
|
-
|
|
4765
|
-
|
|
5025
|
+
return (u, d) => i((p) => p[a]).then(
|
|
5026
|
+
u,
|
|
5027
|
+
d
|
|
4766
5028
|
);
|
|
4767
5029
|
}
|
|
4768
5030
|
});
|
|
@@ -4790,6 +5052,7 @@ class ProcessIdAllocator {
|
|
|
4790
5052
|
}
|
|
4791
5053
|
}
|
|
4792
5054
|
export {
|
|
5055
|
+
AllPHPVersions,
|
|
4793
5056
|
DEFAULT_BASE_URL,
|
|
4794
5057
|
FSHelpers,
|
|
4795
5058
|
FileLock,
|
|
@@ -4797,7 +5060,10 @@ export {
|
|
|
4797
5060
|
FileLockManagerComposite,
|
|
4798
5061
|
FileLockManagerInMemory,
|
|
4799
5062
|
HttpCookieStore,
|
|
5063
|
+
LEGACY_PHP_INI_CONTENT,
|
|
5064
|
+
LEGACY_PHP_INI_PATH,
|
|
4800
5065
|
LatestSupportedPHPVersion,
|
|
5066
|
+
LegacyPHPVersions,
|
|
4801
5067
|
MAX_ADDRESSABLE_FILE_OFFSET,
|
|
4802
5068
|
PHP,
|
|
4803
5069
|
PHPExecutionFailureError,
|
|
@@ -4805,6 +5071,7 @@ export {
|
|
|
4805
5071
|
PHPRequestHandler,
|
|
4806
5072
|
PHPResponse,
|
|
4807
5073
|
PHPWorker,
|
|
5074
|
+
PHP_EXTENSIONS_DIR,
|
|
4808
5075
|
ProcessIdAllocator,
|
|
4809
5076
|
SinglePHPInstanceManager,
|
|
4810
5077
|
StreamedPHPResponse,
|
|
@@ -4815,13 +5082,16 @@ export {
|
|
|
4815
5082
|
applyRewriteRules,
|
|
4816
5083
|
consumeAPI,
|
|
4817
5084
|
consumeAPISync,
|
|
5085
|
+
createLegacyPhpIniPreRunStep,
|
|
4818
5086
|
createObjectPoolProxy,
|
|
4819
5087
|
ensurePathPrefix,
|
|
4820
5088
|
exposeAPI,
|
|
4821
5089
|
exposeSyncAPI,
|
|
4822
5090
|
getPhpIniEntries,
|
|
4823
5091
|
inferMimeType,
|
|
5092
|
+
installPHPExtensionFilesSync,
|
|
4824
5093
|
isExitCode,
|
|
5094
|
+
isLegacyPHPVersion,
|
|
4825
5095
|
isPathToSharedFS,
|
|
4826
5096
|
iteratePhpFiles as iterateFiles,
|
|
4827
5097
|
loadPHPRuntime,
|
|
@@ -4833,12 +5103,14 @@ export {
|
|
|
4833
5103
|
proxyFileSystem,
|
|
4834
5104
|
releaseApiProxy,
|
|
4835
5105
|
removePathPrefix,
|
|
5106
|
+
resolvePHPExtension,
|
|
4836
5107
|
rotatePHPRuntime,
|
|
4837
5108
|
sandboxedSpawnHandlerFactory,
|
|
4838
5109
|
setPhpIniEntries,
|
|
4839
5110
|
streamToPort,
|
|
4840
5111
|
toRelativeUrl,
|
|
4841
5112
|
withPHPIniValues,
|
|
5113
|
+
withResolvedPHPExtensions,
|
|
4842
5114
|
writeFiles,
|
|
4843
5115
|
writeFilesStreamToPhp
|
|
4844
5116
|
};
|