@php-wasm/universal 0.6.2 → 0.6.4
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/index.cjs +11 -7
- package/index.js +301 -285
- package/lib/base-php.d.ts +8 -0
- package/lib/encode-as-multipart.d.ts +10 -0
- package/lib/index.d.ts +1 -1
- package/lib/universal-php.d.ts +9 -22
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
1
|
+
var J = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var a = (e, t, r) => (
|
|
5
|
+
var a = (e, t, r) => (J(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
9
|
-
},
|
|
10
|
-
var f = (e, t, r) => (
|
|
9
|
+
}, h = (e, t, r, s) => (J(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var f = (e, t, r) => (J(e, t, "access private method"), r);
|
|
11
11
|
if (typeof File > "u") {
|
|
12
12
|
class e extends Blob {
|
|
13
|
-
constructor(r, s,
|
|
13
|
+
constructor(r, s, n) {
|
|
14
14
|
super(r);
|
|
15
|
-
let
|
|
16
|
-
|
|
15
|
+
let i;
|
|
16
|
+
n != null && n.lastModified && (i = /* @__PURE__ */ new Date()), (!i || isNaN(i.getFullYear())) && (i = /* @__PURE__ */ new Date()), this.lastModifiedDate = i, this.lastModified = i.getMilliseconds(), this.name = s || "";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
global.File = e;
|
|
@@ -50,7 +50,7 @@ function isByobSupported() {
|
|
|
50
50
|
// this if needed.
|
|
51
51
|
autoAllocateChunkSize: 512 * 1024,
|
|
52
52
|
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view,
|
|
53
|
+
const s = r.byobRequest.view, i = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(i);
|
|
54
54
|
new Uint8Array(s.buffer).set(o);
|
|
55
55
|
const l = o.byteLength;
|
|
56
56
|
r.byobRequest.respond(l), e += l, e >= t.size && r.close();
|
|
@@ -114,16 +114,16 @@ function improveWASMErrorReporting(e) {
|
|
|
114
114
|
for (const r in e.asm)
|
|
115
115
|
if (typeof e.asm[r] == "function") {
|
|
116
116
|
const s = e.asm[r];
|
|
117
|
-
e.asm[r] = function(...
|
|
118
|
-
var
|
|
117
|
+
e.asm[r] = function(...n) {
|
|
118
|
+
var i;
|
|
119
119
|
try {
|
|
120
|
-
return s(...
|
|
120
|
+
return s(...n);
|
|
121
121
|
} catch (o) {
|
|
122
122
|
if (!(o instanceof Error))
|
|
123
123
|
throw o;
|
|
124
124
|
const l = clarifyErrorMessage(
|
|
125
125
|
o,
|
|
126
|
-
(
|
|
126
|
+
(i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
|
|
127
127
|
);
|
|
128
128
|
if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
129
129
|
t.dispatchEvent(
|
|
@@ -266,20 +266,39 @@ function normalizePath(e) {
|
|
|
266
266
|
function normalizePathsArray(e, t) {
|
|
267
267
|
let r = 0;
|
|
268
268
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
269
|
-
const
|
|
270
|
-
|
|
269
|
+
const n = e[s];
|
|
270
|
+
n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
|
|
271
271
|
}
|
|
272
272
|
if (t)
|
|
273
273
|
for (; r; r--)
|
|
274
274
|
e.unshift("..");
|
|
275
275
|
return e;
|
|
276
276
|
}
|
|
277
|
+
function splitShellCommand(e) {
|
|
278
|
+
let s = 0, n = "";
|
|
279
|
+
const i = [];
|
|
280
|
+
let o = "";
|
|
281
|
+
for (let l = 0; l < e.length; l++) {
|
|
282
|
+
const c = e[l];
|
|
283
|
+
c === "\\" ? ((e[l + 1] === '"' || e[l + 1] === "'") && l++, o += e[l]) : s === 0 ? c === '"' || c === "'" ? (s = 1, n = c) : c.match(/\s/) ? (o.trim().length && i.push(o.trim()), o = c) : i.length && !o ? o = i.pop() + c : o += c : s === 1 && (c === n ? (s = 0, n = "") : o += c);
|
|
284
|
+
}
|
|
285
|
+
return o && i.push(o.trim()), i;
|
|
286
|
+
}
|
|
277
287
|
function createSpawnHandler(e) {
|
|
278
|
-
return function(t) {
|
|
279
|
-
const
|
|
288
|
+
return function(t, r = [], s = {}) {
|
|
289
|
+
const n = new ChildProcess(), i = new ProcessApi(n);
|
|
280
290
|
return setTimeout(async () => {
|
|
281
|
-
|
|
282
|
-
|
|
291
|
+
let o = [];
|
|
292
|
+
if (r.length)
|
|
293
|
+
o = [t, ...r];
|
|
294
|
+
else if (typeof t == "string")
|
|
295
|
+
o = splitShellCommand(t);
|
|
296
|
+
else if (Array.isArray(t))
|
|
297
|
+
o = t;
|
|
298
|
+
else
|
|
299
|
+
throw new Error("Invalid command ", t);
|
|
300
|
+
await e(o, i, s), n.emit("spawn", !0);
|
|
301
|
+
}), n;
|
|
283
302
|
};
|
|
284
303
|
}
|
|
285
304
|
class EventEmitter {
|
|
@@ -304,9 +323,15 @@ class ProcessApi extends EventEmitter {
|
|
|
304
323
|
stdout(t) {
|
|
305
324
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
306
325
|
}
|
|
326
|
+
stdoutEnd() {
|
|
327
|
+
this.childProcess.stdout.emit("end", {});
|
|
328
|
+
}
|
|
307
329
|
stderr(t) {
|
|
308
330
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
309
331
|
}
|
|
332
|
+
stderrEnd() {
|
|
333
|
+
this.childProcess.stderr.emit("end", {});
|
|
334
|
+
}
|
|
310
335
|
exit(t) {
|
|
311
336
|
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
312
337
|
}
|
|
@@ -331,7 +356,7 @@ class ChildProcess extends EventEmitter {
|
|
|
331
356
|
}
|
|
332
357
|
function concatUint8Array(...e) {
|
|
333
358
|
const t = new Uint8Array(
|
|
334
|
-
e.reduce((s,
|
|
359
|
+
e.reduce((s, n) => s + n.length, 0)
|
|
335
360
|
);
|
|
336
361
|
let r = 0;
|
|
337
362
|
for (const s of e)
|
|
@@ -365,22 +390,22 @@ function concatBytes(e) {
|
|
|
365
390
|
function limitBytes(e, t) {
|
|
366
391
|
if (t === 0)
|
|
367
392
|
return new ReadableStream({
|
|
368
|
-
start(
|
|
369
|
-
|
|
393
|
+
start(n) {
|
|
394
|
+
n.close();
|
|
370
395
|
}
|
|
371
396
|
});
|
|
372
397
|
const r = e.getReader({ mode: "byob" });
|
|
373
398
|
let s = 0;
|
|
374
399
|
return new ReadableStream({
|
|
375
|
-
async pull(
|
|
376
|
-
const { value:
|
|
400
|
+
async pull(n) {
|
|
401
|
+
const { value: i, done: o } = await r.read(
|
|
377
402
|
new Uint8Array(t - s)
|
|
378
403
|
);
|
|
379
404
|
if (o) {
|
|
380
|
-
r.releaseLock(),
|
|
405
|
+
r.releaseLock(), n.close();
|
|
381
406
|
return;
|
|
382
407
|
}
|
|
383
|
-
s +=
|
|
408
|
+
s += i.length, n.enqueue(i), s >= t && (r.releaseLock(), n.close());
|
|
384
409
|
},
|
|
385
410
|
cancel() {
|
|
386
411
|
r.cancel();
|
|
@@ -459,20 +484,20 @@ function streamReadFileFromPHP(e, t) {
|
|
|
459
484
|
async function* iteratePhpFiles(e, t, {
|
|
460
485
|
relativePaths: r = !0,
|
|
461
486
|
pathPrefix: s,
|
|
462
|
-
exceptPaths:
|
|
487
|
+
exceptPaths: n = []
|
|
463
488
|
} = {}) {
|
|
464
489
|
t = normalizePath(t);
|
|
465
|
-
const
|
|
466
|
-
for (;
|
|
467
|
-
const o =
|
|
490
|
+
const i = [t];
|
|
491
|
+
for (; i.length; ) {
|
|
492
|
+
const o = i.pop();
|
|
468
493
|
if (!o)
|
|
469
494
|
return;
|
|
470
495
|
const l = await e.listFiles(o);
|
|
471
|
-
for (const
|
|
472
|
-
const d = `${o}/${
|
|
473
|
-
if (
|
|
496
|
+
for (const c of l) {
|
|
497
|
+
const d = `${o}/${c}`;
|
|
498
|
+
if (n.includes(d.substring(t.length + 1)))
|
|
474
499
|
continue;
|
|
475
|
-
await e.isDir(d) ?
|
|
500
|
+
await e.isDir(d) ? i.push(d) : yield new StreamedFile(
|
|
476
501
|
streamReadFileFromPHP(e, d),
|
|
477
502
|
r ? joinPaths(
|
|
478
503
|
s || "",
|
|
@@ -494,8 +519,8 @@ function writeFilesStreamToPhp(e, t) {
|
|
|
494
519
|
});
|
|
495
520
|
}
|
|
496
521
|
class PHPResponse {
|
|
497
|
-
constructor(t, r, s,
|
|
498
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode =
|
|
522
|
+
constructor(t, r, s, n = "", i = 0) {
|
|
523
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
|
|
499
524
|
}
|
|
500
525
|
static fromRawData(t) {
|
|
501
526
|
return new PHPResponse(
|
|
@@ -546,16 +571,16 @@ const SupportedPHPVersions = [
|
|
|
546
571
|
], SupportedPHPExtensionBundles = {
|
|
547
572
|
"kitchen-sink": SupportedPHPExtensionsList
|
|
548
573
|
};
|
|
549
|
-
var E,
|
|
574
|
+
var E, b;
|
|
550
575
|
class PHPBrowser {
|
|
551
576
|
/**
|
|
552
577
|
* @param server - The PHP server to browse.
|
|
553
578
|
* @param config - The browser configuration.
|
|
554
579
|
*/
|
|
555
580
|
constructor(t, r = {}) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
this.requestHandler = t,
|
|
581
|
+
u(this, E, void 0);
|
|
582
|
+
u(this, b, void 0);
|
|
583
|
+
this.requestHandler = t, h(this, E, {}), h(this, b, {
|
|
559
584
|
handleRedirects: !1,
|
|
560
585
|
maxRedirects: 4,
|
|
561
586
|
...r
|
|
@@ -583,14 +608,14 @@ class PHPBrowser {
|
|
|
583
608
|
cookie: this.serializeCookies()
|
|
584
609
|
}
|
|
585
610
|
});
|
|
586
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this,
|
|
587
|
-
const
|
|
611
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this, b).handleRedirects && s.headers.location && r < a(this, b).maxRedirects) {
|
|
612
|
+
const n = new URL(
|
|
588
613
|
s.headers.location[0],
|
|
589
614
|
this.requestHandler.absoluteUrl
|
|
590
615
|
);
|
|
591
616
|
return this.request(
|
|
592
617
|
{
|
|
593
|
-
url:
|
|
618
|
+
url: n.toString(),
|
|
594
619
|
method: "GET",
|
|
595
620
|
headers: {}
|
|
596
621
|
},
|
|
@@ -620,8 +645,8 @@ class PHPBrowser {
|
|
|
620
645
|
try {
|
|
621
646
|
if (!r.includes("="))
|
|
622
647
|
continue;
|
|
623
|
-
const s = r.indexOf("="),
|
|
624
|
-
a(this, E)[
|
|
648
|
+
const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
|
|
649
|
+
a(this, E)[n] = i;
|
|
625
650
|
} catch (s) {
|
|
626
651
|
console.error(s);
|
|
627
652
|
}
|
|
@@ -633,7 +658,7 @@ class PHPBrowser {
|
|
|
633
658
|
return t.join("; ");
|
|
634
659
|
}
|
|
635
660
|
}
|
|
636
|
-
E = new WeakMap(),
|
|
661
|
+
E = new WeakMap(), b = new WeakMap();
|
|
637
662
|
const DEFAULT_BASE_URL = "http://example.com";
|
|
638
663
|
function toRelativeUrl(e) {
|
|
639
664
|
return e.toString().substring(e.origin.length);
|
|
@@ -644,7 +669,35 @@ function removePathPrefix(e, t) {
|
|
|
644
669
|
function ensurePathPrefix(e, t) {
|
|
645
670
|
return !t || e.startsWith(t) ? e : t + e;
|
|
646
671
|
}
|
|
647
|
-
|
|
672
|
+
async function encodeAsMultipart(e) {
|
|
673
|
+
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
674
|
+
for (const [c, d] of Object.entries(e))
|
|
675
|
+
n.push(`--${t}\r
|
|
676
|
+
`), n.push(`Content-Disposition: form-data; name="${c}"`), d instanceof File && n.push(`; filename="${d.name}"`), n.push(`\r
|
|
677
|
+
`), d instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
678
|
+
`)), n.push(`\r
|
|
679
|
+
`), d instanceof File ? n.push(await fileToUint8Array(d)) : n.push(d), n.push(`\r
|
|
680
|
+
`);
|
|
681
|
+
n.push(`--${t}--\r
|
|
682
|
+
`);
|
|
683
|
+
const i = n.reduce((c, d) => c + d.length, 0), o = new Uint8Array(i);
|
|
684
|
+
let l = 0;
|
|
685
|
+
for (const c of n)
|
|
686
|
+
o.set(
|
|
687
|
+
typeof c == "string" ? s.encode(c) : c,
|
|
688
|
+
l
|
|
689
|
+
), l += c.length;
|
|
690
|
+
return { bytes: o, contentType: r };
|
|
691
|
+
}
|
|
692
|
+
function fileToUint8Array(e) {
|
|
693
|
+
return new Promise((t) => {
|
|
694
|
+
const r = new FileReader();
|
|
695
|
+
r.onload = () => {
|
|
696
|
+
t(new Uint8Array(r.result));
|
|
697
|
+
}, r.readAsArrayBuffer(e);
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
var m, H, k, v, x, _, F, R, B, Y, I, Z, L, K;
|
|
648
701
|
class PHPRequestHandler {
|
|
649
702
|
/**
|
|
650
703
|
* @param php - The PHP instance.
|
|
@@ -657,7 +710,7 @@ class PHPRequestHandler {
|
|
|
657
710
|
* @param fsPath - Absolute path of the static file to serve.
|
|
658
711
|
* @returns The response.
|
|
659
712
|
*/
|
|
660
|
-
|
|
713
|
+
u(this, B);
|
|
661
714
|
/**
|
|
662
715
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
663
716
|
* superglobals populated.
|
|
@@ -665,7 +718,7 @@ class PHPRequestHandler {
|
|
|
665
718
|
* @param request - The request.
|
|
666
719
|
* @returns The response.
|
|
667
720
|
*/
|
|
668
|
-
|
|
721
|
+
u(this, I);
|
|
669
722
|
/**
|
|
670
723
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
671
724
|
*
|
|
@@ -675,31 +728,31 @@ class PHPRequestHandler {
|
|
|
675
728
|
* @throws {Error} If the requested path doesn't exist.
|
|
676
729
|
* @returns The resolved filesystem path.
|
|
677
730
|
*/
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
731
|
+
u(this, L);
|
|
732
|
+
u(this, m, void 0);
|
|
733
|
+
u(this, H, void 0);
|
|
734
|
+
u(this, k, void 0);
|
|
735
|
+
u(this, v, void 0);
|
|
736
|
+
u(this, x, void 0);
|
|
737
|
+
u(this, _, void 0);
|
|
738
|
+
u(this, F, void 0);
|
|
739
|
+
u(this, R, void 0);
|
|
740
|
+
h(this, R, new Semaphore({ concurrency: 1 }));
|
|
688
741
|
const {
|
|
689
742
|
documentRoot: s = "/www/",
|
|
690
|
-
absoluteUrl:
|
|
743
|
+
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
691
744
|
} = r;
|
|
692
|
-
this.php = t,
|
|
693
|
-
const
|
|
694
|
-
|
|
745
|
+
this.php = t, h(this, m, s);
|
|
746
|
+
const i = new URL(n);
|
|
747
|
+
h(this, k, i.hostname), h(this, v, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), h(this, H, (i.protocol || "").replace(":", ""));
|
|
695
748
|
const o = a(this, v) !== 443 && a(this, v) !== 80;
|
|
696
|
-
|
|
697
|
-
a(this,
|
|
749
|
+
h(this, x, [
|
|
750
|
+
a(this, k),
|
|
698
751
|
o ? `:${a(this, v)}` : ""
|
|
699
|
-
].join("")),
|
|
700
|
-
`${a(this,
|
|
701
|
-
a(this,
|
|
702
|
-
a(this,
|
|
752
|
+
].join("")), h(this, _, i.pathname.replace(/\/+$/, "")), h(this, F, [
|
|
753
|
+
`${a(this, H)}://`,
|
|
754
|
+
a(this, x),
|
|
755
|
+
a(this, _)
|
|
703
756
|
].join(""));
|
|
704
757
|
}
|
|
705
758
|
/** @inheritDoc */
|
|
@@ -709,32 +762,32 @@ class PHPRequestHandler {
|
|
|
709
762
|
/** @inheritDoc */
|
|
710
763
|
internalUrlToPath(t) {
|
|
711
764
|
const r = new URL(t);
|
|
712
|
-
return r.pathname.startsWith(a(this,
|
|
765
|
+
return r.pathname.startsWith(a(this, _)) && (r.pathname = r.pathname.slice(a(this, _).length)), toRelativeUrl(r);
|
|
713
766
|
}
|
|
714
767
|
get isRequestRunning() {
|
|
715
768
|
return a(this, R).running > 0;
|
|
716
769
|
}
|
|
717
770
|
/** @inheritDoc */
|
|
718
771
|
get absoluteUrl() {
|
|
719
|
-
return a(this,
|
|
772
|
+
return a(this, F);
|
|
720
773
|
}
|
|
721
774
|
/** @inheritDoc */
|
|
722
775
|
get documentRoot() {
|
|
723
|
-
return a(this,
|
|
776
|
+
return a(this, m);
|
|
724
777
|
}
|
|
725
778
|
/** @inheritDoc */
|
|
726
779
|
async request(t) {
|
|
727
780
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
728
781
|
t.url,
|
|
729
782
|
r ? void 0 : DEFAULT_BASE_URL
|
|
730
|
-
),
|
|
783
|
+
), n = removePathPrefix(
|
|
731
784
|
s.pathname,
|
|
732
|
-
a(this,
|
|
733
|
-
),
|
|
734
|
-
return seemsLikeAPHPRequestHandlerPath(
|
|
785
|
+
a(this, _)
|
|
786
|
+
), i = `${a(this, m)}${n}`;
|
|
787
|
+
return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, I, Z).call(this, t, s) : f(this, B, Y).call(this, i);
|
|
735
788
|
}
|
|
736
789
|
}
|
|
737
|
-
|
|
790
|
+
m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x = new WeakMap(), _ = new WeakMap(), F = new WeakMap(), R = new WeakMap(), B = new WeakSet(), Y = function(t) {
|
|
738
791
|
if (!this.php.fileExists(t))
|
|
739
792
|
return new PHPResponse(
|
|
740
793
|
404,
|
|
@@ -759,9 +812,9 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
|
|
|
759
812
|
},
|
|
760
813
|
r
|
|
761
814
|
);
|
|
762
|
-
},
|
|
763
|
-
var
|
|
764
|
-
if (a(this, R).running > 0 && ((
|
|
815
|
+
}, I = new WeakSet(), Z = async function(t, r) {
|
|
816
|
+
var n, i;
|
|
817
|
+
if (a(this, R).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
765
818
|
return console.warn(
|
|
766
819
|
"Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
|
|
767
820
|
), new PHPResponse(
|
|
@@ -771,45 +824,32 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
|
|
|
771
824
|
);
|
|
772
825
|
const s = await a(this, R).acquire();
|
|
773
826
|
try {
|
|
774
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this,
|
|
827
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, m)), this.php.addServerGlobalEntry(
|
|
775
828
|
"HTTPS",
|
|
776
|
-
a(this,
|
|
829
|
+
a(this, F).startsWith("https://") ? "on" : ""
|
|
777
830
|
);
|
|
778
|
-
let
|
|
779
|
-
const
|
|
780
|
-
host: a(this,
|
|
831
|
+
let o = "GET";
|
|
832
|
+
const l = {
|
|
833
|
+
host: a(this, x),
|
|
781
834
|
...normalizeHeaders(t.headers || {})
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
key: S,
|
|
789
|
-
name: U.name,
|
|
790
|
-
type: U.type,
|
|
791
|
-
data: new Uint8Array(await U.arrayBuffer())
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
(n = h["content-type"]) != null && n.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
|
|
795
|
-
t.body || ""
|
|
796
|
-
), h["content-type"] = "application/x-www-form-urlencoded", delete t.body);
|
|
835
|
+
};
|
|
836
|
+
let c = t.body;
|
|
837
|
+
if (typeof c == "object" && !(c instanceof Uint8Array)) {
|
|
838
|
+
o = "POST";
|
|
839
|
+
const { bytes: p, contentType: U } = await encodeAsMultipart(c);
|
|
840
|
+
c = p, l["content-type"] = U;
|
|
797
841
|
}
|
|
798
|
-
let
|
|
799
|
-
t.formData !== void 0 ? (l = "POST", h["content-type"] = h["content-type"] || "application/x-www-form-urlencoded", p = new URLSearchParams(
|
|
800
|
-
t.formData
|
|
801
|
-
).toString()) : p = t.body;
|
|
802
|
-
let I;
|
|
842
|
+
let d;
|
|
803
843
|
try {
|
|
804
|
-
let
|
|
805
|
-
if ((
|
|
844
|
+
let p = r.pathname;
|
|
845
|
+
if ((i = t.headers) != null && i["x-rewrite-url"])
|
|
806
846
|
try {
|
|
807
|
-
|
|
847
|
+
p = new URL(
|
|
808
848
|
t.headers["x-rewrite-url"]
|
|
809
849
|
).pathname;
|
|
810
850
|
} catch {
|
|
811
851
|
}
|
|
812
|
-
|
|
852
|
+
d = f(this, L, K).call(this, p);
|
|
813
853
|
} catch {
|
|
814
854
|
return new PHPResponse(
|
|
815
855
|
404,
|
|
@@ -820,41 +860,25 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
|
|
|
820
860
|
return await this.php.run({
|
|
821
861
|
relativeUri: ensurePathPrefix(
|
|
822
862
|
toRelativeUrl(r),
|
|
823
|
-
a(this,
|
|
863
|
+
a(this, _)
|
|
824
864
|
),
|
|
825
|
-
protocol: a(this,
|
|
826
|
-
method: t.method ||
|
|
827
|
-
body:
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
headers: h
|
|
865
|
+
protocol: a(this, H),
|
|
866
|
+
method: t.method || o,
|
|
867
|
+
body: c,
|
|
868
|
+
scriptPath: d,
|
|
869
|
+
headers: l
|
|
831
870
|
});
|
|
832
871
|
} finally {
|
|
833
872
|
s();
|
|
834
873
|
}
|
|
835
|
-
},
|
|
836
|
-
let r = removePathPrefix(t, a(this,
|
|
837
|
-
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r
|
|
838
|
-
const s = `${a(this,
|
|
874
|
+
}, L = new WeakSet(), K = function(t) {
|
|
875
|
+
let r = removePathPrefix(t, a(this, _));
|
|
876
|
+
r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${a(this, m)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
|
|
877
|
+
const s = `${a(this, m)}${r}`;
|
|
839
878
|
if (this.php.fileExists(s))
|
|
840
879
|
return s;
|
|
841
880
|
throw new Error(`File not found: ${s}`);
|
|
842
881
|
};
|
|
843
|
-
function parseMultipartFormDataString(e) {
|
|
844
|
-
const t = {}, r = e.match(/--(.*)\r\n/);
|
|
845
|
-
if (!r)
|
|
846
|
-
return t;
|
|
847
|
-
const s = r[1], i = e.split(`--${s}`);
|
|
848
|
-
return i.shift(), i.pop(), i.forEach((n) => {
|
|
849
|
-
const o = n.indexOf(`\r
|
|
850
|
-
\r
|
|
851
|
-
`), l = n.substring(0, o).trim(), h = n.substring(o + 4).trim(), d = l.match(/name="([^"]+)"/);
|
|
852
|
-
if (d) {
|
|
853
|
-
const p = d[1];
|
|
854
|
-
t[p] = h;
|
|
855
|
-
}
|
|
856
|
-
}), t;
|
|
857
|
-
}
|
|
858
882
|
function inferMimeType(e) {
|
|
859
883
|
switch (e.split(".").pop()) {
|
|
860
884
|
case "css":
|
|
@@ -989,16 +1013,16 @@ function getEmscriptenFsError(e) {
|
|
|
989
1013
|
return FileErrorCodes[t];
|
|
990
1014
|
}
|
|
991
1015
|
function rethrowFileSystemError(e = "") {
|
|
992
|
-
return function(r, s,
|
|
993
|
-
const
|
|
994
|
-
|
|
1016
|
+
return function(r, s, n) {
|
|
1017
|
+
const i = n.value;
|
|
1018
|
+
n.value = function(...o) {
|
|
995
1019
|
try {
|
|
996
|
-
return
|
|
1020
|
+
return i.apply(this, o);
|
|
997
1021
|
} catch (l) {
|
|
998
|
-
const
|
|
999
|
-
if (
|
|
1000
|
-
const d = FileErrorCodes[
|
|
1001
|
-
throw new Error(`${
|
|
1022
|
+
const c = typeof l == "object" ? l == null ? void 0 : l.errno : null;
|
|
1023
|
+
if (c in FileErrorCodes) {
|
|
1024
|
+
const d = FileErrorCodes[c], p = typeof o[0] == "string" ? o[0] : null, U = p !== null ? e.replaceAll("{path}", p) : e;
|
|
1025
|
+
throw new Error(`${U}: ${d}`, {
|
|
1002
1026
|
cause: l
|
|
1003
1027
|
});
|
|
1004
1028
|
}
|
|
@@ -1010,9 +1034,9 @@ function rethrowFileSystemError(e = "") {
|
|
|
1010
1034
|
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
1011
1035
|
let lastRuntimeId = 0;
|
|
1012
1036
|
async function loadPHPRuntime(e, t = {}) {
|
|
1013
|
-
const [r, s,
|
|
1037
|
+
const [r, s, n] = makePromise(), i = e.init(currentJsRuntime, {
|
|
1014
1038
|
onAbort(l) {
|
|
1015
|
-
|
|
1039
|
+
n(l), console.error(l);
|
|
1016
1040
|
},
|
|
1017
1041
|
ENV: {},
|
|
1018
1042
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
@@ -1027,9 +1051,9 @@ async function loadPHPRuntime(e, t = {}) {
|
|
|
1027
1051
|
});
|
|
1028
1052
|
await r;
|
|
1029
1053
|
const o = ++lastRuntimeId;
|
|
1030
|
-
return
|
|
1031
|
-
return loadedRuntimes.delete(o),
|
|
1032
|
-
},
|
|
1054
|
+
return i.id = o, i.originalExit = i._exit, i._exit = function(l) {
|
|
1055
|
+
return loadedRuntimes.delete(o), i.originalExit(l);
|
|
1056
|
+
}, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
|
|
1033
1057
|
}
|
|
1034
1058
|
function getLoadedRuntime(e) {
|
|
1035
1059
|
return loadedRuntimes.get(e);
|
|
@@ -1044,12 +1068,12 @@ const currentJsRuntime = function() {
|
|
|
1044
1068
|
return e.unshift(t), e;
|
|
1045
1069
|
};
|
|
1046
1070
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
1047
|
-
for (var
|
|
1048
|
-
(o = e[
|
|
1049
|
-
return s &&
|
|
1071
|
+
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
|
|
1072
|
+
(o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
|
|
1073
|
+
return s && n && __defProp(t, r, n), n;
|
|
1050
1074
|
};
|
|
1051
1075
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
1052
|
-
var
|
|
1076
|
+
var S, T, A, y, w, g, P, C, N, X, M, ee, q, te, O, re, $, se, D, ne, j, ie, z, oe, W, ae, G, le, V, ce, Q, ue;
|
|
1053
1077
|
class BasePHP {
|
|
1054
1078
|
/**
|
|
1055
1079
|
* Initializes a PHP runtime.
|
|
@@ -1059,55 +1083,46 @@ class BasePHP {
|
|
|
1059
1083
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
1060
1084
|
*/
|
|
1061
1085
|
constructor(e, t) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
c(this, b, void 0);
|
|
1084
|
-
c(this, C, void 0);
|
|
1085
|
-
c(this, k, void 0);
|
|
1086
|
-
c(this, _, void 0);
|
|
1087
|
-
c(this, w, void 0);
|
|
1088
|
-
c(this, g, void 0);
|
|
1089
|
-
c(this, y, void 0);
|
|
1090
|
-
c(this, B, void 0);
|
|
1091
|
-
u(this, b, []), u(this, _, !1), u(this, w, null), u(this, g, {}), u(this, y, /* @__PURE__ */ new Map()), u(this, B, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
1086
|
+
u(this, N);
|
|
1087
|
+
u(this, M);
|
|
1088
|
+
u(this, q);
|
|
1089
|
+
u(this, O);
|
|
1090
|
+
u(this, $);
|
|
1091
|
+
u(this, D);
|
|
1092
|
+
u(this, j);
|
|
1093
|
+
u(this, z);
|
|
1094
|
+
u(this, W);
|
|
1095
|
+
u(this, G);
|
|
1096
|
+
u(this, V);
|
|
1097
|
+
u(this, Q);
|
|
1098
|
+
u(this, S, void 0);
|
|
1099
|
+
u(this, T, void 0);
|
|
1100
|
+
u(this, A, void 0);
|
|
1101
|
+
u(this, y, void 0);
|
|
1102
|
+
u(this, w, void 0);
|
|
1103
|
+
u(this, g, void 0);
|
|
1104
|
+
u(this, P, void 0);
|
|
1105
|
+
u(this, C, void 0);
|
|
1106
|
+
h(this, S, []), h(this, y, !1), h(this, w, null), h(this, g, {}), h(this, P, /* @__PURE__ */ new Map()), h(this, C, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
1092
1107
|
new PHPRequestHandler(this, t)
|
|
1093
1108
|
));
|
|
1094
1109
|
}
|
|
1095
1110
|
addEventListener(e, t) {
|
|
1096
|
-
a(this,
|
|
1111
|
+
a(this, P).has(e) || a(this, P).set(e, /* @__PURE__ */ new Set()), a(this, P).get(e).add(t);
|
|
1097
1112
|
}
|
|
1098
1113
|
removeEventListener(e, t) {
|
|
1099
1114
|
var r;
|
|
1100
|
-
(r = a(this,
|
|
1115
|
+
(r = a(this, P).get(e)) == null || r.delete(t);
|
|
1101
1116
|
}
|
|
1102
1117
|
dispatchEvent(e) {
|
|
1103
|
-
const t = a(this,
|
|
1118
|
+
const t = a(this, P).get(e.type);
|
|
1104
1119
|
if (t)
|
|
1105
1120
|
for (const r of t)
|
|
1106
1121
|
r(e);
|
|
1107
1122
|
}
|
|
1108
1123
|
/** @inheritDoc */
|
|
1109
1124
|
async onMessage(e) {
|
|
1110
|
-
a(this,
|
|
1125
|
+
a(this, C).push(e);
|
|
1111
1126
|
}
|
|
1112
1127
|
/** @inheritDoc */
|
|
1113
1128
|
async setSpawnHandler(handler) {
|
|
@@ -1138,13 +1153,13 @@ class BasePHP {
|
|
|
1138
1153
|
if (!t)
|
|
1139
1154
|
throw new Error("Invalid PHP runtime id.");
|
|
1140
1155
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
1141
|
-
for (const s of a(this,
|
|
1142
|
-
const
|
|
1143
|
-
if (
|
|
1144
|
-
return
|
|
1156
|
+
for (const s of a(this, C)) {
|
|
1157
|
+
const n = await s(r);
|
|
1158
|
+
if (n)
|
|
1159
|
+
return n;
|
|
1145
1160
|
}
|
|
1146
1161
|
return "";
|
|
1147
|
-
},
|
|
1162
|
+
}, h(this, w, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
1148
1163
|
type: "runtime.initialized"
|
|
1149
1164
|
});
|
|
1150
1165
|
}
|
|
@@ -1159,13 +1174,13 @@ class BasePHP {
|
|
|
1159
1174
|
throw new Error(
|
|
1160
1175
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1161
1176
|
);
|
|
1162
|
-
|
|
1177
|
+
h(this, A, e);
|
|
1163
1178
|
}
|
|
1164
1179
|
/** @inheritDoc */
|
|
1165
1180
|
setPhpIniPath(e) {
|
|
1166
|
-
if (a(this,
|
|
1181
|
+
if (a(this, y))
|
|
1167
1182
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1168
|
-
|
|
1183
|
+
h(this, T, e), this[__private__dont__use].ccall(
|
|
1169
1184
|
"wasm_set_phpini_path",
|
|
1170
1185
|
null,
|
|
1171
1186
|
["string"],
|
|
@@ -1174,9 +1189,9 @@ class BasePHP {
|
|
|
1174
1189
|
}
|
|
1175
1190
|
/** @inheritDoc */
|
|
1176
1191
|
setPhpIniEntry(e, t) {
|
|
1177
|
-
if (a(this,
|
|
1192
|
+
if (a(this, y))
|
|
1178
1193
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1179
|
-
a(this,
|
|
1194
|
+
a(this, S).push([e, t]);
|
|
1180
1195
|
}
|
|
1181
1196
|
/** @inheritDoc */
|
|
1182
1197
|
chdir(e) {
|
|
@@ -1193,25 +1208,29 @@ class BasePHP {
|
|
|
1193
1208
|
const t = await this.semaphore.acquire();
|
|
1194
1209
|
let r;
|
|
1195
1210
|
try {
|
|
1196
|
-
a(this,
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1211
|
+
if (a(this, y) || (f(this, N, X).call(this), h(this, y, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
`The script path "${e.scriptPath}" does not exist.`
|
|
1214
|
+
);
|
|
1215
|
+
f(this, z, oe).call(this, e.scriptPath || ""), f(this, q, te).call(this, e.relativeUri || ""), f(this, $, se).call(this, e.method || "GET");
|
|
1216
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1217
|
+
f(this, O, re).call(this, n, e.protocol || "http"), f(this, D, ne).call(this, s), e.body && (r = f(this, j, ie).call(this, e.body)), typeof e.code == "string" && f(this, V, ce).call(this, " ?>" + e.code), f(this, W, ae).call(this);
|
|
1218
|
+
const i = e.env || {};
|
|
1219
|
+
for (const l in i)
|
|
1220
|
+
f(this, G, le).call(this, l, i[l]);
|
|
1221
|
+
const o = await f(this, Q, ue).call(this);
|
|
1222
|
+
if (e.throwOnError && o.exitCode !== 0) {
|
|
1223
|
+
const l = {
|
|
1224
|
+
stdout: o.text,
|
|
1225
|
+
stderr: o.errors
|
|
1207
1226
|
};
|
|
1208
|
-
console.warn("PHP.run() output was:",
|
|
1209
|
-
const
|
|
1210
|
-
`PHP.run() failed with exit code ${
|
|
1227
|
+
console.warn("PHP.run() output was:", l);
|
|
1228
|
+
const c = new Error(
|
|
1229
|
+
`PHP.run() failed with exit code ${o.exitCode} and the following output: ` + o.errors
|
|
1211
1230
|
);
|
|
1212
|
-
throw
|
|
1231
|
+
throw c.output = l, console.error(c), c;
|
|
1213
1232
|
}
|
|
1214
|
-
return
|
|
1233
|
+
return o;
|
|
1215
1234
|
} finally {
|
|
1216
1235
|
try {
|
|
1217
1236
|
r && this[__private__dont__use].free(r);
|
|
@@ -1229,12 +1248,12 @@ class BasePHP {
|
|
|
1229
1248
|
let r = {};
|
|
1230
1249
|
try {
|
|
1231
1250
|
r = JSON.parse(
|
|
1232
|
-
this.fileExists("/
|
|
1251
|
+
this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
|
|
1233
1252
|
);
|
|
1234
1253
|
} catch {
|
|
1235
1254
|
}
|
|
1236
1255
|
this.writeFile(
|
|
1237
|
-
"/
|
|
1256
|
+
"/internal/consts.json",
|
|
1238
1257
|
JSON.stringify({
|
|
1239
1258
|
...r,
|
|
1240
1259
|
[e]: t
|
|
@@ -1288,7 +1307,7 @@ class BasePHP {
|
|
|
1288
1307
|
);
|
|
1289
1308
|
if (t.prependPath) {
|
|
1290
1309
|
const s = e.replace(/\/$/, "");
|
|
1291
|
-
return r.map((
|
|
1310
|
+
return r.map((n) => `${s}/${n}`);
|
|
1292
1311
|
}
|
|
1293
1312
|
return r;
|
|
1294
1313
|
} catch (r) {
|
|
@@ -1319,9 +1338,9 @@ class BasePHP {
|
|
|
1319
1338
|
this.exit();
|
|
1320
1339
|
} catch {
|
|
1321
1340
|
}
|
|
1322
|
-
if (this.initializeRuntime(e), a(this,
|
|
1341
|
+
if (this.initializeRuntime(e), a(this, T) && this.setPhpIniPath(a(this, T)), a(this, A) && this.setSapiName(a(this, A)), this.requestHandler) {
|
|
1323
1342
|
const r = this.documentRoot;
|
|
1324
|
-
|
|
1343
|
+
copyFS(t, this[__private__dont__use].FS, r);
|
|
1325
1344
|
}
|
|
1326
1345
|
}
|
|
1327
1346
|
exit(e = 0) {
|
|
@@ -1332,23 +1351,23 @@ class BasePHP {
|
|
|
1332
1351
|
this[__private__dont__use]._exit(e);
|
|
1333
1352
|
} catch {
|
|
1334
1353
|
}
|
|
1335
|
-
|
|
1354
|
+
h(this, y, !1), h(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1336
1355
|
}
|
|
1337
1356
|
}
|
|
1338
|
-
|
|
1339
|
-
if (this.setPhpIniEntry("auto_prepend_file", "/
|
|
1340
|
-
"/
|
|
1357
|
+
S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), P = new WeakMap(), C = new WeakMap(), N = new WeakSet(), X = function() {
|
|
1358
|
+
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1359
|
+
"/internal/consts.php",
|
|
1341
1360
|
`<?php
|
|
1342
|
-
if(file_exists('/
|
|
1343
|
-
$consts = json_decode(file_get_contents('/
|
|
1361
|
+
if(file_exists('/internal/consts.json')) {
|
|
1362
|
+
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
1344
1363
|
foreach ($consts as $const => $value) {
|
|
1345
1364
|
if (!defined($const) && is_scalar($value)) {
|
|
1346
1365
|
define($const, $value);
|
|
1347
1366
|
}
|
|
1348
1367
|
}
|
|
1349
1368
|
}`
|
|
1350
|
-
), a(this,
|
|
1351
|
-
const e = a(this,
|
|
1369
|
+
), a(this, S).length > 0) {
|
|
1370
|
+
const e = a(this, S).map(([t, r]) => `${t}=${r}`).join(`
|
|
1352
1371
|
`) + `
|
|
1353
1372
|
|
|
1354
1373
|
`;
|
|
@@ -1360,8 +1379,8 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1360
1379
|
);
|
|
1361
1380
|
}
|
|
1362
1381
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1363
|
-
},
|
|
1364
|
-
const e = "/
|
|
1382
|
+
}, M = new WeakSet(), ee = function() {
|
|
1383
|
+
const e = "/internal/headers.json";
|
|
1365
1384
|
if (!this.fileExists(e))
|
|
1366
1385
|
throw new Error(
|
|
1367
1386
|
"SAPI Error: Could not find response headers file."
|
|
@@ -1370,14 +1389,14 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1370
1389
|
for (const s of t.headers) {
|
|
1371
1390
|
if (!s.includes(": "))
|
|
1372
1391
|
continue;
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1392
|
+
const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
|
|
1393
|
+
i in r || (r[i] = []), r[i].push(o);
|
|
1375
1394
|
}
|
|
1376
1395
|
return {
|
|
1377
1396
|
headers: r,
|
|
1378
1397
|
httpStatusCode: t.status
|
|
1379
1398
|
};
|
|
1380
|
-
},
|
|
1399
|
+
}, q = new WeakSet(), te = function(e) {
|
|
1381
1400
|
if (this[__private__dont__use].ccall(
|
|
1382
1401
|
"wasm_set_request_uri",
|
|
1383
1402
|
null,
|
|
@@ -1392,7 +1411,7 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1392
1411
|
[t]
|
|
1393
1412
|
);
|
|
1394
1413
|
}
|
|
1395
|
-
},
|
|
1414
|
+
}, O = new WeakSet(), re = function(e, t) {
|
|
1396
1415
|
this[__private__dont__use].ccall(
|
|
1397
1416
|
"wasm_set_request_host",
|
|
1398
1417
|
null,
|
|
@@ -1410,14 +1429,14 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1410
1429
|
[NUMBER],
|
|
1411
1430
|
[r]
|
|
1412
1431
|
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1413
|
-
},
|
|
1432
|
+
}, $ = new WeakSet(), se = function(e) {
|
|
1414
1433
|
this[__private__dont__use].ccall(
|
|
1415
1434
|
"wasm_set_request_method",
|
|
1416
1435
|
null,
|
|
1417
1436
|
[STRING],
|
|
1418
1437
|
[e]
|
|
1419
1438
|
);
|
|
1420
|
-
},
|
|
1439
|
+
}, D = new WeakSet(), ne = function(e) {
|
|
1421
1440
|
e.cookie && this[__private__dont__use].ccall(
|
|
1422
1441
|
"wasm_set_cookies",
|
|
1423
1442
|
null,
|
|
@@ -1441,33 +1460,37 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1441
1460
|
e[t]
|
|
1442
1461
|
);
|
|
1443
1462
|
}
|
|
1444
|
-
},
|
|
1445
|
-
|
|
1446
|
-
|
|
1463
|
+
}, j = new WeakSet(), ie = function(e) {
|
|
1464
|
+
let t, r;
|
|
1465
|
+
typeof e == "string" ? (console.warn(
|
|
1466
|
+
"Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
|
|
1467
|
+
), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
|
|
1468
|
+
const s = this[__private__dont__use].malloc(t);
|
|
1469
|
+
if (!s)
|
|
1447
1470
|
throw new Error("Could not allocate memory for the request body.");
|
|
1448
|
-
return this[__private__dont__use].stringToUTF8(
|
|
1471
|
+
return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
|
|
1449
1472
|
e,
|
|
1450
|
-
|
|
1473
|
+
s,
|
|
1451
1474
|
t + 1
|
|
1452
|
-
), this[__private__dont__use].ccall(
|
|
1475
|
+
) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
|
|
1453
1476
|
"wasm_set_request_body",
|
|
1454
1477
|
null,
|
|
1455
1478
|
[NUMBER],
|
|
1456
|
-
[
|
|
1479
|
+
[s]
|
|
1457
1480
|
), this[__private__dont__use].ccall(
|
|
1458
1481
|
"wasm_set_content_length",
|
|
1459
1482
|
null,
|
|
1460
1483
|
[NUMBER],
|
|
1461
|
-
[
|
|
1462
|
-
),
|
|
1463
|
-
},
|
|
1484
|
+
[r]
|
|
1485
|
+
), s;
|
|
1486
|
+
}, z = new WeakSet(), oe = function(e) {
|
|
1464
1487
|
this[__private__dont__use].ccall(
|
|
1465
1488
|
"wasm_set_path_translated",
|
|
1466
1489
|
null,
|
|
1467
1490
|
[STRING],
|
|
1468
1491
|
[e]
|
|
1469
1492
|
);
|
|
1470
|
-
},
|
|
1493
|
+
}, W = new WeakSet(), ae = function() {
|
|
1471
1494
|
for (const e in a(this, g))
|
|
1472
1495
|
this[__private__dont__use].ccall(
|
|
1473
1496
|
"wasm_add_SERVER_entry",
|
|
@@ -1475,33 +1498,31 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1475
1498
|
[STRING, STRING],
|
|
1476
1499
|
[e, a(this, g)[e]]
|
|
1477
1500
|
);
|
|
1478
|
-
},
|
|
1479
|
-
const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
|
|
1480
|
-
this.writeFile(n, i);
|
|
1481
|
-
const o = 0;
|
|
1501
|
+
}, G = new WeakSet(), le = function(e, t) {
|
|
1482
1502
|
this[__private__dont__use].ccall(
|
|
1483
|
-
"
|
|
1503
|
+
"wasm_add_ENV_entry",
|
|
1484
1504
|
null,
|
|
1485
|
-
[STRING, STRING
|
|
1486
|
-
[
|
|
1505
|
+
[STRING, STRING],
|
|
1506
|
+
[e, t]
|
|
1487
1507
|
);
|
|
1488
|
-
},
|
|
1508
|
+
}, V = new WeakSet(), ce = function(e) {
|
|
1489
1509
|
this[__private__dont__use].ccall(
|
|
1490
1510
|
"wasm_set_php_code",
|
|
1491
1511
|
null,
|
|
1492
1512
|
[STRING],
|
|
1493
1513
|
[e]
|
|
1494
1514
|
);
|
|
1495
|
-
},
|
|
1496
|
-
var
|
|
1515
|
+
}, Q = new WeakSet(), ue = async function() {
|
|
1516
|
+
var n;
|
|
1497
1517
|
let e, t;
|
|
1498
1518
|
try {
|
|
1499
|
-
e = await new Promise((
|
|
1500
|
-
var
|
|
1519
|
+
e = await new Promise((i, o) => {
|
|
1520
|
+
var c;
|
|
1501
1521
|
t = (d) => {
|
|
1522
|
+
console.error(d), console.error(d.error);
|
|
1502
1523
|
const p = new Error("Rethrown");
|
|
1503
1524
|
p.cause = d.error, p.betterMessage = d.message, o(p);
|
|
1504
|
-
}, (
|
|
1525
|
+
}, (c = a(this, w)) == null || c.addEventListener(
|
|
1505
1526
|
"error",
|
|
1506
1527
|
t
|
|
1507
1528
|
);
|
|
@@ -1512,9 +1533,9 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1512
1533
|
[],
|
|
1513
1534
|
{ async: !0 }
|
|
1514
1535
|
);
|
|
1515
|
-
return l instanceof Promise ? l.then(
|
|
1536
|
+
return l instanceof Promise ? l.then(i, o) : i(l);
|
|
1516
1537
|
});
|
|
1517
|
-
} catch (
|
|
1538
|
+
} catch (i) {
|
|
1518
1539
|
for (const d in this)
|
|
1519
1540
|
typeof this[d] == "function" && (this[d] = () => {
|
|
1520
1541
|
throw new Error(
|
|
@@ -1522,17 +1543,17 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
|
|
|
1522
1543
|
);
|
|
1523
1544
|
});
|
|
1524
1545
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1525
|
-
const o =
|
|
1526
|
-
throw
|
|
1546
|
+
const o = i, l = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(l);
|
|
1547
|
+
throw c.cause = o, console.error(c), c;
|
|
1527
1548
|
} finally {
|
|
1528
|
-
(
|
|
1549
|
+
(n = a(this, w)) == null || n.removeEventListener("error", t), h(this, g, {});
|
|
1529
1550
|
}
|
|
1530
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1551
|
+
const { headers: r, httpStatusCode: s } = f(this, M, ee).call(this);
|
|
1531
1552
|
return new PHPResponse(
|
|
1532
1553
|
s,
|
|
1533
1554
|
r,
|
|
1534
|
-
this.readFileAsBuffer("/
|
|
1535
|
-
this.readFileAsText("/
|
|
1555
|
+
this.readFileAsBuffer("/internal/stdout"),
|
|
1556
|
+
this.readFileAsText("/internal/stderr"),
|
|
1536
1557
|
e
|
|
1537
1558
|
);
|
|
1538
1559
|
};
|
|
@@ -1572,28 +1593,23 @@ function normalizeHeaders(e) {
|
|
|
1572
1593
|
t[r.toLowerCase()] = e[r];
|
|
1573
1594
|
return t;
|
|
1574
1595
|
}
|
|
1575
|
-
function
|
|
1596
|
+
function copyFS(e, t, r) {
|
|
1576
1597
|
let s;
|
|
1577
1598
|
try {
|
|
1578
|
-
s =
|
|
1599
|
+
s = e.lookupPath(r);
|
|
1579
1600
|
} catch {
|
|
1580
1601
|
return;
|
|
1581
1602
|
}
|
|
1582
1603
|
if (!("contents" in s.node))
|
|
1583
1604
|
return;
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
return;
|
|
1587
|
-
} catch {
|
|
1588
|
-
}
|
|
1589
|
-
if (!t.isDir(s.node.mode)) {
|
|
1590
|
-
e.writeFile(r, t.readFile(r));
|
|
1605
|
+
if (!e.isDir(s.node.mode)) {
|
|
1606
|
+
t.writeFile(r, e.readFile(r));
|
|
1591
1607
|
return;
|
|
1592
1608
|
}
|
|
1593
|
-
|
|
1594
|
-
const
|
|
1595
|
-
for (const
|
|
1596
|
-
|
|
1609
|
+
t.mkdirTree(r);
|
|
1610
|
+
const n = e.readdir(r).filter((i) => i !== "." && i !== "..");
|
|
1611
|
+
for (const i of n)
|
|
1612
|
+
copyFS(e, t, joinPaths(r, i));
|
|
1597
1613
|
}
|
|
1598
1614
|
function isLocalPHP(e) {
|
|
1599
1615
|
return !(e instanceof BasePHP);
|
|
@@ -1607,26 +1623,26 @@ function rotatePHPRuntime({
|
|
|
1607
1623
|
maxRequests: r
|
|
1608
1624
|
}) {
|
|
1609
1625
|
let s = 0;
|
|
1610
|
-
async function
|
|
1626
|
+
async function n() {
|
|
1611
1627
|
if (++s < r)
|
|
1612
1628
|
return;
|
|
1613
1629
|
s = 0;
|
|
1614
|
-
const
|
|
1630
|
+
const i = await e.semaphore.acquire();
|
|
1615
1631
|
try {
|
|
1616
1632
|
e.hotSwapPHPRuntime(await t());
|
|
1617
1633
|
} finally {
|
|
1618
|
-
|
|
1634
|
+
i();
|
|
1619
1635
|
}
|
|
1620
1636
|
}
|
|
1621
|
-
return e.addEventListener("request.end",
|
|
1622
|
-
e.removeEventListener("request.end",
|
|
1637
|
+
return e.addEventListener("request.end", n), function() {
|
|
1638
|
+
e.removeEventListener("request.end", n);
|
|
1623
1639
|
};
|
|
1624
1640
|
}
|
|
1625
1641
|
async function writeFiles(e, t, r, { rmRoot: s = !1 } = {}) {
|
|
1626
1642
|
s && await e.isDir(t) && await e.rmdir(t, { recursive: !0 });
|
|
1627
|
-
for (const [
|
|
1628
|
-
const o = joinPaths(t,
|
|
1629
|
-
await e.fileExists(dirname(o)) || await e.mkdir(dirname(o)), await e.writeFile(o,
|
|
1643
|
+
for (const [n, i] of Object.entries(r)) {
|
|
1644
|
+
const o = joinPaths(t, n);
|
|
1645
|
+
await e.fileExists(dirname(o)) || await e.mkdir(dirname(o)), await e.writeFile(o, i);
|
|
1630
1646
|
}
|
|
1631
1647
|
}
|
|
1632
1648
|
export {
|