@php-wasm/web 0.1.37 → 0.1.39

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.
@@ -1,9 +1,9 @@
1
- class R {
2
- constructor(e, r, n, s = "", a = 0) {
3
- this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = a, this.errors = s;
1
+ class v {
2
+ constructor(e, r, n, s = "", o = 0) {
3
+ this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
4
4
  }
5
5
  static fromRawData(e) {
6
- return new R(
6
+ return new v(
7
7
  e.httpStatusCode,
8
8
  e.headers,
9
9
  e.bytes,
@@ -33,7 +33,7 @@ class R {
33
33
  return new TextDecoder().decode(this.bytes);
34
34
  }
35
35
  }
36
- const Q = [
36
+ const ie = [
37
37
  "8.2",
38
38
  "8.1",
39
39
  "8.0",
@@ -43,8 +43,8 @@ const Q = [
43
43
  "7.1",
44
44
  "7.0",
45
45
  "5.6"
46
- ], X = Q[0];
47
- class Z {
46
+ ], oe = ie[0];
47
+ class ae {
48
48
  #e;
49
49
  #t;
50
50
  /**
@@ -77,10 +77,10 @@ class Z {
77
77
  ...e,
78
78
  headers: {
79
79
  ...e.headers,
80
- cookie: this.#n()
80
+ cookie: this.#s()
81
81
  }
82
82
  });
83
- if (n.headers["set-cookie"] && this.#s(n.headers["set-cookie"]), this.#t.handleRedirects && n.headers.location && r < this.#t.maxRedirects) {
83
+ if (n.headers["set-cookie"] && this.#r(n.headers["set-cookie"]), this.#t.handleRedirects && n.headers.location && r < this.#t.maxRedirects) {
84
84
  const s = new URL(
85
85
  n.headers.location[0],
86
86
  this.requestHandler.absoluteUrl
@@ -112,25 +112,25 @@ class Z {
112
112
  get documentRoot() {
113
113
  return this.requestHandler.documentRoot;
114
114
  }
115
- #s(e) {
115
+ #r(e) {
116
116
  for (const r of e)
117
117
  try {
118
118
  if (!r.includes("="))
119
119
  continue;
120
- const n = r.indexOf("="), s = r.substring(0, n), a = r.substring(n + 1).split(";")[0];
121
- this.#e[s] = a;
120
+ const n = r.indexOf("="), s = r.substring(0, n), o = r.substring(n + 1).split(";")[0];
121
+ this.#e[s] = o;
122
122
  } catch (n) {
123
123
  console.error(n);
124
124
  }
125
125
  }
126
- #n() {
126
+ #s() {
127
127
  const e = [];
128
128
  for (const r in this.#e)
129
129
  e.push(`${r}=${this.#e[r]}`);
130
130
  return e.join("; ");
131
131
  }
132
132
  }
133
- class ee {
133
+ class ce {
134
134
  constructor({ concurrency: e }) {
135
135
  this._running = 0, this.concurrency = e, this.queue = [];
136
136
  }
@@ -155,48 +155,48 @@ class ee {
155
155
  }
156
156
  }
157
157
  }
158
- const te = "http://example.com";
159
- function L(t) {
158
+ const le = "http://example.com";
159
+ function W(t) {
160
160
  return t.toString().substring(t.origin.length);
161
161
  }
162
- function N(t, e) {
162
+ function D(t, e) {
163
163
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
164
164
  }
165
- function re(t, e) {
165
+ function ue(t, e) {
166
166
  return !e || t.startsWith(e) ? t : e + t;
167
167
  }
168
- class ne {
168
+ class he {
169
169
  #e;
170
170
  #t;
171
+ #r;
171
172
  #s;
172
- #n;
173
173
  #i;
174
- #r;
174
+ #n;
175
175
  #o;
176
176
  #a;
177
- #l;
177
+ #c;
178
178
  /**
179
179
  * @param php - The PHP instance.
180
180
  * @param config - Request Handler configuration.
181
181
  */
182
182
  constructor(e, r = {}) {
183
- this.#a = new ee({ concurrency: 1 });
183
+ this.#a = new ce({ concurrency: 1 });
184
184
  const {
185
185
  documentRoot: n = "/www/",
186
186
  absoluteUrl: s = typeof location == "object" ? location?.href : "",
187
- isStaticFilePath: a = () => !1
187
+ isStaticFilePath: o = () => !1
188
188
  } = r;
189
- this.php = e, this.#e = n, this.#l = a;
189
+ this.php = e, this.#e = n, this.#c = o;
190
190
  const i = new URL(s);
191
- this.#s = i.hostname, this.#n = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
192
- const o = this.#n !== 443 && this.#n !== 80;
191
+ this.#r = i.hostname, this.#s = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
192
+ const a = this.#s !== 443 && this.#s !== 80;
193
193
  this.#i = [
194
- this.#s,
195
- o ? `:${this.#n}` : ""
196
- ].join(""), this.#r = i.pathname.replace(/\/+$/, ""), this.#o = [
194
+ this.#r,
195
+ a ? `:${this.#s}` : ""
196
+ ].join(""), this.#n = i.pathname.replace(/\/+$/, ""), this.#o = [
197
197
  `${this.#t}://`,
198
198
  this.#i,
199
- this.#r
199
+ this.#n
200
200
  ].join("");
201
201
  }
202
202
  /** @inheritDoc */
@@ -206,7 +206,7 @@ class ne {
206
206
  /** @inheritDoc */
207
207
  internalUrlToPath(e) {
208
208
  const r = new URL(e);
209
- return r.pathname.startsWith(this.#r) && (r.pathname = r.pathname.slice(this.#r.length)), L(r);
209
+ return r.pathname.startsWith(this.#n) && (r.pathname = r.pathname.slice(this.#n.length)), W(r);
210
210
  }
211
211
  get isRequestRunning() {
212
212
  return this.#a.running > 0;
@@ -223,12 +223,12 @@ class ne {
223
223
  async request(e) {
224
224
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
225
225
  e.url,
226
- r ? void 0 : te
227
- ), s = N(
226
+ r ? void 0 : le
227
+ ), s = D(
228
228
  n.pathname,
229
- this.#r
229
+ this.#n
230
230
  );
231
- return this.#l(s) ? this.#c(s) : await this.#u(e, n);
231
+ return this.#c(s) ? this.#l(s) : await this.#u(e, n);
232
232
  }
233
233
  /**
234
234
  * Serves a static file from the PHP filesystem.
@@ -236,23 +236,23 @@ class ne {
236
236
  * @param path - The requested static file path.
237
237
  * @returns The response.
238
238
  */
239
- #c(e) {
239
+ #l(e) {
240
240
  const r = `${this.#e}${e}`;
241
241
  if (!this.php.fileExists(r))
242
- return new R(
242
+ return new v(
243
243
  404,
244
244
  {},
245
245
  new TextEncoder().encode("404 File not found")
246
246
  );
247
247
  const n = this.php.readFileAsBuffer(r);
248
- return new R(
248
+ return new v(
249
249
  200,
250
250
  {
251
251
  "content-length": [`${n.byteLength}`],
252
252
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
253
253
  // The code below won't return the correct mime-type if the extension
254
254
  // was tampered with.
255
- "content-type": [ie(r)],
255
+ "content-type": [fe(r)],
256
256
  "accept-ranges": ["bytes"],
257
257
  "cache-control": ["public, max-age=0"]
258
258
  },
@@ -274,39 +274,39 @@ class ne {
274
274
  this.#o.startsWith("https://") ? "on" : ""
275
275
  );
276
276
  let s = "GET";
277
- const a = {
277
+ const o = {
278
278
  host: this.#i,
279
- ...z(e.headers || {})
279
+ ...K(e.headers || {})
280
280
  }, i = [];
281
281
  if (e.files && Object.keys(e.files).length) {
282
282
  s = "POST";
283
- for (const l in e.files) {
284
- const u = e.files[l];
283
+ for (const c in e.files) {
284
+ const l = e.files[c];
285
285
  i.push({
286
- key: l,
287
- name: u.name,
288
- type: u.type,
289
- data: new Uint8Array(await u.arrayBuffer())
286
+ key: c,
287
+ name: l.name,
288
+ type: l.type,
289
+ data: new Uint8Array(await l.arrayBuffer())
290
290
  });
291
291
  }
292
- a["content-type"]?.startsWith("multipart/form-data") && (e.formData = se(
292
+ o["content-type"]?.startsWith("multipart/form-data") && (e.formData = de(
293
293
  e.body || ""
294
- ), a["content-type"] = "application/x-www-form-urlencoded", delete e.body);
294
+ ), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
295
295
  }
296
- let o;
297
- return e.formData !== void 0 ? (s = "POST", a["content-type"] = a["content-type"] || "application/x-www-form-urlencoded", o = new URLSearchParams(
296
+ let a;
297
+ return e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
298
298
  e.formData
299
- ).toString()) : o = e.body, await this.php.run({
300
- relativeUri: re(
301
- L(r),
302
- this.#r
299
+ ).toString()) : a = e.body, await this.php.run({
300
+ relativeUri: ue(
301
+ W(r),
302
+ this.#n
303
303
  ),
304
304
  protocol: this.#t,
305
305
  method: e.method || s,
306
- body: o,
306
+ body: a,
307
307
  fileInfos: i,
308
- scriptPath: this.#d(r.pathname),
309
- headers: a
308
+ scriptPath: this.#h(r.pathname),
309
+ headers: o
310
310
  });
311
311
  } finally {
312
312
  n();
@@ -320,29 +320,29 @@ class ne {
320
320
  * @param requestedPath - The requested pathname.
321
321
  * @returns The resolved filesystem path.
322
322
  */
323
- #d(e) {
324
- let r = N(e, this.#r);
323
+ #h(e) {
324
+ let r = D(e, this.#n);
325
325
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
326
326
  const n = `${this.#e}${r}`;
327
327
  return this.php.fileExists(n) ? n : `${this.#e}/index.php`;
328
328
  }
329
329
  }
330
- function se(t) {
330
+ function de(t) {
331
331
  const e = {}, r = t.match(/--(.*)\r\n/);
332
332
  if (!r)
333
333
  return e;
334
334
  const n = r[1], s = t.split(`--${n}`);
335
- return s.shift(), s.pop(), s.forEach((a) => {
336
- const i = a.indexOf(`\r
335
+ return s.shift(), s.pop(), s.forEach((o) => {
336
+ const i = o.indexOf(`\r
337
337
  \r
338
- `), o = a.substring(0, i).trim(), l = a.substring(i + 4).trim(), u = o.match(/name="([^"]+)"/);
339
- if (u) {
340
- const d = u[1];
341
- e[d] = l;
338
+ `), a = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), l = a.match(/name="([^"]+)"/);
339
+ if (l) {
340
+ const h = l[1];
341
+ e[h] = c;
342
342
  }
343
343
  }), e;
344
344
  }
345
- function ie(t) {
345
+ function fe(t) {
346
346
  switch (t.split(".").pop()) {
347
347
  case "css":
348
348
  return "text/css";
@@ -382,7 +382,7 @@ function ie(t) {
382
382
  return "application-octet-stream";
383
383
  }
384
384
  }
385
- const D = {
385
+ const $ = {
386
386
  0: "No error occurred. System call completed successfully.",
387
387
  1: "Argument list too long.",
388
388
  2: "Permission denied.",
@@ -463,64 +463,208 @@ const D = {
463
463
  };
464
464
  function y(t = "") {
465
465
  return function(r, n, s) {
466
- const a = s.value;
466
+ const o = s.value;
467
467
  s.value = function(...i) {
468
468
  try {
469
- return a.apply(this, i);
470
- } catch (o) {
471
- const l = typeof o == "object" ? o?.errno : null;
472
- if (l in D) {
473
- const u = D[l], d = typeof i[0] == "string" ? i[0] : null, g = d !== null ? t.replaceAll("{path}", d) : t;
474
- throw new Error(`${g}: ${u}`, {
475
- cause: o
469
+ return o.apply(this, i);
470
+ } catch (a) {
471
+ const c = typeof a == "object" ? a?.errno : null;
472
+ if (c in $) {
473
+ const l = $[c], h = typeof i[0] == "string" ? i[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
474
+ throw new Error(`${g}: ${l}`, {
475
+ cause: a
476
476
  });
477
477
  }
478
- throw o;
478
+ throw a;
479
479
  }
480
480
  };
481
481
  };
482
482
  }
483
- async function oe(t, e = {}, r = []) {
483
+ async function pe(t, e = {}, r = []) {
484
484
  let n, s;
485
- const a = new Promise((l) => {
486
- s = l;
487
- }), i = new Promise((l) => {
488
- n = l;
489
- }), o = t.init(le, {
490
- onAbort(l) {
491
- console.error("WASM aborted: "), console.error(l);
485
+ const o = new Promise((c) => {
486
+ s = c;
487
+ }), i = new Promise((c) => {
488
+ n = c;
489
+ }), a = t.init(ge, {
490
+ onAbort(c) {
491
+ console.error("WASM aborted: "), console.error(c);
492
492
  },
493
493
  ENV: {},
494
494
  // Emscripten sometimes prepends a '/' to the path, which
495
495
  // breaks vite dev mode. An identity `locateFile` function
496
496
  // fixes it.
497
- locateFile: (l) => l,
497
+ locateFile: (c) => c,
498
498
  ...e,
499
499
  noInitialRun: !0,
500
500
  onRuntimeInitialized() {
501
501
  e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
502
502
  },
503
- monitorRunDependencies(l) {
504
- l === 0 && (delete o.monitorRunDependencies, s());
503
+ monitorRunDependencies(c) {
504
+ c === 0 && (delete a.monitorRunDependencies, s());
505
505
  }
506
506
  });
507
- for (const { default: l } of r)
508
- l(o);
509
- return r.length || s(), await a, await i, O.push(o), O.length - 1;
507
+ for (const { default: c } of r)
508
+ c(a);
509
+ return r.length || s(), await o, await i, A.push(a), A.length - 1;
510
510
  }
511
- const O = [];
512
- function ae(t) {
513
- return O[t];
511
+ const A = [];
512
+ function me(t) {
513
+ return A[t];
514
514
  }
515
- const le = function() {
515
+ const ge = function() {
516
516
  return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
517
- }();
518
- var ce = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
519
- for (var s = n > 1 ? void 0 : n ? ue(e, r) : e, a = t.length - 1, i; a >= 0; a--)
520
- (i = t[a]) && (s = (n ? i(e, r, s) : i(s)) || s);
521
- return n && s && ce(e, r, s), s;
517
+ }(), q = Symbol("error"), z = Symbol("message");
518
+ class I extends Event {
519
+ /**
520
+ * Create a new `ErrorEvent`.
521
+ *
522
+ * @param type The name of the event
523
+ * @param options A dictionary object that allows for setting
524
+ * attributes via object members of the same name.
525
+ */
526
+ constructor(e, r = {}) {
527
+ super(e), this[q] = r.error === void 0 ? null : r.error, this[z] = r.message === void 0 ? "" : r.message;
528
+ }
529
+ get error() {
530
+ return this[q];
531
+ }
532
+ get message() {
533
+ return this[z];
534
+ }
535
+ }
536
+ Object.defineProperty(I.prototype, "error", { enumerable: !0 });
537
+ Object.defineProperty(I.prototype, "message", { enumerable: !0 });
538
+ const ye = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : I;
539
+ class we extends EventTarget {
540
+ constructor() {
541
+ super(...arguments), this.listenersCount = 0;
542
+ }
543
+ addEventListener(e, r) {
544
+ ++this.listenersCount, super.addEventListener(e, r);
545
+ }
546
+ removeEventListener(e, r) {
547
+ --this.listenersCount, super.removeEventListener(e, r);
548
+ }
549
+ hasListeners() {
550
+ return this.listenersCount > 0;
551
+ }
552
+ }
553
+ function Pe(t) {
554
+ t.asm = {
555
+ ...t.asm
556
+ };
557
+ const e = new we();
558
+ for (const r in t.asm)
559
+ if (typeof t.asm[r] == "function") {
560
+ const n = t.asm[r];
561
+ t.asm[r] = function(...s) {
562
+ try {
563
+ return n(...s);
564
+ } catch (o) {
565
+ if (!(o instanceof Error))
566
+ throw o;
567
+ if ("exitCode" in o && o?.exitCode === 0)
568
+ return;
569
+ const i = Ee(
570
+ o,
571
+ t.lastAsyncifyStackSource?.stack
572
+ );
573
+ if (t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource), !e.hasListeners())
574
+ throw Se(i), o;
575
+ e.dispatchEvent(
576
+ new ye("error", {
577
+ error: o,
578
+ message: i
579
+ })
580
+ );
581
+ }
582
+ };
583
+ }
584
+ return e;
585
+ }
586
+ let M = [];
587
+ function be() {
588
+ return M;
589
+ }
590
+ function Ee(t, e) {
591
+ if (t.message === "unreachable") {
592
+ let r = ve;
593
+ e || (r += `
594
+
595
+ This stack trace is lacking. For a better one initialize
596
+ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
597
+
598
+ `), M = ke(
599
+ e || t.stack || ""
600
+ );
601
+ for (const n of M)
602
+ r += ` * ${n}
603
+ `;
604
+ return r;
605
+ }
606
+ return t.message;
607
+ }
608
+ const ve = `
609
+ "unreachable" WASM instruction executed.
610
+
611
+ The typical reason is a PHP function missing from the ASYNCIFY_ONLY
612
+ list when building PHP.wasm.
613
+
614
+ You will need to file a new issue in the WordPress Playground repository
615
+ and paste this error message there:
616
+
617
+ https://github.com/WordPress/wordpress-playground/issues/new
618
+
619
+ If you're a core developer, the typical fix is to:
620
+
621
+ * Isolate a minimal reproduction of the error
622
+ * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
623
+ * Run 'npm run fix-asyncify'
624
+ * Commit the changes, push to the repo, release updated NPM packages
625
+
626
+ Below is a list of all the PHP functions found in the stack trace to
627
+ help with the minimal reproduction. If they're all already listed in
628
+ the Dockerfile, you'll need to trigger this error again with long stack
629
+ traces enabled. In node.js, you can do it using the --stack-trace-limit=100
630
+ CLI option:
631
+
632
+ `, B = "\x1B[41m", Re = "\x1B[1m", j = "\x1B[0m", G = "\x1B[K";
633
+ let V = !1;
634
+ function Se(t) {
635
+ if (!V) {
636
+ V = !0, console.log(`${B}
637
+ ${G}
638
+ ${Re} WASM ERROR${j}${B}`);
639
+ for (const e of t.split(`
640
+ `))
641
+ console.log(`${G} ${e} `);
642
+ console.log(`${j}`);
643
+ }
644
+ }
645
+ function ke(t) {
646
+ try {
647
+ const e = t.split(`
648
+ `).slice(1).map((r) => {
649
+ const n = r.trim().substring(3).split(" ");
650
+ return {
651
+ fn: n.length >= 2 ? n[0] : "<unknown>",
652
+ isWasm: r.includes("wasm://")
653
+ };
654
+ }).filter(
655
+ ({ fn: r, isWasm: n }) => n && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
656
+ ).map(({ fn: r }) => r);
657
+ return Array.from(new Set(e));
658
+ } catch {
659
+ return [];
660
+ }
661
+ }
662
+ var xe = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
663
+ for (var s = n > 1 ? void 0 : n ? Te(e, r) : e, o = t.length - 1, i; o >= 0; o--)
664
+ (i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
665
+ return n && s && xe(e, r, s), s;
522
666
  };
523
- const f = "string", b = "number", c = Symbol("__private__dont__use");
667
+ const f = "string", b = "number", u = Symbol("__private__dont__use");
524
668
  class m {
525
669
  /**
526
670
  * Initializes a PHP runtime.
@@ -530,12 +674,13 @@ class m {
530
674
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
531
675
  */
532
676
  constructor(e, r) {
533
- this.#e = [], this.#t = !1, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new Z(
534
- new ne(this, r)
677
+ this.#e = [], this.#t = !1, this.#r = null, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ae(
678
+ new he(this, r)
535
679
  ));
536
680
  }
537
681
  #e;
538
682
  #t;
683
+ #r;
539
684
  /** @inheritDoc */
540
685
  get absoluteUrl() {
541
686
  return this.requestHandler.requestHandler.absoluteUrl;
@@ -555,18 +700,18 @@ class m {
555
700
  );
556
701
  }
557
702
  initializeRuntime(e) {
558
- if (this[c])
703
+ if (this[u])
559
704
  throw new Error("PHP runtime already initialized.");
560
- const r = ae(e);
705
+ const r = me(e);
561
706
  if (!r)
562
707
  throw new Error("Invalid PHP runtime id.");
563
- this[c] = r;
708
+ this[u] = r, this.#r = Pe(r);
564
709
  }
565
710
  /** @inheritDoc */
566
711
  setPhpIniPath(e) {
567
712
  if (this.#t)
568
713
  throw new Error("Cannot set PHP ini path after calling run().");
569
- this[c].ccall(
714
+ this[u].ccall(
570
715
  "wasm_set_phpini_path",
571
716
  null,
572
717
  ["string"],
@@ -581,7 +726,7 @@ class m {
581
726
  }
582
727
  /** @inheritDoc */
583
728
  chdir(e) {
584
- this[c].FS.chdir(e);
729
+ this[u].FS.chdir(e);
585
730
  }
586
731
  /** @inheritDoc */
587
732
  async request(e, r) {
@@ -591,15 +736,15 @@ class m {
591
736
  }
592
737
  /** @inheritDoc */
593
738
  async run(e) {
594
- this.#t || (this.#s(), this.#t = !0), this.#c(e.scriptPath || ""), this.#i(e.relativeUri || ""), this.#o(e.method || "GET");
739
+ this.#t || (this.#s(), this.#t = !0), this.#u(e.scriptPath || ""), this.#n(e.relativeUri || ""), this.#a(e.method || "GET");
595
740
  const { host: r, ...n } = {
596
741
  host: "example.com:443",
597
- ...z(e.headers || {})
742
+ ...K(e.headers || {})
598
743
  };
599
- if (this.#r(r, e.protocol || "http"), this.#a(n), e.body && this.#l(e.body), e.fileInfos)
744
+ if (this.#o(r, e.protocol || "http"), this.#c(n), e.body && this.#l(e.body), e.fileInfos)
600
745
  for (const s of e.fileInfos)
601
- this.#u(s);
602
- return e.code && this.#d(" ?>" + e.code), await this.#h();
746
+ this.#h(s);
747
+ return e.code && this.#d(" ?>" + e.code), await this.#f();
603
748
  }
604
749
  #s() {
605
750
  if (this.#e.length > 0) {
@@ -607,16 +752,16 @@ class m {
607
752
  `) + `
608
753
 
609
754
  `;
610
- this[c].ccall(
755
+ this[u].ccall(
611
756
  "wasm_set_phpini_entries",
612
757
  null,
613
758
  [f],
614
759
  [e]
615
760
  );
616
761
  }
617
- this[c].ccall("php_wasm_init", null, [], []);
762
+ this[u].ccall("php_wasm_init", null, [], []);
618
763
  }
619
- #n() {
764
+ #i() {
620
765
  const e = "/tmp/headers.json";
621
766
  if (!this.fileExists(e))
622
767
  throw new Error(
@@ -626,23 +771,23 @@ class m {
626
771
  for (const s of r.headers) {
627
772
  if (!s.includes(": "))
628
773
  continue;
629
- const a = s.indexOf(": "), i = s.substring(0, a).toLowerCase(), o = s.substring(a + 2);
630
- i in n || (n[i] = []), n[i].push(o);
774
+ const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), a = s.substring(o + 2);
775
+ i in n || (n[i] = []), n[i].push(a);
631
776
  }
632
777
  return {
633
778
  headers: n,
634
779
  httpStatusCode: r.status
635
780
  };
636
781
  }
637
- #i(e) {
638
- if (this[c].ccall(
782
+ #n(e) {
783
+ if (this[u].ccall(
639
784
  "wasm_set_request_uri",
640
785
  null,
641
786
  [f],
642
787
  [e]
643
788
  ), e.includes("?")) {
644
789
  const r = e.substring(e.indexOf("?") + 1);
645
- this[c].ccall(
790
+ this[u].ccall(
646
791
  "wasm_set_query_string",
647
792
  null,
648
793
  [f],
@@ -650,8 +795,8 @@ class m {
650
795
  );
651
796
  }
652
797
  }
653
- #r(e, r) {
654
- this[c].ccall(
798
+ #o(e, r) {
799
+ this[u].ccall(
655
800
  "wasm_set_request_host",
656
801
  null,
657
802
  [f],
@@ -662,33 +807,33 @@ class m {
662
807
  n = parseInt(new URL(e).port, 10);
663
808
  } catch {
664
809
  }
665
- (!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this[c].ccall(
810
+ (!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this[u].ccall(
666
811
  "wasm_set_request_port",
667
812
  null,
668
813
  [b],
669
814
  [n]
670
815
  ), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
671
816
  }
672
- #o(e) {
673
- this[c].ccall(
817
+ #a(e) {
818
+ this[u].ccall(
674
819
  "wasm_set_request_method",
675
820
  null,
676
821
  [f],
677
822
  [e]
678
823
  );
679
824
  }
680
- #a(e) {
681
- e.cookie && this[c].ccall(
825
+ #c(e) {
826
+ e.cookie && this[u].ccall(
682
827
  "wasm_set_cookies",
683
828
  null,
684
829
  [f],
685
830
  [e.cookie]
686
- ), e["content-type"] && this[c].ccall(
831
+ ), e["content-type"] && this[u].ccall(
687
832
  "wasm_set_content_type",
688
833
  null,
689
834
  [f],
690
835
  [e["content-type"]]
691
- ), e["content-length"] && this[c].ccall(
836
+ ), e["content-length"] && this[u].ccall(
692
837
  "wasm_set_content_length",
693
838
  null,
694
839
  [b],
@@ -701,20 +846,20 @@ class m {
701
846
  );
702
847
  }
703
848
  #l(e) {
704
- this[c].ccall(
849
+ this[u].ccall(
705
850
  "wasm_set_request_body",
706
851
  null,
707
852
  [f],
708
853
  [e]
709
- ), this[c].ccall(
854
+ ), this[u].ccall(
710
855
  "wasm_set_content_length",
711
856
  null,
712
857
  [b],
713
- [e.length]
858
+ [new TextEncoder().encode(e).length]
714
859
  );
715
860
  }
716
- #c(e) {
717
- this[c].ccall(
861
+ #u(e) {
862
+ this[u].ccall(
718
863
  "wasm_set_path_translated",
719
864
  null,
720
865
  [f],
@@ -722,7 +867,7 @@ class m {
722
867
  );
723
868
  }
724
869
  addServerGlobalEntry(e, r) {
725
- this[c].ccall(
870
+ this[u].ccall(
726
871
  "wasm_add_SERVER_entry",
727
872
  null,
728
873
  [f, f],
@@ -738,42 +883,79 @@ class m {
738
883
  *
739
884
  * @param fileInfo - File details
740
885
  */
741
- #u(e) {
742
- const { key: r, name: n, type: s, data: a } = e, i = `/tmp/${Math.random().toFixed(20)}`;
743
- this.writeFile(i, a);
744
- const o = 0;
745
- this[c].ccall(
886
+ #h(e) {
887
+ const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
888
+ this.writeFile(i, o);
889
+ const a = 0;
890
+ this[u].ccall(
746
891
  "wasm_add_uploaded_file",
747
892
  null,
748
893
  [f, f, f, f, b, b],
749
- [r, n, s, i, o, a.byteLength]
894
+ [r, n, s, i, a, o.byteLength]
750
895
  );
751
896
  }
752
897
  #d(e) {
753
- this[c].ccall(
898
+ this[u].ccall(
754
899
  "wasm_set_php_code",
755
900
  null,
756
901
  [f],
757
902
  [e]
758
903
  );
759
904
  }
760
- async #h() {
761
- const e = await await this[c].ccall(
762
- "wasm_sapi_handle_request",
763
- b,
764
- [],
765
- []
766
- ), { headers: r, httpStatusCode: n } = this.#n();
767
- return new R(
905
+ async #f() {
906
+ let e, r;
907
+ try {
908
+ e = await new Promise(async (o, i) => {
909
+ r = (a) => {
910
+ const c = new Error("Rethrown");
911
+ c.cause = a.error, c.betterMessage = a.message, i(c);
912
+ }, this.#r?.addEventListener(
913
+ "error",
914
+ r
915
+ );
916
+ try {
917
+ o(
918
+ /**
919
+ * This is awkward, but Asyncify makes wasm_sapi_handle_request return
920
+ * Promise<Promise<number>>.
921
+ *
922
+ * @TODO: Determine whether this is a bug in emscripten or in our code.
923
+ */
924
+ await await this[u].ccall(
925
+ "wasm_sapi_handle_request",
926
+ b,
927
+ [],
928
+ []
929
+ )
930
+ );
931
+ } catch (a) {
932
+ i(a);
933
+ }
934
+ });
935
+ } catch (o) {
936
+ for (const l in this)
937
+ typeof this[l] == "function" && (this[l] = () => {
938
+ throw new Error(
939
+ "PHP runtime has crashed – see the earlier error for details."
940
+ );
941
+ });
942
+ this.functionsMaybeMissingFromAsyncify = be();
943
+ const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(a);
944
+ throw c.cause = i, c;
945
+ } finally {
946
+ this.#r?.removeEventListener("error", r);
947
+ }
948
+ const { headers: n, httpStatusCode: s } = this.#i();
949
+ return new v(
950
+ s,
768
951
  n,
769
- r,
770
952
  this.readFileAsBuffer("/tmp/stdout"),
771
953
  this.readFileAsText("/tmp/stderr"),
772
954
  e
773
955
  );
774
956
  }
775
957
  mkdir(e) {
776
- this[c].FS.mkdirTree(e);
958
+ this[u].FS.mkdirTree(e);
777
959
  }
778
960
  mkdirTree(e) {
779
961
  this.mkdir(e);
@@ -782,28 +964,28 @@ class m {
782
964
  return new TextDecoder().decode(this.readFileAsBuffer(e));
783
965
  }
784
966
  readFileAsBuffer(e) {
785
- return this[c].FS.readFile(e);
967
+ return this[u].FS.readFile(e);
786
968
  }
787
969
  writeFile(e, r) {
788
- this[c].FS.writeFile(e, r);
970
+ this[u].FS.writeFile(e, r);
789
971
  }
790
972
  unlink(e) {
791
- this[c].FS.unlink(e);
973
+ this[u].FS.unlink(e);
792
974
  }
793
975
  mv(e, r) {
794
- this[c].FS.mv(e, r);
976
+ this[u].FS.mv(e, r);
795
977
  }
796
978
  rmdir(e, r = { recursive: !0 }) {
797
979
  r?.recursive && this.listFiles(e).forEach((n) => {
798
980
  const s = `${e}/${n}`;
799
981
  this.isDir(s) ? this.rmdir(s, r) : this.unlink(s);
800
- }), this[c].FS.rmdir(e);
982
+ }), this[u].FS.rmdir(e);
801
983
  }
802
984
  listFiles(e) {
803
985
  if (!this.fileExists(e))
804
986
  return [];
805
987
  try {
806
- return this[c].FS.readdir(e).filter(
988
+ return this[u].FS.readdir(e).filter(
807
989
  (r) => r !== "." && r !== ".."
808
990
  );
809
991
  } catch (r) {
@@ -811,13 +993,13 @@ class m {
811
993
  }
812
994
  }
813
995
  isDir(e) {
814
- return this.fileExists(e) ? this[c].FS.isDir(
815
- this[c].FS.lookupPath(e).node.mode
996
+ return this.fileExists(e) ? this[u].FS.isDir(
997
+ this[u].FS.lookupPath(e).node.mode
816
998
  ) : !1;
817
999
  }
818
1000
  fileExists(e) {
819
1001
  try {
820
- return this[c].FS.lookupPath(e), !0;
1002
+ return this[u].FS.lookupPath(e), !0;
821
1003
  } catch {
822
1004
  return !1;
823
1005
  }
@@ -856,7 +1038,7 @@ w([
856
1038
  w([
857
1039
  y('Could not stat "{path}"')
858
1040
  ], m.prototype, "fileExists", 1);
859
- function z(t) {
1041
+ function K(t) {
860
1042
  const e = {};
861
1043
  for (const r in t)
862
1044
  e[r.toLowerCase()] = t[r];
@@ -867,17 +1049,17 @@ function z(t) {
867
1049
  * Copyright 2019 Google LLC
868
1050
  * SPDX-License-Identifier: Apache-2.0
869
1051
  */
870
- const $ = Symbol("Comlink.proxy"), de = Symbol("Comlink.endpoint"), he = Symbol("Comlink.releaseProxy"), H = Symbol("Comlink.finalizer"), k = Symbol("Comlink.thrown"), j = (t) => typeof t == "object" && t !== null || typeof t == "function", fe = {
871
- canHandle: (t) => j(t) && t[$],
1052
+ const Q = Symbol("Comlink.proxy"), _e = Symbol("Comlink.endpoint"), Ce = Symbol("Comlink.releaseProxy"), H = Symbol("Comlink.finalizer"), x = Symbol("Comlink.thrown"), X = (t) => typeof t == "object" && t !== null || typeof t == "function", Fe = {
1053
+ canHandle: (t) => X(t) && t[Q],
872
1054
  serialize(t) {
873
1055
  const { port1: e, port2: r } = new MessageChannel();
874
1056
  return F(t, e), [r, [r]];
875
1057
  },
876
1058
  deserialize(t) {
877
- return t.start(), I(t);
1059
+ return t.start(), U(t);
878
1060
  }
879
- }, pe = {
880
- canHandle: (t) => j(t) && k in t,
1061
+ }, He = {
1062
+ canHandle: (t) => X(t) && x in t,
881
1063
  serialize({ value: t }) {
882
1064
  let e;
883
1065
  return t instanceof Error ? e = {
@@ -893,10 +1075,10 @@ const $ = Symbol("Comlink.proxy"), de = Symbol("Comlink.endpoint"), he = Symbol(
893
1075
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
894
1076
  }
895
1077
  }, S = /* @__PURE__ */ new Map([
896
- ["proxy", fe],
897
- ["throw", pe]
1078
+ ["proxy", Fe],
1079
+ ["throw", He]
898
1080
  ]);
899
- function me(t, e) {
1081
+ function Ae(t, e) {
900
1082
  for (const r of t)
901
1083
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
902
1084
  return !0;
@@ -906,160 +1088,160 @@ function F(t, e = globalThis, r = ["*"]) {
906
1088
  e.addEventListener("message", function n(s) {
907
1089
  if (!s || !s.data)
908
1090
  return;
909
- if (!me(r, s.origin)) {
1091
+ if (!Ae(r, s.origin)) {
910
1092
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
911
1093
  return;
912
1094
  }
913
- const { id: a, type: i, path: o } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(P);
914
- let u;
1095
+ const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(P);
1096
+ let l;
915
1097
  try {
916
- const d = o.slice(0, -1).reduce((p, v) => p[v], t), g = o.reduce((p, v) => p[v], t);
1098
+ const h = a.slice(0, -1).reduce((p, R) => p[R], t), g = a.reduce((p, R) => p[R], t);
917
1099
  switch (i) {
918
1100
  case "GET":
919
- u = g;
1101
+ l = g;
920
1102
  break;
921
1103
  case "SET":
922
- d[o.slice(-1)[0]] = P(s.data.value), u = !0;
1104
+ h[a.slice(-1)[0]] = P(s.data.value), l = !0;
923
1105
  break;
924
1106
  case "APPLY":
925
- u = g.apply(d, l);
1107
+ l = g.apply(h, c);
926
1108
  break;
927
1109
  case "CONSTRUCT":
928
1110
  {
929
- const p = new g(...l);
930
- u = J(p);
1111
+ const p = new g(...c);
1112
+ l = re(p);
931
1113
  }
932
1114
  break;
933
1115
  case "ENDPOINT":
934
1116
  {
935
- const { port1: p, port2: v } = new MessageChannel();
936
- F(t, v), u = be(p, [p]);
1117
+ const { port1: p, port2: R } = new MessageChannel();
1118
+ F(t, R), l = Ue(p, [p]);
937
1119
  }
938
1120
  break;
939
1121
  case "RELEASE":
940
- u = void 0;
1122
+ l = void 0;
941
1123
  break;
942
1124
  default:
943
1125
  return;
944
1126
  }
945
- } catch (d) {
946
- u = { value: d, [k]: 0 };
1127
+ } catch (h) {
1128
+ l = { value: h, [x]: 0 };
947
1129
  }
948
- Promise.resolve(u).catch((d) => ({ value: d, [k]: 0 })).then((d) => {
949
- const [g, p] = C(d);
950
- e.postMessage(Object.assign(Object.assign({}, g), { id: a }), p), i === "RELEASE" && (e.removeEventListener("message", n), B(e), H in t && typeof t[H] == "function" && t[H]());
951
- }).catch((d) => {
1130
+ Promise.resolve(l).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1131
+ const [g, p] = C(h);
1132
+ e.postMessage(Object.assign(Object.assign({}, g), { id: o }), p), i === "RELEASE" && (e.removeEventListener("message", n), Z(e), H in t && typeof t[H] == "function" && t[H]());
1133
+ }).catch((h) => {
952
1134
  const [g, p] = C({
953
1135
  value: new TypeError("Unserializable return value"),
954
- [k]: 0
1136
+ [x]: 0
955
1137
  });
956
- e.postMessage(Object.assign(Object.assign({}, g), { id: a }), p);
1138
+ e.postMessage(Object.assign(Object.assign({}, g), { id: o }), p);
957
1139
  });
958
1140
  }), e.start && e.start();
959
1141
  }
960
- function ge(t) {
1142
+ function Me(t) {
961
1143
  return t.constructor.name === "MessagePort";
962
1144
  }
963
- function B(t) {
964
- ge(t) && t.close();
1145
+ function Z(t) {
1146
+ Me(t) && t.close();
965
1147
  }
966
- function I(t, e) {
967
- return U(t, [], e);
1148
+ function U(t, e) {
1149
+ return O(t, [], e);
968
1150
  }
969
- function _(t) {
1151
+ function k(t) {
970
1152
  if (t)
971
1153
  throw new Error("Proxy has been released and is not useable");
972
1154
  }
973
- function G(t) {
1155
+ function ee(t) {
974
1156
  return E(t, {
975
1157
  type: "RELEASE"
976
1158
  }).then(() => {
977
- B(t);
1159
+ Z(t);
978
1160
  });
979
1161
  }
980
- const x = /* @__PURE__ */ new WeakMap(), T = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
981
- const e = (x.get(t) || 0) - 1;
982
- x.set(t, e), e === 0 && G(t);
1162
+ const T = /* @__PURE__ */ new WeakMap(), _ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
1163
+ const e = (T.get(t) || 0) - 1;
1164
+ T.set(t, e), e === 0 && ee(t);
983
1165
  });
984
- function ye(t, e) {
985
- const r = (x.get(e) || 0) + 1;
986
- x.set(e, r), T && T.register(t, e, t);
1166
+ function Oe(t, e) {
1167
+ const r = (T.get(e) || 0) + 1;
1168
+ T.set(e, r), _ && _.register(t, e, t);
987
1169
  }
988
- function we(t) {
989
- T && T.unregister(t);
1170
+ function Le(t) {
1171
+ _ && _.unregister(t);
990
1172
  }
991
- function U(t, e = [], r = function() {
1173
+ function O(t, e = [], r = function() {
992
1174
  }) {
993
1175
  let n = !1;
994
1176
  const s = new Proxy(r, {
995
- get(a, i) {
996
- if (_(n), i === he)
1177
+ get(o, i) {
1178
+ if (k(n), i === Ce)
997
1179
  return () => {
998
- we(s), G(t), n = !0;
1180
+ Le(s), ee(t), n = !0;
999
1181
  };
1000
1182
  if (i === "then") {
1001
1183
  if (e.length === 0)
1002
1184
  return { then: () => s };
1003
- const o = E(t, {
1185
+ const a = E(t, {
1004
1186
  type: "GET",
1005
- path: e.map((l) => l.toString())
1187
+ path: e.map((c) => c.toString())
1006
1188
  }).then(P);
1007
- return o.then.bind(o);
1189
+ return a.then.bind(a);
1008
1190
  }
1009
- return U(t, [...e, i]);
1191
+ return O(t, [...e, i]);
1010
1192
  },
1011
- set(a, i, o) {
1012
- _(n);
1013
- const [l, u] = C(o);
1193
+ set(o, i, a) {
1194
+ k(n);
1195
+ const [c, l] = C(a);
1014
1196
  return E(t, {
1015
1197
  type: "SET",
1016
- path: [...e, i].map((d) => d.toString()),
1017
- value: l
1018
- }, u).then(P);
1198
+ path: [...e, i].map((h) => h.toString()),
1199
+ value: c
1200
+ }, l).then(P);
1019
1201
  },
1020
- apply(a, i, o) {
1021
- _(n);
1022
- const l = e[e.length - 1];
1023
- if (l === de)
1202
+ apply(o, i, a) {
1203
+ k(n);
1204
+ const c = e[e.length - 1];
1205
+ if (c === _e)
1024
1206
  return E(t, {
1025
1207
  type: "ENDPOINT"
1026
1208
  }).then(P);
1027
- if (l === "bind")
1028
- return U(t, e.slice(0, -1));
1029
- const [u, d] = W(o);
1209
+ if (c === "bind")
1210
+ return O(t, e.slice(0, -1));
1211
+ const [l, h] = Y(a);
1030
1212
  return E(t, {
1031
1213
  type: "APPLY",
1032
1214
  path: e.map((g) => g.toString()),
1033
- argumentList: u
1034
- }, d).then(P);
1215
+ argumentList: l
1216
+ }, h).then(P);
1035
1217
  },
1036
- construct(a, i) {
1037
- _(n);
1038
- const [o, l] = W(i);
1218
+ construct(o, i) {
1219
+ k(n);
1220
+ const [a, c] = Y(i);
1039
1221
  return E(t, {
1040
1222
  type: "CONSTRUCT",
1041
- path: e.map((u) => u.toString()),
1042
- argumentList: o
1043
- }, l).then(P);
1223
+ path: e.map((l) => l.toString()),
1224
+ argumentList: a
1225
+ }, c).then(P);
1044
1226
  }
1045
1227
  });
1046
- return ye(s, t), s;
1228
+ return Oe(s, t), s;
1047
1229
  }
1048
- function Pe(t) {
1230
+ function Ie(t) {
1049
1231
  return Array.prototype.concat.apply([], t);
1050
1232
  }
1051
- function W(t) {
1233
+ function Y(t) {
1052
1234
  const e = t.map(C);
1053
- return [e.map((r) => r[0]), Pe(e.map((r) => r[1]))];
1235
+ return [e.map((r) => r[0]), Ie(e.map((r) => r[1]))];
1054
1236
  }
1055
- const V = /* @__PURE__ */ new WeakMap();
1056
- function be(t, e) {
1057
- return V.set(t, e), t;
1237
+ const te = /* @__PURE__ */ new WeakMap();
1238
+ function Ue(t, e) {
1239
+ return te.set(t, e), t;
1058
1240
  }
1059
- function J(t) {
1060
- return Object.assign(t, { [$]: !0 });
1241
+ function re(t) {
1242
+ return Object.assign(t, { [Q]: !0 });
1061
1243
  }
1062
- function Y(t, e = globalThis, r = "*") {
1244
+ function ne(t, e = globalThis, r = "*") {
1063
1245
  return {
1064
1246
  postMessage: (n, s) => t.postMessage(n, r, s),
1065
1247
  addEventListener: e.addEventListener.bind(e),
@@ -1084,7 +1266,7 @@ function C(t) {
1084
1266
  type: "RAW",
1085
1267
  value: t
1086
1268
  },
1087
- V.get(t) || []
1269
+ te.get(t) || []
1088
1270
  ];
1089
1271
  }
1090
1272
  function P(t) {
@@ -1097,39 +1279,39 @@ function P(t) {
1097
1279
  }
1098
1280
  function E(t, e, r) {
1099
1281
  return new Promise((n) => {
1100
- const s = Ee();
1101
- t.addEventListener("message", function a(i) {
1102
- !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", a), n(i.data));
1282
+ const s = Ne();
1283
+ t.addEventListener("message", function o(i) {
1284
+ !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", o), n(i.data));
1103
1285
  }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
1104
1286
  });
1105
1287
  }
1106
- function Ee() {
1288
+ function Ne() {
1107
1289
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1108
1290
  }
1109
- function xe(t) {
1110
- K();
1111
- const e = t instanceof Worker ? t : Y(t), r = I(e), n = M(r);
1291
+ function Be(t) {
1292
+ se();
1293
+ const e = t instanceof Worker ? t : ne(t), r = U(e), n = N(r);
1112
1294
  return new Proxy(n, {
1113
- get: (s, a) => a === "isConnected" ? () => r.isConnected() : r[a]
1295
+ get: (s, o) => o === "isConnected" ? () => r.isConnected() : r[o]
1114
1296
  });
1115
1297
  }
1116
- function Te(t, e) {
1117
- K();
1298
+ function je(t, e) {
1299
+ se();
1118
1300
  const r = Promise.resolve();
1119
1301
  let n;
1120
- const s = new Promise((o) => {
1121
- n = o;
1122
- }), a = M(t), i = new Proxy(a, {
1123
- get: (o, l) => l === "isConnected" ? () => r : l === "isReady" ? () => s : l in o ? o[l] : e?.[l]
1302
+ const s = new Promise((a) => {
1303
+ n = a;
1304
+ }), o = N(t), i = new Proxy(o, {
1305
+ get: (a, c) => c === "isConnected" ? () => r : c === "isReady" ? () => s : c in a ? a[c] : e?.[c]
1124
1306
  });
1125
1307
  return F(
1126
1308
  i,
1127
- typeof window < "u" ? Y(self.parent) : void 0
1309
+ typeof window < "u" ? ne(self.parent) : void 0
1128
1310
  ), [n, i];
1129
1311
  }
1130
- let q = !1;
1131
- function K() {
1132
- q || (q = !0, S.set("EVENT", {
1312
+ let J = !1;
1313
+ function se() {
1314
+ J || (J = !0, S.set("EVENT", {
1133
1315
  canHandle: (t) => t instanceof CustomEvent,
1134
1316
  serialize: (t) => [
1135
1317
  {
@@ -1146,7 +1328,7 @@ function K() {
1146
1328
  return F(t, e), [r, [r]];
1147
1329
  },
1148
1330
  deserialize(t) {
1149
- return t.start(), I(t);
1331
+ return t.start(), U(t);
1150
1332
  }
1151
1333
  }), S.set("PHPResponse", {
1152
1334
  canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
@@ -1154,29 +1336,29 @@ function K() {
1154
1336
  return [t.toRawData(), []];
1155
1337
  },
1156
1338
  deserialize(t) {
1157
- return R.fromRawData(t);
1339
+ return v.fromRawData(t);
1158
1340
  }
1159
1341
  }));
1160
1342
  }
1161
- function M(t) {
1343
+ function N(t) {
1162
1344
  return new Proxy(t, {
1163
1345
  get(e, r) {
1164
1346
  switch (typeof e[r]) {
1165
1347
  case "function":
1166
1348
  return (...n) => e[r](...n);
1167
1349
  case "object":
1168
- return e[r] === null ? e[r] : M(e[r]);
1350
+ return e[r] === null ? e[r] : N(e[r]);
1169
1351
  case "undefined":
1170
1352
  case "number":
1171
1353
  case "string":
1172
1354
  return e[r];
1173
1355
  default:
1174
- return J(e[r]);
1356
+ return re(e[r]);
1175
1357
  }
1176
1358
  }
1177
1359
  });
1178
1360
  }
1179
- async function Re(t = X) {
1361
+ async function We(t = oe) {
1180
1362
  switch (t) {
1181
1363
  case "8.2":
1182
1364
  return await import("php_8_2.js");
@@ -1199,7 +1381,7 @@ async function Re(t = X) {
1199
1381
  }
1200
1382
  throw new Error(`Unsupported PHP version ${t}`);
1201
1383
  }
1202
- class A extends m {
1384
+ class L extends m {
1203
1385
  /**
1204
1386
  * Creates a new PHP instance.
1205
1387
  *
@@ -1213,7 +1395,7 @@ class A extends m {
1213
1395
  * @returns A new PHP instance
1214
1396
  */
1215
1397
  static async load(e, r = {}) {
1216
- return await A.loadSync(e, r).phpReady;
1398
+ return await L.loadSync(e, r).phpReady;
1217
1399
  }
1218
1400
  /**
1219
1401
  * Does what load() does, but synchronously returns
@@ -1223,141 +1405,141 @@ class A extends m {
1223
1405
  * @see load
1224
1406
  */
1225
1407
  static loadSync(e, r = {}) {
1226
- const n = new A(void 0, r.requestHandler), a = (async () => {
1408
+ const n = new L(void 0, r.requestHandler), o = (async () => {
1227
1409
  const i = await Promise.all([
1228
- Re(e),
1410
+ We(e),
1229
1411
  ...r.dataModules || []
1230
- ]), [o, ...l] = i;
1412
+ ]), [a, ...c] = i;
1231
1413
  r.downloadMonitor?.setModules(i);
1232
- const u = await oe(
1233
- o,
1414
+ const l = await pe(
1415
+ a,
1234
1416
  {
1235
1417
  ...r.emscriptenOptions || {},
1236
1418
  ...r.downloadMonitor?.getEmscriptenOptions() || {}
1237
1419
  },
1238
- l
1420
+ c
1239
1421
  );
1240
- return n.initializeRuntime(u), { dataModules: l };
1422
+ return n.initializeRuntime(l), { dataModules: c };
1241
1423
  })();
1242
1424
  return {
1243
1425
  php: n,
1244
- phpReady: a.then(() => n),
1245
- dataModules: a.then((i) => i.dataModules)
1426
+ phpReady: o.then(() => n),
1427
+ dataModules: o.then((i) => i.dataModules)
1246
1428
  };
1247
1429
  }
1248
1430
  }
1249
- const h = /* @__PURE__ */ new WeakMap();
1250
- class Ce {
1431
+ const d = /* @__PURE__ */ new WeakMap();
1432
+ class Ge {
1251
1433
  /** @inheritDoc */
1252
1434
  constructor(e, r) {
1253
- h.set(this, {
1435
+ d.set(this, {
1254
1436
  php: e,
1255
1437
  monitor: r
1256
1438
  }), this.absoluteUrl = e.absoluteUrl, this.documentRoot = e.documentRoot;
1257
1439
  }
1258
1440
  /** @inheritDoc */
1259
1441
  pathToInternalUrl(e) {
1260
- return h.get(this).php.pathToInternalUrl(e);
1442
+ return d.get(this).php.pathToInternalUrl(e);
1261
1443
  }
1262
1444
  /** @inheritDoc */
1263
1445
  internalUrlToPath(e) {
1264
- return h.get(this).php.internalUrlToPath(e);
1446
+ return d.get(this).php.internalUrlToPath(e);
1265
1447
  }
1266
1448
  async onDownloadProgress(e) {
1267
- return h.get(this).monitor?.addEventListener("progress", e);
1449
+ return d.get(this).monitor?.addEventListener("progress", e);
1268
1450
  }
1269
1451
  /** @inheritDoc */
1270
1452
  mv(e, r) {
1271
- return h.get(this).php.mv(e, r);
1453
+ return d.get(this).php.mv(e, r);
1272
1454
  }
1273
1455
  /** @inheritDoc */
1274
1456
  rmdir(e, r) {
1275
- return h.get(this).php.rmdir(e, r);
1457
+ return d.get(this).php.rmdir(e, r);
1276
1458
  }
1277
1459
  /** @inheritDoc @php-wasm/universal!RequestHandler.request */
1278
1460
  request(e, r) {
1279
- return h.get(this).php.request(e, r);
1461
+ return d.get(this).php.request(e, r);
1280
1462
  }
1281
1463
  /** @inheritDoc @php-wasm/web!WebPHP.run */
1282
1464
  async run(e) {
1283
- return h.get(this).php.run(e);
1465
+ return d.get(this).php.run(e);
1284
1466
  }
1285
1467
  /** @inheritDoc @php-wasm/web!WebPHP.chdir */
1286
1468
  chdir(e) {
1287
- return h.get(this).php.chdir(e);
1469
+ return d.get(this).php.chdir(e);
1288
1470
  }
1289
1471
  /** @inheritDoc @php-wasm/web!WebPHP.setPhpIniPath */
1290
1472
  setPhpIniPath(e) {
1291
- return h.get(this).php.setPhpIniPath(e);
1473
+ return d.get(this).php.setPhpIniPath(e);
1292
1474
  }
1293
1475
  /** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
1294
1476
  setPhpIniEntry(e, r) {
1295
- return h.get(this).php.setPhpIniEntry(e, r);
1477
+ return d.get(this).php.setPhpIniEntry(e, r);
1296
1478
  }
1297
1479
  /** @inheritDoc @php-wasm/web!WebPHP.mkdir */
1298
1480
  mkdir(e) {
1299
- return h.get(this).php.mkdir(e);
1481
+ return d.get(this).php.mkdir(e);
1300
1482
  }
1301
1483
  /** @inheritDoc @php-wasm/web!WebPHP.mkdirTree */
1302
1484
  mkdirTree(e) {
1303
- return h.get(this).php.mkdirTree(e);
1485
+ return d.get(this).php.mkdirTree(e);
1304
1486
  }
1305
1487
  /** @inheritDoc @php-wasm/web!WebPHP.readFileAsText */
1306
1488
  readFileAsText(e) {
1307
- return h.get(this).php.readFileAsText(e);
1489
+ return d.get(this).php.readFileAsText(e);
1308
1490
  }
1309
1491
  /** @inheritDoc @php-wasm/web!WebPHP.readFileAsBuffer */
1310
1492
  readFileAsBuffer(e) {
1311
- return h.get(this).php.readFileAsBuffer(e);
1493
+ return d.get(this).php.readFileAsBuffer(e);
1312
1494
  }
1313
1495
  /** @inheritDoc @php-wasm/web!WebPHP.writeFile */
1314
1496
  writeFile(e, r) {
1315
- return h.get(this).php.writeFile(e, r);
1497
+ return d.get(this).php.writeFile(e, r);
1316
1498
  }
1317
1499
  /** @inheritDoc @php-wasm/web!WebPHP.unlink */
1318
1500
  unlink(e) {
1319
- return h.get(this).php.unlink(e);
1501
+ return d.get(this).php.unlink(e);
1320
1502
  }
1321
1503
  /** @inheritDoc @php-wasm/web!WebPHP.listFiles */
1322
1504
  listFiles(e) {
1323
- return h.get(this).php.listFiles(e);
1505
+ return d.get(this).php.listFiles(e);
1324
1506
  }
1325
1507
  /** @inheritDoc @php-wasm/web!WebPHP.isDir */
1326
1508
  isDir(e) {
1327
- return h.get(this).php.isDir(e);
1509
+ return d.get(this).php.isDir(e);
1328
1510
  }
1329
1511
  /** @inheritDoc @php-wasm/web!WebPHP.fileExists */
1330
1512
  fileExists(e) {
1331
- return h.get(this).php.fileExists(e);
1513
+ return d.get(this).php.fileExists(e);
1332
1514
  }
1333
1515
  }
1334
- function ve(t, e) {
1516
+ function De(t, e) {
1335
1517
  return {
1336
1518
  type: "response",
1337
1519
  requestId: t,
1338
1520
  response: e
1339
1521
  };
1340
1522
  }
1341
- async function Fe(t, e, r, n) {
1523
+ async function Ve(t, e, r, n) {
1342
1524
  const s = navigator.serviceWorker;
1343
1525
  if (!s)
1344
1526
  throw new Error("Service workers are not supported in this browser.");
1345
- const a = await s.getRegistrations();
1346
- if (a.length > 0) {
1347
- const i = await Se();
1527
+ const o = await s.getRegistrations();
1528
+ if (o.length > 0) {
1529
+ const i = await $e();
1348
1530
  if (n !== i) {
1349
1531
  console.debug(
1350
1532
  `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
1351
1533
  );
1352
- for (const o of a) {
1353
- let l = !1;
1534
+ for (const a of o) {
1535
+ let c = !1;
1354
1536
  try {
1355
- await o.update();
1537
+ await a.update();
1356
1538
  } catch {
1357
- l = !0;
1539
+ c = !0;
1358
1540
  }
1359
- const u = o.waiting || o.installing;
1360
- u && !l && (i !== null ? u.postMessage("skip-waiting") : l = !0), l && (await o.unregister(), window.location.reload());
1541
+ const l = a.waiting || a.installing;
1542
+ l && !c && (i !== null ? l.postMessage("skip-waiting") : c = !0), c && (await a.unregister(), window.location.reload());
1361
1543
  }
1362
1544
  }
1363
1545
  } else
@@ -1368,38 +1550,38 @@ async function Fe(t, e, r, n) {
1368
1550
  });
1369
1551
  navigator.serviceWorker.addEventListener(
1370
1552
  "message",
1371
- async function(o) {
1372
- if (console.debug("Message from ServiceWorker", o), e && o.data.scope !== e)
1553
+ async function(a) {
1554
+ if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1373
1555
  return;
1374
- const l = o.data.args || [], u = o.data.method, d = await t[u](...l);
1375
- o.source.postMessage(ve(o.data.requestId, d));
1556
+ const c = a.data.args || [], l = a.data.method, h = await t[l](...c);
1557
+ a.source.postMessage(De(a.data.requestId, h));
1376
1558
  }
1377
1559
  ), s.startMessages();
1378
1560
  }
1379
- async function Se() {
1561
+ async function $e() {
1380
1562
  try {
1381
1563
  return (await (await fetch("/version")).json()).version;
1382
1564
  } catch {
1383
1565
  return null;
1384
1566
  }
1385
1567
  }
1386
- function He() {
1568
+ function Ye() {
1387
1569
  const t = {};
1388
1570
  return typeof self?.location?.href < "u" && new URL(self.location.href).searchParams.forEach((r, n) => {
1389
1571
  t[n] = r;
1390
1572
  }), t;
1391
1573
  }
1392
- const Oe = function() {
1574
+ const Je = function() {
1393
1575
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
1394
1576
  }();
1395
- async function Ue(t, e = "webworker", r = {}) {
1396
- if (t = _e(t, r), e === "webworker")
1577
+ async function Ke(t, e = "webworker", r = {}) {
1578
+ if (t = qe(t, r), e === "webworker")
1397
1579
  return new Worker(t, { type: "module" });
1398
1580
  if (e === "iframe")
1399
- return (await ke(t)).contentWindow;
1581
+ return (await ze(t)).contentWindow;
1400
1582
  throw new Error(`Unknown backendName: ${e}`);
1401
1583
  }
1402
- function _e(t, e) {
1584
+ function qe(t, e) {
1403
1585
  if (!Object.entries(e).length)
1404
1586
  return t + "";
1405
1587
  const r = new URL(t);
@@ -1407,20 +1589,20 @@ function _e(t, e) {
1407
1589
  r.searchParams.set(n, s);
1408
1590
  return r.toString();
1409
1591
  }
1410
- async function ke(t) {
1592
+ async function ze(t) {
1411
1593
  const e = document.createElement("iframe"), r = "/" + t.split("/").slice(-1)[0];
1412
1594
  return e.src = r, e.style.display = "none", document.body.appendChild(e), await new Promise((n) => {
1413
1595
  e.addEventListener("load", n);
1414
1596
  }), e;
1415
1597
  }
1416
1598
  export {
1417
- A as WebPHP,
1418
- Ce as WebPHPEndpoint,
1419
- xe as consumeAPI,
1420
- Te as exposeAPI,
1421
- Re as getPHPLoaderModule,
1422
- He as parseWorkerStartupOptions,
1423
- Oe as recommendedWorkerBackend,
1424
- Fe as registerServiceWorker,
1425
- Ue as spawnPHPWorkerThread
1599
+ L as WebPHP,
1600
+ Ge as WebPHPEndpoint,
1601
+ Be as consumeAPI,
1602
+ je as exposeAPI,
1603
+ We as getPHPLoaderModule,
1604
+ Ye as parseWorkerStartupOptions,
1605
+ Je as recommendedWorkerBackend,
1606
+ Ve as registerServiceWorker,
1607
+ Ke as spawnPHPWorkerThread
1426
1608
  };