@php-wasm/node 0.1.16 → 0.1.18
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 +10 -13
- package/index.cjs +34 -30
- package/index.d.ts +257 -308
- package/package.json +5 -3
- package/packages/php-wasm/node/README.md +10 -13
- package/php_5_6.wasm +0 -0
- package/php_7_0.wasm +0 -0
- package/php_7_1.wasm +0 -0
- package/php_7_2.wasm +0 -0
- package/php_7_3.wasm +0 -0
- package/php_7_4.wasm +0 -0
- package/php_8_0.wasm +0 -0
- package/php_8_1.wasm +0 -0
- package/php_8_2.wasm +0 -0
package/index.d.ts
CHANGED
|
@@ -1,6 +1,158 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v7.2.0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* PHP response. Body is an `ArrayBuffer` because it can
|
|
5
|
+
* contain binary data.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PHPResponse {
|
|
8
|
+
/**
|
|
9
|
+
* Response headers.
|
|
10
|
+
*/
|
|
11
|
+
readonly headers: Record<string, string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Response body. Contains the output from `echo`,
|
|
14
|
+
* `print`, inline HTML etc.
|
|
15
|
+
*/
|
|
16
|
+
private readonly body;
|
|
17
|
+
/**
|
|
18
|
+
* Stderr contents, if any.
|
|
19
|
+
*/
|
|
20
|
+
readonly errors: string;
|
|
21
|
+
/**
|
|
22
|
+
* The exit code of the script. `0` is a success, while
|
|
23
|
+
* `1` and `2` indicate an error.
|
|
24
|
+
*/
|
|
25
|
+
readonly exitCode: number;
|
|
26
|
+
/**
|
|
27
|
+
* Response HTTP status code, e.g. 200.
|
|
28
|
+
*/
|
|
29
|
+
readonly httpStatusCode: number;
|
|
30
|
+
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Response body as JSON.
|
|
33
|
+
*/
|
|
34
|
+
get json(): any;
|
|
35
|
+
/**
|
|
36
|
+
* Response body as text.
|
|
37
|
+
*/
|
|
38
|
+
get text(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Response body as bytes.
|
|
41
|
+
*/
|
|
42
|
+
get bytes(): ArrayBuffer;
|
|
43
|
+
}
|
|
44
|
+
export type PHPRequest = Pick<PHPRunOptions, "method" | "headers"> & {
|
|
45
|
+
url: string;
|
|
46
|
+
files?: Record<string, File>;
|
|
47
|
+
} & ((Pick<PHPRunOptions, "body"> & {
|
|
48
|
+
formData?: never;
|
|
49
|
+
}) | {
|
|
50
|
+
body?: never;
|
|
51
|
+
formData: Record<string, unknown>;
|
|
52
|
+
});
|
|
53
|
+
export interface PHPRequestHandlerConfiguration {
|
|
54
|
+
/**
|
|
55
|
+
* The directory in the PHP filesystem where the server will look
|
|
56
|
+
* for the files to serve. Default: `/var/www`.
|
|
57
|
+
*/
|
|
58
|
+
documentRoot?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
61
|
+
*/
|
|
62
|
+
absoluteUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Callback used by the PHPRequestHandler to decide whether
|
|
65
|
+
* the requested path refers to a PHP file or a static file.
|
|
66
|
+
*/
|
|
67
|
+
isStaticFilePath?: (path: string) => boolean;
|
|
68
|
+
}
|
|
69
|
+
declare class PHPRequestHandler {
|
|
70
|
+
#private;
|
|
71
|
+
/**
|
|
72
|
+
* The PHP instance
|
|
73
|
+
*/
|
|
74
|
+
php: BasePHP;
|
|
75
|
+
/**
|
|
76
|
+
* @param php - The PHP instance.
|
|
77
|
+
* @param config - Request Handler configuration.
|
|
78
|
+
*/
|
|
79
|
+
constructor(php: BasePHP, config?: PHPRequestHandlerConfiguration);
|
|
80
|
+
/**
|
|
81
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
82
|
+
* root.
|
|
83
|
+
*
|
|
84
|
+
* @param path The server path to convert to an absolute URL.
|
|
85
|
+
* @returns The absolute URL.
|
|
86
|
+
*/
|
|
87
|
+
pathToInternalUrl(path: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
90
|
+
* without the server pathname and scope.
|
|
91
|
+
*
|
|
92
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
93
|
+
* @returns The relative path.
|
|
94
|
+
*/
|
|
95
|
+
internalUrlToPath(internalUrl: string): string;
|
|
96
|
+
get isRequestRunning(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
99
|
+
*/
|
|
100
|
+
get absoluteUrl(): string;
|
|
101
|
+
/**
|
|
102
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
103
|
+
*/
|
|
104
|
+
get documentRoot(): string;
|
|
105
|
+
/**
|
|
106
|
+
* Serves the request – either by serving a static file, or by
|
|
107
|
+
* dispatching it to the PHP runtime.
|
|
108
|
+
*
|
|
109
|
+
* @param request - The request.
|
|
110
|
+
* @returns The response.
|
|
111
|
+
*/
|
|
112
|
+
request(request: PHPRequest): Promise<PHPResponse>;
|
|
113
|
+
}
|
|
114
|
+
export interface PHPBrowserConfiguration {
|
|
115
|
+
/**
|
|
116
|
+
* Should handle redirects internally?
|
|
117
|
+
*/
|
|
118
|
+
handleRedirects?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The maximum number of redirects to follow internally. Once
|
|
121
|
+
* exceeded, request() will return the redirecting response.
|
|
122
|
+
*/
|
|
123
|
+
maxRedirects?: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A fake web browser that handles PHPRequestHandler's cookies and redirects
|
|
127
|
+
* internally without exposing them to the consumer.
|
|
128
|
+
*
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export declare class PHPBrowser implements WithRequestHandler {
|
|
132
|
+
#private;
|
|
133
|
+
server: PHPRequestHandler;
|
|
134
|
+
/**
|
|
135
|
+
* @param server - The PHP server to browse.
|
|
136
|
+
* @param config - The browser configuration.
|
|
137
|
+
*/
|
|
138
|
+
constructor(server: PHPRequestHandler, config?: PHPBrowserConfiguration);
|
|
139
|
+
/**
|
|
140
|
+
* Sends the request to the server.
|
|
141
|
+
*
|
|
142
|
+
* When cookies are present in the response, this method stores
|
|
143
|
+
* them and sends them with any subsequent requests.
|
|
144
|
+
*
|
|
145
|
+
* When a redirection is present in the response, this method
|
|
146
|
+
* follows it by discarding a response and sending a subsequent
|
|
147
|
+
* request.
|
|
148
|
+
*
|
|
149
|
+
* @param request - The request.
|
|
150
|
+
* @param redirects - Internal. The number of redirects handled so far.
|
|
151
|
+
* @returns PHPRequestHandler response.
|
|
152
|
+
*/
|
|
153
|
+
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
154
|
+
}
|
|
155
|
+
export type RuntimeType = "NODE" | "WEB" | "WORKER";
|
|
4
156
|
export type PHPRequestHeaders = Record<string, string>;
|
|
5
157
|
export interface FileInfo {
|
|
6
158
|
key: string;
|
|
@@ -8,7 +160,7 @@ export interface FileInfo {
|
|
|
8
160
|
type: string;
|
|
9
161
|
data: Uint8Array;
|
|
10
162
|
}
|
|
11
|
-
export interface
|
|
163
|
+
export interface PHPRunOptions {
|
|
12
164
|
/**
|
|
13
165
|
* Request path following the domain:port part.
|
|
14
166
|
*/
|
|
@@ -42,149 +194,7 @@ export interface PHPRequest {
|
|
|
42
194
|
*/
|
|
43
195
|
code?: string;
|
|
44
196
|
}
|
|
45
|
-
export interface PHPResponse {
|
|
46
|
-
/**
|
|
47
|
-
* The exit code of the script. `0` is a success, while
|
|
48
|
-
* `1` and `2` indicate an error.
|
|
49
|
-
*/
|
|
50
|
-
exitCode: number;
|
|
51
|
-
/**
|
|
52
|
-
* Response body. Contains the output from `echo`,
|
|
53
|
-
* `print`, inline HTML etc.
|
|
54
|
-
*/
|
|
55
|
-
body: ArrayBuffer;
|
|
56
|
-
/**
|
|
57
|
-
* PHP errors.
|
|
58
|
-
*/
|
|
59
|
-
errors: string;
|
|
60
|
-
/**
|
|
61
|
-
* Response headers.
|
|
62
|
-
*/
|
|
63
|
-
headers: Record<string, string[]>;
|
|
64
|
-
/**
|
|
65
|
-
* Response HTTP status code, e.g. 200.
|
|
66
|
-
*/
|
|
67
|
-
httpStatusCode: number;
|
|
68
|
-
}
|
|
69
197
|
export type PHPRuntimeId = number;
|
|
70
|
-
/**
|
|
71
|
-
* Loads the PHP runtime with the given arguments and data dependencies.
|
|
72
|
-
*
|
|
73
|
-
* This function handles the entire PHP initialization pipeline. In particular, it:
|
|
74
|
-
*
|
|
75
|
-
* * Instantiates the Emscripten PHP module
|
|
76
|
-
* * Wires it together with the data dependencies and loads them
|
|
77
|
-
* * Ensures is all happens in a correct order
|
|
78
|
-
* * Waits until the entire loading sequence is finished
|
|
79
|
-
*
|
|
80
|
-
* Basic usage:
|
|
81
|
-
*
|
|
82
|
-
* ```js
|
|
83
|
-
* const phpLoaderModule = await getPHPLoaderModule("7.4");
|
|
84
|
-
* const php = await loadPHPRuntime( phpLoaderModule );
|
|
85
|
-
* console.log(php.run(`<?php echo "Hello, world!"; `));
|
|
86
|
-
* // { stdout: ArrayBuffer containing the string "Hello, world!", stderr: [''], exitCode: 0 }
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* **The PHP loader module:**
|
|
90
|
-
*
|
|
91
|
-
* In the basic usage example, `phpLoaderModule` is **not** a vanilla Emscripten module. Instead,
|
|
92
|
-
* it's an ESM module that wraps the regular Emscripten output and adds some
|
|
93
|
-
* extra functionality. It's generated by the Dockerfile shipped with this repo.
|
|
94
|
-
* Here's the API it provides:
|
|
95
|
-
*
|
|
96
|
-
* ```js
|
|
97
|
-
* // php.wasm size in bytes:
|
|
98
|
-
* export const dependenciesTotalSize = 5644199;
|
|
99
|
-
*
|
|
100
|
-
* // php.wasm filename:
|
|
101
|
-
* export const dependencyFilename = 'php.wasm';
|
|
102
|
-
*
|
|
103
|
-
* // Run Emscripten's generated module:
|
|
104
|
-
* export default function(jsEnv, emscriptenModuleArgs) {}
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* **PHP Filesystem:**
|
|
108
|
-
*
|
|
109
|
-
* Once initialized, the PHP has its own filesystem separate from the project
|
|
110
|
-
* files. It's provided by [Emscripten and uses its FS library](https://emscripten.org/docs/api_reference/Filesystem-API.html).
|
|
111
|
-
*
|
|
112
|
-
* The API exposed to you via the PHP class is succinct and abstracts
|
|
113
|
-
* await certain unintuitive parts of low-level FS interactions.
|
|
114
|
-
*
|
|
115
|
-
* Here's how to use it:
|
|
116
|
-
*
|
|
117
|
-
* ```js
|
|
118
|
-
* // Recursively create a /var/www directory
|
|
119
|
-
* php.mkdirTree('/var/www');
|
|
120
|
-
*
|
|
121
|
-
* console.log(php.fileExists('/var/www/file.txt'));
|
|
122
|
-
* // false
|
|
123
|
-
*
|
|
124
|
-
* php.writeFile('/var/www/file.txt', 'Hello from the filesystem!');
|
|
125
|
-
*
|
|
126
|
-
* console.log(php.fileExists('/var/www/file.txt'));
|
|
127
|
-
* // true
|
|
128
|
-
*
|
|
129
|
-
* console.log(php.readFile('/var/www/file.txt'));
|
|
130
|
-
* // "Hello from the filesystem!
|
|
131
|
-
*
|
|
132
|
-
* // Delete the file:
|
|
133
|
-
* php.unlink('/var/www/file.txt');
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* For more details consult the PHP class directly.
|
|
137
|
-
*
|
|
138
|
-
* **Data dependencies:**
|
|
139
|
-
*
|
|
140
|
-
* Using existing PHP packages by manually recreating them file-by-file would
|
|
141
|
-
* be quite inconvenient. Fortunately, Emscripten provides a "data dependencies"
|
|
142
|
-
* feature.
|
|
143
|
-
*
|
|
144
|
-
* Data dependencies consist of a `dependency.data` file and a `dependency.js` loader and
|
|
145
|
-
* can be packaged with the [file_packager.py tool]( https://emscripten.org/docs/porting/files/packaging_files.html#packaging-using-the-file-packager-tool).
|
|
146
|
-
* This project requires wrapping the Emscripten-generated `dependency.js` file in an ES
|
|
147
|
-
* module as follows:
|
|
148
|
-
*
|
|
149
|
-
* 1. Prepend `export default function(emscriptenPHPModule) {'; `
|
|
150
|
-
* 2. Prepend `export const dependencyFilename = '<DATA FILE NAME>'; `
|
|
151
|
-
* 3. Prepend `export const dependenciesTotalSize = <DATA FILE SIZE>;`
|
|
152
|
-
* 4. Append `}`
|
|
153
|
-
*
|
|
154
|
-
* Be sure to use the `--export-name="emscriptenPHPModule"` file_packager.py option.
|
|
155
|
-
*
|
|
156
|
-
* You want the final output to look as follows:
|
|
157
|
-
*
|
|
158
|
-
* ```js
|
|
159
|
-
* export const dependenciesTotalSize = 5644199;
|
|
160
|
-
* export const dependencyFilename = 'dependency.data';
|
|
161
|
-
* export default function(emscriptenPHPModule) {
|
|
162
|
-
* // Emscripten-generated code:
|
|
163
|
-
* var Module = typeof emscriptenPHPModule !== 'undefined' ? emscriptenPHPModule : {};
|
|
164
|
-
* // ... the rest of it ...
|
|
165
|
-
* }
|
|
166
|
-
* ```
|
|
167
|
-
*
|
|
168
|
-
* Such a constructions enables loading the `dependency.js` as an ES Module using
|
|
169
|
-
* `import("/dependency.js")`.
|
|
170
|
-
*
|
|
171
|
-
* Once it's ready, you can load PHP and your data dependencies as follows:
|
|
172
|
-
*
|
|
173
|
-
* ```js
|
|
174
|
-
* const [phpLoaderModule, wordPressLoaderModule] = await Promise.all([
|
|
175
|
-
* getPHPLoaderModule("7.4"),
|
|
176
|
-
* import("/wp.js")
|
|
177
|
-
* ]);
|
|
178
|
-
* const php = await loadPHPRuntime(phpLoaderModule, {}, [wordPressLoaderModule]);
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* @public
|
|
182
|
-
* @param phpLoaderModule - The ESM-wrapped Emscripten module. Consult the Dockerfile for the build process.
|
|
183
|
-
* @param phpModuleArgs - The Emscripten module arguments, see https://emscripten.org/docs/api_reference/module.html#affecting-execution.
|
|
184
|
-
* @param dataDependenciesModules - A list of the ESM-wrapped Emscripten data dependency modules.
|
|
185
|
-
* @returns Loaded runtime id.
|
|
186
|
-
*/
|
|
187
|
-
export declare function loadPHPRuntime(phpLoaderModule: PHPLoaderModule, phpModuleArgs?: EmscriptenOptions, dataDependenciesModules?: DataModule[]): Promise<number>;
|
|
188
198
|
export interface WithPHPIniBindings {
|
|
189
199
|
setPhpIniPath(path: string): void;
|
|
190
200
|
setPhpIniEntry(key: string, value: string): void;
|
|
@@ -272,21 +282,30 @@ export interface WithFilesystem {
|
|
|
272
282
|
* @returns True if the file exists, false otherwise.
|
|
273
283
|
*/
|
|
274
284
|
fileExists(path: string): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Changes the current working directory in the PHP filesystem.
|
|
287
|
+
* This is the directory that will be used as the base for relative paths.
|
|
288
|
+
* For example, if the current working directory is `/root/php`, and the
|
|
289
|
+
* path is `data`, the absolute path will be `/root/php/data`.
|
|
290
|
+
*
|
|
291
|
+
* @param path - The new working directory.
|
|
292
|
+
*/
|
|
293
|
+
chdir(path: string): void;
|
|
275
294
|
}
|
|
276
295
|
export interface WithRun {
|
|
277
296
|
/**
|
|
278
|
-
*
|
|
297
|
+
* Runs PHP code.
|
|
279
298
|
* Cannot be used in conjunction with `cli()`.
|
|
280
299
|
*
|
|
281
300
|
* @example
|
|
282
301
|
* ```js
|
|
283
|
-
* const output = php.run('<?php echo "Hello world!";');
|
|
302
|
+
* const output = await php.run('<?php echo "Hello world!";');
|
|
284
303
|
* console.log(output.stdout); // "Hello world!"
|
|
285
304
|
* ```
|
|
286
305
|
*
|
|
287
306
|
* @example
|
|
288
307
|
* ```js
|
|
289
|
-
* console.log(php.run(`<?php
|
|
308
|
+
* console.log(await php.run(`<?php
|
|
290
309
|
* $fp = fopen('php://stderr', 'w');
|
|
291
310
|
* fwrite($fp, "Hello, world!");
|
|
292
311
|
* `));
|
|
@@ -295,13 +314,37 @@ export interface WithRun {
|
|
|
295
314
|
*
|
|
296
315
|
* @param request - PHP Request data.
|
|
297
316
|
*/
|
|
298
|
-
run(request?:
|
|
317
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
318
|
+
}
|
|
319
|
+
export interface WithRequestHandler {
|
|
320
|
+
/**
|
|
321
|
+
* Dispatches a HTTP request using PHP as a backend.
|
|
322
|
+
* Cannot be used in conjunction with `cli()`.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```js
|
|
326
|
+
* const output = await php.request({
|
|
327
|
+
* method: 'GET',
|
|
328
|
+
* url: '/index.php',
|
|
329
|
+
* headers: {
|
|
330
|
+
* 'X-foo': 'bar',
|
|
331
|
+
* },
|
|
332
|
+
* formData: {
|
|
333
|
+
* foo: 'bar',
|
|
334
|
+
* },
|
|
335
|
+
* });
|
|
336
|
+
* console.log(output.stdout); // "Hello world!"
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @param request - PHP Request data.
|
|
340
|
+
*/
|
|
341
|
+
request(request?: PHPRequest): Promise<PHPResponse>;
|
|
299
342
|
}
|
|
300
343
|
export type PHPRuntime = any;
|
|
301
344
|
export type PHPLoaderModule = {
|
|
302
345
|
dependencyFilename: string;
|
|
303
346
|
dependenciesTotalSize: number;
|
|
304
|
-
|
|
347
|
+
init: (jsRuntime: string, options: EmscriptenOptions) => PHPRuntime;
|
|
305
348
|
};
|
|
306
349
|
export type DataModule = {
|
|
307
350
|
dependencyFilename: string;
|
|
@@ -321,39 +364,35 @@ export type EmscriptenOptions = {
|
|
|
321
364
|
} & Record<string, any>;
|
|
322
365
|
export type MountSettings = {
|
|
323
366
|
root: string;
|
|
324
|
-
mountpoint?: string;
|
|
325
367
|
};
|
|
326
|
-
|
|
327
|
-
* An environment-agnostic wrapper around the Emscripten PHP runtime
|
|
328
|
-
* that abstracts the super low-level API and provides a more convenient
|
|
329
|
-
* higher-level API.
|
|
330
|
-
*
|
|
331
|
-
* It exposes a minimal set of methods to run PHP scripts and to
|
|
332
|
-
* interact with the PHP filesystem.
|
|
333
|
-
*
|
|
334
|
-
* @see {startPHP} This class is not meant to be used directly. Use `startPHP` instead.
|
|
335
|
-
*/
|
|
336
|
-
export declare class PHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesystem, WithCLI, WithRun {
|
|
368
|
+
declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesystem, WithCLI, WithRequestHandler, WithRun {
|
|
337
369
|
#private;
|
|
370
|
+
requestHandler?: PHPBrowser;
|
|
338
371
|
/**
|
|
339
372
|
* Initializes a PHP runtime.
|
|
340
373
|
*
|
|
341
374
|
* @internal
|
|
342
375
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
376
|
+
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
343
377
|
*/
|
|
344
|
-
constructor(PHPRuntimeId?: PHPRuntimeId);
|
|
378
|
+
constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
|
|
345
379
|
initializeRuntime(runtimeId: PHPRuntimeId): void;
|
|
346
380
|
/** @inheritDoc */
|
|
347
381
|
setPhpIniPath(path: string): void;
|
|
348
382
|
/** @inheritDoc */
|
|
349
383
|
setPhpIniEntry(key: string, value: string): void;
|
|
384
|
+
/** @inheritDoc */
|
|
350
385
|
chdir(path: string): void;
|
|
351
386
|
/** @inheritDoc */
|
|
352
|
-
|
|
387
|
+
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>;
|
|
388
|
+
/** @inheritDoc */
|
|
389
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
353
390
|
cli(argv: string[]): Promise<number>;
|
|
354
391
|
setSkipShebang(shouldSkip: boolean): void;
|
|
355
392
|
addServerGlobalEntry(key: string, value: string): void;
|
|
393
|
+
/** @inheritDoc */
|
|
356
394
|
mkdirTree(path: string): void;
|
|
395
|
+
/** @inheritDoc */
|
|
357
396
|
readFileAsText(path: string): string;
|
|
358
397
|
/** @inheritDoc */
|
|
359
398
|
readFileAsBuffer(path: string): Uint8Array;
|
|
@@ -363,8 +402,11 @@ export declare class PHP implements WithPHPIniBindings, WithFilesystem, WithNode
|
|
|
363
402
|
unlink(path: string): void;
|
|
364
403
|
/** @inheritDoc */
|
|
365
404
|
listFiles(path: string): string[];
|
|
405
|
+
/** @inheritDoc */
|
|
366
406
|
isDir(path: string): boolean;
|
|
407
|
+
/** @inheritDoc */
|
|
367
408
|
fileExists(path: string): boolean;
|
|
409
|
+
/** @inheritDoc */
|
|
368
410
|
mount(settings: MountSettings, path: string): void;
|
|
369
411
|
}
|
|
370
412
|
/**
|
|
@@ -383,162 +425,69 @@ export interface PHPOutput {
|
|
|
383
425
|
*
|
|
384
426
|
* @see https://emscripten.org/docs/api_reference/Filesystem-API.html
|
|
385
427
|
* @see https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/arch/emscripten/bits/errno.h
|
|
428
|
+
* @see https://github.com/emscripten-core/emscripten/blob/38eedc630f17094b3202fd48ac0c2c585dbea31e/system/include/wasi/api.h#L336
|
|
386
429
|
*/
|
|
387
|
-
export
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
absoluteUrl: string;
|
|
392
|
-
relativeUrl?: never;
|
|
393
|
-
} | {
|
|
394
|
-
absoluteUrl?: never;
|
|
395
|
-
relativeUrl: string;
|
|
396
|
-
}) & ((Pick<PHPRequest, "body"> & {
|
|
397
|
-
formData?: never;
|
|
398
|
-
}) | {
|
|
399
|
-
body?: never;
|
|
400
|
-
formData: Record<string, unknown>;
|
|
401
|
-
});
|
|
402
|
-
/**
|
|
403
|
-
* A fake PHP server that handles HTTP requests but does not
|
|
404
|
-
* bind to any port.
|
|
405
|
-
*
|
|
406
|
-
* @public
|
|
407
|
-
* @example
|
|
408
|
-
* ```js
|
|
409
|
-
* import {
|
|
410
|
-
* loadPHPRuntime,
|
|
411
|
-
* PHP,
|
|
412
|
-
* PHPServer,
|
|
413
|
-
* PHPBrowser,
|
|
414
|
-
* getPHPLoaderModule,
|
|
415
|
-
* } from '@php-wasm/web';
|
|
416
|
-
*
|
|
417
|
-
* const runtime = await loadPHPRuntime( await getPHPLoaderModule('7.4') );
|
|
418
|
-
* const php = new PHP( runtime );
|
|
419
|
-
*
|
|
420
|
-
* php.mkdirTree('/www');
|
|
421
|
-
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; ');
|
|
422
|
-
*
|
|
423
|
-
* const server = new PHPServer(php, {
|
|
424
|
-
* // PHP FS path to serve the files from:
|
|
425
|
-
* documentRoot: '/www',
|
|
426
|
-
*
|
|
427
|
-
* // Used to populate $_SERVER['SERVER_NAME'] etc.:
|
|
428
|
-
* absoluteUrl: 'http://127.0.0.1'
|
|
429
|
-
* });
|
|
430
|
-
*
|
|
431
|
-
* const output = server.request({ path: '/index.php' }).body;
|
|
432
|
-
* console.log(new TextDecoder().decode(output));
|
|
433
|
-
* // "Hi from PHP!"
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
export declare class PHPServer {
|
|
437
|
-
#private;
|
|
438
|
-
/**
|
|
439
|
-
* The PHP instance
|
|
440
|
-
*/
|
|
441
|
-
php: PHP;
|
|
442
|
-
/**
|
|
443
|
-
* @param php - The PHP instance.
|
|
444
|
-
* @param config - Server configuration.
|
|
445
|
-
*/
|
|
446
|
-
constructor(php: PHP, config?: PHPServerConfigation);
|
|
447
|
-
/**
|
|
448
|
-
* Converts a path to an absolute URL based at the PHPServer
|
|
449
|
-
* root.
|
|
450
|
-
*
|
|
451
|
-
* @param path The server path to convert to an absolute URL.
|
|
452
|
-
* @returns The absolute URL.
|
|
453
|
-
*/
|
|
454
|
-
pathToInternalUrl(path: string): string;
|
|
455
|
-
/**
|
|
456
|
-
* Converts an absolute URL based at the PHPServer to a relative path
|
|
457
|
-
* without the server pathname and scope.
|
|
458
|
-
*
|
|
459
|
-
* @param internalUrl An absolute URL based at the PHPServer root.
|
|
460
|
-
* @returns The relative path.
|
|
461
|
-
*/
|
|
462
|
-
internalUrlToPath(internalUrl: string): string;
|
|
463
|
-
/**
|
|
464
|
-
* The absolute URL of this PHPServer instance.
|
|
465
|
-
*/
|
|
466
|
-
get absoluteUrl(): string;
|
|
467
|
-
/**
|
|
468
|
-
* The absolute URL of this PHPServer instance.
|
|
469
|
-
*/
|
|
470
|
-
get documentRoot(): string;
|
|
471
|
-
/**
|
|
472
|
-
* Serves the request – either by serving a static file, or by
|
|
473
|
-
* dispatching it to the PHP runtime.
|
|
474
|
-
*
|
|
475
|
-
* @param request - The request.
|
|
476
|
-
* @returns The response.
|
|
477
|
-
*/
|
|
478
|
-
request(request: PHPServerRequest): Promise<PHPResponse>;
|
|
430
|
+
export interface ErrnoError extends Error {
|
|
431
|
+
node?: any;
|
|
432
|
+
errno: number;
|
|
433
|
+
message: string;
|
|
479
434
|
}
|
|
480
|
-
export
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
435
|
+
export declare const SupportedPHPVersions: readonly [
|
|
436
|
+
"8.2",
|
|
437
|
+
"8.1",
|
|
438
|
+
"8.0",
|
|
439
|
+
"7.4",
|
|
440
|
+
"7.3",
|
|
441
|
+
"7.2",
|
|
442
|
+
"7.1",
|
|
443
|
+
"7.0",
|
|
444
|
+
"5.6"
|
|
445
|
+
];
|
|
446
|
+
export declare const LatestSupportedPHPVersion: "8.2";
|
|
447
|
+
export declare const SupportedPHPVersionsList: string[];
|
|
448
|
+
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
449
|
+
export type WorkerStartupOptions<T extends Record<string, string> = Record<string, string>> = T;
|
|
450
|
+
export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promise<PHPLoaderModule>;
|
|
451
|
+
export declare function parseWorkerStartupOptions(): WorkerStartupOptions;
|
|
452
|
+
export declare function withNetworking(phpModuleArgs?: EmscriptenOptions): Promise<EmscriptenOptions>;
|
|
453
|
+
export interface PHPLoaderOptions {
|
|
454
|
+
emscriptenOptions?: EmscriptenOptions;
|
|
455
|
+
requestHandler?: PHPRequestHandlerConfiguration;
|
|
495
456
|
}
|
|
496
|
-
export
|
|
457
|
+
export declare class PHP extends BasePHP {
|
|
497
458
|
/**
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
* When cookies are present in the response, this method stores
|
|
501
|
-
* them and sends them with any subsequent requests.
|
|
459
|
+
* Creates a new PHP instance.
|
|
502
460
|
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
461
|
+
* Dynamically imports the PHP module, initializes the runtime,
|
|
462
|
+
* and sets up networking. It's a shorthand for the lower-level
|
|
463
|
+
* functions like `getPHPLoaderModule`, `loadPHPRuntime`, and
|
|
464
|
+
* `PHP.initializeRuntime`
|
|
506
465
|
*
|
|
507
|
-
* @param
|
|
508
|
-
* @param
|
|
509
|
-
* @returns
|
|
466
|
+
* @param phpVersion The PHP Version to load
|
|
467
|
+
* @param options The options to use when loading PHP
|
|
468
|
+
* @returns A new PHP instance
|
|
510
469
|
*/
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* A fake web browser that handles PHPServer's cookies and redirects
|
|
515
|
-
* internally without exposing them to the consumer.
|
|
516
|
-
*
|
|
517
|
-
* @public
|
|
518
|
-
*/
|
|
519
|
-
export declare class PHPBrowser implements WithRequest {
|
|
520
|
-
#private;
|
|
521
|
-
server: PHPServer;
|
|
522
|
-
/**
|
|
523
|
-
* @param server - The PHP server to browse.
|
|
524
|
-
* @param config - The browser configuration.
|
|
525
|
-
*/
|
|
526
|
-
constructor(server: PHPServer, config?: PHPBrowserConfiguration);
|
|
527
|
-
request(request: PHPServerRequest, redirects?: number): Promise<PHPResponse>;
|
|
528
|
-
}
|
|
529
|
-
export interface PHPBrowserConfiguration {
|
|
470
|
+
static load(phpVersion: SupportedPHPVersion, options?: PHPLoaderOptions): Promise<PHP>;
|
|
530
471
|
/**
|
|
531
|
-
*
|
|
472
|
+
* Does what load() does, but synchronously returns
|
|
473
|
+
* an object with the PHP instance and a promise that
|
|
474
|
+
* resolves when the PHP instance is ready.
|
|
475
|
+
*
|
|
476
|
+
* @see load
|
|
477
|
+
* @inheritdoc load
|
|
532
478
|
*/
|
|
533
|
-
|
|
479
|
+
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPLoaderOptions): {
|
|
480
|
+
php: PHP;
|
|
481
|
+
phpReady: Promise<PHP>;
|
|
482
|
+
};
|
|
534
483
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
484
|
+
* Enables host filesystem usage by mounting root
|
|
485
|
+
* directories (e.g. /, /home, /var) into the in-memory
|
|
486
|
+
* virtual filesystem used by this PHP instance, and
|
|
487
|
+
* setting the current working directory to one used by
|
|
488
|
+
* the current node.js process.
|
|
537
489
|
*/
|
|
538
|
-
|
|
490
|
+
useHostFilesystem(): void;
|
|
539
491
|
}
|
|
540
|
-
export type WorkerStartupOptions<T extends Record<string, string> = Record<string, string>> = T;
|
|
541
|
-
export declare function getPHPLoaderModule(version?: string): Promise<PHPLoaderModule>;
|
|
542
|
-
export declare function parseWorkerStartupOptions(): WorkerStartupOptions;
|
|
543
492
|
|
|
544
493
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "PHP.wasm for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
"directory": "../../../dist/packages/php-wasm/node"
|
|
21
21
|
},
|
|
22
22
|
"license": "(GPL-2.0-or-later OR MPL-2.0)",
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "2de8f9182b249b7e87694efaa06e7f25b64b7bb3",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"comlink": "4.4.1"
|
|
25
|
+
"comlink": "4.4.1",
|
|
26
|
+
"express": "4.18.2",
|
|
27
|
+
"ws": "8.13.0"
|
|
26
28
|
},
|
|
27
29
|
"main": "index.cjs"
|
|
28
30
|
}
|