@php-wasm/web 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +270 -234
  3. package/kitchen-sink/7_0_33/php_7_0.wasm +0 -0
  4. package/kitchen-sink/7_1_30/php_7_1.wasm +0 -0
  5. package/kitchen-sink/7_2_34/php_7_2.wasm +0 -0
  6. package/kitchen-sink/7_3_33/php_7_3.wasm +0 -0
  7. package/kitchen-sink/7_4_33/php_7_4.wasm +0 -0
  8. package/kitchen-sink/8_0_30/php_8_0.wasm +0 -0
  9. package/kitchen-sink/8_1_23/php_8_1.wasm +0 -0
  10. package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
  11. package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
  12. package/kitchen-sink/php_7_0.js +3 -3
  13. package/kitchen-sink/php_7_1.js +3 -3
  14. package/kitchen-sink/php_7_2.js +3 -3
  15. package/kitchen-sink/php_7_3.js +3 -3
  16. package/kitchen-sink/php_7_4.js +3 -3
  17. package/kitchen-sink/php_8_0.js +3 -3
  18. package/kitchen-sink/php_8_1.js +3 -3
  19. package/kitchen-sink/php_8_2.js +3 -3
  20. package/kitchen-sink/php_8_3.js +3 -3
  21. package/light/7_0_33/php_7_0.wasm +0 -0
  22. package/light/7_1_30/php_7_1.wasm +0 -0
  23. package/light/7_2_34/php_7_2.wasm +0 -0
  24. package/light/7_3_33/php_7_3.wasm +0 -0
  25. package/light/7_4_33/php_7_4.wasm +0 -0
  26. package/light/8_0_30/php_8_0.wasm +0 -0
  27. package/light/8_1_23/php_8_1.wasm +0 -0
  28. package/light/8_2_10/php_8_2.wasm +0 -0
  29. package/light/8_3_0/php_8_3.wasm +0 -0
  30. package/light/php_7_0.js +3 -3
  31. package/light/php_7_1.js +3 -3
  32. package/light/php_7_2.js +3 -3
  33. package/light/php_7_3.js +3 -3
  34. package/light/php_7_4.js +3 -3
  35. package/light/php_8_0.js +3 -3
  36. package/light/php_8_1.js +3 -3
  37. package/light/php_8_2.js +3 -3
  38. package/light/php_8_3.js +3 -3
  39. package/package.json +5 -5
