@php-wasm/web 0.6.16 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +100 -201
- package/index.js +363 -298
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Z = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var u = (e, t, r) => (
|
|
5
|
+
var u = (e, t, r) => (Z(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
9
|
-
}, p = (e, t, r, s) => (
|
|
10
|
-
var f = (e, t, r) => (
|
|
9
|
+
}, p = (e, t, r, s) => (Z(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var f = (e, t, r) => (Z(e, t, "access private method"), r);
|
|
11
11
|
const currentJsRuntime$1 = function() {
|
|
12
12
|
var e;
|
|
13
13
|
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
@@ -59,10 +59,10 @@ if (currentJsRuntime$1 === "NODE") {
|
|
|
59
59
|
const o = n.byobRequest.view, a = await s.slice(
|
|
60
60
|
r,
|
|
61
61
|
r + o.byteLength
|
|
62
|
-
).arrayBuffer(),
|
|
63
|
-
new Uint8Array(o.buffer).set(
|
|
64
|
-
const
|
|
65
|
-
n.byobRequest.respond(
|
|
62
|
+
).arrayBuffer(), c = new Uint8Array(a);
|
|
63
|
+
new Uint8Array(o.buffer).set(c);
|
|
64
|
+
const l = c.byteLength;
|
|
65
|
+
n.byobRequest.respond(l), r += l, r >= s.size && n.close();
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -226,18 +226,40 @@ function extractPHPFunctionsFromStack(e) {
|
|
|
226
226
|
return [];
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
+
const SleepFinished = Symbol("SleepFinished");
|
|
230
|
+
function sleep(e) {
|
|
231
|
+
return new Promise((t) => {
|
|
232
|
+
setTimeout(() => t(SleepFinished), e);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
class AcquireTimeoutError extends Error {
|
|
236
|
+
constructor() {
|
|
237
|
+
super("Acquiring lock timed out");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
229
240
|
class Semaphore {
|
|
230
|
-
constructor({ concurrency: t }) {
|
|
231
|
-
this._running = 0, this.concurrency = t, this.queue = [];
|
|
241
|
+
constructor({ concurrency: t, timeout: r }) {
|
|
242
|
+
this._running = 0, this.concurrency = t, this.timeout = r, this.queue = [];
|
|
243
|
+
}
|
|
244
|
+
get remaining() {
|
|
245
|
+
return this.concurrency - this.running;
|
|
232
246
|
}
|
|
233
247
|
get running() {
|
|
234
248
|
return this._running;
|
|
235
249
|
}
|
|
236
250
|
async acquire() {
|
|
237
251
|
for (; ; )
|
|
238
|
-
if (this._running >= this.concurrency)
|
|
239
|
-
|
|
240
|
-
|
|
252
|
+
if (this._running >= this.concurrency) {
|
|
253
|
+
const t = new Promise((r) => {
|
|
254
|
+
this.queue.push(r);
|
|
255
|
+
});
|
|
256
|
+
this.timeout !== void 0 ? await Promise.race([t, sleep(this.timeout)]).then(
|
|
257
|
+
(r) => {
|
|
258
|
+
if (r === SleepFinished)
|
|
259
|
+
throw new AcquireTimeoutError();
|
|
260
|
+
}
|
|
261
|
+
) : await t;
|
|
262
|
+
} else {
|
|
241
263
|
this._running++;
|
|
242
264
|
let t = !1;
|
|
243
265
|
return () => {
|
|
@@ -287,8 +309,8 @@ function splitShellCommand(e) {
|
|
|
287
309
|
const o = [];
|
|
288
310
|
let i = "";
|
|
289
311
|
for (let a = 0; a < e.length; a++) {
|
|
290
|
-
const
|
|
291
|
-
|
|
312
|
+
const c = e[a];
|
|
313
|
+
c === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, i += e[a]) : s === 0 ? c === '"' || c === "'" ? (s = 1, n = c) : c.match(/\s/) ? (i.trim().length && o.push(i.trim()), i = c) : o.length && !i ? i = o.pop() + c : i += c : s === 1 && (c === n ? (s = 0, n = "") : i += c);
|
|
292
314
|
}
|
|
293
315
|
return i && o.push(i.trim()), o;
|
|
294
316
|
}
|
|
@@ -421,96 +443,7 @@ const SupportedPHPVersions = [
|
|
|
421
443
|
"7.2",
|
|
422
444
|
"7.1",
|
|
423
445
|
"7.0"
|
|
424
|
-
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
425
|
-
var R, T;
|
|
426
|
-
class PHPBrowser {
|
|
427
|
-
/**
|
|
428
|
-
* @param server - The PHP server to browse.
|
|
429
|
-
* @param config - The browser configuration.
|
|
430
|
-
*/
|
|
431
|
-
constructor(t, r = {}) {
|
|
432
|
-
d(this, R, void 0);
|
|
433
|
-
d(this, T, void 0);
|
|
434
|
-
this.requestHandler = t, p(this, R, {}), p(this, T, {
|
|
435
|
-
handleRedirects: !1,
|
|
436
|
-
maxRedirects: 4,
|
|
437
|
-
...r
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Sends the request to the server.
|
|
442
|
-
*
|
|
443
|
-
* When cookies are present in the response, this method stores
|
|
444
|
-
* them and sends them with any subsequent requests.
|
|
445
|
-
*
|
|
446
|
-
* When a redirection is present in the response, this method
|
|
447
|
-
* follows it by discarding a response and sending a subsequent
|
|
448
|
-
* request.
|
|
449
|
-
*
|
|
450
|
-
* @param request - The request.
|
|
451
|
-
* @param redirects - Internal. The number of redirects handled so far.
|
|
452
|
-
* @returns PHPRequestHandler response.
|
|
453
|
-
*/
|
|
454
|
-
async request(t, r = 0) {
|
|
455
|
-
const s = await this.requestHandler.request({
|
|
456
|
-
...t,
|
|
457
|
-
headers: {
|
|
458
|
-
...t.headers,
|
|
459
|
-
cookie: this.serializeCookies()
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), u(this, T).handleRedirects && s.headers.location && r < u(this, T).maxRedirects) {
|
|
463
|
-
const n = new URL(
|
|
464
|
-
s.headers.location[0],
|
|
465
|
-
this.requestHandler.absoluteUrl
|
|
466
|
-
);
|
|
467
|
-
return this.request(
|
|
468
|
-
{
|
|
469
|
-
url: n.toString(),
|
|
470
|
-
method: "GET",
|
|
471
|
-
headers: {}
|
|
472
|
-
},
|
|
473
|
-
r + 1
|
|
474
|
-
);
|
|
475
|
-
}
|
|
476
|
-
return s;
|
|
477
|
-
}
|
|
478
|
-
/** @inheritDoc */
|
|
479
|
-
pathToInternalUrl(t) {
|
|
480
|
-
return this.requestHandler.pathToInternalUrl(t);
|
|
481
|
-
}
|
|
482
|
-
/** @inheritDoc */
|
|
483
|
-
internalUrlToPath(t) {
|
|
484
|
-
return this.requestHandler.internalUrlToPath(t);
|
|
485
|
-
}
|
|
486
|
-
/** @inheritDoc */
|
|
487
|
-
get absoluteUrl() {
|
|
488
|
-
return this.requestHandler.absoluteUrl;
|
|
489
|
-
}
|
|
490
|
-
/** @inheritDoc */
|
|
491
|
-
get documentRoot() {
|
|
492
|
-
return this.requestHandler.documentRoot;
|
|
493
|
-
}
|
|
494
|
-
setCookies(t) {
|
|
495
|
-
for (const r of t)
|
|
496
|
-
try {
|
|
497
|
-
if (!r.includes("="))
|
|
498
|
-
continue;
|
|
499
|
-
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
500
|
-
u(this, R)[n] = o;
|
|
501
|
-
} catch (s) {
|
|
502
|
-
console.error(s);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
serializeCookies() {
|
|
506
|
-
const t = [];
|
|
507
|
-
for (const r in u(this, R))
|
|
508
|
-
t.push(`${r}=${u(this, R)[r]}`);
|
|
509
|
-
return t.join("; ");
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
R = new WeakMap(), T = new WeakMap();
|
|
513
|
-
const DEFAULT_BASE_URL = "http://example.com";
|
|
446
|
+
], LatestSupportedPHPVersion = SupportedPHPVersions[0], DEFAULT_BASE_URL = "http://example.com";
|
|
514
447
|
function toRelativeUrl(e) {
|
|
515
448
|
return e.toString().substring(e.origin.length);
|
|
516
449
|
}
|
|
@@ -522,22 +455,22 @@ function ensurePathPrefix(e, t) {
|
|
|
522
455
|
}
|
|
523
456
|
async function encodeAsMultipart(e) {
|
|
524
457
|
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
525
|
-
for (const [
|
|
458
|
+
for (const [c, l] of Object.entries(e))
|
|
526
459
|
n.push(`--${t}\r
|
|
527
|
-
`), n.push(`Content-Disposition: form-data; name="${
|
|
528
|
-
`),
|
|
460
|
+
`), n.push(`Content-Disposition: form-data; name="${c}"`), l instanceof File && n.push(`; filename="${l.name}"`), n.push(`\r
|
|
461
|
+
`), l instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
529
462
|
`)), n.push(`\r
|
|
530
|
-
`),
|
|
463
|
+
`), l instanceof File ? n.push(await fileToUint8Array(l)) : n.push(l), n.push(`\r
|
|
531
464
|
`);
|
|
532
465
|
n.push(`--${t}--\r
|
|
533
466
|
`);
|
|
534
|
-
const o = n.reduce((
|
|
467
|
+
const o = n.reduce((c, l) => c + l.length, 0), i = new Uint8Array(o);
|
|
535
468
|
let a = 0;
|
|
536
|
-
for (const
|
|
469
|
+
for (const c of n)
|
|
537
470
|
i.set(
|
|
538
|
-
typeof
|
|
471
|
+
typeof c == "string" ? s.encode(c) : c,
|
|
539
472
|
a
|
|
540
|
-
), a +=
|
|
473
|
+
), a += c.length;
|
|
541
474
|
return { bytes: i, contentType: r };
|
|
542
475
|
}
|
|
543
476
|
function fileToUint8Array(e) {
|
|
@@ -548,7 +481,30 @@ function fileToUint8Array(e) {
|
|
|
548
481
|
}, r.readAsArrayBuffer(e);
|
|
549
482
|
});
|
|
550
483
|
}
|
|
551
|
-
|
|
484
|
+
class HttpCookieStore {
|
|
485
|
+
constructor() {
|
|
486
|
+
this.cookies = {};
|
|
487
|
+
}
|
|
488
|
+
rememberCookiesFromResponseHeaders(t) {
|
|
489
|
+
if (t != null && t["set-cookie"])
|
|
490
|
+
for (const r of t["set-cookie"])
|
|
491
|
+
try {
|
|
492
|
+
if (!r.includes("="))
|
|
493
|
+
continue;
|
|
494
|
+
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
495
|
+
this.cookies[n] = o;
|
|
496
|
+
} catch (s) {
|
|
497
|
+
console.error(s);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
getCookieRequestHeader() {
|
|
501
|
+
const t = [];
|
|
502
|
+
for (const r in this.cookies)
|
|
503
|
+
t.push(`${r}=${this.cookies[r]}`);
|
|
504
|
+
return t.join("; ");
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
var g, x, M, v, S, y, T, R, k, I, X, N, ee, L, te;
|
|
552
508
|
class PHPRequestHandler {
|
|
553
509
|
/**
|
|
554
510
|
* @param php - The PHP instance.
|
|
@@ -561,7 +517,7 @@ class PHPRequestHandler {
|
|
|
561
517
|
* @param fsPath - Absolute path of the static file to serve.
|
|
562
518
|
* @returns The response.
|
|
563
519
|
*/
|
|
564
|
-
d(this,
|
|
520
|
+
d(this, I);
|
|
565
521
|
/**
|
|
566
522
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
567
523
|
* superglobals populated.
|
|
@@ -569,7 +525,7 @@ class PHPRequestHandler {
|
|
|
569
525
|
* @param request - The request.
|
|
570
526
|
* @returns The response.
|
|
571
527
|
*/
|
|
572
|
-
d(this,
|
|
528
|
+
d(this, N);
|
|
573
529
|
/**
|
|
574
530
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
575
531
|
*
|
|
@@ -579,55 +535,120 @@ class PHPRequestHandler {
|
|
|
579
535
|
* @throws {Error} If the requested path doesn't exist.
|
|
580
536
|
* @returns The resolved filesystem path.
|
|
581
537
|
*/
|
|
582
|
-
d(this,
|
|
538
|
+
d(this, L);
|
|
583
539
|
d(this, g, void 0);
|
|
584
|
-
d(this,
|
|
585
|
-
d(this,
|
|
586
|
-
d(this,
|
|
587
|
-
d(this, k, void 0);
|
|
588
|
-
d(this, y, void 0);
|
|
589
|
-
d(this, C, void 0);
|
|
540
|
+
d(this, x, void 0);
|
|
541
|
+
d(this, M, void 0);
|
|
542
|
+
d(this, v, void 0);
|
|
590
543
|
d(this, S, void 0);
|
|
591
|
-
|
|
544
|
+
d(this, y, void 0);
|
|
545
|
+
d(this, T, void 0);
|
|
546
|
+
d(this, R, void 0);
|
|
547
|
+
d(this, k, void 0);
|
|
548
|
+
p(this, R, new Semaphore({ concurrency: 1 }));
|
|
592
549
|
const {
|
|
593
550
|
documentRoot: s = "/www/",
|
|
594
551
|
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "",
|
|
595
552
|
rewriteRules: o = []
|
|
596
553
|
} = r;
|
|
597
|
-
this.php = t, p(this, g, s);
|
|
554
|
+
this.php = t, p(this, k, new HttpCookieStore()), p(this, g, s);
|
|
598
555
|
const i = new URL(n);
|
|
599
|
-
p(this,
|
|
600
|
-
const a = u(this,
|
|
601
|
-
p(this,
|
|
602
|
-
u(this,
|
|
603
|
-
a ? `:${u(this,
|
|
604
|
-
].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this,
|
|
605
|
-
`${u(this,
|
|
606
|
-
u(this,
|
|
556
|
+
p(this, M, i.hostname), p(this, v, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), p(this, x, (i.protocol || "").replace(":", ""));
|
|
557
|
+
const a = u(this, v) !== 443 && u(this, v) !== 80;
|
|
558
|
+
p(this, S, [
|
|
559
|
+
u(this, M),
|
|
560
|
+
a ? `:${u(this, v)}` : ""
|
|
561
|
+
].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this, T, [
|
|
562
|
+
`${u(this, x)}://`,
|
|
563
|
+
u(this, S),
|
|
607
564
|
u(this, y)
|
|
608
565
|
].join("")), this.rewriteRules = o;
|
|
609
566
|
}
|
|
610
|
-
/**
|
|
567
|
+
/**
|
|
568
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
569
|
+
* root.
|
|
570
|
+
*
|
|
571
|
+
* @param path The server path to convert to an absolute URL.
|
|
572
|
+
* @returns The absolute URL.
|
|
573
|
+
*/
|
|
611
574
|
pathToInternalUrl(t) {
|
|
612
575
|
return `${this.absoluteUrl}${t}`;
|
|
613
576
|
}
|
|
614
|
-
/**
|
|
577
|
+
/**
|
|
578
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
579
|
+
* without the server pathname and scope.
|
|
580
|
+
*
|
|
581
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
582
|
+
* @returns The relative path.
|
|
583
|
+
*/
|
|
615
584
|
internalUrlToPath(t) {
|
|
616
585
|
const r = new URL(t);
|
|
617
586
|
return r.pathname.startsWith(u(this, y)) && (r.pathname = r.pathname.slice(u(this, y).length)), toRelativeUrl(r);
|
|
618
587
|
}
|
|
619
588
|
get isRequestRunning() {
|
|
620
|
-
return u(this,
|
|
589
|
+
return u(this, R).running > 0;
|
|
621
590
|
}
|
|
622
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
593
|
+
*/
|
|
623
594
|
get absoluteUrl() {
|
|
624
|
-
return u(this,
|
|
595
|
+
return u(this, T);
|
|
625
596
|
}
|
|
626
|
-
/**
|
|
597
|
+
/**
|
|
598
|
+
* The directory in the PHP filesystem where the server will look
|
|
599
|
+
* for the files to serve. Default: `/var/www`.
|
|
600
|
+
*/
|
|
627
601
|
get documentRoot() {
|
|
628
602
|
return u(this, g);
|
|
629
603
|
}
|
|
630
|
-
/**
|
|
604
|
+
/**
|
|
605
|
+
* Serves the request – either by serving a static file, or by
|
|
606
|
+
* dispatching it to the PHP runtime.
|
|
607
|
+
*
|
|
608
|
+
* The request() method mode behaves like a web server and only works if
|
|
609
|
+
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
610
|
+
* of WordPress Playground does by default).
|
|
611
|
+
*
|
|
612
|
+
* In the request mode, you pass an object containing the request information
|
|
613
|
+
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
614
|
+
*
|
|
615
|
+
* ```ts
|
|
616
|
+
* const php = PHP.load('7.4', {
|
|
617
|
+
* requestHandler: {
|
|
618
|
+
* documentRoot: "/www"
|
|
619
|
+
* }
|
|
620
|
+
* })
|
|
621
|
+
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
622
|
+
* const result = await php.request({
|
|
623
|
+
* method: "GET",
|
|
624
|
+
* headers: {
|
|
625
|
+
* "Content-Type": "text/plain"
|
|
626
|
+
* },
|
|
627
|
+
* body: "Hello world!",
|
|
628
|
+
* path: "/www/index.php"
|
|
629
|
+
* });
|
|
630
|
+
* // result.text === "Hello world!"
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```js
|
|
637
|
+
* const output = await php.request({
|
|
638
|
+
* method: 'GET',
|
|
639
|
+
* url: '/index.php',
|
|
640
|
+
* headers: {
|
|
641
|
+
* 'X-foo': 'bar',
|
|
642
|
+
* },
|
|
643
|
+
* body: {
|
|
644
|
+
* foo: 'bar',
|
|
645
|
+
* },
|
|
646
|
+
* });
|
|
647
|
+
* console.log(output.stdout); // "Hello world!"
|
|
648
|
+
* ```
|
|
649
|
+
*
|
|
650
|
+
* @param request - PHP Request data.
|
|
651
|
+
*/
|
|
631
652
|
async request(t) {
|
|
632
653
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
633
654
|
// Remove the hash part of the URL as it's not meant for the server.
|
|
@@ -640,10 +661,10 @@ class PHPRequestHandler {
|
|
|
640
661
|
),
|
|
641
662
|
this.rewriteRules
|
|
642
663
|
), o = joinPaths(u(this, g), n);
|
|
643
|
-
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this,
|
|
664
|
+
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, N, ee).call(this, t, s) : f(this, I, X).call(this, o);
|
|
644
665
|
}
|
|
645
666
|
}
|
|
646
|
-
g = new WeakMap(),
|
|
667
|
+
g = new WeakMap(), x = new WeakMap(), M = new WeakMap(), v = new WeakMap(), S = new WeakMap(), y = new WeakMap(), T = new WeakMap(), R = new WeakMap(), k = new WeakMap(), I = new WeakSet(), X = function(t) {
|
|
647
668
|
if (!this.php.fileExists(t))
|
|
648
669
|
return new PHPResponse(
|
|
649
670
|
404,
|
|
@@ -668,9 +689,9 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
|
|
|
668
689
|
},
|
|
669
690
|
r
|
|
670
691
|
);
|
|
671
|
-
},
|
|
692
|
+
}, N = new WeakSet(), ee = async function(t, r) {
|
|
672
693
|
var n;
|
|
673
|
-
if (u(this,
|
|
694
|
+
if (u(this, R).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
674
695
|
return console.warn(
|
|
675
696
|
"Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
|
|
676
697
|
), new PHPResponse(
|
|
@@ -678,26 +699,23 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
|
|
|
678
699
|
{},
|
|
679
700
|
new TextEncoder().encode("502 Bad Gateway")
|
|
680
701
|
);
|
|
681
|
-
const s = await u(this,
|
|
702
|
+
const s = await u(this, R).acquire();
|
|
682
703
|
try {
|
|
683
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", u(this, g)), this.php.addServerGlobalEntry(
|
|
684
|
-
"HTTPS",
|
|
685
|
-
u(this, C).startsWith("https://") ? "on" : ""
|
|
686
|
-
);
|
|
687
704
|
let o = "GET";
|
|
688
705
|
const i = {
|
|
689
|
-
host: u(this,
|
|
690
|
-
...normalizeHeaders(t.headers || {})
|
|
706
|
+
host: u(this, S),
|
|
707
|
+
...normalizeHeaders(t.headers || {}),
|
|
708
|
+
cookie: u(this, k).getCookieRequestHeader()
|
|
691
709
|
};
|
|
692
710
|
let a = t.body;
|
|
693
711
|
if (typeof a == "object" && !(a instanceof Uint8Array)) {
|
|
694
712
|
o = "POST";
|
|
695
|
-
const { bytes:
|
|
696
|
-
a =
|
|
713
|
+
const { bytes: l, contentType: h } = await encodeAsMultipart(a);
|
|
714
|
+
a = l, i["content-type"] = h;
|
|
697
715
|
}
|
|
698
|
-
let
|
|
716
|
+
let c;
|
|
699
717
|
try {
|
|
700
|
-
|
|
718
|
+
c = f(this, L, te).call(this, decodeURIComponent(r.pathname));
|
|
701
719
|
} catch {
|
|
702
720
|
return new PHPResponse(
|
|
703
721
|
404,
|
|
@@ -706,27 +724,35 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
|
|
|
706
724
|
);
|
|
707
725
|
}
|
|
708
726
|
try {
|
|
709
|
-
|
|
727
|
+
const l = await this.php.run({
|
|
710
728
|
relativeUri: ensurePathPrefix(
|
|
711
729
|
toRelativeUrl(r),
|
|
712
730
|
u(this, y)
|
|
713
731
|
),
|
|
714
|
-
protocol: u(this,
|
|
732
|
+
protocol: u(this, x),
|
|
715
733
|
method: t.method || o,
|
|
734
|
+
$_SERVER: {
|
|
735
|
+
REMOTE_ADDR: "127.0.0.1",
|
|
736
|
+
DOCUMENT_ROOT: u(this, g),
|
|
737
|
+
HTTPS: u(this, T).startsWith("https://") ? "on" : ""
|
|
738
|
+
},
|
|
716
739
|
body: a,
|
|
717
|
-
scriptPath:
|
|
740
|
+
scriptPath: c,
|
|
718
741
|
headers: i
|
|
719
742
|
});
|
|
720
|
-
|
|
721
|
-
|
|
743
|
+
return u(this, k).rememberCookiesFromResponseHeaders(
|
|
744
|
+
l.headers
|
|
745
|
+
), l;
|
|
746
|
+
} catch (l) {
|
|
747
|
+
const h = l;
|
|
722
748
|
if (h != null && h.response)
|
|
723
749
|
return h.response;
|
|
724
|
-
throw
|
|
750
|
+
throw l;
|
|
725
751
|
}
|
|
726
752
|
} finally {
|
|
727
753
|
s();
|
|
728
754
|
}
|
|
729
|
-
},
|
|
755
|
+
}, L = new WeakSet(), te = function(t) {
|
|
730
756
|
let r = removePathPrefix(t, u(this, y));
|
|
731
757
|
r = applyRewriteRules(r, this.rewriteRules), r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${u(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
|
|
732
758
|
const s = `${u(this, g)}${r}`;
|
|
@@ -770,6 +796,38 @@ function inferMimeType(e) {
|
|
|
770
796
|
case "txt":
|
|
771
797
|
case "md":
|
|
772
798
|
return "text/plain";
|
|
799
|
+
case "pdf":
|
|
800
|
+
return "application/pdf";
|
|
801
|
+
case "webp":
|
|
802
|
+
return "image/webp";
|
|
803
|
+
case "mp3":
|
|
804
|
+
return "audio/mpeg";
|
|
805
|
+
case "mp4":
|
|
806
|
+
return "video/mp4";
|
|
807
|
+
case "csv":
|
|
808
|
+
return "text/csv";
|
|
809
|
+
case "xls":
|
|
810
|
+
return "application/vnd.ms-excel";
|
|
811
|
+
case "xlsx":
|
|
812
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
813
|
+
case "doc":
|
|
814
|
+
return "application/msword";
|
|
815
|
+
case "docx":
|
|
816
|
+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
817
|
+
case "ppt":
|
|
818
|
+
return "application/vnd.ms-powerpoint";
|
|
819
|
+
case "pptx":
|
|
820
|
+
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
821
|
+
case "zip":
|
|
822
|
+
return "application/zip";
|
|
823
|
+
case "rar":
|
|
824
|
+
return "application/x-rar-compressed";
|
|
825
|
+
case "tar":
|
|
826
|
+
return "application/x-tar";
|
|
827
|
+
case "gz":
|
|
828
|
+
return "application/gzip";
|
|
829
|
+
case "7z":
|
|
830
|
+
return "application/x-7z-compressed";
|
|
773
831
|
default:
|
|
774
832
|
return "application-octet-stream";
|
|
775
833
|
}
|
|
@@ -880,10 +938,10 @@ function rethrowFileSystemError(e = "") {
|
|
|
880
938
|
try {
|
|
881
939
|
return o.apply(this, i);
|
|
882
940
|
} catch (a) {
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
885
|
-
const
|
|
886
|
-
throw new Error(`${_}: ${
|
|
941
|
+
const c = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
942
|
+
if (c in FileErrorCodes) {
|
|
943
|
+
const l = FileErrorCodes[c], h = typeof i[0] == "string" ? i[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
|
|
944
|
+
throw new Error(`${_}: ${l}`, {
|
|
887
945
|
cause: a
|
|
888
946
|
});
|
|
889
947
|
}
|
|
@@ -939,7 +997,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
939
997
|
super(t), this.response = r, this.source = s;
|
|
940
998
|
}
|
|
941
999
|
}
|
|
942
|
-
var
|
|
1000
|
+
var b, C, H, w, E, P, F, O, re, U, se, W, ne, B, ie, D, oe, $, ae, q, le, z, ce, j, ue, V, de, G, he, J, pe, Q, fe, Y, me, K, _e;
|
|
943
1001
|
class BasePHP {
|
|
944
1002
|
/**
|
|
945
1003
|
* Initializes a PHP runtime.
|
|
@@ -949,29 +1007,38 @@ class BasePHP {
|
|
|
949
1007
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
950
1008
|
*/
|
|
951
1009
|
constructor(e, t) {
|
|
1010
|
+
/**
|
|
1011
|
+
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1012
|
+
*
|
|
1013
|
+
* @param defaults Default entries to include in $_SERVER.
|
|
1014
|
+
* @param headers HTTP headers to include in $_SERVER (as HTTP_ prefixed entries).
|
|
1015
|
+
* @param port HTTP port, used to determine infer $_SERVER['HTTPS'] value if none
|
|
1016
|
+
* was provided.
|
|
1017
|
+
* @returns Computed $_SERVER entries.
|
|
1018
|
+
*/
|
|
1019
|
+
d(this, O);
|
|
1020
|
+
d(this, U);
|
|
952
1021
|
d(this, W);
|
|
953
|
-
d(this, q);
|
|
954
1022
|
d(this, B);
|
|
955
1023
|
d(this, D);
|
|
956
1024
|
d(this, $);
|
|
1025
|
+
d(this, q);
|
|
957
1026
|
d(this, z);
|
|
958
1027
|
d(this, j);
|
|
959
|
-
d(this, G);
|
|
960
1028
|
d(this, V);
|
|
1029
|
+
d(this, G);
|
|
961
1030
|
d(this, J);
|
|
962
1031
|
d(this, Q);
|
|
963
1032
|
d(this, Y);
|
|
964
|
-
d(this,
|
|
965
|
-
d(this,
|
|
966
|
-
d(this,
|
|
1033
|
+
d(this, K);
|
|
1034
|
+
d(this, b, void 0);
|
|
1035
|
+
d(this, C, void 0);
|
|
1036
|
+
d(this, H, void 0);
|
|
967
1037
|
d(this, w, void 0);
|
|
968
1038
|
d(this, E, void 0);
|
|
969
|
-
d(this, v, void 0);
|
|
970
1039
|
d(this, P, void 0);
|
|
971
|
-
d(this,
|
|
972
|
-
p(this,
|
|
973
|
-
new PHPRequestHandler(this, t)
|
|
974
|
-
));
|
|
1040
|
+
d(this, F, void 0);
|
|
1041
|
+
p(this, b, []), p(this, w, !1), p(this, E, null), p(this, P, /* @__PURE__ */ new Map()), p(this, F, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPRequestHandler(this, t));
|
|
975
1042
|
}
|
|
976
1043
|
addEventListener(e, t) {
|
|
977
1044
|
u(this, P).has(e) || u(this, P).set(e, /* @__PURE__ */ new Set()), u(this, P).get(e).add(t);
|
|
@@ -988,7 +1055,7 @@ class BasePHP {
|
|
|
988
1055
|
}
|
|
989
1056
|
/** @inheritDoc */
|
|
990
1057
|
async onMessage(e) {
|
|
991
|
-
u(this,
|
|
1058
|
+
u(this, F).push(e);
|
|
992
1059
|
}
|
|
993
1060
|
/** @inheritDoc */
|
|
994
1061
|
async setSpawnHandler(handler) {
|
|
@@ -996,21 +1063,19 @@ class BasePHP {
|
|
|
996
1063
|
}
|
|
997
1064
|
/** @inheritDoc */
|
|
998
1065
|
get absoluteUrl() {
|
|
999
|
-
return this.requestHandler.
|
|
1066
|
+
return this.requestHandler.absoluteUrl;
|
|
1000
1067
|
}
|
|
1001
1068
|
/** @inheritDoc */
|
|
1002
1069
|
get documentRoot() {
|
|
1003
|
-
return this.requestHandler.
|
|
1070
|
+
return this.requestHandler.documentRoot;
|
|
1004
1071
|
}
|
|
1005
1072
|
/** @inheritDoc */
|
|
1006
1073
|
pathToInternalUrl(e) {
|
|
1007
|
-
return this.requestHandler.
|
|
1074
|
+
return this.requestHandler.pathToInternalUrl(e);
|
|
1008
1075
|
}
|
|
1009
1076
|
/** @inheritDoc */
|
|
1010
1077
|
internalUrlToPath(e) {
|
|
1011
|
-
return this.requestHandler.
|
|
1012
|
-
e
|
|
1013
|
-
);
|
|
1078
|
+
return this.requestHandler.internalUrlToPath(e);
|
|
1014
1079
|
}
|
|
1015
1080
|
initializeRuntime(e) {
|
|
1016
1081
|
if (this[__private__dont__use])
|
|
@@ -1019,7 +1084,7 @@ class BasePHP {
|
|
|
1019
1084
|
if (!t)
|
|
1020
1085
|
throw new Error("Invalid PHP runtime id.");
|
|
1021
1086
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
1022
|
-
for (const s of u(this,
|
|
1087
|
+
for (const s of u(this, F)) {
|
|
1023
1088
|
const n = await s(r);
|
|
1024
1089
|
if (n)
|
|
1025
1090
|
return n;
|
|
@@ -1040,13 +1105,13 @@ class BasePHP {
|
|
|
1040
1105
|
throw new Error(
|
|
1041
1106
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1042
1107
|
);
|
|
1043
|
-
p(this,
|
|
1108
|
+
p(this, H, e);
|
|
1044
1109
|
}
|
|
1045
1110
|
/** @inheritDoc */
|
|
1046
1111
|
setPhpIniPath(e) {
|
|
1047
1112
|
if (u(this, w))
|
|
1048
1113
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1049
|
-
p(this,
|
|
1114
|
+
p(this, C, e), this[__private__dont__use].ccall(
|
|
1050
1115
|
"wasm_set_phpini_path",
|
|
1051
1116
|
null,
|
|
1052
1117
|
["string"],
|
|
@@ -1057,44 +1122,47 @@ class BasePHP {
|
|
|
1057
1122
|
setPhpIniEntry(e, t) {
|
|
1058
1123
|
if (u(this, w))
|
|
1059
1124
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1060
|
-
u(this,
|
|
1125
|
+
u(this, b).push([e, t]);
|
|
1061
1126
|
}
|
|
1062
1127
|
/** @inheritDoc */
|
|
1063
1128
|
chdir(e) {
|
|
1064
1129
|
this[__private__dont__use].FS.chdir(e);
|
|
1065
1130
|
}
|
|
1066
1131
|
/** @inheritDoc */
|
|
1067
|
-
async request(e
|
|
1132
|
+
async request(e) {
|
|
1068
1133
|
if (!this.requestHandler)
|
|
1069
1134
|
throw new Error("No request handler available.");
|
|
1070
|
-
return this.requestHandler.request(e
|
|
1135
|
+
return this.requestHandler.request(e);
|
|
1071
1136
|
}
|
|
1072
1137
|
/** @inheritDoc */
|
|
1073
1138
|
async run(e) {
|
|
1074
1139
|
const t = await this.semaphore.acquire();
|
|
1075
1140
|
let r;
|
|
1076
1141
|
try {
|
|
1077
|
-
if (u(this, w) || (f(this,
|
|
1142
|
+
if (u(this, w) || (f(this, U, se).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1078
1143
|
throw new Error(
|
|
1079
1144
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1080
1145
|
);
|
|
1081
|
-
f(this, G,
|
|
1082
|
-
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1083
|
-
f(this, D,
|
|
1084
|
-
const
|
|
1085
|
-
for (const
|
|
1086
|
-
f(this, J,
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1146
|
+
f(this, G, he).call(this, e.scriptPath || ""), f(this, B, ie).call(this, e.relativeUri || ""), f(this, z, ce).call(this, e.method || "GET");
|
|
1147
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443", o = f(this, q, le).call(this, n, e.protocol || "http");
|
|
1148
|
+
f(this, D, oe).call(this, n), f(this, $, ae).call(this, o), f(this, j, ue).call(this, s), e.body && (r = f(this, V, de).call(this, e.body)), typeof e.code == "string" && f(this, Y, me).call(this, " ?>" + e.code);
|
|
1149
|
+
const i = f(this, O, re).call(this, e.$_SERVER, s, o);
|
|
1150
|
+
for (const l in i)
|
|
1151
|
+
f(this, J, pe).call(this, l, i[l]);
|
|
1152
|
+
const a = e.env || {};
|
|
1153
|
+
for (const l in a)
|
|
1154
|
+
f(this, Q, fe).call(this, l, a[l]);
|
|
1155
|
+
const c = await f(this, K, _e).call(this);
|
|
1156
|
+
if (c.exitCode !== 0) {
|
|
1157
|
+
console.warn("PHP.run() output was:", c.text);
|
|
1158
|
+
const l = new PHPExecutionFailureError(
|
|
1159
|
+
`PHP.run() failed with exit code ${c.exitCode} and the following output: ` + c.errors,
|
|
1160
|
+
c,
|
|
1093
1161
|
"request"
|
|
1094
1162
|
);
|
|
1095
|
-
throw console.error(
|
|
1163
|
+
throw console.error(l), l;
|
|
1096
1164
|
}
|
|
1097
|
-
return
|
|
1165
|
+
return c;
|
|
1098
1166
|
} catch (s) {
|
|
1099
1167
|
throw this.dispatchEvent({
|
|
1100
1168
|
type: "request.error",
|
|
@@ -1112,9 +1180,6 @@ class BasePHP {
|
|
|
1112
1180
|
}
|
|
1113
1181
|
}
|
|
1114
1182
|
}
|
|
1115
|
-
addServerGlobalEntry(e, t) {
|
|
1116
|
-
u(this, v)[e] = t;
|
|
1117
|
-
}
|
|
1118
1183
|
defineConstant(e, t) {
|
|
1119
1184
|
let r = {};
|
|
1120
1185
|
try {
|
|
@@ -1202,17 +1267,18 @@ class BasePHP {
|
|
|
1202
1267
|
* interrupting the operations of this PHP instance.
|
|
1203
1268
|
*
|
|
1204
1269
|
* @param runtime
|
|
1270
|
+
* @param cwd. Internal, the VFS path to recreate in the new runtime.
|
|
1271
|
+
* This arg is temporary and will be removed once BasePHP
|
|
1272
|
+
* is fully decoupled from the request handler and
|
|
1273
|
+
* accepts a constructor-level cwd argument.
|
|
1205
1274
|
*/
|
|
1206
|
-
hotSwapPHPRuntime(e) {
|
|
1207
|
-
const
|
|
1275
|
+
hotSwapPHPRuntime(e, t) {
|
|
1276
|
+
const r = this[__private__dont__use].FS;
|
|
1208
1277
|
try {
|
|
1209
1278
|
this.exit();
|
|
1210
1279
|
} catch {
|
|
1211
1280
|
}
|
|
1212
|
-
|
|
1213
|
-
const r = this.documentRoot;
|
|
1214
|
-
copyFS(t, this[__private__dont__use].FS, r);
|
|
1215
|
-
}
|
|
1281
|
+
this.initializeRuntime(e), u(this, C) && this.setPhpIniPath(u(this, C)), u(this, H) && this.setSapiName(u(this, H)), t && copyFS(r, this[__private__dont__use].FS, t);
|
|
1216
1282
|
}
|
|
1217
1283
|
exit(e = 0) {
|
|
1218
1284
|
this.dispatchEvent({
|
|
@@ -1225,7 +1291,17 @@ class BasePHP {
|
|
|
1225
1291
|
p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1226
1292
|
}
|
|
1227
1293
|
}
|
|
1228
|
-
|
|
1294
|
+
b = new WeakMap(), C = new WeakMap(), H = new WeakMap(), w = new WeakMap(), E = new WeakMap(), P = new WeakMap(), F = new WeakMap(), O = new WeakSet(), re = function(e, t, r) {
|
|
1295
|
+
const s = {
|
|
1296
|
+
...e || {}
|
|
1297
|
+
};
|
|
1298
|
+
s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
|
|
1299
|
+
for (const n in t) {
|
|
1300
|
+
let o = "HTTP_";
|
|
1301
|
+
["content-type", "content-length"].includes(n.toLowerCase()) && (o = ""), s[`${o}${n.toUpperCase().replace(/-/g, "_")}`] = t[n];
|
|
1302
|
+
}
|
|
1303
|
+
return s;
|
|
1304
|
+
}, U = new WeakSet(), se = function() {
|
|
1229
1305
|
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1230
1306
|
"/internal/consts.php",
|
|
1231
1307
|
`<?php
|
|
@@ -1237,8 +1313,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1237
1313
|
}
|
|
1238
1314
|
}
|
|
1239
1315
|
}`
|
|
1240
|
-
), u(this,
|
|
1241
|
-
const e = u(this,
|
|
1316
|
+
), u(this, b).length > 0) {
|
|
1317
|
+
const e = u(this, b).map(([t, r]) => `${t}=${r}`).join(`
|
|
1242
1318
|
`) + `
|
|
1243
1319
|
|
|
1244
1320
|
`;
|
|
@@ -1250,7 +1326,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1250
1326
|
);
|
|
1251
1327
|
}
|
|
1252
1328
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1253
|
-
},
|
|
1329
|
+
}, W = new WeakSet(), ne = function() {
|
|
1254
1330
|
const e = "/internal/headers.json";
|
|
1255
1331
|
if (!this.fileExists(e))
|
|
1256
1332
|
throw new Error(
|
|
@@ -1267,7 +1343,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1267
1343
|
headers: r,
|
|
1268
1344
|
httpStatusCode: t.status
|
|
1269
1345
|
};
|
|
1270
|
-
}, B = new WeakSet(),
|
|
1346
|
+
}, B = new WeakSet(), ie = function(e) {
|
|
1271
1347
|
if (this[__private__dont__use].ccall(
|
|
1272
1348
|
"wasm_set_request_uri",
|
|
1273
1349
|
null,
|
|
@@ -1282,32 +1358,35 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1282
1358
|
[t]
|
|
1283
1359
|
);
|
|
1284
1360
|
}
|
|
1285
|
-
}, D = new WeakSet(),
|
|
1361
|
+
}, D = new WeakSet(), oe = function(e) {
|
|
1286
1362
|
this[__private__dont__use].ccall(
|
|
1287
1363
|
"wasm_set_request_host",
|
|
1288
1364
|
null,
|
|
1289
1365
|
[STRING],
|
|
1290
1366
|
[e]
|
|
1291
1367
|
);
|
|
1368
|
+
}, $ = new WeakSet(), ae = function(e) {
|
|
1369
|
+
this[__private__dont__use].ccall(
|
|
1370
|
+
"wasm_set_request_port",
|
|
1371
|
+
null,
|
|
1372
|
+
[NUMBER],
|
|
1373
|
+
[e]
|
|
1374
|
+
);
|
|
1375
|
+
}, q = new WeakSet(), le = function(e, t) {
|
|
1292
1376
|
let r;
|
|
1293
1377
|
try {
|
|
1294
1378
|
r = parseInt(new URL(e).port, 10);
|
|
1295
1379
|
} catch {
|
|
1296
1380
|
}
|
|
1297
|
-
(!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80),
|
|
1298
|
-
|
|
1299
|
-
null,
|
|
1300
|
-
[NUMBER],
|
|
1301
|
-
[r]
|
|
1302
|
-
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1303
|
-
}, $ = new WeakSet(), ie = function(e) {
|
|
1381
|
+
return (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), r;
|
|
1382
|
+
}, z = new WeakSet(), ce = function(e) {
|
|
1304
1383
|
this[__private__dont__use].ccall(
|
|
1305
1384
|
"wasm_set_request_method",
|
|
1306
1385
|
null,
|
|
1307
1386
|
[STRING],
|
|
1308
1387
|
[e]
|
|
1309
1388
|
);
|
|
1310
|
-
},
|
|
1389
|
+
}, j = new WeakSet(), ue = function(e) {
|
|
1311
1390
|
e.cookie && this[__private__dont__use].ccall(
|
|
1312
1391
|
"wasm_set_cookies",
|
|
1313
1392
|
null,
|
|
@@ -1324,14 +1403,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1324
1403
|
[NUMBER],
|
|
1325
1404
|
[parseInt(e["content-length"], 10)]
|
|
1326
1405
|
);
|
|
1327
|
-
|
|
1328
|
-
let r = "HTTP_";
|
|
1329
|
-
["content-type", "content-length"].includes(t.toLowerCase()) && (r = ""), this.addServerGlobalEntry(
|
|
1330
|
-
`${r}${t.toUpperCase().replace(/-/g, "_")}`,
|
|
1331
|
-
e[t]
|
|
1332
|
-
);
|
|
1333
|
-
}
|
|
1334
|
-
}, j = new WeakSet(), ae = function(e) {
|
|
1406
|
+
}, V = new WeakSet(), de = function(e) {
|
|
1335
1407
|
let t, r;
|
|
1336
1408
|
typeof e == "string" ? (console.warn(
|
|
1337
1409
|
"Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
|
|
@@ -1354,46 +1426,45 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1354
1426
|
[NUMBER],
|
|
1355
1427
|
[r]
|
|
1356
1428
|
), s;
|
|
1357
|
-
}, G = new WeakSet(),
|
|
1429
|
+
}, G = new WeakSet(), he = function(e) {
|
|
1358
1430
|
this[__private__dont__use].ccall(
|
|
1359
1431
|
"wasm_set_path_translated",
|
|
1360
1432
|
null,
|
|
1361
1433
|
[STRING],
|
|
1362
1434
|
[e]
|
|
1363
1435
|
);
|
|
1364
|
-
},
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
}, J = new WeakSet(), ue = function(e, t) {
|
|
1436
|
+
}, J = new WeakSet(), pe = function(e, t) {
|
|
1437
|
+
this[__private__dont__use].ccall(
|
|
1438
|
+
"wasm_add_SERVER_entry",
|
|
1439
|
+
null,
|
|
1440
|
+
[STRING, STRING],
|
|
1441
|
+
[e, t]
|
|
1442
|
+
);
|
|
1443
|
+
}, Q = new WeakSet(), fe = function(e, t) {
|
|
1373
1444
|
this[__private__dont__use].ccall(
|
|
1374
1445
|
"wasm_add_ENV_entry",
|
|
1375
1446
|
null,
|
|
1376
1447
|
[STRING, STRING],
|
|
1377
1448
|
[e, t]
|
|
1378
1449
|
);
|
|
1379
|
-
},
|
|
1450
|
+
}, Y = new WeakSet(), me = function(e) {
|
|
1380
1451
|
this[__private__dont__use].ccall(
|
|
1381
1452
|
"wasm_set_php_code",
|
|
1382
1453
|
null,
|
|
1383
1454
|
[STRING],
|
|
1384
1455
|
[e]
|
|
1385
1456
|
);
|
|
1386
|
-
},
|
|
1457
|
+
}, K = new WeakSet(), _e = async function() {
|
|
1387
1458
|
var n;
|
|
1388
1459
|
let e, t;
|
|
1389
1460
|
try {
|
|
1390
1461
|
e = await new Promise((o, i) => {
|
|
1391
|
-
var
|
|
1392
|
-
t = (
|
|
1393
|
-
console.error(
|
|
1462
|
+
var c;
|
|
1463
|
+
t = (l) => {
|
|
1464
|
+
console.error(l), console.error(l.error);
|
|
1394
1465
|
const h = new Error("Rethrown");
|
|
1395
|
-
h.cause =
|
|
1396
|
-
}, (
|
|
1466
|
+
h.cause = l.error, h.betterMessage = l.message, i(h);
|
|
1467
|
+
}, (c = u(this, E)) == null || c.addEventListener(
|
|
1397
1468
|
"error",
|
|
1398
1469
|
t
|
|
1399
1470
|
);
|
|
@@ -1407,19 +1478,19 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1407
1478
|
return a instanceof Promise ? a.then(o, i) : o(a);
|
|
1408
1479
|
});
|
|
1409
1480
|
} catch (o) {
|
|
1410
|
-
for (const
|
|
1411
|
-
typeof this[
|
|
1481
|
+
for (const l in this)
|
|
1482
|
+
typeof this[l] == "function" && (this[l] = () => {
|
|
1412
1483
|
throw new Error(
|
|
1413
1484
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1414
1485
|
);
|
|
1415
1486
|
});
|
|
1416
1487
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1417
|
-
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message,
|
|
1418
|
-
throw
|
|
1488
|
+
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(a);
|
|
1489
|
+
throw c.cause = i, console.error(c), c;
|
|
1419
1490
|
} finally {
|
|
1420
|
-
(n = u(this, E)) == null || n.removeEventListener("error", t)
|
|
1491
|
+
(n = u(this, E)) == null || n.removeEventListener("error", t);
|
|
1421
1492
|
}
|
|
1422
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1493
|
+
const { headers: r, httpStatusCode: s } = f(this, W, ne).call(this);
|
|
1423
1494
|
return new PHPResponse(
|
|
1424
1495
|
e === 0 ? s : 500,
|
|
1425
1496
|
r,
|
|
@@ -1530,42 +1601,42 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1530
1601
|
console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
|
|
1531
1602
|
return;
|
|
1532
1603
|
}
|
|
1533
|
-
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data),
|
|
1534
|
-
let
|
|
1604
|
+
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(fromWireValue);
|
|
1605
|
+
let l;
|
|
1535
1606
|
try {
|
|
1536
|
-
const h = a.slice(0, -1).reduce((m,
|
|
1607
|
+
const h = a.slice(0, -1).reduce((m, A) => m[A], e), _ = a.reduce((m, A) => m[A], e);
|
|
1537
1608
|
switch (i) {
|
|
1538
1609
|
case "GET":
|
|
1539
|
-
|
|
1610
|
+
l = _;
|
|
1540
1611
|
break;
|
|
1541
1612
|
case "SET":
|
|
1542
|
-
h[a.slice(-1)[0]] = fromWireValue(n.data.value),
|
|
1613
|
+
h[a.slice(-1)[0]] = fromWireValue(n.data.value), l = !0;
|
|
1543
1614
|
break;
|
|
1544
1615
|
case "APPLY":
|
|
1545
|
-
|
|
1616
|
+
l = _.apply(h, c);
|
|
1546
1617
|
break;
|
|
1547
1618
|
case "CONSTRUCT":
|
|
1548
1619
|
{
|
|
1549
|
-
const m = new _(...
|
|
1550
|
-
|
|
1620
|
+
const m = new _(...c);
|
|
1621
|
+
l = proxy(m);
|
|
1551
1622
|
}
|
|
1552
1623
|
break;
|
|
1553
1624
|
case "ENDPOINT":
|
|
1554
1625
|
{
|
|
1555
|
-
const { port1: m, port2:
|
|
1556
|
-
expose(e,
|
|
1626
|
+
const { port1: m, port2: A } = new MessageChannel();
|
|
1627
|
+
expose(e, A), l = transfer(m, [m]);
|
|
1557
1628
|
}
|
|
1558
1629
|
break;
|
|
1559
1630
|
case "RELEASE":
|
|
1560
|
-
|
|
1631
|
+
l = void 0;
|
|
1561
1632
|
break;
|
|
1562
1633
|
default:
|
|
1563
1634
|
return;
|
|
1564
1635
|
}
|
|
1565
1636
|
} catch (h) {
|
|
1566
|
-
|
|
1637
|
+
l = { value: h, [throwMarker]: 0 };
|
|
1567
1638
|
}
|
|
1568
|
-
Promise.resolve(
|
|
1639
|
+
Promise.resolve(l).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1569
1640
|
const [_, m] = toWireValue(h);
|
|
1570
1641
|
t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1571
1642
|
}).catch((h) => {
|
|
@@ -1622,7 +1693,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1622
1693
|
return { then: () => n };
|
|
1623
1694
|
const a = requestResponseMessage(e, {
|
|
1624
1695
|
type: "GET",
|
|
1625
|
-
path: t.map((
|
|
1696
|
+
path: t.map((c) => c.toString())
|
|
1626
1697
|
}).then(fromWireValue);
|
|
1627
1698
|
return a.then.bind(a);
|
|
1628
1699
|
}
|
|
@@ -1630,37 +1701,37 @@ function createProxy(e, t = [], r = function() {
|
|
|
1630
1701
|
},
|
|
1631
1702
|
set(o, i, a) {
|
|
1632
1703
|
throwIfProxyReleased(s);
|
|
1633
|
-
const [
|
|
1704
|
+
const [c, l] = toWireValue(a);
|
|
1634
1705
|
return requestResponseMessage(e, {
|
|
1635
1706
|
type: "SET",
|
|
1636
1707
|
path: [...t, i].map((h) => h.toString()),
|
|
1637
|
-
value:
|
|
1638
|
-
},
|
|
1708
|
+
value: c
|
|
1709
|
+
}, l).then(fromWireValue);
|
|
1639
1710
|
},
|
|
1640
1711
|
apply(o, i, a) {
|
|
1641
1712
|
throwIfProxyReleased(s);
|
|
1642
|
-
const
|
|
1643
|
-
if (
|
|
1713
|
+
const c = t[t.length - 1];
|
|
1714
|
+
if (c === createEndpoint)
|
|
1644
1715
|
return requestResponseMessage(e, {
|
|
1645
1716
|
type: "ENDPOINT"
|
|
1646
1717
|
}).then(fromWireValue);
|
|
1647
|
-
if (
|
|
1718
|
+
if (c === "bind")
|
|
1648
1719
|
return createProxy(e, t.slice(0, -1));
|
|
1649
|
-
const [
|
|
1720
|
+
const [l, h] = processArguments(a);
|
|
1650
1721
|
return requestResponseMessage(e, {
|
|
1651
1722
|
type: "APPLY",
|
|
1652
1723
|
path: t.map((_) => _.toString()),
|
|
1653
|
-
argumentList:
|
|
1724
|
+
argumentList: l
|
|
1654
1725
|
}, h).then(fromWireValue);
|
|
1655
1726
|
},
|
|
1656
1727
|
construct(o, i) {
|
|
1657
1728
|
throwIfProxyReleased(s);
|
|
1658
|
-
const [a,
|
|
1729
|
+
const [a, c] = processArguments(i);
|
|
1659
1730
|
return requestResponseMessage(e, {
|
|
1660
1731
|
type: "CONSTRUCT",
|
|
1661
|
-
path: t.map((
|
|
1732
|
+
path: t.map((l) => l.toString()),
|
|
1662
1733
|
argumentList: a
|
|
1663
|
-
},
|
|
1734
|
+
}, c).then(fromWireValue);
|
|
1664
1735
|
}
|
|
1665
1736
|
});
|
|
1666
1737
|
return registerProxy(n, e), n;
|
|
@@ -1749,10 +1820,10 @@ function exposeAPI(e, t) {
|
|
|
1749
1820
|
setupTransferHandlers();
|
|
1750
1821
|
const r = Promise.resolve();
|
|
1751
1822
|
let s, n;
|
|
1752
|
-
const o = new Promise((
|
|
1753
|
-
s =
|
|
1823
|
+
const o = new Promise((c, l) => {
|
|
1824
|
+
s = c, n = l;
|
|
1754
1825
|
}), i = proxyClone(e), a = new Proxy(i, {
|
|
1755
|
-
get: (
|
|
1826
|
+
get: (c, l) => l === "isConnected" ? () => r : l === "isReady" ? () => o : l in c ? c[l] : t == null ? void 0 : t[l]
|
|
1756
1827
|
});
|
|
1757
1828
|
return expose(
|
|
1758
1829
|
a,
|
|
@@ -1897,9 +1968,7 @@ class WebPHP extends BasePHP {
|
|
|
1897
1968
|
static async loadRuntime(t, r = {}) {
|
|
1898
1969
|
var o;
|
|
1899
1970
|
const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
|
|
1900
|
-
return (o = r.
|
|
1901
|
-
[n.dependencyFilename]: n.dependenciesTotalSize
|
|
1902
|
-
}), await loadPHPRuntime(n, {
|
|
1971
|
+
return (o = r.onPhpLoaderModuleLoaded) == null || o.call(r, n), await loadPHPRuntime(n, {
|
|
1903
1972
|
...r.emscriptenOptions || {},
|
|
1904
1973
|
...fakeWebsocket()
|
|
1905
1974
|
});
|
|
@@ -1938,17 +2007,13 @@ class WebPHPEndpoint {
|
|
|
1938
2007
|
return _private.get(this).php.rmdir(t, r);
|
|
1939
2008
|
}
|
|
1940
2009
|
/** @inheritDoc @php-wasm/universal!RequestHandler.request */
|
|
1941
|
-
request(t
|
|
1942
|
-
return _private.get(this).php.request(t
|
|
2010
|
+
request(t) {
|
|
2011
|
+
return _private.get(this).php.request(t);
|
|
1943
2012
|
}
|
|
1944
2013
|
/** @inheritDoc @php-wasm/web!WebPHP.run */
|
|
1945
2014
|
async run(t) {
|
|
1946
2015
|
return _private.get(this).php.run(t);
|
|
1947
2016
|
}
|
|
1948
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setSpawnHandler */
|
|
1949
|
-
setSpawnHandler(t) {
|
|
1950
|
-
_private.get(this).php.setSpawnHandler(t);
|
|
1951
|
-
}
|
|
1952
2017
|
/** @inheritDoc @php-wasm/web!WebPHP.chdir */
|
|
1953
2018
|
chdir(t) {
|
|
1954
2019
|
return _private.get(this).php.chdir(t);
|
|
@@ -2042,8 +2107,8 @@ async function registerServiceWorker(e, t, r) {
|
|
|
2042
2107
|
async function(i) {
|
|
2043
2108
|
if (t && i.data.scope !== t)
|
|
2044
2109
|
return;
|
|
2045
|
-
const a = i.data.args || [],
|
|
2046
|
-
i.source.postMessage(responseTo(i.data.requestId,
|
|
2110
|
+
const a = i.data.args || [], c = i.data.method, l = await e[c](...a);
|
|
2111
|
+
i.source.postMessage(responseTo(i.data.requestId, l));
|
|
2047
2112
|
}
|
|
2048
2113
|
), s.startMessages();
|
|
2049
2114
|
}
|