@php-wasm/universal 0.1.46 → 0.1.49
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/lib/universal-php.d.ts +95 -10
- package/package.json +2 -2
package/lib/universal-php.d.ts
CHANGED
|
@@ -58,7 +58,33 @@ export interface RequestHandler {
|
|
|
58
58
|
/**
|
|
59
59
|
* Serves the request – either by serving a static file, or by
|
|
60
60
|
* dispatching it to the PHP runtime.
|
|
61
|
-
*
|
|
61
|
+
*
|
|
62
|
+
* The request() method mode behaves like a web server and only works if
|
|
63
|
+
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
64
|
+
* of WordPress Playground does by default).
|
|
65
|
+
*
|
|
66
|
+
* In the request mode, you pass an object containing the request information
|
|
67
|
+
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* const php = PHP.load('7.4', {
|
|
71
|
+
* requestHandler: {
|
|
72
|
+
* documentRoot: "/www"
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
76
|
+
* const result = await php.run({
|
|
77
|
+
* method: "GET",
|
|
78
|
+
* headers: {
|
|
79
|
+
* "Content-Type": "text/plain"
|
|
80
|
+
* },
|
|
81
|
+
* body: "Hello world!",
|
|
82
|
+
* path: "/www/index.php"
|
|
83
|
+
* });
|
|
84
|
+
* // result.text === "Hello world!"
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
62
88
|
*
|
|
63
89
|
* @example
|
|
64
90
|
* ```js
|
|
@@ -105,7 +131,18 @@ export interface RequestHandler {
|
|
|
105
131
|
documentRoot: string;
|
|
106
132
|
}
|
|
107
133
|
export interface IsomorphicLocalPHP extends RequestHandler {
|
|
134
|
+
/**
|
|
135
|
+
* Sets the path to the php.ini file to use for the PHP instance.
|
|
136
|
+
*
|
|
137
|
+
* @param path - The path to the php.ini file.
|
|
138
|
+
*/
|
|
108
139
|
setPhpIniPath(path: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Sets a value for a specific key in the php.ini file for the PHP instance.
|
|
142
|
+
*
|
|
143
|
+
* @param key - The key to set the value for.
|
|
144
|
+
* @param value - The value to set for the key.
|
|
145
|
+
*/
|
|
109
146
|
setPhpIniEntry(key: string, value: string): void;
|
|
110
147
|
/**
|
|
111
148
|
* Recursively creates a directory with the given path in the PHP filesystem.
|
|
@@ -197,24 +234,72 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
197
234
|
chdir(path: string): void;
|
|
198
235
|
/**
|
|
199
236
|
* Runs PHP code.
|
|
200
|
-
* Cannot be used in conjunction with `cli()`.
|
|
201
237
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
238
|
+
* This low-level method directly interacts with the WebAssembly
|
|
239
|
+
* PHP interpreter.
|
|
240
|
+
*
|
|
241
|
+
* Every time you call run(), it prepares the PHP
|
|
242
|
+
* environment and:
|
|
243
|
+
*
|
|
244
|
+
* * Resets the internal PHP state
|
|
245
|
+
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
246
|
+
* * Handles file uploads
|
|
247
|
+
* * Populates input streams (stdin, argv, etc.)
|
|
248
|
+
* * Sets the current working directory
|
|
249
|
+
*
|
|
250
|
+
* You can use run() in two primary modes:
|
|
251
|
+
*
|
|
252
|
+
* ### Code snippet mode
|
|
253
|
+
*
|
|
254
|
+
* In this mode, you pass a string containing PHP code to run.
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* const result = await php.run({
|
|
258
|
+
* code: `<?php echo "Hello world!";`
|
|
259
|
+
* });
|
|
260
|
+
* // result.text === "Hello world!"
|
|
206
261
|
* ```
|
|
207
262
|
*
|
|
263
|
+
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
264
|
+
* useful because the code is not associated with any file.
|
|
265
|
+
*
|
|
266
|
+
* Under the hood, the PHP snippet is passed to the `zend_eval_string`
|
|
267
|
+
* C function.
|
|
268
|
+
*
|
|
269
|
+
* ### File mode
|
|
270
|
+
*
|
|
271
|
+
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
272
|
+
* found at a that path:
|
|
273
|
+
*
|
|
274
|
+
* ```ts
|
|
275
|
+
* php.writeFile(
|
|
276
|
+
* "/www/index.php",
|
|
277
|
+
* `<?php echo "Hello world!";"`
|
|
278
|
+
* );
|
|
279
|
+
* const result = await php.run({
|
|
280
|
+
* scriptPath: "/www/index.php"
|
|
281
|
+
* });
|
|
282
|
+
* // result.text === "Hello world!"
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* In this mode, you can rely on path-related information like __DIR__
|
|
286
|
+
* or __FILE__.
|
|
287
|
+
*
|
|
288
|
+
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
289
|
+
* C function.
|
|
290
|
+
*
|
|
291
|
+
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
292
|
+
*
|
|
208
293
|
* @example
|
|
209
294
|
* ```js
|
|
210
|
-
*
|
|
295
|
+
* const result = await php.run(`<?php
|
|
211
296
|
* $fp = fopen('php://stderr', 'w');
|
|
212
297
|
* fwrite($fp, "Hello, world!");
|
|
213
|
-
* `)
|
|
214
|
-
* //
|
|
298
|
+
* `);
|
|
299
|
+
* // result.errors === "Hello, world!"
|
|
215
300
|
* ```
|
|
216
301
|
*
|
|
217
|
-
* @param options - PHP
|
|
302
|
+
* @param options - PHP runtime options.
|
|
218
303
|
*/
|
|
219
304
|
run(options: PHPRunOptions): Promise<PHPResponse>;
|
|
220
305
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/universal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"description": "PHP.wasm – emscripten bindings for PHP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"main": "./index.cjs",
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"license": "GPL-2.0-or-later",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "93834fa77a89c21be2ade4c1d67430981ed92c83"
|
|
40
40
|
}
|