package/index.js CHANGED
@@ -2,7 +2,7 @@ var K = (e, t, r) => {
2
2
  if (!t.has(e))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var l = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
5
+ var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (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);
@@ -12,8 +12,8 @@ if (typeof File > "u") {
12
12
  class e extends Blob {
13
13
  constructor(r, s, n) {
14
14
  super(r);
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 || "";
15
+ let o;
16
+ n != null && n.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = s || "";
17
17
  }
18
18
  }
19
19
  global.File = e;
@@ -50,9 +50,9 @@ function isByobSupported() {
50
50
  // this if needed.
51
51
  autoAllocateChunkSize: 512 * 1024,
52
52
  async pull(r) {
53
- const s = r.byobRequest.view, i = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(i);
54
- new Uint8Array(s.buffer).set(o);
55
- const a = o.byteLength;
53
+ const s = r.byobRequest.view, o = await t.slice(e, e + s.byteLength).arrayBuffer(), i = new Uint8Array(o);
54
+ new Uint8Array(s.buffer).set(i);
55
+ const a = i.byteLength;
56
56
  r.byobRequest.respond(a), e += a, e >= t.size && r.close();
57
57
  }
58
58
  });
@@ -115,26 +115,26 @@ function improveWASMErrorReporting(e) {
115
115
  if (typeof e.asm[r] == "function") {
116
116
  const s = e.asm[r];
117
117
  e.asm[r] = function(...n) {
118
- var i;
118
+ var o;
119
119
  try {
120
120
  return s(...n);
121
- } catch (o) {
122
- if (!(o instanceof Error))
123
- throw o;
121
+ } catch (i) {
122
+ if (!(i instanceof Error))
123
+ throw i;
124
124
  const a = clarifyErrorMessage(
125
- o,
126
- (i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
125
+ i,
126
+ (o = e.lastAsyncifyStackSource) == null ? void 0 : o.stack
127
127
  );
128
- if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
128
+ if (e.lastAsyncifyStackSource && (i.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
129
129
  t.dispatchEvent(
130
130
  new ErrorEvent("error", {
131
- error: o,
131
+ error: i,
132
132
  message: a
133
133
  })
134
134
  );
135
135
  return;
136
136
  }
137
- throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
137
+ throw isExitCodeZero(i) || showCriticalErrorBox(a), i;
138
138
  }
139
139
  };
140
140
  }
@@ -267,12 +267,31 @@ function normalizePathsArray(e, t) {
267
267
  e.unshift("..");
268
268
  return e;
269
269
  }
270
+ function splitShellCommand(e) {
271
+ let s = 0, n = "";
272
+ const o = [];
273
+ let i = "";
274
+ for (let a = 0; a < e.length; a++) {
275
+ const l = e[a];
276
+ l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, i += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (i.trim().length && o.push(i.trim()), i = l) : o.length && !i ? i = o.pop() + l : i += l : s === 1 && (l === n ? (s = 0, n = "") : i += l);
277
+ }
278
+ return i && o.push(i.trim()), o;
279
+ }
270
280
  function createSpawnHandler(e) {
271
- return function(t) {
272
- const r = new ChildProcess(), s = new ProcessApi(r);
281
+ return function(t, r = [], s = {}) {
282
+ const n = new ChildProcess(), o = new ProcessApi(n);
273
283
  return setTimeout(async () => {
274
- await e(t, s), r.emit("spawn", !0);
275
- }), r;
284
+ let i = [];
285
+ if (r.length)
286
+ i = [t, ...r];
287
+ else if (typeof t == "string")
288
+ i = splitShellCommand(t);
289
+ else if (Array.isArray(t))
290
+ i = t;
291
+ else
292
+ throw new Error("Invalid command ", t);
293
+ await e(i, o, s), n.emit("spawn", !0);
294
+ }), n;
276
295
  };
277
296
  }
278
297
  class EventEmitter {
@@ -297,9 +316,15 @@ class ProcessApi extends EventEmitter {
297
316
  stdout(t) {
298
317
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
299
318
  }
319
+ stdoutEnd() {
320
+ this.childProcess.stdout.emit("end", {});
321
+ }
300
322
  stderr(t) {
301
323
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
302
324
  }
325
+ stderrEnd() {
326
+ this.childProcess.stderr.emit("end", {});
327
+ }
303
328
  exit(t) {
304
329
  this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
305
330
  }
@@ -337,8 +362,8 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
337
362
  }, ReadableStream.prototype.iterate = // @ts-ignore
338
363
  ReadableStream.prototype[Symbol.asyncIterator]);
339
364
  class PHPResponse {
340
- constructor(t, r, s, n = "", i = 0) {
341
- this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
365
+ constructor(t, r, s, n = "", o = 0) {
366
+ this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
342
367
  }
343
368
  static fromRawData(t) {
344
369
  return new PHPResponse(
@@ -419,7 +444,7 @@ class PHPBrowser {
419
444
  cookie: this.serializeCookies()
420
445
  }
421
446
  });
422
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, T).handleRedirects && s.headers.location && r < l(this, T).maxRedirects) {
447
+ if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), c(this, T).handleRedirects && s.headers.location && r < c(this, T).maxRedirects) {
423
448
  const n = new URL(
424
449
  s.headers.location[0],
425
450
  this.requestHandler.absoluteUrl
@@ -456,16 +481,16 @@ class PHPBrowser {
456
481
  try {
457
482
  if (!r.includes("="))
458
483
  continue;
459
- const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
460
- l(this, b)[n] = i;
484
+ const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
485
+ c(this, b)[n] = o;
461
486
  } catch (s) {
462
487
  console.error(s);
463
488
  }
464
489
  }
465
490
  serializeCookies() {
466
491
  const t = [];
467
- for (const r in l(this, b))
468
- t.push(`${r}=${l(this, b)[r]}`);
492
+ for (const r in c(this, b))
493
+ t.push(`${r}=${c(this, b)[r]}`);
469
494
  return t.join("; ");
470
495
  }
471
496
  }
@@ -482,23 +507,23 @@ function ensurePathPrefix(e, t) {
482
507
  }
483
508
  async function encodeAsMultipart(e) {
484
509
  const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
485
- for (const [u, c] of Object.entries(e))
510
+ for (const [l, u] of Object.entries(e))
486
511
  n.push(`--${t}\r
487
- `), n.push(`Content-Disposition: form-data; name="${u}"`), c instanceof File && n.push(`; filename="${c.name}"`), n.push(`\r
488
- `), c instanceof File && n.push("Content-Type: application/octet-stream"), n.push(`\r
489
- \r
490
- `), c instanceof File ? n.push(await fileToUint8Array(c)) : n.push(c), n.push(`\r
512
+ `), n.push(`Content-Disposition: form-data; name="${l}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
513
+ `), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
514
+ `)), n.push(`\r
515
+ `), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
491
516
  `);
492
517
  n.push(`--${t}--\r
493
518
  `);
494
- const i = n.reduce((u, c) => u + c.length, 0), o = new Uint8Array(i);
519
+ const o = n.reduce((l, u) => l + u.length, 0), i = new Uint8Array(o);
495
520
  let a = 0;
496
- for (const u of n)
497
- o.set(
498
- typeof u == "string" ? s.encode(u) : u,
521
+ for (const l of n)
522
+ i.set(
523
+ typeof l == "string" ? s.encode(l) : l,
499
524
  a
500
- ), a += u.length;
501
- return { bytes: o, contentType: r };
525
+ ), a += l.length;
526
+ return { bytes: i, contentType: r };
502
527
  }
503
528
  function fileToUint8Array(e) {
504
529
  return new Promise((t) => {
@@ -508,7 +533,7 @@ function fileToUint8Array(e) {
508
533
  }, r.readAsArrayBuffer(e);
509
534
  });
510
535
  }
511
- var P, H, L, R, k, y, C, x, N, Q, U, Z, O, X;
536
+ var g, H, L, R, k, y, C, S, N, Z, U, X, O, ee;
512
537
  class PHPRequestHandler {
513
538
  /**
514
539
  * @param php - The PHP instance.
@@ -540,30 +565,30 @@ class PHPRequestHandler {
540
565
  * @returns The resolved filesystem path.
541
566
  */
542
567
  d(this, O);
543
- d(this, P, void 0);
568
+ d(this, g, void 0);
544
569
  d(this, H, void 0);
545
570
  d(this, L, void 0);
546
571
  d(this, R, void 0);
547
572
  d(this, k, void 0);
548
573
  d(this, y, void 0);
549
574
  d(this, C, void 0);
550
- d(this, x, void 0);
551
- p(this, x, new Semaphore({ concurrency: 1 }));
575
+ d(this, S, void 0);
576
+ p(this, S, new Semaphore({ concurrency: 1 }));
552
577
  const {
553
578
  documentRoot: s = "/www/",
554
579
  absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
555
580
  } = r;
556
- this.php = t, p(this, P, s);
557
- const i = new URL(n);
558
- p(this, L, i.hostname), p(this, R, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), p(this, H, (i.protocol || "").replace(":", ""));
559
- const o = l(this, R) !== 443 && l(this, R) !== 80;
581
+ this.php = t, p(this, g, s);
582
+ const o = new URL(n);
583
+ p(this, L, o.hostname), p(this, R, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, H, (o.protocol || "").replace(":", ""));
584
+ const i = c(this, R) !== 443 && c(this, R) !== 80;
560
585
  p(this, k, [
561
- l(this, L),
562
- o ? `:${l(this, R)}` : ""
563
- ].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this, C, [
564
- `${l(this, H)}://`,
565
- l(this, k),
566
- l(this, y)
586
+ c(this, L),
587
+ i ? `:${c(this, R)}` : ""
588
+ ].join("")), p(this, y, o.pathname.replace(/\/+$/, "")), p(this, C, [
589
+ `${c(this, H)}://`,
590
+ c(this, k),
591
+ c(this, y)
567
592
  ].join(""));
568
593
  }
569
594
  /** @inheritDoc */
@@ -573,18 +598,18 @@ class PHPRequestHandler {
573
598
  /** @inheritDoc */
574
599
  internalUrlToPath(t) {
575
600
  const r = new URL(t);
576
- return r.pathname.startsWith(l(this, y)) && (r.pathname = r.pathname.slice(l(this, y).length)), toRelativeUrl(r);
601
+ return r.pathname.startsWith(c(this, y)) && (r.pathname = r.pathname.slice(c(this, y).length)), toRelativeUrl(r);
577
602
  }
578
603
  get isRequestRunning() {
579
- return l(this, x).running > 0;
604
+ return c(this, S).running > 0;
580
605
  }
581
606
  /** @inheritDoc */
582
607
  get absoluteUrl() {
583
- return l(this, C);
608
+ return c(this, C);
584
609
  }
585
610
  /** @inheritDoc */
586
611
  get documentRoot() {
587
- return l(this, P);
612
+ return c(this, g);
588
613
  }
589
614
  /** @inheritDoc */
590
615
  async request(t) {
@@ -593,12 +618,12 @@ class PHPRequestHandler {
593
618
  r ? void 0 : DEFAULT_BASE_URL
594
619
  ), n = removePathPrefix(
595
620
  s.pathname,
596
- l(this, y)
597
- ), i = `${l(this, P)}${n}`;
598
- return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, U, Z).call(this, t, s) : f(this, N, Q).call(this, i);
621
+ c(this, y)
622
+ ), o = `${c(this, g)}${n}`;
623
+ return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, U, X).call(this, t, s) : f(this, N, Z).call(this, o);
599
624
  }
