@php-wasm/web 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/{index-61d766d5.js → index-40326b86.js} +7 -4
- package/index.d.ts +105 -17
- package/package.json +2 -2
|
@@ -1448,22 +1448,25 @@ class Ge {
|
|
|
1448
1448
|
monitor: r
|
|
1449
1449
|
}), this.absoluteUrl = e.absoluteUrl, this.documentRoot = e.documentRoot;
|
|
1450
1450
|
}
|
|
1451
|
-
/** @inheritDoc */
|
|
1451
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.pathToInternalUrl */
|
|
1452
1452
|
pathToInternalUrl(e) {
|
|
1453
1453
|
return d.get(this).php.pathToInternalUrl(e);
|
|
1454
1454
|
}
|
|
1455
|
-
/** @inheritDoc */
|
|
1455
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.internalUrlToPath */
|
|
1456
1456
|
internalUrlToPath(e) {
|
|
1457
1457
|
return d.get(this).php.internalUrlToPath(e);
|
|
1458
1458
|
}
|
|
1459
|
+
/**
|
|
1460
|
+
* The onDownloadProgress event listener.
|
|
1461
|
+
*/
|
|
1459
1462
|
async onDownloadProgress(e) {
|
|
1460
1463
|
return d.get(this).monitor?.addEventListener("progress", e);
|
|
1461
1464
|
}
|
|
1462
|
-
/** @inheritDoc */
|
|
1465
|
+
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.mv */
|
|
1463
1466
|
mv(e, r) {
|
|
1464
1467
|
return d.get(this).php.mv(e, r);
|
|
1465
1468
|
}
|
|
1466
|
-
/** @inheritDoc */
|
|
1469
|
+
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */
|
|
1467
1470
|
rmdir(e, r) {
|
|
1468
1471
|
return d.get(this).php.rmdir(e, r);
|
|
1469
1472
|
}
|
package/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type WithAPIState = {
|
|
|
15
15
|
*/
|
|
16
16
|
isReady: () => Promise<void>;
|
|
17
17
|
};
|
|
18
|
-
export type RemoteAPI<T> = Comlink.Remote<T & WithAPIState
|
|
18
|
+
export type RemoteAPI<T> = Comlink.Remote<T> & WithAPIState;
|
|
19
19
|
export declare function consumeAPI<APIType>(remote: Worker | Window): RemoteAPI<APIType>;
|
|
20
20
|
export type PublicAPI<Methods, PipedAPI = unknown> = RemoteAPI<Methods & PipedAPI>;
|
|
21
21
|
export declare function exposeAPI<Methods, PipedAPI>(apiMethods?: Methods, pipedApi?: PipedAPI): [
|
|
@@ -127,7 +127,33 @@ export interface RequestHandler {
|
|
|
127
127
|
/**
|
|
128
128
|
* Serves the request – either by serving a static file, or by
|
|
129
129
|
* dispatching it to the PHP runtime.
|
|
130
|
-
*
|
|
130
|
+
*
|
|
131
|
+
* The request() method mode behaves like a web server and only works if
|
|
132
|
+
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
133
|
+
* of WordPress Playground does by default).
|
|
134
|
+
*
|
|
135
|
+
* In the request mode, you pass an object containing the request information
|
|
136
|
+
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* const php = PHP.load('7.4', {
|
|
140
|
+
* requestHandler: {
|
|
141
|
+
* documentRoot: "/www"
|
|
142
|
+
* }
|
|
143
|
+
* })
|
|
144
|
+
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
145
|
+
* const result = await php.run({
|
|
146
|
+
* method: "GET",
|
|
147
|
+
* headers: {
|
|
148
|
+
* "Content-Type": "text/plain"
|
|
149
|
+
* },
|
|
150
|
+
* body: "Hello world!",
|
|
151
|
+
* path: "/www/index.php"
|
|
152
|
+
* });
|
|
153
|
+
* // result.text === "Hello world!"
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
131
157
|
*
|
|
132
158
|
* @example
|
|
133
159
|
* ```js
|
|
@@ -174,7 +200,18 @@ export interface RequestHandler {
|
|
|
174
200
|
documentRoot: string;
|
|
175
201
|
}
|
|
176
202
|
export interface IsomorphicLocalPHP extends RequestHandler {
|
|
203
|
+
/**
|
|
204
|
+
* Sets the path to the php.ini file to use for the PHP instance.
|
|
205
|
+
*
|
|
206
|
+
* @param path - The path to the php.ini file.
|
|
207
|
+
*/
|
|
177
208
|
setPhpIniPath(path: string): void;
|
|
209
|
+
/**
|
|
210
|
+
* Sets a value for a specific key in the php.ini file for the PHP instance.
|
|
211
|
+
*
|
|
212
|
+
* @param key - The key to set the value for.
|
|
213
|
+
* @param value - The value to set for the key.
|
|
214
|
+
*/
|
|
178
215
|
setPhpIniEntry(key: string, value: string): void;
|
|
179
216
|
/**
|
|
180
217
|
* Recursively creates a directory with the given path in the PHP filesystem.
|
|
@@ -266,24 +303,72 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
266
303
|
chdir(path: string): void;
|
|
267
304
|
/**
|
|
268
305
|
* Runs PHP code.
|
|
269
|
-
* Cannot be used in conjunction with `cli()`.
|
|
270
306
|
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
307
|
+
* This low-level method directly interacts with the WebAssembly
|
|
308
|
+
* PHP interpreter.
|
|
309
|
+
*
|
|
310
|
+
* Every time you call run(), it prepares the PHP
|
|
311
|
+
* environment and:
|
|
312
|
+
*
|
|
313
|
+
* * Resets the internal PHP state
|
|
314
|
+
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
315
|
+
* * Handles file uploads
|
|
316
|
+
* * Populates input streams (stdin, argv, etc.)
|
|
317
|
+
* * Sets the current working directory
|
|
318
|
+
*
|
|
319
|
+
* You can use run() in two primary modes:
|
|
320
|
+
*
|
|
321
|
+
* ### Code snippet mode
|
|
322
|
+
*
|
|
323
|
+
* In this mode, you pass a string containing PHP code to run.
|
|
324
|
+
*
|
|
325
|
+
* ```ts
|
|
326
|
+
* const result = await php.run({
|
|
327
|
+
* code: `<?php echo "Hello world!";`
|
|
328
|
+
* });
|
|
329
|
+
* // result.text === "Hello world!"
|
|
275
330
|
* ```
|
|
276
331
|
*
|
|
332
|
+
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
333
|
+
* useful because the code is not associated with any file.
|
|
334
|
+
*
|
|
335
|
+
* Under the hood, the PHP snippet is passed to the `zend_eval_string`
|
|
336
|
+
* C function.
|
|
337
|
+
*
|
|
338
|
+
* ### File mode
|
|
339
|
+
*
|
|
340
|
+
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
341
|
+
* found at a that path:
|
|
342
|
+
*
|
|
343
|
+
* ```ts
|
|
344
|
+
* php.writeFile(
|
|
345
|
+
* "/www/index.php",
|
|
346
|
+
* `<?php echo "Hello world!";"`
|
|
347
|
+
* );
|
|
348
|
+
* const result = await php.run({
|
|
349
|
+
* scriptPath: "/www/index.php"
|
|
350
|
+
* });
|
|
351
|
+
* // result.text === "Hello world!"
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* In this mode, you can rely on path-related information like __DIR__
|
|
355
|
+
* or __FILE__.
|
|
356
|
+
*
|
|
357
|
+
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
358
|
+
* C function.
|
|
359
|
+
*
|
|
360
|
+
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
361
|
+
*
|
|
277
362
|
* @example
|
|
278
363
|
* ```js
|
|
279
|
-
*
|
|
364
|
+
* const result = await php.run(`<?php
|
|
280
365
|
* $fp = fopen('php://stderr', 'w');
|
|
281
366
|
* fwrite($fp, "Hello, world!");
|
|
282
|
-
* `)
|
|
283
|
-
* //
|
|
367
|
+
* `);
|
|
368
|
+
* // result.errors === "Hello, world!"
|
|
284
369
|
* ```
|
|
285
370
|
*
|
|
286
|
-
* @param options - PHP
|
|
371
|
+
* @param options - PHP runtime options.
|
|
287
372
|
*/
|
|
288
373
|
run(options: PHPRunOptions): Promise<PHPResponse>;
|
|
289
374
|
}
|
|
@@ -590,20 +675,23 @@ export declare class WebPHP extends BasePHP {
|
|
|
590
675
|
* A PHP client that can be used to run PHP code in the browser.
|
|
591
676
|
*/
|
|
592
677
|
export declare class WebPHPEndpoint implements IsomorphicLocalPHP {
|
|
593
|
-
/** @inheritDoc */
|
|
678
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.absoluteUrl */
|
|
594
679
|
absoluteUrl: string;
|
|
595
|
-
/** @inheritDoc */
|
|
680
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.documentRoot */
|
|
596
681
|
documentRoot: string;
|
|
597
682
|
/** @inheritDoc */
|
|
598
683
|
constructor(php: BasePHP, monitor?: EmscriptenDownloadMonitor);
|
|
599
|
-
/** @inheritDoc */
|
|
684
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.pathToInternalUrl */
|
|
600
685
|
pathToInternalUrl(path: string): string;
|
|
601
|
-
/** @inheritDoc */
|
|
686
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.internalUrlToPath */
|
|
602
687
|
internalUrlToPath(internalUrl: string): string;
|
|
688
|
+
/**
|
|
689
|
+
* The onDownloadProgress event listener.
|
|
690
|
+
*/
|
|
603
691
|
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
604
|
-
/** @inheritDoc */
|
|
692
|
+
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.mv */
|
|
605
693
|
mv(fromPath: string, toPath: string): void;
|
|
606
|
-
/** @inheritDoc */
|
|
694
|
+
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */
|
|
607
695
|
rmdir(path: string, options?: RmDirOptions): void;
|
|
608
696
|
/** @inheritDoc @php-wasm/universal!RequestHandler.request */
|
|
609
697
|
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"description": "PHP.wasm for the web",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "93834fa77a89c21be2ade4c1d67430981ed92c83"
|
|
33
33
|
}
|