@wp-playground/client 0.1.17 → 0.1.19
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/README.md +38 -4
- package/index.d.ts +393 -161
- package/index.js +1158 -410
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,13 +1,191 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v7.2.0
|
|
2
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
|
+
/**
|
|
28
|
+
* PHP response. Body is an `ArrayBuffer` because it can
|
|
29
|
+
* contain binary data.
|
|
30
|
+
*
|
|
31
|
+
* This type is used in Comlink.transferHandlers.set('PHPResponse', { ... })
|
|
32
|
+
* so be sure to update that if you change this type.
|
|
33
|
+
*/
|
|
34
|
+
export declare class PHPResponse implements PHPResponseData {
|
|
35
|
+
/** @inheritDoc */
|
|
36
|
+
readonly headers: Record<string, string[]>;
|
|
37
|
+
/** @inheritDoc */
|
|
38
|
+
readonly bytes: ArrayBuffer;
|
|
39
|
+
/** @inheritDoc */
|
|
40
|
+
readonly errors: string;
|
|
41
|
+
/** @inheritDoc */
|
|
42
|
+
readonly exitCode: number;
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
readonly httpStatusCode: number;
|
|
45
|
+
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
46
|
+
static fromRawData(data: PHPResponseData): PHPResponse;
|
|
47
|
+
toRawData(): PHPResponseData;
|
|
48
|
+
/**
|
|
49
|
+
* Response body as JSON.
|
|
50
|
+
*/
|
|
51
|
+
get json(): any;
|
|
52
|
+
/**
|
|
53
|
+
* Response body as text.
|
|
54
|
+
*/
|
|
55
|
+
get text(): string;
|
|
56
|
+
}
|
|
57
|
+
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
3
58
|
export type PHPRequestHeaders = Record<string, string>;
|
|
59
|
+
export interface PHPRequest {
|
|
60
|
+
/**
|
|
61
|
+
* Request method. Default: `GET`.
|
|
62
|
+
*/
|
|
63
|
+
method?: HTTPMethod;
|
|
64
|
+
/**
|
|
65
|
+
* Request path or absolute URL.
|
|
66
|
+
*/
|
|
67
|
+
url: string;
|
|
68
|
+
/**
|
|
69
|
+
* Request headers.
|
|
70
|
+
*/
|
|
71
|
+
headers?: PHPRequestHeaders;
|
|
72
|
+
/**
|
|
73
|
+
* Uploaded files
|
|
74
|
+
*/
|
|
75
|
+
files?: Record<string, File>;
|
|
76
|
+
/**
|
|
77
|
+
* Request body without the files.
|
|
78
|
+
*/
|
|
79
|
+
body?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Form data. If set, the request body will be ignored and
|
|
82
|
+
* the content-type header will be set to `application/x-www-form-urlencoded`.
|
|
83
|
+
*/
|
|
84
|
+
formData?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
export interface PHPRequestHandlerConfiguration {
|
|
87
|
+
/**
|
|
88
|
+
* The directory in the PHP filesystem where the server will look
|
|
89
|
+
* for the files to serve. Default: `/var/www`.
|
|
90
|
+
*/
|
|
91
|
+
documentRoot?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
94
|
+
*/
|
|
95
|
+
absoluteUrl?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Callback used by the PHPRequestHandler to decide whether
|
|
98
|
+
* the requested path refers to a PHP file or a static file.
|
|
99
|
+
*/
|
|
100
|
+
isStaticFilePath?: (path: string) => boolean;
|
|
101
|
+
}
|
|
102
|
+
declare class PHPRequestHandler {
|
|
103
|
+
#private;
|
|
104
|
+
/**
|
|
105
|
+
* The PHP instance
|
|
106
|
+
*/
|
|
107
|
+
php: BasePHP;
|
|
108
|
+
/**
|
|
109
|
+
* @param php - The PHP instance.
|
|
110
|
+
* @param config - Request Handler configuration.
|
|
111
|
+
*/
|
|
112
|
+
constructor(php: BasePHP, config?: PHPRequestHandlerConfiguration);
|
|
113
|
+
/**
|
|
114
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
115
|
+
* root.
|
|
116
|
+
*
|
|
117
|
+
* @param path The server path to convert to an absolute URL.
|
|
118
|
+
* @returns The absolute URL.
|
|
119
|
+
*/
|
|
120
|
+
pathToInternalUrl(path: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
123
|
+
* without the server pathname and scope.
|
|
124
|
+
*
|
|
125
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
126
|
+
* @returns The relative path.
|
|
127
|
+
*/
|
|
128
|
+
internalUrlToPath(internalUrl: string): string;
|
|
129
|
+
get isRequestRunning(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
132
|
+
*/
|
|
133
|
+
get absoluteUrl(): string;
|
|
134
|
+
/**
|
|
135
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
136
|
+
*/
|
|
137
|
+
get documentRoot(): string;
|
|
138
|
+
/**
|
|
139
|
+
* Serves the request – either by serving a static file, or by
|
|
140
|
+
* dispatching it to the PHP runtime.
|
|
141
|
+
*
|
|
142
|
+
* @param request - The request.
|
|
143
|
+
* @returns The response.
|
|
144
|
+
*/
|
|
145
|
+
request(request: PHPRequest): Promise<PHPResponse>;
|
|
146
|
+
}
|
|
147
|
+
export interface PHPBrowserConfiguration {
|
|
148
|
+
/**
|
|
149
|
+
* Should handle redirects internally?
|
|
150
|
+
*/
|
|
151
|
+
handleRedirects?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The maximum number of redirects to follow internally. Once
|
|
154
|
+
* exceeded, request() will return the redirecting response.
|
|
155
|
+
*/
|
|
156
|
+
maxRedirects?: number;
|
|
157
|
+
}
|
|
158
|
+
declare class PHPBrowser implements WithRequestHandler {
|
|
159
|
+
#private;
|
|
160
|
+
server: PHPRequestHandler;
|
|
161
|
+
/**
|
|
162
|
+
* @param server - The PHP server to browse.
|
|
163
|
+
* @param config - The browser configuration.
|
|
164
|
+
*/
|
|
165
|
+
constructor(server: PHPRequestHandler, config?: PHPBrowserConfiguration);
|
|
166
|
+
/**
|
|
167
|
+
* Sends the request to the server.
|
|
168
|
+
*
|
|
169
|
+
* When cookies are present in the response, this method stores
|
|
170
|
+
* them and sends them with any subsequent requests.
|
|
171
|
+
*
|
|
172
|
+
* When a redirection is present in the response, this method
|
|
173
|
+
* follows it by discarding a response and sending a subsequent
|
|
174
|
+
* request.
|
|
175
|
+
*
|
|
176
|
+
* @param request - The request.
|
|
177
|
+
* @param redirects - Internal. The number of redirects handled so far.
|
|
178
|
+
* @returns PHPRequestHandler response.
|
|
179
|
+
*/
|
|
180
|
+
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
181
|
+
}
|
|
4
182
|
export interface FileInfo {
|
|
5
183
|
key: string;
|
|
6
184
|
name: string;
|
|
7
185
|
type: string;
|
|
8
186
|
data: Uint8Array;
|
|
9
187
|
}
|
|
10
|
-
export interface
|
|
188
|
+
export interface PHPRunOptions {
|
|
11
189
|
/**
|
|
12
190
|
* Request path following the domain:port part.
|
|
13
191
|
*/
|
|
@@ -23,7 +201,7 @@ export interface PHPRequest {
|
|
|
23
201
|
/**
|
|
24
202
|
* Request method. Default: `GET`.
|
|
25
203
|
*/
|
|
26
|
-
method?:
|
|
204
|
+
method?: HTTPMethod;
|
|
27
205
|
/**
|
|
28
206
|
* Request headers.
|
|
29
207
|
*/
|
|
@@ -41,30 +219,6 @@ export interface PHPRequest {
|
|
|
41
219
|
*/
|
|
42
220
|
code?: string;
|
|
43
221
|
}
|
|
44
|
-
export interface PHPResponse {
|
|
45
|
-
/**
|
|
46
|
-
* The exit code of the script. `0` is a success, while
|
|
47
|
-
* `1` and `2` indicate an error.
|
|
48
|
-
*/
|
|
49
|
-
exitCode: number;
|
|
50
|
-
/**
|
|
51
|
-
* Response body. Contains the output from `echo`,
|
|
52
|
-
* `print`, inline HTML etc.
|
|
53
|
-
*/
|
|
54
|
-
body: ArrayBuffer;
|
|
55
|
-
/**
|
|
56
|
-
* PHP errors.
|
|
57
|
-
*/
|
|
58
|
-
errors: string;
|
|
59
|
-
/**
|
|
60
|
-
* Response headers.
|
|
61
|
-
*/
|
|
62
|
-
headers: Record<string, string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Response HTTP status code, e.g. 200.
|
|
65
|
-
*/
|
|
66
|
-
httpStatusCode: number;
|
|
67
|
-
}
|
|
68
222
|
export type PHPRuntimeId = number;
|
|
69
223
|
export interface WithPHPIniBindings {
|
|
70
224
|
setPhpIniPath(path: string): void;
|
|
@@ -153,21 +307,30 @@ export interface WithFilesystem {
|
|
|
153
307
|
* @returns True if the file exists, false otherwise.
|
|
154
308
|
*/
|
|
155
309
|
fileExists(path: string): boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Changes the current working directory in the PHP filesystem.
|
|
312
|
+
* This is the directory that will be used as the base for relative paths.
|
|
313
|
+
* For example, if the current working directory is `/root/php`, and the
|
|
314
|
+
* path is `data`, the absolute path will be `/root/php/data`.
|
|
315
|
+
*
|
|
316
|
+
* @param path - The new working directory.
|
|
317
|
+
*/
|
|
318
|
+
chdir(path: string): void;
|
|
156
319
|
}
|
|
157
320
|
export interface WithRun {
|
|
158
321
|
/**
|
|
159
|
-
*
|
|
322
|
+
* Runs PHP code.
|
|
160
323
|
* Cannot be used in conjunction with `cli()`.
|
|
161
324
|
*
|
|
162
325
|
* @example
|
|
163
326
|
* ```js
|
|
164
|
-
* const output = php.run('<?php echo "Hello world!";');
|
|
327
|
+
* const output = await php.run('<?php echo "Hello world!";');
|
|
165
328
|
* console.log(output.stdout); // "Hello world!"
|
|
166
329
|
* ```
|
|
167
330
|
*
|
|
168
331
|
* @example
|
|
169
332
|
* ```js
|
|
170
|
-
* console.log(php.run(`<?php
|
|
333
|
+
* console.log(await php.run(`<?php
|
|
171
334
|
* $fp = fopen('php://stderr', 'w');
|
|
172
335
|
* fwrite($fp, "Hello, world!");
|
|
173
336
|
* `));
|
|
@@ -176,33 +339,80 @@ export interface WithRun {
|
|
|
176
339
|
*
|
|
177
340
|
* @param request - PHP Request data.
|
|
178
341
|
*/
|
|
179
|
-
run(request?:
|
|
342
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
180
343
|
}
|
|
344
|
+
export interface WithRequestHandler {
|
|
345
|
+
/**
|
|
346
|
+
* Dispatches a HTTP request using PHP as a backend.
|
|
347
|
+
* Cannot be used in conjunction with `cli()`.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```js
|
|
351
|
+
* const output = await php.request({
|
|
352
|
+
* method: 'GET',
|
|
353
|
+
* url: '/index.php',
|
|
354
|
+
* headers: {
|
|
355
|
+
* 'X-foo': 'bar',
|
|
356
|
+
* },
|
|
357
|
+
* formData: {
|
|
358
|
+
* foo: 'bar',
|
|
359
|
+
* },
|
|
360
|
+
* });
|
|
361
|
+
* console.log(output.stdout); // "Hello world!"
|
|
362
|
+
* ```
|
|
363
|
+
*
|
|
364
|
+
* @param request - PHP Request data.
|
|
365
|
+
*/
|
|
366
|
+
request(request?: PHPRequest): Promise<PHPResponse>;
|
|
367
|
+
}
|
|
368
|
+
export type PHPRuntime = any;
|
|
369
|
+
export type DataModule = {
|
|
370
|
+
dependencyFilename: string;
|
|
371
|
+
dependenciesTotalSize: number;
|
|
372
|
+
default: (phpRuntime: PHPRuntime) => void;
|
|
373
|
+
};
|
|
374
|
+
export type EmscriptenOptions = {
|
|
375
|
+
onAbort?: (message: string) => void;
|
|
376
|
+
ENV?: Record<string, string>;
|
|
377
|
+
locateFile?: (path: string) => string;
|
|
378
|
+
noInitialRun?: boolean;
|
|
379
|
+
dataFileDownloads?: Record<string, number>;
|
|
380
|
+
print?: (message: string) => void;
|
|
381
|
+
printErr?: (message: string) => void;
|
|
382
|
+
onRuntimeInitialized?: () => void;
|
|
383
|
+
monitorRunDependencies?: (left: number) => void;
|
|
384
|
+
} & Record<string, any>;
|
|
181
385
|
export type MountSettings = {
|
|
182
386
|
root: string;
|
|
183
|
-
mountpoint?: string;
|
|
184
387
|
};
|
|
185
|
-
declare class
|
|
388
|
+
declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesystem, WithCLI, WithRequestHandler, WithRun {
|
|
186
389
|
#private;
|
|
390
|
+
requestHandler?: PHPBrowser;
|
|
187
391
|
/**
|
|
188
392
|
* Initializes a PHP runtime.
|
|
189
393
|
*
|
|
190
394
|
* @internal
|
|
191
395
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
396
|
+
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
192
397
|
*/
|
|
193
|
-
constructor(PHPRuntimeId?: PHPRuntimeId);
|
|
398
|
+
constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
|
|
194
399
|
initializeRuntime(runtimeId: PHPRuntimeId): void;
|
|
195
400
|
/** @inheritDoc */
|
|
196
401
|
setPhpIniPath(path: string): void;
|
|
197
402
|
/** @inheritDoc */
|
|
198
403
|
setPhpIniEntry(key: string, value: string): void;
|
|
404
|
+
/** @inheritDoc */
|
|
199
405
|
chdir(path: string): void;
|
|
200
406
|
/** @inheritDoc */
|
|
201
|
-
|
|
407
|
+
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>;
|
|
408
|
+
/** @inheritDoc */
|
|
409
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
202
410
|
cli(argv: string[]): Promise<number>;
|
|
203
411
|
setSkipShebang(shouldSkip: boolean): void;
|
|
204
412
|
addServerGlobalEntry(key: string, value: string): void;
|
|
413
|
+
/** @inheritDoc */
|
|
205
414
|
mkdirTree(path: string): void;
|
|
415
|
+
/** @inheritDoc */
|
|
206
416
|
readFileAsText(path: string): string;
|
|
207
417
|
/** @inheritDoc */
|
|
208
418
|
readFileAsBuffer(path: string): Uint8Array;
|
|
@@ -212,122 +422,25 @@ declare class PHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesys
|
|
|
212
422
|
unlink(path: string): void;
|
|
213
423
|
/** @inheritDoc */
|
|
214
424
|
listFiles(path: string): string[];
|
|
425
|
+
/** @inheritDoc */
|
|
215
426
|
isDir(path: string): boolean;
|
|
427
|
+
/** @inheritDoc */
|
|
216
428
|
fileExists(path: string): boolean;
|
|
429
|
+
/** @inheritDoc */
|
|
217
430
|
mount(settings: MountSettings, path: string): void;
|
|
218
431
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
formData: Record<string, unknown>;
|
|
232
|
-
});
|
|
233
|
-
declare class PHPServer {
|
|
234
|
-
#private;
|
|
235
|
-
/**
|
|
236
|
-
* The PHP instance
|
|
237
|
-
*/
|
|
238
|
-
php: PHP;
|
|
239
|
-
/**
|
|
240
|
-
* @param php - The PHP instance.
|
|
241
|
-
* @param config - Server configuration.
|
|
242
|
-
*/
|
|
243
|
-
constructor(php: PHP, config?: PHPServerConfigation);
|
|
244
|
-
/**
|
|
245
|
-
* Converts a path to an absolute URL based at the PHPServer
|
|
246
|
-
* root.
|
|
247
|
-
*
|
|
248
|
-
* @param path The server path to convert to an absolute URL.
|
|
249
|
-
* @returns The absolute URL.
|
|
250
|
-
*/
|
|
251
|
-
pathToInternalUrl(path: string): string;
|
|
252
|
-
/**
|
|
253
|
-
* Converts an absolute URL based at the PHPServer to a relative path
|
|
254
|
-
* without the server pathname and scope.
|
|
255
|
-
*
|
|
256
|
-
* @param internalUrl An absolute URL based at the PHPServer root.
|
|
257
|
-
* @returns The relative path.
|
|
258
|
-
*/
|
|
259
|
-
internalUrlToPath(internalUrl: string): string;
|
|
260
|
-
/**
|
|
261
|
-
* The absolute URL of this PHPServer instance.
|
|
262
|
-
*/
|
|
263
|
-
get absoluteUrl(): string;
|
|
264
|
-
/**
|
|
265
|
-
* The absolute URL of this PHPServer instance.
|
|
266
|
-
*/
|
|
267
|
-
get documentRoot(): string;
|
|
268
|
-
/**
|
|
269
|
-
* Serves the request – either by serving a static file, or by
|
|
270
|
-
* dispatching it to the PHP runtime.
|
|
271
|
-
*
|
|
272
|
-
* @param request - The request.
|
|
273
|
-
* @returns The response.
|
|
274
|
-
*/
|
|
275
|
-
request(request: PHPServerRequest): Promise<PHPResponse>;
|
|
276
|
-
}
|
|
277
|
-
export interface PHPServerConfigation {
|
|
278
|
-
/**
|
|
279
|
-
* The directory in the PHP filesystem where the server will look
|
|
280
|
-
* for the files to serve. Default: `/var/www`.
|
|
281
|
-
*/
|
|
282
|
-
documentRoot?: string;
|
|
283
|
-
/**
|
|
284
|
-
* Server URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
285
|
-
*/
|
|
286
|
-
absoluteUrl?: string;
|
|
287
|
-
/**
|
|
288
|
-
* Callback used by the PHPServer to decide whether
|
|
289
|
-
* the requested path refers to a PHP file or a static file.
|
|
290
|
-
*/
|
|
291
|
-
isStaticFilePath?: (path: string) => boolean;
|
|
292
|
-
}
|
|
293
|
-
export interface WithRequest {
|
|
294
|
-
/**
|
|
295
|
-
* Sends the request to the server.
|
|
296
|
-
*
|
|
297
|
-
* When cookies are present in the response, this method stores
|
|
298
|
-
* them and sends them with any subsequent requests.
|
|
299
|
-
*
|
|
300
|
-
* When a redirection is present in the response, this method
|
|
301
|
-
* follows it by discarding a response and sending a subsequent
|
|
302
|
-
* request.
|
|
303
|
-
*
|
|
304
|
-
* @param request - The request.
|
|
305
|
-
* @param redirects - Internal. The number of redirects handled so far.
|
|
306
|
-
* @returns PHPServer response.
|
|
307
|
-
*/
|
|
308
|
-
request(request: PHPServerRequest, redirects?: number): Promise<PHPResponse>;
|
|
309
|
-
}
|
|
310
|
-
declare class PHPBrowser implements WithRequest {
|
|
311
|
-
#private;
|
|
312
|
-
server: PHPServer;
|
|
313
|
-
/**
|
|
314
|
-
* @param server - The PHP server to browse.
|
|
315
|
-
* @param config - The browser configuration.
|
|
316
|
-
*/
|
|
317
|
-
constructor(server: PHPServer, config?: PHPBrowserConfiguration);
|
|
318
|
-
request(request: PHPServerRequest, redirects?: number): Promise<PHPResponse>;
|
|
319
|
-
}
|
|
320
|
-
export interface PHPBrowserConfiguration {
|
|
321
|
-
/**
|
|
322
|
-
* Should handle redirects internally?
|
|
323
|
-
*/
|
|
324
|
-
handleRedirects?: boolean;
|
|
325
|
-
/**
|
|
326
|
-
* The maximum number of redirects to follow internally. Once
|
|
327
|
-
* exceeded, request() will return the redirecting response.
|
|
328
|
-
*/
|
|
329
|
-
maxRedirects?: number;
|
|
330
|
-
}
|
|
432
|
+
declare const SupportedPHPVersions: readonly [
|
|
433
|
+
"8.2",
|
|
434
|
+
"8.1",
|
|
435
|
+
"8.0",
|
|
436
|
+
"7.4",
|
|
437
|
+
"7.3",
|
|
438
|
+
"7.2",
|
|
439
|
+
"7.1",
|
|
440
|
+
"7.0",
|
|
441
|
+
"5.6"
|
|
442
|
+
];
|
|
443
|
+
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
331
444
|
export type PublicAPI<Methods, PipedAPI = unknown> = Methods & PipedAPI & {
|
|
332
445
|
isReady: () => Promise<void>;
|
|
333
446
|
};
|
|
@@ -338,7 +451,7 @@ export interface MonitoredModule {
|
|
|
338
451
|
declare class EmscriptenDownloadMonitor extends EventTarget {
|
|
339
452
|
#private;
|
|
340
453
|
constructor(modules?: MonitoredModule[]);
|
|
341
|
-
|
|
454
|
+
getEmscriptenOptions(): {
|
|
342
455
|
dataFileDownloads: Record<string, any>;
|
|
343
456
|
};
|
|
344
457
|
setModules(modules: MonitoredModule[]): void;
|
|
@@ -374,6 +487,39 @@ declare class ProgressObserver extends EventTarget {
|
|
|
374
487
|
slowlyIncrementBy(progress: number): void;
|
|
375
488
|
get totalProgress(): number;
|
|
376
489
|
}
|
|
490
|
+
export interface PHPWebLoaderOptions {
|
|
491
|
+
emscriptenOptions?: EmscriptenOptions;
|
|
492
|
+
downloadMonitor?: EmscriptenDownloadMonitor;
|
|
493
|
+
requestHandler?: PHPRequestHandlerConfiguration;
|
|
494
|
+
dataModules?: Array<DataModule | Promise<DataModule>>;
|
|
495
|
+
}
|
|
496
|
+
declare class PHP extends BasePHP {
|
|
497
|
+
/**
|
|
498
|
+
* Creates a new PHP instance.
|
|
499
|
+
*
|
|
500
|
+
* Dynamically imports the PHP module, initializes the runtime,
|
|
501
|
+
* and sets up networking. It's a shorthand for the lower-level
|
|
502
|
+
* functions like `getPHPLoaderModule`, `loadPHPRuntime`, and
|
|
503
|
+
* `PHP.initializeRuntime`
|
|
504
|
+
*
|
|
505
|
+
* @param phpVersion The PHP Version to load
|
|
506
|
+
* @param options The options to use when loading PHP
|
|
507
|
+
* @returns A new PHP instance
|
|
508
|
+
*/
|
|
509
|
+
static load(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): Promise<PHP>;
|
|
510
|
+
/**
|
|
511
|
+
* Does what load() does, but synchronously returns
|
|
512
|
+
* an object with the PHP instance and a promise that
|
|
513
|
+
* resolves when the PHP instance is ready.
|
|
514
|
+
*
|
|
515
|
+
* @see load
|
|
516
|
+
*/
|
|
517
|
+
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
|
|
518
|
+
php: PHP;
|
|
519
|
+
phpReady: Promise<PHP>;
|
|
520
|
+
dataModules: Promise<DataModule[]>;
|
|
521
|
+
};
|
|
522
|
+
}
|
|
377
523
|
/** @inheritdoc T */
|
|
378
524
|
export type Promisify<T> = {
|
|
379
525
|
[P in keyof T]: T[P] extends (...args: infer A) => infer R ? R extends void | Promise<any> ? T[P] : (...args: A) => Promise<ReturnType<T[P]>> : Promise<T[P]>;
|
|
@@ -385,22 +531,24 @@ export interface WithPathConversion {
|
|
|
385
531
|
export interface WithProgress {
|
|
386
532
|
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
387
533
|
}
|
|
388
|
-
declare class PHPClient implements Promisify<
|
|
389
|
-
/** @inheritDoc @php-wasm/web!
|
|
534
|
+
declare class PHPClient implements Promisify<WithPHPIniBindings & WithFilesystem & WithRun & WithRequestHandler & WithProgress & WithPathConversion> {
|
|
535
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.absoluteUrl */
|
|
390
536
|
absoluteUrl: Promise<string>;
|
|
391
|
-
/** @inheritDoc @php-wasm/web!
|
|
537
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.documentRoot */
|
|
392
538
|
documentRoot: Promise<string>;
|
|
393
539
|
/** @inheritDoc */
|
|
394
|
-
constructor(
|
|
395
|
-
/** @inheritDoc @php-wasm/web!
|
|
540
|
+
constructor(php: BasePHP, monitor?: EmscriptenDownloadMonitor);
|
|
541
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.pathToInternalUrl */
|
|
396
542
|
pathToInternalUrl(path: string): Promise<string>;
|
|
397
|
-
/** @inheritDoc @php-wasm/web!
|
|
543
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.internalUrlToPath */
|
|
398
544
|
internalUrlToPath(internalUrl: string): Promise<string>;
|
|
399
545
|
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
400
|
-
/** @inheritDoc @php-wasm/web!
|
|
401
|
-
request(request:
|
|
546
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.request */
|
|
547
|
+
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
402
548
|
/** @inheritDoc @php-wasm/web!PHP.run */
|
|
403
|
-
run(request?:
|
|
549
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
550
|
+
/** @inheritDoc @php-wasm/web!PHP.chdir */
|
|
551
|
+
chdir(path: string): void;
|
|
404
552
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniPath */
|
|
405
553
|
setPhpIniPath(path: string): void;
|
|
406
554
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
|
|
@@ -426,7 +574,7 @@ declare class PlaygroundWorkerClientClass extends PHPClient {
|
|
|
426
574
|
scope: Promise<string>;
|
|
427
575
|
wordPressVersion: Promise<string>;
|
|
428
576
|
phpVersion: Promise<string>;
|
|
429
|
-
constructor(
|
|
577
|
+
constructor(php: PHP, monitor: EmscriptenDownloadMonitor, scope: string, wordPressVersion: string, phpVersion: string);
|
|
430
578
|
getWordPressModuleDetails(): Promise<{
|
|
431
579
|
staticAssetsDirectory: string;
|
|
432
580
|
defaultTheme: any;
|
|
@@ -449,12 +597,96 @@ export interface PlaygroundClient extends WebClientMixin, PlaygroundWorkerClient
|
|
|
449
597
|
}
|
|
450
598
|
export declare function exportFile(playground: PlaygroundClient): Promise<void>;
|
|
451
599
|
export declare function importFile(playground: PlaygroundClient, file: File): Promise<boolean>;
|
|
600
|
+
/**
|
|
601
|
+
* Logs in to the Playground.
|
|
602
|
+
* Under the hood, this function submits the wp-login.php form
|
|
603
|
+
* just like a user would.
|
|
604
|
+
*
|
|
605
|
+
* @param playground The playground client.
|
|
606
|
+
* @param user The user to log in as. Defaults to 'admin'.
|
|
607
|
+
* @param password The password to log in with. Defaults to 'password'.
|
|
608
|
+
*/
|
|
452
609
|
export declare function login(playground: PlaygroundClient, user?: string, password?: string): Promise<void>;
|
|
453
|
-
export
|
|
454
|
-
|
|
610
|
+
export interface InstallThemeOptions {
|
|
611
|
+
/**
|
|
612
|
+
* Whether to activate the theme after installing it.
|
|
613
|
+
*/
|
|
614
|
+
activate?: boolean;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Installs a WordPress theme in the Playground.
|
|
618
|
+
* Technically, it uses the same theme upload form as a WordPress user
|
|
619
|
+
* would, and then activates the theme if needed.
|
|
620
|
+
*
|
|
621
|
+
* @param playground The playground client.
|
|
622
|
+
* @param themeZipFile The theme zip file.
|
|
623
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the theme.
|
|
624
|
+
*/
|
|
625
|
+
export declare function installTheme(playground: PlaygroundClient, themeZipFile: File, options?: InstallThemeOptions): Promise<void>;
|
|
626
|
+
export interface InstallPluginOptions {
|
|
627
|
+
/**
|
|
628
|
+
* Whether to activate the plugin after installing it.
|
|
629
|
+
*/
|
|
630
|
+
activate?: boolean;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Installs a WordPress plugin in the Playground.
|
|
634
|
+
* Technically, it uses the same plugin upload form as a WordPress user
|
|
635
|
+
* would, and then activates the plugin if needed.
|
|
636
|
+
*
|
|
637
|
+
* @param playground The playground client.
|
|
638
|
+
* @param pluginZipFile The plugin zip file.
|
|
639
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the plugin.
|
|
640
|
+
*/
|
|
641
|
+
export declare function installPlugin(playground: PlaygroundClient, pluginZipFile: File, options?: InstallPluginOptions): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* Activates a WordPress plugin in the Playground.
|
|
644
|
+
*
|
|
645
|
+
* @param playground The playground client.
|
|
646
|
+
* @param plugin The plugin slug.
|
|
647
|
+
*/
|
|
455
648
|
export declare function activatePlugin(playground: PlaygroundClient, plugin: string): Promise<void>;
|
|
649
|
+
/**
|
|
650
|
+
* Downloads and installs a theme from the WordPress.org theme directory.
|
|
651
|
+
* Under the hood, it downloads the themes through a proxy endpoint
|
|
652
|
+
* and installs then one after another using the installTheme function.
|
|
653
|
+
*
|
|
654
|
+
* @see installPlugin
|
|
655
|
+
* @param playground The playground client.
|
|
656
|
+
* @param themeZipName The theme zip file name. For example, set this parameter
|
|
657
|
+
* to "twentytwentythree.1.1.zip" to download the Twenty Twenty Three theme
|
|
658
|
+
* from https://downloads.wordpress.org/theme/twentytwentythree.1.1.zip.
|
|
659
|
+
*
|
|
660
|
+
* @param maxProgress Optional. The maximum progress value to use. Defaults to 100.
|
|
661
|
+
* @param progress Optional. The progress observer that will be notified of the progress.
|
|
662
|
+
*/
|
|
456
663
|
export declare function installThemeFromDirectory(playground: PlaygroundClient, themeZipName: string, progressBudget?: number, progress?: ProgressObserver): Promise<void>;
|
|
457
|
-
|
|
458
|
-
|
|
664
|
+
/**
|
|
665
|
+
* Downloads and installs multiple plugins from the WordPress.org plugin directory.
|
|
666
|
+
* Under the hood, it downloads the plugins through a proxy endpoint
|
|
667
|
+
* and installs then one after another using the installPlugin function.
|
|
668
|
+
*
|
|
669
|
+
* @see installPlugin
|
|
670
|
+
* @param playground The playground client.
|
|
671
|
+
* @param pluginsZipNames The plugin zip file names. For example, set this parameter
|
|
672
|
+
* to ["gutenberg.15.5.0.zip"] to download the Gutenberg plugin
|
|
673
|
+
* from https://downloads.wordpress.org/plugin/gutenberg.15.5.0.zip.
|
|
674
|
+
* @param maxProgress Optional. The maximum progress value to use. Defaults to 100.
|
|
675
|
+
* @param progress Optional. The progress observer that will be notified of the progress.
|
|
676
|
+
*/
|
|
677
|
+
export declare function installPluginsFromDirectory(playground: PlaygroundClient, pluginsZipNames: string[], maxProgress?: number, progress?: ProgressObserver): Promise<void>;
|
|
678
|
+
export interface ConnectPlaygroundOptions {
|
|
679
|
+
loadRemote?: string;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Connects to a playground iframe and returns a PlaygroundClient instance.
|
|
683
|
+
*
|
|
684
|
+
* @param iframe Any iframe with Playground's remote.html loaded.
|
|
685
|
+
* @param options Optional. If `loadRemote` is set, the iframe's `src` will be set to that URL.
|
|
686
|
+
* In other words, use this option if your iframe doesn't have remote.html already
|
|
687
|
+
* loaded.
|
|
688
|
+
* @returns A PlaygroundClient instance.
|
|
689
|
+
*/
|
|
690
|
+
export declare function connectPlayground(iframe: HTMLIFrameElement, options?: ConnectPlaygroundOptions): Promise<PlaygroundClient>;
|
|
459
691
|
|
|
460
692
|
export {};
|