@php-wasm/web 0.6.0 → 0.6.1

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.
@@ -0,0 +1,4 @@
1
+ const e = {};
2
+ export {
3
+ e as default
4
+ };
package/index.d.ts CHANGED
@@ -239,7 +239,7 @@ export interface IsomorphicLocalPHP extends RequestHandler {
239
239
  * @param key - The name of the constant.
240
240
  * @param value - The value of the constant.
241
241
  */
242
- defineConstant(key: string, value: string | number | null): void;
242
+ defineConstant(key: string, value: boolean | string | number | null): void;
243
243
  /**
244
244
  * Adds an event listener for a PHP event.
245
245
  * @param eventType - The type of event to listen for.
package/index.js CHANGED
@@ -2,12 +2,12 @@ var Q = (e, t, r) => {
2
2
  if (!t.has(e))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var l = (e, t, r) => (Q(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
5
+ var l = (e, t, r) => (Q(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);
9
9
  }, p = (e, t, r, s) => (Q(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
- var _ = (e, t, r) => (Q(e, t, "access private method"), r);
10
+ var m = (e, t, r) => (Q(e, t, "access private method"), r);
11
11
  if (typeof File > "u") {
12
12
  class e extends Blob {
13
13
  constructor(r, s, i) {
@@ -67,6 +67,9 @@ if (typeof CustomEvent > "u") {
67
67
  }
68
68
  globalThis.CustomEvent = e;
69
69
  }
70
+ typeof crypto > "u" && import("./__vite-browser-external-2447137e.js").then((e) => {
71
+ global.crypto = e;
72
+ });
70
73
  const kError = Symbol("error"), kMessage = Symbol("message");
71
74
  class ErrorEvent2 extends Event {
72
75
  /**
@@ -382,16 +385,16 @@ const SupportedPHPVersions = [
382
385
  "7.1",
383
386
  "7.0"
384
387
  ], LatestSupportedPHPVersion = SupportedPHPVersions[0];
385
- var b, x;
388
+ var R, H;
386
389
  class PHPBrowser {
387
390
  /**
388
391
  * @param server - The PHP server to browse.
389
392
  * @param config - The browser configuration.
390
393
  */
391
394
  constructor(t, r = {}) {
392
- u(this, b, void 0);
393
- u(this, x, void 0);
394
- this.requestHandler = t, p(this, b, {}), p(this, x, {
395
+ d(this, R, void 0);
396
+ d(this, H, void 0);
397
+ this.requestHandler = t, p(this, R, {}), p(this, H, {
395
398
  handleRedirects: !1,
396
399
  maxRedirects: 4,
397
400
  ...r
@@ -419,7 +422,7 @@ class PHPBrowser {
419
422
  cookie: this.serializeCookies()
420
423
  }
421
424
  });
422
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, x).handleRedirects && s.headers.location && r < l(this, x).maxRedirects) {
425
+ if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, H).handleRedirects && s.headers.location && r < l(this, H).maxRedirects) {
423
426
  const i = new URL(
424
427
  s.headers.location[0],
425
428
  this.requestHandler.absoluteUrl
@@ -457,19 +460,19 @@ class PHPBrowser {
457
460
  if (!r.includes("="))
458
461
  continue;
459
462
  const s = r.indexOf("="), i = r.substring(0, s), n = r.substring(s + 1).split(";")[0];
460
- l(this, b)[i] = n;
463
+ l(this, R)[i] = n;
461
464
  } catch (s) {
462
465
  console.error(s);
463
466
  }
464
467
  }
465
468
  serializeCookies() {
466
469
  const t = [];
467
- for (const r in l(this, b))
468
- t.push(`${r}=${l(this, b)[r]}`);
470
+ for (const r in l(this, R))
471
+ t.push(`${r}=${l(this, R)[r]}`);
469
472
  return t.join("; ");
470
473
  }
471
474
  }
472
- b = new WeakMap(), x = new WeakMap();
475
+ R = new WeakMap(), H = new WeakMap();
473
476
  const DEFAULT_BASE_URL = "http://example.com";
474
477
  function toRelativeUrl(e) {
475
478
  return e.toString().substring(e.origin.length);
@@ -480,7 +483,7 @@ function removePathPrefix(e, t) {
480
483
  function ensurePathPrefix(e, t) {
481
484
  return !t || e.startsWith(t) ? e : t + e;
482
485
  }
483
- var P, T, L, R, k, y, H, C, N, Z, U, X, O, ee;
486
+ var E, k, L, S, C, g, F, x, N, Z, U, X, B, ee;
484
487
  class PHPRequestHandler {
485
488
  /**
486
489
  * @param php - The PHP instance.
@@ -493,7 +496,7 @@ class PHPRequestHandler {
493
496
  * @param fsPath - Absolute path of the static file to serve.
494
497
  * @returns The response.
495
498
  */
496
- u(this, N);
499
+ d(this, N);
497
500
  /**
498
501
  * Runs the requested PHP file with all the request and $_SERVER
499
502
  * superglobals populated.
@@ -501,7 +504,7 @@ class PHPRequestHandler {
501
504
  * @param request - The request.
502
505
  * @returns The response.
503
506
  */
504
- u(this, U);
507
+ d(this, U);
505
508
  /**
506
509
  * Resolve the requested path to the filesystem path of the requested PHP file.
507
510
  *
@@ -511,31 +514,31 @@ class PHPRequestHandler {
511
514
  * @throws {Error} If the requested path doesn't exist.
512
515
  * @returns The resolved filesystem path.
513
516
  */
514
- u(this, O);
515
- u(this, P, void 0);
516
- u(this, T, void 0);
517
- u(this, L, void 0);
518
- u(this, R, void 0);
519
- u(this, k, void 0);
520
- u(this, y, void 0);
521
- u(this, H, void 0);
522
- u(this, C, void 0);
523
- p(this, C, new Semaphore({ concurrency: 1 }));
517
+ d(this, B);
518
+ d(this, E, void 0);
519
+ d(this, k, void 0);
520
+ d(this, L, void 0);
521
+ d(this, S, void 0);
522
+ d(this, C, void 0);
523
+ d(this, g, void 0);
524
+ d(this, F, void 0);
525
+ d(this, x, void 0);
526
+ p(this, x, new Semaphore({ concurrency: 1 }));
524
527
  const {
525
528
  documentRoot: s = "/www/",
526
529
  absoluteUrl: i = typeof location == "object" ? location == null ? void 0 : location.href : ""
527
530
  } = r;
528
- this.php = t, p(this, P, s);
531
+ this.php = t, p(this, E, s);
529
532
  const n = new URL(i);
530
- p(this, L, n.hostname), p(this, R, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), p(this, T, (n.protocol || "").replace(":", ""));
531
- const o = l(this, R) !== 443 && l(this, R) !== 80;
532
- p(this, k, [
533
+ p(this, L, n.hostname), p(this, S, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), p(this, k, (n.protocol || "").replace(":", ""));
534
+ const o = l(this, S) !== 443 && l(this, S) !== 80;
535
+ p(this, C, [
533
536
  l(this, L),
534
- o ? `:${l(this, R)}` : ""
535
- ].join("")), p(this, y, n.pathname.replace(/\/+$/, "")), p(this, H, [
536
- `${l(this, T)}://`,
537
- l(this, k),
538
- l(this, y)
537
+ o ? `:${l(this, S)}` : ""
538
+ ].join("")), p(this, g, n.pathname.replace(/\/+$/, "")), p(this, F, [
539
+ `${l(this, k)}://`,
540
+ l(this, C),
541
+ l(this, g)
539
542
  ].join(""));
540
543
  }
541
544
  /** @inheritDoc */
@@ -545,18 +548,18 @@ class PHPRequestHandler {
545
548
  /** @inheritDoc */
546
549
  internalUrlToPath(t) {
547
550
  const r = new URL(t);
548
- return r.pathname.startsWith(l(this, y)) && (r.pathname = r.pathname.slice(l(this, y).length)), toRelativeUrl(r);
551
+ return r.pathname.startsWith(l(this, g)) && (r.pathname = r.pathname.slice(l(this, g).length)), toRelativeUrl(r);
549
552
  }
550
553
  get isRequestRunning() {
551
- return l(this, C).running > 0;
554
+ return l(this, x).running > 0;
552
555
  }
553
556
  /** @inheritDoc */
554
557
  get absoluteUrl() {
555
- return l(this, H);
558
+ return l(this, F);
556
559
  }
557
560
  /** @inheritDoc */
558
561
  get documentRoot() {
559
- return l(this, P);
562
+ return l(this, E);
560
563
  }
561
564
  /** @inheritDoc */
562
565
  async request(t) {
@@ -565,12 +568,12 @@ class PHPRequestHandler {
565
568
  r ? void 0 : DEFAULT_BASE_URL
566
569
  ), i = removePathPrefix(
567
570
  s.pathname,
568
- l(this, y)
569
- ), n = `${l(this, P)}${i}`;
570
- return seemsLikeAPHPRequestHandlerPath(n) ? await _(this, U, X).call(this, t, s) : _(this, N, Z).call(this, n);
571
+ l(this, g)
572
+ ), n = `${l(this, E)}${i}`;
573
+ return seemsLikeAPHPRequestHandlerPath(n) ? await m(this, U, X).call(this, t, s) : m(this, N, Z).call(this, n);
571
574
  }
572
575
  }
573
- P = new WeakMap(), T = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), H = new WeakMap(), C = new WeakMap(), N = new WeakSet(), Z = function(t) {
576
+ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C = new WeakMap(), g = new WeakMap(), F = new WeakMap(), x = new WeakMap(), N = new WeakSet(), Z = function(t) {
574
577
  if (!this.php.fileExists(t))
575
578
  return new PHPResponse(
576
579
  404,
@@ -596,48 +599,56 @@ P = new WeakMap(), T = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
596
599
  r
597
600
  );
598
601
  }, U = new WeakSet(), X = async function(t, r) {
599
- var i, n;
600
- const s = await l(this, C).acquire();
602
+ var i, n, o;
603
+ if (l(this, x).running > 0 && ((i = t.headers) == null ? void 0 : i["x-request-issuer"]) === "php")
604
+ return console.warn(
605
+ "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."
606
+ ), new PHPResponse(
607
+ 502,
608
+ {},
609
+ new TextEncoder().encode("502 Bad Gateway")
610
+ );
611
+ const s = await l(this, x).acquire();
601
612
  try {
602
- this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, P)), this.php.addServerGlobalEntry(
613
+ this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, E)), this.php.addServerGlobalEntry(
603
614
  "HTTPS",
604
- l(this, H).startsWith("https://") ? "on" : ""
615
+ l(this, F).startsWith("https://") ? "on" : ""
605
616
  );
606
- let o = "GET";
607
- const a = {
608
- host: l(this, k),
617
+ let a = "GET";
618
+ const u = {
619
+ host: l(this, C),
609
620
  ...normalizeHeaders(t.headers || {})
610
- }, d = [];
621
+ }, c = [];
611
622
  if (t.files && Object.keys(t.files).length) {
612
- o = "POST";
623
+ a = "POST";
613
624
  for (const f in t.files) {
614
- const m = t.files[f];
615
- d.push({
625
+ const y = t.files[f];
626
+ c.push({
616
627
  key: f,
617
- name: m.name,
618
- type: m.type,
619
- data: new Uint8Array(await m.arrayBuffer())
628
+ name: y.name,
629
+ type: y.type,
630
+ data: new Uint8Array(await y.arrayBuffer())
620
631
  });
621
632
  }
622
- (i = a["content-type"]) != null && i.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
633
+ (n = u["content-type"]) != null && n.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
623
634
  t.body || ""
624
- ), a["content-type"] = "application/x-www-form-urlencoded", delete t.body);
635
+ ), u["content-type"] = "application/x-www-form-urlencoded", delete t.body);
625
636
  }
626
- let c;
627
- t.formData !== void 0 ? (o = "POST", a["content-type"] = a["content-type"] || "application/x-www-form-urlencoded", c = new URLSearchParams(
628
- t.formData
629
- ).toString()) : c = t.body;
630
637
  let h;
638
+ t.formData !== void 0 ? (a = "POST", u["content-type"] = u["content-type"] || "application/x-www-form-urlencoded", h = new URLSearchParams(
639
+ t.formData
640
+ ).toString()) : h = t.body;
641
+ let _;
631
642
  try {
632
643
  let f = r.pathname;
633
- if ((n = t.headers) != null && n["x-rewrite-url"])
644
+ if ((o = t.headers) != null && o["x-rewrite-url"])
634
645
  try {
635
646
  f = new URL(
636
647
  t.headers["x-rewrite-url"]
637
648
  ).pathname;
638
649
  } catch {
639
650
  }
640
- h = _(this, O, ee).call(this, f);
651
+ _ = m(this, B, ee).call(this, f);
641
652
  } catch {
642
653
  return new PHPResponse(
643
654
  404,
@@ -648,22 +659,22 @@ P = new WeakMap(), T = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
648
659
  return await this.php.run({
649
660
  relativeUri: ensurePathPrefix(
650
661
  toRelativeUrl(r),
651
- l(this, y)
662
+ l(this, g)
652
663
  ),
653
- protocol: l(this, T),
654
- method: t.method || o,
655
- body: c,
656
- fileInfos: d,
657
- scriptPath: h,
658
- headers: a
664
+ protocol: l(this, k),
665
+ method: t.method || a,
666
+ body: h,
667
+ fileInfos: c,
668
+ scriptPath: _,
669
+ headers: u
659
670
  });
660
671
  } finally {
661
672
  s();
662
673
  }
663
- }, O = new WeakSet(), ee = function(t) {
664
- let r = removePathPrefix(t, l(this, y));
674
+ }, B = new WeakSet(), ee = function(t) {
675
+ let r = removePathPrefix(t, l(this, g));
665
676
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
666
- const s = `${l(this, P)}${r}`;
677
+ const s = `${l(this, E)}${r}`;
667
678
  if (this.php.fileExists(s))
668
679
  return s;
669
680
  throw new Error(`File not found: ${s}`);
@@ -676,10 +687,10 @@ function parseMultipartFormDataString(e) {
676
687
  return i.shift(), i.pop(), i.forEach((n) => {
677
688
  const o = n.indexOf(`\r
678
689
  \r
679
- `), a = n.substring(0, o).trim(), d = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
690
+ `), a = n.substring(0, o).trim(), u = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
680
691
  if (c) {
681
692
  const h = c[1];
682
- t[h] = d;
693
+ t[h] = u;
683
694
  }
684
695
  }), t;
685
696
  }
@@ -823,10 +834,10 @@ function rethrowFileSystemError(e = "") {
823
834
  try {
824
835
  return n.apply(this, o);
825
836
  } catch (a) {
826
- const d = typeof a == "object" ? a == null ? void 0 : a.errno : null;
827
- if (d in FileErrorCodes) {
828
- const c = FileErrorCodes[d], h = typeof o[0] == "string" ? o[0] : null, f = h !== null ? e.replaceAll("{path}", h) : e;
829
- throw new Error(`${f}: ${c}`, {
837
+ const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
838
+ if (u in FileErrorCodes) {
839
+ const c = FileErrorCodes[u], h = typeof o[0] == "string" ? o[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
840
+ throw new Error(`${_}: ${c}`, {
830
841
  cause: a
831
842
  });
832
843
  }
@@ -877,7 +888,7 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
877
888
  return s && i && __defProp(t, r, i), i;
878
889
  };
879
890
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
880
- var S, F, M, g, E, v, w, I, B, te, W, re, z, se, D, ne, q, ie, $, oe, j, ae, G, le, V, ce, Y, ue, J, de, K, he;
891
+ var T, M, I, w, v, b, P, A, O, te, W, re, q, se, z, ne, D, ie, $, oe, j, ae, G, le, V, ce, Y, ue, J, de, K, he;
881
892
  class BasePHP {
882
893
  /**
883
894
  * Initializes a PHP runtime.
@@ -887,15 +898,15 @@ class BasePHP {
887
898
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
888
899
  */
889
900
  constructor(e, t) {
890
- u(this, B);
891
- u(this, W);
892
- u(this, z);
893
- u(this, D);
894
- u(this, q);
895
- u(this, $);
896
- u(this, j);
897
- u(this, G);
898
- u(this, V);
901
+ d(this, O);
902
+ d(this, W);
903
+ d(this, q);
904
+ d(this, z);
905
+ d(this, D);
906
+ d(this, $);
907
+ d(this, j);
908
+ d(this, G);
909
+ d(this, V);
899
910
  /**
900
911
  * Adds file information to $_FILES superglobal in PHP.
901
912
  *
@@ -905,37 +916,37 @@ class BasePHP {
905
916
  *
906
917
  * @param fileInfo - File details
907
918
  */
908
- u(this, Y);
909
- u(this, J);
910
- u(this, K);
911
- u(this, S, void 0);
912
- u(this, F, void 0);
913
- u(this, M, void 0);
914
- u(this, g, void 0);
915
- u(this, E, void 0);
916
- u(this, v, void 0);
917
- u(this, w, void 0);
918
- u(this, I, void 0);
919
- p(this, S, []), p(this, g, !1), p(this, E, null), p(this, v, {}), p(this, w, /* @__PURE__ */ new Map()), p(this, I, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
919
+ d(this, Y);
920
+ d(this, J);
921
+ d(this, K);
922
+ d(this, T, void 0);
923
+ d(this, M, void 0);
924
+ d(this, I, void 0);
925
+ d(this, w, void 0);
926
+ d(this, v, void 0);
927
+ d(this, b, void 0);
928
+ d(this, P, void 0);
929
+ d(this, A, void 0);
930
+ p(this, T, []), p(this, w, !1), p(this, v, null), p(this, b, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, A, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
920
931
  new PHPRequestHandler(this, t)
921
932
  ));
922
933
  }
923
934
  addEventListener(e, t) {
924
- l(this, w).has(e) || l(this, w).set(e, /* @__PURE__ */ new Set()), l(this, w).get(e).add(t);
935
+ l(this, P).has(e) || l(this, P).set(e, /* @__PURE__ */ new Set()), l(this, P).get(e).add(t);
925
936
  }
926
937
  removeEventListener(e, t) {
927
938
  var r;
928
- (r = l(this, w).get(e)) == null || r.delete(t);
939
+ (r = l(this, P).get(e)) == null || r.delete(t);
929
940
  }
930
941
  dispatchEvent(e) {
931
- const t = l(this, w).get(e.type);
942
+ const t = l(this, P).get(e.type);
932
943
  if (t)
933
944
  for (const r of t)
934
945
  r(e);
935
946
  }
936
947
  /** @inheritDoc */
937
948
  async onMessage(e) {
938
- l(this, I).push(e);
949
+ l(this, A).push(e);
939
950
  }
940
951
  /** @inheritDoc */
941
952
  async setSpawnHandler(handler) {
@@ -966,13 +977,13 @@ class BasePHP {
966
977
  if (!t)
967
978
  throw new Error("Invalid PHP runtime id.");
968
979
  this[__private__dont__use] = t, t.onMessage = async (r) => {
969
- for (const s of l(this, I)) {
980
+ for (const s of l(this, A)) {
970
981
  const i = await s(r);
971
982
  if (i)
972
983
  return i;
973
984
  }
974
985
  return "";
975
- }, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
986
+ }, p(this, v, improveWASMErrorReporting(t)), this.dispatchEvent({
976
987
  type: "runtime.initialized"
977
988
  });
978
989
  }
@@ -987,13 +998,13 @@ class BasePHP {
987
998
  throw new Error(
988
999
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
989
1000
  );
990
- p(this, M, e);
1001
+ p(this, I, e);
991
1002
  }
992
1003
  /** @inheritDoc */
993
1004
  setPhpIniPath(e) {
994
- if (l(this, g))
1005
+ if (l(this, w))
995
1006
  throw new Error("Cannot set PHP ini path after calling run().");
996
- p(this, F, e), this[__private__dont__use].ccall(
1007
+ p(this, M, e), this[__private__dont__use].ccall(
997
1008
  "wasm_set_phpini_path",
998
1009
  null,
999
1010
  ["string"],
@@ -1002,9 +1013,9 @@ class BasePHP {
1002
1013
  }
1003
1014
  /** @inheritDoc */
1004
1015
  setPhpIniEntry(e, t) {
1005
- if (l(this, g))
1016
+ if (l(this, w))
1006
1017
  throw new Error("Cannot set PHP ini entries after calling run().");
1007
- l(this, S).push([e, t]);
1018
+ l(this, T).push([e, t]);
1008
1019
  }
1009
1020
  /** @inheritDoc */
1010
1021
  chdir(e) {
@@ -1021,13 +1032,13 @@ class BasePHP {
1021
1032
  const t = await this.semaphore.acquire();
1022
1033
  let r;
1023
1034
  try {
1024
- l(this, g) || (_(this, B, te).call(this), p(this, g, !0)), _(this, G, le).call(this, e.scriptPath || ""), _(this, z, se).call(this, e.relativeUri || ""), _(this, q, ie).call(this, e.method || "GET");
1035
+ l(this, w) || (m(this, O, te).call(this), p(this, w, !0)), m(this, G, le).call(this, e.scriptPath || ""), m(this, q, se).call(this, e.relativeUri || ""), m(this, D, ie).call(this, e.method || "GET");
1025
1036
  const s = normalizeHeaders(e.headers || {}), i = s.host || "example.com:443";
1026
- if (_(this, D, ne).call(this, i, e.protocol || "http"), _(this, $, oe).call(this, s), e.body && (r = _(this, j, ae).call(this, e.body)), e.fileInfos)
1037
+ if (m(this, z, ne).call(this, i, e.protocol || "http"), m(this, $, oe).call(this, s), e.body && (r = m(this, j, ae).call(this, e.body)), e.fileInfos)
1027
1038
  for (const o of e.fileInfos)
1028
- _(this, Y, ue).call(this, o);
1029
- typeof e.code == "string" && _(this, J, de).call(this, " ?>" + e.code), _(this, V, ce).call(this);
1030
- const n = await _(this, K, he).call(this);
1039
+ m(this, Y, ue).call(this, o);
1040
+ typeof e.code == "string" && m(this, J, de).call(this, " ?>" + e.code), m(this, V, ce).call(this);
1041
+ const n = await m(this, K, he).call(this);
1031
1042
  if (e.throwOnError && n.exitCode !== 0) {
1032
1043
  const o = {
1033
1044
  stdout: n.text,
@@ -1051,7 +1062,7 @@ class BasePHP {
1051
1062
  }
1052
1063
  }
1053
1064
  addServerGlobalEntry(e, t) {
1054
- l(this, v)[e] = t;
1065
+ l(this, b)[e] = t;
1055
1066
  }
1056
1067
  defineConstant(e, t) {
1057
1068
  let r = {};
@@ -1147,7 +1158,7 @@ class BasePHP {
1147
1158
  this.exit();
1148
1159
  } catch {
1149
1160
  }
1150
- if (this.initializeRuntime(e), l(this, F) && this.setPhpIniPath(l(this, F)), l(this, M) && this.setSapiName(l(this, M)), this.requestHandler) {
1161
+ if (this.initializeRuntime(e), l(this, M) && this.setPhpIniPath(l(this, M)), l(this, I) && this.setSapiName(l(this, I)), this.requestHandler) {
1151
1162
  const r = this.documentRoot;
1152
1163
  recreateMemFS(this[__private__dont__use].FS, t, r);
1153
1164
  }
@@ -1160,10 +1171,10 @@ class BasePHP {
1160
1171
  this[__private__dont__use]._exit(e);
1161
1172
  } catch {
1162
1173
  }
1163
- p(this, g, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1174
+ p(this, w, !1), p(this, v, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1164
1175
  }
1165
1176
  }
1166
- S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E = new WeakMap(), v = new WeakMap(), w = new WeakMap(), I = new WeakMap(), B = new WeakSet(), te = function() {
1177
+ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v = new WeakMap(), b = new WeakMap(), P = new WeakMap(), A = new WeakMap(), O = new WeakSet(), te = function() {
1167
1178
  if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
1168
1179
  "/tmp/consts.php",
1169
1180
  `<?php
@@ -1175,8 +1186,8 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1175
1186
  }
1176
1187
  }
1177
1188
  }`
1178
- ), l(this, S).length > 0) {
1179
- const e = l(this, S).map(([t, r]) => `${t}=${r}`).join(`
1189
+ ), l(this, T).length > 0) {
1190
+ const e = l(this, T).map(([t, r]) => `${t}=${r}`).join(`
1180
1191
  `) + `
1181
1192
 
1182
1193
  `;
@@ -1205,7 +1216,7 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1205
1216
  headers: r,
1206
1217
  httpStatusCode: t.status
1207
1218
  };
