@php-wasm/web 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +63 -30
- package/index.js +1033 -877
- package/kitchen-sink/7_0_33/php_7_0.wasm +0 -0
- package/kitchen-sink/7_1_30/php_7_1.wasm +0 -0
- package/kitchen-sink/7_2_34/php_7_2.wasm +0 -0
- package/kitchen-sink/7_3_33/php_7_3.wasm +0 -0
- package/kitchen-sink/7_4_33/php_7_4.wasm +0 -0
- package/kitchen-sink/8_0_30/php_8_0.wasm +0 -0
- package/kitchen-sink/8_1_23/php_8_1.wasm +0 -0
- package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
- package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
- package/kitchen-sink/php_7_0.js +6 -3
- package/kitchen-sink/php_7_1.js +6 -3
- package/kitchen-sink/php_7_2.js +6 -3
- package/kitchen-sink/php_7_3.js +6 -3
- package/kitchen-sink/php_7_4.js +6 -3
- package/kitchen-sink/php_8_0.js +6 -3
- package/kitchen-sink/php_8_1.js +6 -3
- package/kitchen-sink/php_8_2.js +6 -3
- package/kitchen-sink/php_8_3.js +6 -3
- package/light/7_0_33/php_7_0.wasm +0 -0
- package/light/7_1_30/php_7_1.wasm +0 -0
- package/light/7_2_34/php_7_2.wasm +0 -0
- package/light/7_3_33/php_7_3.wasm +0 -0
- package/light/7_4_33/php_7_4.wasm +0 -0
- package/light/8_0_30/php_8_0.wasm +0 -0
- package/light/8_1_23/php_8_1.wasm +0 -0
- package/light/8_2_10/php_8_2.wasm +0 -0
- package/light/8_3_0/php_8_3.wasm +0 -0
- package/light/php_7_0.js +6 -3
- package/light/php_7_1.js +6 -3
- package/light/php_7_2.js +6 -3
- package/light/php_7_3.js +6 -3
- package/light/php_7_4.js +6 -3
- package/light/php_8_0.js +6 -3
- package/light/php_8_1.js +6 -3
- package/light/php_8_2.js +6 -3
- package/light/php_8_3.js +6 -3
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (!
|
|
1
|
+
var Q = (e, t, r) => {
|
|
2
|
+
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
if (
|
|
5
|
+
var l = (e, t, r) => (Q(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
|
|
6
|
+
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
var
|
|
8
|
+
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
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 _ = (e, t, r) => (Q(e, t, "access private method"), r);
|
|
11
11
|
if (typeof File > "u") {
|
|
12
|
-
class
|
|
13
|
-
constructor(r,
|
|
12
|
+
class e extends Blob {
|
|
13
|
+
constructor(r, s, i) {
|
|
14
14
|
super(r);
|
|
15
|
-
let
|
|
16
|
-
|
|
15
|
+
let n;
|
|
16
|
+
i != null && i.lastModified && (n = /* @__PURE__ */ new Date()), (!n || isNaN(n.getFullYear())) && (n = /* @__PURE__ */ new Date()), this.lastModifiedDate = n, this.lastModified = n.getMilliseconds(), this.name = s || "";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
global.File =
|
|
19
|
+
global.File = e;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return new Promise(function(
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
function asPromise(e) {
|
|
22
|
+
return new Promise(function(t, r) {
|
|
23
|
+
e.onload = e.onerror = function(s) {
|
|
24
|
+
e.onload = e.onerror = null, s.type === "load" ? t(e.result) : r(new Error("Failed to read the blob/file"));
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
29
|
-
const
|
|
30
|
-
return
|
|
29
|
+
const t = new FileReader();
|
|
30
|
+
return t.readAsArrayBuffer(this), asPromise(t);
|
|
31
31
|
});
|
|
32
32
|
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
33
|
-
const
|
|
34
|
-
return
|
|
33
|
+
const t = new FileReader();
|
|
34
|
+
return t.readAsText(this), asPromise(t);
|
|
35
35
|
});
|
|
36
|
-
function
|
|
37
|
-
const
|
|
36
|
+
function isByobSupported() {
|
|
37
|
+
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
|
|
38
38
|
try {
|
|
39
39
|
return r.getReader({ mode: "byob" }), !0;
|
|
40
40
|
} catch {
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
(typeof Blob.prototype.stream > "u" || !
|
|
45
|
-
let
|
|
46
|
-
const
|
|
44
|
+
(typeof Blob.prototype.stream > "u" || !isByobSupported()) && (Blob.prototype.stream = function() {
|
|
45
|
+
let e = 0;
|
|
46
|
+
const t = this;
|
|
47
47
|
return new ReadableStream({
|
|
48
48
|
type: "bytes",
|
|
49
49
|
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
50
50
|
// this if needed.
|
|
51
51
|
autoAllocateChunkSize: 512 * 1024,
|
|
52
52
|
async pull(r) {
|
|
53
|
-
const
|
|
54
|
-
new Uint8Array(
|
|
55
|
-
const a =
|
|
56
|
-
r.byobRequest.respond(a),
|
|
53
|
+
const s = r.byobRequest.view, n = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(n);
|
|
54
|
+
new Uint8Array(s.buffer).set(o);
|
|
55
|
+
const a = o.byteLength;
|
|
56
|
+
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
if (typeof CustomEvent > "u") {
|
|
61
|
-
class
|
|
62
|
-
constructor(r,
|
|
63
|
-
super(r,
|
|
61
|
+
class e extends Event {
|
|
62
|
+
constructor(r, s = {}) {
|
|
63
|
+
super(r, s), this.detail = s.detail;
|
|
64
64
|
}
|
|
65
65
|
initCustomEvent() {
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
globalThis.CustomEvent =
|
|
68
|
+
globalThis.CustomEvent = e;
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
class
|
|
70
|
+
const kError = Symbol("error"), kMessage = Symbol("message");
|
|
71
|
+
class ErrorEvent2 extends Event {
|
|
72
72
|
/**
|
|
73
73
|
* Create a new `ErrorEvent`.
|
|
74
74
|
*
|
|
@@ -76,93 +76,93 @@ class Pe extends Event {
|
|
|
76
76
|
* @param options A dictionary object that allows for setting
|
|
77
77
|
* attributes via object members of the same name.
|
|
78
78
|
*/
|
|
79
|
-
constructor(
|
|
80
|
-
super(
|
|
79
|
+
constructor(t, r = {}) {
|
|
80
|
+
super(t), this[kError] = r.error === void 0 ? null : r.error, this[kMessage] = r.message === void 0 ? "" : r.message;
|
|
81
81
|
}
|
|
82
82
|
get error() {
|
|
83
|
-
return this[
|
|
83
|
+
return this[kError];
|
|
84
84
|
}
|
|
85
85
|
get message() {
|
|
86
|
-
return this[
|
|
86
|
+
return this[kMessage];
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
Object.defineProperty(
|
|
90
|
-
Object.defineProperty(
|
|
91
|
-
const
|
|
92
|
-
function
|
|
93
|
-
return
|
|
89
|
+
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
|
|
90
|
+
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
|
|
91
|
+
const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
|
|
92
|
+
function isExitCodeZero(e) {
|
|
93
|
+
return e instanceof Error ? "exitCode" in e && (e == null ? void 0 : e.exitCode) === 0 || (e == null ? void 0 : e.name) === "ExitStatus" && "status" in e && e.status === 0 : !1;
|
|
94
94
|
}
|
|
95
|
-
class
|
|
95
|
+
class UnhandledRejectionsTarget extends EventTarget {
|
|
96
96
|
constructor() {
|
|
97
97
|
super(...arguments), this.listenersCount = 0;
|
|
98
98
|
}
|
|
99
|
-
addEventListener(
|
|
100
|
-
++this.listenersCount, super.addEventListener(
|
|
99
|
+
addEventListener(t, r) {
|
|
100
|
+
++this.listenersCount, super.addEventListener(t, r);
|
|
101
101
|
}
|
|
102
|
-
removeEventListener(
|
|
103
|
-
--this.listenersCount, super.removeEventListener(
|
|
102
|
+
removeEventListener(t, r) {
|
|
103
|
+
--this.listenersCount, super.removeEventListener(t, r);
|
|
104
104
|
}
|
|
105
105
|
hasListeners() {
|
|
106
106
|
return this.listenersCount > 0;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
...
|
|
109
|
+
function improveWASMErrorReporting(e) {
|
|
110
|
+
e.asm = {
|
|
111
|
+
...e.asm
|
|
112
112
|
};
|
|
113
|
-
const
|
|
114
|
-
for (const r in
|
|
115
|
-
if (typeof
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
var
|
|
113
|
+
const t = new UnhandledRejectionsTarget();
|
|
114
|
+
for (const r in e.asm)
|
|
115
|
+
if (typeof e.asm[r] == "function") {
|
|
116
|
+
const s = e.asm[r];
|
|
117
|
+
e.asm[r] = function(...i) {
|
|
118
|
+
var n;
|
|
119
119
|
try {
|
|
120
|
-
return
|
|
121
|
-
} catch (
|
|
122
|
-
if (!(
|
|
123
|
-
throw
|
|
124
|
-
const a =
|
|
125
|
-
|
|
126
|
-
(
|
|
120
|
+
return s(...i);
|
|
121
|
+
} catch (o) {
|
|
122
|
+
if (!(o instanceof Error))
|
|
123
|
+
throw o;
|
|
124
|
+
const a = clarifyErrorMessage(
|
|
125
|
+
o,
|
|
126
|
+
(n = e.lastAsyncifyStackSource) == null ? void 0 : n.stack
|
|
127
127
|
);
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
new
|
|
131
|
-
error:
|
|
128
|
+
if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
129
|
+
t.dispatchEvent(
|
|
130
|
+
new ErrorEvent("error", {
|
|
131
|
+
error: o,
|
|
132
132
|
message: a
|
|
133
133
|
})
|
|
134
134
|
);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
throw
|
|
137
|
+
throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
-
return
|
|
141
|
+
return t;
|
|
142
142
|
}
|
|
143
|
-
let
|
|
144
|
-
function
|
|
145
|
-
return
|
|
143
|
+
let functionsMaybeMissingFromAsyncify = [];
|
|
144
|
+
function getFunctionsMaybeMissingFromAsyncify() {
|
|
145
|
+
return functionsMaybeMissingFromAsyncify;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
if (
|
|
149
|
-
let r =
|
|
150
|
-
|
|
147
|
+
function clarifyErrorMessage(e, t) {
|
|
148
|
+
if (e.message === "unreachable") {
|
|
149
|
+
let r = UNREACHABLE_ERROR;
|
|
150
|
+
t || (r += `
|
|
151
151
|
|
|
152
152
|
This stack trace is lacking. For a better one initialize
|
|
153
153
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
154
154
|
|
|
155
|
-
`),
|
|
156
|
-
|
|
155
|
+
`), functionsMaybeMissingFromAsyncify = extractPHPFunctionsFromStack(
|
|
156
|
+
t || e.stack || ""
|
|
157
157
|
);
|
|
158
|
-
for (const
|
|
159
|
-
r += ` * ${
|
|
158
|
+
for (const s of functionsMaybeMissingFromAsyncify)
|
|
159
|
+
r += ` * ${s}
|
|
160
160
|
`;
|
|
161
161
|
return r;
|
|
162
162
|
}
|
|
163
|
-
return
|
|
163
|
+
return e.message;
|
|
164
164
|
}
|
|
165
|
-
const
|
|
165
|
+
const UNREACHABLE_ERROR = `
|
|
166
166
|
"unreachable" WASM instruction executed.
|
|
167
167
|
|
|
168
168
|
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
@@ -186,39 +186,39 @@ the Dockerfile, you'll need to trigger this error again with long stack
|
|
|
186
186
|
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
187
187
|
CLI option:
|
|
188
188
|
|
|
189
|
-
`,
|
|
190
|
-
let
|
|
191
|
-
function
|
|
192
|
-
if (!
|
|
193
|
-
|
|
194
|
-
${
|
|
195
|
-
${
|
|
196
|
-
for (const
|
|
189
|
+
`, redBg = "\x1B[41m", bold = "\x1B[1m", reset = "\x1B[0m", eol = "\x1B[K";
|
|
190
|
+
let logged = !1;
|
|
191
|
+
function showCriticalErrorBox(e) {
|
|
192
|
+
if (!logged && (logged = !0, !(e != null && e.trim().startsWith("Program terminated with exit")))) {
|
|
193
|
+
console.log(`${redBg}
|
|
194
|
+
${eol}
|
|
195
|
+
${bold} WASM ERROR${reset}${redBg}`);
|
|
196
|
+
for (const t of e.split(`
|
|
197
197
|
`))
|
|
198
|
-
console.log(`${
|
|
199
|
-
console.log(`${
|
|
198
|
+
console.log(`${eol} ${t} `);
|
|
199
|
+
console.log(`${reset}`);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function extractPHPFunctionsFromStack(e) {
|
|
203
203
|
try {
|
|
204
|
-
const
|
|
204
|
+
const t = e.split(`
|
|
205
205
|
`).slice(1).map((r) => {
|
|
206
|
-
const
|
|
206
|
+
const s = r.trim().substring(3).split(" ");
|
|
207
207
|
return {
|
|
208
|
-
fn:
|
|
208
|
+
fn: s.length >= 2 ? s[0] : "<unknown>",
|
|
209
209
|
isWasm: r.includes("wasm://")
|
|
210
210
|
};
|
|
211
211
|
}).filter(
|
|
212
|
-
({ fn: r, isWasm:
|
|
212
|
+
({ fn: r, isWasm: s }) => s && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
|
|
213
213
|
).map(({ fn: r }) => r);
|
|
214
|
-
return Array.from(new Set(
|
|
214
|
+
return Array.from(new Set(t));
|
|
215
215
|
} catch {
|
|
216
216
|
return [];
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
class
|
|
220
|
-
constructor({ concurrency:
|
|
221
|
-
this._running = 0, this.concurrency =
|
|
219
|
+
class Semaphore {
|
|
220
|
+
constructor({ concurrency: t }) {
|
|
221
|
+
this._running = 0, this.concurrency = t, this.queue = [];
|
|
222
222
|
}
|
|
223
223
|
get running() {
|
|
224
224
|
return this._running;
|
|
@@ -226,49 +226,127 @@ class Oe {
|
|
|
226
226
|
async acquire() {
|
|
227
227
|
for (; ; )
|
|
228
228
|
if (this._running >= this.concurrency)
|
|
229
|
-
await new Promise((
|
|
229
|
+
await new Promise((t) => this.queue.push(t));
|
|
230
230
|
else {
|
|
231
231
|
this._running++;
|
|
232
|
-
let
|
|
232
|
+
let t = !1;
|
|
233
233
|
return () => {
|
|
234
|
-
|
|
234
|
+
t || (t = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
async run(
|
|
238
|
+
async run(t) {
|
|
239
239
|
const r = await this.acquire();
|
|
240
240
|
try {
|
|
241
|
-
return await
|
|
241
|
+
return await t();
|
|
242
242
|
} finally {
|
|
243
243
|
r();
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
+
function joinPaths(...e) {
|
|
248
|
+
let t = e.join("/");
|
|
249
|
+
const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
|
|
250
|
+
return t = normalizePath(t), !t && !r && (t = "."), t && s && (t += "/"), t;
|
|
251
|
+
}
|
|
252
|
+
function normalizePath(e) {
|
|
253
|
+
const t = e[0] === "/";
|
|
254
|
+
return e = normalizePathsArray(
|
|
255
|
+
e.split("/").filter((r) => !!r),
|
|
256
|
+
!t
|
|
257
|
+
).join("/"), (t ? "/" : "") + e.replace(/\/$/, "");
|
|
258
|
+
}
|
|
259
|
+
function normalizePathsArray(e, t) {
|
|
260
|
+
let r = 0;
|
|
261
|
+
for (let s = e.length - 1; s >= 0; s--) {
|
|
262
|
+
const i = e[s];
|
|
263
|
+
i === "." ? e.splice(s, 1) : i === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
|
|
264
|
+
}
|
|
265
|
+
if (t)
|
|
266
|
+
for (; r; r--)
|
|
267
|
+
e.unshift("..");
|
|
268
|
+
return e;
|
|
269
|
+
}
|
|
270
|
+
function createSpawnHandler(e) {
|
|
271
|
+
return function(t) {
|
|
272
|
+
const r = new ChildProcess(), s = new ProcessApi(r);
|
|
273
|
+
return setTimeout(async () => {
|
|
274
|
+
await e(t, s), r.emit("spawn", !0);
|
|
275
|
+
}), r;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
class EventEmitter {
|
|
279
|
+
constructor() {
|
|
280
|
+
this.listeners = {};
|
|
281
|
+
}
|
|
282
|
+
emit(t, r) {
|
|
283
|
+
this.listeners[t] && this.listeners[t].forEach(function(s) {
|
|
284
|
+
s(r);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
on(t, r) {
|
|
288
|
+
this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(r);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
class ProcessApi extends EventEmitter {
|
|
292
|
+
constructor(t) {
|
|
293
|
+
super(), this.childProcess = t, this.exited = !1, this.stdinData = [], t.on("stdin", (r) => {
|
|
294
|
+
this.stdinData ? this.stdinData.push(r.slice()) : this.emit("stdin", r);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
stdout(t) {
|
|
298
|
+
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
299
|
+
}
|
|
300
|
+
stderr(t) {
|
|
301
|
+
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
302
|
+
}
|
|
303
|
+
exit(t) {
|
|
304
|
+
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
305
|
+
}
|
|
306
|
+
flushStdin() {
|
|
307
|
+
if (this.stdinData)
|
|
308
|
+
for (let t = 0; t < this.stdinData.length; t++)
|
|
309
|
+
this.emit("stdin", this.stdinData[t]);
|
|
310
|
+
this.stdinData = null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
let lastPid = 9743;
|
|
314
|
+
class ChildProcess extends EventEmitter {
|
|
315
|
+
constructor(t = lastPid++) {
|
|
316
|
+
super(), this.pid = t, this.stdout = new EventEmitter(), this.stderr = new EventEmitter();
|
|
317
|
+
const r = this;
|
|
318
|
+
this.stdin = {
|
|
319
|
+
write: (s) => {
|
|
320
|
+
r.emit("stdin", s);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
247
325
|
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
248
|
-
const
|
|
326
|
+
const e = this.getReader();
|
|
249
327
|
try {
|
|
250
328
|
for (; ; ) {
|
|
251
|
-
const { done:
|
|
252
|
-
if (
|
|
329
|
+
const { done: t, value: r } = await e.read();
|
|
330
|
+
if (t)
|
|
253
331
|
return;
|
|
254
332
|
yield r;
|
|
255
333
|
}
|
|
256
334
|
} finally {
|
|
257
|
-
|
|
335
|
+
e.releaseLock();
|
|
258
336
|
}
|
|
259
337
|
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
260
338
|
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
261
|
-
class
|
|
262
|
-
constructor(
|
|
263
|
-
this.httpStatusCode =
|
|
264
|
-
}
|
|
265
|
-
static fromRawData(
|
|
266
|
-
return new
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
339
|
+
class PHPResponse {
|
|
340
|
+
constructor(t, r, s, i = "", n = 0) {
|
|
341
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
|
|
342
|
+
}
|
|
343
|
+
static fromRawData(t) {
|
|
344
|
+
return new PHPResponse(
|
|
345
|
+
t.httpStatusCode,
|
|
346
|
+
t.headers,
|
|
347
|
+
t.bytes,
|
|
348
|
+
t.errors,
|
|
349
|
+
t.exitCode
|
|
272
350
|
);
|
|
273
351
|
}
|
|
274
352
|
toRawData() {
|
|
@@ -293,7 +371,7 @@ class L {
|
|
|
293
371
|
return new TextDecoder().decode(this.bytes);
|
|
294
372
|
}
|
|
295
373
|
}
|
|
296
|
-
const
|
|
374
|
+
const SupportedPHPVersions = [
|
|
297
375
|
"8.3",
|
|
298
376
|
"8.2",
|
|
299
377
|
"8.1",
|
|
@@ -303,17 +381,17 @@ const gt = [
|
|
|
303
381
|
"7.2",
|
|
304
382
|
"7.1",
|
|
305
383
|
"7.0"
|
|
306
|
-
],
|
|
307
|
-
var
|
|
308
|
-
class
|
|
384
|
+
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
385
|
+
var b, x;
|
|
386
|
+
class PHPBrowser {
|
|
309
387
|
/**
|
|
310
388
|
* @param server - The PHP server to browse.
|
|
311
389
|
* @param config - The browser configuration.
|
|
312
390
|
*/
|
|
313
|
-
constructor(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
this.requestHandler =
|
|
391
|
+
constructor(t, r = {}) {
|
|
392
|
+
u(this, b, void 0);
|
|
393
|
+
u(this, x, void 0);
|
|
394
|
+
this.requestHandler = t, p(this, b, {}), p(this, x, {
|
|
317
395
|
handleRedirects: !1,
|
|
318
396
|
maxRedirects: 4,
|
|
319
397
|
...r
|
|
@@ -333,37 +411,37 @@ class bt {
|
|
|
333
411
|
* @param redirects - Internal. The number of redirects handled so far.
|
|
334
412
|
* @returns PHPRequestHandler response.
|
|
335
413
|
*/
|
|
336
|
-
async request(
|
|
337
|
-
const
|
|
338
|
-
...
|
|
414
|
+
async request(t, r = 0) {
|
|
415
|
+
const s = await this.requestHandler.request({
|
|
416
|
+
...t,
|
|
339
417
|
headers: {
|
|
340
|
-
...
|
|
418
|
+
...t.headers,
|
|
341
419
|
cookie: this.serializeCookies()
|
|
342
420
|
}
|
|
343
421
|
});
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
|
|
422
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, x).handleRedirects && s.headers.location && r < l(this, x).maxRedirects) {
|
|
423
|
+
const i = new URL(
|
|
424
|
+
s.headers.location[0],
|
|
347
425
|
this.requestHandler.absoluteUrl
|
|
348
426
|
);
|
|
349
427
|
return this.request(
|
|
350
428
|
{
|
|
351
|
-
url:
|
|
429
|
+
url: i.toString(),
|
|
352
430
|
method: "GET",
|
|
353
431
|
headers: {}
|
|
354
432
|
},
|
|
355
433
|
r + 1
|
|
356
434
|
);
|
|
357
435
|
}
|
|
358
|
-
return
|
|
436
|
+
return s;
|
|
359
437
|
}
|
|
360
438
|
/** @inheritDoc */
|
|
361
|
-
pathToInternalUrl(
|
|
362
|
-
return this.requestHandler.pathToInternalUrl(
|
|
439
|
+
pathToInternalUrl(t) {
|
|
440
|
+
return this.requestHandler.pathToInternalUrl(t);
|
|
363
441
|
}
|
|
364
442
|
/** @inheritDoc */
|
|
365
|
-
internalUrlToPath(
|
|
366
|
-
return this.requestHandler.internalUrlToPath(
|
|
443
|
+
internalUrlToPath(t) {
|
|
444
|
+
return this.requestHandler.internalUrlToPath(t);
|
|
367
445
|
}
|
|
368
446
|
/** @inheritDoc */
|
|
369
447
|
get absoluteUrl() {
|
|
@@ -373,49 +451,49 @@ class bt {
|
|
|
373
451
|
get documentRoot() {
|
|
374
452
|
return this.requestHandler.documentRoot;
|
|
375
453
|
}
|
|
376
|
-
setCookies(
|
|
377
|
-
for (const r of
|
|
454
|
+
setCookies(t) {
|
|
455
|
+
for (const r of t)
|
|
378
456
|
try {
|
|
379
457
|
if (!r.includes("="))
|
|
380
458
|
continue;
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
} catch (
|
|
384
|
-
console.error(
|
|
459
|
+
const s = r.indexOf("="), i = r.substring(0, s), n = r.substring(s + 1).split(";")[0];
|
|
460
|
+
l(this, b)[i] = n;
|
|
461
|
+
} catch (s) {
|
|
462
|
+
console.error(s);
|
|
385
463
|
}
|
|
386
464
|
}
|
|
387
465
|
serializeCookies() {
|
|
388
|
-
const
|
|
389
|
-
for (const r in
|
|
390
|
-
|
|
391
|
-
return
|
|
466
|
+
const t = [];
|
|
467
|
+
for (const r in l(this, b))
|
|
468
|
+
t.push(`${r}=${l(this, b)[r]}`);
|
|
469
|
+
return t.join("; ");
|
|
392
470
|
}
|
|
393
471
|
}
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
function
|
|
397
|
-
return
|
|
472
|
+
b = new WeakMap(), x = new WeakMap();
|
|
473
|
+
const DEFAULT_BASE_URL = "http://example.com";
|
|
474
|
+
function toRelativeUrl(e) {
|
|
475
|
+
return e.toString().substring(e.origin.length);
|
|
398
476
|
}
|
|
399
|
-
function
|
|
400
|
-
return !
|
|
477
|
+
function removePathPrefix(e, t) {
|
|
478
|
+
return !t || !e.startsWith(t) ? e : e.substring(t.length);
|
|
401
479
|
}
|
|
402
|
-
function
|
|
403
|
-
return !
|
|
480
|
+
function ensurePathPrefix(e, t) {
|
|
481
|
+
return !t || e.startsWith(t) ? e : t + e;
|
|
404
482
|
}
|
|
405
|
-
var
|
|
406
|
-
class
|
|
483
|
+
var P, T, L, R, k, y, H, C, N, Z, U, X, O, ee;
|
|
484
|
+
class PHPRequestHandler {
|
|
407
485
|
/**
|
|
408
486
|
* @param php - The PHP instance.
|
|
409
487
|
* @param config - Request Handler configuration.
|
|
410
488
|
*/
|
|
411
|
-
constructor(
|
|
489
|
+
constructor(t, r = {}) {
|
|
412
490
|
/**
|
|
413
491
|
* Serves a static file from the PHP filesystem.
|
|
414
492
|
*
|
|
415
493
|
* @param fsPath - Absolute path of the static file to serve.
|
|
416
494
|
* @returns The response.
|
|
417
495
|
*/
|
|
418
|
-
|
|
496
|
+
u(this, N);
|
|
419
497
|
/**
|
|
420
498
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
421
499
|
* superglobals populated.
|
|
@@ -423,7 +501,7 @@ class vt {
|
|
|
423
501
|
* @param request - The request.
|
|
424
502
|
* @returns The response.
|
|
425
503
|
*/
|
|
426
|
-
|
|
504
|
+
u(this, U);
|
|
427
505
|
/**
|
|
428
506
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
429
507
|
*
|
|
@@ -433,68 +511,68 @@ class vt {
|
|
|
433
511
|
* @throws {Error} If the requested path doesn't exist.
|
|
434
512
|
* @returns The resolved filesystem path.
|
|
435
513
|
*/
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
514
|
+
u(this, O);
|
|
515
|
+
u(this, P, void 0);
|
|
516
|
+
u(this, T, void 0);
|
|
517
|
+
u(this, L, void 0);
|
|
518
|
+
u(this, R, void 0);
|
|
519
|
+
u(this, k, void 0);
|
|
520
|
+
u(this, y, void 0);
|
|
521
|
+
u(this, H, void 0);
|
|
522
|
+
u(this, C, void 0);
|
|
523
|
+
p(this, C, new Semaphore({ concurrency: 1 }));
|
|
446
524
|
const {
|
|
447
|
-
documentRoot:
|
|
448
|
-
absoluteUrl:
|
|
525
|
+
documentRoot: s = "/www/",
|
|
526
|
+
absoluteUrl: i = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
449
527
|
} = r;
|
|
450
|
-
this.php =
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
].join("")),
|
|
458
|
-
`${
|
|
459
|
-
|
|
460
|
-
|
|
528
|
+
this.php = t, p(this, P, s);
|
|
529
|
+
const n = new URL(i);
|
|
530
|
+
p(this, L, n.hostname), p(this, R, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), p(this, T, (n.protocol || "").replace(":", ""));
|
|
531
|
+
const o = l(this, R) !== 443 && l(this, R) !== 80;
|
|
532
|
+
p(this, k, [
|
|
533
|
+
l(this, L),
|
|
534
|
+
o ? `:${l(this, R)}` : ""
|
|
535
|
+
].join("")), p(this, y, n.pathname.replace(/\/+$/, "")), p(this, H, [
|
|
536
|
+
`${l(this, T)}://`,
|
|
537
|
+
l(this, k),
|
|
538
|
+
l(this, y)
|
|
461
539
|
].join(""));
|
|
462
540
|
}
|
|
463
541
|
/** @inheritDoc */
|
|
464
|
-
pathToInternalUrl(
|
|
465
|
-
return `${this.absoluteUrl}${
|
|
542
|
+
pathToInternalUrl(t) {
|
|
543
|
+
return `${this.absoluteUrl}${t}`;
|
|
466
544
|
}
|
|
467
545
|
/** @inheritDoc */
|
|
468
|
-
internalUrlToPath(
|
|
469
|
-
const r = new URL(
|
|
470
|
-
return r.pathname.startsWith(
|
|
546
|
+
internalUrlToPath(t) {
|
|
547
|
+
const r = new URL(t);
|
|
548
|
+
return r.pathname.startsWith(l(this, y)) && (r.pathname = r.pathname.slice(l(this, y).length)), toRelativeUrl(r);
|
|
471
549
|
}
|
|
472
550
|
get isRequestRunning() {
|
|
473
|
-
return
|
|
551
|
+
return l(this, C).running > 0;
|
|
474
552
|
}
|
|
475
553
|
/** @inheritDoc */
|
|
476
554
|
get absoluteUrl() {
|
|
477
|
-
return
|
|
555
|
+
return l(this, H);
|
|
478
556
|
}
|
|
479
557
|
/** @inheritDoc */
|
|
480
558
|
get documentRoot() {
|
|
481
|
-
return
|
|
559
|
+
return l(this, P);
|
|
482
560
|
}
|
|
483
561
|
/** @inheritDoc */
|
|
484
|
-
async request(
|
|
485
|
-
const r =
|
|
486
|
-
|
|
487
|
-
r ? void 0 :
|
|
488
|
-
),
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
),
|
|
492
|
-
return
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
if (!this.php.fileExists(
|
|
497
|
-
return new
|
|
562
|
+
async request(t) {
|
|
563
|
+
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
564
|
+
t.url,
|
|
565
|
+
r ? void 0 : DEFAULT_BASE_URL
|
|
566
|
+
), i = removePathPrefix(
|
|
567
|
+
s.pathname,
|
|
568
|
+
l(this, y)
|
|
569
|
+
), n = `${l(this, P)}${i}`;
|
|
570
|
+
return seemsLikeAPHPRequestHandlerPath(n) ? await _(this, U, X).call(this, t, s) : _(this, N, Z).call(this, n);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
P = new WeakMap(), T = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), H = new WeakMap(), C = new WeakMap(), N = new WeakSet(), Z = function(t) {
|
|
574
|
+
if (!this.php.fileExists(t))
|
|
575
|
+
return new PHPResponse(
|
|
498
576
|
404,
|
|
499
577
|
// Let the service worker know that no static file was found
|
|
500
578
|
// and that it's okay to issue a real fetch() to the server.
|
|
@@ -503,104 +581,110 @@ E = new WeakMap(), N = new WeakMap(), z = new WeakMap(), F = new WeakMap(), U =
|
|
|
503
581
|
},
|
|
504
582
|
new TextEncoder().encode("404 File not found")
|
|
505
583
|
);
|
|
506
|
-
const r = this.php.readFileAsBuffer(
|
|
507
|
-
return new
|
|
584
|
+
const r = this.php.readFileAsBuffer(t);
|
|
585
|
+
return new PHPResponse(
|
|
508
586
|
200,
|
|
509
587
|
{
|
|
510
588
|
"content-length": [`${r.byteLength}`],
|
|
511
589
|
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
512
590
|
// The code below won't return the correct mime-type if the extension
|
|
513
591
|
// was tampered with.
|
|
514
|
-
"content-type": [
|
|
592
|
+
"content-type": [inferMimeType(t)],
|
|
515
593
|
"accept-ranges": ["bytes"],
|
|
516
594
|
"cache-control": ["public, max-age=0"]
|
|
517
595
|
},
|
|
518
596
|
r
|
|
519
597
|
);
|
|
520
|
-
},
|
|
521
|
-
var
|
|
522
|
-
const
|
|
598
|
+
}, U = new WeakSet(), X = async function(t, r) {
|
|
599
|
+
var i, n;
|
|
600
|
+
const s = await l(this, C).acquire();
|
|
523
601
|
try {
|
|
524
|
-
this.php.addServerGlobalEntry("DOCUMENT_ROOT",
|
|
602
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, P)), this.php.addServerGlobalEntry(
|
|
525
603
|
"HTTPS",
|
|
526
|
-
|
|
604
|
+
l(this, H).startsWith("https://") ? "on" : ""
|
|
527
605
|
);
|
|
528
606
|
let o = "GET";
|
|
529
|
-
const
|
|
530
|
-
host:
|
|
531
|
-
...
|
|
532
|
-
},
|
|
533
|
-
if (
|
|
607
|
+
const a = {
|
|
608
|
+
host: l(this, k),
|
|
609
|
+
...normalizeHeaders(t.headers || {})
|
|
610
|
+
}, d = [];
|
|
611
|
+
if (t.files && Object.keys(t.files).length) {
|
|
534
612
|
o = "POST";
|
|
535
|
-
for (const
|
|
536
|
-
const m =
|
|
537
|
-
|
|
538
|
-
key:
|
|
613
|
+
for (const f in t.files) {
|
|
614
|
+
const m = t.files[f];
|
|
615
|
+
d.push({
|
|
616
|
+
key: f,
|
|
539
617
|
name: m.name,
|
|
540
618
|
type: m.type,
|
|
541
619
|
data: new Uint8Array(await m.arrayBuffer())
|
|
542
620
|
});
|
|
543
621
|
}
|
|
544
|
-
(
|
|
545
|
-
|
|
546
|
-
),
|
|
622
|
+
(i = a["content-type"]) != null && i.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
|
|
623
|
+
t.body || ""
|
|
624
|
+
), a["content-type"] = "application/x-www-form-urlencoded", delete t.body);
|
|
547
625
|
}
|
|
548
|
-
let
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
).toString()) :
|
|
552
|
-
let
|
|
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
|
+
let h;
|
|
553
631
|
try {
|
|
554
|
-
|
|
632
|
+
let f = r.pathname;
|
|
633
|
+
if ((n = t.headers) != null && n["x-rewrite-url"])
|
|
634
|
+
try {
|
|
635
|
+
f = new URL(
|
|
636
|
+
t.headers["x-rewrite-url"]
|
|
637
|
+
).pathname;
|
|
638
|
+
} catch {
|
|
639
|
+
}
|
|
640
|
+
h = _(this, O, ee).call(this, f);
|
|
555
641
|
} catch {
|
|
556
|
-
return new
|
|
642
|
+
return new PHPResponse(
|
|
557
643
|
404,
|
|
558
644
|
{},
|
|
559
645
|
new TextEncoder().encode("404 File not found")
|
|
560
646
|
);
|
|
561
647
|
}
|
|
562
648
|
return await this.php.run({
|
|
563
|
-
relativeUri:
|
|
564
|
-
|
|
565
|
-
|
|
649
|
+
relativeUri: ensurePathPrefix(
|
|
650
|
+
toRelativeUrl(r),
|
|
651
|
+
l(this, y)
|
|
566
652
|
),
|
|
567
|
-
protocol:
|
|
568
|
-
method:
|
|
569
|
-
body:
|
|
570
|
-
fileInfos:
|
|
571
|
-
scriptPath:
|
|
572
|
-
headers:
|
|
653
|
+
protocol: l(this, T),
|
|
654
|
+
method: t.method || o,
|
|
655
|
+
body: c,
|
|
656
|
+
fileInfos: d,
|
|
657
|
+
scriptPath: h,
|
|
658
|
+
headers: a
|
|
573
659
|
});
|
|
574
660
|
} finally {
|
|
575
|
-
|
|
661
|
+
s();
|
|
576
662
|
}
|
|
577
|
-
},
|
|
578
|
-
let r =
|
|
663
|
+
}, O = new WeakSet(), ee = function(t) {
|
|
664
|
+
let r = removePathPrefix(t, l(this, y));
|
|
579
665
|
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
|
|
580
|
-
const
|
|
581
|
-
if (this.php.fileExists(
|
|
582
|
-
return
|
|
583
|
-
|
|
584
|
-
throw new Error(`File not found: ${n}`);
|
|
585
|
-
return `${c(this, E)}/index.php`;
|
|
666
|
+
const s = `${l(this, P)}${r}`;
|
|
667
|
+
if (this.php.fileExists(s))
|
|
668
|
+
return s;
|
|
669
|
+
throw new Error(`File not found: ${s}`);
|
|
586
670
|
};
|
|
587
|
-
function
|
|
588
|
-
const
|
|
671
|
+
function parseMultipartFormDataString(e) {
|
|
672
|
+
const t = {}, r = e.match(/--(.*)\r\n/);
|
|
589
673
|
if (!r)
|
|
590
|
-
return
|
|
591
|
-
const
|
|
592
|
-
return
|
|
593
|
-
const
|
|
674
|
+
return t;
|
|
675
|
+
const s = r[1], i = e.split(`--${s}`);
|
|
676
|
+
return i.shift(), i.pop(), i.forEach((n) => {
|
|
677
|
+
const o = n.indexOf(`\r
|
|
594
678
|
\r
|
|
595
|
-
`), a =
|
|
596
|
-
if (
|
|
597
|
-
const h =
|
|
598
|
-
|
|
679
|
+
`), a = n.substring(0, o).trim(), d = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
|
|
680
|
+
if (c) {
|
|
681
|
+
const h = c[1];
|
|
682
|
+
t[h] = d;
|
|
599
683
|
}
|
|
600
|
-
}),
|
|
684
|
+
}), t;
|
|
601
685
|
}
|
|
602
|
-
function
|
|
603
|
-
switch (
|
|
686
|
+
function inferMimeType(e) {
|
|
687
|
+
switch (e.split(".").pop()) {
|
|
604
688
|
case "css":
|
|
605
689
|
return "text/css";
|
|
606
690
|
case "js":
|
|
@@ -639,16 +723,16 @@ function xt(t) {
|
|
|
639
723
|
return "application-octet-stream";
|
|
640
724
|
}
|
|
641
725
|
}
|
|
642
|
-
function
|
|
643
|
-
return
|
|
726
|
+
function seemsLikeAPHPRequestHandlerPath(e) {
|
|
727
|
+
return seemsLikeAPHPFile(e) || seemsLikeADirectoryRoot(e);
|
|
644
728
|
}
|
|
645
|
-
function
|
|
646
|
-
return
|
|
729
|
+
function seemsLikeAPHPFile(e) {
|
|
730
|
+
return e.endsWith(".php") || e.includes(".php/");
|
|
647
731
|
}
|
|
648
|
-
function
|
|
649
|
-
return !
|
|
732
|
+
function seemsLikeADirectoryRoot(e) {
|
|
733
|
+
return !e.split("/").pop().includes(".");
|
|
650
734
|
}
|
|
651
|
-
const
|
|
735
|
+
const FileErrorCodes = {
|
|
652
736
|
0: "No error occurred. System call completed successfully.",
|
|
653
737
|
1: "Argument list too long.",
|
|
654
738
|
2: "Permission denied.",
|
|
@@ -727,22 +811,22 @@ const J = {
|
|
|
727
811
|
75: "Cross-device link.",
|
|
728
812
|
76: "Extension: Capabilities insufficient."
|
|
729
813
|
};
|
|
730
|
-
function
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
return
|
|
734
|
-
}
|
|
735
|
-
function
|
|
736
|
-
return function(r,
|
|
737
|
-
const
|
|
738
|
-
|
|
814
|
+
function getEmscriptenFsError(e) {
|
|
815
|
+
const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
|
|
816
|
+
if (t in FileErrorCodes)
|
|
817
|
+
return FileErrorCodes[t];
|
|
818
|
+
}
|
|
819
|
+
function rethrowFileSystemError(e = "") {
|
|
820
|
+
return function(r, s, i) {
|
|
821
|
+
const n = i.value;
|
|
822
|
+
i.value = function(...o) {
|
|
739
823
|
try {
|
|
740
|
-
return
|
|
824
|
+
return n.apply(this, o);
|
|
741
825
|
} catch (a) {
|
|
742
|
-
const
|
|
743
|
-
if (
|
|
744
|
-
const
|
|
745
|
-
throw new Error(`${
|
|
826
|
+
const d = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
827
|
+
if (d in FileErrorCodes) {
|
|
828
|
+
const c = FileErrorCodes[d], h = typeof o[0] == "string" ? o[0] : null, f = h !== null ? e.replaceAll("{path}", h) : e;
|
|
829
|
+
throw new Error(`${f}: ${c}`, {
|
|
746
830
|
cause: a
|
|
747
831
|
});
|
|
748
832
|
}
|
|
@@ -751,56 +835,50 @@ function R(t = "") {
|
|
|
751
835
|
};
|
|
752
836
|
};
|
|
753
837
|
}
|
|
754
|
-
const
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
838
|
+
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
839
|
+
let lastRuntimeId = 0;
|
|
840
|
+
async function loadPHPRuntime(e, t = {}) {
|
|
841
|
+
const [r, s, i] = makePromise(), n = e.init(currentJsRuntime, {
|
|
842
|
+
onAbort(a) {
|
|
843
|
+
i(a), console.error(a);
|
|
759
844
|
},
|
|
760
845
|
ENV: {},
|
|
761
846
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
762
847
|
// breaks vite dev mode. An identity `locateFile` function
|
|
763
848
|
// fixes it.
|
|
764
|
-
locateFile: (
|
|
765
|
-
...
|
|
849
|
+
locateFile: (a) => a,
|
|
850
|
+
...t,
|
|
766
851
|
noInitialRun: !0,
|
|
767
852
|
onRuntimeInitialized() {
|
|
768
|
-
|
|
769
|
-
},
|
|
770
|
-
monitorRunDependencies(h) {
|
|
771
|
-
h === 0 && (delete u.monitorRunDependencies, a());
|
|
853
|
+
t.onRuntimeInitialized && t.onRuntimeInitialized(), s();
|
|
772
854
|
}
|
|
773
855
|
});
|
|
774
|
-
await
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
)
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
return
|
|
786
|
-
}
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
return typeof process < "u" && ((t = process.release) == null ? void 0 : t.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
790
|
-
}(), He = () => {
|
|
791
|
-
const t = [], e = new Promise((r, n) => {
|
|
792
|
-
t.push(r, n);
|
|
856
|
+
await r;
|
|
857
|
+
const o = ++lastRuntimeId;
|
|
858
|
+
return n.id = o, n.originalExit = n._exit, n._exit = function(a) {
|
|
859
|
+
return loadedRuntimes.delete(o), n.originalExit(a);
|
|
860
|
+
}, n[RuntimeId] = o, loadedRuntimes.set(o, n), o;
|
|
861
|
+
}
|
|
862
|
+
function getLoadedRuntime(e) {
|
|
863
|
+
return loadedRuntimes.get(e);
|
|
864
|
+
}
|
|
865
|
+
const currentJsRuntime = function() {
|
|
866
|
+
var e;
|
|
867
|
+
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
868
|
+
}(), makePromise = () => {
|
|
869
|
+
const e = [], t = new Promise((r, s) => {
|
|
870
|
+
e.push(r, s);
|
|
793
871
|
});
|
|
794
|
-
return
|
|
872
|
+
return e.unshift(t), e;
|
|
795
873
|
};
|
|
796
|
-
var
|
|
797
|
-
for (var
|
|
798
|
-
(
|
|
799
|
-
return
|
|
874
|
+
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
875
|
+
for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, n = e.length - 1, o; n >= 0; n--)
|
|
876
|
+
(o = e[n]) && (i = (s ? o(t, r, i) : o(i)) || i);
|
|
877
|
+
return s && i && __defProp(t, r, i), i;
|
|
800
878
|
};
|
|
801
|
-
const
|
|
802
|
-
var
|
|
803
|
-
class
|
|
879
|
+
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
880
|
+
var S, F, M, g, E, v, w, I, B, te, W, re, z, se, D, ne, q, ie, $, oe, j, ae, G, le, V, ce, Y, ue, J, de, K, he;
|
|
881
|
+
class BasePHP {
|
|
804
882
|
/**
|
|
805
883
|
* Initializes a PHP runtime.
|
|
806
884
|
*
|
|
@@ -808,16 +886,16 @@ class P {
|
|
|
808
886
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
809
887
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
810
888
|
*/
|
|
811
|
-
constructor(e,
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
889
|
+
constructor(e, t) {
|
|
890
|
+
u(this, B);
|
|
891
|
+
u(this, W);
|
|
892
|
+
u(this, z);
|
|
893
|
+
u(this, D);
|
|
894
|
+
u(this, q);
|
|
895
|
+
u(this, $);
|
|
896
|
+
u(this, j);
|
|
897
|
+
u(this, G);
|
|
898
|
+
u(this, V);
|
|
821
899
|
/**
|
|
822
900
|
* Adds file information to $_FILES superglobal in PHP.
|
|
823
901
|
*
|
|
@@ -827,40 +905,41 @@ class P {
|
|
|
827
905
|
*
|
|
828
906
|
* @param fileInfo - File details
|
|
829
907
|
*/
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
908
|
+
u(this, Y);
|
|
909
|
+
u(this, J);
|
|
910
|
+
u(this, K);
|
|
911
|
+
u(this, S, void 0);
|
|
912
|
+
u(this, F, void 0);
|
|
913
|
+
u(this, M, void 0);
|
|
914
|
+
u(this, g, void 0);
|
|
915
|
+
u(this, E, void 0);
|
|
916
|
+
u(this, v, void 0);
|
|
917
|
+
u(this, w, void 0);
|
|
918
|
+
u(this, I, void 0);
|
|
919
|
+
p(this, S, []), p(this, g, !1), p(this, E, null), p(this, v, {}), p(this, w, /* @__PURE__ */ new Map()), p(this, I, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
920
|
+
new PHPRequestHandler(this, t)
|
|
842
921
|
));
|
|
843
922
|
}
|
|
844
|
-
addEventListener(e,
|
|
845
|
-
|
|
923
|
+
addEventListener(e, t) {
|
|
924
|
+
l(this, w).has(e) || l(this, w).set(e, /* @__PURE__ */ new Set()), l(this, w).get(e).add(t);
|
|
846
925
|
}
|
|
847
|
-
removeEventListener(e,
|
|
848
|
-
var
|
|
849
|
-
(
|
|
926
|
+
removeEventListener(e, t) {
|
|
927
|
+
var r;
|
|
928
|
+
(r = l(this, w).get(e)) == null || r.delete(t);
|
|
850
929
|
}
|
|
851
930
|
dispatchEvent(e) {
|
|
852
|
-
const
|
|
853
|
-
if (
|
|
854
|
-
for (const
|
|
855
|
-
|
|
931
|
+
const t = l(this, w).get(e.type);
|
|
932
|
+
if (t)
|
|
933
|
+
for (const r of t)
|
|
934
|
+
r(e);
|
|
856
935
|
}
|
|
857
936
|
/** @inheritDoc */
|
|
858
937
|
async onMessage(e) {
|
|
859
|
-
|
|
938
|
+
l(this, I).push(e);
|
|
860
939
|
}
|
|
861
940
|
/** @inheritDoc */
|
|
862
|
-
async setSpawnHandler(
|
|
863
|
-
this[
|
|
941
|
+
async setSpawnHandler(handler) {
|
|
942
|
+
typeof handler == "string" && (handler = createSpawnHandler(eval(handler))), this[__private__dont__use].spawnProcess = handler;
|
|
864
943
|
}
|
|
865
944
|
/** @inheritDoc */
|
|
866
945
|
get absoluteUrl() {
|
|
@@ -881,25 +960,40 @@ class P {
|
|
|
881
960
|
);
|
|
882
961
|
}
|
|
883
962
|
initializeRuntime(e) {
|
|
884
|
-
if (this[
|
|
963
|
+
if (this[__private__dont__use])
|
|
885
964
|
throw new Error("PHP runtime already initialized.");
|
|
886
|
-
const
|
|
887
|
-
if (!
|
|
965
|
+
const t = getLoadedRuntime(e);
|
|
966
|
+
if (!t)
|
|
888
967
|
throw new Error("Invalid PHP runtime id.");
|
|
889
|
-
this[
|
|
890
|
-
for (const s of
|
|
891
|
-
const
|
|
892
|
-
if (
|
|
893
|
-
return
|
|
968
|
+
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
969
|
+
for (const s of l(this, I)) {
|
|
970
|
+
const i = await s(r);
|
|
971
|
+
if (i)
|
|
972
|
+
return i;
|
|
894
973
|
}
|
|
895
974
|
return "";
|
|
896
|
-
},
|
|
975
|
+
}, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
976
|
+
type: "runtime.initialized"
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
/** @inheritDoc */
|
|
980
|
+
async setSapiName(e) {
|
|
981
|
+
if (this[__private__dont__use].ccall(
|
|
982
|
+
"wasm_set_sapi_name",
|
|
983
|
+
NUMBER,
|
|
984
|
+
[STRING],
|
|
985
|
+
[e]
|
|
986
|
+
) !== 0)
|
|
987
|
+
throw new Error(
|
|
988
|
+
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
989
|
+
);
|
|
990
|
+
p(this, M, e);
|
|
897
991
|
}
|
|
898
992
|
/** @inheritDoc */
|
|
899
993
|
setPhpIniPath(e) {
|
|
900
|
-
if (
|
|
994
|
+
if (l(this, g))
|
|
901
995
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
902
|
-
this[
|
|
996
|
+
p(this, F, e), this[__private__dont__use].ccall(
|
|
903
997
|
"wasm_set_phpini_path",
|
|
904
998
|
null,
|
|
905
999
|
["string"],
|
|
@@ -907,44 +1001,62 @@ class P {
|
|
|
907
1001
|
);
|
|
908
1002
|
}
|
|
909
1003
|
/** @inheritDoc */
|
|
910
|
-
setPhpIniEntry(e,
|
|
911
|
-
if (
|
|
1004
|
+
setPhpIniEntry(e, t) {
|
|
1005
|
+
if (l(this, g))
|
|
912
1006
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
913
|
-
|
|
1007
|
+
l(this, S).push([e, t]);
|
|
914
1008
|
}
|
|
915
1009
|
/** @inheritDoc */
|
|
916
1010
|
chdir(e) {
|
|
917
|
-
this[
|
|
1011
|
+
this[__private__dont__use].FS.chdir(e);
|
|
918
1012
|
}
|
|
919
1013
|
/** @inheritDoc */
|
|
920
|
-
async request(e,
|
|
1014
|
+
async request(e, t) {
|
|
921
1015
|
if (!this.requestHandler)
|
|
922
1016
|
throw new Error("No request handler available.");
|
|
923
|
-
return this.requestHandler.request(e,
|
|
1017
|
+
return this.requestHandler.request(e, t);
|
|
924
1018
|
}
|
|
925
1019
|
/** @inheritDoc */
|
|
926
1020
|
async run(e) {
|
|
927
|
-
const
|
|
1021
|
+
const t = await this.semaphore.acquire();
|
|
1022
|
+
let r;
|
|
928
1023
|
try {
|
|
929
|
-
|
|
930
|
-
const
|
|
931
|
-
if (
|
|
1024
|
+
l(this, g) || (_(this, B, te).call(this), p(this, g, !0)), _(this, G, le).call(this, e.scriptPath || ""), _(this, z, se).call(this, e.relativeUri || ""), _(this, q, ie).call(this, e.method || "GET");
|
|
1025
|
+
const s = normalizeHeaders(e.headers || {}), i = s.host || "example.com:443";
|
|
1026
|
+
if (_(this, D, ne).call(this, i, e.protocol || "http"), _(this, $, oe).call(this, s), e.body && (r = _(this, j, ae).call(this, e.body)), e.fileInfos)
|
|
932
1027
|
for (const o of e.fileInfos)
|
|
933
|
-
|
|
934
|
-
|
|
1028
|
+
_(this, Y, ue).call(this, o);
|
|
1029
|
+
typeof e.code == "string" && _(this, J, de).call(this, " ?>" + e.code), _(this, V, ce).call(this);
|
|
1030
|
+
const n = await _(this, K, he).call(this);
|
|
1031
|
+
if (e.throwOnError && n.exitCode !== 0) {
|
|
1032
|
+
const o = {
|
|
1033
|
+
stdout: n.text,
|
|
1034
|
+
stderr: n.errors
|
|
1035
|
+
};
|
|
1036
|
+
console.warn("PHP.run() output was:", o);
|
|
1037
|
+
const a = new Error(
|
|
1038
|
+
`PHP.run() failed with exit code ${n.exitCode} and the following output`
|
|
1039
|
+
);
|
|
1040
|
+
throw a.output = o, a;
|
|
1041
|
+
}
|
|
1042
|
+
return n;
|
|
935
1043
|
} finally {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
}
|
|
1044
|
+
try {
|
|
1045
|
+
r && this[__private__dont__use].free(r);
|
|
1046
|
+
} finally {
|
|
1047
|
+
t(), this.dispatchEvent({
|
|
1048
|
+
type: "request.end"
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
939
1051
|
}
|
|
940
1052
|
}
|
|
941
|
-
addServerGlobalEntry(e,
|
|
942
|
-
|
|
1053
|
+
addServerGlobalEntry(e, t) {
|
|
1054
|
+
l(this, v)[e] = t;
|
|
943
1055
|
}
|
|
944
|
-
defineConstant(e,
|
|
945
|
-
let
|
|
1056
|
+
defineConstant(e, t) {
|
|
1057
|
+
let r = {};
|
|
946
1058
|
try {
|
|
947
|
-
|
|
1059
|
+
r = JSON.parse(
|
|
948
1060
|
this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
|
|
949
1061
|
);
|
|
950
1062
|
} catch {
|
|
@@ -952,13 +1064,13 @@ class P {
|
|
|
952
1064
|
this.writeFile(
|
|
953
1065
|
"/tmp/consts.json",
|
|
954
1066
|
JSON.stringify({
|
|
955
|
-
...
|
|
956
|
-
[e]:
|
|
1067
|
+
...r,
|
|
1068
|
+
[e]: t
|
|
957
1069
|
})
|
|
958
1070
|
);
|
|
959
1071
|
}
|
|
960
1072
|
mkdir(e) {
|
|
961
|
-
this[
|
|
1073
|
+
this[__private__dont__use].FS.mkdirTree(e);
|
|
962
1074
|
}
|
|
963
1075
|
mkdirTree(e) {
|
|
964
1076
|
this.mkdir(e);
|
|
@@ -967,67 +1079,91 @@ class P {
|
|
|
967
1079
|
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
968
1080
|
}
|
|
969
1081
|
readFileAsBuffer(e) {
|
|
970
|
-
return this[
|
|
1082
|
+
return this[__private__dont__use].FS.readFile(e);
|
|
971
1083
|
}
|
|
972
|
-
writeFile(e,
|
|
973
|
-
this[
|
|
1084
|
+
writeFile(e, t) {
|
|
1085
|
+
this[__private__dont__use].FS.writeFile(e, t);
|
|
974
1086
|
}
|
|
975
1087
|
unlink(e) {
|
|
976
|
-
this[
|
|
1088
|
+
this[__private__dont__use].FS.unlink(e);
|
|
977
1089
|
}
|
|
978
1090
|
/** @inheritDoc */
|
|
979
|
-
mv(e,
|
|
1091
|
+
mv(e, t) {
|
|
980
1092
|
try {
|
|
981
|
-
this[
|
|
982
|
-
} catch (
|
|
983
|
-
const s =
|
|
1093
|
+
this[__private__dont__use].FS.rename(e, t);
|
|
1094
|
+
} catch (r) {
|
|
1095
|
+
const s = getEmscriptenFsError(r);
|
|
984
1096
|
throw s ? new Error(
|
|
985
|
-
`Could not move ${e} to ${
|
|
1097
|
+
`Could not move ${e} to ${t}: ${s}`,
|
|
986
1098
|
{
|
|
987
|
-
cause:
|
|
1099
|
+
cause: r
|
|
988
1100
|
}
|
|
989
|
-
) :
|
|
1101
|
+
) : r;
|
|
990
1102
|
}
|
|
991
1103
|
}
|
|
992
|
-
rmdir(e,
|
|
993
|
-
|
|
994
|
-
const s = `${e}/${
|
|
995
|
-
this.isDir(s) ? this.rmdir(s,
|
|
996
|
-
}), this[
|
|
1104
|
+
rmdir(e, t = { recursive: !0 }) {
|
|
1105
|
+
t != null && t.recursive && this.listFiles(e).forEach((r) => {
|
|
1106
|
+
const s = `${e}/${r}`;
|
|
1107
|
+
this.isDir(s) ? this.rmdir(s, t) : this.unlink(s);
|
|
1108
|
+
}), this[__private__dont__use].FS.rmdir(e);
|
|
997
1109
|
}
|
|
998
|
-
listFiles(e,
|
|
1110
|
+
listFiles(e, t = { prependPath: !1 }) {
|
|
999
1111
|
if (!this.fileExists(e))
|
|
1000
1112
|
return [];
|
|
1001
1113
|
try {
|
|
1002
|
-
const
|
|
1114
|
+
const r = this[__private__dont__use].FS.readdir(e).filter(
|
|
1003
1115
|
(s) => s !== "." && s !== ".."
|
|
1004
1116
|
);
|
|
1005
|
-
if (
|
|
1117
|
+
if (t.prependPath) {
|
|
1006
1118
|
const s = e.replace(/\/$/, "");
|
|
1007
|
-
return
|
|
1119
|
+
return r.map((i) => `${s}/${i}`);
|
|
1008
1120
|
}
|
|
1009
|
-
return
|
|
1010
|
-
} catch (
|
|
1011
|
-
return console.error(
|
|
1121
|
+
return r;
|
|
1122
|
+
} catch (r) {
|
|
1123
|
+
return console.error(r, { path: e }), [];
|
|
1012
1124
|
}
|
|
1013
1125
|
}
|
|
1014
1126
|
isDir(e) {
|
|
1015
|
-
return this.fileExists(e) ? this[
|
|
1016
|
-
this[
|
|
1127
|
+
return this.fileExists(e) ? this[__private__dont__use].FS.isDir(
|
|
1128
|
+
this[__private__dont__use].FS.lookupPath(e).node.mode
|
|
1017
1129
|
) : !1;
|
|
1018
1130
|
}
|
|
1019
1131
|
fileExists(e) {
|
|
1020
1132
|
try {
|
|
1021
|
-
return this[
|
|
1133
|
+
return this[__private__dont__use].FS.lookupPath(e), !0;
|
|
1022
1134
|
} catch {
|
|
1023
1135
|
return !1;
|
|
1024
1136
|
}
|
|
1025
1137
|
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Hot-swaps the PHP runtime for a new one without
|
|
1140
|
+
* interrupting the operations of this PHP instance.
|
|
1141
|
+
*
|
|
1142
|
+
* @param runtime
|
|
1143
|
+
*/
|
|
1144
|
+
hotSwapPHPRuntime(e) {
|
|
1145
|
+
const t = this[__private__dont__use].FS;
|
|
1146
|
+
try {
|
|
1147
|
+
this.exit();
|
|
1148
|
+
} catch {
|
|
1149
|
+
}
|
|
1150
|
+
if (this.initializeRuntime(e), l(this, F) && this.setPhpIniPath(l(this, F)), l(this, M) && this.setSapiName(l(this, M)), this.requestHandler) {
|
|
1151
|
+
const r = this.documentRoot;
|
|
1152
|
+
recreateMemFS(this[__private__dont__use].FS, t, r);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1026
1155
|
exit(e = 0) {
|
|
1027
|
-
|
|
1156
|
+
this.dispatchEvent({
|
|
1157
|
+
type: "runtime.beforedestroy"
|
|
1158
|
+
});
|
|
1159
|
+
try {
|
|
1160
|
+
this[__private__dont__use]._exit(e);
|
|
1161
|
+
} catch {
|
|
1162
|
+
}
|
|
1163
|
+
p(this, g, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1028
1164
|
}
|
|
1029
1165
|
}
|
|
1030
|
-
|
|
1166
|
+
S = new WeakMap(), F = new WeakMap(), M = new WeakMap(), g = new WeakMap(), E = new WeakMap(), v = new WeakMap(), w = new WeakMap(), I = new WeakMap(), B = new WeakSet(), te = function() {
|
|
1031
1167
|
if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
|
|
1032
1168
|
"/tmp/consts.php",
|
|
1033
1169
|
`<?php
|
|
@@ -1039,553 +1175,583 @@ H = new WeakMap(), k = new WeakMap(), A = new WeakMap(), _ = new WeakMap(), S =
|
|
|
1039
1175
|
}
|
|
1040
1176
|
}
|
|
1041
1177
|
}`
|
|
1042
|
-
),
|
|
1043
|
-
const e =
|
|
1178
|
+
), l(this, S).length > 0) {
|
|
1179
|
+
const e = l(this, S).map(([t, r]) => `${t}=${r}`).join(`
|
|
1044
1180
|
`) + `
|
|
1045
1181
|
|
|
1046
1182
|
`;
|
|
1047
|
-
this[
|
|
1183
|
+
this[__private__dont__use].ccall(
|
|
1048
1184
|
"wasm_set_phpini_entries",
|
|
1049
1185
|
null,
|
|
1050
|
-
[
|
|
1186
|
+
[STRING],
|
|
1051
1187
|
[e]
|
|
1052
1188
|
);
|
|
1053
1189
|
}
|
|
1054
|
-
this[
|
|
1055
|
-
},
|
|
1190
|
+
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1191
|
+
}, W = new WeakSet(), re = function() {
|
|
1056
1192
|
const e = "/tmp/headers.json";
|
|
1057
1193
|
if (!this.fileExists(e))
|
|
1058
1194
|
throw new Error(
|
|
1059
1195
|
"SAPI Error: Could not find response headers file."
|
|
1060
1196
|
);
|
|
1061
|
-
const
|
|
1062
|
-
for (const s of
|
|
1197
|
+
const t = JSON.parse(this.readFileAsText(e)), r = {};
|
|
1198
|
+
for (const s of t.headers) {
|
|
1063
1199
|
if (!s.includes(": "))
|
|
1064
1200
|
continue;
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1201
|
+
const i = s.indexOf(": "), n = s.substring(0, i).toLowerCase(), o = s.substring(i + 2);
|
|
1202
|
+
n in r || (r[n] = []), r[n].push(o);
|
|
1067
1203
|
}
|
|
1068
1204
|
return {
|
|
1069
|
-
headers:
|
|
1070
|
-
httpStatusCode:
|
|
1205
|
+
headers: r,
|
|
1206
|
+
httpStatusCode: t.status
|
|
1071
1207
|
};
|
|
1072
|
-
},
|
|
1073
|
-
if (this[
|
|
1208
|
+
}, z = new WeakSet(), se = function(e) {
|
|
1209
|
+
if (this[__private__dont__use].ccall(
|
|
1074
1210
|
"wasm_set_request_uri",
|
|
1075
1211
|
null,
|
|
1076
|
-
[
|
|
1212
|
+
[STRING],
|
|
1077
1213
|
[e]
|
|
1078
1214
|
), e.includes("?")) {
|
|
1079
|
-
const
|
|
1080
|
-
this[
|
|
1215
|
+
const t = e.substring(e.indexOf("?") + 1);
|
|
1216
|
+
this[__private__dont__use].ccall(
|
|
1081
1217
|
"wasm_set_query_string",
|
|
1082
1218
|
null,
|
|
1083
|
-
[
|
|
1084
|
-
[
|
|
1219
|
+
[STRING],
|
|
1220
|
+
[t]
|
|
1085
1221
|
);
|
|
1086
1222
|
}
|
|
1087
|
-
},
|
|
1088
|
-
this[
|
|
1223
|
+
}, D = new WeakSet(), ne = function(e, t) {
|
|
1224
|
+
this[__private__dont__use].ccall(
|
|
1089
1225
|
"wasm_set_request_host",
|
|
1090
1226
|
null,
|
|
1091
|
-
[
|
|
1227
|
+
[STRING],
|
|
1092
1228
|
[e]
|
|
1093
1229
|
);
|
|
1094
|
-
let
|
|
1230
|
+
let r;
|
|
1095
1231
|
try {
|
|
1096
|
-
|
|
1232
|
+
r = parseInt(new URL(e).port, 10);
|
|
1097
1233
|
} catch {
|
|
1098
1234
|
}
|
|
1099
|
-
(!
|
|
1235
|
+
(!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), this[__private__dont__use].ccall(
|
|
1100
1236
|
"wasm_set_request_port",
|
|
1101
1237
|
null,
|
|
1102
|
-
[
|
|
1103
|
-
[
|
|
1104
|
-
), (
|
|
1105
|
-
},
|
|
1106
|
-
this[
|
|
1238
|
+
[NUMBER],
|
|
1239
|
+
[r]
|
|
1240
|
+
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1241
|
+
}, q = new WeakSet(), ie = function(e) {
|
|
1242
|
+
this[__private__dont__use].ccall(
|
|
1107
1243
|
"wasm_set_request_method",
|
|
1108
1244
|
null,
|
|
1109
|
-
[
|
|
1245
|
+
[STRING],
|
|
1110
1246
|
[e]
|
|
1111
1247
|
);
|
|
1112
|
-
},
|
|
1113
|
-
e.cookie && this[
|
|
1248
|
+
}, $ = new WeakSet(), oe = function(e) {
|
|
1249
|
+
e.cookie && this[__private__dont__use].ccall(
|
|
1114
1250
|
"wasm_set_cookies",
|
|
1115
1251
|
null,
|
|
1116
|
-
[
|
|
1252
|
+
[STRING],
|
|
1117
1253
|
[e.cookie]
|
|
1118
|
-
), e["content-type"] && this[
|
|
1254
|
+
), e["content-type"] && this[__private__dont__use].ccall(
|
|
1119
1255
|
"wasm_set_content_type",
|
|
1120
1256
|
null,
|
|
1121
|
-
[
|
|
1257
|
+
[STRING],
|
|
1122
1258
|
[e["content-type"]]
|
|
1123
|
-
), e["content-length"] && this[
|
|
1259
|
+
), e["content-length"] && this[__private__dont__use].ccall(
|
|
1124
1260
|
"wasm_set_content_length",
|
|
1125
1261
|
null,
|
|
1126
|
-
[
|
|
1262
|
+
[NUMBER],
|
|
1127
1263
|
[parseInt(e["content-length"], 10)]
|
|
1128
1264
|
);
|
|
1129
|
-
for (const
|
|
1130
|
-
let
|
|
1131
|
-
["content-type", "content-length"].includes(
|
|
1132
|
-
`${
|
|
1133
|
-
e[
|
|
1265
|
+
for (const t in e) {
|
|
1266
|
+
let r = "HTTP_";
|
|
1267
|
+
["content-type", "content-length"].includes(t.toLowerCase()) && (r = ""), this.addServerGlobalEntry(
|
|
1268
|
+
`${r}${t.toUpperCase().replace(/-/g, "_")}`,
|
|
1269
|
+
e[t]
|
|
1134
1270
|
);
|
|
1135
1271
|
}
|
|
1136
|
-
},
|
|
1137
|
-
this[
|
|
1272
|
+
}, j = new WeakSet(), ae = function(e) {
|
|
1273
|
+
const t = this[__private__dont__use].lengthBytesUTF8(e), r = this[__private__dont__use].malloc(t + 1);
|
|
1274
|
+
if (!r)
|
|
1275
|
+
throw new Error("Could not allocate memory for the request body.");
|
|
1276
|
+
return this[__private__dont__use].stringToUTF8(
|
|
1277
|
+
e,
|
|
1278
|
+
r,
|
|
1279
|
+
t + 1
|
|
1280
|
+
), this[__private__dont__use].ccall(
|
|
1138
1281
|
"wasm_set_request_body",
|
|
1139
1282
|
null,
|
|
1140
|
-
[
|
|
1141
|
-
[
|
|
1142
|
-
), this[
|
|
1283
|
+
[NUMBER],
|
|
1284
|
+
[r]
|
|
1285
|
+
), this[__private__dont__use].ccall(
|
|
1143
1286
|
"wasm_set_content_length",
|
|
1144
1287
|
null,
|
|
1145
|
-
[
|
|
1288
|
+
[NUMBER],
|
|
1146
1289
|
[new TextEncoder().encode(e).length]
|
|
1147
|
-
);
|
|
1148
|
-
},
|
|
1149
|
-
this[
|
|
1290
|
+
), r;
|
|
1291
|
+
}, G = new WeakSet(), le = function(e) {
|
|
1292
|
+
this[__private__dont__use].ccall(
|
|
1150
1293
|
"wasm_set_path_translated",
|
|
1151
1294
|
null,
|
|
1152
|
-
[
|
|
1295
|
+
[STRING],
|
|
1153
1296
|
[e]
|
|
1154
1297
|
);
|
|
1155
|
-
},
|
|
1156
|
-
for (const e in
|
|
1157
|
-
this[
|
|
1298
|
+
}, V = new WeakSet(), ce = function() {
|
|
1299
|
+
for (const e in l(this, v))
|
|
1300
|
+
this[__private__dont__use].ccall(
|
|
1158
1301
|
"wasm_add_SERVER_entry",
|
|
1159
1302
|
null,
|
|
1160
|
-
[
|
|
1161
|
-
[e,
|
|
1303
|
+
[STRING, STRING],
|
|
1304
|
+
[e, l(this, v)[e]]
|
|
1162
1305
|
);
|
|
1163
|
-
},
|
|
1164
|
-
const { key:
|
|
1165
|
-
this.writeFile(
|
|
1166
|
-
const
|
|
1167
|
-
this[
|
|
1306
|
+
}, Y = new WeakSet(), ue = function(e) {
|
|
1307
|
+
const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
|
|
1308
|
+
this.writeFile(n, i);
|
|
1309
|
+
const o = 0;
|
|
1310
|
+
this[__private__dont__use].ccall(
|
|
1168
1311
|
"wasm_add_uploaded_file",
|
|
1169
1312
|
null,
|
|
1170
|
-
[
|
|
1171
|
-
[
|
|
1313
|
+
[STRING, STRING, STRING, STRING, NUMBER, NUMBER],
|
|
1314
|
+
[t, r, s, n, o, i.byteLength]
|
|
1172
1315
|
);
|
|
1173
|
-
},
|
|
1174
|
-
this[
|
|
1316
|
+
}, J = new WeakSet(), de = function(e) {
|
|
1317
|
+
this[__private__dont__use].ccall(
|
|
1175
1318
|
"wasm_set_php_code",
|
|
1176
1319
|
null,
|
|
1177
|
-
[
|
|
1320
|
+
[STRING],
|
|
1178
1321
|
[e]
|
|
1179
1322
|
);
|
|
1180
|
-
},
|
|
1181
|
-
var
|
|
1182
|
-
let e,
|
|
1323
|
+
}, K = new WeakSet(), he = async function() {
|
|
1324
|
+
var i;
|
|
1325
|
+
let e, t;
|
|
1183
1326
|
try {
|
|
1184
|
-
e = await new Promise((
|
|
1185
|
-
var
|
|
1186
|
-
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
}, (
|
|
1327
|
+
e = await new Promise((n, o) => {
|
|
1328
|
+
var d;
|
|
1329
|
+
t = (c) => {
|
|
1330
|
+
const h = new Error("Rethrown");
|
|
1331
|
+
h.cause = c.error, h.betterMessage = c.message, o(h);
|
|
1332
|
+
}, (d = l(this, E)) == null || d.addEventListener(
|
|
1190
1333
|
"error",
|
|
1191
|
-
|
|
1334
|
+
t
|
|
1192
1335
|
);
|
|
1193
|
-
const
|
|
1336
|
+
const a = this[__private__dont__use].ccall(
|
|
1194
1337
|
"wasm_sapi_handle_request",
|
|
1195
|
-
|
|
1338
|
+
NUMBER,
|
|
1196
1339
|
[],
|
|
1197
1340
|
[],
|
|
1198
1341
|
{ async: !0 }
|
|
1199
1342
|
);
|
|
1200
|
-
return
|
|
1343
|
+
return a instanceof Promise ? a.then(n, o) : n(a);
|
|
1201
1344
|
});
|
|
1202
|
-
} catch (
|
|
1203
|
-
for (const
|
|
1204
|
-
typeof this[
|
|
1345
|
+
} catch (n) {
|
|
1346
|
+
for (const c in this)
|
|
1347
|
+
typeof this[c] == "function" && (this[c] = () => {
|
|
1205
1348
|
throw new Error(
|
|
1206
1349
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1207
1350
|
);
|
|
1208
1351
|
});
|
|
1209
|
-
this.functionsMaybeMissingFromAsyncify =
|
|
1210
|
-
const
|
|
1211
|
-
throw
|
|
1352
|
+
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1353
|
+
const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, d = new Error(a);
|
|
1354
|
+
throw d.cause = o, d;
|
|
1212
1355
|
} finally {
|
|
1213
|
-
(
|
|
1356
|
+
(i = l(this, E)) == null || i.removeEventListener("error", t), p(this, v, {});
|
|
1214
1357
|
}
|
|
1215
|
-
const { headers:
|
|
1216
|
-
return new
|
|
1358
|
+
const { headers: r, httpStatusCode: s } = _(this, W, re).call(this);
|
|
1359
|
+
return new PHPResponse(
|
|
1217
1360
|
s,
|
|
1218
|
-
|
|
1361
|
+
r,
|
|
1219
1362
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
1220
1363
|
this.readFileAsText("/tmp/stderr"),
|
|
1221
1364
|
e
|
|
1222
1365
|
);
|
|
1223
1366
|
};
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
],
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
],
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
],
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
],
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
],
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
],
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
],
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
],
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
],
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
],
|
|
1254
|
-
function
|
|
1255
|
-
const
|
|
1256
|
-
for (const r in
|
|
1257
|
-
|
|
1258
|
-
return
|
|
1367
|
+
__decorateClass([
|
|
1368
|
+
rethrowFileSystemError('Could not create directory "{path}"')
|
|
1369
|
+
], BasePHP.prototype, "mkdir", 1);
|
|
1370
|
+
__decorateClass([
|
|
1371
|
+
rethrowFileSystemError('Could not create directory "{path}"')
|
|
1372
|
+
], BasePHP.prototype, "mkdirTree", 1);
|
|
1373
|
+
__decorateClass([
|
|
1374
|
+
rethrowFileSystemError('Could not read "{path}"')
|
|
1375
|
+
], BasePHP.prototype, "readFileAsText", 1);
|
|
1376
|
+
__decorateClass([
|
|
1377
|
+
rethrowFileSystemError('Could not read "{path}"')
|
|
1378
|
+
], BasePHP.prototype, "readFileAsBuffer", 1);
|
|
1379
|
+
__decorateClass([
|
|
1380
|
+
rethrowFileSystemError('Could not write to "{path}"')
|
|
1381
|
+
], BasePHP.prototype, "writeFile", 1);
|
|
1382
|
+
__decorateClass([
|
|
1383
|
+
rethrowFileSystemError('Could not unlink "{path}"')
|
|
1384
|
+
], BasePHP.prototype, "unlink", 1);
|
|
1385
|
+
__decorateClass([
|
|
1386
|
+
rethrowFileSystemError('Could not remove directory "{path}"')
|
|
1387
|
+
], BasePHP.prototype, "rmdir", 1);
|
|
1388
|
+
__decorateClass([
|
|
1389
|
+
rethrowFileSystemError('Could not list files in "{path}"')
|
|
1390
|
+
], BasePHP.prototype, "listFiles", 1);
|
|
1391
|
+
__decorateClass([
|
|
1392
|
+
rethrowFileSystemError('Could not stat "{path}"')
|
|
1393
|
+
], BasePHP.prototype, "isDir", 1);
|
|
1394
|
+
__decorateClass([
|
|
1395
|
+
rethrowFileSystemError('Could not stat "{path}"')
|
|
1396
|
+
], BasePHP.prototype, "fileExists", 1);
|
|
1397
|
+
function normalizeHeaders(e) {
|
|
1398
|
+
const t = {};
|
|
1399
|
+
for (const r in e)
|
|
1400
|
+
t[r.toLowerCase()] = e[r];
|
|
1401
|
+
return t;
|
|
1402
|
+
}
|
|
1403
|
+
function recreateMemFS(e, t, r) {
|
|
1404
|
+
let s;
|
|
1405
|
+
try {
|
|
1406
|
+
s = t.lookupPath(r);
|
|
1407
|
+
} catch {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
if (!("contents" in s.node))
|
|
1411
|
+
return;
|
|
1412
|
+
try {
|
|
1413
|
+
e = e.lookupPath(r);
|
|
1414
|
+
return;
|
|
1415
|
+
} catch {
|
|
1416
|
+
}
|
|
1417
|
+
if (!t.isDir(s.node.mode)) {
|
|
1418
|
+
e.writeFile(r, t.readFile(r));
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
e.mkdirTree(r);
|
|
1422
|
+
const i = t.readdir(r).filter((n) => n !== "." && n !== "..");
|
|
1423
|
+
for (const n of i)
|
|
1424
|
+
recreateMemFS(e, t, joinPaths(r, n));
|
|
1259
1425
|
}
|
|
1260
1426
|
/**
|
|
1261
1427
|
* @license
|
|
1262
1428
|
* Copyright 2019 Google LLC
|
|
1263
1429
|
* SPDX-License-Identifier: Apache-2.0
|
|
1264
1430
|
*/
|
|
1265
|
-
const
|
|
1266
|
-
canHandle: (
|
|
1267
|
-
serialize(
|
|
1268
|
-
const { port1:
|
|
1269
|
-
return
|
|
1431
|
+
const proxyMarker = Symbol("Comlink.proxy"), createEndpoint = Symbol("Comlink.endpoint"), releaseProxy = Symbol("Comlink.releaseProxy"), finalizer = Symbol("Comlink.finalizer"), throwMarker = Symbol("Comlink.thrown"), isObject = (e) => typeof e == "object" && e !== null || typeof e == "function", proxyTransferHandler = {
|
|
1432
|
+
canHandle: (e) => isObject(e) && e[proxyMarker],
|
|
1433
|
+
serialize(e) {
|
|
1434
|
+
const { port1: t, port2: r } = new MessageChannel();
|
|
1435
|
+
return expose(e, t), [r, [r]];
|
|
1270
1436
|
},
|
|
1271
|
-
deserialize(
|
|
1272
|
-
return
|
|
1273
|
-
}
|
|
1274
|
-
},
|
|
1275
|
-
canHandle: (
|
|
1276
|
-
serialize({ value:
|
|
1277
|
-
let
|
|
1278
|
-
return
|
|
1437
|
+
deserialize(e) {
|
|
1438
|
+
return e.start(), wrap(e);
|
|
1439
|
+
}
|
|
1440
|
+
}, throwTransferHandler = {
|
|
1441
|
+
canHandle: (e) => isObject(e) && throwMarker in e,
|
|
1442
|
+
serialize({ value: e }) {
|
|
1443
|
+
let t;
|
|
1444
|
+
return e instanceof Error ? t = {
|
|
1279
1445
|
isError: !0,
|
|
1280
1446
|
value: {
|
|
1281
|
-
message:
|
|
1282
|
-
name:
|
|
1283
|
-
stack:
|
|
1447
|
+
message: e.message,
|
|
1448
|
+
name: e.name,
|
|
1449
|
+
stack: e.stack
|
|
1284
1450
|
}
|
|
1285
|
-
} :
|
|
1451
|
+
} : t = { isError: !1, value: e }, [t, []];
|
|
1286
1452
|
},
|
|
1287
|
-
deserialize(
|
|
1288
|
-
throw
|
|
1453
|
+
deserialize(e) {
|
|
1454
|
+
throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
|
|
1289
1455
|
}
|
|
1290
|
-
},
|
|
1291
|
-
["proxy",
|
|
1292
|
-
["throw",
|
|
1456
|
+
}, transferHandlers = /* @__PURE__ */ new Map([
|
|
1457
|
+
["proxy", proxyTransferHandler],
|
|
1458
|
+
["throw", throwTransferHandler]
|
|
1293
1459
|
]);
|
|
1294
|
-
function
|
|
1295
|
-
for (const r of
|
|
1296
|
-
if (
|
|
1460
|
+
function isAllowedOrigin(e, t) {
|
|
1461
|
+
for (const r of e)
|
|
1462
|
+
if (t === r || r === "*" || r instanceof RegExp && r.test(t))
|
|
1297
1463
|
return !0;
|
|
1298
1464
|
return !1;
|
|
1299
1465
|
}
|
|
1300
|
-
function
|
|
1301
|
-
|
|
1302
|
-
if (!
|
|
1466
|
+
function expose(e, t = globalThis, r = ["*"]) {
|
|
1467
|
+
t.addEventListener("message", function s(i) {
|
|
1468
|
+
if (!i || !i.data)
|
|
1303
1469
|
return;
|
|
1304
|
-
if (
|
|
1305
|
-
console.warn(`Invalid origin '${
|
|
1470
|
+
if (!isAllowedOrigin(r, i.origin)) {
|
|
1471
|
+
console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
|
|
1306
1472
|
return;
|
|
1307
1473
|
}
|
|
1308
|
-
const { id:
|
|
1309
|
-
let
|
|
1474
|
+
const { id: n, type: o, path: a } = Object.assign({ path: [] }, i.data), d = (i.data.argumentList || []).map(fromWireValue);
|
|
1475
|
+
let c;
|
|
1310
1476
|
try {
|
|
1311
|
-
const h = a.slice(0, -1).reduce((
|
|
1312
|
-
switch (
|
|
1477
|
+
const h = a.slice(0, -1).reduce((m, A) => m[A], e), f = a.reduce((m, A) => m[A], e);
|
|
1478
|
+
switch (o) {
|
|
1313
1479
|
case "GET":
|
|
1314
|
-
|
|
1480
|
+
c = f;
|
|
1315
1481
|
break;
|
|
1316
1482
|
case "SET":
|
|
1317
|
-
h[a.slice(-1)[0]] =
|
|
1483
|
+
h[a.slice(-1)[0]] = fromWireValue(i.data.value), c = !0;
|
|
1318
1484
|
break;
|
|
1319
1485
|
case "APPLY":
|
|
1320
|
-
|
|
1486
|
+
c = f.apply(h, d);
|
|
1321
1487
|
break;
|
|
1322
1488
|
case "CONSTRUCT":
|
|
1323
1489
|
{
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1490
|
+
const m = new f(...d);
|
|
1491
|
+
c = proxy(m);
|
|
1326
1492
|
}
|
|
1327
1493
|
break;
|
|
1328
1494
|
case "ENDPOINT":
|
|
1329
1495
|
{
|
|
1330
|
-
const { port1:
|
|
1331
|
-
|
|
1496
|
+
const { port1: m, port2: A } = new MessageChannel();
|
|
1497
|
+
expose(e, A), c = transfer(m, [m]);
|
|
1332
1498
|
}
|
|
1333
1499
|
break;
|
|
1334
1500
|
case "RELEASE":
|
|
1335
|
-
|
|
1501
|
+
c = void 0;
|
|
1336
1502
|
break;
|
|
1337
1503
|
default:
|
|
1338
1504
|
return;
|
|
1339
1505
|
}
|
|
1340
1506
|
} catch (h) {
|
|
1341
|
-
|
|
1507
|
+
c = { value: h, [throwMarker]: 0 };
|
|
1342
1508
|
}
|
|
1343
|
-
Promise.resolve(
|
|
1344
|
-
const [
|
|
1345
|
-
|
|
1509
|
+
Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1510
|
+
const [f, m] = toWireValue(h);
|
|
1511
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: n }), m), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1346
1512
|
}).catch((h) => {
|
|
1347
|
-
const [
|
|
1513
|
+
const [f, m] = toWireValue({
|
|
1348
1514
|
value: new TypeError("Unserializable return value"),
|
|
1349
|
-
[
|
|
1515
|
+
[throwMarker]: 0
|
|
1350
1516
|
});
|
|
1351
|
-
|
|
1517
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: n }), m);
|
|
1352
1518
|
});
|
|
1353
|
-
}),
|
|
1519
|
+
}), t.start && t.start();
|
|
1354
1520
|
}
|
|
1355
|
-
function
|
|
1356
|
-
return
|
|
1521
|
+
function isMessagePort(e) {
|
|
1522
|
+
return e.constructor.name === "MessagePort";
|
|
1357
1523
|
}
|
|
1358
|
-
function
|
|
1359
|
-
|
|
1524
|
+
function closeEndPoint(e) {
|
|
1525
|
+
isMessagePort(e) && e.close();
|
|
1360
1526
|
}
|
|
1361
|
-
function
|
|
1362
|
-
return
|
|
1527
|
+
function wrap(e, t) {
|
|
1528
|
+
return createProxy(e, [], t);
|
|
1363
1529
|
}
|
|
1364
|
-
function
|
|
1365
|
-
if (
|
|
1530
|
+
function throwIfProxyReleased(e) {
|
|
1531
|
+
if (e)
|
|
1366
1532
|
throw new Error("Proxy has been released and is not useable");
|
|
1367
1533
|
}
|
|
1368
|
-
function
|
|
1369
|
-
return
|
|
1534
|
+
function releaseEndpoint(e) {
|
|
1535
|
+
return requestResponseMessage(e, {
|
|
1370
1536
|
type: "RELEASE"
|
|
1371
1537
|
}).then(() => {
|
|
1372
|
-
|
|
1538
|
+
closeEndPoint(e);
|
|
1373
1539
|
});
|
|
1374
1540
|
}
|
|
1375
|
-
const
|
|
1376
|
-
const
|
|
1377
|
-
|
|
1541
|
+
const proxyCounter = /* @__PURE__ */ new WeakMap(), proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
|
|
1542
|
+
const t = (proxyCounter.get(e) || 0) - 1;
|
|
1543
|
+
proxyCounter.set(e, t), t === 0 && releaseEndpoint(e);
|
|
1378
1544
|
});
|
|
1379
|
-
function
|
|
1380
|
-
const r = (
|
|
1381
|
-
|
|
1545
|
+
function registerProxy(e, t) {
|
|
1546
|
+
const r = (proxyCounter.get(t) || 0) + 1;
|
|
1547
|
+
proxyCounter.set(t, r), proxyFinalizers && proxyFinalizers.register(e, t, e);
|
|
1382
1548
|
}
|
|
1383
|
-
function
|
|
1384
|
-
|
|
1549
|
+
function unregisterProxy(e) {
|
|
1550
|
+
proxyFinalizers && proxyFinalizers.unregister(e);
|
|
1385
1551
|
}
|
|
1386
|
-
function
|
|
1552
|
+
function createProxy(e, t = [], r = function() {
|
|
1387
1553
|
}) {
|
|
1388
|
-
let
|
|
1389
|
-
const
|
|
1390
|
-
get(
|
|
1391
|
-
if (
|
|
1554
|
+
let s = !1;
|
|
1555
|
+
const i = new Proxy(r, {
|
|
1556
|
+
get(n, o) {
|
|
1557
|
+
if (throwIfProxyReleased(s), o === releaseProxy)
|
|
1392
1558
|
return () => {
|
|
1393
|
-
|
|
1559
|
+
unregisterProxy(i), releaseEndpoint(e), s = !0;
|
|
1394
1560
|
};
|
|
1395
|
-
if (
|
|
1396
|
-
if (
|
|
1397
|
-
return { then: () =>
|
|
1398
|
-
const a =
|
|
1561
|
+
if (o === "then") {
|
|
1562
|
+
if (t.length === 0)
|
|
1563
|
+
return { then: () => i };
|
|
1564
|
+
const a = requestResponseMessage(e, {
|
|
1399
1565
|
type: "GET",
|
|
1400
|
-
path:
|
|
1401
|
-
}).then(
|
|
1566
|
+
path: t.map((d) => d.toString())
|
|
1567
|
+
}).then(fromWireValue);
|
|
1402
1568
|
return a.then.bind(a);
|
|
1403
1569
|
}
|
|
1404
|
-
return
|
|
1570
|
+
return createProxy(e, [...t, o]);
|
|
1405
1571
|
},
|
|
1406
|
-
set(
|
|
1407
|
-
|
|
1408
|
-
const [
|
|
1409
|
-
return
|
|
1572
|
+
set(n, o, a) {
|
|
1573
|
+
throwIfProxyReleased(s);
|
|
1574
|
+
const [d, c] = toWireValue(a);
|
|
1575
|
+
return requestResponseMessage(e, {
|
|
1410
1576
|
type: "SET",
|
|
1411
|
-
path: [...
|
|
1412
|
-
value:
|
|
1413
|
-
},
|
|
1577
|
+
path: [...t, o].map((h) => h.toString()),
|
|
1578
|
+
value: d
|
|
1579
|
+
}, c).then(fromWireValue);
|
|
1414
1580
|
},
|
|
1415
|
-
apply(
|
|
1416
|
-
|
|
1417
|
-
const
|
|
1418
|
-
if (
|
|
1419
|
-
return
|
|
1581
|
+
apply(n, o, a) {
|
|
1582
|
+
throwIfProxyReleased(s);
|
|
1583
|
+
const d = t[t.length - 1];
|
|
1584
|
+
if (d === createEndpoint)
|
|
1585
|
+
return requestResponseMessage(e, {
|
|
1420
1586
|
type: "ENDPOINT"
|
|
1421
|
-
}).then(
|
|
1422
|
-
if (
|
|
1423
|
-
return
|
|
1424
|
-
const [
|
|
1425
|
-
return
|
|
1587
|
+
}).then(fromWireValue);
|
|
1588
|
+
if (d === "bind")
|
|
1589
|
+
return createProxy(e, t.slice(0, -1));
|
|
1590
|
+
const [c, h] = processArguments(a);
|
|
1591
|
+
return requestResponseMessage(e, {
|
|
1426
1592
|
type: "APPLY",
|
|
1427
|
-
path:
|
|
1428
|
-
argumentList:
|
|
1429
|
-
}, h).then(
|
|
1593
|
+
path: t.map((f) => f.toString()),
|
|
1594
|
+
argumentList: c
|
|
1595
|
+
}, h).then(fromWireValue);
|
|
1430
1596
|
},
|
|
1431
|
-
construct(
|
|
1432
|
-
|
|
1433
|
-
const [a,
|
|
1434
|
-
return
|
|
1597
|
+
construct(n, o) {
|
|
1598
|
+
throwIfProxyReleased(s);
|
|
1599
|
+
const [a, d] = processArguments(o);
|
|
1600
|
+
return requestResponseMessage(e, {
|
|
1435
1601
|
type: "CONSTRUCT",
|
|
1436
|
-
path:
|
|
1602
|
+
path: t.map((c) => c.toString()),
|
|
1437
1603
|
argumentList: a
|
|
1438
|
-
},
|
|
1604
|
+
}, d).then(fromWireValue);
|
|
1439
1605
|
}
|
|
1440
1606
|
});
|
|
1441
|
-
return
|
|
1607
|
+
return registerProxy(i, e), i;
|
|
1442
1608
|
}
|
|
1443
|
-
function
|
|
1444
|
-
return Array.prototype.concat.apply([],
|
|
1609
|
+
function myFlat(e) {
|
|
1610
|
+
return Array.prototype.concat.apply([], e);
|
|
1445
1611
|
}
|
|
1446
|
-
function
|
|
1447
|
-
const
|
|
1448
|
-
return [
|
|
1612
|
+
function processArguments(e) {
|
|
1613
|
+
const t = e.map(toWireValue);
|
|
1614
|
+
return [t.map((r) => r[0]), myFlat(t.map((r) => r[1]))];
|
|
1449
1615
|
}
|
|
1450
|
-
const
|
|
1451
|
-
function
|
|
1452
|
-
return
|
|
1616
|
+
const transferCache = /* @__PURE__ */ new WeakMap();
|
|
1617
|
+
function transfer(e, t) {
|
|
1618
|
+
return transferCache.set(e, t), e;
|
|
1453
1619
|
}
|
|
1454
|
-
function
|
|
1455
|
-
return Object.assign(
|
|
1620
|
+
function proxy(e) {
|
|
1621
|
+
return Object.assign(e, { [proxyMarker]: !0 });
|
|
1456
1622
|
}
|
|
1457
|
-
function
|
|
1623
|
+
function windowEndpoint(e, t = globalThis, r = "*") {
|
|
1458
1624
|
return {
|
|
1459
|
-
postMessage: (
|
|
1460
|
-
addEventListener:
|
|
1461
|
-
removeEventListener:
|
|
1625
|
+
postMessage: (s, i) => e.postMessage(s, r, i),
|
|
1626
|
+
addEventListener: t.addEventListener.bind(t),
|
|
1627
|
+
removeEventListener: t.removeEventListener.bind(t)
|
|
1462
1628
|
};
|
|
1463
1629
|
}
|
|
1464
|
-
function
|
|
1465
|
-
for (const [
|
|
1466
|
-
if (r.canHandle(
|
|
1467
|
-
const [
|
|
1630
|
+
function toWireValue(e) {
|
|
1631
|
+
for (const [t, r] of transferHandlers)
|
|
1632
|
+
if (r.canHandle(e)) {
|
|
1633
|
+
const [s, i] = r.serialize(e);
|
|
1468
1634
|
return [
|
|
1469
1635
|
{
|
|
1470
1636
|
type: "HANDLER",
|
|
1471
|
-
name:
|
|
1472
|
-
value:
|
|
1637
|
+
name: t,
|
|
1638
|
+
value: s
|
|
1473
1639
|
},
|
|
1474
|
-
|
|
1640
|
+
i
|
|
1475
1641
|
];
|
|
1476
1642
|
}
|
|
1477
1643
|
return [
|
|
1478
1644
|
{
|
|
1479
1645
|
type: "RAW",
|
|
1480
|
-
value:
|
|
1646
|
+
value: e
|
|
1481
1647
|
},
|
|
1482
|
-
|
|
1648
|
+
transferCache.get(e) || []
|
|
1483
1649
|
];
|
|
1484
1650
|
}
|
|
1485
|
-
function
|
|
1486
|
-
switch (
|
|
1651
|
+
function fromWireValue(e) {
|
|
1652
|
+
switch (e.type) {
|
|
1487
1653
|
case "HANDLER":
|
|
1488
|
-
return
|
|
1654
|
+
return transferHandlers.get(e.name).deserialize(e.value);
|
|
1489
1655
|
case "RAW":
|
|
1490
|
-
return
|
|
1656
|
+
return e.value;
|
|
1491
1657
|
}
|
|
1492
1658
|
}
|
|
1493
|
-
function
|
|
1494
|
-
return new Promise((
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1497
|
-
!
|
|
1498
|
-
}),
|
|
1659
|
+
function requestResponseMessage(e, t, r) {
|
|
1660
|
+
return new Promise((s) => {
|
|
1661
|
+
const i = generateUUID();
|
|
1662
|
+
e.addEventListener("message", function n(o) {
|
|
1663
|
+
!o.data || !o.data.id || o.data.id !== i || (e.removeEventListener("message", n), s(o.data));
|
|
1664
|
+
}), e.start && e.start(), e.postMessage(Object.assign({ id: i }, t), r);
|
|
1499
1665
|
});
|
|
1500
1666
|
}
|
|
1501
|
-
function
|
|
1667
|
+
function generateUUID() {
|
|
1502
1668
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
1503
1669
|
}
|
|
1504
|
-
function
|
|
1505
|
-
|
|
1506
|
-
const
|
|
1507
|
-
return new Proxy(
|
|
1508
|
-
get: (
|
|
1509
|
-
for (let
|
|
1670
|
+
function consumeAPI(e) {
|
|
1671
|
+
setupTransferHandlers();
|
|
1672
|
+
const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
|
|
1673
|
+
return new Proxy(s, {
|
|
1674
|
+
get: (i, n) => n === "isConnected" ? async () => {
|
|
1675
|
+
for (let o = 0; o < 10; o++)
|
|
1510
1676
|
try {
|
|
1511
|
-
await
|
|
1677
|
+
await runWithTimeout(r.isConnected(), 200);
|
|
1512
1678
|
break;
|
|
1513
1679
|
} catch {
|
|
1514
1680
|
}
|
|
1515
|
-
} : r[
|
|
1681
|
+
} : r[n]
|
|
1516
1682
|
});
|
|
1517
1683
|
}
|
|
1518
|
-
async function
|
|
1519
|
-
return new Promise((r,
|
|
1520
|
-
setTimeout(
|
|
1684
|
+
async function runWithTimeout(e, t) {
|
|
1685
|
+
return new Promise((r, s) => {
|
|
1686
|
+
setTimeout(s, t), e.then(r);
|
|
1521
1687
|
});
|
|
1522
1688
|
}
|
|
1523
|
-
function
|
|
1524
|
-
|
|
1689
|
+
function exposeAPI(e, t) {
|
|
1690
|
+
setupTransferHandlers();
|
|
1525
1691
|
const r = Promise.resolve();
|
|
1526
|
-
let
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
}),
|
|
1530
|
-
get: (
|
|
1692
|
+
let s, i;
|
|
1693
|
+
const n = new Promise((d, c) => {
|
|
1694
|
+
s = d, i = c;
|
|
1695
|
+
}), o = proxyClone(e), a = new Proxy(o, {
|
|
1696
|
+
get: (d, c) => c === "isConnected" ? () => r : c === "isReady" ? () => n : c in d ? d[c] : t == null ? void 0 : t[c]
|
|
1531
1697
|
});
|
|
1532
|
-
return
|
|
1698
|
+
return expose(
|
|
1533
1699
|
a,
|
|
1534
|
-
typeof window < "u" ?
|
|
1535
|
-
), [
|
|
1536
|
-
}
|
|
1537
|
-
let
|
|
1538
|
-
function
|
|
1539
|
-
|
|
1540
|
-
canHandle: (
|
|
1541
|
-
serialize: (
|
|
1700
|
+
typeof window < "u" ? windowEndpoint(self.parent) : void 0
|
|
1701
|
+
), [s, i, a];
|
|
1702
|
+
}
|
|
1703
|
+
let isTransferHandlersSetup = !1;
|
|
1704
|
+
function setupTransferHandlers() {
|
|
1705
|
+
isTransferHandlersSetup || (isTransferHandlersSetup = !0, transferHandlers.set("EVENT", {
|
|
1706
|
+
canHandle: (e) => e instanceof CustomEvent,
|
|
1707
|
+
serialize: (e) => [
|
|
1542
1708
|
{
|
|
1543
|
-
detail:
|
|
1709
|
+
detail: e.detail
|
|
1544
1710
|
},
|
|
1545
1711
|
[]
|
|
1546
1712
|
],
|
|
1547
|
-
deserialize: (
|
|
1548
|
-
}),
|
|
1549
|
-
canHandle: (
|
|
1550
|
-
serialize(
|
|
1713
|
+
deserialize: (e) => e
|
|
1714
|
+
}), transferHandlers.set("FUNCTION", {
|
|
1715
|
+
canHandle: (e) => typeof e == "function",
|
|
1716
|
+
serialize(e) {
|
|
1551
1717
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
1552
|
-
const { port1:
|
|
1553
|
-
return
|
|
1718
|
+
const { port1: t, port2: r } = new MessageChannel();
|
|
1719
|
+
return expose(e, t), [r, [r]];
|
|
1554
1720
|
},
|
|
1555
|
-
deserialize(
|
|
1556
|
-
return
|
|
1721
|
+
deserialize(e) {
|
|
1722
|
+
return e.start(), wrap(e);
|
|
1557
1723
|
}
|
|
1558
|
-
}),
|
|
1559
|
-
canHandle: (
|
|
1560
|
-
serialize(
|
|
1561
|
-
return [
|
|
1724
|
+
}), transferHandlers.set("PHPResponse", {
|
|
1725
|
+
canHandle: (e) => typeof e == "object" && e !== null && "headers" in e && "bytes" in e && "errors" in e && "exitCode" in e && "httpStatusCode" in e,
|
|
1726
|
+
serialize(e) {
|
|
1727
|
+
return [e.toRawData(), []];
|
|
1562
1728
|
},
|
|
1563
|
-
deserialize(
|
|
1564
|
-
return
|
|
1729
|
+
deserialize(e) {
|
|
1730
|
+
return PHPResponse.fromRawData(e);
|
|
1565
1731
|
}
|
|
1566
1732
|
}));
|
|
1567
1733
|
}
|
|
1568
|
-
function
|
|
1569
|
-
return new Proxy(
|
|
1570
|
-
get(
|
|
1571
|
-
switch (typeof
|
|
1734
|
+
function proxyClone(e) {
|
|
1735
|
+
return new Proxy(e, {
|
|
1736
|
+
get(t, r) {
|
|
1737
|
+
switch (typeof t[r]) {
|
|
1572
1738
|
case "function":
|
|
1573
|
-
return (...
|
|
1739
|
+
return (...s) => t[r](...s);
|
|
1574
1740
|
case "object":
|
|
1575
|
-
return
|
|
1741
|
+
return t[r] === null ? t[r] : proxyClone(t[r]);
|
|
1576
1742
|
case "undefined":
|
|
1577
1743
|
case "number":
|
|
1578
1744
|
case "string":
|
|
1579
|
-
return
|
|
1745
|
+
return t[r];
|
|
1580
1746
|
default:
|
|
1581
|
-
return
|
|
1747
|
+
return proxy(t[r]);
|
|
1582
1748
|
}
|
|
1583
1749
|
}
|
|
1584
1750
|
});
|
|
1585
1751
|
}
|
|
1586
|
-
async function
|
|
1587
|
-
if (
|
|
1588
|
-
switch (
|
|
1752
|
+
async function getPHPLoaderModule(e = LatestSupportedPHPVersion, t = "light") {
|
|
1753
|
+
if (t === "kitchen-sink")
|
|
1754
|
+
switch (e) {
|
|
1589
1755
|
case "8.3":
|
|
1590
1756
|
return await import("./kitchen-sink/php_8_3.js");
|
|
1591
1757
|
case "8.2":
|
|
@@ -1606,7 +1772,7 @@ async function Vt(t = wt, e = "light") {
|
|
|
1606
1772
|
return await import("./kitchen-sink/php_7_0.js");
|
|
1607
1773
|
}
|
|
1608
1774
|
else
|
|
1609
|
-
switch (
|
|
1775
|
+
switch (e) {
|
|
1610
1776
|
case "8.3":
|
|
1611
1777
|
return await import("./light/php_8_3.js");
|
|
1612
1778
|
case "8.2":
|
|
@@ -1626,11 +1792,11 @@ async function Vt(t = wt, e = "light") {
|
|
|
1626
1792
|
case "7.0":
|
|
1627
1793
|
return await import("./light/php_7_0.js");
|
|
1628
1794
|
}
|
|
1629
|
-
throw new Error(`Unsupported PHP version ${
|
|
1795
|
+
throw new Error(`Unsupported PHP version ${e}`);
|
|
1630
1796
|
}
|
|
1631
|
-
const
|
|
1797
|
+
const fakeWebsocket = () => ({
|
|
1632
1798
|
websocket: {
|
|
1633
|
-
decorator: (
|
|
1799
|
+
decorator: (e) => class extends e {
|
|
1634
1800
|
constructor() {
|
|
1635
1801
|
try {
|
|
1636
1802
|
super();
|
|
@@ -1643,7 +1809,7 @@ const Yt = () => ({
|
|
|
1643
1809
|
}
|
|
1644
1810
|
}
|
|
1645
1811
|
});
|
|
1646
|
-
class
|
|
1812
|
+
class WebPHP extends BasePHP {
|
|
1647
1813
|
/**
|
|
1648
1814
|
* Creates a new PHP instance.
|
|
1649
1815
|
*
|
|
@@ -1656,209 +1822,199 @@ class be extends P {
|
|
|
1656
1822
|
* @param options The options to use when loading PHP
|
|
1657
1823
|
* @returns A new PHP instance
|
|
1658
1824
|
*/
|
|
1659
|
-
static async load(
|
|
1660
|
-
return
|
|
1825
|
+
static async load(t, r = {}) {
|
|
1826
|
+
return new WebPHP(
|
|
1827
|
+
await WebPHP.loadRuntime(t, r),
|
|
1828
|
+
r.requestHandler
|
|
1829
|
+
);
|
|
1661
1830
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
var m, b;
|
|
1672
|
-
const a = await Promise.all([
|
|
1673
|
-
Vt(e, s),
|
|
1674
|
-
...r.dataModules || []
|
|
1675
|
-
]), [u, ...l] = a;
|
|
1676
|
-
(m = r.downloadMonitor) == null || m.setModules(a);
|
|
1677
|
-
const h = await Ft(
|
|
1678
|
-
u,
|
|
1679
|
-
{
|
|
1680
|
-
...r.emscriptenOptions || {},
|
|
1681
|
-
...((b = r.downloadMonitor) == null ? void 0 : b.getEmscriptenOptions()) || {},
|
|
1682
|
-
...Yt()
|
|
1683
|
-
},
|
|
1684
|
-
l
|
|
1685
|
-
);
|
|
1686
|
-
n.initializeRuntime(h);
|
|
1687
|
-
})();
|
|
1688
|
-
return {
|
|
1689
|
-
php: n,
|
|
1690
|
-
phpReady: i.then(() => n)
|
|
1691
|
-
};
|
|
1831
|
+
static async loadRuntime(t, r = {}) {
|
|
1832
|
+
var n;
|
|
1833
|
+
const s = r.loadAllExtensions ? "kitchen-sink" : "light", i = await getPHPLoaderModule(t, s);
|
|
1834
|
+
return (n = r.downloadMonitor) == null || n.expectAssets({
|
|
1835
|
+
[i.dependencyFilename]: i.dependenciesTotalSize
|
|
1836
|
+
}), await loadPHPRuntime(i, {
|
|
1837
|
+
...r.emscriptenOptions || {},
|
|
1838
|
+
...fakeWebsocket()
|
|
1839
|
+
});
|
|
1692
1840
|
}
|
|
1693
1841
|
}
|
|
1694
|
-
const
|
|
1695
|
-
class
|
|
1842
|
+
const _private = /* @__PURE__ */ new WeakMap();
|
|
1843
|
+
class WebPHPEndpoint {
|
|
1696
1844
|
/** @inheritDoc */
|
|
1697
|
-
constructor(
|
|
1698
|
-
|
|
1699
|
-
php:
|
|
1845
|
+
constructor(t, r) {
|
|
1846
|
+
_private.set(this, {
|
|
1847
|
+
php: t,
|
|
1700
1848
|
monitor: r
|
|
1701
|
-
}), this.absoluteUrl =
|
|
1849
|
+
}), this.absoluteUrl = t.absoluteUrl, this.documentRoot = t.documentRoot;
|
|
1702
1850
|
}
|
|
1703
1851
|
/** @inheritDoc @php-wasm/universal!RequestHandler.pathToInternalUrl */
|
|
1704
|
-
pathToInternalUrl(
|
|
1705
|
-
return
|
|
1852
|
+
pathToInternalUrl(t) {
|
|
1853
|
+
return _private.get(this).php.pathToInternalUrl(t);
|
|
1706
1854
|
}
|
|
1707
1855
|
/** @inheritDoc @php-wasm/universal!RequestHandler.internalUrlToPath */
|
|
1708
|
-
internalUrlToPath(
|
|
1709
|
-
return
|
|
1856
|
+
internalUrlToPath(t) {
|
|
1857
|
+
return _private.get(this).php.internalUrlToPath(t);
|
|
1710
1858
|
}
|
|
1711
1859
|
/**
|
|
1712
1860
|
* The onDownloadProgress event listener.
|
|
1713
1861
|
*/
|
|
1714
|
-
async onDownloadProgress(
|
|
1862
|
+
async onDownloadProgress(t) {
|
|
1715
1863
|
var r;
|
|
1716
|
-
return (r =
|
|
1864
|
+
return (r = _private.get(this).monitor) == null ? void 0 : r.addEventListener("progress", t);
|
|
1717
1865
|
}
|
|
1718
1866
|
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.mv */
|
|
1719
|
-
mv(
|
|
1720
|
-
return
|
|
1867
|
+
mv(t, r) {
|
|
1868
|
+
return _private.get(this).php.mv(t, r);
|
|
1721
1869
|
}
|
|
1722
1870
|
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */
|
|
1723
|
-
rmdir(
|
|
1724
|
-
return
|
|
1871
|
+
rmdir(t, r) {
|
|
1872
|
+
return _private.get(this).php.rmdir(t, r);
|
|
1725
1873
|
}
|
|
1726
1874
|
/** @inheritDoc @php-wasm/universal!RequestHandler.request */
|
|
1727
|
-
request(
|
|
1728
|
-
return
|
|
1875
|
+
request(t, r) {
|
|
1876
|
+
return _private.get(this).php.request(t, r);
|
|
1729
1877
|
}
|
|
1730
1878
|
/** @inheritDoc @php-wasm/web!WebPHP.run */
|
|
1731
|
-
async run(
|
|
1732
|
-
return
|
|
1879
|
+
async run(t) {
|
|
1880
|
+
return _private.get(this).php.run(t);
|
|
1733
1881
|
}
|
|
1734
1882
|
/** @inheritDoc @php-wasm/web!WebPHP.setSpawnHandler */
|
|
1735
|
-
setSpawnHandler(
|
|
1736
|
-
|
|
1883
|
+
setSpawnHandler(t) {
|
|
1884
|
+
_private.get(this).php.setSpawnHandler(t);
|
|
1737
1885
|
}
|
|
1738
1886
|
/** @inheritDoc @php-wasm/web!WebPHP.chdir */
|
|
1739
|
-
chdir(
|
|
1740
|
-
return
|
|
1887
|
+
chdir(t) {
|
|
1888
|
+
return _private.get(this).php.chdir(t);
|
|
1889
|
+
}
|
|
1890
|
+
/** @inheritDoc @php-wasm/web!WebPHP.setSapiName */
|
|
1891
|
+
setSapiName(t) {
|
|
1892
|
+
_private.get(this).php.setSapiName(t);
|
|
1741
1893
|
}
|
|
1742
1894
|
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniPath */
|
|
1743
|
-
setPhpIniPath(
|
|
1744
|
-
return
|
|
1895
|
+
setPhpIniPath(t) {
|
|
1896
|
+
return _private.get(this).php.setPhpIniPath(t);
|
|
1745
1897
|
}
|
|
1746
1898
|
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
|
|
1747
|
-
setPhpIniEntry(
|
|
1748
|
-
return
|
|
1899
|
+
setPhpIniEntry(t, r) {
|
|
1900
|
+
return _private.get(this).php.setPhpIniEntry(t, r);
|
|
1749
1901
|
}
|
|
1750
1902
|
/** @inheritDoc @php-wasm/web!WebPHP.mkdir */
|
|
1751
|
-
mkdir(
|
|
1752
|
-
return
|
|
1903
|
+
mkdir(t) {
|
|
1904
|
+
return _private.get(this).php.mkdir(t);
|
|
1753
1905
|
}
|
|
1754
1906
|
/** @inheritDoc @php-wasm/web!WebPHP.mkdirTree */
|
|
1755
|
-
mkdirTree(
|
|
1756
|
-
return
|
|
1907
|
+
mkdirTree(t) {
|
|
1908
|
+
return _private.get(this).php.mkdirTree(t);
|
|
1757
1909
|
}
|
|
1758
1910
|
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsText */
|
|
1759
|
-
readFileAsText(
|
|
1760
|
-
return
|
|
1911
|
+
readFileAsText(t) {
|
|
1912
|
+
return _private.get(this).php.readFileAsText(t);
|
|
1761
1913
|
}
|
|
1762
1914
|
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsBuffer */
|
|
1763
|
-
readFileAsBuffer(
|
|
1764
|
-
return
|
|
1915
|
+
readFileAsBuffer(t) {
|
|
1916
|
+
return _private.get(this).php.readFileAsBuffer(t);
|
|
1765
1917
|
}
|
|
1766
1918
|
/** @inheritDoc @php-wasm/web!WebPHP.writeFile */
|
|
1767
|
-
writeFile(
|
|
1768
|
-
return
|
|
1919
|
+
writeFile(t, r) {
|
|
1920
|
+
return _private.get(this).php.writeFile(t, r);
|
|
1769
1921
|
}
|
|
1770
1922
|
/** @inheritDoc @php-wasm/web!WebPHP.unlink */
|
|
1771
|
-
unlink(
|
|
1772
|
-
return
|
|
1923
|
+
unlink(t) {
|
|
1924
|
+
return _private.get(this).php.unlink(t);
|
|
1773
1925
|
}
|
|
1774
1926
|
/** @inheritDoc @php-wasm/web!WebPHP.listFiles */
|
|
1775
|
-
listFiles(
|
|
1776
|
-
return
|
|
1927
|
+
listFiles(t, r) {
|
|
1928
|
+
return _private.get(this).php.listFiles(t, r);
|
|
1777
1929
|
}
|
|
1778
1930
|
/** @inheritDoc @php-wasm/web!WebPHP.isDir */
|
|
1779
|
-
isDir(
|
|
1780
|
-
return
|
|
1931
|
+
isDir(t) {
|
|
1932
|
+
return _private.get(this).php.isDir(t);
|
|
1781
1933
|
}
|
|
1782
1934
|
/** @inheritDoc @php-wasm/web!WebPHP.fileExists */
|
|
1783
|
-
fileExists(
|
|
1784
|
-
return
|
|
1935
|
+
fileExists(t) {
|
|
1936
|
+
return _private.get(this).php.fileExists(t);
|
|
1785
1937
|
}
|
|
1786
1938
|
/** @inheritDoc @php-wasm/web!WebPHP.onMessage */
|
|
1787
|
-
onMessage(
|
|
1788
|
-
|
|
1939
|
+
onMessage(t) {
|
|
1940
|
+
_private.get(this).php.onMessage(t);
|
|
1789
1941
|
}
|
|
1790
1942
|
/** @inheritDoc @php-wasm/web!WebPHP.defineConstant */
|
|
1791
|
-
defineConstant(
|
|
1792
|
-
|
|
1943
|
+
defineConstant(t, r) {
|
|
1944
|
+
_private.get(this).php.defineConstant(t, r);
|
|
1793
1945
|
}
|
|
1794
1946
|
/** @inheritDoc @php-wasm/web!WebPHP.addEventListener */
|
|
1795
|
-
addEventListener(
|
|
1796
|
-
|
|
1947
|
+
addEventListener(t, r) {
|
|
1948
|
+
_private.get(this).php.addEventListener(t, r);
|
|
1797
1949
|
}
|
|
1798
1950
|
/** @inheritDoc @php-wasm/web!WebPHP.removeEventListener */
|
|
1799
|
-
removeEventListener(
|
|
1800
|
-
|
|
1951
|
+
removeEventListener(t, r) {
|
|
1952
|
+
_private.get(this).php.removeEventListener(t, r);
|
|
1801
1953
|
}
|
|
1802
1954
|
}
|
|
1803
|
-
function
|
|
1955
|
+
function responseTo(e, t) {
|
|
1804
1956
|
return {
|
|
1805
1957
|
type: "response",
|
|
1806
|
-
requestId:
|
|
1807
|
-
response:
|
|
1958
|
+
requestId: e,
|
|
1959
|
+
response: t
|
|
1808
1960
|
};
|
|
1809
1961
|
}
|
|
1810
|
-
async function
|
|
1811
|
-
const
|
|
1812
|
-
if (!
|
|
1813
|
-
throw
|
|
1814
|
-
|
|
1962
|
+
async function registerServiceWorker(e, t, r) {
|
|
1963
|
+
const s = navigator.serviceWorker;
|
|
1964
|
+
if (!s)
|
|
1965
|
+
throw location.protocol === "https:" ? new Error(
|
|
1966
|
+
"Service workers are not supported in this browser."
|
|
1967
|
+
) : new Error(
|
|
1968
|
+
"WordPress Playground requires service workers which are only supported on HTTPS sites. This site does not use HTTPS, please retry on one that does. "
|
|
1969
|
+
);
|
|
1970
|
+
console.debug("[window][sw] Registering a Service Worker"), await (await s.register(r, {
|
|
1815
1971
|
type: "module",
|
|
1816
1972
|
// Always bypass HTTP cache when fetching the new Service Worker script:
|
|
1817
1973
|
updateViaCache: "none"
|
|
1818
1974
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
1819
1975
|
"message",
|
|
1820
|
-
async function(
|
|
1821
|
-
if (console.debug("[window][sw] Message from ServiceWorker",
|
|
1976
|
+
async function(o) {
|
|
1977
|
+
if (console.debug("[window][sw] Message from ServiceWorker", o), t && o.data.scope !== t)
|
|
1822
1978
|
return;
|
|
1823
|
-
const a =
|
|
1824
|
-
|
|
1979
|
+
const a = o.data.args || [], d = o.data.method, c = await e[d](...a);
|
|
1980
|
+
o.source.postMessage(responseTo(o.data.requestId, c));
|
|
1825
1981
|
}
|
|
1826
|
-
),
|
|
1982
|
+
), s.startMessages();
|
|
1827
1983
|
}
|
|
1828
|
-
async function
|
|
1829
|
-
|
|
1830
|
-
const r = new Worker(
|
|
1831
|
-
return new Promise((
|
|
1832
|
-
r.onerror = (
|
|
1984
|
+
async function spawnPHPWorkerThread(e, t = {}) {
|
|
1985
|
+
e = addQueryParams(e, t);
|
|
1986
|
+
const r = new Worker(e, { type: "module" });
|
|
1987
|
+
return new Promise((s, i) => {
|
|
1988
|
+
r.onerror = (o) => {
|
|
1833
1989
|
const a = new Error(
|
|
1834
|
-
`WebWorker failed to load at ${
|
|
1990
|
+
`WebWorker failed to load at ${e}. ${o.message ? `Original error: ${o.message}` : ""}`
|
|
1835
1991
|
);
|
|
1836
|
-
a.filename =
|
|
1992
|
+
a.filename = o.filename, i(a);
|
|
1837
1993
|
};
|
|
1838
|
-
function o
|
|
1839
|
-
|
|
1994
|
+
function n(o) {
|
|
1995
|
+
o.data === "worker-script-started" && (s(r), r.removeEventListener("message", n));
|
|
1840
1996
|
}
|
|
1841
|
-
r.addEventListener("message",
|
|
1997
|
+
r.addEventListener("message", n);
|
|
1842
1998
|
});
|
|
1843
1999
|
}
|
|
1844
|
-
function
|
|
1845
|
-
if (!Object.entries(
|
|
1846
|
-
return
|
|
1847
|
-
const r = new URL(
|
|
1848
|
-
for (const [
|
|
1849
|
-
if (Array.isArray(
|
|
1850
|
-
for (const
|
|
1851
|
-
r.searchParams.append(
|
|
2000
|
+
function addQueryParams(e, t) {
|
|
2001
|
+
if (!Object.entries(t).length)
|
|
2002
|
+
return e + "";
|
|
2003
|
+
const r = new URL(e);
|
|
2004
|
+
for (const [s, i] of Object.entries(t))
|
|
2005
|
+
if (Array.isArray(i))
|
|
2006
|
+
for (const n of i)
|
|
2007
|
+
r.searchParams.append(s, n);
|
|
1852
2008
|
else
|
|
1853
|
-
r.searchParams.set(
|
|
2009
|
+
r.searchParams.set(s, i);
|
|
1854
2010
|
return r.toString();
|
|
1855
2011
|
}
|
|
1856
2012
|
export {
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
2013
|
+
WebPHP,
|
|
2014
|
+
WebPHPEndpoint,
|
|
2015
|
+
consumeAPI,
|
|
2016
|
+
exposeAPI,
|
|
2017
|
+
getPHPLoaderModule,
|
|
2018
|
+
registerServiceWorker,
|
|
2019
|
+
spawnPHPWorkerThread
|
|
1864
2020
|
};
|