600
625
  }
601
- P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), x = new WeakMap(), N = new WeakSet(), Q = function(t) {
626
+ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), N = new WeakSet(), Z = function(t) {
602
627
  if (!this.php.fileExists(t))
603
628
  return new PHPResponse(
604
629
  404,
@@ -623,9 +648,9 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
623
648
  },
624
649
  r
625
650
  );
626
- }, U = new WeakSet(), Z = async function(t, r) {
627
- var n, i;
628
- if (l(this, x).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
651
+ }, U = new WeakSet(), X = async function(t, r) {
652
+ var n, o;
653
+ if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
629
654
  return console.warn(
630
655
  "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."
631
656
  ), new PHPResponse(
@@ -633,34 +658,34 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
633
658
  {},
634
659
  new TextEncoder().encode("502 Bad Gateway")
635
660
  );
636
- const s = await l(this, x).acquire();
661
+ const s = await c(this, S).acquire();
637
662
  try {
638
- this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, P)), this.php.addServerGlobalEntry(
663
+ this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, g)), this.php.addServerGlobalEntry(
639
664
  "HTTPS",
640
- l(this, C).startsWith("https://") ? "on" : ""
665
+ c(this, C).startsWith("https://") ? "on" : ""
641
666
  );
642
- let o = "GET";
667
+ let i = "GET";
643
668
  const a = {
644
- host: l(this, k),
669
+ host: c(this, k),
645
670
  ...normalizeHeaders(t.headers || {})
646
671
  };