1208
- }, z = new WeakSet(), se = function(e) {
1219
+ }, q = new WeakSet(), se = function(e) {
1209
1220
  if (this[__private__dont__use].ccall(
1210
1221
  "wasm_set_request_uri",
1211
1222
  null,
@@ -1220,7 +1231,7 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1220
1231
  [t]
1221
1232
  );
1222
1233
  }
1223
- }, D = new WeakSet(), ne = function(e, t) {
1234
+ }, z = new WeakSet(), ne = function(e, t) {
1224
1235
  this[__private__dont__use].ccall(
1225
1236
  "wasm_set_request_host",
1226
1237
  null,
@@ -1238,7 +1249,7 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1238
1249
  [NUMBER],
1239
1250
  [r]
1240
1251
  ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1241
- }, q = new WeakSet(), ie = function(e) {
1252
+ }, D = new WeakSet(), ie = function(e) {
1242
1253
  this[__private__dont__use].ccall(
1243
1254
  "wasm_set_request_method",
1244
1255
  null,
@@ -1296,12 +1307,12 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1296
1307
  [e]
1297
1308
  );
1298
1309
  }, V = new WeakSet(), ce = function() {
1299
- for (const e in l(this, v))
1310
+ for (const e in l(this, b))
1300
1311
  this[__private__dont__use].ccall(
1301
1312
  "wasm_add_SERVER_entry",
1302
1313
  null,
1303
1314
  [STRING, STRING],
1304
- [e, l(this, v)[e]]
1315
+ [e, l(this, b)[e]]
1305
1316
  );
1306
1317
  }, Y = new WeakSet(), ue = function(e) {
1307
1318
  const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
@@ -1325,11 +1336,11 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1325
1336
  let e, t;
1326
1337
  try {
1327
1338
  e = await new Promise((n, o) => {
1328
- var d;
1339
+ var u;
1329
1340
  t = (c) => {
1330
1341
  const h = new Error("Rethrown");
1331
1342
  h.cause = c.error, h.betterMessage = c.message, o(h);
1332
- }, (d = l(this, E)) == null || d.addEventListener(
1343
+ }, (u = l(this, v)) == null || u.addEventListener(
1333
1344
  "error",
1334
1345
  t
1335
1346
  );
@@ -1350,12 +1361,12 @@ S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E =
1350
1361
  );
1351
1362
  });
1352
1363
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1353
- const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, d = new Error(a);
1354
- throw d.cause = o, d;
1364
+ const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, u = new Error(a);
1365
+ throw u.cause = o, u;
1355
1366
  } finally {
1356
- (i = l(this, E)) == null || i.removeEventListener("error", t), p(this, v, {});
1367
+ (i = l(this, v)) == null || i.removeEventListener("error", t), p(this, b, {});
1357
1368
  }
1358
- const { headers: r, httpStatusCode: s } = _(this, W, re).call(this);
1369
+ const { headers: r, httpStatusCode: s } = m(this, W, re).call(this);
1359
1370
  return new PHPResponse(
1360
1371
  s,
1361
1372
  r,
@@ -1471,30 +1482,30 @@ function expose(e, t = globalThis, r = ["*"]) {
1471
1482
  console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
1472
1483
  return;
1473
1484
  }
1474
- const { id: n, type: o, path: a } = Object.assign({ path: [] }, i.data), d = (i.data.argumentList || []).map(fromWireValue);
1485
+ const { id: n, type: o, path: a } = Object.assign({ path: [] }, i.data), u = (i.data.argumentList || []).map(fromWireValue);
1475
1486
  let c;
1476
1487
  try {
1477
- const h = a.slice(0, -1).reduce((m, A) => m[A], e), f = a.reduce((m, A) => m[A], e);
1488
+ const h = a.slice(0, -1).reduce((f, y) => f[y], e), _ = a.reduce((f, y) => f[y], e);
1478
1489
  switch (o) {
1479
1490
  case "GET":
1480
- c = f;
1491
+ c = _;
1481
1492
  break;
1482
1493
  case "SET":
1483
1494
  h[a.slice(-1)[0]] = fromWireValue(i.data.value), c = !0;
1484
1495
  break;
1485
1496
  case "APPLY":
1486
- c = f.apply(h, d);
1497
+ c = _.apply(h, u);
1487
1498
  break;
1488
1499
  case "CONSTRUCT":
1489
1500
  {
1490
- const m = new f(...d);
1491
- c = proxy(m);
1501
+ const f = new _(...u);
1502
+ c = proxy(f);
1492
1503
  }
1493
1504
  break;
1494
1505
  case "ENDPOINT":
1495
1506
  {
1496
- const { port1: m, port2: A } = new MessageChannel();
1497
- expose(e, A), c = transfer(m, [m]);
1507
+ const { port1: f, port2: y } = new MessageChannel();
1508
+ expose(e, y), c = transfer(f, [f]);
1498
1509
  }
1499
1510
  break;
1500
1511
  case "RELEASE":
@@ -1507,14 +1518,14 @@ function expose(e, t = globalThis, r = ["*"]) {
1507
1518
  c = { value: h, [throwMarker]: 0 };
1508
1519
  }
1509
1520
  Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1510
- const [f, m] = toWireValue(h);
1511
- t.postMessage(Object.assign(Object.assign({}, f), { id: n }), m), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1521
+ const [_, f] = toWireValue(h);
1522
+ t.postMessage(Object.assign(Object.assign({}, _), { id: n }), f), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1512
1523
  }).catch((h) => {
1513
- const [f, m] = toWireValue({
1524
+ const [_, f] = toWireValue({
1514
1525
  value: new TypeError("Unserializable return value"),
1515
1526
  [throwMarker]: 0
1516
1527
  });
1517
- t.postMessage(Object.assign(Object.assign({}, f), { id: n }), m);
1528
+ t.postMessage(Object.assign(Object.assign({}, _), { id: n }), f);
1518
1529
  });
1519
1530
  }), t.start && t.start();
1520
1531
  }
@@ -1563,7 +1574,7 @@ function createProxy(e, t = [], r = function() {
1563
1574
  return { then: () => i };
1564
1575
  const a = requestResponseMessage(e, {
1565
1576
  type: "GET",
1566
- path: t.map((d) => d.toString())
1577
+ path: t.map((u) => u.toString())
1567
1578
  }).then(fromWireValue);
1568
1579
  return a.then.bind(a);
1569
1580
  }
@@ -1571,37 +1582,37 @@ function createProxy(e, t = [], r = function() {
1571
1582
  },
1572
1583
  set(n, o, a) {
1573
1584
  throwIfProxyReleased(s);
1574
- const [d, c] = toWireValue(a);
1585
+ const [u, c] = toWireValue(a);
1575
1586
  return requestResponseMessage(e, {
1576
1587
  type: "SET",
1577
1588
  path: [...t, o].map((h) => h.toString()),
1578
- value: d
1589
+ value: u
1579
1590
  }, c).then(fromWireValue);
1580
1591
  },
1581
1592
  apply(n, o, a) {
1582
1593
  throwIfProxyReleased(s);
1583
- const d = t[t.length - 1];
1584
- if (d === createEndpoint)
1594
+ const u = t[t.length - 1];
1595
+ if (u === createEndpoint)
1585
1596
  return requestResponseMessage(e, {
1586
1597
  type: "ENDPOINT"
1587
1598
  }).then(fromWireValue);
1588
- if (d === "bind")
1599
+ if (u === "bind")
1589
1600
  return createProxy(e, t.slice(0, -1));
1590
1601
  const [c, h] = processArguments(a);
1591
1602
  return requestResponseMessage(e, {
1592
1603
  type: "APPLY",
1593
- path: t.map((f) => f.toString()),
1604
+ path: t.map((_) => _.toString()),
1594
1605
  argumentList: c
1595
1606
  }, h).then(fromWireValue);
1596
1607
  },
1597
1608
  construct(n, o) {
1598
1609
  throwIfProxyReleased(s);
1599
- const [a, d] = processArguments(o);
1610
+ const [a, u] = processArguments(o);
1600
1611
  return requestResponseMessage(e, {
1601
1612
  type: "CONSTRUCT",
1602
1613
  path: t.map((c) => c.toString()),
1603
1614
  argumentList: a
1604
- }, d).then(fromWireValue);
1615
+ }, u).then(fromWireValue);
1605
1616
  }
1606
1617
  });
