@php-wasm/node 0.9.19 → 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/index.d.ts +0 -1024
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
4
4
|
"description": "PHP.wasm for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "GPL-2.0-or-later",
|
|
40
40
|
"types": "index.d.ts",
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "a497916495035caba2f28cfdef75a8a0f3732f0e",
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18.18.0",
|
|
44
44
|
"npm": ">=8.11.0"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"ini": "4.1.2",
|
|
50
50
|
"ws": "8.13.0",
|
|
51
51
|
"yargs": "17.7.2",
|
|
52
|
-
"@php-wasm/node-polyfills": "0.9.
|
|
53
|
-
"@php-wasm/universal": "0.9.
|
|
54
|
-
"@php-wasm/logger": "0.9.
|
|
55
|
-
"@php-wasm/util": "0.9.
|
|
56
|
-
"@wp-playground/common": "0.9.
|
|
52
|
+
"@php-wasm/node-polyfills": "0.9.21",
|
|
53
|
+
"@php-wasm/universal": "0.9.21",
|
|
54
|
+
"@php-wasm/logger": "0.9.21",
|
|
55
|
+
"@php-wasm/util": "0.9.21",
|
|
56
|
+
"@wp-playground/common": "0.9.21"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/index.d.ts
DELETED
|
@@ -1,1024 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v7.2.0
|
|
2
|
-
|
|
3
|
-
export interface PHPResponseData {
|
|
4
|
-
/**
|
|
5
|
-
* Response headers.
|
|
6
|
-
*/
|
|
7
|
-
readonly headers: Record<string, string[]>;
|
|
8
|
-
/**
|
|
9
|
-
* Response body. Contains the output from `echo`,
|
|
10
|
-
* `print`, inline HTML etc.
|
|
11
|
-
*/
|
|
12
|
-
readonly bytes: ArrayBuffer;
|
|
13
|
-
/**
|
|
14
|
-
* Stderr contents, if any.
|
|
15
|
-
*/
|
|
16
|
-
readonly errors: string;
|
|
17
|
-
/**
|
|
18
|
-
* The exit code of the script. `0` is a success, while
|
|
19
|
-
* `1` and `2` indicate an error.
|
|
20
|
-
*/
|
|
21
|
-
readonly exitCode: number;
|
|
22
|
-
/**
|
|
23
|
-
* Response HTTP status code, e.g. 200.
|
|
24
|
-
*/
|
|
25
|
-
readonly httpStatusCode: number;
|
|
26
|
-
}
|
|
27
|
-
declare class PHPResponse implements PHPResponseData {
|
|
28
|
-
/** @inheritDoc */
|
|
29
|
-
readonly headers: Record<string, string[]>;
|
|
30
|
-
/** @inheritDoc */
|
|
31
|
-
readonly bytes: ArrayBuffer;
|
|
32
|
-
/** @inheritDoc */
|
|
33
|
-
readonly errors: string;
|
|
34
|
-
/** @inheritDoc */
|
|
35
|
-
readonly exitCode: number;
|
|
36
|
-
/** @inheritDoc */
|
|
37
|
-
readonly httpStatusCode: number;
|
|
38
|
-
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
39
|
-
static forHttpCode(httpStatusCode: number, text?: string): PHPResponse;
|
|
40
|
-
static fromRawData(data: PHPResponseData): PHPResponse;
|
|
41
|
-
toRawData(): PHPResponseData;
|
|
42
|
-
/**
|
|
43
|
-
* Response body as JSON.
|
|
44
|
-
*/
|
|
45
|
-
get json(): any;
|
|
46
|
-
/**
|
|
47
|
-
* Response body as text.
|
|
48
|
-
*/
|
|
49
|
-
get text(): string;
|
|
50
|
-
}
|
|
51
|
-
export type PHPRuntimeId = number;
|
|
52
|
-
export type PHPRuntime = any;
|
|
53
|
-
export type PHPLoaderModule = {
|
|
54
|
-
dependencyFilename: string;
|
|
55
|
-
dependenciesTotalSize: number;
|
|
56
|
-
init: (jsRuntime: string, options: EmscriptenOptions) => PHPRuntime;
|
|
57
|
-
};
|
|
58
|
-
export type EmscriptenOptions = {
|
|
59
|
-
onAbort?: (message: string) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Set to true for debugging tricky WebAssembly errors.
|
|
62
|
-
*/
|
|
63
|
-
debug?: boolean;
|
|
64
|
-
ENV?: Record<string, string>;
|
|
65
|
-
locateFile?: (path: string) => string;
|
|
66
|
-
noInitialRun?: boolean;
|
|
67
|
-
print?: (message: string) => void;
|
|
68
|
-
printErr?: (message: string) => void;
|
|
69
|
-
quit?: (status: number, toThrow: any) => void;
|
|
70
|
-
onRuntimeInitialized?: () => void;
|
|
71
|
-
monitorRunDependencies?: (left: number) => void;
|
|
72
|
-
onMessage?: (listener: EmscriptenMessageListener) => void;
|
|
73
|
-
instantiateWasm?: (info: WebAssembly.Imports, receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) => void;
|
|
74
|
-
} & Record<string, any>;
|
|
75
|
-
export type EmscriptenMessageListener = (type: string, data: string) => void;
|
|
76
|
-
/** Other WebAssembly declarations, for compatibility with older versions of Typescript */
|
|
77
|
-
export declare namespace Emscripten {
|
|
78
|
-
export interface RootFS extends Emscripten.FileSystemInstance {
|
|
79
|
-
filesystems: Record<string, Emscripten.FileSystemType>;
|
|
80
|
-
}
|
|
81
|
-
export interface FileSystemType {
|
|
82
|
-
mount(mount: FS.Mount): FS.FSNode;
|
|
83
|
-
syncfs(mount: FS.Mount, populate: () => unknown, done: (err?: number | null) => unknown): void;
|
|
84
|
-
}
|
|
85
|
-
export type EnvironmentType = "WEB" | "NODE" | "SHELL" | "WORKER";
|
|
86
|
-
export type JSType = "number" | "string" | "array" | "boolean";
|
|
87
|
-
export type TypeCompatibleWithC = number | string | any[] | boolean;
|
|
88
|
-
export type CIntType = "i8" | "i16" | "i32" | "i64";
|
|
89
|
-
export type CFloatType = "float" | "double";
|
|
90
|
-
export type CPointerType = "i8*" | "i16*" | "i32*" | "i64*" | "float*" | "double*" | "*";
|
|
91
|
-
export type CType = CIntType | CFloatType | CPointerType;
|
|
92
|
-
export interface CCallOpts {
|
|
93
|
-
async?: boolean | undefined;
|
|
94
|
-
}
|
|
95
|
-
type NamespaceToInstance<T> = {
|
|
96
|
-
[K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never;
|
|
97
|
-
};
|
|
98
|
-
export type FileSystemInstance = NamespaceToInstance<typeof FS> & {
|
|
99
|
-
mkdirTree(path: string): void;
|
|
100
|
-
lookupPath(path: string, opts?: any): FS.Lookup;
|
|
101
|
-
};
|
|
102
|
-
export interface EmscriptenModule {
|
|
103
|
-
print(str: string): void;
|
|
104
|
-
printErr(str: string): void;
|
|
105
|
-
arguments: string[];
|
|
106
|
-
environment: Emscripten.EnvironmentType;
|
|
107
|
-
preInit: Array<{
|
|
108
|
-
(): void;
|
|
109
|
-
}>;
|
|
110
|
-
preRun: Array<{
|
|
111
|
-
(): void;
|
|
112
|
-
}>;
|
|
113
|
-
postRun: Array<{
|
|
114
|
-
(): void;
|
|
115
|
-
}>;
|
|
116
|
-
onAbort: {
|
|
117
|
-
(what: any): void;
|
|
118
|
-
};
|
|
119
|
-
onRuntimeInitialized: {
|
|
120
|
-
(): void;
|
|
121
|
-
};
|
|
122
|
-
preinitializedWebGLContext: WebGLRenderingContext;
|
|
123
|
-
noInitialRun: boolean;
|
|
124
|
-
noExitRuntime: boolean;
|
|
125
|
-
logReadFiles: boolean;
|
|
126
|
-
filePackagePrefixURL: string;
|
|
127
|
-
wasmBinary: ArrayBuffer;
|
|
128
|
-
destroy(object: object): void;
|
|
129
|
-
getPreloadedPackage(remotePackageName: string, remotePackageSize: number): ArrayBuffer;
|
|
130
|
-
instantiateWasm(imports: WebAssembly.Imports, successCallback: (module: WebAssembly.Instance) => void): WebAssembly.Exports | undefined;
|
|
131
|
-
locateFile(url: string, scriptDirectory: string): string;
|
|
132
|
-
onCustomMessage(event: MessageEvent): void;
|
|
133
|
-
HEAP: Int32Array;
|
|
134
|
-
IHEAP: Int32Array;
|
|
135
|
-
FHEAP: Float64Array;
|
|
136
|
-
HEAP8: Int8Array;
|
|
137
|
-
HEAP16: Int16Array;
|
|
138
|
-
HEAP32: Int32Array;
|
|
139
|
-
HEAPU8: Uint8Array;
|
|
140
|
-
HEAPU16: Uint16Array;
|
|
141
|
-
HEAPU32: Uint32Array;
|
|
142
|
-
HEAPF32: Float32Array;
|
|
143
|
-
HEAPF64: Float64Array;
|
|
144
|
-
HEAP64: BigInt64Array;
|
|
145
|
-
HEAPU64: BigUint64Array;
|
|
146
|
-
TOTAL_STACK: number;
|
|
147
|
-
TOTAL_MEMORY: number;
|
|
148
|
-
FAST_MEMORY: number;
|
|
149
|
-
addOnPreRun(cb: () => any): void;
|
|
150
|
-
addOnInit(cb: () => any): void;
|
|
151
|
-
addOnPreMain(cb: () => any): void;
|
|
152
|
-
addOnExit(cb: () => any): void;
|
|
153
|
-
addOnPostRun(cb: () => any): void;
|
|
154
|
-
preloadedImages: any;
|
|
155
|
-
preloadedAudios: any;
|
|
156
|
-
_malloc(size: number): number;
|
|
157
|
-
_free(ptr: number): void;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* A factory function is generated when setting the `MODULARIZE` build option
|
|
161
|
-
* to `1` in your Emscripten build. It return a Promise that resolves to an
|
|
162
|
-
* initialized, ready-to-call `EmscriptenModule` instance.
|
|
163
|
-
*
|
|
164
|
-
* By default, the factory function will be named `Module`. It's recommended to
|
|
165
|
-
* use the `EXPORT_ES6` option, in which the factory function will be the
|
|
166
|
-
* default export. If used without `EXPORT_ES6`, the factory function will be a
|
|
167
|
-
* global variable. You can rename the variable using the `EXPORT_NAME` build
|
|
168
|
-
* option. It's left to you to export any global variables as needed in your
|
|
169
|
-
* application's types.
|
|
170
|
-
* @param moduleOverrides Default properties for the initialized module.
|
|
171
|
-
*/
|
|
172
|
-
export type EmscriptenModuleFactory<T extends EmscriptenModule = EmscriptenModule> = (moduleOverrides?: Partial<T>) => Promise<T>;
|
|
173
|
-
export namespace FS {
|
|
174
|
-
interface Lookup {
|
|
175
|
-
path: string;
|
|
176
|
-
node: FSNode;
|
|
177
|
-
}
|
|
178
|
-
interface Analyze {
|
|
179
|
-
isRoot: boolean;
|
|
180
|
-
exists: boolean;
|
|
181
|
-
error: Error;
|
|
182
|
-
name: string;
|
|
183
|
-
path: Lookup["path"];
|
|
184
|
-
object: Lookup["node"];
|
|
185
|
-
parentExists: boolean;
|
|
186
|
-
parentPath: Lookup["path"];
|
|
187
|
-
parentObject: Lookup["node"];
|
|
188
|
-
}
|
|
189
|
-
interface Mount {
|
|
190
|
-
type: Emscripten.FileSystemType;
|
|
191
|
-
opts: object;
|
|
192
|
-
mountpoint: string;
|
|
193
|
-
mounts: Mount[];
|
|
194
|
-
root: FSNode;
|
|
195
|
-
}
|
|
196
|
-
class FSStream {
|
|
197
|
-
constructor();
|
|
198
|
-
object: FSNode;
|
|
199
|
-
readonly isRead: boolean;
|
|
200
|
-
readonly isWrite: boolean;
|
|
201
|
-
readonly isAppend: boolean;
|
|
202
|
-
flags: number;
|
|
203
|
-
position: number;
|
|
204
|
-
}
|
|
205
|
-
class FSNode {
|
|
206
|
-
parent: FSNode;
|
|
207
|
-
mount: Mount;
|
|
208
|
-
mounted?: Mount;
|
|
209
|
-
id: number;
|
|
210
|
-
name: string;
|
|
211
|
-
mode: number;
|
|
212
|
-
rdev: number;
|
|
213
|
-
readMode: number;
|
|
214
|
-
writeMode: number;
|
|
215
|
-
constructor(parent: FSNode, name: string, mode: number, rdev: number);
|
|
216
|
-
read: boolean;
|
|
217
|
-
write: boolean;
|
|
218
|
-
readonly isFolder: boolean;
|
|
219
|
-
readonly isDevice: boolean;
|
|
220
|
-
}
|
|
221
|
-
interface ErrnoError extends Error {
|
|
222
|
-
name: "ErronoError";
|
|
223
|
-
errno: number;
|
|
224
|
-
code: string;
|
|
225
|
-
}
|
|
226
|
-
function lookupPath(path: string, opts: any): Lookup;
|
|
227
|
-
function getPath(node: FSNode): string;
|
|
228
|
-
function analyzePath(path: string, dontResolveLastLink?: boolean): Analyze;
|
|
229
|
-
function isFile(mode: number): boolean;
|
|
230
|
-
function isDir(mode: number): boolean;
|
|
231
|
-
function isLink(mode: number): boolean;
|
|
232
|
-
function isChrdev(mode: number): boolean;
|
|
233
|
-
function isBlkdev(mode: number): boolean;
|
|
234
|
-
function isFIFO(mode: number): boolean;
|
|
235
|
-
function isSocket(mode: number): boolean;
|
|
236
|
-
function major(dev: number): number;
|
|
237
|
-
function minor(dev: number): number;
|
|
238
|
-
function makedev(ma: number, mi: number): number;
|
|
239
|
-
function registerDevice(dev: number, ops: any): void;
|
|
240
|
-
function syncfs(populate: boolean, callback: (e: any) => any): void;
|
|
241
|
-
function syncfs(callback: (e: any) => any, populate?: boolean): void;
|
|
242
|
-
function mount(type: Emscripten.FileSystemType, opts: any, mountpoint: string): any;
|
|
243
|
-
function unmount(mountpoint: string): void;
|
|
244
|
-
function mkdir(path: string, mode?: number): any;
|
|
245
|
-
function mkdev(path: string, mode?: number, dev?: number): any;
|
|
246
|
-
function symlink(oldpath: string, newpath: string): any;
|
|
247
|
-
function rename(old_path: string, new_path: string): void;
|
|
248
|
-
function rmdir(path: string): void;
|
|
249
|
-
function readdir(path: string): any;
|
|
250
|
-
function unlink(path: string): void;
|
|
251
|
-
function readlink(path: string): string;
|
|
252
|
-
function stat(path: string, dontFollow?: boolean): any;
|
|
253
|
-
function lstat(path: string): any;
|
|
254
|
-
function chmod(path: string, mode: number, dontFollow?: boolean): void;
|
|
255
|
-
function lchmod(path: string, mode: number): void;
|
|
256
|
-
function fchmod(fd: number, mode: number): void;
|
|
257
|
-
function chown(path: string, uid: number, gid: number, dontFollow?: boolean): void;
|
|
258
|
-
function lchown(path: string, uid: number, gid: number): void;
|
|
259
|
-
function fchown(fd: number, uid: number, gid: number): void;
|
|
260
|
-
function truncate(path: string, len: number): void;
|
|
261
|
-
function ftruncate(fd: number, len: number): void;
|
|
262
|
-
function utime(path: string, atime: number, mtime: number): void;
|
|
263
|
-
function open(path: string, flags: string, mode?: number, fd_start?: number, fd_end?: number): FSStream;
|
|
264
|
-
function close(stream: FSStream): void;
|
|
265
|
-
function llseek(stream: FSStream, offset: number, whence: number): any;
|
|
266
|
-
function read(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number): number;
|
|
267
|
-
function write(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number, canOwn?: boolean): number;
|
|
268
|
-
function allocate(stream: FSStream, offset: number, length: number): void;
|
|
269
|
-
function mmap(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position: number, prot: number, flags: number): any;
|
|
270
|
-
function ioctl(stream: FSStream, cmd: any, arg: any): any;
|
|
271
|
-
function readFile(path: string, opts: {
|
|
272
|
-
encoding: "binary";
|
|
273
|
-
flags?: string | undefined;
|
|
274
|
-
}): Uint8Array;
|
|
275
|
-
function readFile(path: string, opts: {
|
|
276
|
-
encoding: "utf8";
|
|
277
|
-
flags?: string | undefined;
|
|
278
|
-
}): string;
|
|
279
|
-
function readFile(path: string, opts?: {
|
|
280
|
-
flags?: string | undefined;
|
|
281
|
-
}): Uint8Array;
|
|
282
|
-
function writeFile(path: string, data: string | ArrayBufferView, opts?: {
|
|
283
|
-
flags?: string | undefined;
|
|
284
|
-
}): void;
|
|
285
|
-
function cwd(): string;
|
|
286
|
-
function chdir(path: string): void;
|
|
287
|
-
function init(input: null | (() => number | null), output: null | ((c: number) => any), error: null | ((c: number) => any)): void;
|
|
288
|
-
function createLazyFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean): FSNode;
|
|
289
|
-
function createPreloadedFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean, onload?: () => void, onerror?: () => void, dontCreateFile?: boolean, canOwn?: boolean): void;
|
|
290
|
-
function createDataFile(parent: string | FSNode, name: string, data: ArrayBufferView, canRead: boolean, canWrite: boolean, canOwn: boolean): FSNode;
|
|
291
|
-
}
|
|
292
|
-
export const MEMFS: Emscripten.FileSystemType;
|
|
293
|
-
export const NODEFS: Emscripten.FileSystemType;
|
|
294
|
-
export const IDBFS: Emscripten.FileSystemType;
|
|
295
|
-
type StringToType<R> = R extends Emscripten.JSType ? {
|
|
296
|
-
number: number;
|
|
297
|
-
string: string;
|
|
298
|
-
array: number[] | string[] | boolean[] | Uint8Array | Int8Array;
|
|
299
|
-
boolean: boolean;
|
|
300
|
-
null: null;
|
|
301
|
-
}[R] : never;
|
|
302
|
-
type ArgsToType<T extends Array<Emscripten.JSType | null>> = Extract<{
|
|
303
|
-
[P in keyof T]: StringToType<T[P]>;
|
|
304
|
-
}, any[]>;
|
|
305
|
-
type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null : StringToType<Exclude<R, null>>;
|
|
306
|
-
export function cwrap<I extends Array<Emscripten.JSType | null> | [
|
|
307
|
-
], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, opts?: Emscripten.CCallOpts): (...arg: ArgsToType<I>) => ReturnToType<R>;
|
|
308
|
-
export function ccall<I extends Array<Emscripten.JSType | null> | [
|
|
309
|
-
], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, args: ArgsToType<I>, opts?: Emscripten.CCallOpts): ReturnToType<R>;
|
|
310
|
-
export function setValue(ptr: number, value: any, type: Emscripten.CType, noSafe?: boolean): void;
|
|
311
|
-
export function getValue(ptr: number, type: Emscripten.CType, noSafe?: boolean): number;
|
|
312
|
-
export function allocate(slab: number[] | ArrayBufferView | number, types: Emscripten.CType | Emscripten.CType[], allocator: number, ptr?: number): number;
|
|
313
|
-
export function stackAlloc(size: number): number;
|
|
314
|
-
export function stackSave(): number;
|
|
315
|
-
export function stackRestore(ptr: number): void;
|
|
316
|
-
export function UTF8ToString(ptr: number, maxBytesToRead?: number): string;
|
|
317
|
-
export function stringToUTF8(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
318
|
-
export function lengthBytesUTF8(str: string): number;
|
|
319
|
-
export function allocateUTF8(str: string): number;
|
|
320
|
-
export function allocateUTF8OnStack(str: string): number;
|
|
321
|
-
export function UTF16ToString(ptr: number): string;
|
|
322
|
-
export function stringToUTF16(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
323
|
-
export function lengthBytesUTF16(str: string): number;
|
|
324
|
-
export function UTF32ToString(ptr: number): string;
|
|
325
|
-
export function stringToUTF32(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
326
|
-
export function lengthBytesUTF32(str: string): number;
|
|
327
|
-
export function intArrayFromString(stringy: string, dontAddNull?: boolean, length?: number): number[];
|
|
328
|
-
export function intArrayToString(array: number[]): string;
|
|
329
|
-
export function writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void;
|
|
330
|
-
export function writeArrayToMemory(array: number[], buffer: number): void;
|
|
331
|
-
export function writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void;
|
|
332
|
-
export function addRunDependency(id: any): void;
|
|
333
|
-
export function removeRunDependency(id: any): void;
|
|
334
|
-
export function addFunction(func: (...args: any[]) => any, signature?: string): number;
|
|
335
|
-
export function removeFunction(funcPtr: number): void;
|
|
336
|
-
export const ALLOC_NORMAL: number;
|
|
337
|
-
export const ALLOC_STACK: number;
|
|
338
|
-
export const ALLOC_STATIC: number;
|
|
339
|
-
export const ALLOC_DYNAMIC: number;
|
|
340
|
-
export const ALLOC_NONE: number;
|
|
341
|
-
export {};
|
|
342
|
-
}
|
|
343
|
-
export interface RmDirOptions {
|
|
344
|
-
/**
|
|
345
|
-
* If true, recursively removes the directory and all its contents.
|
|
346
|
-
* Default: true.
|
|
347
|
-
*/
|
|
348
|
-
recursive?: boolean;
|
|
349
|
-
}
|
|
350
|
-
export interface ListFilesOptions {
|
|
351
|
-
/**
|
|
352
|
-
* If true, prepend given folder path to all file names.
|
|
353
|
-
* Default: false.
|
|
354
|
-
*/
|
|
355
|
-
prependPath: boolean;
|
|
356
|
-
}
|
|
357
|
-
export interface SemaphoreOptions {
|
|
358
|
-
/**
|
|
359
|
-
* The maximum number of concurrent locks.
|
|
360
|
-
*/
|
|
361
|
-
concurrency: number;
|
|
362
|
-
/**
|
|
363
|
-
* The maximum time to wait for a lock to become available.
|
|
364
|
-
*/
|
|
365
|
-
timeout?: number;
|
|
366
|
-
}
|
|
367
|
-
declare class Semaphore {
|
|
368
|
-
private _running;
|
|
369
|
-
private concurrency;
|
|
370
|
-
private timeout?;
|
|
371
|
-
private queue;
|
|
372
|
-
constructor({ concurrency, timeout }: SemaphoreOptions);
|
|
373
|
-
get remaining(): number;
|
|
374
|
-
get running(): number;
|
|
375
|
-
acquire(): Promise<() => void>;
|
|
376
|
-
run<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
377
|
-
}
|
|
378
|
-
export type PHPFactoryOptions = {
|
|
379
|
-
isPrimary: boolean;
|
|
380
|
-
};
|
|
381
|
-
export type PHPFactory = (options: PHPFactoryOptions) => Promise<PHP>;
|
|
382
|
-
export interface ProcessManagerOptions {
|
|
383
|
-
/**
|
|
384
|
-
* The maximum number of PHP instances that can exist at
|
|
385
|
-
* the same time.
|
|
386
|
-
*/
|
|
387
|
-
maxPhpInstances?: number;
|
|
388
|
-
/**
|
|
389
|
-
* The number of milliseconds to wait for a PHP instance when
|
|
390
|
-
* we have reached the maximum number of PHP instances and
|
|
391
|
-
* cannot spawn a new one. If the timeout is reached, we assume
|
|
392
|
-
* all the PHP instances are deadlocked and a throw MaxPhpInstancesError.
|
|
393
|
-
*
|
|
394
|
-
* Default: 5000
|
|
395
|
-
*/
|
|
396
|
-
timeout?: number;
|
|
397
|
-
/**
|
|
398
|
-
* The primary PHP instance that's never killed. This instance
|
|
399
|
-
* contains the reference filesystem used by all other PHP instances.
|
|
400
|
-
*/
|
|
401
|
-
primaryPhp?: PHP;
|
|
402
|
-
/**
|
|
403
|
-
* A factory function used for spawning new PHP instances.
|
|
404
|
-
*/
|
|
405
|
-
phpFactory?: PHPFactory;
|
|
406
|
-
}
|
|
407
|
-
export interface SpawnedPHP {
|
|
408
|
-
php: PHP;
|
|
409
|
-
reap: () => void;
|
|
410
|
-
}
|
|
411
|
-
declare class PHPProcessManager implements AsyncDisposable {
|
|
412
|
-
private primaryPhp?;
|
|
413
|
-
private primaryIdle;
|
|
414
|
-
private nextInstance;
|
|
415
|
-
/**
|
|
416
|
-
* All spawned PHP instances, including the primary PHP instance.
|
|
417
|
-
* Used for bookkeeping and reaping all instances on dispose.
|
|
418
|
-
*/
|
|
419
|
-
private allInstances;
|
|
420
|
-
private phpFactory?;
|
|
421
|
-
private maxPhpInstances;
|
|
422
|
-
private semaphore;
|
|
423
|
-
constructor(options?: ProcessManagerOptions);
|
|
424
|
-
/**
|
|
425
|
-
* Get the primary PHP instance.
|
|
426
|
-
*
|
|
427
|
-
* If the primary PHP instance is not set, it will be spawned
|
|
428
|
-
* using the provided phpFactory.
|
|
429
|
-
*
|
|
430
|
-
* @throws {Error} when called twice before the first call is resolved.
|
|
431
|
-
*/
|
|
432
|
-
getPrimaryPhp(): Promise<PHP>;
|
|
433
|
-
/**
|
|
434
|
-
* Get a PHP instance.
|
|
435
|
-
*
|
|
436
|
-
* It could be either the primary PHP instance, an idle disposable PHP instance,
|
|
437
|
-
* or a newly spawned PHP instance – depending on the resource availability.
|
|
438
|
-
*
|
|
439
|
-
* @throws {MaxPhpInstancesError} when the maximum number of PHP instances is reached
|
|
440
|
-
* and the waiting timeout is exceeded.
|
|
441
|
-
*/
|
|
442
|
-
acquirePHPInstance(): Promise<SpawnedPHP>;
|
|
443
|
-
/**
|
|
444
|
-
* Initiated spawning of a new PHP instance.
|
|
445
|
-
* This function is synchronous on purpose – it needs to synchronously
|
|
446
|
-
* add the spawn promise to the allInstances array without waiting
|
|
447
|
-
* for PHP to spawn.
|
|
448
|
-
*/
|
|
449
|
-
private spawn;
|
|
450
|
-
/**
|
|
451
|
-
* Actually acquires the lock and spawns a new PHP instance.
|
|
452
|
-
*/
|
|
453
|
-
private doSpawn;
|
|
454
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
455
|
-
}
|
|
456
|
-
export type RewriteRule = {
|
|
457
|
-
match: RegExp;
|
|
458
|
-
replacement: string;
|
|
459
|
-
};
|
|
460
|
-
export interface BaseConfiguration {
|
|
461
|
-
/**
|
|
462
|
-
* The directory in the PHP filesystem where the server will look
|
|
463
|
-
* for the files to serve. Default: `/var/www`.
|
|
464
|
-
*/
|
|
465
|
-
documentRoot?: string;
|
|
466
|
-
/**
|
|
467
|
-
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
468
|
-
*/
|
|
469
|
-
absoluteUrl?: string;
|
|
470
|
-
/**
|
|
471
|
-
* Rewrite rules
|
|
472
|
-
*/
|
|
473
|
-
rewriteRules?: RewriteRule[];
|
|
474
|
-
}
|
|
475
|
-
export type PHPRequestHandlerFactoryArgs = PHPFactoryOptions & {
|
|
476
|
-
requestHandler: PHPRequestHandler;
|
|
477
|
-
};
|
|
478
|
-
export type PHPRequestHandlerConfiguration = BaseConfiguration & ({
|
|
479
|
-
/**
|
|
480
|
-
* PHPProcessManager is required because the request handler needs
|
|
481
|
-
* to make a decision for each request.
|
|
482
|
-
*
|
|
483
|
-
* Static assets are served using the primary PHP's filesystem, even
|
|
484
|
-
* when serving 100 static files concurrently. No new PHP interpreter
|
|
485
|
-
* is ever created as there's no need for it.
|
|
486
|
-
*
|
|
487
|
-
* Dynamic PHP requests, however, require grabbing an available PHP
|
|
488
|
-
* interpreter, and that's where the PHPProcessManager comes in.
|
|
489
|
-
*/
|
|
490
|
-
processManager: PHPProcessManager;
|
|
491
|
-
} | {
|
|
492
|
-
phpFactory: (requestHandler: PHPRequestHandlerFactoryArgs) => Promise<PHP>;
|
|
493
|
-
/**
|
|
494
|
-
* The maximum number of PHP instances that can exist at
|
|
495
|
-
* the same time.
|
|
496
|
-
*/
|
|
497
|
-
maxPhpInstances?: number;
|
|
498
|
-
});
|
|
499
|
-
declare class PHPRequestHandler {
|
|
500
|
-
#private;
|
|
501
|
-
rewriteRules: RewriteRule[];
|
|
502
|
-
processManager: PHPProcessManager;
|
|
503
|
-
/**
|
|
504
|
-
* The request handler needs to decide whether to serve a static asset or
|
|
505
|
-
* run the PHP interpreter. For static assets it should just reuse the primary
|
|
506
|
-
* PHP even if there's 50 concurrent requests to serve. However, for
|
|
507
|
-
* dynamic PHP requests, it needs to grab an available interpreter.
|
|
508
|
-
* Therefore, it cannot just accept PHP as an argument as serving requests
|
|
509
|
-
* requires access to ProcessManager.
|
|
510
|
-
*
|
|
511
|
-
* @param php - The PHP instance.
|
|
512
|
-
* @param config - Request Handler configuration.
|
|
513
|
-
*/
|
|
514
|
-
constructor(config: PHPRequestHandlerConfiguration);
|
|
515
|
-
getPrimaryPhp(): Promise<PHP>;
|
|
516
|
-
/**
|
|
517
|
-
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
518
|
-
* root.
|
|
519
|
-
*
|
|
520
|
-
* @param path The server path to convert to an absolute URL.
|
|
521
|
-
* @returns The absolute URL.
|
|
522
|
-
*/
|
|
523
|
-
pathToInternalUrl(path: string): string;
|
|
524
|
-
/**
|
|
525
|
-
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
526
|
-
* without the server pathname and scope.
|
|
527
|
-
*
|
|
528
|
-
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
529
|
-
* @returns The relative path.
|
|
530
|
-
*/
|
|
531
|
-
internalUrlToPath(internalUrl: string): string;
|
|
532
|
-
/**
|
|
533
|
-
* The absolute URL of this PHPRequestHandler instance.
|
|
534
|
-
*/
|
|
535
|
-
get absoluteUrl(): string;
|
|
536
|
-
/**
|
|
537
|
-
* The directory in the PHP filesystem where the server will look
|
|
538
|
-
* for the files to serve. Default: `/var/www`.
|
|
539
|
-
*/
|
|
540
|
-
get documentRoot(): string;
|
|
541
|
-
/**
|
|
542
|
-
* Serves the request – either by serving a static file, or by
|
|
543
|
-
* dispatching it to the PHP runtime.
|
|
544
|
-
*
|
|
545
|
-
* The request() method mode behaves like a web server and only works if
|
|
546
|
-
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
547
|
-
* of WordPress Playground does by default).
|
|
548
|
-
*
|
|
549
|
-
* In the request mode, you pass an object containing the request information
|
|
550
|
-
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
551
|
-
*
|
|
552
|
-
* ```ts
|
|
553
|
-
* const php = PHP.load('7.4', {
|
|
554
|
-
* requestHandler: {
|
|
555
|
-
* documentRoot: "/www"
|
|
556
|
-
* }
|
|
557
|
-
* })
|
|
558
|
-
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
559
|
-
* const result = await php.request({
|
|
560
|
-
* method: "GET",
|
|
561
|
-
* headers: {
|
|
562
|
-
* "Content-Type": "text/plain"
|
|
563
|
-
* },
|
|
564
|
-
* body: "Hello world!",
|
|
565
|
-
* path: "/www/index.php"
|
|
566
|
-
* });
|
|
567
|
-
* // result.text === "Hello world!"
|
|
568
|
-
* ```
|
|
569
|
-
*
|
|
570
|
-
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```js
|
|
574
|
-
* const output = await php.request({
|
|
575
|
-
* method: 'GET',
|
|
576
|
-
* url: '/index.php',
|
|
577
|
-
* headers: {
|
|
578
|
-
* 'X-foo': 'bar',
|
|
579
|
-
* },
|
|
580
|
-
* body: {
|
|
581
|
-
* foo: 'bar',
|
|
582
|
-
* },
|
|
583
|
-
* });
|
|
584
|
-
* console.log(output.stdout); // "Hello world!"
|
|
585
|
-
* ```
|
|
586
|
-
*
|
|
587
|
-
* @param request - PHP Request data.
|
|
588
|
-
*/
|
|
589
|
-
request(request: PHPRequest): Promise<PHPResponse>;
|
|
590
|
-
}
|
|
591
|
-
declare const __private__dont__use: unique symbol;
|
|
592
|
-
export type UnmountFunction = (() => Promise<any>) | (() => any);
|
|
593
|
-
export type MountHandler = (php: PHP, FS: Emscripten.RootFS, vfsMountPoint: string) => UnmountFunction | Promise<UnmountFunction>;
|
|
594
|
-
declare class PHP implements Disposable {
|
|
595
|
-
#private;
|
|
596
|
-
protected [__private__dont__use]: any;
|
|
597
|
-
requestHandler?: PHPRequestHandler;
|
|
598
|
-
/**
|
|
599
|
-
* An exclusive lock that prevent multiple requests from running at
|
|
600
|
-
* the same time.
|
|
601
|
-
*/
|
|
602
|
-
semaphore: Semaphore;
|
|
603
|
-
/**
|
|
604
|
-
* Initializes a PHP runtime.
|
|
605
|
-
*
|
|
606
|
-
* @internal
|
|
607
|
-
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
608
|
-
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
609
|
-
*/
|
|
610
|
-
constructor(PHPRuntimeId?: PHPRuntimeId);
|
|
611
|
-
/**
|
|
612
|
-
* Adds an event listener for a PHP event.
|
|
613
|
-
* @param eventType - The type of event to listen for.
|
|
614
|
-
* @param listener - The listener function to be called when the event is triggered.
|
|
615
|
-
*/
|
|
616
|
-
addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
617
|
-
/**
|
|
618
|
-
* Removes an event listener for a PHP event.
|
|
619
|
-
* @param eventType - The type of event to remove the listener from.
|
|
620
|
-
* @param listener - The listener function to be removed.
|
|
621
|
-
*/
|
|
622
|
-
removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
623
|
-
dispatchEvent<Event extends PHPEvent>(event: Event): void;
|
|
624
|
-
/**
|
|
625
|
-
* Listens to message sent by the PHP code.
|
|
626
|
-
*
|
|
627
|
-
* To dispatch messages, call:
|
|
628
|
-
*
|
|
629
|
-
* post_message_to_js(string $data)
|
|
630
|
-
*
|
|
631
|
-
* Arguments:
|
|
632
|
-
* $data (string) – Data to pass to JavaScript.
|
|
633
|
-
*
|
|
634
|
-
* @example
|
|
635
|
-
*
|
|
636
|
-
* ```ts
|
|
637
|
-
* const php = await PHP.load('8.0');
|
|
638
|
-
*
|
|
639
|
-
* php.onMessage(
|
|
640
|
-
* // The data is always passed as a string
|
|
641
|
-
* function (data: string) {
|
|
642
|
-
* // Let's decode and log the data:
|
|
643
|
-
* console.log(JSON.parse(data));
|
|
644
|
-
* }
|
|
645
|
-
* );
|
|
646
|
-
*
|
|
647
|
-
* // Now that we have a listener in place, let's
|
|
648
|
-
* // dispatch a message:
|
|
649
|
-
* await php.run({
|
|
650
|
-
* code: `<?php
|
|
651
|
-
* post_message_to_js(
|
|
652
|
-
* json_encode([
|
|
653
|
-
* 'post_id' => '15',
|
|
654
|
-
* 'post_title' => 'This is a blog post!'
|
|
655
|
-
* ])
|
|
656
|
-
* ));
|
|
657
|
-
* `,
|
|
658
|
-
* });
|
|
659
|
-
* ```
|
|
660
|
-
*
|
|
661
|
-
* @param listener Callback function to handle the message.
|
|
662
|
-
*/
|
|
663
|
-
onMessage(listener: MessageListener): void;
|
|
664
|
-
setSpawnHandler(handler: SpawnHandler | string): Promise<void>;
|
|
665
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
666
|
-
get absoluteUrl(): string;
|
|
667
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
668
|
-
get documentRoot(): string;
|
|
669
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
670
|
-
pathToInternalUrl(path: string): string;
|
|
671
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
672
|
-
internalUrlToPath(internalUrl: string): string;
|
|
673
|
-
initializeRuntime(runtimeId: PHPRuntimeId): void;
|
|
674
|
-
/** @inheritDoc */
|
|
675
|
-
setSapiName(newName: string): Promise<void>;
|
|
676
|
-
/**
|
|
677
|
-
* Changes the current working directory in the PHP filesystem.
|
|
678
|
-
* This is the directory that will be used as the base for relative paths.
|
|
679
|
-
* For example, if the current working directory is `/root/php`, and the
|
|
680
|
-
* path is `data`, the absolute path will be `/root/php/data`.
|
|
681
|
-
*
|
|
682
|
-
* @param path - The new working directory.
|
|
683
|
-
*/
|
|
684
|
-
chdir(path: string): void;
|
|
685
|
-
/**
|
|
686
|
-
* Do not use. Use new PHPRequestHandler() instead.
|
|
687
|
-
* @deprecated
|
|
688
|
-
*/
|
|
689
|
-
request(request: PHPRequest): Promise<PHPResponse>;
|
|
690
|
-
/**
|
|
691
|
-
* Runs PHP code.
|
|
692
|
-
*
|
|
693
|
-
* This low-level method directly interacts with the WebAssembly
|
|
694
|
-
* PHP interpreter.
|
|
695
|
-
*
|
|
696
|
-
* Every time you call run(), it prepares the PHP
|
|
697
|
-
* environment and:
|
|
698
|
-
*
|
|
699
|
-
* * Resets the internal PHP state
|
|
700
|
-
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
701
|
-
* * Handles file uploads
|
|
702
|
-
* * Populates input streams (stdin, argv, etc.)
|
|
703
|
-
* * Sets the current working directory
|
|
704
|
-
*
|
|
705
|
-
* You can use run() in two primary modes:
|
|
706
|
-
*
|
|
707
|
-
* ### Code snippet mode
|
|
708
|
-
*
|
|
709
|
-
* In this mode, you pass a string containing PHP code to run.
|
|
710
|
-
*
|
|
711
|
-
* ```ts
|
|
712
|
-
* const result = await php.run({
|
|
713
|
-
* code: `<?php echo "Hello world!";`
|
|
714
|
-
* });
|
|
715
|
-
* // result.text === "Hello world!"
|
|
716
|
-
* ```
|
|
717
|
-
*
|
|
718
|
-
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
719
|
-
* useful because the code is not associated with any file.
|
|
720
|
-
*
|
|
721
|
-
* Under the hood, the PHP snippet is passed to the `zend_eval_string`
|
|
722
|
-
* C function.
|
|
723
|
-
*
|
|
724
|
-
* ### File mode
|
|
725
|
-
*
|
|
726
|
-
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
727
|
-
* found at a that path:
|
|
728
|
-
*
|
|
729
|
-
* ```ts
|
|
730
|
-
* php.writeFile(
|
|
731
|
-
* "/www/index.php",
|
|
732
|
-
* `<?php echo "Hello world!";"`
|
|
733
|
-
* );
|
|
734
|
-
* const result = await php.run({
|
|
735
|
-
* scriptPath: "/www/index.php"
|
|
736
|
-
* });
|
|
737
|
-
* // result.text === "Hello world!"
|
|
738
|
-
* ```
|
|
739
|
-
*
|
|
740
|
-
* In this mode, you can rely on path-related information like __DIR__
|
|
741
|
-
* or __FILE__.
|
|
742
|
-
*
|
|
743
|
-
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
744
|
-
* C function.
|
|
745
|
-
*
|
|
746
|
-
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
747
|
-
*
|
|
748
|
-
* @example
|
|
749
|
-
* ```js
|
|
750
|
-
* const result = await php.run(`<?php
|
|
751
|
-
* $fp = fopen('php://stderr', 'w');
|
|
752
|
-
* fwrite($fp, "Hello, world!");
|
|
753
|
-
* `);
|
|
754
|
-
* // result.errors === "Hello, world!"
|
|
755
|
-
* ```
|
|
756
|
-
*
|
|
757
|
-
* @param options - PHP runtime options.
|
|
758
|
-
*/
|
|
759
|
-
run(request: PHPRunOptions): Promise<PHPResponse>;
|
|
760
|
-
/**
|
|
761
|
-
* Defines a constant in the PHP runtime.
|
|
762
|
-
* @param key - The name of the constant.
|
|
763
|
-
* @param value - The value of the constant.
|
|
764
|
-
*/
|
|
765
|
-
defineConstant(key: string, value: string | boolean | number | null): void;
|
|
766
|
-
/**
|
|
767
|
-
* Recursively creates a directory with the given path in the PHP filesystem.
|
|
768
|
-
* For example, if the path is `/root/php/data`, and `/root` already exists,
|
|
769
|
-
* it will create the directories `/root/php` and `/root/php/data`.
|
|
770
|
-
*
|
|
771
|
-
* @param path - The directory path to create.
|
|
772
|
-
*/
|
|
773
|
-
mkdir(path: string): void;
|
|
774
|
-
/**
|
|
775
|
-
* @deprecated Use mkdir instead.
|
|
776
|
-
*/
|
|
777
|
-
mkdirTree(path: string): void;
|
|
778
|
-
/**
|
|
779
|
-
* Reads a file from the PHP filesystem and returns it as a string.
|
|
780
|
-
*
|
|
781
|
-
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
782
|
-
* @param path - The file path to read.
|
|
783
|
-
* @returns The file contents.
|
|
784
|
-
*/
|
|
785
|
-
readFileAsText(path: string): string;
|
|
786
|
-
/**
|
|
787
|
-
* Reads a file from the PHP filesystem and returns it as an array buffer.
|
|
788
|
-
*
|
|
789
|
-
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
790
|
-
* @param path - The file path to read.
|
|
791
|
-
* @returns The file contents.
|
|
792
|
-
*/
|
|
793
|
-
readFileAsBuffer(path: string): Uint8Array;
|
|
794
|
-
/**
|
|
795
|
-
* Overwrites data in a file in the PHP filesystem.
|
|
796
|
-
* Creates a new file if one doesn't exist yet.
|
|
797
|
-
*
|
|
798
|
-
* @param path - The file path to write to.
|
|
799
|
-
* @param data - The data to write to the file.
|
|
800
|
-
*/
|
|
801
|
-
writeFile(path: string, data: string | Uint8Array): void;
|
|
802
|
-
/**
|
|
803
|
-
* Removes a file from the PHP filesystem.
|
|
804
|
-
*
|
|
805
|
-
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
806
|
-
* @param path - The file path to remove.
|
|
807
|
-
*/
|
|
808
|
-
unlink(path: string): void;
|
|
809
|
-
/**
|
|
810
|
-
* Moves a file or directory in the PHP filesystem to a
|
|
811
|
-
* new location.
|
|
812
|
-
*
|
|
813
|
-
* @param oldPath The path to rename.
|
|
814
|
-
* @param newPath The new path.
|
|
815
|
-
*/
|
|
816
|
-
mv(fromPath: string, toPath: string): void;
|
|
817
|
-
/**
|
|
818
|
-
* Removes a directory from the PHP filesystem.
|
|
819
|
-
*
|
|
820
|
-
* @param path The directory path to remove.
|
|
821
|
-
* @param options Options for the removal.
|
|
822
|
-
*/
|
|
823
|
-
rmdir(path: string, options?: RmDirOptions): void;
|
|
824
|
-
/**
|
|
825
|
-
* Lists the files and directories in the given directory.
|
|
826
|
-
*
|
|
827
|
-
* @param path - The directory path to list.
|
|
828
|
-
* @param options - Options for the listing.
|
|
829
|
-
* @returns The list of files and directories in the given directory.
|
|
830
|
-
*/
|
|
831
|
-
listFiles(path: string, options?: ListFilesOptions): string[];
|
|
832
|
-
/**
|
|
833
|
-
* Checks if a directory exists in the PHP filesystem.
|
|
834
|
-
*
|
|
835
|
-
* @param path – The path to check.
|
|
836
|
-
* @returns True if the path is a directory, false otherwise.
|
|
837
|
-
*/
|
|
838
|
-
isDir(path: string): boolean;
|
|
839
|
-
/**
|
|
840
|
-
* Checks if a file (or a directory) exists in the PHP filesystem.
|
|
841
|
-
*
|
|
842
|
-
* @param path - The file path to check.
|
|
843
|
-
* @returns True if the file exists, false otherwise.
|
|
844
|
-
*/
|
|
845
|
-
fileExists(path: string): boolean;
|
|
846
|
-
/**
|
|
847
|
-
* Hot-swaps the PHP runtime for a new one without
|
|
848
|
-
* interrupting the operations of this PHP instance.
|
|
849
|
-
*
|
|
850
|
-
* @param runtime
|
|
851
|
-
* @param cwd. Internal, the VFS path to recreate in the new runtime.
|
|
852
|
-
* This arg is temporary and will be removed once BasePHP
|
|
853
|
-
* is fully decoupled from the request handler and
|
|
854
|
-
* accepts a constructor-level cwd argument.
|
|
855
|
-
*/
|
|
856
|
-
hotSwapPHPRuntime(runtime: number, cwd?: string): void;
|
|
857
|
-
/**
|
|
858
|
-
* Mounts a filesystem to a given path in the PHP filesystem.
|
|
859
|
-
*
|
|
860
|
-
* @param virtualFSPath - Where to mount it in the PHP virtual filesystem.
|
|
861
|
-
* @param mountHandler - The mount handler to use.
|
|
862
|
-
* @return Unmount function to unmount the filesystem.
|
|
863
|
-
*/
|
|
864
|
-
mount(virtualFSPath: string, mountHandler: MountHandler): Promise<UnmountFunction>;
|
|
865
|
-
/**
|
|
866
|
-
* Starts a PHP CLI session with given arguments.
|
|
867
|
-
*
|
|
868
|
-
* This method can only be used when PHP was compiled with the CLI SAPI
|
|
869
|
-
* and it cannot be used in conjunction with `run()`.
|
|
870
|
-
*
|
|
871
|
-
* Once this method finishes running, the PHP instance is no
|
|
872
|
-
* longer usable and should be discarded. This is because PHP
|
|
873
|
-
* internally cleans up all the resources and calls exit().
|
|
874
|
-
*
|
|
875
|
-
* @param argv - The arguments to pass to the CLI.
|
|
876
|
-
* @returns The exit code of the CLI session.
|
|
877
|
-
*/
|
|
878
|
-
cli(argv: string[]): Promise<number>;
|
|
879
|
-
setSkipShebang(shouldSkip: boolean): void;
|
|
880
|
-
exit(code?: number): void;
|
|
881
|
-
[Symbol.dispose](): void;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Represents an event related to the PHP request.
|
|
885
|
-
*/
|
|
886
|
-
export interface PHPRequestEndEvent {
|
|
887
|
-
type: "request.end";
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Represents an error event related to the PHP request.
|
|
891
|
-
*/
|
|
892
|
-
export interface PHPRequestErrorEvent {
|
|
893
|
-
type: "request.error";
|
|
894
|
-
error: Error;
|
|
895
|
-
source?: "request" | "php-wasm";
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Represents a PHP runtime initialization event.
|
|
899
|
-
*/
|
|
900
|
-
export interface PHPRuntimeInitializedEvent {
|
|
901
|
-
type: "runtime.initialized";
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Represents a PHP runtime destruction event.
|
|
905
|
-
*/
|
|
906
|
-
export interface PHPRuntimeBeforeDestroyEvent {
|
|
907
|
-
type: "runtime.beforedestroy";
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Represents an event related to the PHP instance.
|
|
911
|
-
* This is intentionally not an extension of CustomEvent
|
|
912
|
-
* to make it isomorphic between different JavaScript runtimes.
|
|
913
|
-
*/
|
|
914
|
-
export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
915
|
-
/**
|
|
916
|
-
* A callback function that handles PHP events.
|
|
917
|
-
*/
|
|
918
|
-
export type PHPEventListener = (event: PHPEvent) => void;
|
|
919
|
-
export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
|
|
920
|
-
export interface EventEmitter {
|
|
921
|
-
on(event: string, listener: (...args: any[]) => void): this;
|
|
922
|
-
emit(event: string, ...args: any[]): boolean;
|
|
923
|
-
}
|
|
924
|
-
export type ChildProcess = EventEmitter & {
|
|
925
|
-
stdout: EventEmitter;
|
|
926
|
-
stderr: EventEmitter;
|
|
927
|
-
};
|
|
928
|
-
export type SpawnHandler = (command: string, args: string[]) => ChildProcess;
|
|
929
|
-
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
930
|
-
export type PHPRequestHeaders = Record<string, string>;
|
|
931
|
-
export interface PHPRequest {
|
|
932
|
-
/**
|
|
933
|
-
* Request method. Default: `GET`.
|
|
934
|
-
*/
|
|
935
|
-
method?: HTTPMethod;
|
|
936
|
-
/**
|
|
937
|
-
* Request path or absolute URL.
|
|
938
|
-
*/
|
|
939
|
-
url: string;
|
|
940
|
-
/**
|
|
941
|
-
* Request headers.
|
|
942
|
-
*/
|
|
943
|
-
headers?: PHPRequestHeaders;
|
|
944
|
-
/**
|
|
945
|
-
* Request body.
|
|
946
|
-
* If an object is given, the request will be encoded as multipart
|
|
947
|
-
* and sent with a `multipart/form-data` header.
|
|
948
|
-
*/
|
|
949
|
-
body?: string | Uint8Array | Record<string, string | Uint8Array | File>;
|
|
950
|
-
}
|
|
951
|
-
export interface PHPRunOptions {
|
|
952
|
-
/**
|
|
953
|
-
* Request path following the domain:port part.
|
|
954
|
-
*/
|
|
955
|
-
relativeUri?: string;
|
|
956
|
-
/**
|
|
957
|
-
* Path of the .php file to execute.
|
|
958
|
-
*/
|
|
959
|
-
scriptPath?: string;
|
|
960
|
-
/**
|
|
961
|
-
* Request protocol.
|
|
962
|
-
*/
|
|
963
|
-
protocol?: string;
|
|
964
|
-
/**
|
|
965
|
-
* Request method. Default: `GET`.
|
|
966
|
-
*/
|
|
967
|
-
method?: HTTPMethod;
|
|
968
|
-
/**
|
|
969
|
-
* Request headers.
|
|
970
|
-
*/
|
|
971
|
-
headers?: PHPRequestHeaders;
|
|
972
|
-
/**
|
|
973
|
-
* Request body.
|
|
974
|
-
*/
|
|
975
|
-
body?: string | Uint8Array;
|
|
976
|
-
/**
|
|
977
|
-
* Environment variables to set for this run.
|
|
978
|
-
*/
|
|
979
|
-
env?: Record<string, string>;
|
|
980
|
-
/**
|
|
981
|
-
* $_SERVER entries to set for this run.
|
|
982
|
-
*/
|
|
983
|
-
$_SERVER?: Record<string, string>;
|
|
984
|
-
/**
|
|
985
|
-
* The code snippet to eval instead of a php file.
|
|
986
|
-
*/
|
|
987
|
-
code?: string;
|
|
988
|
-
}
|
|
989
|
-
declare const SupportedPHPVersions: readonly [
|
|
990
|
-
"8.3",
|
|
991
|
-
"8.2",
|
|
992
|
-
"8.1",
|
|
993
|
-
"8.0",
|
|
994
|
-
"7.4",
|
|
995
|
-
"7.3",
|
|
996
|
-
"7.2",
|
|
997
|
-
"7.1",
|
|
998
|
-
"7.0"
|
|
999
|
-
];
|
|
1000
|
-
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
1001
|
-
export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promise<PHPLoaderModule>;
|
|
1002
|
-
export declare function withNetworking(phpModuleArgs?: EmscriptenOptions): Promise<EmscriptenOptions>;
|
|
1003
|
-
export interface PHPLoaderOptions {
|
|
1004
|
-
emscriptenOptions?: EmscriptenOptions;
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Does what load() does, but synchronously returns
|
|
1008
|
-
* an object with the PHP instance and a promise that
|
|
1009
|
-
* resolves when the PHP instance is ready.
|
|
1010
|
-
*
|
|
1011
|
-
* @see load
|
|
1012
|
-
*/
|
|
1013
|
-
export declare function loadNodeRuntime(phpVersion: SupportedPHPVersion, options?: PHPLoaderOptions): Promise<number>;
|
|
1014
|
-
/**
|
|
1015
|
-
* Enables host filesystem usage by mounting root
|
|
1016
|
-
* directories (e.g. /, /home, /var) into the in-memory
|
|
1017
|
-
* virtual filesystem used by this PHP instance, and
|
|
1018
|
-
* setting the current working directory to one used by
|
|
1019
|
-
* the current node.js process.
|
|
1020
|
-
*/
|
|
1021
|
-
export declare function useHostFilesystem(php: PHP): void;
|
|
1022
|
-
export declare function createNodeFsMountHandler(localPath: string): MountHandler;
|
|
1023
|
-
|
|
1024
|
-
export {};
|