@php-wasm/universal 0.3.1 → 0.4.0

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,5 +1,15 @@
1
- const v = Symbol("error"), E = Symbol("message");
2
- class b extends Event {
1
+ var se = (s, e, t) => {
2
+ if (!e.has(s))
3
+ throw TypeError("Cannot " + t);
4
+ };
5
+ var i = (s, e, t) => (se(s, e, "read from private field"), t ? t.call(s) : e.get(s)), l = (s, e, t) => {
6
+ if (e.has(s))
7
+ throw TypeError("Cannot add the same private member more than once");
8
+ e instanceof WeakSet ? e.add(s) : e.set(s, t);
9
+ }, p = (s, e, t, r) => (se(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
10
+ var m = (s, e, t) => (se(s, e, "access private method"), t);
11
+ const ie = Symbol("error"), oe = Symbol("message");
12
+ class ne extends Event {
3
13
  /**
4
14
  * Create a new `ErrorEvent`.
5
15
  *
@@ -8,22 +18,22 @@ class b extends Event {
8
18
  * attributes via object members of the same name.
9
19
  */
10
20
  constructor(e, t = {}) {
11
- super(e), this[v] = t.error === void 0 ? null : t.error, this[E] = t.message === void 0 ? "" : t.message;
21
+ super(e), this[ie] = t.error === void 0 ? null : t.error, this[oe] = t.message === void 0 ? "" : t.message;
12
22
  }
13
23
  get error() {
14
- return this[v];
24
+ return this[ie];
15
25
  }
16
26
  get message() {
17
- return this[E];
27
+ return this[oe];
18
28
  }
19
29
  }
20
- Object.defineProperty(b.prototype, "error", { enumerable: !0 });
21
- Object.defineProperty(b.prototype, "message", { enumerable: !0 });
22
- const U = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : b;
23
- function I(s) {
24
- return s instanceof Error ? "exitCode" in s && s?.exitCode === 0 || s?.name === "ExitStatus" && "status" in s && s.status === 0 : !1;
30
+ Object.defineProperty(ne.prototype, "error", { enumerable: !0 });
31
+ Object.defineProperty(ne.prototype, "message", { enumerable: !0 });
32
+ const Ae = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ne;
33
+ function Oe(s) {
34
+ return s instanceof Error ? "exitCode" in s && (s == null ? void 0 : s.exitCode) === 0 || (s == null ? void 0 : s.name) === "ExitStatus" && "status" in s && s.status === 0 : !1;
25
35
  }
26
- class L extends EventTarget {
36
+ class Ie extends EventTarget {
27
37
  constructor() {
28
38
  super(...arguments), this.listenersCount = 0;
29
39
  }
@@ -37,62 +47,63 @@ class L extends EventTarget {
37
47
  return this.listenersCount > 0;
38
48
  }
39
49
  }
40
- function N(s) {
50
+ function Le(s) {
41
51
  s.asm = {
42
52
  ...s.asm
43
53
  };
44
- const e = new L();
54
+ const e = new Ie();
45
55
  for (const t in s.asm)
46
56
  if (typeof s.asm[t] == "function") {
47
57
  const r = s.asm[t];
48
58
  s.asm[t] = function(...n) {
59
+ var o;
49
60
  try {
50
61
  return r(...n);
51
- } catch (o) {
52
- if (!(o instanceof Error))
53
- throw o;
54
- const i = M(
55
- o,
56
- s.lastAsyncifyStackSource?.stack
62
+ } catch (a) {
63
+ if (!(a instanceof Error))
64
+ throw a;
65
+ const h = Ne(
66
+ a,
67
+ (o = s.lastAsyncifyStackSource) == null ? void 0 : o.stack
57
68
  );
58
- if (s.lastAsyncifyStackSource && (o.cause = s.lastAsyncifyStackSource), e.hasListeners()) {
69
+ if (s.lastAsyncifyStackSource && (a.cause = s.lastAsyncifyStackSource), e.hasListeners()) {
59
70
  e.dispatchEvent(
60
- new U("error", {
61
- error: o,
62
- message: i
71
+ new Ae("error", {
72
+ error: a,
73
+ message: h
63
74
  })
64
75
  );
65
76
  return;
66
77
  }
67
- throw I(o) || D(i), o;
78
+ throw Oe(a) || De(h), a;
68
79
  }
69
80
  };
70
81
  }
71
82
  return e;
72
83
  }
73
- let w = [];
74
- function $() {
75
- return w;
84
+ let re = [];
85
+ function Ue() {
86
+ return re;
76
87
  }
77
- function M(s, e) {
88
+ function Ne(s, e) {
78
89
  if (s.message === "unreachable") {
79
- let t = q;
90
+ let t = Me;
80
91
  e || (t += `
81
92
 
82
93
  This stack trace is lacking. For a better one initialize
83
94
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
84
95
 
85
- `), w = W(
96
+ `), re = je(
86
97
  e || s.stack || ""
87
98
  );
88
- for (const r of w)
99
+ for (const r of re)
89
100
  t += ` * ${r}
90
101
  `;
91
102
  return t;
92
103
  }
93
104
  return s.message;
94
105
  }
95
- const q = `
106
+ const Me = `
96
107
  "unreachable" WASM instruction executed.
97
108
 
98
109
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -116,20 +127,20 @@ the Dockerfile, you'll need to trigger this error again with long stack
116
127
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
117
128
  CLI option:
118
129
 
119
- `, _ = "\x1B[41m", B = "\x1B[1m", R = "\x1B[0m", x = "\x1B[K";
120
- let S = !1;
121
- function D(s) {
122
- if (!S) {
123
- S = !0, console.log(`${_}
124
- ${x}
125
- ${B} WASM ERROR${R}${_}`);
130
+ `, ae = "\x1B[41m", qe = "\x1B[1m", le = "\x1B[0m", ce = "\x1B[K";
131
+ let he = !1;
132
+ function De(s) {
133
+ if (!he) {
134
+ he = !0, console.log(`${ae}
135
+ ${ce}
136
+ ${qe} WASM ERROR${le}${ae}`);
126
137
  for (const e of s.split(`
127
138
  `))
128
- console.log(`${x} ${e} `);
129
- console.log(`${R}`);
139
+ console.log(`${ce} ${e} `);
140
+ console.log(`${le}`);
130
141
  }
131
142
  }
132
- function W(s) {
143
+ function je(s) {
133
144
  try {
134
145
  const e = s.split(`
135
146
  `).slice(1).map((t) => {
@@ -146,12 +157,12 @@ function W(s) {
146
157
  return [];
147
158
  }
148
159
  }
149
- class g {
160
+ class F {
150
161
  constructor(e, t, r, n = "", o = 0) {
151
162
  this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = n;
152
163
  }
153
164
  static fromRawData(e) {
154
- return new g(
165
+ return new F(
155
166
  e.httpStatusCode,
156
167
  e.headers,
157
168
  e.bytes,
@@ -181,7 +192,8 @@ class g {
181
192
  return new TextDecoder().decode(this.bytes);
182
193
  }
183
194
  }
184
- const F = [
195
+ const me = [
196
+ "8.3",
185
197
  "8.2",
186
198
  "8.1",
187
199
  "8.0",
@@ -189,29 +201,29 @@ const F = [
189
201
  "7.3",
190
202
  "7.2",
191
203
  "7.1",
192
- "7.0",
193
- "5.6"
194
- ], ie = F[0], ae = F, j = [
204
+ "7.0"
205
+ ], ot = me[0], at = me, Be = [
195
206
  "iconv",
196
207
  "mbstring",
197
208
  "xml-bundle",
198
209
  "gd"
199
- ], le = {
200
- "kitchen-sink": j
210
+ ], lt = {
211
+ "kitchen-sink": Be
201
212
  };
202
- class z {
203
- #e;
204
- #t;
213
+ var S, $;
214
+ class We {
205
215
  /**
206
216
  * @param server - The PHP server to browse.
207
217
  * @param config - The browser configuration.
208
218
  */
209
219
  constructor(e, t = {}) {
210
- this.requestHandler = e, this.#e = {}, this.#t = {
220
+ l(this, S, void 0);
221
+ l(this, $, void 0);
222
+ this.requestHandler = e, p(this, S, {}), p(this, $, {
211
223
  handleRedirects: !1,
212
224
  maxRedirects: 4,
213
225
  ...t
214
- };
226
+ });
215
227
  }
216
228
  /**
217
229
  * Sends the request to the server.
@@ -232,10 +244,10 @@ class z {
232
244
  ...e,
233
245
  headers: {
234
246
  ...e.headers,
235
- cookie: this.#r()
247
+ cookie: this.serializeCookies()
236
248
  }
237
249
  });
238
- if (r.headers["set-cookie"] && this.#s(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && t < this.#t.maxRedirects) {
250
+ if (r.headers["set-cookie"] && this.setCookies(r.headers["set-cookie"]), i(this, $).handleRedirects && r.headers.location && t < i(this, $).maxRedirects) {
239
251
  const n = new URL(
240
252
  r.headers.location[0],
241
253
  this.requestHandler.absoluteUrl
@@ -267,25 +279,26 @@ class z {
267
279
  get documentRoot() {
268
280
  return this.requestHandler.documentRoot;
269
281
  }
270
- #s(e) {
282
+ setCookies(e) {
271
283
  for (const t of e)
272
284
  try {
273
285
  if (!t.includes("="))
274
286
  continue;
275
287
  const r = t.indexOf("="), n = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
276
- this.#e[n] = o;
288
+ i(this, S)[n] = o;
277
289
  } catch (r) {
278
290
  console.error(r);
279
291
  }
280
292
  }
281
- #r() {
293
+ serializeCookies() {
282
294
  const e = [];
283
- for (const t in this.#e)
284
- e.push(`${t}=${this.#e[t]}`);
295
+ for (const t in i(this, S))
296
+ e.push(`${t}=${i(this, S)[t]}`);
285
297
  return e.join("; ");
286
298
  }
287
299
  }
288
- class G {
300
+ S = new WeakMap(), $ = new WeakMap();
301
+ class ye {
289
302
  constructor({ concurrency: e }) {
290
303
  this._running = 0, this.concurrency = e, this.queue = [];
291
304
  }
@@ -313,47 +326,73 @@ class G {
313
326
  }
314
327
  }
315
328
  }
316
- const V = "http://example.com";
317
- function k(s) {
329
+ const ze = "http://example.com";
330
+ function ue(s) {
318
331
  return s.toString().substring(s.origin.length);
319
332
  }
320
- function H(s, e) {
333
+ function de(s, e) {
321
334
  return !e || !s.startsWith(e) ? s : s.substring(e.length);
322
335
  }
323
- function Y(s, e) {
336
+ function Ge(s, e) {
324
337
  return !e || s.startsWith(e) ? s : e + s;
325
338
  }
326
- class J {
327
- #e;
328
- #t;
329
- #s;
330
- #r;
331
- #o;
332
- #n;
333
- #i;
334
- #a;
339
+ var b, A, N, k, O, _, I, L, D, ge, j, we, B, Pe;
340
+ class Ve {
335
341
  /**
336
342
  * @param php - The PHP instance.
337
343
  * @param config - Request Handler configuration.
338
344
  */
339
345
  constructor(e, t = {}) {
340
- this.#a = new G({ concurrency: 1 });
346
+ /**
347
+ * Serves a static file from the PHP filesystem.
348
+ *
349
+ * @param fsPath - Absolute path of the static file to serve.
350
+ * @returns The response.
351
+ */
352
+ l(this, D);
353
+ /**
354
+ * Runs the requested PHP file with all the request and $_SERVER
355
+ * superglobals populated.
356
+ *
357
+ * @param request - The request.
358
+ * @returns The response.
359
+ */
360
+ l(this, j);
361
+ /**
362
+ * Resolve the requested path to the filesystem path of the requested PHP file.
363
+ *
364
+ * Fall back to index.php as if there was a url rewriting rule in place.
365
+ *
366
+ * @param requestedPath - The requested pathname.
367
+ * @throws {Error} If the requested path doesn't exist.
368
+ * @returns The resolved filesystem path.
369
+ */
370
+ l(this, B);
371
+ l(this, b, void 0);
372
+ l(this, A, void 0);
373
+ l(this, N, void 0);
374
+ l(this, k, void 0);
375
+ l(this, O, void 0);
376
+ l(this, _, void 0);
377
+ l(this, I, void 0);
378
+ l(this, L, void 0);
379
+ p(this, L, new ye({ concurrency: 1 }));
341
380
  const {
342
381
  documentRoot: r = "/www/",
343
- absoluteUrl: n = typeof location == "object" ? location?.href : ""
382
+ absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
344
383
  } = t;
345
- this.php = e, this.#e = r;
384
+ this.php = e, p(this, b, r);
346
385
  const o = new URL(n);
347
- this.#s = o.hostname, this.#r = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
348
- const i = this.#r !== 443 && this.#r !== 80;
349
- this.#o = [
350
- this.#s,
351
- i ? `:${this.#r}` : ""
352
- ].join(""), this.#n = o.pathname.replace(/\/+$/, ""), this.#i = [
353
- `${this.#t}://`,
354
- this.#o,
355
- this.#n
356
- ].join("");
386
+ p(this, N, o.hostname), p(this, k, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, A, (o.protocol || "").replace(":", ""));
387
+ const a = i(this, k) !== 443 && i(this, k) !== 80;
388
+ p(this, O, [
389
+ i(this, N),
390
+ a ? `:${i(this, k)}` : ""
391
+ ].join("")), p(this, _, o.pathname.replace(/\/+$/, "")), p(this, I, [
392
+ `${i(this, A)}://`,
393
+ i(this, O),
394
+ i(this, _)
395
+ ].join(""));
357
396
  }
358
397
  /** @inheritDoc */
359
398
  pathToInternalUrl(e) {
@@ -362,162 +401,139 @@ class J {
362
401
  /** @inheritDoc */
363
402
  internalUrlToPath(e) {
364
403
  const t = new URL(e);
365
- return t.pathname.startsWith(this.#n) && (t.pathname = t.pathname.slice(this.#n.length)), k(t);
404
+ return t.pathname.startsWith(i(this, _)) && (t.pathname = t.pathname.slice(i(this, _).length)), ue(t);
366
405
  }
367
406
  get isRequestRunning() {
368
- return this.#a.running > 0;
407
+ return i(this, L).running > 0;
369
408
  }
370
409
  /** @inheritDoc */
371
410
  get absoluteUrl() {
372
- return this.#i;
411
+ return i(this, I);
373
412
  }
374
413
  /** @inheritDoc */
375
414
  get documentRoot() {
376
- return this.#e;
415
+ return i(this, b);
377
416
  }
378
417
  /** @inheritDoc */
379
418
  async request(e) {
380
419
  const t = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
381
420
  e.url,
382
- t ? void 0 : V
383
- ), n = H(
421
+ t ? void 0 : ze
422
+ ), n = de(
384
423
  r.pathname,
385
- this.#n
386
- ), o = `${this.#e}${n}`;
387
- return Q(o) ? await this.#c(e, r) : this.#l(o);
424
+ i(this, _)
425
+ ), o = `${i(this, b)}${n}`;
426
+ return Ke(o) ? await m(this, j, we).call(this, e, r) : m(this, D, ge).call(this, o);
388
427
  }
389
- /**
390
- * Serves a static file from the PHP filesystem.
391
- *
392
- * @param fsPath - Absolute path of the static file to serve.
393
- * @returns The response.
394
- */
395
- #l(e) {
396
- if (!this.php.fileExists(e))
397
- return new g(
398
- 404,
399
- // Let the service worker know that no static file was found
400
- // and that it's okay to issue a real fetch() to the server.
401
- {
402
- "x-file-type": ["static"]
403
- },
404
- new TextEncoder().encode("404 File not found")
405
- );
406
- const t = this.php.readFileAsBuffer(e);
407
- return new g(
408
- 200,
428
+ }
429
+ b = new WeakMap(), A = new WeakMap(), N = new WeakMap(), k = new WeakMap(), O = new WeakMap(), _ = new WeakMap(), I = new WeakMap(), L = new WeakMap(), D = new WeakSet(), ge = function(e) {
430
+ if (!this.php.fileExists(e))
431
+ return new F(
432
+ 404,
433
+ // Let the service worker know that no static file was found
434
+ // and that it's okay to issue a real fetch() to the server.
409
435
  {
410
- "content-length": [`${t.byteLength}`],
411
- // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
412
- // The code below won't return the correct mime-type if the extension
413
- // was tampered with.
414
- "content-type": [Z(e)],
415
- "accept-ranges": ["bytes"],
416
- "cache-control": ["public, max-age=0"]
436
+ "x-file-type": ["static"]
417
437
  },
418
- t
438
+ new TextEncoder().encode("404 File not found")
419
439
  );
420
- }
421
- /**
422
- * Runs the requested PHP file with all the request and $_SERVER
423
- * superglobals populated.
424
- *
425
- * @param request - The request.
426
- * @returns The response.
427
- */
428
- async #c(e, t) {
429
- const r = await this.#a.acquire();
440
+ const t = this.php.readFileAsBuffer(e);
441
+ return new F(
442
+ 200,
443
+ {
444
+ "content-length": [`${t.byteLength}`],
445
+ // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
446
+ // The code below won't return the correct mime-type if the extension
447
+ // was tampered with.
448
+ "content-type": [Ye(e)],
449
+ "accept-ranges": ["bytes"],
450
+ "cache-control": ["public, max-age=0"]
451
+ },
452
+ t
453
+ );
454
+ }, j = new WeakSet(), we = async function(e, t) {
455
+ var n;
456
+ const r = await i(this, L).acquire();
457
+ try {
458
+ this.php.addServerGlobalEntry("DOCUMENT_ROOT", i(this, b)), this.php.addServerGlobalEntry(
459
+ "HTTPS",
460
+ i(this, I).startsWith("https://") ? "on" : ""
461
+ );
462
+ let o = "GET";
463
+ const a = {
464
+ host: i(this, O),
465
+ ...$e(e.headers || {})
466
+ }, h = [];
467
+ if (e.files && Object.keys(e.files).length) {
468
+ o = "POST";
469
+ for (const u in e.files) {
470
+ const E = e.files[u];
471
+ h.push({
472
+ key: u,
473
+ name: E.name,
474
+ type: E.type,
475
+ data: new Uint8Array(await E.arrayBuffer())
476
+ });
477
+ }
478
+ (n = a["content-type"]) != null && n.startsWith("multipart/form-data") && (e.formData = Je(
479
+ e.body || ""
480
+ ), a["content-type"] = "application/x-www-form-urlencoded", delete e.body);
481
+ }
482
+ let d;
483
+ e.formData !== void 0 ? (o = "POST", a["content-type"] = a["content-type"] || "application/x-www-form-urlencoded", d = new URLSearchParams(
484
+ e.formData
485
+ ).toString()) : d = e.body;
486
+ let f;
430
487
  try {
431
- this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
432
- "HTTPS",
433
- this.#i.startsWith("https://") ? "on" : ""
488
+ f = m(this, B, Pe).call(this, t.pathname);
489
+ } catch {
490
+ return new F(
491
+ 404,
492
+ {},
493
+ new TextEncoder().encode("404 File not found")
434
494
  );
435
- let n = "GET";
436
- const o = {
437
- host: this.#o,
438
- ...A(e.headers || {})
439
- }, i = [];
440
- if (e.files && Object.keys(e.files).length) {
441
- n = "POST";
442
- for (const c in e.files) {
443
- const m = e.files[c];
444
- i.push({
445
- key: c,
446
- name: m.name,
447
- type: m.type,
448
- data: new Uint8Array(await m.arrayBuffer())
449
- });
450
- }
451
- o["content-type"]?.startsWith("multipart/form-data") && (e.formData = K(
452
- e.body || ""
453
- ), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
454
- }
455
- let l;
456
- e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
457
- e.formData
458
- ).toString()) : l = e.body;
459
- let h;
460
- try {
461
- h = this.#h(t.pathname);
462
- } catch {
463
- return new g(
464
- 404,
465
- {},
466
- new TextEncoder().encode("404 File not found")
467
- );
468
- }
469
- return await this.php.run({
470
- relativeUri: Y(
471
- k(t),
472
- this.#n
473
- ),
474
- protocol: this.#t,
475
- method: e.method || n,
476
- body: l,
477
- fileInfos: i,
478
- scriptPath: h,
479
- headers: o
480
- });
481
- } finally {
482
- r();
483
495
  }
484
- }
485
- /**
486
- * Resolve the requested path to the filesystem path of the requested PHP file.
487
- *
488
- * Fall back to index.php as if there was a url rewriting rule in place.
489
- *
490
- * @param requestedPath - The requested pathname.
491
- * @throws {Error} If the requested path doesn't exist.
492
- * @returns The resolved filesystem path.
493
- */
494
- #h(e) {
495
- let t = H(e, this.#n);
496
- t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
497
- const r = `${this.#e}${t}`;
498
- if (this.php.fileExists(r))
499
- return r;
500
- if (!this.php.fileExists(`${this.#e}/index.php`))
501
- throw new Error(`File not found: ${r}`);
502
- return `${this.#e}/index.php`;
503
- }
504
- }
505
- function K(s) {
496
+ return await this.php.run({
497
+ relativeUri: Ge(
498
+ ue(t),
499
+ i(this, _)
500
+ ),
501
+ protocol: i(this, A),
502
+ method: e.method || o,
503
+ body: d,
504
+ fileInfos: h,
505
+ scriptPath: f,
506
+ headers: a
507
+ });
508
+ } finally {
509
+ r();
510
+ }
511
+ }, B = new WeakSet(), Pe = function(e) {
512
+ let t = de(e, i(this, _));
513
+ t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
514
+ const r = `${i(this, b)}${t}`;
515
+ if (this.php.fileExists(r))
516
+ return r;
517
+ if (!this.php.fileExists(`${i(this, b)}/index.php`))
518
+ throw new Error(`File not found: ${r}`);
519
+ return `${i(this, b)}/index.php`;
520
+ };
521
+ function Je(s) {
506
522
  const e = {}, t = s.match(/--(.*)\r\n/);
507
523
  if (!t)
508
524
  return e;
509
525
  const r = t[1], n = s.split(`--${r}`);
510
526
  return n.shift(), n.pop(), n.forEach((o) => {
511
- const i = o.indexOf(`\r
527
+ const a = o.indexOf(`\r
512
528
  \r
513
- `), l = o.substring(0, i).trim(), h = o.substring(i + 4).trim(), c = l.match(/name="([^"]+)"/);
514
- if (c) {
515
- const m = c[1];
516
- e[m] = h;
529
+ `), h = o.substring(0, a).trim(), d = o.substring(a + 4).trim(), f = h.match(/name="([^"]+)"/);
530
+ if (f) {
531
+ const u = f[1];
532
+ e[u] = d;
517
533
  }
518
534
  }), e;
519
535
  }
520
- function Z(s) {
536
+ function Ye(s) {
521
537
  switch (s.split(".").pop()) {
522
538
  case "css":
523
539
  return "text/css";
@@ -557,16 +573,16 @@ function Z(s) {
557
573
  return "application-octet-stream";
558
574
  }
559
575
  }
560
- function Q(s) {
561
- return X(s) || ee(s);
576
+ function Ke(s) {
577
+ return Ze(s) || Qe(s);
562
578
  }
563
- function X(s) {
579
+ function Ze(s) {
564
580
  return s.endsWith(".php") || s.includes(".php/");
565
581
  }
566
- function ee(s) {
582
+ function Qe(s) {
567
583
  return !s.split("/").pop().includes(".");
568
584
  }
569
- const T = {
585
+ const pe = {
570
586
  0: "No error occurred. System call completed successfully.",
571
587
  1: "Argument list too long.",
572
588
  2: "Permission denied.",
@@ -645,69 +661,75 @@ const T = {
645
661
  75: "Cross-device link.",
646
662
  76: "Extension: Capabilities insufficient."
647
663
  };
648
- function p(s = "") {
664
+ function w(s = "") {
649
665
  return function(t, r, n) {
650
666
  const o = n.value;
651
- n.value = function(...i) {
667
+ n.value = function(...a) {
652
668
  try {
653
- return o.apply(this, i);
654
- } catch (l) {
655
- const h = typeof l == "object" ? l?.errno : null;
656
- if (h in T) {
657
- const c = T[h], m = typeof i[0] == "string" ? i[0] : null, O = m !== null ? s.replaceAll("{path}", m) : s;
658
- throw new Error(`${O}: ${c}`, {
659
- cause: l
669
+ return o.apply(this, a);
670
+ } catch (h) {
671
+ const d = typeof h == "object" ? h == null ? void 0 : h.errno : null;
672
+ if (d in pe) {
673
+ const f = pe[d], u = typeof a[0] == "string" ? a[0] : null, E = u !== null ? s.replaceAll("{path}", u) : s;
674
+ throw new Error(`${E}: ${f}`, {
675
+ cause: h
660
676
  });
661
677
  }
662
- throw l;
678
+ throw h;
663
679
  }
664
680
  };
665
681
  };
666
682
  }
667
- async function ce(s, e = {}, t = []) {
668
- const [r, n, o] = C(), [i, l] = C(), h = s.init(re, {
669
- onAbort(c) {
670
- o(c), l(), console.error(c);
683
+ const Xe = Symbol("RuntimeId"), q = /* @__PURE__ */ new Map();
684
+ async function ct(s, e = {}, t = []) {
685
+ const [r, n, o] = fe(), [a, h] = fe(), d = s.init(tt, {
686
+ onAbort(u) {
687
+ o(u), h(), console.error(u);
671
688
  },
672
689
  ENV: {},
673
690
  // Emscripten sometimes prepends a '/' to the path, which
674
691
  // breaks vite dev mode. An identity `locateFile` function
675
692
  // fixes it.
676
- locateFile: (c) => c,
693
+ locateFile: (u) => u,
677
694
  ...e,
678
695
  noInitialRun: !0,
679
696
  onRuntimeInitialized() {
680
697
  e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
681
698
  },
682
- monitorRunDependencies(c) {
683
- c === 0 && (delete h.monitorRunDependencies, l());
699
+ monitorRunDependencies(u) {
700
+ u === 0 && (delete d.monitorRunDependencies, h());
684
701
  }
685
702
  });
686
- return await Promise.all(
703
+ await Promise.all(
687
704
  t.map(
688
- ({ default: c }) => c(h)
705
+ ({ default: u }) => u(d)
689
706
  )
690
- ), t.length || l(), await i, await r, P.push(h), P.length - 1;
707
+ ), t.length || h(), await a, await r;
708
+ const f = q.size;
709
+ return d.originalExit = d._exit, d._exit = function(u) {
710
+ return q.delete(f), d.originalExit(u);
711
+ }, d[Xe] = f, q.set(f, d), f;
691
712
  }
692
- const P = [];
693
- function te(s) {
694
- return P[s];
713
+ function et(s) {
714
+ return q.get(s);
695
715
  }
696
- const re = function() {
697
- return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
698
- }(), C = () => {
716
+ const tt = function() {
717
+ var s;
718
+ return typeof process < "u" && ((s = process.release) == null ? void 0 : s.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
719
+ }(), fe = () => {
699
720
  const s = [], e = new Promise((t, r) => {
700
721
  s.push(t, r);
701
722
  });
702
723
  return s.unshift(e), s;
703
724
  };
704
- var se = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, f = (s, e, t, r) => {
705
- for (var n = r > 1 ? void 0 : r ? ne(e, t) : e, o = s.length - 1, i; o >= 0; o--)
706
- (i = s[o]) && (n = (r ? i(e, t, n) : i(n)) || n);
707
- return r && n && se(e, t, n), n;
725
+ var st = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, P = (s, e, t, r) => {
726
+ for (var n = r > 1 ? void 0 : r ? rt(e, t) : e, o = s.length - 1, a; o >= 0; o--)
727
+ (a = s[o]) && (n = (r ? a(e, t, n) : a(n)) || n);
728
+ return r && n && st(e, t, n), n;
708
729
  };
709
- const u = "string", y = "number", a = Symbol("__private__dont__use");
710
- class d {
730
+ const y = "string", T = "number", c = Symbol("__private__dont__use");
731
+ var H, x, C, R, v, U, M, W, be, z, _e, G, Ee, V, ve, J, xe, Y, Re, K, Se, Z, ke, Q, He, X, Ce, ee, Te, te, Fe;
732
+ class g {
711
733
  /**
712
734
  * Initializes a PHP runtime.
713
735
  *
@@ -716,18 +738,58 @@ class d {
716
738
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
717
739
  */
718
740
  constructor(e, t) {
719
- this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, this.#o = [], e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new z(
720
- new J(this, t)
741
+ l(this, W);
742
+ l(this, z);
743
+ l(this, G);
744
+ l(this, V);
745
+ l(this, J);
746
+ l(this, Y);
747
+ l(this, K);
748
+ l(this, Z);
749
+ l(this, Q);
750
+ /**
751
+ * Adds file information to $_FILES superglobal in PHP.
752
+ *
753
+ * In particular:
754
+ * * Creates the file data in the filesystem
755
+ * * Registers the file details in PHP
756
+ *
757
+ * @param fileInfo - File details
758
+ */
759
+ l(this, X);
760
+ l(this, ee);
761
+ l(this, te);
762
+ l(this, H, void 0);
763
+ l(this, x, void 0);
764
+ l(this, C, void 0);
765
+ l(this, R, void 0);
766
+ l(this, v, void 0);
767
+ l(this, U, void 0);
768
+ l(this, M, void 0);
769
+ p(this, H, []), p(this, x, !1), p(this, C, null), p(this, R, {}), p(this, v, /* @__PURE__ */ new Map()), p(this, U, []), p(this, M, new ye({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new We(
770
+ new Ve(this, t)
721
771
  ));
722
772
  }
723
- #e;
724
- #t;
725
- #s;
726
- #r;
727
- #o;
773
+ addEventListener(e, t) {
774
+ i(this, v).has(e) || i(this, v).set(e, /* @__PURE__ */ new Set()), i(this, v).get(e).add(t);
775
+ }
776
+ removeEventListener(e, t) {
777
+ var r;
778
+ (r = i(this, v).get(e)) == null || r.delete(t);
779
+ }
780
+ dispatchEvent(e) {
781
+ const t = i(this, v).get(e.type);
782
+ if (t)
783
+ for (const r of t)
784
+ r(e);
785
+ }
728
786
  /** @inheritDoc */
729
787
  async onMessage(e) {
730
- this.#o.push(e);
788
+ i(this, U).push(e);
789
+ }
790
+ /** @inheritDoc */
791
+ async setSpawnHandler(e) {
792
+ this[c].spawnProcess = e;
731
793
  }
732
794
  /** @inheritDoc */
733
795
  get absoluteUrl() {
@@ -748,21 +810,25 @@ class d {
748
810
  );
749
811
  }
750
812
  initializeRuntime(e) {
751
- if (this[a])
813
+ if (this[c])
752
814
  throw new Error("PHP runtime already initialized.");
753
- const t = te(e);
815
+ const t = et(e);
754
816
  if (!t)
755
817
  throw new Error("Invalid PHP runtime id.");
756
- this[a] = t, t.onMessage = (r) => {
757
- for (const n of this.#o)
758
- n(r);
759
- }, this.#s = N(t);
818
+ this[c] = t, t.onMessage = async (r) => {
819
+ for (const n of i(this, U)) {
820
+ const o = await n(r);
821
+ if (o)
822
+ return o;
823
+ }
824
+ return "";
825
+ }, p(this, C, Le(t));
760
826
  }
761
827
  /** @inheritDoc */
762
828
  setPhpIniPath(e) {
763
- if (this.#t)
829
+ if (i(this, x))
764
830
  throw new Error("Cannot set PHP ini path after calling run().");
765
- this[a].ccall(
831
+ this[c].ccall(
766
832
  "wasm_set_phpini_path",
767
833
  null,
768
834
  ["string"],
@@ -771,13 +837,13 @@ class d {
771
837
  }
772
838
  /** @inheritDoc */
773
839
  setPhpIniEntry(e, t) {
774
- if (this.#t)
840
+ if (i(this, x))
775
841
  throw new Error("Cannot set PHP ini entries after calling run().");
776
- this.#e.push([e, t]);
842
+ i(this, H).push([e, t]);
777
843
  }
778
844
  /** @inheritDoc */
779
845
  chdir(e) {
780
- this[a].FS.chdir(e);
846
+ this[c].FS.chdir(e);
781
847
  }
782
848
  /** @inheritDoc */
783
849
  async request(e, t) {
@@ -787,221 +853,41 @@ class d {
787
853
  }
788
854
  /** @inheritDoc */
789
855
  async run(e) {
790
- this.#t || (this.#n(), this.#t = !0), this.#d(e.scriptPath || ""), this.#a(e.relativeUri || ""), this.#c(e.method || "GET");
791
- const { host: t, ...r } = {
792
- host: "example.com:443",
793
- ...A(e.headers || {})
794
- };
795
- if (this.#l(t, e.protocol || "http"), this.#h(r), e.body && this.#u(e.body), e.fileInfos)
796
- for (const n of e.fileInfos)
797
- this.#f(n);
798
- return e.code && this.#m(" ?>" + e.code), this.#p(), await this.#y();
799
- }
800
- #n() {
801
- if (this.#e.length > 0) {
802
- const e = this.#e.map(([t, r]) => `${t}=${r}`).join(`
803
- `) + `
804
-
805
- `;
806
- this[a].ccall(
807
- "wasm_set_phpini_entries",
808
- null,
809
- [u],
810
- [e]
811
- );
812
- }
813
- this[a].ccall("php_wasm_init", null, [], []);
814
- }
815
- #i() {
816
- const e = "/tmp/headers.json";
817
- if (!this.fileExists(e))
818
- throw new Error(
819
- "SAPI Error: Could not find response headers file."
820
- );
821
- const t = JSON.parse(this.readFileAsText(e)), r = {};
822
- for (const n of t.headers) {
823
- if (!n.includes(": "))
824
- continue;
825
- const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), l = n.substring(o + 2);
826
- i in r || (r[i] = []), r[i].push(l);
827
- }
828
- return {
829
- headers: r,
830
- httpStatusCode: t.status
831
- };
832
- }
833
- #a(e) {
834
- if (this[a].ccall(
835
- "wasm_set_request_uri",
836
- null,
837
- [u],
838
- [e]
839
- ), e.includes("?")) {
840
- const t = e.substring(e.indexOf("?") + 1);
841
- this[a].ccall(
842
- "wasm_set_query_string",
843
- null,
844
- [u],
845
- [t]
846
- );
847
- }
848
- }
849
- #l(e, t) {
850
- this[a].ccall(
851
- "wasm_set_request_host",
852
- null,
853
- [u],
854
- [e]
855
- );
856
- let r;
856
+ const t = await i(this, M).acquire();
857
857
  try {
858
- r = parseInt(new URL(e).port, 10);
859
- } catch {
860
- }
861
- (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), this[a].ccall(
862
- "wasm_set_request_port",
863
- null,
864
- [y],
865
- [r]
866
- ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
867
- }
868
- #c(e) {
869
- this[a].ccall(
870
- "wasm_set_request_method",
871
- null,
872
- [u],
873
- [e]
874
- );
875
- }
876
- #h(e) {
877
- e.cookie && this[a].ccall(
878
- "wasm_set_cookies",
879
- null,
880
- [u],
881
- [e.cookie]
882
- ), e["content-type"] && this[a].ccall(
883
- "wasm_set_content_type",
884
- null,
885
- [u],
886
- [e["content-type"]]
887
- ), e["content-length"] && this[a].ccall(
888
- "wasm_set_content_length",
889
- null,
890
- [y],
891
- [parseInt(e["content-length"], 10)]
892
- );
893
- for (const t in e) {
894
- let r = "HTTP_";
895
- ["content-type", "content-length"].includes(t.toLowerCase()) && (r = ""), this.addServerGlobalEntry(
896
- `${r}${t.toUpperCase().replace(/-/g, "_")}`,
897
- e[t]
898
- );
858
+ i(this, x) || (m(this, W, be).call(this), p(this, x, !0)), m(this, Z, ke).call(this, e.scriptPath || ""), m(this, G, Ee).call(this, e.relativeUri || ""), m(this, J, xe).call(this, e.method || "GET");
859
+ const r = $e(e.headers || {}), n = r.host || "example.com:443";
860
+ if (m(this, V, ve).call(this, n, e.protocol || "http"), m(this, Y, Re).call(this, r), e.body && m(this, K, Se).call(this, e.body), e.fileInfos)
861
+ for (const o of e.fileInfos)
862
+ m(this, X, Ce).call(this, o);
863
+ return e.code && m(this, ee, Te).call(this, " ?>" + e.code), m(this, Q, He).call(this), await m(this, te, Fe).call(this);
864
+ } finally {
865
+ t(), this.dispatchEvent({
866
+ type: "request.end"
867
+ });
899
868
  }
900
869
  }
901
- #u(e) {
902
- this[a].ccall(
903
- "wasm_set_request_body",
904
- null,
905
- [u],
906
- [e]
907
- ), this[a].ccall(
908
- "wasm_set_content_length",
909
- null,
910
- [y],
911
- [new TextEncoder().encode(e).length]
912
- );
913
- }
914
- #d(e) {
915
- this[a].ccall(
916
- "wasm_set_path_translated",
917
- null,
918
- [u],
919
- [e]
920
- );
921
- }
922
870
  addServerGlobalEntry(e, t) {
923
- this.#r[e] = t;
924
- }
925
- #p() {
926
- for (const e in this.#r)
927
- this[a].ccall(
928
- "wasm_add_SERVER_entry",
929
- null,
930
- [u, u],
931
- [e, this.#r[e]]
932
- );
933
- }
934
- /**
935
- * Adds file information to $_FILES superglobal in PHP.
936
- *
937
- * In particular:
938
- * * Creates the file data in the filesystem
939
- * * Registers the file details in PHP
940
- *
941
- * @param fileInfo - File details
942
- */
943
- #f(e) {
944
- const { key: t, name: r, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
945
- this.writeFile(i, o);
946
- const l = 0;
947
- this[a].ccall(
948
- "wasm_add_uploaded_file",
949
- null,
950
- [u, u, u, u, y, y],
951
- [t, r, n, i, l, o.byteLength]
952
- );
953
- }
954
- #m(e) {
955
- this[a].ccall(
956
- "wasm_set_php_code",
957
- null,
958
- [u],
959
- [e]
960
- );
871
+ i(this, R)[e] = t;
961
872
  }
962
- async #y() {
963
- let e, t;
873
+ defineConstant(e, t) {
874
+ let r = {};
964
875
  try {
965
- e = await new Promise((o, i) => {
966
- t = (h) => {
967
- const c = new Error("Rethrown");
968
- c.cause = h.error, c.betterMessage = h.message, i(c);
969
- }, this.#s?.addEventListener(
970
- "error",
971
- t
972
- );
973
- const l = this[a].ccall(
974
- "wasm_sapi_handle_request",
975
- y,
976
- [],
977
- []
978
- );
979
- return l instanceof Promise ? l.then(o, i) : o(l);
980
- });
981
- } catch (o) {
982
- for (const c in this)
983
- typeof this[c] == "function" && (this[c] = () => {
984
- throw new Error(
985
- "PHP runtime has crashed – see the earlier error for details."
986
- );
987
- });
988
- this.functionsMaybeMissingFromAsyncify = $();
989
- const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, h = new Error(l);
990
- throw h.cause = i, h;
991
- } finally {
992
- this.#s?.removeEventListener("error", t), this.#r = {};
876
+ r = JSON.parse(
877
+ this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
878
+ );
879
+ } catch {
993
880
  }
994
- const { headers: r, httpStatusCode: n } = this.#i();
995
- return new g(
996
- n,
997
- r,
998
- this.readFileAsBuffer("/tmp/stdout"),
999
- this.readFileAsText("/tmp/stderr"),
1000
- e
881
+ this.writeFile(
882
+ "/tmp/consts.json",
883
+ JSON.stringify({
884
+ ...r,
885
+ [e]: t
886
+ })
1001
887
  );
1002
888
  }
1003
889
  mkdir(e) {
1004
- this[a].FS.mkdirTree(e);
890
+ this[c].FS.mkdirTree(e);
1005
891
  }
1006
892
  mkdirTree(e) {
1007
893
  this.mkdir(e);
@@ -1010,28 +896,28 @@ class d {
1010
896
  return new TextDecoder().decode(this.readFileAsBuffer(e));
1011
897
  }
1012
898
  readFileAsBuffer(e) {
1013
- return this[a].FS.readFile(e);
899
+ return this[c].FS.readFile(e);
1014
900
  }
1015
901
  writeFile(e, t) {
1016
- this[a].FS.writeFile(e, t);
902
+ this[c].FS.writeFile(e, t);
1017
903
  }
1018
904
  unlink(e) {
1019
- this[a].FS.unlink(e);
905
+ this[c].FS.unlink(e);
1020
906
  }
1021
907
  mv(e, t) {
1022
- this[a].FS.rename(e, t);
908
+ this[c].FS.rename(e, t);
1023
909
  }
1024
910
  rmdir(e, t = { recursive: !0 }) {
1025
- t?.recursive && this.listFiles(e).forEach((r) => {
911
+ t != null && t.recursive && this.listFiles(e).forEach((r) => {
1026
912
  const n = `${e}/${r}`;
1027
913
  this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
1028
- }), this[a].FS.rmdir(e);
914
+ }), this[c].FS.rmdir(e);
1029
915
  }
1030
916
  listFiles(e, t = { prependPath: !1 }) {
1031
917
  if (!this.fileExists(e))
1032
918
  return [];
1033
919
  try {
1034
- const r = this[a].FS.readdir(e).filter(
920
+ const r = this[c].FS.readdir(e).filter(
1035
921
  (n) => n !== "." && n !== ".."
1036
922
  );
1037
923
  if (t.prependPath) {
@@ -1044,82 +930,279 @@ class d {
1044
930
  }
1045
931
  }
1046
932
  isDir(e) {
1047
- return this.fileExists(e) ? this[a].FS.isDir(
1048
- this[a].FS.lookupPath(e).node.mode
933
+ return this.fileExists(e) ? this[c].FS.isDir(
934
+ this[c].FS.lookupPath(e).node.mode
1049
935
  ) : !1;
1050
936
  }
1051
937
  fileExists(e) {
1052
938
  try {
1053
- return this[a].FS.lookupPath(e), !0;
939
+ return this[c].FS.lookupPath(e), !0;
1054
940
  } catch {
1055
941
  return !1;
1056
942
  }
1057
943
  }
944
+ exit(e = 0) {
945
+ return this[c]._exit(e);
946
+ }
1058
947
  }
1059
- f([
1060
- p('Could not create directory "{path}"')
1061
- ], d.prototype, "mkdir", 1);
1062
- f([
1063
- p('Could not create directory "{path}"')
1064
- ], d.prototype, "mkdirTree", 1);
1065
- f([
1066
- p('Could not read "{path}"')
1067
- ], d.prototype, "readFileAsText", 1);
1068
- f([
1069
- p('Could not read "{path}"')
1070
- ], d.prototype, "readFileAsBuffer", 1);
1071
- f([
1072
- p('Could not write to "{path}"')
1073
- ], d.prototype, "writeFile", 1);
1074
- f([
1075
- p('Could not unlink "{path}"')
1076
- ], d.prototype, "unlink", 1);
1077
- f([
1078
- p('Could not move "{path}"')
1079
- ], d.prototype, "mv", 1);
1080
- f([
1081
- p('Could not remove directory "{path}"')
1082
- ], d.prototype, "rmdir", 1);
1083
- f([
1084
- p('Could not list files in "{path}"')
1085
- ], d.prototype, "listFiles", 1);
1086
- f([
1087
- p('Could not stat "{path}"')
1088
- ], d.prototype, "isDir", 1);
1089
- f([
1090
- p('Could not stat "{path}"')
1091
- ], d.prototype, "fileExists", 1);
1092
- function A(s) {
948
+ H = new WeakMap(), x = new WeakMap(), C = new WeakMap(), R = new WeakMap(), v = new WeakMap(), U = new WeakMap(), M = new WeakMap(), W = new WeakSet(), be = function() {
949
+ if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
950
+ "/tmp/consts.php",
951
+ `<?php
952
+ if(file_exists('/tmp/consts.json')) {
953
+ $consts = json_decode(file_get_contents('/tmp/consts.json'), true);
954
+ foreach ($consts as $const => $value) {
955
+ if (!defined($const) && is_scalar($value)) {
956
+ define($const, $value);
957
+ }
958
+ }
959
+ }`
960
+ ), i(this, H).length > 0) {
961
+ const e = i(this, H).map(([t, r]) => `${t}=${r}`).join(`
962
+ `) + `
963
+
964
+ `;
965
+ this[c].ccall(
966
+ "wasm_set_phpini_entries",
967
+ null,
968
+ [y],
969
+ [e]
970
+ );
971
+ }
972
+ this[c].ccall("php_wasm_init", null, [], []);
973
+ }, z = new WeakSet(), _e = function() {
974
+ const e = "/tmp/headers.json";
975
+ if (!this.fileExists(e))
976
+ throw new Error(
977
+ "SAPI Error: Could not find response headers file."
978
+ );
979
+ const t = JSON.parse(this.readFileAsText(e)), r = {};
980
+ for (const n of t.headers) {
981
+ if (!n.includes(": "))
982
+ continue;
983
+ const o = n.indexOf(": "), a = n.substring(0, o).toLowerCase(), h = n.substring(o + 2);
984
+ a in r || (r[a] = []), r[a].push(h);
985
+ }
986
+ return {
987
+ headers: r,
988
+ httpStatusCode: t.status
989
+ };
990
+ }, G = new WeakSet(), Ee = function(e) {
991
+ if (this[c].ccall(
992
+ "wasm_set_request_uri",
993
+ null,
994
+ [y],
995
+ [e]
996
+ ), e.includes("?")) {
997
+ const t = e.substring(e.indexOf("?") + 1);
998
+ this[c].ccall(
999
+ "wasm_set_query_string",
1000
+ null,
1001
+ [y],
1002
+ [t]
1003
+ );
1004
+ }
1005
+ }, V = new WeakSet(), ve = function(e, t) {
1006
+ this[c].ccall(
1007
+ "wasm_set_request_host",
1008
+ null,
1009
+ [y],
1010
+ [e]
1011
+ );
1012
+ let r;
1013
+ try {
1014
+ r = parseInt(new URL(e).port, 10);
1015
+ } catch {
1016
+ }
1017
+ (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), this[c].ccall(
1018
+ "wasm_set_request_port",
1019
+ null,
1020
+ [T],
1021
+ [r]
1022
+ ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1023
+ }, J = new WeakSet(), xe = function(e) {
1024
+ this[c].ccall(
1025
+ "wasm_set_request_method",
1026
+ null,
1027
+ [y],
1028
+ [e]
1029
+ );
1030
+ }, Y = new WeakSet(), Re = function(e) {
1031
+ e.cookie && this[c].ccall(
1032
+ "wasm_set_cookies",
1033
+ null,
1034
+ [y],
1035
+ [e.cookie]
1036
+ ), e["content-type"] && this[c].ccall(
1037
+ "wasm_set_content_type",
1038
+ null,
1039
+ [y],
1040
+ [e["content-type"]]
1041
+ ), e["content-length"] && this[c].ccall(
1042
+ "wasm_set_content_length",
1043
+ null,
1044
+ [T],
1045
+ [parseInt(e["content-length"], 10)]
1046
+ );
1047
+ for (const t in e) {
1048
+ let r = "HTTP_";
1049
+ ["content-type", "content-length"].includes(t.toLowerCase()) && (r = ""), this.addServerGlobalEntry(
1050
+ `${r}${t.toUpperCase().replace(/-/g, "_")}`,
1051
+ e[t]
1052
+ );
1053
+ }
1054
+ }, K = new WeakSet(), Se = function(e) {
1055
+ this[c].ccall(
1056
+ "wasm_set_request_body",
1057
+ null,
1058
+ [y],
1059
+ [e]
1060
+ ), this[c].ccall(
1061
+ "wasm_set_content_length",
1062
+ null,
1063
+ [T],
1064
+ [new TextEncoder().encode(e).length]
1065
+ );
1066
+ }, Z = new WeakSet(), ke = function(e) {
1067
+ this[c].ccall(
1068
+ "wasm_set_path_translated",
1069
+ null,
1070
+ [y],
1071
+ [e]
1072
+ );
1073
+ }, Q = new WeakSet(), He = function() {
1074
+ for (const e in i(this, R))
1075
+ this[c].ccall(
1076
+ "wasm_add_SERVER_entry",
1077
+ null,
1078
+ [y, y],
1079
+ [e, i(this, R)[e]]
1080
+ );
1081
+ }, X = new WeakSet(), Ce = function(e) {
1082
+ const { key: t, name: r, type: n, data: o } = e, a = `/tmp/${Math.random().toFixed(20)}`;
1083
+ this.writeFile(a, o);
1084
+ const h = 0;
1085
+ this[c].ccall(
1086
+ "wasm_add_uploaded_file",
1087
+ null,
1088
+ [y, y, y, y, T, T],
1089
+ [t, r, n, a, h, o.byteLength]
1090
+ );
1091
+ }, ee = new WeakSet(), Te = function(e) {
1092
+ this[c].ccall(
1093
+ "wasm_set_php_code",
1094
+ null,
1095
+ [y],
1096
+ [e]
1097
+ );
1098
+ }, te = new WeakSet(), Fe = async function() {
1099
+ var o;
1100
+ let e, t;
1101
+ try {
1102
+ e = await new Promise((a, h) => {
1103
+ var f;
1104
+ t = (u) => {
1105
+ const E = new Error("Rethrown");
1106
+ E.cause = u.error, E.betterMessage = u.message, h(E);
1107
+ }, (f = i(this, C)) == null || f.addEventListener(
1108
+ "error",
1109
+ t
1110
+ );
1111
+ const d = this[c].ccall(
1112
+ "wasm_sapi_handle_request",
1113
+ T,
1114
+ [],
1115
+ [],
1116
+ { async: !0 }
1117
+ );
1118
+ return d instanceof Promise ? d.then(a, h) : a(d);
1119
+ });
1120
+ } catch (a) {
1121
+ for (const u in this)
1122
+ typeof this[u] == "function" && (this[u] = () => {
1123
+ throw new Error(
1124
+ "PHP runtime has crashed – see the earlier error for details."
1125
+ );
1126
+ });
1127
+ this.functionsMaybeMissingFromAsyncify = Ue();
1128
+ const h = a, d = "betterMessage" in h ? h.betterMessage : h.message, f = new Error(d);
1129
+ throw f.cause = h, f;
1130
+ } finally {
1131
+ (o = i(this, C)) == null || o.removeEventListener("error", t), p(this, R, {});
1132
+ }
1133
+ const { headers: r, httpStatusCode: n } = m(this, z, _e).call(this);
1134
+ return new F(
1135
+ n,
1136
+ r,
1137
+ this.readFileAsBuffer("/tmp/stdout"),
1138
+ this.readFileAsText("/tmp/stderr"),
1139
+ e
1140
+ );
1141
+ };
1142
+ P([
1143
+ w('Could not create directory "{path}"')
1144
+ ], g.prototype, "mkdir", 1);
1145
+ P([
1146
+ w('Could not create directory "{path}"')
1147
+ ], g.prototype, "mkdirTree", 1);
1148
+ P([
1149
+ w('Could not read "{path}"')
1150
+ ], g.prototype, "readFileAsText", 1);
1151
+ P([
1152
+ w('Could not read "{path}"')
1153
+ ], g.prototype, "readFileAsBuffer", 1);
1154
+ P([
1155
+ w('Could not write to "{path}"')
1156
+ ], g.prototype, "writeFile", 1);
1157
+ P([
1158
+ w('Could not unlink "{path}"')
1159
+ ], g.prototype, "unlink", 1);
1160
+ P([
1161
+ w('Could not move "{path}"')
1162
+ ], g.prototype, "mv", 1);
1163
+ P([
1164
+ w('Could not remove directory "{path}"')
1165
+ ], g.prototype, "rmdir", 1);
1166
+ P([
1167
+ w('Could not list files in "{path}"')
1168
+ ], g.prototype, "listFiles", 1);
1169
+ P([
1170
+ w('Could not stat "{path}"')
1171
+ ], g.prototype, "isDir", 1);
1172
+ P([
1173
+ w('Could not stat "{path}"')
1174
+ ], g.prototype, "fileExists", 1);
1175
+ function $e(s) {
1093
1176
  const e = {};
1094
1177
  for (const t in s)
1095
1178
  e[t.toLowerCase()] = s[t];
1096
1179
  return e;
1097
1180
  }
1098
- function oe(s) {
1099
- return !(s instanceof d);
1181
+ function nt(s) {
1182
+ return !(s instanceof g);
1100
1183
  }
1101
- function he(s) {
1102
- return !oe(s);
1184
+ function ht(s) {
1185
+ return !nt(s);
1103
1186
  }
1104
1187
  export {
1105
- d as BasePHP,
1106
- V as DEFAULT_BASE_URL,
1107
- ie as LatestSupportedPHPVersion,
1108
- z as PHPBrowser,
1109
- J as PHPRequestHandler,
1110
- g as PHPResponse,
1111
- le as SupportedPHPExtensionBundles,
1112
- j as SupportedPHPExtensionsList,
1113
- F as SupportedPHPVersions,
1114
- ae as SupportedPHPVersionsList,
1115
- L as UnhandledRejectionsTarget,
1116
- a as __private__dont__use,
1117
- Y as ensurePathPrefix,
1118
- I as isExitCodeZero,
1119
- oe as isLocalPHP,
1120
- he as isRemotePHP,
1121
- ce as loadPHPRuntime,
1122
- H as removePathPrefix,
1123
- p as rethrowFileSystemError,
1124
- k as toRelativeUrl
1188
+ g as BasePHP,
1189
+ ze as DEFAULT_BASE_URL,
1190
+ ot as LatestSupportedPHPVersion,
1191
+ We as PHPBrowser,
1192
+ Ve as PHPRequestHandler,
1193
+ F as PHPResponse,
1194
+ lt as SupportedPHPExtensionBundles,
1195
+ Be as SupportedPHPExtensionsList,
1196
+ me as SupportedPHPVersions,
1197
+ at as SupportedPHPVersionsList,
1198
+ Ie as UnhandledRejectionsTarget,
1199
+ c as __private__dont__use,
1200
+ Ge as ensurePathPrefix,
1201
+ Oe as isExitCodeZero,
1202
+ nt as isLocalPHP,
1203
+ ht as isRemotePHP,
1204
+ ct as loadPHPRuntime,
1205
+ de as removePathPrefix,
1206
+ w as rethrowFileSystemError,
1207
+ ue as toRelativeUrl
1125
1208
  };