647
- let u = t.body;
648
- if (typeof u == "object" && !(u instanceof Uint8Array)) {
649
- o = "POST";
650
- const { bytes: h, contentType: m } = await encodeAsMultipart(u);
651
- u = h, a["content-type"] = m;
672
+ let l = t.body;
673
+ if (typeof l == "object" && !(l instanceof Uint8Array)) {
674
+ i = "POST";
675
+ const { bytes: h, contentType: m } = await encodeAsMultipart(l);
676
+ l = h, a["content-type"] = m;
652
677
  }
653
- let c;
678
+ let u;
654
679
  try {
655
680
  let h = r.pathname;
656
- if ((i = t.headers) != null && i["x-rewrite-url"])
681
+ if ((o = t.headers) != null && o["x-rewrite-url"])
657
682
  try {
658
683
  h = new URL(
659
684
  t.headers["x-rewrite-url"]
660
685
  ).pathname;
661
686
  } catch {
662
687
  }
663
- c = f(this, O, X).call(this, h);
688
+ u = f(this, O, ee).call(this, h);
664
689
  } catch {
665
690
  return new PHPResponse(
666
691
  404,
@@ -671,21 +696,21 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
671
696
  return await this.php.run({
672
697
  relativeUri: ensurePathPrefix(
673
698
  toRelativeUrl(r),
674
- l(this, y)
699
+ c(this, y)
675
700
  ),
676
- protocol: l(this, H),
677
- method: t.method || o,
678
- body: u,
679
- scriptPath: c,
701
+ protocol: c(this, H),
702
+ method: t.method || i,
703
+ body: l,
704
+ scriptPath: u,
680
705
  headers: a
681
706
  });
682
707
  } finally {
683
708
  s();
684
709
  }
685
- }, O = new WeakSet(), X = function(t) {
686
- let r = removePathPrefix(t, l(this, y));
687
- r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
688
- const s = `${l(this, P)}${r}`;
710
+ }, O = new WeakSet(), ee = function(t) {
711
+ let r = removePathPrefix(t, c(this, y));
712
+ r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${c(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
713
+ const s = `${c(this, g)}${r}`;
689
714
  if (this.php.fileExists(s))
690
715
  return s;
691
716
  throw new Error(`File not found: ${s}`);
@@ -825,15 +850,15 @@ function getEmscriptenFsError(e) {
825
850
  }
826
851
  function rethrowFileSystemError(e = "") {
827
852
  return function(r, s, n) {
828
- const i = n.value;
829
- n.value = function(...o) {
853
+ const o = n.value;
854
+ n.value = function(...i) {
830
855
  try {
831
- return i.apply(this, o);
856
+ return o.apply(this, i);
832
857
  } catch (a) {
833
- const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
834
- if (u in FileErrorCodes) {
835
- const c = FileErrorCodes[u], h = typeof o[0] == "string" ? o[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
836
- throw new Error(`${m}: ${c}`, {
858
+ const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
859
+ if (l in FileErrorCodes) {
860
+ const u = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
861
+ throw new Error(`${m}: ${u}`, {
837
862
  cause: a
838
863
  });
839
864
  }
@@ -845,7 +870,7 @@ function rethrowFileSystemError(e = "") {
845
870
  const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
846
871
  let lastRuntimeId = 0;
847
872
  async function loadPHPRuntime(e, t = {}) {
848
- const [r, s, n] = makePromise(), i = e.init(currentJsRuntime, {
873
+ const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
849
874
  onAbort(a) {
850
875
  n(a), console.error(a);
851
876
  },
@@ -861,10 +886,10 @@ async function loadPHPRuntime(e, t = {}) {
861
886
  }
862
887
  });
863
888
  await r;
864
- const o = ++lastRuntimeId;
865
- return i.id = o, i.originalExit = i._exit, i._exit = function(a) {
866
- return loadedRuntimes.delete(o), i.originalExit(a);
867
- }, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
889
+ const i = ++lastRuntimeId;
890
+ return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
891
+ return loadedRuntimes.delete(i), o.originalExit(a);
892
+ }, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
868
893
  }
869
894
  function getLoadedRuntime(e) {
870
895
  return loadedRuntimes.get(e);
@@ -879,12 +904,12 @@ const currentJsRuntime = function() {
879
904
  return e.unshift(t), e;
880
905
  };
881
906
  var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
882
- for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
883
- (o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
907
+ for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, o = e.length - 1, i; o >= 0; o--)
908
+ (i = e[o]) && (n = (s ? i(t, r, n) : i(n)) || n);
884
909
  return s && n && __defProp(t, r, n), n;
885
910
  };
886
911
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
887
- var S, F, A, g, E, v, w, M, q, ee, B, te, W, re, $, se, z, ne, D, ie, j, oe, G, ae, V, le, Y, ce, J, ue;
912
+ var x, F, A, w, E, v, P, M, B, te, W, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, Q, ue, Y, de, J, he;
888
913
  class BasePHP {
889
914
  /**
890
915
  * Initializes a PHP runtime.
@@ -894,45 +919,46 @@ class BasePHP {
894
919
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
895
920
  */
896
921
  constructor(e, t) {
897
- d(this, q);
898
922
  d(this, B);
899
923
  d(this, W);
924
+ d(this, q);
925
+ d(this, D);
900
926
  d(this, $);
901
927
  d(this, z);
902
- d(this, D);
903
928
  d(this, j);
904
929
  d(this, G);
905
930
  d(this, V);
931
+ d(this, Q);
906
932
  d(this, Y);
907
933
  d(this, J);
908
- d(this, S, void 0);
934
+ d(this, x, void 0);
909
935
  d(this, F, void 0);
910
936
  d(this, A, void 0);
911
- d(this, g, void 0);
937
+ d(this, w, void 0);
912
938
  d(this, E, void 0);
913
939
  d(this, v, void 0);
914
- d(this, w, void 0);
940
+ d(this, P, void 0);
915
941
  d(this, M, void 0);
916
- p(this, S, []), p(this, g, !1), p(this, E, null), p(this, v, {}), p(this, w, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
942
+ p(this, x, []), p(this, w, !1), p(this, E, null), p(this, v, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
917
943
  new PHPRequestHandler(this, t)
918
944
  ));
919
945
  }
920
946
  addEventListener(e, t) {
921
- l(this, w).has(e) || l(this, w).set(e, /* @__PURE__ */ new Set()), l(this, w).get(e).add(t);
947
+ c(this, P).has(e) || c(this, P).set(e, /* @__PURE__ */ new Set()), c(this, P).get(e).add(t);
922
948
  }
923
949
  removeEventListener(e, t) {
924
950
  var r;
925
- (r = l(this, w).get(e)) == null || r.delete(t);
951
+ (r = c(this, P).get(e)) == null || r.delete(t);
926
952
  }
927
953
  dispatchEvent(e) {
928
- const t = l(this, w).get(e.type);
954
+ const t = c(this, P).get(e.type);
929
955
  if (t)
930
956
  for (const r of t)
931
957
  r(e);
932
958
  }
933
959
  /** @inheritDoc */
934
960
  async onMessage(e) {
935
- l(this, M).push(e);
961
+ c(this, M).push(e);
936
962
  }
937
963
  /** @inheritDoc */
938
964
  async setSpawnHandler(handler) {
@@ -963,7 +989,7 @@ class BasePHP {
963
989
  if (!t)
964
990
  throw new Error("Invalid PHP runtime id.");
965
991
  this[__private__dont__use] = t, t.onMessage = async (r) => {
966
- for (const s of l(this, M)) {
992
+ for (const s of c(this, M)) {
967
993
  const n = await s(r);
968
994
  if (n)
969
995
  return n;
@@ -988,7 +1014,7 @@ class BasePHP {
988
1014
  }
989
1015
  /** @inheritDoc */
990
1016
  setPhpIniPath(e) {
991
- if (l(this, g))
1017
+ if (c(this, w))
992
1018
  throw new Error("Cannot set PHP ini path after calling run().");
993
1019
  p(this, F, e), this[__private__dont__use].ccall(
994
1020
  "wasm_set_phpini_path",
@@ -999,9 +1025,9 @@ class BasePHP {
999
1025
  }
1000
1026
  /** @inheritDoc */
1001
1027
  setPhpIniEntry(e, t) {
1002
- if (l(this, g))
1028
+ if (c(this, w))
1003
1029
  throw new Error("Cannot set PHP ini entries after calling run().");
1004
- l(this, S).push([e, t]);
1030
+ c(this, x).push([e, t]);
1005
1031
  }
1006
1032
  /** @inheritDoc */
1007
1033
  chdir(e) {
@@ -1018,20 +1044,27 @@ class BasePHP {
1018
1044
  const t = await this.semaphore.acquire();
1019
1045
  let r;
1020
1046
  try {
1021
- l(this, g) || (f(this, q, ee).call(this), p(this, g, !0)), f(this, G, ae).call(this, e.scriptPath || ""), f(this, W, re).call(this, e.relativeUri || ""), f(this, z, ne).call(this, e.method || "GET");
1047
+ if (c(this, w) || (f(this, B, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1048
+ throw new Error(
1049
+ `The script path "${e.scriptPath}" does not exist.`
1050
+ );
1051
+ f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
1022
1052
  const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
1023
- f(this, $, se).call(this, n, e.protocol || "http"), f(this, D, ie).call(this, s), e.body && (r = f(this, j, oe).call(this, e.body)), typeof e.code == "string" && f(this, Y, ce).call(this, " ?>" + e.code), f(this, V, le).call(this);
1024
- const i = await f(this, J, ue).call(this);
1053
+ f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Y, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
1054
+ const o = e.env || {};
1055
+ for (const a in o)
1056
+ f(this, Q, ue).call(this, a, o[a]);
1057
+ const i = await f(this, J, he).call(this);
1025
1058
  if (e.throwOnError && i.exitCode !== 0) {
1026
- const o = {
1059
+ const a = {
1027
1060
  stdout: i.text,
1028
1061
  stderr: i.errors
1029
1062
  };
1030
- console.warn("PHP.run() output was:", o);
1031
- const a = new Error(
1032
- `PHP.run() failed with exit code ${i.exitCode} and the following output`
1063
+ console.warn("PHP.run() output was:", a);
1064
+ const l = new Error(
1065
+ `PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
1033
1066
  );
1034
- throw a.output = o, a;
1067
+ throw l.output = a, console.error(l), l;
1035
1068
  }
1036
1069
  return i;
1037
1070
  } finally {
@@ -1045,18 +1078,18 @@ class BasePHP {
1045
1078
  }
1046
1079
  }
1047
1080
  addServerGlobalEntry(e, t) {
1048
- l(this, v)[e] = t;
1081
+ c(this, v)[e] = t;
1049
1082
  }
1050
1083
  defineConstant(e, t) {
1051
1084
  let r = {};
1052
1085
  try {
1053
1086
  r = JSON.parse(
1054
- this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
1087
+ this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
1055
1088
  );
1056
1089
  } catch {
1057
1090
  }
1058
1091
  this.writeFile(
1059
- "/tmp/consts.json",
1092
+ "/internal/consts.json",
1060
1093
  JSON.stringify({
1061
1094
  ...r,
1062
1095
  [e]: t
@@ -1141,9 +1174,9 @@ class BasePHP {
1141
1174
  this.exit();
1142
1175
  } catch {
1143
1176
  }
1144
- if (this.initializeRuntime(e), l(this, F) && this.setPhpIniPath(l(this, F)), l(this, A) && this.setSapiName(l(this, A)), this.requestHandler) {
1177
+ if (this.initializeRuntime(e), c(this, F) && this.setPhpIniPath(c(this, F)), c(this, A) && this.setSapiName(c(this, A)), this.requestHandler) {
1145
1178
  const r = this.documentRoot;
1146
- recreateMemFS(this[__private__dont__use].FS, t, r);
1179
+ copyFS(t, this[__private__dont__use].FS, r);
1147
1180
  }
1148
1181
  }
1149
1182
  exit(e = 0) {
@@ -1154,23 +1187,23 @@ class BasePHP {
1154
1187
  this[__private__dont__use]._exit(e);
1155
1188
  } catch {
1156
1189
  }
1157
- p(this, g, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1190
+ p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1158
1191
  }
1159
1192
  }
1160
- S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E = new WeakMap(), v = new WeakMap(), w = new WeakMap(), M = new WeakMap(), q = new WeakSet(), ee = function() {
1161
- if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
1162
- "/tmp/consts.php",
1193
+ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), B = new WeakSet(), te = function() {
1194
+ if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
1195
+ "/internal/consts.php",
1163
1196
  `<?php
1164
- if(file_exists('/tmp/consts.json')) {
1165
- $consts = json_decode(file_get_contents('/tmp/consts.json'), true);
1197
+ if(file_exists('/internal/consts.json')) {
1198
+ $consts = json_decode(file_get_contents('/internal/consts.json'), true);
1166
1199
  foreach ($consts as $const => $value) {
1167
1200
  if (!defined($const) && is_scalar($value)) {
1168
1201
  define($const, $value);
1169
1202
  }
1170
1203
  }
1171
1204
  }`
1172
- ), l(this, S).length > 0) {
1173
- const e = l(this, S).map(([t, r]) => `${t}=${r}`).join(`
1205
+ ), c(this, x).length > 0) {
1206
+ const e = c(this, x).map(([t, r]) => `${t}=${r}`).join(`
1174
1207
  `) + `
1175
1208
 
1176
1209
  `;
@@ -1182,8 +1215,8 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1182
1215
  );
1183
1216
  }
1184
1217
  this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1185
- }, B = new WeakSet(), te = function() {
1186
- const e = "/tmp/headers.json";
1218
+ }, W = new WeakSet(), re = function() {
1219
+ const e = "/internal/headers.json";
1187
1220
  if (!this.fileExists(e))
1188
1221
  throw new Error(
1189
1222
  "SAPI Error: Could not find response headers file."
@@ -1192,14 +1225,14 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1192
1225
  for (const s of t.headers) {
1193
1226
  if (!s.includes(": "))
1194
1227
  continue;
1195
- const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
1196
- i in r || (r[i] = []), r[i].push(o);
1228
+ const n = s.indexOf(": "), o = s.substring(0, n).toLowerCase(), i = s.substring(n + 2);
1229
+ o in r || (r[o] = []), r[o].push(i);
1197
1230
  }
1198
1231
  return {
1199
1232
  headers: r,
1200
1233
  httpStatusCode: t.status
1201
1234
  };
1202
- }, W = new WeakSet(), re = function(e) {
1235
+ }, q = new WeakSet(), se = function(e) {
1203
1236
  if (this[__private__dont__use].ccall(
1204
1237
  "wasm_set_request_uri",
1205
1238
  null,
@@ -1214,7 +1247,7 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1214
1247
  [t]
1215
1248
  );
1216
1249
  }
1217
- }, $ = new WeakSet(), se = function(e, t) {
1250
+ }, D = new WeakSet(), ne = function(e, t) {
1218
1251
  this[__private__dont__use].ccall(
1219
1252
  "wasm_set_request_host",
1220
1253
  null,
@@ -1232,14 +1265,14 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1232
1265
  [NUMBER],
1233
1266
  [r]
1234
1267
  ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1235
- }, z = new WeakSet(), ne = function(e) {
1268
+ }, $ = new WeakSet(), ie = function(e) {
1236
1269
  this[__private__dont__use].ccall(
1237
1270
  "wasm_set_request_method",
1238
1271
  null,
1239
1272
  [STRING],
1240
1273
  [e]
1241
1274
  );
1242
- }, D = new WeakSet(), ie = function(e) {
1275
+ }, z = new WeakSet(), oe = function(e) {
1243
1276
  e.cookie && this[__private__dont__use].ccall(
1244
1277
  "wasm_set_cookies",
1245
1278
  null,
@@ -1263,7 +1296,7 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1263
1296
  e[t]
1264
1297
  );
1265
1298
  }
1266
- }, j = new WeakSet(), oe = function(e) {
1299
+ }, j = new WeakSet(), ae = function(e) {
1267
1300
  let t, r;
1268
1301
  typeof e == "string" ? (console.warn(
1269
1302
  "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"
@@ -1286,38 +1319,46 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1286
1319
  [NUMBER],
1287
1320
  [r]
1288
1321
  ), s;
1289
- }, G = new WeakSet(), ae = function(e) {
1322
+ }, G = new WeakSet(), le = function(e) {
1290
1323
  this[__private__dont__use].ccall(
1291
1324
  "wasm_set_path_translated",
1292
1325
  null,
1293
1326
  [STRING],
1294
1327
  [e]
1295
1328
  );
1296
- }, V = new WeakSet(), le = function() {
1297
- for (const e in l(this, v))
1329
+ }, V = new WeakSet(), ce = function() {
1330
+ for (const e in c(this, v))
1298
1331
  this[__private__dont__use].ccall(
1299
1332
  "wasm_add_SERVER_entry",
1300
1333
  null,
1301
1334
  [STRING, STRING],
1302
- [e, l(this, v)[e]]
1335
+ [e, c(this, v)[e]]
1303
1336
  );
1304
- }, Y = new WeakSet(), ce = function(e) {
1337
+ }, Q = new WeakSet(), ue = function(e, t) {
1338
+ this[__private__dont__use].ccall(
1339
+ "wasm_add_ENV_entry",
1340
+ null,
1341
+ [STRING, STRING],
1342
+ [e, t]
1343
+ );
1344
+ }, Y = new WeakSet(), de = function(e) {
1305
1345
  this[__private__dont__use].ccall(
1306
1346
  "wasm_set_php_code",
1307
1347
  null,
1308
1348
  [STRING],
1309
1349
  [e]
1310
1350
  );
1311
- }, J = new WeakSet(), ue = async function() {
1351
+ }, J = new WeakSet(), he = async function() {
1312
1352
  var n;
1313
1353
  let e, t;
1314
1354
  try {
1315
- e = await new Promise((i, o) => {
1316
- var u;
1317
- t = (c) => {
1355
+ e = await new Promise((o, i) => {
1356
+ var l;
1357
+ t = (u) => {
1358
+ console.error(u), console.error(u.error);
1318
1359
  const h = new Error("Rethrown");
1319
- h.cause = c.error, h.betterMessage = c.message, o(h);
1320
- }, (u = l(this, E)) == null || u.addEventListener(
1360
+ h.cause = u.error, h.betterMessage = u.message, i(h);
1361
+ }, (l = c(this, E)) == null || l.addEventListener(
1321
1362
  "error",
1322
1363
  t
1323
1364
  );
@@ -1328,27 +1369,27 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
1328
1369
  [],
1329
1370
  { async: !0 }
1330
1371
  );
1331
- return a instanceof Promise ? a.then(i, o) : i(a);
1372
+ return a instanceof Promise ? a.then(o, i) : o(a);
1332
1373
  });
1333
- } catch (i) {
1334
- for (const c in this)
1335
- typeof this[c] == "function" && (this[c] = () => {
1374
+ } catch (o) {
1375
+ for (const u in this)
1376
+ typeof this[u] == "function" && (this[u] = () => {
1336
1377
  throw new Error(
1337
1378
  "PHP runtime has crashed – see the earlier error for details."
1338
1379
  );
1339
1380
  });
1340
1381
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1341
- const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, u = new Error(a);
1342
- throw u.cause = o, u;
1382
+ const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
1383
+ throw l.cause = i, console.error(l), l;
1343
1384
  } finally {
1344
- (n = l(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
1385
+ (n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
1345
1386
  }
1346
- const { headers: r, httpStatusCode: s } = f(this, B, te).call(this);
1387
+ const { headers: r, httpStatusCode: s } = f(this, W, re).call(this);
1347
1388
  return new PHPResponse(
1348
1389
  s,
1349
1390
  r,
1350
- this.readFileAsBuffer("/tmp/stdout"),
1351
- this.readFileAsText("/tmp/stderr"),
1391
+ this.readFileAsBuffer("/internal/stdout"),
1392
+ this.readFileAsText("/internal/stderr"),
1352
1393
  e
1353
1394
  );
1354
1395
  };
@@ -1388,28 +1429,23 @@ function normalizeHeaders(e) {
1388
1429
  t[r.toLowerCase()] = e[r];
1389
1430
  return t;
1390
1431
  }
1391
- function recreateMemFS(e, t, r) {
1432
+ function copyFS(e, t, r) {
1392
1433
  let s;
1393
1434
  try {
1394
- s = t.lookupPath(r);
1435
+ s = e.lookupPath(r);
1395
1436
  } catch {
1396
1437
  return;
1397
1438
  }
1398
1439
  if (!("contents" in s.node))
1399
1440
  return;
1400
- try {
1401
- e = e.lookupPath(r);
1441
+ if (!e.isDir(s.node.mode)) {
1442
+ t.writeFile(r, e.readFile(r));
1402
1443
  return;
1403
- } catch {
1404
1444
  }
1405
- if (!t.isDir(s.node.mode)) {
1406
- e.writeFile(r, t.readFile(r));
1407
- return;
1408
- }
1409
- e.mkdirTree(r);
1410
- const n = t.readdir(r).filter((i) => i !== "." && i !== "..");
1411
- for (const i of n)
1412
- recreateMemFS(e, t, joinPaths(r, i));
1445
+ t.mkdirTree(r);
1446
+ const n = e.readdir(r).filter((o) => o !== "." && o !== "..");
1447
+ for (const o of n)
1448
+ copyFS(e, t, joinPaths(r, o));
1413
1449
  }
1414
1450
  /**
1415
1451
  * @license
@@ -1459,50 +1495,50 @@ function expose(e, t = globalThis, r = ["*"]) {
1459
1495
  console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
1460
1496
  return;
1461
1497
  }
1462
- const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), u = (n.data.argumentList || []).map(fromWireValue);
1463
- let c;
1498
+ const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
1499
+ let u;
1464
1500
  try {
1465
1501
  const h = a.slice(0, -1).reduce((_, I) => _[I], e), m = a.reduce((_, I) => _[I], e);
1466
- switch (o) {
1502
+ switch (i) {
1467
1503
  case "GET":
1468
- c = m;
1504
+ u = m;
1469
1505
  break;
1470
1506
  case "SET":
1471
- h[a.slice(-1)[0]] = fromWireValue(n.data.value), c = !0;
1507
+ h[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
1472
1508
  break;
1473
1509
  case "APPLY":
1474
- c = m.apply(h, u);
1510
+ u = m.apply(h, l);
1475
1511
  break;
1476
1512
  case "CONSTRUCT":
1477
1513
  {
1478
- const _ = new m(...u);
1479
- c = proxy(_);
1514
+ const _ = new m(...l);
1515
+ u = proxy(_);
1480
1516
  }
1481
1517
  break;
1482
1518
  case "ENDPOINT":
1483
1519
  {
1484
1520
  const { port1: _, port2: I } = new MessageChannel();
1485
- expose(e, I), c = transfer(_, [_]);
1521
+ expose(e, I), u = transfer(_, [_]);
1486
1522
  }
1487
1523
  break;
1488
1524
  case "RELEASE":
1489
- c = void 0;
1525
+ u = void 0;
1490
1526
  break;
1491
1527
  default:
1492
1528
  return;
1493
1529
  }
1494
1530
  } catch (h) {
1495
- c = { value: h, [throwMarker]: 0 };
1531
+ u = { value: h, [throwMarker]: 0 };
1496
1532
  }
1497
- Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1533
+ Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1498
1534
  const [m, _] = toWireValue(h);
1499
- t.postMessage(Object.assign(Object.assign({}, m), { id: i }), _), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1535
+ t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1500
1536
  }).catch((h) => {
1501
1537
  const [m, _] = toWireValue({
1502
1538
  value: new TypeError("Unserializable return value"),
1503
1539
  [throwMarker]: 0
1504
1540
  });
1505
- t.postMessage(Object.assign(Object.assign({}, m), { id: i }), _);
1541
+ t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _);
1506
1542
  });
1507
1543
  }), t.start && t.start();
1508
1544
  }
@@ -1541,55 +1577,55 @@ function createProxy(e, t = [], r = function() {
1541
1577
  }) {
1542
1578
  let s = !1;
1543
1579
  const n = new Proxy(r, {
1544
- get(i, o) {
1545
- if (throwIfProxyReleased(s), o === releaseProxy)
1580
+ get(o, i) {
1581
+ if (throwIfProxyReleased(s), i === releaseProxy)
1546
1582
  return () => {
1547
1583
  unregisterProxy(n), releaseEndpoint(e), s = !0;
1548
1584
  };
1549
- if (o === "then") {
1585
+ if (i === "then") {
1550
1586
  if (t.length === 0)
1551
1587
  return { then: () => n };
1552
1588
  const a = requestResponseMessage(e, {
1553
1589
  type: "GET",
1554
- path: t.map((u) => u.toString())
1590
+ path: t.map((l) => l.toString())
1555
1591
  }).then(fromWireValue);
1556
1592
  return a.then.bind(a);
1557
1593
  }
1558
- return createProxy(e, [...t, o]);
1594
+ return createProxy(e, [...t, i]);
1559
1595
  },
1560
- set(i, o, a) {
1596
+ set(o, i, a) {
1561
1597
  throwIfProxyReleased(s);
1562
- const [u, c] = toWireValue(a);
1598
+ const [l, u] = toWireValue(a);
1563
1599
  return requestResponseMessage(e, {
1564
1600
  type: "SET",
1565
- path: [...t, o].map((h) => h.toString()),
1566
- value: u
1567
- }, c).then(fromWireValue);
1601
+ path: [...t, i].map((h) => h.toString()),
1602
+ value: l
1603
+ }, u).then(fromWireValue);
1568
1604
  },
1569
- apply(i, o, a) {
1605
+ apply(o, i, a) {
1570
1606
  throwIfProxyReleased(s);
1571
- const u = t[t.length - 1];
1572
- if (u === createEndpoint)
1607
+ const l = t[t.length - 1];
1608
+ if (l === createEndpoint)
1573
1609
  return requestResponseMessage(e, {
1574
1610
  type: "ENDPOINT"
1575
1611
  }).then(fromWireValue);
1576
- if (u === "bind")
1612
+ if (l === "bind")
1577
1613
  return createProxy(e, t.slice(0, -1));
1578
- const [c, h] = processArguments(a);
1614
+ const [u, h] = processArguments(a);
1579
1615
  return requestResponseMessage(e, {
1580
1616
  type: "APPLY",
1581
1617
  path: t.map((m) => m.toString()),
1582
- argumentList: c
1618
+ argumentList: u
1583
1619
  }, h).then(fromWireValue);
1584
1620
  },
1585
- construct(i, o) {
1621
+ construct(o, i) {
1586
1622
  throwIfProxyReleased(s);
1587
- const [a, u] = processArguments(o);
1623
+ const [a, l] = processArguments(i);
1588
1624
  return requestResponseMessage(e, {
1589
1625
  type: "CONSTRUCT",
1590
- path: t.map((c) => c.toString()),
1626
+ path: t.map((u) => u.toString()),
1591
1627
  argumentList: a
1592
- }, u).then(fromWireValue);
1628
+ }, l).then(fromWireValue);
1593
1629
  }
1594
1630
  });
1595
1631
  return registerProxy(n, e), n;
@@ -1647,8 +1683,8 @@ function fromWireValue(e) {
1647
1683
  function requestResponseMessage(e, t, r) {
1648
1684
  return new Promise((s) => {
1649
1685
  const n = generateUUID();
1650
- e.addEventListener("message", function i(o) {
1651
- !o.data || !o.data.id || o.data.id !== n || (e.removeEventListener("message", i), s(o.data));
1686
+ e.addEventListener("message", function o(i) {
1687
+ !i.data || !i.data.id || i.data.id !== n || (e.removeEventListener("message", o), s(i.data));
1652
1688
  }), e.start && e.start(), e.postMessage(Object.assign({ id: n }, t), r);
1653
1689
  });
1654
1690
  }
@@ -1659,14 +1695,14 @@ function consumeAPI(e) {
1659
1695
  setupTransferHandlers();
1660
1696
  const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
1661
1697
  return new Proxy(s, {
1662
- get: (n, i) => i === "isConnected" ? async () => {
1663
- for (let o = 0; o < 10; o++)
1698
+ get: (n, o) => o === "isConnected" ? async () => {
1699
+ for (let i = 0; i < 10; i++)
1664
1700
  try {
1665
1701
  await runWithTimeout(r.isConnected(), 200);
1666
1702
  break;
1667
1703
  } catch {
1668
1704
  }
1669
- } : r[i]
1705
+ } : r[o]
1670
1706
  });
1671
1707
  }
1672
1708
  async function runWithTimeout(e, t) {
@@ -1678,10 +1714,10 @@ function exposeAPI(e, t) {
1678
1714
  setupTransferHandlers();
1679
1715
  const r = Promise.resolve();
1680
1716
  let s, n;
1681
- const i = new Promise((u, c) => {
1682
- s = u, n = c;
1683
- }), o = proxyClone(e), a = new Proxy(o, {
1684
- get: (u, c) => c === "isConnected" ? () => r : c === "isReady" ? () => i : c in u ? u[c] : t == null ? void 0 : t[c]
1717
+ const o = new Promise((l, u) => {
1718
+ s = l, n = u;
1719
+ }), i = proxyClone(e), a = new Proxy(i, {
1720
+ get: (l, u) => u === "isConnected" ? () => r : u === "isReady" ? () => o : u in l ? l[u] : t == null ? void 0 : t[u]
1685
1721
  });
1686
1722
  return expose(
1687
1723
  a,
@@ -1817,9 +1853,9 @@ class WebPHP extends BasePHP {
1817
1853
  );
1818
1854
  }
1819
1855
  static async loadRuntime(t, r = {}) {
1820
- var i;
1856
+ var o;
1821
1857
  const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
1822
- return (i = r.downloadMonitor) == null || i.expectAssets({
1858
+ return (o = r.downloadMonitor) == null || o.expectAssets({
1823
1859
  [n.dependencyFilename]: n.dependenciesTotalSize
1824
1860
  }), await loadPHPRuntime(n, {
1825
1861
  ...r.emscriptenOptions || {},
@@ -1961,11 +1997,11 @@ async function registerServiceWorker(e, t, r) {
1961
1997
  updateViaCache: "none"
1962
1998
  })).update(), navigator.serviceWorker.addEventListener(
1963
1999
  "message",
1964
- async function(o) {
1965
- if (console.debug("[window][sw] Message from ServiceWorker", o), t && o.data.scope !== t)
2000
+ async function(i) {
2001
+ if (console.debug("[window][sw] Message from ServiceWorker", i), t && i.data.scope !== t)
1966
2002
  return;
1967
- const a = o.data.args || [], u = o.data.method, c = await e[u](...a);
1968
- o.source.postMessage(responseTo(o.data.requestId, c));
2003
+ const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
2004
+ i.source.postMessage(responseTo(i.data.requestId, u));
1969
2005
  }
1970
2006
  ), s.startMessages();
1971
2007
  }
@@ -1973,16 +2009,16 @@ async function spawnPHPWorkerThread(e, t = {}) {
1973
2009
  e = addQueryParams(e, t);
1974
2010
  const r = new Worker(e, { type: "module" });
1975
2011
  return new Promise((s, n) => {
1976
- r.onerror = (o) => {
2012
+ r.onerror = (i) => {
1977
2013
  const a = new Error(
1978
- `WebWorker failed to load at ${e}. ${o.message ? `Original error: ${o.message}` : ""}`
2014
+ `WebWorker failed to load at ${e}. ${i.message ? `Original error: ${i.message}` : ""}`
1979
2015
  );
1980
- a.filename = o.filename, n(a);
2016
+ a.filename = i.filename, n(a);
1981
2017
  };
1982
- function i(o) {
1983
- o.data === "worker-script-started" && (s(r), r.removeEventListener("message", i));
2018
+ function o(i) {
2019
+ i.data === "worker-script-started" && (s(r), r.removeEventListener("message", o));
1984
2020
  }
1985
- r.addEventListener("message", i);
2021
+ r.addEventListener("message", o);
1986
2022
  });
1987
2023
  }
1988
2024
  function addQueryParams(e, t) {
@@ -1991,8 +2027,8 @@ function addQueryParams(e, t) {
1991
2027
  const r = new URL(e);
1992
2028
  for (const [s, n] of Object.entries(t))
1993
2029
  if (Array.isArray(n))
1994
- for (const i of n)
1995
- r.searchParams.append(s, i);
2030
+ for (const o of n)
2031
+ r.searchParams.append(s, o);
1996
2032
  else
1997
2033
  r.searchParams.set(s, n);
1998
2034
  return r.toString();