1607
1618
  return registerProxy(i, e), i;
@@ -1690,10 +1701,10 @@ function exposeAPI(e, t) {
1690
1701
  setupTransferHandlers();
1691
1702
  const r = Promise.resolve();
1692
1703
  let s, i;
1693
- const n = new Promise((d, c) => {
1694
- s = d, i = c;
1704
+ const n = new Promise((u, c) => {
1705
+ s = u, i = c;
1695
1706
  }), o = proxyClone(e), a = new Proxy(o, {
1696
- get: (d, c) => c === "isConnected" ? () => r : c === "isReady" ? () => n : c in d ? d[c] : t == null ? void 0 : t[c]
1707
+ get: (u, c) => c === "isConnected" ? () => r : c === "isReady" ? () => n : c in u ? u[c] : t == null ? void 0 : t[c]
1697
1708
  });
1698
1709
  return expose(
1699
1710
  a,
@@ -1976,7 +1987,7 @@ async function registerServiceWorker(e, t, r) {
1976
1987
  async function(o) {
1977
1988
  if (console.debug("[window][sw] Message from ServiceWorker", o), t && o.data.scope !== t)
1978
1989
  return;
1979
- const a = o.data.args || [], d = o.data.method, c = await e[d](...a);
1990
+ const a = o.data.args || [], u = o.data.method, c = await e[u](...a);
1980
1991
  o.source.postMessage(responseTo(o.data.requestId, c));
1981
1992
  }
1982
1993
  ), s.startMessages();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,15 +29,15 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "3f137306ec8e3b10ec0674a1fe69ee43349edb4a",
32
+ "gitHead": "171b22b853786b8912d9624ea064eaa1e985e96b",
33
33
  "engines": {
34
34
  "node": ">=16.15.1",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "comlink": "^4.4.1",
39
- "@php-wasm/universal": "0.6.0",
40
- "@php-wasm/web-service-worker": "0.6.0",
41
- "@php-wasm/progress": "0.6.0"
39
+ "@php-wasm/universal": "0.6.1",
40
+ "@php-wasm/web-service-worker": "0.6.1",
41
+ "@php-wasm/progress": "0.6.1"
42
42
  }
43
43
  }