@php-wasm/web 0.7.19 → 0.7.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -22
- package/index.js +440 -423
- 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 +3 -3
- package/kitchen-sink/php_7_1.js +3 -3
- package/kitchen-sink/php_7_2.js +3 -3
- package/kitchen-sink/php_7_3.js +3 -3
- package/kitchen-sink/php_7_4.js +3 -3
- package/kitchen-sink/php_8_0.js +3 -3
- package/kitchen-sink/php_8_1.js +3 -3
- package/kitchen-sink/php_8_2.js +3 -3
- package/kitchen-sink/php_8_3.js +3 -7313
- 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 +3 -3
- package/light/php_7_1.js +3 -3
- package/light/php_7_2.js +3 -3
- package/light/php_7_3.js +3 -3
- package/light/php_7_4.js +3 -3
- package/light/php_8_0.js +3 -3
- package/light/php_8_1.js +3 -3
- package/light/php_8_2.js +3 -3
- package/light/php_8_3.js +3 -7297
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var p = (e, t, r) => (O(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
9
|
-
},
|
|
10
|
-
var
|
|
9
|
+
}, _ = (e, t, r, s) => (O(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var h = (e, t, r) => (O(e, t, "access private method"), r);
|
|
11
11
|
const currentJsRuntime$1 = function() {
|
|
12
12
|
var e;
|
|
13
13
|
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
@@ -77,33 +77,170 @@ if (currentJsRuntime$1 === "NODE" && typeof CustomEvent > "u") {
|
|
|
77
77
|
}
|
|
78
78
|
globalThis.CustomEvent = e;
|
|
79
79
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
80
|
+
const responseTexts = {
|
|
81
|
+
500: "Internal Server Error",
|
|
82
|
+
502: "Bad Gateway",
|
|
83
|
+
404: "Not Found",
|
|
84
|
+
403: "Forbidden",
|
|
85
|
+
401: "Unauthorized",
|
|
86
|
+
400: "Bad Request",
|
|
87
|
+
301: "Moved Permanently",
|
|
88
|
+
302: "Found",
|
|
89
|
+
307: "Temporary Redirect",
|
|
90
|
+
308: "Permanent Redirect",
|
|
91
|
+
204: "No Content",
|
|
92
|
+
201: "Created",
|
|
93
|
+
200: "OK"
|
|
94
|
+
};
|
|
95
|
+
class PHPResponse {
|
|
96
|
+
constructor(t, r, s, n = "", o = 0) {
|
|
97
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
|
|
98
|
+
}
|
|
99
|
+
static forHttpCode(t, r = "") {
|
|
100
|
+
return new PHPResponse(
|
|
101
|
+
t,
|
|
102
|
+
{},
|
|
103
|
+
new TextEncoder().encode(
|
|
104
|
+
r || responseTexts[t] || ""
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
static fromRawData(t) {
|
|
109
|
+
return new PHPResponse(
|
|
110
|
+
t.httpStatusCode,
|
|
111
|
+
t.headers,
|
|
112
|
+
t.bytes,
|
|
113
|
+
t.errors,
|
|
114
|
+
t.exitCode
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
toRawData() {
|
|
118
|
+
return {
|
|
119
|
+
headers: this.headers,
|
|
120
|
+
bytes: this.bytes,
|
|
121
|
+
errors: this.errors,
|
|
122
|
+
exitCode: this.exitCode,
|
|
123
|
+
httpStatusCode: this.httpStatusCode
|
|
124
|
+
};
|
|
125
|
+
}
|
|
82
126
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param type The name of the event
|
|
86
|
-
* @param options A dictionary object that allows for setting
|
|
87
|
-
* attributes via object members of the same name.
|
|
127
|
+
* Response body as JSON.
|
|
88
128
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
get error() {
|
|
93
|
-
return this[kError];
|
|
129
|
+
get json() {
|
|
130
|
+
return JSON.parse(this.text);
|
|
94
131
|
}
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Response body as text.
|
|
134
|
+
*/
|
|
135
|
+
get text() {
|
|
136
|
+
return new TextDecoder().decode(this.bytes);
|
|
97
137
|
}
|
|
98
138
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
139
|
+
const FileErrorCodes = {
|
|
140
|
+
0: "No error occurred. System call completed successfully.",
|
|
141
|
+
1: "Argument list too long.",
|
|
142
|
+
2: "Permission denied.",
|
|
143
|
+
3: "Address in use.",
|
|
144
|
+
4: "Address not available.",
|
|
145
|
+
5: "Address family not supported.",
|
|
146
|
+
6: "Resource unavailable, or operation would block.",
|
|
147
|
+
7: "Connection already in progress.",
|
|
148
|
+
8: "Bad file descriptor.",
|
|
149
|
+
9: "Bad message.",
|
|
150
|
+
10: "Device or resource busy.",
|
|
151
|
+
11: "Operation canceled.",
|
|
152
|
+
12: "No child processes.",
|
|
153
|
+
13: "Connection aborted.",
|
|
154
|
+
14: "Connection refused.",
|
|
155
|
+
15: "Connection reset.",
|
|
156
|
+
16: "Resource deadlock would occur.",
|
|
157
|
+
17: "Destination address required.",
|
|
158
|
+
18: "Mathematics argument out of domain of function.",
|
|
159
|
+
19: "Reserved.",
|
|
160
|
+
20: "File exists.",
|
|
161
|
+
21: "Bad address.",
|
|
162
|
+
22: "File too large.",
|
|
163
|
+
23: "Host is unreachable.",
|
|
164
|
+
24: "Identifier removed.",
|
|
165
|
+
25: "Illegal byte sequence.",
|
|
166
|
+
26: "Operation in progress.",
|
|
167
|
+
27: "Interrupted function.",
|
|
168
|
+
28: "Invalid argument.",
|
|
169
|
+
29: "I/O error.",
|
|
170
|
+
30: "Socket is connected.",
|
|
171
|
+
31: "There is a directory under that path.",
|
|
172
|
+
32: "Too many levels of symbolic links.",
|
|
173
|
+
33: "File descriptor value too large.",
|
|
174
|
+
34: "Too many links.",
|
|
175
|
+
35: "Message too large.",
|
|
176
|
+
36: "Reserved.",
|
|
177
|
+
37: "Filename too long.",
|
|
178
|
+
38: "Network is down.",
|
|
179
|
+
39: "Connection aborted by network.",
|
|
180
|
+
40: "Network unreachable.",
|
|
181
|
+
41: "Too many files open in system.",
|
|
182
|
+
42: "No buffer space available.",
|
|
183
|
+
43: "No such device.",
|
|
184
|
+
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
185
|
+
45: "Executable file format error.",
|
|
186
|
+
46: "No locks available.",
|
|
187
|
+
47: "Reserved.",
|
|
188
|
+
48: "Not enough space.",
|
|
189
|
+
49: "No message of the desired type.",
|
|
190
|
+
50: "Protocol not available.",
|
|
191
|
+
51: "No space left on device.",
|
|
192
|
+
52: "Function not supported.",
|
|
193
|
+
53: "The socket is not connected.",
|
|
194
|
+
54: "Not a directory or a symbolic link to a directory.",
|
|
195
|
+
55: "Directory not empty.",
|
|
196
|
+
56: "State not recoverable.",
|
|
197
|
+
57: "Not a socket.",
|
|
198
|
+
58: "Not supported, or operation not supported on socket.",
|
|
199
|
+
59: "Inappropriate I/O control operation.",
|
|
200
|
+
60: "No such device or address.",
|
|
201
|
+
61: "Value too large to be stored in data type.",
|
|
202
|
+
62: "Previous owner died.",
|
|
203
|
+
63: "Operation not permitted.",
|
|
204
|
+
64: "Broken pipe.",
|
|
205
|
+
65: "Protocol error.",
|
|
206
|
+
66: "Protocol not supported.",
|
|
207
|
+
67: "Protocol wrong type for socket.",
|
|
208
|
+
68: "Result too large.",
|
|
209
|
+
69: "Read-only file system.",
|
|
210
|
+
70: "Invalid seek.",
|
|
211
|
+
71: "No such process.",
|
|
212
|
+
72: "Reserved.",
|
|
213
|
+
73: "Connection timed out.",
|
|
214
|
+
74: "Text file busy.",
|
|
215
|
+
75: "Cross-device link.",
|
|
216
|
+
76: "Extension: Capabilities insufficient."
|
|
217
|
+
};
|
|
218
|
+
function getEmscriptenFsError(e) {
|
|
219
|
+
const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
|
|
220
|
+
if (t in FileErrorCodes)
|
|
221
|
+
return FileErrorCodes[t];
|
|
222
|
+
}
|
|
223
|
+
function rethrowFileSystemError(e = "") {
|
|
224
|
+
return function(r, s, n) {
|
|
225
|
+
const o = n.value;
|
|
226
|
+
n.value = function(...i) {
|
|
227
|
+
try {
|
|
228
|
+
return o.apply(this, i);
|
|
229
|
+
} catch (a) {
|
|
230
|
+
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
231
|
+
if (l in FileErrorCodes) {
|
|
232
|
+
const c = FileErrorCodes[l], u = typeof i[0] == "string" ? i[0] : null, m = u !== null ? e.replaceAll("{path}", u) : e;
|
|
233
|
+
throw new Error(`${m}: ${c}`, {
|
|
234
|
+
cause: a
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
throw a;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
};
|
|
104
241
|
}
|
|
105
242
|
const logToConsole = (e, ...t) => {
|
|
106
|
-
switch (e.severity) {
|
|
243
|
+
switch (typeof e.message == "string" ? e.message = prepareLogMessage(e.message) : e.message.message && typeof e.message.message == "string" && (e.message.message = prepareLogMessage(e.message.message)), e.severity) {
|
|
107
244
|
case "Debug":
|
|
108
245
|
console.debug(e.message, ...t);
|
|
109
246
|
break;
|
|
@@ -122,17 +259,15 @@ const logToConsole = (e, ...t) => {
|
|
|
122
259
|
default:
|
|
123
260
|
console.log(e.message, ...t);
|
|
124
261
|
}
|
|
125
|
-
}, prepareLogMessage = (e
|
|
126
|
-
|
|
127
|
-
...t.map((r) => JSON.stringify(r))
|
|
128
|
-
].join(" "), logs = [], addToLogArray = (e) => {
|
|
262
|
+
}, prepareLogMessage$1 = (e) => e instanceof Error ? [e.message, e.stack].join(`
|
|
263
|
+
`) : JSON.stringify(e, null, 2), logs = [], addToLogArray = (e) => {
|
|
129
264
|
logs.push(e);
|
|
130
265
|
}, logToMemory = (e) => {
|
|
131
266
|
if (e.raw === !0)
|
|
132
267
|
addToLogArray(e.message);
|
|
133
268
|
else {
|
|
134
269
|
const t = formatLogEntry(
|
|
135
|
-
typeof e.message == "object" ? prepareLogMessage(e.message) : e.message,
|
|
270
|
+
typeof e.message == "object" ? prepareLogMessage$1(e.message) : e.message,
|
|
136
271
|
e.severity ?? "Info",
|
|
137
272
|
e.prefix ?? "JavaScript"
|
|
138
273
|
);
|
|
@@ -251,7 +386,14 @@ class Logger extends EventTarget {
|
|
|
251
386
|
);
|
|
252
387
|
}
|
|
253
388
|
}
|
|
254
|
-
const
|
|
389
|
+
const getDefaultHandlers = () => {
|
|
390
|
+
try {
|
|
391
|
+
if (process.env.NODE_ENV === "test")
|
|
392
|
+
return [logToMemory];
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
return [logToMemory, logToConsole];
|
|
396
|
+
}, logger = new Logger(getDefaultHandlers()), prepareLogMessage = (e) => e.replace(/\t/g, ""), formatLogEntry = (e, t, r) => {
|
|
255
397
|
const s = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
|
|
256
398
|
year: "numeric",
|
|
257
399
|
month: "short",
|
|
@@ -264,9 +406,68 @@ const logger = new Logger([logToMemory, logToConsole]), formatLogEntry = (e, t,
|
|
|
264
406
|
hour12: !1,
|
|
265
407
|
timeZone: "UTC",
|
|
266
408
|
timeZoneName: "short"
|
|
267
|
-
}).format(s);
|
|
268
|
-
return `[${
|
|
269
|
-
};
|
|
409
|
+
}).format(s), i = n + " " + o;
|
|
410
|
+
return e = prepareLogMessage(e), `[${i}] ${r} ${t}: ${e}`;
|
|
411
|
+
}, RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
412
|
+
let lastRuntimeId = 0;
|
|
413
|
+
async function loadPHPRuntime(e, t = {}) {
|
|
414
|
+
const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
|
|
415
|
+
onAbort(a) {
|
|
416
|
+
n(a), logger.error(a);
|
|
417
|
+
},
|
|
418
|
+
ENV: {},
|
|
419
|
+
// Emscripten sometimes prepends a '/' to the path, which
|
|
420
|
+
// breaks vite dev mode. An identity `locateFile` function
|
|
421
|
+
// fixes it.
|
|
422
|
+
locateFile: (a) => a,
|
|
423
|
+
...t,
|
|
424
|
+
noInitialRun: !0,
|
|
425
|
+
onRuntimeInitialized() {
|
|
426
|
+
t.onRuntimeInitialized && t.onRuntimeInitialized(), s();
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
await r;
|
|
430
|
+
const i = ++lastRuntimeId;
|
|
431
|
+
return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
|
|
432
|
+
return loadedRuntimes.delete(i), o.originalExit(a);
|
|
433
|
+
}, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
|
|
434
|
+
}
|
|
435
|
+
function getLoadedRuntime(e) {
|
|
436
|
+
return loadedRuntimes.get(e);
|
|
437
|
+
}
|
|
438
|
+
const currentJsRuntime = function() {
|
|
439
|
+
var e;
|
|
440
|
+
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";
|
|
441
|
+
}(), makePromise = () => {
|
|
442
|
+
const e = [], t = new Promise((r, s) => {
|
|
443
|
+
e.push(r, s);
|
|
444
|
+
});
|
|
445
|
+
return e.unshift(t), e;
|
|
446
|
+
}, kError = Symbol("error"), kMessage = Symbol("message");
|
|
447
|
+
class ErrorEvent2 extends Event {
|
|
448
|
+
/**
|
|
449
|
+
* Create a new `ErrorEvent`.
|
|
450
|
+
*
|
|
451
|
+
* @param type The name of the event
|
|
452
|
+
* @param options A dictionary object that allows for setting
|
|
453
|
+
* attributes via object members of the same name.
|
|
454
|
+
*/
|
|
455
|
+
constructor(t, r = {}) {
|
|
456
|
+
super(t), this[kError] = r.error === void 0 ? null : r.error, this[kMessage] = r.message === void 0 ? "" : r.message;
|
|
457
|
+
}
|
|
458
|
+
get error() {
|
|
459
|
+
return this[kError];
|
|
460
|
+
}
|
|
461
|
+
get message() {
|
|
462
|
+
return this[kMessage];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
|
|
466
|
+
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
|
|
467
|
+
const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
|
|
468
|
+
function isExitCodeZero(e) {
|
|
469
|
+
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;
|
|
470
|
+
}
|
|
270
471
|
class UnhandledRejectionsTarget extends EventTarget {
|
|
271
472
|
constructor() {
|
|
272
473
|
super(...arguments), this.listenersCount = 0;
|
|
@@ -451,6 +652,13 @@ function joinPaths(...e) {
|
|
|
451
652
|
const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
|
|
452
653
|
return t = normalizePath(t), !t && !r && (t = "."), t && s && (t += "/"), t;
|
|
453
654
|
}
|
|
655
|
+
function dirname(e) {
|
|
656
|
+
if (e === "/")
|
|
657
|
+
return "/";
|
|
658
|
+
e = normalizePath(e);
|
|
659
|
+
const t = e.lastIndexOf("/");
|
|
660
|
+
return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
|
|
661
|
+
}
|
|
454
662
|
function normalizePath(e) {
|
|
455
663
|
const t = e[0] === "/";
|
|
456
664
|
return e = normalizePathsArray(
|
|
@@ -524,258 +732,36 @@ class ProcessApi extends EventEmitter {
|
|
|
524
732
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
525
733
|
}
|
|
526
734
|
stdoutEnd() {
|
|
527
|
-
this.childProcess.stdout.emit("end", {});
|
|
528
|
-
}
|
|
529
|
-
stderr(t) {
|
|
530
|
-
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
531
|
-
}
|
|
532
|
-
stderrEnd() {
|
|
533
|
-
this.childProcess.stderr.emit("end", {});
|
|
534
|
-
}
|
|
535
|
-
exit(t) {
|
|
536
|
-
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
537
|
-
}
|
|
538
|
-
flushStdin() {
|
|
539
|
-
if (this.stdinData)
|
|
540
|
-
for (let t = 0; t < this.stdinData.length; t++)
|
|
541
|
-
this.emit("stdin", this.stdinData[t]);
|
|
542
|
-
this.stdinData = null;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
let lastPid = 9743;
|
|
546
|
-
class ChildProcess extends EventEmitter {
|
|
547
|
-
constructor(t = lastPid++) {
|
|
548
|
-
super(), this.pid = t, this.stdout = new EventEmitter(), this.stderr = new EventEmitter();
|
|
549
|
-
const r = this;
|
|
550
|
-
this.stdin = {
|
|
551
|
-
write: (s) => {
|
|
552
|
-
r.emit("stdin", s);
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
558
|
-
const e = this.getReader();
|
|
559
|
-
try {
|
|
560
|
-
for (; ; ) {
|
|
561
|
-
const { done: t, value: r } = await e.read();
|
|
562
|
-
if (t)
|
|
563
|
-
return;
|
|
564
|
-
yield r;
|
|
565
|
-
}
|
|
566
|
-
} finally {
|
|
567
|
-
e.releaseLock();
|
|
568
|
-
}
|
|
569
|
-
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
570
|
-
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
571
|
-
const responseTexts = {
|
|
572
|
-
500: "Internal Server Error",
|
|
573
|
-
502: "Bad Gateway",
|
|
574
|
-
404: "Not Found",
|
|
575
|
-
403: "Forbidden",
|
|
576
|
-
401: "Unauthorized",
|
|
577
|
-
400: "Bad Request",
|
|
578
|
-
301: "Moved Permanently",
|
|
579
|
-
302: "Found",
|
|
580
|
-
307: "Temporary Redirect",
|
|
581
|
-
308: "Permanent Redirect",
|
|
582
|
-
204: "No Content",
|
|
583
|
-
201: "Created",
|
|
584
|
-
200: "OK"
|
|
585
|
-
};
|
|
586
|
-
class PHPResponse {
|
|
587
|
-
constructor(t, r, s, n = "", o = 0) {
|
|
588
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
|
|
589
|
-
}
|
|
590
|
-
static forHttpCode(t, r = "") {
|
|
591
|
-
return new PHPResponse(
|
|
592
|
-
t,
|
|
593
|
-
{},
|
|
594
|
-
new TextEncoder().encode(
|
|
595
|
-
r || responseTexts[t] || ""
|
|
596
|
-
)
|
|
597
|
-
);
|
|
735
|
+
this.childProcess.stdout.emit("end", {});
|
|
598
736
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
t.httpStatusCode,
|
|
602
|
-
t.headers,
|
|
603
|
-
t.bytes,
|
|
604
|
-
t.errors,
|
|
605
|
-
t.exitCode
|
|
606
|
-
);
|
|
737
|
+
stderr(t) {
|
|
738
|
+
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
607
739
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
headers: this.headers,
|
|
611
|
-
bytes: this.bytes,
|
|
612
|
-
errors: this.errors,
|
|
613
|
-
exitCode: this.exitCode,
|
|
614
|
-
httpStatusCode: this.httpStatusCode
|
|
615
|
-
};
|
|
740
|
+
stderrEnd() {
|
|
741
|
+
this.childProcess.stderr.emit("end", {});
|
|
616
742
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
*/
|
|
620
|
-
get json() {
|
|
621
|
-
return JSON.parse(this.text);
|
|
743
|
+
exit(t) {
|
|
744
|
+
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
622
745
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
746
|
+
flushStdin() {
|
|
747
|
+
if (this.stdinData)
|
|
748
|
+
for (let t = 0; t < this.stdinData.length; t++)
|
|
749
|
+
this.emit("stdin", this.stdinData[t]);
|
|
750
|
+
this.stdinData = null;
|
|
628
751
|
}
|
|
629
752
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
"7.1",
|
|
639
|
-
"7.0"
|
|
640
|
-
], LatestSupportedPHPVersion = SupportedPHPVersions[0], FileErrorCodes = {
|
|
641
|
-
0: "No error occurred. System call completed successfully.",
|
|
642
|
-
1: "Argument list too long.",
|
|
643
|
-
2: "Permission denied.",
|
|
644
|
-
3: "Address in use.",
|
|
645
|
-
4: "Address not available.",
|
|
646
|
-
5: "Address family not supported.",
|
|
647
|
-
6: "Resource unavailable, or operation would block.",
|
|
648
|
-
7: "Connection already in progress.",
|
|
649
|
-
8: "Bad file descriptor.",
|
|
650
|
-
9: "Bad message.",
|
|
651
|
-
10: "Device or resource busy.",
|
|
652
|
-
11: "Operation canceled.",
|
|
653
|
-
12: "No child processes.",
|
|
654
|
-
13: "Connection aborted.",
|
|
655
|
-
14: "Connection refused.",
|
|
656
|
-
15: "Connection reset.",
|
|
657
|
-
16: "Resource deadlock would occur.",
|
|
658
|
-
17: "Destination address required.",
|
|
659
|
-
18: "Mathematics argument out of domain of function.",
|
|
660
|
-
19: "Reserved.",
|
|
661
|
-
20: "File exists.",
|
|
662
|
-
21: "Bad address.",
|
|
663
|
-
22: "File too large.",
|
|
664
|
-
23: "Host is unreachable.",
|
|
665
|
-
24: "Identifier removed.",
|
|
666
|
-
25: "Illegal byte sequence.",
|
|
667
|
-
26: "Operation in progress.",
|
|
668
|
-
27: "Interrupted function.",
|
|
669
|
-
28: "Invalid argument.",
|
|
670
|
-
29: "I/O error.",
|
|
671
|
-
30: "Socket is connected.",
|
|
672
|
-
31: "There is a directory under that path.",
|
|
673
|
-
32: "Too many levels of symbolic links.",
|
|
674
|
-
33: "File descriptor value too large.",
|
|
675
|
-
34: "Too many links.",
|
|
676
|
-
35: "Message too large.",
|
|
677
|
-
36: "Reserved.",
|
|
678
|
-
37: "Filename too long.",
|
|
679
|
-
38: "Network is down.",
|
|
680
|
-
39: "Connection aborted by network.",
|
|
681
|
-
40: "Network unreachable.",
|
|
682
|
-
41: "Too many files open in system.",
|
|
683
|
-
42: "No buffer space available.",
|
|
684
|
-
43: "No such device.",
|
|
685
|
-
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
686
|
-
45: "Executable file format error.",
|
|
687
|
-
46: "No locks available.",
|
|
688
|
-
47: "Reserved.",
|
|
689
|
-
48: "Not enough space.",
|
|
690
|
-
49: "No message of the desired type.",
|
|
691
|
-
50: "Protocol not available.",
|
|
692
|
-
51: "No space left on device.",
|
|
693
|
-
52: "Function not supported.",
|
|
694
|
-
53: "The socket is not connected.",
|
|
695
|
-
54: "Not a directory or a symbolic link to a directory.",
|
|
696
|
-
55: "Directory not empty.",
|
|
697
|
-
56: "State not recoverable.",
|
|
698
|
-
57: "Not a socket.",
|
|
699
|
-
58: "Not supported, or operation not supported on socket.",
|
|
700
|
-
59: "Inappropriate I/O control operation.",
|
|
701
|
-
60: "No such device or address.",
|
|
702
|
-
61: "Value too large to be stored in data type.",
|
|
703
|
-
62: "Previous owner died.",
|
|
704
|
-
63: "Operation not permitted.",
|
|
705
|
-
64: "Broken pipe.",
|
|
706
|
-
65: "Protocol error.",
|
|
707
|
-
66: "Protocol not supported.",
|
|
708
|
-
67: "Protocol wrong type for socket.",
|
|
709
|
-
68: "Result too large.",
|
|
710
|
-
69: "Read-only file system.",
|
|
711
|
-
70: "Invalid seek.",
|
|
712
|
-
71: "No such process.",
|
|
713
|
-
72: "Reserved.",
|
|
714
|
-
73: "Connection timed out.",
|
|
715
|
-
74: "Text file busy.",
|
|
716
|
-
75: "Cross-device link.",
|
|
717
|
-
76: "Extension: Capabilities insufficient."
|
|
718
|
-
};
|
|
719
|
-
function getEmscriptenFsError(e) {
|
|
720
|
-
const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
|
|
721
|
-
if (t in FileErrorCodes)
|
|
722
|
-
return FileErrorCodes[t];
|
|
723
|
-
}
|
|
724
|
-
function rethrowFileSystemError(e = "") {
|
|
725
|
-
return function(r, s, n) {
|
|
726
|
-
const o = n.value;
|
|
727
|
-
n.value = function(...i) {
|
|
728
|
-
try {
|
|
729
|
-
return o.apply(this, i);
|
|
730
|
-
} catch (a) {
|
|
731
|
-
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
732
|
-
if (l in FileErrorCodes) {
|
|
733
|
-
const c = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
|
|
734
|
-
throw new Error(`${_}: ${c}`, {
|
|
735
|
-
cause: a
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
throw a;
|
|
753
|
+
let lastPid = 9743;
|
|
754
|
+
class ChildProcess extends EventEmitter {
|
|
755
|
+
constructor(t = lastPid++) {
|
|
756
|
+
super(), this.pid = t, this.stdout = new EventEmitter(), this.stderr = new EventEmitter();
|
|
757
|
+
const r = this;
|
|
758
|
+
this.stdin = {
|
|
759
|
+
write: (s) => {
|
|
760
|
+
r.emit("stdin", s);
|
|
739
761
|
}
|
|
740
762
|
};
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
744
|
-
let lastRuntimeId = 0;
|
|
745
|
-
async function loadPHPRuntime(e, t = {}) {
|
|
746
|
-
const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
|
|
747
|
-
onAbort(a) {
|
|
748
|
-
n(a), logger.error(a);
|
|
749
|
-
},
|
|
750
|
-
ENV: {},
|
|
751
|
-
// Emscripten sometimes prepends a '/' to the path, which
|
|
752
|
-
// breaks vite dev mode. An identity `locateFile` function
|
|
753
|
-
// fixes it.
|
|
754
|
-
locateFile: (a) => a,
|
|
755
|
-
...t,
|
|
756
|
-
noInitialRun: !0,
|
|
757
|
-
onRuntimeInitialized() {
|
|
758
|
-
t.onRuntimeInitialized && t.onRuntimeInitialized(), s();
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
await r;
|
|
762
|
-
const i = ++lastRuntimeId;
|
|
763
|
-
return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
|
|
764
|
-
return loadedRuntimes.delete(i), o.originalExit(a);
|
|
765
|
-
}, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
|
|
766
|
-
}
|
|
767
|
-
function getLoadedRuntime(e) {
|
|
768
|
-
return loadedRuntimes.get(e);
|
|
763
|
+
}
|
|
769
764
|
}
|
|
770
|
-
const currentJsRuntime = function() {
|
|
771
|
-
var e;
|
|
772
|
-
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";
|
|
773
|
-
}(), makePromise = () => {
|
|
774
|
-
const e = [], t = new Promise((r, s) => {
|
|
775
|
-
e.push(r, s);
|
|
776
|
-
});
|
|
777
|
-
return e.unshift(t), e;
|
|
778
|
-
};
|
|
779
765
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
780
766
|
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
781
767
|
(i = e[o]) && (n = (s ? i(t, r, n) : i(n)) || n);
|
|
@@ -787,7 +773,8 @@ class PHPExecutionFailureError extends Error {
|
|
|
787
773
|
super(t), this.response = r, this.source = s;
|
|
788
774
|
}
|
|
789
775
|
}
|
|
790
|
-
|
|
776
|
+
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
|
|
777
|
+
var E, g, w, y, P, R, B, S, W, x, U, T, q, k, z, C, $, F, V, H, j, M, G, N, J, b, D, A, Q, I, Y, L, Z;
|
|
791
778
|
class BasePHP {
|
|
792
779
|
/**
|
|
793
780
|
* Initializes a PHP runtime.
|
|
@@ -806,46 +793,43 @@ class BasePHP {
|
|
|
806
793
|
* was provided.
|
|
807
794
|
* @returns Computed $_SERVER entries.
|
|
808
795
|
*/
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
u(this, g, void 0);
|
|
830
|
-
u(this, b, void 0);
|
|
831
|
-
m(this, P, []), m(this, y, !1), m(this, w, null), m(this, g, /* @__PURE__ */ new Map()), m(this, b, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
|
|
796
|
+
d(this, R);
|
|
797
|
+
d(this, S);
|
|
798
|
+
d(this, x);
|
|
799
|
+
d(this, T);
|
|
800
|
+
d(this, k);
|
|
801
|
+
d(this, C);
|
|
802
|
+
d(this, F);
|
|
803
|
+
d(this, H);
|
|
804
|
+
d(this, M);
|
|
805
|
+
d(this, N);
|
|
806
|
+
d(this, b);
|
|
807
|
+
d(this, A);
|
|
808
|
+
d(this, I);
|
|
809
|
+
d(this, L);
|
|
810
|
+
d(this, E, void 0);
|
|
811
|
+
d(this, g, void 0);
|
|
812
|
+
d(this, w, void 0);
|
|
813
|
+
d(this, y, void 0);
|
|
814
|
+
d(this, P, void 0);
|
|
815
|
+
_(this, g, !1), _(this, w, null), _(this, y, /* @__PURE__ */ new Map()), _(this, P, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
|
|
832
816
|
}
|
|
833
817
|
addEventListener(e, t) {
|
|
834
|
-
|
|
818
|
+
p(this, y).has(e) || p(this, y).set(e, /* @__PURE__ */ new Set()), p(this, y).get(e).add(t);
|
|
835
819
|
}
|
|
836
820
|
removeEventListener(e, t) {
|
|
837
821
|
var r;
|
|
838
|
-
(r =
|
|
822
|
+
(r = p(this, y).get(e)) == null || r.delete(t);
|
|
839
823
|
}
|
|
840
824
|
dispatchEvent(e) {
|
|
841
|
-
const t =
|
|
825
|
+
const t = p(this, y).get(e.type);
|
|
842
826
|
if (t)
|
|
843
827
|
for (const r of t)
|
|
844
828
|
r(e);
|
|
845
829
|
}
|
|
846
830
|
/** @inheritDoc */
|
|
847
831
|
async onMessage(e) {
|
|
848
|
-
|
|
832
|
+
p(this, P).push(e);
|
|
849
833
|
}
|
|
850
834
|
/** @inheritDoc */
|
|
851
835
|
async setSpawnHandler(handler) {
|
|
@@ -873,14 +857,60 @@ class BasePHP {
|
|
|
873
857
|
const t = getLoadedRuntime(e);
|
|
874
858
|
if (!t)
|
|
875
859
|
throw new Error("Invalid PHP runtime id.");
|
|
876
|
-
this[__private__dont__use] = t,
|
|
877
|
-
|
|
860
|
+
this[__private__dont__use] = t, this[__private__dont__use].ccall(
|
|
861
|
+
"wasm_set_phpini_path",
|
|
862
|
+
null,
|
|
863
|
+
["string"],
|
|
864
|
+
[PHP_INI_PATH]
|
|
865
|
+
), this.fileExists(PHP_INI_PATH) || this.writeFile(
|
|
866
|
+
PHP_INI_PATH,
|
|
867
|
+
[
|
|
868
|
+
"auto_prepend_file=" + AUTO_PREPEND_SCRIPT,
|
|
869
|
+
"memory_limit=256M",
|
|
870
|
+
"ignore_repeated_errors = 1",
|
|
871
|
+
"error_reporting = E_ALL",
|
|
872
|
+
"display_errors = 1",
|
|
873
|
+
"html_errors = 1",
|
|
874
|
+
"display_startup_errors = On",
|
|
875
|
+
"log_errors = 1",
|
|
876
|
+
"always_populate_raw_post_data = -1",
|
|
877
|
+
"upload_max_filesize = 2000M",
|
|
878
|
+
"post_max_size = 2000M",
|
|
879
|
+
"disable_functions = curl_exec,curl_multi_exec",
|
|
880
|
+
"allow_url_fopen = Off",
|
|
881
|
+
"allow_url_include = Off",
|
|
882
|
+
"session.save_path = /home/web_user",
|
|
883
|
+
"implicit_flush = 1",
|
|
884
|
+
"output_buffering = 0",
|
|
885
|
+
"max_execution_time = 0",
|
|
886
|
+
"max_input_time = -1"
|
|
887
|
+
].join(`
|
|
888
|
+
`)
|
|
889
|
+
), this.fileExists(AUTO_PREPEND_SCRIPT) || this.writeFile(
|
|
890
|
+
AUTO_PREPEND_SCRIPT,
|
|
891
|
+
`<?php
|
|
892
|
+
// Define constants set via defineConstant() calls
|
|
893
|
+
if(file_exists('/internal/shared/consts.json')) {
|
|
894
|
+
$consts = json_decode(file_get_contents('/internal/shared/consts.json'), true);
|
|
895
|
+
foreach ($consts as $const => $value) {
|
|
896
|
+
if (!defined($const) && is_scalar($value)) {
|
|
897
|
+
define($const, $value);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
// Preload all the files from /internal/shared/preload
|
|
902
|
+
foreach (glob('/internal/shared/preload/*.php') as $file) {
|
|
903
|
+
require_once $file;
|
|
904
|
+
}
|
|
905
|
+
`
|
|
906
|
+
), t.onMessage = async (r) => {
|
|
907
|
+
for (const s of p(this, P)) {
|
|
878
908
|
const n = await s(r);
|
|
879
909
|
if (n)
|
|
880
910
|
return n;
|
|
881
911
|
}
|
|
882
912
|
return "";
|
|
883
|
-
},
|
|
913
|
+
}, _(this, w, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
884
914
|
type: "runtime.initialized"
|
|
885
915
|
});
|
|
886
916
|
}
|
|
@@ -895,24 +925,7 @@ class BasePHP {
|
|
|
895
925
|
throw new Error(
|
|
896
926
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
897
927
|
);
|
|
898
|
-
|
|
899
|
-
}
|
|
900
|
-
/** @inheritDoc */
|
|
901
|
-
setPhpIniPath(e) {
|
|
902
|
-
if (d(this, y))
|
|
903
|
-
throw new Error("Cannot set PHP ini path after calling run().");
|
|
904
|
-
m(this, E, e), this[__private__dont__use].ccall(
|
|
905
|
-
"wasm_set_phpini_path",
|
|
906
|
-
null,
|
|
907
|
-
["string"],
|
|
908
|
-
[e]
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
/** @inheritDoc */
|
|
912
|
-
setPhpIniEntry(e, t) {
|
|
913
|
-
if (d(this, y))
|
|
914
|
-
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
915
|
-
d(this, P).push([e, t]);
|
|
928
|
+
_(this, E, e);
|
|
916
929
|
}
|
|
917
930
|
/** @inheritDoc */
|
|
918
931
|
chdir(e) {
|
|
@@ -934,20 +947,20 @@ class BasePHP {
|
|
|
934
947
|
const t = await this.semaphore.acquire();
|
|
935
948
|
let r;
|
|
936
949
|
try {
|
|
937
|
-
if (
|
|
950
|
+
if (p(this, g) || (h(this, S, W).call(this), _(this, g, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
938
951
|
throw new Error(
|
|
939
952
|
`The script path "${e.scriptPath}" does not exist.`
|
|
940
953
|
);
|
|
941
|
-
|
|
942
|
-
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443", o =
|
|
943
|
-
|
|
944
|
-
const i =
|
|
954
|
+
h(this, T, q).call(this, e.relativeUri || ""), h(this, H, j).call(this, e.method || "GET");
|
|
955
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443", o = h(this, F, V).call(this, n, e.protocol || "http");
|
|
956
|
+
h(this, k, z).call(this, n), h(this, C, $).call(this, o), h(this, M, G).call(this, s), e.body && (r = h(this, N, J).call(this, e.body)), typeof e.code == "string" ? (this.writeFile("/internal/eval.php", e.code), h(this, b, D).call(this, "/internal/eval.php")) : h(this, b, D).call(this, e.scriptPath || "");
|
|
957
|
+
const i = h(this, R, B).call(this, e.$_SERVER, s, o);
|
|
945
958
|
for (const c in i)
|
|
946
|
-
|
|
959
|
+
h(this, A, Q).call(this, c, i[c]);
|
|
947
960
|
const a = e.env || {};
|
|
948
961
|
for (const c in a)
|
|
949
|
-
|
|
950
|
-
const l = await
|
|
962
|
+
h(this, I, Y).call(this, c, a[c]);
|
|
963
|
+
const l = await h(this, L, Z).call(this);
|
|
951
964
|
if (l.exitCode !== 0) {
|
|
952
965
|
logger.warn("PHP.run() output was:", l.text);
|
|
953
966
|
const c = new PHPExecutionFailureError(
|
|
@@ -979,12 +992,12 @@ class BasePHP {
|
|
|
979
992
|
let r = {};
|
|
980
993
|
try {
|
|
981
994
|
r = JSON.parse(
|
|
982
|
-
this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
|
|
995
|
+
this.fileExists("/internal/shared/consts.json") && this.readFileAsText("/internal/shared/consts.json") || "{}"
|
|
983
996
|
);
|
|
984
997
|
} catch {
|
|
985
998
|
}
|
|
986
999
|
this.writeFile(
|
|
987
|
-
"/internal/consts.json",
|
|
1000
|
+
"/internal/shared/consts.json",
|
|
988
1001
|
JSON.stringify({
|
|
989
1002
|
...r,
|
|
990
1003
|
[e]: t
|
|
@@ -1011,16 +1024,18 @@ class BasePHP {
|
|
|
1011
1024
|
}
|
|
1012
1025
|
/** @inheritDoc */
|
|
1013
1026
|
mv(e, t) {
|
|
1027
|
+
const r = this[__private__dont__use].FS;
|
|
1014
1028
|
try {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1029
|
+
const s = r.lookupPath(e).node.mount, n = this.fileExists(t) ? r.lookupPath(t).node.mount : r.lookupPath(dirname(t)).node.mount;
|
|
1030
|
+
s.mountpoint !== n.mountpoint ? (copyRecursive(r, e, t), this.rmdir(e, { recursive: !0 })) : r.rename(e, t);
|
|
1031
|
+
} catch (s) {
|
|
1032
|
+
const n = getEmscriptenFsError(s);
|
|
1033
|
+
throw n ? new Error(
|
|
1034
|
+
`Could not move ${e} to ${t}: ${n}`,
|
|
1020
1035
|
{
|
|
1021
|
-
cause:
|
|
1036
|
+
cause: s
|
|
1022
1037
|
}
|
|
1023
|
-
) :
|
|
1038
|
+
) : s;
|
|
1024
1039
|
}
|
|
1025
1040
|
}
|
|
1026
1041
|
rmdir(e, t = { recursive: !0 }) {
|
|
@@ -1073,7 +1088,7 @@ class BasePHP {
|
|
|
1073
1088
|
this.exit();
|
|
1074
1089
|
} catch {
|
|
1075
1090
|
}
|
|
1076
|
-
this.initializeRuntime(e),
|
|
1091
|
+
this.initializeRuntime(e), p(this, E) && this.setSapiName(p(this, E)), t && copyFS(r, this[__private__dont__use].FS, t);
|
|
1077
1092
|
}
|
|
1078
1093
|
exit(e = 0) {
|
|
1079
1094
|
this.dispatchEvent({
|
|
@@ -1083,13 +1098,13 @@ class BasePHP {
|
|
|
1083
1098
|
this[__private__dont__use]._exit(e);
|
|
1084
1099
|
} catch {
|
|
1085
1100
|
}
|
|
1086
|
-
|
|
1101
|
+
_(this, g, !1), _(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1087
1102
|
}
|
|
1088
1103
|
[Symbol.dispose]() {
|
|
1089
|
-
|
|
1104
|
+
p(this, g) && this.exit(0);
|
|
1090
1105
|
}
|
|
1091
1106
|
}
|
|
1092
|
-
|
|
1107
|
+
E = new WeakMap(), g = new WeakMap(), w = new WeakMap(), y = new WeakMap(), P = new WeakMap(), R = new WeakSet(), B = function(e, t, r) {
|
|
1093
1108
|
const s = {
|
|
1094
1109
|
...e || {}
|
|
1095
1110
|
};
|
|
@@ -1099,32 +1114,9 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1099
1114
|
["content-type", "content-length"].includes(n.toLowerCase()) && (o = ""), s[`${o}${n.toUpperCase().replace(/-/g, "_")}`] = t[n];
|
|
1100
1115
|
}
|
|
1101
1116
|
return s;
|
|
1102
|
-
},
|
|
1103
|
-
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1104
|
-
"/internal/consts.php",
|
|
1105
|
-
`<?php
|
|
1106
|
-
if(file_exists('/internal/consts.json')) {
|
|
1107
|
-
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
1108
|
-
foreach ($consts as $const => $value) {
|
|
1109
|
-
if (!defined($const) && is_scalar($value)) {
|
|
1110
|
-
define($const, $value);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
}`
|
|
1114
|
-
), d(this, P).length > 0) {
|
|
1115
|
-
const e = d(this, P).map(([t, r]) => `${t}=${r}`).join(`
|
|
1116
|
-
`) + `
|
|
1117
|
-
|
|
1118
|
-
`;
|
|
1119
|
-
this[__private__dont__use].ccall(
|
|
1120
|
-
"wasm_set_phpini_entries",
|
|
1121
|
-
null,
|
|
1122
|
-
[STRING],
|
|
1123
|
-
[e]
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1117
|
+
}, S = new WeakSet(), W = function() {
|
|
1126
1118
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1127
|
-
},
|
|
1119
|
+
}, x = new WeakSet(), U = function() {
|
|
1128
1120
|
const e = "/internal/headers.json";
|
|
1129
1121
|
if (!this.fileExists(e))
|
|
1130
1122
|
throw new Error(
|
|
@@ -1141,7 +1133,7 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1141
1133
|
headers: r,
|
|
1142
1134
|
httpStatusCode: t.status
|
|
1143
1135
|
};
|
|
1144
|
-
},
|
|
1136
|
+
}, T = new WeakSet(), q = function(e) {
|
|
1145
1137
|
if (this[__private__dont__use].ccall(
|
|
1146
1138
|
"wasm_set_request_uri",
|
|
1147
1139
|
null,
|
|
@@ -1156,35 +1148,35 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1156
1148
|
[t]
|
|
1157
1149
|
);
|
|
1158
1150
|
}
|
|
1159
|
-
},
|
|
1151
|
+
}, k = new WeakSet(), z = function(e) {
|
|
1160
1152
|
this[__private__dont__use].ccall(
|
|
1161
1153
|
"wasm_set_request_host",
|
|
1162
1154
|
null,
|
|
1163
1155
|
[STRING],
|
|
1164
1156
|
[e]
|
|
1165
1157
|
);
|
|
1166
|
-
},
|
|
1158
|
+
}, C = new WeakSet(), $ = function(e) {
|
|
1167
1159
|
this[__private__dont__use].ccall(
|
|
1168
1160
|
"wasm_set_request_port",
|
|
1169
1161
|
null,
|
|
1170
1162
|
[NUMBER],
|
|
1171
1163
|
[e]
|
|
1172
1164
|
);
|
|
1173
|
-
},
|
|
1165
|
+
}, F = new WeakSet(), V = function(e, t) {
|
|
1174
1166
|
let r;
|
|
1175
1167
|
try {
|
|
1176
1168
|
r = parseInt(new URL(e).port, 10);
|
|
1177
1169
|
} catch {
|
|
1178
1170
|
}
|
|
1179
1171
|
return (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), r;
|
|
1180
|
-
},
|
|
1172
|
+
}, H = new WeakSet(), j = function(e) {
|
|
1181
1173
|
this[__private__dont__use].ccall(
|
|
1182
1174
|
"wasm_set_request_method",
|
|
1183
1175
|
null,
|
|
1184
1176
|
[STRING],
|
|
1185
1177
|
[e]
|
|
1186
1178
|
);
|
|
1187
|
-
},
|
|
1179
|
+
}, M = new WeakSet(), G = function(e) {
|
|
1188
1180
|
e.cookie && this[__private__dont__use].ccall(
|
|
1189
1181
|
"wasm_set_cookies",
|
|
1190
1182
|
null,
|
|
@@ -1201,7 +1193,7 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1201
1193
|
[NUMBER],
|
|
1202
1194
|
[parseInt(e["content-length"], 10)]
|
|
1203
1195
|
);
|
|
1204
|
-
}, N = new WeakSet(),
|
|
1196
|
+
}, N = new WeakSet(), J = function(e) {
|
|
1205
1197
|
let t, r;
|
|
1206
1198
|
typeof e == "string" ? (logger.warn(
|
|
1207
1199
|
"Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
|
|
@@ -1224,35 +1216,28 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1224
1216
|
[NUMBER],
|
|
1225
1217
|
[r]
|
|
1226
1218
|
), s;
|
|
1227
|
-
},
|
|
1219
|
+
}, b = new WeakSet(), D = function(e) {
|
|
1228
1220
|
this[__private__dont__use].ccall(
|
|
1229
1221
|
"wasm_set_path_translated",
|
|
1230
1222
|
null,
|
|
1231
1223
|
[STRING],
|
|
1232
1224
|
[e]
|
|
1233
1225
|
);
|
|
1234
|
-
},
|
|
1226
|
+
}, A = new WeakSet(), Q = function(e, t) {
|
|
1235
1227
|
this[__private__dont__use].ccall(
|
|
1236
1228
|
"wasm_add_SERVER_entry",
|
|
1237
1229
|
null,
|
|
1238
1230
|
[STRING, STRING],
|
|
1239
1231
|
[e, t]
|
|
1240
1232
|
);
|
|
1241
|
-
},
|
|
1233
|
+
}, I = new WeakSet(), Y = function(e, t) {
|
|
1242
1234
|
this[__private__dont__use].ccall(
|
|
1243
1235
|
"wasm_add_ENV_entry",
|
|
1244
1236
|
null,
|
|
1245
1237
|
[STRING, STRING],
|
|
1246
1238
|
[e, t]
|
|
1247
1239
|
);
|
|
1248
|
-
},
|
|
1249
|
-
this[__private__dont__use].ccall(
|
|
1250
|
-
"wasm_set_php_code",
|
|
1251
|
-
null,
|
|
1252
|
-
[STRING],
|
|
1253
|
-
[e]
|
|
1254
|
-
);
|
|
1255
|
-
}, B = new WeakSet(), te = async function() {
|
|
1240
|
+
}, L = new WeakSet(), Z = async function() {
|
|
1256
1241
|
var n;
|
|
1257
1242
|
let e, t;
|
|
1258
1243
|
try {
|
|
@@ -1260,9 +1245,9 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1260
1245
|
var l;
|
|
1261
1246
|
t = (c) => {
|
|
1262
1247
|
logger.error(c), logger.error(c.error);
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
}, (l =
|
|
1248
|
+
const u = new Error("Rethrown");
|
|
1249
|
+
u.cause = c.error, u.betterMessage = c.message, i(u);
|
|
1250
|
+
}, (l = p(this, w)) == null || l.addEventListener(
|
|
1266
1251
|
"error",
|
|
1267
1252
|
t
|
|
1268
1253
|
);
|
|
@@ -1286,9 +1271,9 @@ P = new WeakMap(), E = new WeakMap(), v = new WeakMap(), y = new WeakMap(), w =
|
|
|
1286
1271
|
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1287
1272
|
throw l.cause = i, logger.error(l), l;
|
|
1288
1273
|
} finally {
|
|
1289
|
-
(n =
|
|
1274
|
+
(n = p(this, w)) == null || n.removeEventListener("error", t);
|
|
1290
1275
|
}
|
|
1291
|
-
const { headers: r, httpStatusCode: s } =
|
|
1276
|
+
const { headers: r, httpStatusCode: s } = h(this, x, U).call(this);
|
|
1292
1277
|
return new PHPResponse(
|
|
1293
1278
|
e === 0 ? s : 500,
|
|
1294
1279
|
r,
|
|
@@ -1351,6 +1336,47 @@ function copyFS(e, t, r) {
|
|
|
1351
1336
|
for (const o of n)
|
|
1352
1337
|
copyFS(e, t, joinPaths(r, o));
|
|
1353
1338
|
}
|
|
1339
|
+
function copyRecursive(e, t, r) {
|
|
1340
|
+
const s = e.lookupPath(t).node;
|
|
1341
|
+
if (e.isDir(s.mode)) {
|
|
1342
|
+
e.mkdirTree(r);
|
|
1343
|
+
const n = e.readdir(t).filter(
|
|
1344
|
+
(o) => o !== "." && o !== ".."
|
|
1345
|
+
);
|
|
1346
|
+
for (const o of n)
|
|
1347
|
+
copyRecursive(
|
|
1348
|
+
e,
|
|
1349
|
+
joinPaths(t, o),
|
|
1350
|
+
joinPaths(r, o)
|
|
1351
|
+
);
|
|
1352
|
+
} else
|
|
1353
|
+
e.writeFile(r, e.readFile(t));
|
|
1354
|
+
}
|
|
1355
|
+
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
1356
|
+
const e = this.getReader();
|
|
1357
|
+
try {
|
|
1358
|
+
for (; ; ) {
|
|
1359
|
+
const { done: t, value: r } = await e.read();
|
|
1360
|
+
if (t)
|
|
1361
|
+
return;
|
|
1362
|
+
yield r;
|
|
1363
|
+
}
|
|
1364
|
+
} finally {
|
|
1365
|
+
e.releaseLock();
|
|
1366
|
+
}
|
|
1367
|
+
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
1368
|
+
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
1369
|
+
const SupportedPHPVersions = [
|
|
1370
|
+
"8.3",
|
|
1371
|
+
"8.2",
|
|
1372
|
+
"8.1",
|
|
1373
|
+
"8.0",
|
|
1374
|
+
"7.4",
|
|
1375
|
+
"7.3",
|
|
1376
|
+
"7.2",
|
|
1377
|
+
"7.1",
|
|
1378
|
+
"7.0"
|
|
1379
|
+
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
1354
1380
|
/**
|
|
1355
1381
|
* @license
|
|
1356
1382
|
* Copyright 2019 Google LLC
|
|
@@ -1402,27 +1428,27 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1402
1428
|
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1403
1429
|
let c;
|
|
1404
1430
|
try {
|
|
1405
|
-
const
|
|
1431
|
+
const u = a.slice(0, -1).reduce((f, v) => f[v], e), m = a.reduce((f, v) => f[v], e);
|
|
1406
1432
|
switch (i) {
|
|
1407
1433
|
case "GET":
|
|
1408
|
-
c =
|
|
1434
|
+
c = m;
|
|
1409
1435
|
break;
|
|
1410
1436
|
case "SET":
|
|
1411
|
-
|
|
1437
|
+
u[a.slice(-1)[0]] = fromWireValue(n.data.value), c = !0;
|
|
1412
1438
|
break;
|
|
1413
1439
|
case "APPLY":
|
|
1414
|
-
c =
|
|
1440
|
+
c = m.apply(u, l);
|
|
1415
1441
|
break;
|
|
1416
1442
|
case "CONSTRUCT":
|
|
1417
1443
|
{
|
|
1418
|
-
const f = new
|
|
1444
|
+
const f = new m(...l);
|
|
1419
1445
|
c = proxy(f);
|
|
1420
1446
|
}
|
|
1421
1447
|
break;
|
|
1422
1448
|
case "ENDPOINT":
|
|
1423
1449
|
{
|
|
1424
|
-
const { port1: f, port2:
|
|
1425
|
-
expose(e,
|
|
1450
|
+
const { port1: f, port2: v } = new MessageChannel();
|
|
1451
|
+
expose(e, v), c = transfer(f, [f]);
|
|
1426
1452
|
}
|
|
1427
1453
|
break;
|
|
1428
1454
|
case "RELEASE":
|
|
@@ -1431,18 +1457,18 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1431
1457
|
default:
|
|
1432
1458
|
return;
|
|
1433
1459
|
}
|
|
1434
|
-
} catch (
|
|
1435
|
-
c = { value:
|
|
1460
|
+
} catch (u) {
|
|
1461
|
+
c = { value: u, [throwMarker]: 0 };
|
|
1436
1462
|
}
|
|
1437
|
-
Promise.resolve(c).catch((
|
|
1438
|
-
const [
|
|
1439
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1440
|
-
}).catch((
|
|
1441
|
-
const [
|
|
1463
|
+
Promise.resolve(c).catch((u) => ({ value: u, [throwMarker]: 0 })).then((u) => {
|
|
1464
|
+
const [m, f] = toWireValue(u);
|
|
1465
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), f), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1466
|
+
}).catch((u) => {
|
|
1467
|
+
const [m, f] = toWireValue({
|
|
1442
1468
|
value: new TypeError("Unserializable return value"),
|
|
1443
1469
|
[throwMarker]: 0
|
|
1444
1470
|
});
|
|
1445
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1471
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), f);
|
|
1446
1472
|
});
|
|
1447
1473
|
}), t.start && t.start();
|
|
1448
1474
|
}
|
|
@@ -1502,7 +1528,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1502
1528
|
const [l, c] = toWireValue(a);
|
|
1503
1529
|
return requestResponseMessage(e, {
|
|
1504
1530
|
type: "SET",
|
|
1505
|
-
path: [...t, i].map((
|
|
1531
|
+
path: [...t, i].map((u) => u.toString()),
|
|
1506
1532
|
value: l
|
|
1507
1533
|
}, c).then(fromWireValue);
|
|
1508
1534
|
},
|
|
@@ -1515,12 +1541,12 @@ function createProxy(e, t = [], r = function() {
|
|
|
1515
1541
|
}).then(fromWireValue);
|
|
1516
1542
|
if (l === "bind")
|
|
1517
1543
|
return createProxy(e, t.slice(0, -1));
|
|
1518
|
-
const [c,
|
|
1544
|
+
const [c, u] = processArguments(a);
|
|
1519
1545
|
return requestResponseMessage(e, {
|
|
1520
1546
|
type: "APPLY",
|
|
1521
|
-
path: t.map((
|
|
1547
|
+
path: t.map((m) => m.toString()),
|
|
1522
1548
|
argumentList: c
|
|
1523
|
-
},
|
|
1549
|
+
}, u).then(fromWireValue);
|
|
1524
1550
|
},
|
|
1525
1551
|
construct(o, i) {
|
|
1526
1552
|
throwIfProxyReleased(s);
|
|
@@ -1644,7 +1670,6 @@ function setupTransferHandlers() {
|
|
|
1644
1670
|
}), transferHandlers.set("FUNCTION", {
|
|
1645
1671
|
canHandle: (r) => typeof r == "function",
|
|
1646
1672
|
serialize(r) {
|
|
1647
|
-
logger.debug("[Comlink][Performance] Proxying a function");
|
|
1648
1673
|
const { port1: s, port2: n } = new MessageChannel();
|
|
1649
1674
|
return expose(r, s), [n, [n]];
|
|
1650
1675
|
},
|
|
@@ -1838,14 +1863,6 @@ class WebPHPEndpoint {
|
|
|
1838
1863
|
setSapiName(t) {
|
|
1839
1864
|
_private.get(this).php.setSapiName(t);
|
|
1840
1865
|
}
|
|
1841
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniPath */
|
|
1842
|
-
setPhpIniPath(t) {
|
|
1843
|
-
return _private.get(this).php.setPhpIniPath(t);
|
|
1844
|
-
}
|
|
1845
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
|
|
1846
|
-
setPhpIniEntry(t, r) {
|
|
1847
|
-
return _private.get(this).php.setPhpIniEntry(t, r);
|
|
1848
|
-
}
|
|
1849
1866
|
/** @inheritDoc @php-wasm/web!WebPHP.mkdir */
|
|
1850
1867
|
mkdir(t) {
|
|
1851
1868
|
return _private.get(this).php.mkdir(t);
|
|
@@ -1914,7 +1931,7 @@ async function registerServiceWorker(e, t, r) {
|
|
|
1914
1931
|
) : new PhpWasmError(
|
|
1915
1932
|
"WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
|
|
1916
1933
|
);
|
|
1917
|
-
|
|
1934
|
+
await (await s.register(r, {
|
|
1918
1935
|
type: "module",
|
|
1919
1936
|
// Always bypass HTTP cache when fetching the new Service Worker script:
|
|
1920
1937
|
updateViaCache: "none"
|