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