@php-wasm/universal 3.0.2 → 3.0.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.js CHANGED
@@ -1,8 +1,8 @@
1
- var W = (t) => {
1
+ var B = (t) => {
2
2
  throw TypeError(t);
3
3
  };
4
- var O = (t, e, r) => e.has(t) || W("Cannot " + r);
5
- var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), y = (t, e, r) => e.has(t) ? W("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), m = (t, e, r) => (O(t, e, "access private method"), r);
4
+ var O = (t, e, r) => e.has(t) || B("Cannot " + r);
5
+ var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), m = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), y = (t, e, r) => (O(t, e, "access private method"), r);
6
6
  import "@php-wasm/node-polyfills";
7
7
  import { logger } from "@php-wasm/logger";
8
8
  import { dirname, joinPaths, Semaphore, createSpawnHandler, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
@@ -363,10 +363,12 @@ FSHelpers.copyRecursive = rethrowFileSystemError(
363
363
  'Could not copy files from "{path}"'
364
364
  )(FSHelpers.copyRecursive);
365
365
  const _private = /* @__PURE__ */ new WeakMap();
366
+ var P;
366
367
  class PHPWorker {
367
368
  /** @inheritDoc */
368
369
  constructor(e, r) {
369
- this.absoluteUrl = "", this.documentRoot = "", _private.set(this, {
370
+ m(this, P);
371
+ this.absoluteUrl = "", this.documentRoot = "", w(this, P, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
370
372
  monitor: r
371
373
  }), e && this.__internal_setRequestHandler(e);
372
374
  }
@@ -497,7 +499,11 @@ class PHPWorker {
497
499
  }
498
500
  /** @inheritDoc @php-wasm/universal!/PHP.onMessage */
499
501
  onMessage(e) {
500
- return _private.get(this).php.onMessage(e);
502
+ return this.onMessageListeners.push(e), async () => {
503
+ this.onMessageListeners = this.onMessageListeners.filter(
504
+ (r) => r !== e
505
+ );
506
+ };
501
507
  }
502
508
  /** @inheritDoc @php-wasm/universal!/PHP.defineConstant */
503
509
  defineConstant(e, r) {
@@ -505,17 +511,41 @@ class PHPWorker {
505
511
  }
506
512
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
507
513
  addEventListener(e, r) {
508
- _private.get(this).php.addEventListener(e, r);
514
+ u(this, P).has(e) || u(this, P).set(e, /* @__PURE__ */ new Set()), u(this, P).get(e).add(r);
509
515
  }
510
- /** @inheritDoc @php-wasm/universal!/PHP.removeEventListener */
516
+ /**
517
+ * Removes an event listener for a PHP event.
518
+ * @param eventType - The type of event to remove the listener from.
519
+ * @param listener - The listener function to be removed.
520
+ */
511
521
  removeEventListener(e, r) {
512
- _private.get(this).php.removeEventListener(e, r);
522
+ var s;
523
+ (s = u(this, P).get(e)) == null || s.delete(r);
524
+ }
525
+ dispatchEvent(e) {
526
+ const r = u(this, P).get(e.type);
527
+ if (r)
528
+ for (const s of r)
529
+ s(e);
530
+ }
531
+ registerWorkerListeners(e) {
532
+ e.addEventListener("*", async (r) => {
533
+ this.dispatchEvent(r);
534
+ }), e.onMessage(async (r) => {
535
+ for (const s of this.onMessageListeners) {
536
+ const n = await s(r);
537
+ if (n)
538
+ return n;
539
+ }
540
+ return "";
541
+ });
513
542
  }
514
543
  async [Symbol.asyncDispose]() {
515
544
  var e;
516
545
  await ((e = _private.get(this).requestHandler) == null ? void 0 : e[Symbol.asyncDispose]());
517
546
  }
518
547
  }
548
+ P = new WeakMap();
519
549
  function isExitCode(t) {
520
550
  return t instanceof Error ? (t == null ? void 0 : t.name) === "ExitStatus" && "status" in t : !1;
521
551
  }
@@ -907,7 +937,7 @@ class PHPExecutionFailureError extends Error {
907
937
  }
908
938
  }
909
939
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
910
- var k, H, b, E, T, C, _, h, B, z, $, V, G, J, Y, K, L, X, U, j;
940
+ var C, b, T, E, F, M, _, h, z, $, V, G, J, Y, K, X, U, Q, j, q;
911
941
  class PHP {
912
942
  /**
913
943
  * Initializes a PHP runtime.
@@ -917,14 +947,17 @@ class PHP {
917
947
  * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
918
948
  */
919
949
  constructor(t) {
920
- y(this, h);
921
- y(this, k);
922
- y(this, H, !1);
923
- y(this, b, null);
924
- y(this, E, /* @__PURE__ */ new Map());
925
- y(this, T, []);
926
- y(this, C, {});
927
- y(this, _, {
950
+ m(this, h);
951
+ m(this, C);
952
+ m(this, b, !1);
953
+ m(this, T, null);
954
+ m(this, E, /* @__PURE__ */ new Map([
955
+ // Listen to all events
956
+ ["*", /* @__PURE__ */ new Set()]
957
+ ]));
958
+ m(this, F, []);
959
+ m(this, M, {});
960
+ m(this, _, {
928
961
  enabled: !1,
929
962
  recreateRuntime: () => 0,
930
963
  needsRotating: !1,
@@ -953,7 +986,10 @@ class PHP {
953
986
  (r = u(this, E).get(t)) == null || r.delete(e);
954
987
  }
955
988
  dispatchEvent(t) {
956
- const e = u(this, E).get(t.type);
989
+ const e = [
990
+ ...u(this, E).get(t.type) || [],
991
+ ...u(this, E).get("*") || []
992
+ ];
957
993
  if (e)
958
994
  for (const r of e)
959
995
  r(t);
@@ -998,8 +1034,8 @@ class PHP {
998
1034
  * @param listener Callback function to handle the message.
999
1035
  */
1000
1036
  onMessage(t) {
1001
- return u(this, T).push(t), async () => {
1002
- w(this, T, u(this, T).filter(
1037
+ return u(this, F).push(t), async () => {
1038
+ w(this, F, u(this, F).filter(
1003
1039
  (e) => e !== t
1004
1040
  ));
1005
1041
  };
@@ -1093,13 +1129,13 @@ class PHP {
1093
1129
  }
1094
1130
  `
1095
1131
  ), e.onMessage = async (r) => {
1096
- for (const s of u(this, T)) {
1132
+ for (const s of u(this, F)) {
1097
1133
  const n = await s(r);
1098
1134
  if (n)
1099
1135
  return n;
1100
1136
  }
1101
1137
  return "";
1102
- }, w(this, b, improveWASMErrorReporting(e)), this.dispatchEvent({
1138
+ }, w(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1103
1139
  type: "runtime.initialized"
1104
1140
  });
1105
1141
  }
@@ -1114,7 +1150,7 @@ class PHP {
1114
1150
  throw new Error(
1115
1151
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1116
1152
  );
1117
- w(this, k, t);
1153
+ w(this, C, t);
1118
1154
  }
1119
1155
  /**
1120
1156
  * Changes the current working directory in the PHP filesystem.
@@ -1330,8 +1366,8 @@ class PHP {
1330
1366
  async runStream(t) {
1331
1367
  const e = await this.semaphore.acquire();
1332
1368
  let r;
1333
- const s = m(this, h, j).call(this, async () => {
1334
- if (u(this, H) || (await this[__private__dont__use].ccall(
1369
+ const s = y(this, h, q).call(this, async () => {
1370
+ if (u(this, b) || (await this[__private__dont__use].ccall(
1335
1371
  "php_wasm_init",
1336
1372
  null,
1337
1373
  [],
@@ -1339,26 +1375,26 @@ class PHP {
1339
1375
  {
1340
1376
  isAsync: !0
1341
1377
  }
1342
- ), w(this, H, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1378
+ ), w(this, b, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1343
1379
  throw new Error(
1344
1380
  `The script path "${t.scriptPath}" does not exist.`
1345
1381
  );
1346
- m(this, h, z).call(this, t.relativeUri || ""), m(this, h, J).call(this, t.method || "GET");
1347
- const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = m(this, h, G).call(this, o, t.protocol || "http");
1348
- if (m(this, h, $).call(this, o), m(this, h, V).call(this, a), m(this, h, Y).call(this, i), t.body && (r = m(this, h, K).call(this, t.body)), typeof t.code == "string")
1349
- this.writeFile("/internal/eval.php", t.code), m(this, h, L).call(this, "/internal/eval.php");
1382
+ y(this, h, $).call(this, t.relativeUri || ""), y(this, h, Y).call(this, t.method || "GET");
1383
+ const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = y(this, h, J).call(this, o, t.protocol || "http");
1384
+ if (y(this, h, V).call(this, o), y(this, h, G).call(this, a), y(this, h, K).call(this, i), t.body && (r = y(this, h, X).call(this, t.body)), typeof t.code == "string")
1385
+ this.writeFile("/internal/eval.php", t.code), y(this, h, U).call(this, "/internal/eval.php");
1350
1386
  else if (typeof t.scriptPath == "string")
1351
- m(this, h, L).call(this, t.scriptPath || "");
1387
+ y(this, h, U).call(this, t.scriptPath || "");
1352
1388
  else
1353
1389
  throw new TypeError(
1354
1390
  "The request object must have either a `code` or a `scriptPath` property."
1355
1391
  );
1356
- const c = m(this, h, B).call(this, t.$_SERVER, i, a);
1392
+ const c = y(this, h, z).call(this, t.$_SERVER, i, a);
1357
1393
  for (const p in c)
1358
- m(this, h, X).call(this, p, c[p]);
1394
+ y(this, h, Q).call(this, p, c[p]);
1359
1395
  const l = t.env || {};
1360
1396
  for (const p in l)
1361
- m(this, h, U).call(this, p, l[p]);
1397
+ y(this, h, j).call(this, p, l[p]);
1362
1398
  return await this[__private__dont__use].ccall(
1363
1399
  "wasm_sapi_handle_request",
1364
1400
  NUMBER,
@@ -1589,13 +1625,13 @@ class PHP {
1589
1625
  */
1590
1626
  async hotSwapPHPRuntime(t) {
1591
1627
  const e = this[__private__dont__use].FS, r = this.listFiles("/").map((o) => `/${o}`), s = this[__private__dont__use].spawnProcess, n = [];
1592
- for (const [o, a] of Object.entries(u(this, C)))
1628
+ for (const [o, a] of Object.entries(u(this, M)))
1593
1629
  n.push({ mountHandler: a.mountHandler, vfsPath: o }), await a.unmount();
1594
1630
  try {
1595
1631
  this.exit();
1596
1632
  } catch {
1597
1633
  }
1598
- this.initializeRuntime(t), s && (this[__private__dont__use].spawnProcess = s), u(this, k) && this.setSapiName(u(this, k));
1634
+ this.initializeRuntime(t), s && (this[__private__dont__use].spawnProcess = s), u(this, C) && this.setSapiName(u(this, C));
1599
1635
  const i = this[__private__dont__use].FS;
1600
1636
  for (const o of r)
1601
1637
  o && o !== "/request" && copyMEMFSNodes(e, i, o);
@@ -1617,10 +1653,10 @@ class PHP {
1617
1653
  ), s = {
1618
1654
  mountHandler: e,
1619
1655
  unmount: async () => {
1620
- await r(), delete u(this, C)[t];
1656
+ await r(), delete u(this, M)[t];
1621
1657
  }
1622
1658
  };
1623
- return u(this, C)[t] = s, () => {
1659
+ return u(this, M)[t] = s, () => {
1624
1660
  s.unmount();
1625
1661
  };
1626
1662
  }
@@ -1638,12 +1674,12 @@ class PHP {
1638
1674
  * @returns The exit code of the CLI session.
1639
1675
  */
1640
1676
  async cli(t, e = {}) {
1641
- u(this, H) && (u(this, _).needsRotating = !0);
1677
+ u(this, b) && (u(this, _).needsRotating = !0);
1642
1678
  const r = await this.semaphore.acquire();
1643
- return await m(this, h, j).call(this, () => {
1679
+ return await y(this, h, q).call(this, () => {
1644
1680
  const s = e.env || {};
1645
1681
  for (const [n, i] of Object.entries(s))
1646
- m(this, h, U).call(this, n, i);
1682
+ y(this, h, j).call(this, n, i);
1647
1683
  t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
1648
1684
  for (const n of t)
1649
1685
  this[__private__dont__use].ccall(
@@ -1675,13 +1711,13 @@ class PHP {
1675
1711
  this[__private__dont__use]._exit(t);
1676
1712
  } catch {
1677
1713
  }
1678
- w(this, H, !1), w(this, b, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1714
+ w(this, b, !1), w(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1679
1715
  }
1680
1716
  [Symbol.dispose]() {
1681
1717
  this.exit(0);
1682
1718
  }
1683
1719
  }
1684
- k = new WeakMap(), H = new WeakMap(), b = new WeakMap(), E = new WeakMap(), T = new WeakMap(), C = new WeakMap(), _ = new WeakMap(), h = new WeakSet(), /**
1720
+ C = new WeakMap(), b = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F = new WeakMap(), M = new WeakMap(), _ = new WeakMap(), h = new WeakSet(), /**
1685
1721
  * Prepares the $_SERVER entries for the PHP runtime.
1686
1722
  *
1687
1723
  * @param defaults Default entries to include in $_SERVER.
@@ -1690,7 +1726,7 @@ k = new WeakMap(), H = new WeakMap(), b = new WeakMap(), E = new WeakMap(), T =
1690
1726
  * was provided.
1691
1727
  * @returns Computed $_SERVER entries.
1692
1728
  */
1693
- B = function(t, e, r) {
1729
+ z = function(t, e, r) {
1694
1730
  const s = {
1695
1731
  ...t || {}
1696
1732
  };
@@ -1700,7 +1736,7 @@ B = function(t, e, r) {
1700
1736
  ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1701
1737
  }
1702
1738
  return s;
1703
- }, z = function(t) {
1739
+ }, $ = function(t) {
1704
1740
  this[__private__dont__use].ccall(
1705
1741
  "wasm_set_request_uri",
1706
1742
  null,
@@ -1714,35 +1750,35 @@ B = function(t, e, r) {
1714
1750
  [STRING],
1715
1751
  [e]
1716
1752
  );
1717
- }, $ = function(t) {
1753
+ }, V = function(t) {
1718
1754
  this[__private__dont__use].ccall(
1719
1755
  "wasm_set_request_host",
1720
1756
  null,
1721
1757
  [STRING],
1722
1758
  [t]
1723
1759
  );
1724
- }, V = function(t) {
1760
+ }, G = function(t) {
1725
1761
  this[__private__dont__use].ccall(
1726
1762
  "wasm_set_request_port",
1727
1763
  null,
1728
1764
  [NUMBER],
1729
1765
  [t]
1730
1766
  );
1731
- }, G = function(t, e) {
1767
+ }, J = function(t, e) {
1732
1768
  let r;
1733
1769
  try {
1734
1770
  r = parseInt(new URL(t).port, 10);
1735
1771
  } catch {
1736
1772
  }
1737
1773
  return (!r || isNaN(r) || r === 80) && (r = e === "https" ? 443 : 80), r;
1738
- }, J = function(t) {
1774
+ }, Y = function(t) {
1739
1775
  this[__private__dont__use].ccall(
1740
1776
  "wasm_set_request_method",
1741
1777
  null,
1742
1778
  [STRING],
1743
1779
  [t]
1744
1780
  );
1745
- }, Y = function(t) {
1781
+ }, K = function(t) {
1746
1782
  t.cookie && this[__private__dont__use].ccall(
1747
1783
  "wasm_set_cookies",
1748
1784
  null,
@@ -1759,7 +1795,7 @@ B = function(t, e, r) {
1759
1795
  [NUMBER],
1760
1796
  [parseInt(t["content-length"], 10)]
1761
1797
  );
1762
- }, K = function(t) {
1798
+ }, X = function(t) {
1763
1799
  let e, r;
1764
1800
  typeof t == "string" ? (logger.warn(
1765
1801
  "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"
@@ -1782,28 +1818,28 @@ B = function(t, e, r) {
1782
1818
  [NUMBER],
1783
1819
  [r]
1784
1820
  ), s;
1785
- }, L = function(t) {
1821
+ }, U = function(t) {
1786
1822
  this[__private__dont__use].ccall(
1787
1823
  "wasm_set_path_translated",
1788
1824
  null,
1789
1825
  [STRING],
1790
1826
  [t]
1791
1827
  );
1792
- }, X = function(t, e) {
1828
+ }, Q = function(t, e) {
1793
1829
  this[__private__dont__use].ccall(
1794
1830
  "wasm_add_SERVER_entry",
1795
1831
  null,
1796
1832
  [STRING, STRING],
1797
1833
  [t, e]
1798
1834
  );
1799
- }, U = function(t, e) {
1835
+ }, j = function(t, e) {
1800
1836
  this[__private__dont__use].ccall(
1801
1837
  "wasm_add_ENV_entry",
1802
1838
  null,
1803
1839
  [STRING, STRING],
1804
1840
  [t, e]
1805
1841
  );
1806
- }, j = async function(t) {
1842
+ }, q = async function(t) {
1807
1843
  u(this, _).enabled && u(this, _).needsRotating && await this.rotateRuntime(), ++u(this, _).requestsMade, u(this, _).requestsMade >= u(this, _).maxRequests && (u(this, _).needsRotating = !0);
1808
1844
  const e = this[__private__dont__use], r = await createInvertedReadableStream();
1809
1845
  e.onHeaders = (d) => {
@@ -1826,11 +1862,11 @@ B = function(t, e, r) {
1826
1862
  try {
1827
1863
  return await Promise.race([
1828
1864
  t(),
1829
- new Promise((g, R) => {
1830
- var q;
1831
- c = (D) => {
1832
- isExitCode(D.error) || R(D.error);
1833
- }, (q = u(this, b)) == null || q.addEventListener(
1865
+ new Promise((g, H) => {
1866
+ var D;
1867
+ c = (W) => {
1868
+ isExitCode(W.error) || H(W.error);
1869
+ }, (D = u(this, T)) == null || D.addEventListener(
1834
1870
  "error",
1835
1871
  c,
1836
1872
  { once: !0 }
@@ -1849,7 +1885,7 @@ B = function(t, e, r) {
1849
1885
  });
1850
1886
  throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
1851
1887
  } finally {
1852
- a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, b)) == null || d.removeEventListener(
1888
+ a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, T)) == null || d.removeEventListener(
1853
1889
  "error",
1854
1890
  c
1855
1891
  );
@@ -2333,7 +2369,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2333
2369
  xspf,
2334
2370
  zip
2335
2371
  };
2336
- var x, M, N, F, I, P, A, v, S, Q, Z, ee;
2372
+ var S, I, L, k, A, x, N, v, R, Z, ee, te;
2337
2373
  class PHPRequestHandler {
2338
2374
  /**
2339
2375
  * The request handler needs to decide whether to serve a static asset or
@@ -2347,15 +2383,15 @@ class PHPRequestHandler {
2347
2383
  * @param config - Request Handler configuration.
2348
2384
  */
2349
2385
  constructor(e) {
2350
- y(this, S);
2351
- y(this, x);
2352
- y(this, M);
2353
- y(this, N);
2354
- y(this, F);
2355
- y(this, I);
2356
- y(this, P);
2357
- y(this, A);
2358
- y(this, v);
2386
+ m(this, R);
2387
+ m(this, S);
2388
+ m(this, I);
2389
+ m(this, L);
2390
+ m(this, k);
2391
+ m(this, A);
2392
+ m(this, x);
2393
+ m(this, N);
2394
+ m(this, v);
2359
2395
  const {
2360
2396
  documentRoot: r = "/www/",
2361
2397
  absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
@@ -2371,17 +2407,17 @@ class PHPRequestHandler {
2371
2407
  return l.isDir(r) || l.mkdir(r), l.chdir(r), l.requestHandler = this, l;
2372
2408
  },
2373
2409
  maxPhpInstances: e.maxPhpInstances
2374
- }), w(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, x, r);
2410
+ }), w(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, S, r);
2375
2411
  const o = new URL(s);
2376
- w(this, N, o.hostname), w(this, F, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), w(this, M, (o.protocol || "").replace(":", ""));
2377
- const a = u(this, F) !== 443 && u(this, F) !== 80;
2378
- w(this, I, [
2379
- u(this, N),
2380
- a ? `:${u(this, F)}` : ""
2381
- ].join("")), w(this, P, o.pathname.replace(/\/+$/, "")), w(this, A, [
2382
- `${u(this, M)}://`,
2383
- u(this, I),
2384
- u(this, P)
2412
+ w(this, L, o.hostname), w(this, k, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), w(this, I, (o.protocol || "").replace(":", ""));
2413
+ const a = u(this, k) !== 443 && u(this, k) !== 80;
2414
+ w(this, A, [
2415
+ u(this, L),
2416
+ a ? `:${u(this, k)}` : ""
2417
+ ].join("")), w(this, x, o.pathname.replace(/\/+$/, "")), w(this, N, [
2418
+ `${u(this, I)}://`,
2419
+ u(this, A),
2420
+ u(this, x)
2385
2421
  ].join("")), this.rewriteRules = n, this.getFileNotFoundAction = i;
2386
2422
  }
2387
2423
  async getPrimaryPhp() {
@@ -2406,20 +2442,20 @@ class PHPRequestHandler {
2406
2442
  */
2407
2443
  internalUrlToPath(e) {
2408
2444
  const r = new URL(e, "https://playground.internal");
2409
- return r.pathname.startsWith(u(this, P)) && (r.pathname = r.pathname.slice(u(this, P).length)), toRelativeUrl(r);
2445
+ return r.pathname.startsWith(u(this, x)) && (r.pathname = r.pathname.slice(u(this, x).length)), toRelativeUrl(r);
2410
2446
  }
2411
2447
  /**
2412
2448
  * The absolute URL of this PHPRequestHandler instance.
2413
2449
  */
2414
2450
  get absoluteUrl() {
2415
- return u(this, A);
2451
+ return u(this, N);
2416
2452
  }
2417
2453
  /**
2418
2454
  * The directory in the PHP filesystem where the server will look
2419
2455
  * for the files to serve. Default: `/var/www`.
2420
2456
  */
2421
2457
  get documentRoot() {
2422
- return u(this, x);
2458
+ return u(this, S);
2423
2459
  }
2424
2460
  /**
2425
2461
  * Serves the request – either by serving a static file, or by
@@ -2477,11 +2513,11 @@ class PHPRequestHandler {
2477
2513
  ), n = applyRewriteRules(
2478
2514
  removePathPrefix(
2479
2515
  decodeURIComponent(s.pathname),
2480
- u(this, P)
2516
+ u(this, x)
2481
2517
  ),
2482
2518
  this.rewriteRules
2483
2519
  ), i = await this.getPrimaryPhp();
2484
- let o = joinPaths(u(this, x), n);
2520
+ let o = joinPaths(u(this, S), n);
2485
2521
  if (i.isDir(o)) {
2486
2522
  if (!o.endsWith("/"))
2487
2523
  return new PHPResponse(
@@ -2505,7 +2541,7 @@ class PHPRequestHandler {
2505
2541
  case "response":
2506
2542
  return a.response;
2507
2543
  case "internal-redirect":
2508
- o = joinPaths(u(this, x), a.uri);
2544
+ o = joinPaths(u(this, S), a.uri);
2509
2545
  break;
2510
2546
  case "404":
2511
2547
  return PHPResponse.forHttpCode(404);
@@ -2521,7 +2557,7 @@ class PHPRequestHandler {
2521
2557
  ...e,
2522
2558
  // Pass along URL with the #fragment filtered out
2523
2559
  url: s.toString()
2524
- }, c = await m(this, S, Z).call(this, a, o);
2560
+ }, c = await y(this, R, ee).call(this, a, o);
2525
2561
  return c.ok() && c.exitCode !== 0 ? new PHPResponse(
2526
2562
  500,
2527
2563
  c.headers,
@@ -2530,7 +2566,7 @@ class PHPRequestHandler {
2530
2566
  c.exitCode
2531
2567
  ) : c;
2532
2568
  } else
2533
- return m(this, S, Q).call(this, i, o);
2569
+ return y(this, R, Z).call(this, i, o);
2534
2570
  else
2535
2571
  return PHPResponse.forHttpCode(404);
2536
2572
  }
@@ -2538,13 +2574,13 @@ class PHPRequestHandler {
2538
2574
  await this.processManager[Symbol.asyncDispose]();
2539
2575
  }
2540
2576
  }
2541
- x = new WeakMap(), M = new WeakMap(), N = new WeakMap(), F = new WeakMap(), I = new WeakMap(), P = new WeakMap(), A = new WeakMap(), v = new WeakMap(), S = new WeakSet(), /**
2577
+ S = new WeakMap(), I = new WeakMap(), L = new WeakMap(), k = new WeakMap(), A = new WeakMap(), x = new WeakMap(), N = new WeakMap(), v = new WeakMap(), R = new WeakSet(), /**
2542
2578
  * Serves a static file from the PHP filesystem.
2543
2579
  *
2544
2580
  * @param fsPath - Absolute path of the static file to serve.
2545
2581
  * @returns The response.
2546
2582
  */
2547
- Q = function(e, r) {
2583
+ Z = function(e, r) {
2548
2584
  const s = e.readFileAsBuffer(r);
2549
2585
  return new PHPResponse(
2550
2586
  200,
@@ -2559,7 +2595,7 @@ Q = function(e, r) {
2559
2595
  },
2560
2596
  s
2561
2597
  );
2562
- }, Z = async function(e, r) {
2598
+ }, ee = async function(e, r) {
2563
2599
  let s;
2564
2600
  try {
2565
2601
  s = await this.processManager.acquirePHPInstance({
@@ -2569,14 +2605,14 @@ Q = function(e, r) {
2569
2605
  return n instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2570
2606
  }
2571
2607
  try {
2572
- return await m(this, S, ee).call(this, s.php, e, r);
2608
+ return await y(this, R, te).call(this, s.php, e, r);
2573
2609
  } finally {
2574
2610
  s.reap();
2575
2611
  }
2576
- }, ee = async function(e, r, s) {
2612
+ }, te = async function(e, r, s) {
2577
2613
  let n = "GET";
2578
2614
  const i = {
2579
- host: u(this, I),
2615
+ host: u(this, A),
2580
2616
  ...normalizeHeaders(r.headers || {})
2581
2617
  };
2582
2618
  u(this, v) && (i.cookie = u(this, v).getCookieRequestHeader());
@@ -2590,14 +2626,14 @@ Q = function(e, r) {
2590
2626
  const a = await e.run({
2591
2627
  relativeUri: ensurePathPrefix(
2592
2628
  toRelativeUrl(new URL(r.url)),
2593
- u(this, P)
2629
+ u(this, x)
2594
2630
  ),
2595
- protocol: u(this, M),
2631
+ protocol: u(this, I),
2596
2632
  method: r.method || n,
2597
2633
  $_SERVER: {
2598
2634
  REMOTE_ADDR: "127.0.0.1",
2599
- DOCUMENT_ROOT: u(this, x),
2600
- HTTPS: u(this, A).startsWith("https://") ? "on" : ""
2635
+ DOCUMENT_ROOT: u(this, S),
2636
+ HTTPS: u(this, N).startsWith("https://") ? "on" : ""
2601
2637
  },
2602
2638
  body: o,
2603
2639
  scriptPath: s,
@@ -2885,7 +2921,7 @@ function expose(t, e = globalThis, r = ["*"], s) {
2885
2921
  }, l = (i.data.argumentList || []).map(fromWireValue);
2886
2922
  let p;
2887
2923
  try {
2888
- const d = c.slice(0, -1).reduce((g, R) => g[R], t), f = c.reduce((g, R) => g[R], t);
2924
+ const d = c.slice(0, -1).reduce((g, H) => g[H], t), f = c.reduce((g, H) => g[H], t);
2889
2925
  switch (a) {
2890
2926
  case MessageType.GET:
2891
2927
  p = f;
@@ -2906,8 +2942,8 @@ function expose(t, e = globalThis, r = ["*"], s) {
2906
2942
  break;
2907
2943
  case MessageType.ENDPOINT:
2908
2944
  {
2909
- const { port1: g, port2: R } = new MessageChannel();
2910
- expose(t, R), p = transfer(g, [g]);
2945
+ const { port1: g, port2: H } = new MessageChannel();
2946
+ expose(t, H), p = transfer(g, [g]);
2911
2947
  }
2912
2948
  break;
2913
2949
  case MessageType.RELEASE: