@php-wasm/universal 3.1.19 → 3.1.21
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.cjs +9 -8
- package/index.cjs.map +1 -1
- package/index.js +170 -117
- package/index.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/legacy-php-ini.d.ts +32 -0
- package/lib/proxy-file-system.d.ts +14 -2
- package/lib/supported-php-versions.d.ts +10 -0
- package/package.json +8 -8
package/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Y = (r) => {
|
|
2
2
|
throw TypeError(r);
|
|
3
3
|
};
|
|
4
|
-
var W = (r, e, t) => e.has(r) ||
|
|
5
|
-
var u = (r, e, t) => (W(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ?
|
|
6
|
-
import "@php-wasm/node-polyfills";
|
|
4
|
+
var W = (r, e, t) => e.has(r) || Y("Cannot " + t);
|
|
5
|
+
var u = (r, e, t) => (W(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ? Y("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), g = (r, e, t, s) => (W(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), m = (r, e, t) => (W(r, e, "access private method"), t);
|
|
7
6
|
import { logger } from "@php-wasm/logger";
|
|
8
7
|
import { dirname, joinPaths, Semaphore, createSpawnHandler, basename, normalizePath, AcquireTimeoutError, splitShellCommand } from "@php-wasm/util";
|
|
9
8
|
import { parse, stringify } from "ini";
|
|
@@ -1052,7 +1051,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
1052
1051
|
}
|
|
1053
1052
|
}
|
|
1054
1053
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
|
|
1055
|
-
var C, R, b, x,
|
|
1054
|
+
var C, R, b, x, H, T, _, h, J, X, Q, K, Z, ee, te, re, $, se, q, z;
|
|
1056
1055
|
class PHP {
|
|
1057
1056
|
/**
|
|
1058
1057
|
* Initializes a PHP runtime.
|
|
@@ -1062,7 +1061,7 @@ class PHP {
|
|
|
1062
1061
|
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
1063
1062
|
*/
|
|
1064
1063
|
constructor(r) {
|
|
1065
|
-
y(this,
|
|
1064
|
+
y(this, h);
|
|
1066
1065
|
y(this, C);
|
|
1067
1066
|
y(this, R, !1);
|
|
1068
1067
|
y(this, b, null);
|
|
@@ -1070,9 +1069,9 @@ class PHP {
|
|
|
1070
1069
|
// Listen to all events
|
|
1071
1070
|
["*", /* @__PURE__ */ new Set()]
|
|
1072
1071
|
]));
|
|
1073
|
-
y(this,
|
|
1074
|
-
y(this,
|
|
1075
|
-
y(this,
|
|
1072
|
+
y(this, H, []);
|
|
1073
|
+
y(this, T, {});
|
|
1074
|
+
y(this, _, {
|
|
1076
1075
|
enabled: !1,
|
|
1077
1076
|
recreateRuntime: () => 0,
|
|
1078
1077
|
needsRotating: !1,
|
|
@@ -1080,7 +1079,7 @@ class PHP {
|
|
|
1080
1079
|
requestsMade: 0
|
|
1081
1080
|
});
|
|
1082
1081
|
this.semaphore = new Semaphore({ concurrency: 1 }), r !== void 0 && this.initializeRuntime(r), this.addEventListener("request.error", (e) => {
|
|
1083
|
-
e.source === "php-wasm" && (u(this,
|
|
1082
|
+
e.source === "php-wasm" && (u(this, _).needsRotating = !0);
|
|
1084
1083
|
});
|
|
1085
1084
|
}
|
|
1086
1085
|
/**
|
|
@@ -1149,8 +1148,8 @@ class PHP {
|
|
|
1149
1148
|
* @param listener Callback function to handle the message.
|
|
1150
1149
|
*/
|
|
1151
1150
|
onMessage(r) {
|
|
1152
|
-
return u(this,
|
|
1153
|
-
g(this,
|
|
1151
|
+
return u(this, H).push(r), async () => {
|
|
1152
|
+
g(this, H, u(this, H).filter(
|
|
1154
1153
|
(e) => e !== r
|
|
1155
1154
|
));
|
|
1156
1155
|
};
|
|
@@ -1244,7 +1243,7 @@ class PHP {
|
|
|
1244
1243
|
}
|
|
1245
1244
|
`
|
|
1246
1245
|
), e.onMessage = async (t) => {
|
|
1247
|
-
for (const s of u(this,
|
|
1246
|
+
for (const s of u(this, H)) {
|
|
1248
1247
|
const n = await s(t);
|
|
1249
1248
|
if (n)
|
|
1250
1249
|
return n;
|
|
@@ -1487,7 +1486,7 @@ class PHP {
|
|
|
1487
1486
|
async runStream(r) {
|
|
1488
1487
|
const e = await this.semaphore.acquire();
|
|
1489
1488
|
let t;
|
|
1490
|
-
const s = m(this,
|
|
1489
|
+
const s = m(this, h, z).call(this, async () => {
|
|
1491
1490
|
if (u(this, R) || (await this[__private__dont__use].ccall(
|
|
1492
1491
|
"php_wasm_init",
|
|
1493
1492
|
null,
|
|
@@ -1500,22 +1499,22 @@ class PHP {
|
|
|
1500
1499
|
throw new Error(
|
|
1501
1500
|
`The script path "${r.scriptPath}" does not exist.`
|
|
1502
1501
|
);
|
|
1503
|
-
m(this,
|
|
1504
|
-
const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this,
|
|
1505
|
-
if (m(this,
|
|
1506
|
-
this.writeFile("/internal/eval.php", r.code), m(this,
|
|
1502
|
+
m(this, h, X).call(this, r.relativeUri || ""), m(this, h, ee).call(this, r.method || "GET");
|
|
1503
|
+
const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, h, Z).call(this, o, r.protocol || "http");
|
|
1504
|
+
if (m(this, h, Q).call(this, o), m(this, h, K).call(this, a), m(this, h, te).call(this, i), r.body && (t = m(this, h, re).call(this, r.body)), typeof r.code == "string")
|
|
1505
|
+
this.writeFile("/internal/eval.php", r.code), m(this, h, $).call(this, "/internal/eval.php");
|
|
1507
1506
|
else if (typeof r.scriptPath == "string")
|
|
1508
|
-
m(this,
|
|
1507
|
+
m(this, h, $).call(this, r.scriptPath || "");
|
|
1509
1508
|
else
|
|
1510
1509
|
throw new TypeError(
|
|
1511
1510
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
1512
1511
|
);
|
|
1513
|
-
const c = m(this,
|
|
1512
|
+
const c = m(this, h, J).call(this, r.$_SERVER, i, a);
|
|
1514
1513
|
for (const d in c)
|
|
1515
|
-
m(this,
|
|
1514
|
+
m(this, h, se).call(this, d, c[d]);
|
|
1516
1515
|
const l = r.env || {};
|
|
1517
1516
|
for (const d in l)
|
|
1518
|
-
m(this,
|
|
1517
|
+
m(this, h, q).call(this, d, l[d]);
|
|
1519
1518
|
return await this[__private__dont__use].ccall(
|
|
1520
1519
|
"wasm_sapi_handle_request",
|
|
1521
1520
|
NUMBER,
|
|
@@ -1753,21 +1752,21 @@ class PHP {
|
|
|
1753
1752
|
* or an internal crash.
|
|
1754
1753
|
*/
|
|
1755
1754
|
enableRuntimeRotation(r) {
|
|
1756
|
-
g(this,
|
|
1757
|
-
...u(this,
|
|
1755
|
+
g(this, _, {
|
|
1756
|
+
...u(this, _),
|
|
1758
1757
|
enabled: !0,
|
|
1759
1758
|
recreateRuntime: r.recreateRuntime,
|
|
1760
1759
|
maxRequests: r.maxRequests ?? 400
|
|
1761
1760
|
});
|
|
1762
1761
|
}
|
|
1763
1762
|
async rotateRuntime() {
|
|
1764
|
-
if (!u(this,
|
|
1763
|
+
if (!u(this, _).enabled)
|
|
1765
1764
|
throw new Error(
|
|
1766
1765
|
"Runtime rotation is not enabled. Call enableRuntimeRotation() first."
|
|
1767
1766
|
);
|
|
1768
1767
|
await this.hotSwapPHPRuntime(
|
|
1769
|
-
await u(this,
|
|
1770
|
-
), u(this,
|
|
1768
|
+
await u(this, _).recreateRuntime()
|
|
1769
|
+
), u(this, _).requestsMade = 0, u(this, _).needsRotating = !1;
|
|
1771
1770
|
}
|
|
1772
1771
|
/**
|
|
1773
1772
|
* Hot-swaps the PHP runtime for a new one without
|
|
@@ -1778,13 +1777,13 @@ class PHP {
|
|
|
1778
1777
|
async hotSwapPHPRuntime(r) {
|
|
1779
1778
|
const e = this[__private__dont__use].FS, t = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
|
|
1780
1779
|
e.chdir("/");
|
|
1781
|
-
const i = Object.entries(u(this,
|
|
1780
|
+
const i = Object.entries(u(this, T)).map(
|
|
1782
1781
|
([c, l]) => ({
|
|
1783
1782
|
mountHandler: l.mountHandler,
|
|
1784
1783
|
vfsPath: c
|
|
1785
1784
|
})
|
|
1786
1785
|
), o = Object.values(
|
|
1787
|
-
u(this,
|
|
1786
|
+
u(this, T)
|
|
1788
1787
|
).reverse();
|
|
1789
1788
|
for (const c of o)
|
|
1790
1789
|
await c.unmount();
|
|
@@ -1824,12 +1823,14 @@ class PHP {
|
|
|
1824
1823
|
), s = {
|
|
1825
1824
|
mountHandler: e,
|
|
1826
1825
|
unmount: async () => {
|
|
1827
|
-
|
|
1826
|
+
try {
|
|
1827
|
+
await t();
|
|
1828
|
+
} finally {
|
|
1829
|
+
delete u(this, T)[r];
|
|
1830
|
+
}
|
|
1828
1831
|
}
|
|
1829
1832
|
};
|
|
1830
|
-
return u(this,
|
|
1831
|
-
s.unmount();
|
|
1832
|
-
};
|
|
1833
|
+
return u(this, T)[r] = s, () => s.unmount();
|
|
1833
1834
|
}
|
|
1834
1835
|
/**
|
|
1835
1836
|
* Starts a PHP CLI session with given arguments.
|
|
@@ -1847,12 +1848,12 @@ class PHP {
|
|
|
1847
1848
|
async cli(r, e = {}) {
|
|
1848
1849
|
if (basename(r[0] ?? "") !== "php")
|
|
1849
1850
|
return this.subProcess(r, e);
|
|
1850
|
-
u(this, R) && (u(this,
|
|
1851
|
+
u(this, R) && (u(this, _).needsRotating = !0);
|
|
1851
1852
|
const t = await this.semaphore.acquire();
|
|
1852
|
-
return await m(this,
|
|
1853
|
+
return await m(this, h, z).call(this, () => {
|
|
1853
1854
|
const s = e.env || {};
|
|
1854
1855
|
for (const [n, i] of Object.entries(s))
|
|
1855
|
-
m(this,
|
|
1856
|
+
m(this, h, q).call(this, n, i);
|
|
1856
1857
|
r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
|
|
1857
1858
|
for (const n of r)
|
|
1858
1859
|
this[__private__dont__use].ccall(
|
|
@@ -1865,7 +1866,7 @@ class PHP {
|
|
|
1865
1866
|
async: !0
|
|
1866
1867
|
});
|
|
1867
1868
|
}).then((s) => (s.exitCode.finally(t), s)).finally(() => {
|
|
1868
|
-
u(this,
|
|
1869
|
+
u(this, _).needsRotating = !0;
|
|
1869
1870
|
});
|
|
1870
1871
|
}
|
|
1871
1872
|
/**
|
|
@@ -1953,7 +1954,7 @@ class PHP {
|
|
|
1953
1954
|
this.exit(0);
|
|
1954
1955
|
}
|
|
1955
1956
|
}
|
|
1956
|
-
C = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(),
|
|
1957
|
+
C = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(), H = new WeakMap(), T = new WeakMap(), _ = new WeakMap(), h = new WeakSet(), /**
|
|
1957
1958
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1958
1959
|
*
|
|
1959
1960
|
* @param defaults Default entries to include in $_SERVER.
|
|
@@ -1962,7 +1963,7 @@ C = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(), T =
|
|
|
1962
1963
|
* was provided.
|
|
1963
1964
|
* @returns Computed $_SERVER entries.
|
|
1964
1965
|
*/
|
|
1965
|
-
|
|
1966
|
+
J = function(r, e, t) {
|
|
1966
1967
|
const s = {
|
|
1967
1968
|
...r || {}
|
|
1968
1969
|
};
|
|
@@ -2076,29 +2077,29 @@ Y = function(r, e, t) {
|
|
|
2076
2077
|
[r, e]
|
|
2077
2078
|
);
|
|
2078
2079
|
}, z = async function(r) {
|
|
2079
|
-
u(this,
|
|
2080
|
+
u(this, _).enabled && u(this, _).needsRotating && await this.rotateRuntime(), ++u(this, _).requestsMade, u(this, _).requestsMade >= u(this, _).maxRequests && (u(this, _).needsRotating = !0);
|
|
2080
2081
|
const e = this[__private__dont__use], t = await createInvertedReadableStream();
|
|
2081
|
-
e.onHeaders = (
|
|
2082
|
-
a || s || t.controller.enqueue(
|
|
2082
|
+
e.onHeaders = (p) => {
|
|
2083
|
+
a || s || t.controller.enqueue(p.slice());
|
|
2083
2084
|
};
|
|
2084
2085
|
let s = !1;
|
|
2085
2086
|
const n = () => {
|
|
2086
2087
|
s || (s = !0, t.controller.close());
|
|
2087
2088
|
}, i = await createInvertedReadableStream();
|
|
2088
|
-
e.onStdout = (
|
|
2089
|
-
n(), !a && i.controller.enqueue(
|
|
2089
|
+
e.onStdout = (p) => {
|
|
2090
|
+
n(), !a && i.controller.enqueue(p.slice());
|
|
2090
2091
|
};
|
|
2091
2092
|
const o = await createInvertedReadableStream();
|
|
2092
|
-
e.onStderr = (
|
|
2093
|
-
a || o.controller.enqueue(
|
|
2093
|
+
e.onStderr = (p) => {
|
|
2094
|
+
a || o.controller.enqueue(p.slice());
|
|
2094
2095
|
};
|
|
2095
2096
|
let a = !1, c;
|
|
2096
2097
|
const d = (async () => {
|
|
2097
|
-
var
|
|
2098
|
+
var p;
|
|
2098
2099
|
try {
|
|
2099
2100
|
return await Promise.race([
|
|
2100
2101
|
r(),
|
|
2101
|
-
new Promise((
|
|
2102
|
+
new Promise((w, F) => {
|
|
2102
2103
|
var V;
|
|
2103
2104
|
c = (G) => {
|
|
2104
2105
|
isExitCode(G.error) || F(G.error);
|
|
@@ -2113,35 +2114,35 @@ Y = function(r, e, t) {
|
|
|
2113
2114
|
if (isExitCode(f))
|
|
2114
2115
|
return f.status;
|
|
2115
2116
|
safeStreamError$1(i.controller, f), safeStreamError$1(o.controller, f), safeStreamError$1(t.controller, f), a = !0;
|
|
2116
|
-
for (const
|
|
2117
|
-
typeof this[
|
|
2117
|
+
for (const w in this)
|
|
2118
|
+
typeof this[w] == "function" && (this[w] = () => {
|
|
2118
2119
|
throw new Error(
|
|
2119
2120
|
"PHP runtime has crashed – see the earlier error for details."
|
|
2120
2121
|
);
|
|
2121
2122
|
});
|
|
2122
2123
|
throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
|
|
2123
2124
|
} finally {
|
|
2124
|
-
a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (
|
|
2125
|
+
a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (p = u(this, b)) == null || p.removeEventListener(
|
|
2125
2126
|
"error",
|
|
2126
2127
|
c
|
|
2127
2128
|
);
|
|
2128
2129
|
}
|
|
2129
2130
|
})().then(
|
|
2130
|
-
(
|
|
2131
|
+
(p) => (p !== 0 && this.dispatchEvent({
|
|
2131
2132
|
type: "request.error",
|
|
2132
2133
|
error: new Error(
|
|
2133
|
-
`PHP.run() failed with exit code ${
|
|
2134
|
+
`PHP.run() failed with exit code ${p}.`
|
|
2134
2135
|
),
|
|
2135
2136
|
// Distinguish between PHP request and PHP-wasm errors
|
|
2136
2137
|
source: "php-wasm"
|
|
2137
|
-
}),
|
|
2138
|
-
(
|
|
2139
|
-
const f =
|
|
2138
|
+
}), p),
|
|
2139
|
+
(p) => {
|
|
2140
|
+
const f = p.source ?? "php-wasm";
|
|
2140
2141
|
throw this.dispatchEvent({
|
|
2141
2142
|
type: "request.error",
|
|
2142
|
-
error:
|
|
2143
|
+
error: p,
|
|
2143
2144
|
source: f
|
|
2144
|
-
}),
|
|
2145
|
+
}), p;
|
|
2145
2146
|
}
|
|
2146
2147
|
);
|
|
2147
2148
|
return new StreamedPHPResponse(
|
|
@@ -2160,7 +2161,12 @@ function normalizeHeaders(r) {
|
|
|
2160
2161
|
function copyMEMFSNodes(r, e, t) {
|
|
2161
2162
|
if (getNodeType(r, t) !== "memfs" || !["memfs", "missing"].includes(getNodeType(e, t)))
|
|
2162
2163
|
return;
|
|
2163
|
-
const s = r.lookupPath(t);
|
|
2164
|
+
const s = r.lookupPath(t, { follow: !1 });
|
|
2165
|
+
if (r.isLink(s.node.mode)) {
|
|
2166
|
+
const i = r.readlink(t);
|
|
2167
|
+
e.symlink(i, t);
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2164
2170
|
if (!r.isDir(s.node.mode)) {
|
|
2165
2171
|
e.writeFile(t, r.readFile(t));
|
|
2166
2172
|
return;
|
|
@@ -2467,7 +2473,43 @@ const SupportedPHPVersions = [
|
|
|
2467
2473
|
"8.1",
|
|
2468
2474
|
"8.0",
|
|
2469
2475
|
"7.4"
|
|
2470
|
-
], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions,
|
|
2476
|
+
], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions, LegacyPHPVersions = ["5.2"];
|
|
2477
|
+
function isLegacyPHPVersion(r) {
|
|
2478
|
+
return LegacyPHPVersions.includes(r ?? "");
|
|
2479
|
+
}
|
|
2480
|
+
const AllPHPVersions = [
|
|
2481
|
+
...SupportedPHPVersions,
|
|
2482
|
+
...LegacyPHPVersions
|
|
2483
|
+
], LEGACY_PHP_INI_PATH = "/internal/shared/php.ini", LEGACY_PHP_INI_CONTENT = [
|
|
2484
|
+
"auto_prepend_file=/internal/shared/auto_prepend_file.php",
|
|
2485
|
+
"memory_limit=256M",
|
|
2486
|
+
"ignore_repeated_errors = 1",
|
|
2487
|
+
"error_reporting = E_ALL",
|
|
2488
|
+
"display_errors = 1",
|
|
2489
|
+
"html_errors = 1",
|
|
2490
|
+
"display_startup_errors = On",
|
|
2491
|
+
"log_errors = 1",
|
|
2492
|
+
"always_populate_raw_post_data = -1",
|
|
2493
|
+
"upload_max_filesize = 2000M",
|
|
2494
|
+
"post_max_size = 2000M",
|
|
2495
|
+
"allow_url_fopen = On",
|
|
2496
|
+
"allow_url_include = Off",
|
|
2497
|
+
"session.save_path = /home/web_user",
|
|
2498
|
+
"implicit_flush = 1",
|
|
2499
|
+
"output_buffering = 0",
|
|
2500
|
+
"max_execution_time = 0",
|
|
2501
|
+
"max_input_time = -1",
|
|
2502
|
+
"disable_functions = ini_get_all",
|
|
2503
|
+
"opcache.enable = 0",
|
|
2504
|
+
"opcache.enable_cli = 0"
|
|
2505
|
+
].join(`
|
|
2506
|
+
`);
|
|
2507
|
+
function createLegacyPhpIniPreRunStep() {
|
|
2508
|
+
return (r) => {
|
|
2509
|
+
r.FS.mkdirTree("/internal/shared"), r.FS.writeFile(LEGACY_PHP_INI_PATH, LEGACY_PHP_INI_CONTENT);
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
const DEFAULT_BASE_URL = "http://example.com";
|
|
2471
2513
|
function toRelativeUrl(r) {
|
|
2472
2514
|
return r.origin === "null" ? r.toString() : r.toString().substring(r.origin.length);
|
|
2473
2515
|
}
|
|
@@ -2598,7 +2640,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2598
2640
|
xspf,
|
|
2599
2641
|
zip
|
|
2600
2642
|
};
|
|
2601
|
-
var S,
|
|
2643
|
+
var S, I, U, L, M, E, A, k, j, P, ne, B, ie, oe, ae;
|
|
2602
2644
|
class PHPRequestHandler {
|
|
2603
2645
|
/**
|
|
2604
2646
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2614,14 +2656,14 @@ class PHPRequestHandler {
|
|
|
2614
2656
|
constructor(e) {
|
|
2615
2657
|
y(this, P);
|
|
2616
2658
|
y(this, S);
|
|
2617
|
-
y(this,
|
|
2659
|
+
y(this, I);
|
|
2618
2660
|
y(this, U);
|
|
2619
2661
|
y(this, L);
|
|
2620
|
-
y(this,
|
|
2662
|
+
y(this, M);
|
|
2621
2663
|
y(this, E);
|
|
2622
2664
|
y(this, A);
|
|
2623
2665
|
y(this, k);
|
|
2624
|
-
y(this,
|
|
2666
|
+
y(this, j);
|
|
2625
2667
|
const {
|
|
2626
2668
|
documentRoot: t = "/www/",
|
|
2627
2669
|
absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
|
|
@@ -2638,11 +2680,11 @@ class PHPRequestHandler {
|
|
|
2638
2680
|
else if (e.phpFactory)
|
|
2639
2681
|
this.instanceManager = new PHPProcessManager({
|
|
2640
2682
|
phpFactory: async (d) => {
|
|
2641
|
-
const
|
|
2683
|
+
const p = await e.phpFactory({
|
|
2642
2684
|
...d,
|
|
2643
2685
|
requestHandler: this
|
|
2644
2686
|
});
|
|
2645
|
-
return a(
|
|
2687
|
+
return a(p), p;
|
|
2646
2688
|
},
|
|
2647
2689
|
maxPhpInstances: e.maxPhpInstances
|
|
2648
2690
|
});
|
|
@@ -2652,16 +2694,16 @@ class PHPRequestHandler {
|
|
|
2652
2694
|
);
|
|
2653
2695
|
g(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this, S, t);
|
|
2654
2696
|
const c = new URL(s);
|
|
2655
|
-
g(this, U, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this,
|
|
2697
|
+
g(this, U, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this, I, (c.protocol || "").replace(":", ""));
|
|
2656
2698
|
const l = u(this, L) !== 443 && u(this, L) !== 80;
|
|
2657
|
-
g(this,
|
|
2699
|
+
g(this, M, [
|
|
2658
2700
|
u(this, U),
|
|
2659
2701
|
l ? `:${u(this, L)}` : ""
|
|
2660
2702
|
].join("")), g(this, E, c.pathname.replace(/\/+$/, "")), g(this, A, [
|
|
2661
|
-
`${u(this,
|
|
2662
|
-
u(this,
|
|
2703
|
+
`${u(this, I)}://`,
|
|
2704
|
+
u(this, M),
|
|
2663
2705
|
u(this, E)
|
|
2664
|
-
].join("")), this.rewriteRules = n, g(this,
|
|
2706
|
+
].join("")), this.rewriteRules = n, g(this, j, i), this.getFileNotFoundAction = o;
|
|
2665
2707
|
}
|
|
2666
2708
|
async getPrimaryPhp() {
|
|
2667
2709
|
return await this.instanceManager.getPrimaryPhp();
|
|
@@ -2782,7 +2824,7 @@ class PHPRequestHandler {
|
|
|
2782
2824
|
decodeURIComponent(n.pathname),
|
|
2783
2825
|
u(this, E)
|
|
2784
2826
|
);
|
|
2785
|
-
let a = m(this, P,
|
|
2827
|
+
let a = m(this, P, B).call(this, o);
|
|
2786
2828
|
if (i.isDir(a)) {
|
|
2787
2829
|
if (!o.endsWith("/"))
|
|
2788
2830
|
return StreamedPHPResponse.fromPHPResponse(
|
|
@@ -2807,10 +2849,10 @@ class PHPRequestHandler {
|
|
|
2807
2849
|
let c = o;
|
|
2808
2850
|
for (; c.startsWith("/") && c !== dirname(c); ) {
|
|
2809
2851
|
c = dirname(c);
|
|
2810
|
-
const l = m(this, P,
|
|
2852
|
+
const l = m(this, P, B).call(this, c);
|
|
2811
2853
|
if (i.isFile(l) && // Only run partial path resolution for PHP files.
|
|
2812
2854
|
l.endsWith(".php")) {
|
|
2813
|
-
a = m(this, P,
|
|
2855
|
+
a = m(this, P, B).call(this, c);
|
|
2814
2856
|
break;
|
|
2815
2857
|
}
|
|
2816
2858
|
}
|
|
@@ -2946,7 +2988,7 @@ class PHPRequestHandler {
|
|
|
2946
2988
|
await this.instanceManager[Symbol.asyncDispose]();
|
|
2947
2989
|
}
|
|
2948
2990
|
}
|
|
2949
|
-
S = new WeakMap(),
|
|
2991
|
+
S = new WeakMap(), I = new WeakMap(), U = new WeakMap(), L = new WeakMap(), M = new WeakMap(), E = new WeakMap(), A = new WeakMap(), k = new WeakMap(), j = new WeakMap(), P = new WeakSet(), /**
|
|
2950
2992
|
* Apply the rewrite rules to the original request URL.
|
|
2951
2993
|
*
|
|
2952
2994
|
* @param originalRequestUrl - The original request URL.
|
|
@@ -2975,8 +3017,8 @@ ne = function(e) {
|
|
|
2975
3017
|
* @param urlPath - The URL path to resolve (e.g., '/phpmyadmin/index.php')
|
|
2976
3018
|
* @returns The resolved filesystem path
|
|
2977
3019
|
*/
|
|
2978
|
-
|
|
2979
|
-
for (const t of u(this,
|
|
3020
|
+
B = function(e) {
|
|
3021
|
+
for (const t of u(this, j))
|
|
2980
3022
|
if (e === t.urlPrefix || e.startsWith(t.urlPrefix + "/")) {
|
|
2981
3023
|
const s = e.slice(t.urlPrefix.length);
|
|
2982
3024
|
return joinPaths(t.fsPath, s);
|
|
@@ -3022,22 +3064,22 @@ ie = function(e, t) {
|
|
|
3022
3064
|
}, ae = async function(e, t, s, n, i) {
|
|
3023
3065
|
let o = "GET";
|
|
3024
3066
|
const a = {
|
|
3025
|
-
host: u(this,
|
|
3067
|
+
host: u(this, M),
|
|
3026
3068
|
...normalizeHeaders(t.headers || {})
|
|
3027
3069
|
};
|
|
3028
3070
|
u(this, k) && (a.cookie = u(this, k).getCookieRequestHeader());
|
|
3029
3071
|
let c = t.body;
|
|
3030
3072
|
if (typeof c == "object" && !(c instanceof Uint8Array)) {
|
|
3031
3073
|
o = "POST";
|
|
3032
|
-
const { bytes: d, contentType:
|
|
3033
|
-
c = d, a["content-type"] =
|
|
3074
|
+
const { bytes: d, contentType: p } = await encodeAsMultipart(c);
|
|
3075
|
+
c = d, a["content-type"] = p;
|
|
3034
3076
|
}
|
|
3035
3077
|
const l = await e.runStream({
|
|
3036
3078
|
relativeUri: ensurePathPrefix(
|
|
3037
3079
|
toRelativeUrl(new URL(n.toString())),
|
|
3038
3080
|
u(this, E)
|
|
3039
3081
|
),
|
|
3040
|
-
protocol: u(this,
|
|
3082
|
+
protocol: u(this, I),
|
|
3041
3083
|
method: t.method || o,
|
|
3042
3084
|
$_SERVER: this.prepare_$_SERVER_superglobal(
|
|
3043
3085
|
s,
|
|
@@ -3092,6 +3134,11 @@ async function writeFiles(r, e, t, { rmRoot: s = !1 } = {}) {
|
|
|
3092
3134
|
await r.fileExists(dirname(o)) || await r.mkdir(dirname(o)), i instanceof Uint8Array || typeof i == "string" ? await r.writeFile(o, i) : await writeFiles(r, o, i);
|
|
3093
3135
|
}
|
|
3094
3136
|
}
|
|
3137
|
+
function isLegacyPhpInstance(r) {
|
|
3138
|
+
var n;
|
|
3139
|
+
const e = Object.getOwnPropertySymbols(r)[0], t = r[e], s = (n = t == null ? void 0 : t.phpVersion) == null ? void 0 : n.major;
|
|
3140
|
+
return typeof s == "number" && s < 7;
|
|
3141
|
+
}
|
|
3095
3142
|
function ensureProxyFSHasMmapSupport(r) {
|
|
3096
3143
|
const e = Object.getOwnPropertySymbols(r)[0], t = r[e], s = t.PROXYFS, n = t.FS;
|
|
3097
3144
|
s.stream_ops.mmap || (s.stream_ops.mmap = function(i, o, a, c, l) {
|
|
@@ -3102,18 +3149,18 @@ function ensureProxyFSHasMmapSupport(r) {
|
|
|
3102
3149
|
const d = t.malloc(o);
|
|
3103
3150
|
if (!d)
|
|
3104
3151
|
throw new n.ErrnoError(48);
|
|
3105
|
-
const
|
|
3152
|
+
const p = t.HEAPU8.subarray(d, d + o);
|
|
3106
3153
|
let f = 0;
|
|
3107
3154
|
for (; f < o; ) {
|
|
3108
|
-
const
|
|
3155
|
+
const w = i.stream_ops.read(
|
|
3109
3156
|
i,
|
|
3110
|
-
|
|
3157
|
+
p,
|
|
3111
3158
|
f,
|
|
3112
3159
|
o - f,
|
|
3113
3160
|
f
|
|
3114
3161
|
);
|
|
3115
|
-
if (
|
|
3116
|
-
f +=
|
|
3162
|
+
if (w <= 0) break;
|
|
3163
|
+
f += w;
|
|
3117
3164
|
}
|
|
3118
3165
|
if (f !== o)
|
|
3119
3166
|
throw t.free(d), new n.ErrnoError(5);
|
|
@@ -3130,23 +3177,23 @@ function ensureProxyFSHasMmapSupport(r) {
|
|
|
3130
3177
|
});
|
|
3131
3178
|
}
|
|
3132
3179
|
async function proxyFileSystem(r, e, t) {
|
|
3133
|
-
const s = Object.getOwnPropertySymbols(r)[0];
|
|
3134
|
-
for (const
|
|
3135
|
-
r.fileExists(
|
|
3136
|
-
ensureProxyFSHasMmapSupport(
|
|
3137
|
-
const
|
|
3138
|
-
return
|
|
3180
|
+
const s = isLegacyPhpInstance(e), n = Object.getOwnPropertySymbols(r)[0];
|
|
3181
|
+
for (const i of t)
|
|
3182
|
+
r.fileExists(i) || r.mkdir(i), e.mkdir(i), await e.mount(i, (o) => {
|
|
3183
|
+
s || ensureProxyFSHasMmapSupport(o);
|
|
3184
|
+
const a = Object.getOwnPropertySymbols(o)[0];
|
|
3185
|
+
return o[a].FS.mount(
|
|
3139
3186
|
// @ts-ignore
|
|
3140
|
-
|
|
3187
|
+
o[a].PROXYFS,
|
|
3141
3188
|
{
|
|
3142
|
-
root:
|
|
3189
|
+
root: i,
|
|
3143
3190
|
// @ts-ignore
|
|
3144
|
-
fs: r[
|
|
3191
|
+
fs: r[n].FS
|
|
3145
3192
|
},
|
|
3146
|
-
|
|
3193
|
+
i
|
|
3147
3194
|
), () => {
|
|
3148
3195
|
try {
|
|
3149
|
-
|
|
3196
|
+
o[a].FS.unmount(i);
|
|
3150
3197
|
} catch {
|
|
3151
3198
|
}
|
|
3152
3199
|
};
|
|
@@ -3408,29 +3455,29 @@ function expose(r, e = globalThis, t = ["*"], s) {
|
|
|
3408
3455
|
}, l = (i.data.argumentList || []).map(fromWireValue);
|
|
3409
3456
|
let d;
|
|
3410
3457
|
try {
|
|
3411
|
-
const
|
|
3458
|
+
const p = c.slice(0, -1).reduce((w, F) => w[F], r), f = c.reduce((w, F) => w[F], r);
|
|
3412
3459
|
switch (a) {
|
|
3413
3460
|
case MessageType.GET:
|
|
3414
3461
|
d = f;
|
|
3415
3462
|
break;
|
|
3416
3463
|
case MessageType.SET:
|
|
3417
|
-
|
|
3464
|
+
p[c.slice(-1)[0]] = fromWireValue(
|
|
3418
3465
|
i.data.value
|
|
3419
3466
|
), d = !0;
|
|
3420
3467
|
break;
|
|
3421
3468
|
case MessageType.APPLY:
|
|
3422
|
-
d = f.apply(
|
|
3469
|
+
d = f.apply(p, l);
|
|
3423
3470
|
break;
|
|
3424
3471
|
case MessageType.CONSTRUCT:
|
|
3425
3472
|
{
|
|
3426
|
-
const
|
|
3427
|
-
d = proxy(
|
|
3473
|
+
const w = new f(...l);
|
|
3474
|
+
d = proxy(w);
|
|
3428
3475
|
}
|
|
3429
3476
|
break;
|
|
3430
3477
|
case MessageType.ENDPOINT:
|
|
3431
3478
|
{
|
|
3432
|
-
const { port1:
|
|
3433
|
-
expose(r, F), d = transfer(
|
|
3479
|
+
const { port1: w, port2: F } = new MessageChannel();
|
|
3480
|
+
expose(r, F), d = transfer(w, [w]);
|
|
3434
3481
|
}
|
|
3435
3482
|
break;
|
|
3436
3483
|
case MessageType.RELEASE:
|
|
@@ -3439,18 +3486,18 @@ function expose(r, e = globalThis, t = ["*"], s) {
|
|
|
3439
3486
|
default:
|
|
3440
3487
|
return;
|
|
3441
3488
|
}
|
|
3442
|
-
} catch (
|
|
3443
|
-
d = { value:
|
|
3489
|
+
} catch (p) {
|
|
3490
|
+
d = { value: p, [throwMarker]: 0 };
|
|
3444
3491
|
}
|
|
3445
|
-
Promise.resolve(d).catch((
|
|
3446
|
-
const [f,
|
|
3447
|
-
e.postMessage({ ...f, id: o },
|
|
3492
|
+
Promise.resolve(d).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
|
|
3493
|
+
const [f, w] = toWireValue(p);
|
|
3494
|
+
e.postMessage({ ...f, id: o }, w), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in r && typeof r[finalizer] == "function" && r[finalizer]());
|
|
3448
3495
|
}).catch(() => {
|
|
3449
|
-
const [
|
|
3496
|
+
const [p, f] = toWireValue({
|
|
3450
3497
|
value: new TypeError("Unserializable return value"),
|
|
3451
3498
|
[throwMarker]: 0
|
|
3452
3499
|
});
|
|
3453
|
-
e.postMessage({ ...
|
|
3500
|
+
e.postMessage({ ...p, id: o }, f);
|
|
3454
3501
|
}).finally(() => {
|
|
3455
3502
|
s == null || s(i);
|
|
3456
3503
|
});
|
|
@@ -3527,7 +3574,7 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3527
3574
|
e,
|
|
3528
3575
|
{
|
|
3529
3576
|
type: MessageType.SET,
|
|
3530
|
-
path: [...t, a].map((
|
|
3577
|
+
path: [...t, a].map((p) => p.toString()),
|
|
3531
3578
|
value: l
|
|
3532
3579
|
},
|
|
3533
3580
|
d
|
|
@@ -3542,7 +3589,7 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3542
3589
|
}).then(fromWireValue);
|
|
3543
3590
|
if (l === "bind")
|
|
3544
3591
|
return createProxy(r, e, t.slice(0, -1));
|
|
3545
|
-
const [d,
|
|
3592
|
+
const [d, p] = processArguments(c);
|
|
3546
3593
|
return requestResponseMessage(
|
|
3547
3594
|
r,
|
|
3548
3595
|
e,
|
|
@@ -3551,7 +3598,7 @@ function createProxy(r, e, t = [], s = function() {
|
|
|
3551
3598
|
path: t.map((f) => f.toString()),
|
|
3552
3599
|
argumentList: d
|
|
3553
3600
|
},
|
|
3554
|
-
|
|
3601
|
+
p
|
|
3555
3602
|
).then(fromWireValue);
|
|
3556
3603
|
},
|
|
3557
3604
|
construct(o, a) {
|
|
@@ -4757,13 +4804,13 @@ function createObjectPoolProxy(r) {
|
|
|
4757
4804
|
return new Proxy(function() {
|
|
4758
4805
|
}, {
|
|
4759
4806
|
apply(c, l, d) {
|
|
4760
|
-
return i((
|
|
4807
|
+
return i((p) => p[a](...d));
|
|
4761
4808
|
},
|
|
4762
4809
|
get(c, l) {
|
|
4763
4810
|
if (l === "then")
|
|
4764
|
-
return (d,
|
|
4811
|
+
return (d, p) => i((f) => f[a]).then(
|
|
4765
4812
|
d,
|
|
4766
|
-
|
|
4813
|
+
p
|
|
4767
4814
|
);
|
|
4768
4815
|
}
|
|
4769
4816
|
});
|
|
@@ -4791,6 +4838,7 @@ class ProcessIdAllocator {
|
|
|
4791
4838
|
}
|
|
4792
4839
|
}
|
|
4793
4840
|
export {
|
|
4841
|
+
AllPHPVersions,
|
|
4794
4842
|
DEFAULT_BASE_URL,
|
|
4795
4843
|
FSHelpers,
|
|
4796
4844
|
FileLock,
|
|
@@ -4798,7 +4846,10 @@ export {
|
|
|
4798
4846
|
FileLockManagerComposite,
|
|
4799
4847
|
FileLockManagerInMemory,
|
|
4800
4848
|
HttpCookieStore,
|
|
4849
|
+
LEGACY_PHP_INI_CONTENT,
|
|
4850
|
+
LEGACY_PHP_INI_PATH,
|
|
4801
4851
|
LatestSupportedPHPVersion,
|
|
4852
|
+
LegacyPHPVersions,
|
|
4802
4853
|
MAX_ADDRESSABLE_FILE_OFFSET,
|
|
4803
4854
|
PHP,
|
|
4804
4855
|
PHPExecutionFailureError,
|
|
@@ -4816,6 +4867,7 @@ export {
|
|
|
4816
4867
|
applyRewriteRules,
|
|
4817
4868
|
consumeAPI,
|
|
4818
4869
|
consumeAPISync,
|
|
4870
|
+
createLegacyPhpIniPreRunStep,
|
|
4819
4871
|
createObjectPoolProxy,
|
|
4820
4872
|
ensurePathPrefix,
|
|
4821
4873
|
exposeAPI,
|
|
@@ -4823,6 +4875,7 @@ export {
|
|
|
4823
4875
|
getPhpIniEntries,
|
|
4824
4876
|
inferMimeType,
|
|
4825
4877
|
isExitCode,
|
|
4878
|
+
isLegacyPHPVersion,
|
|
4826
4879
|
isPathToSharedFS,
|
|
4827
4880
|
iteratePhpFiles as iterateFiles,
|
|
4828
4881
|
loadPHPRuntime,
|