@php-wasm/web 3.0.12 → 3.0.13

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.
Files changed (2) hide show
  1. package/README.md +25 -12
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -5,29 +5,42 @@ This package ships WebAssembly PHP binaries and the JavaScript API optimized for
5
5
  Here's how to use it:
6
6
 
7
7
  ```js
8
- import { PHP } from '@php-wasm/web';
8
+ import { PHP, PHPRequestHandler } from '@php-wasm/universal';
9
+ import { loadWebRuntime } from '@php-wasm/web';
9
10
 
10
- // PHP.load() calls import('php.wasm') internally
11
+ // loadWebRuntime() calls import('php.wasm') and import('icudt74l.dat') internally.
11
12
  // Your bundler must resolve import('php.wasm') as a static file URL.
12
13
  // If you use Webpack, you can use the file-loader to do so.
13
- const php = await PHP.load('8.0', {
14
- requestHandler: {
15
- documentRoot: '/www',
16
- },
14
+ const php = new PHP(await loadWebRuntime('8.3'));
15
+
16
+ let response;
17
+
18
+ php.writeFile('/test.php', `<?php echo "Hello, World!"; ?>`);
19
+
20
+ // Run a script directly:
21
+ response = await php.runStream({
22
+ scriptPath: '/test.php',
17
23
  });
18
24
 
19
- // Create and run a script directly
20
- php.mkdirTree('/www');
25
+ console.log(await response.stdoutText);
26
+ // You will see the following output in the browser console:
27
+ // Hello, World!
28
+
29
+ php.mkdir('/www');
21
30
  php.writeFile('/www/index.php', `<?php echo "Hello " . $_POST['name']; ?>`);
22
- await php.run({ scriptPath: './index.php' });
23
31
 
24
32
  // Or use the familiar HTTP concepts:
25
- const response = await php.request({
33
+ const handler = new PHPRequestHandler({ phpFactory: async () => php });
34
+
35
+ response = await handler.request({
26
36
  method: 'POST',
27
- url: '/index.php',
28
- data: { name: 'John' },
37
+ url: 'index.php',
38
+ body: { name: 'John' },
29
39
  });
40
+
30
41
  console.log(response.text);
42
+ // You will see the following output in the browser console:
43
+ // Hello John
31
44
  ```
32
45
 
33
46
  ## Attribution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "main": "./index.cjs",
38
38
  "module": "./index.js",
39
39
  "types": "index.d.ts",
40
- "gitHead": "75715549fdb6064f4fa335e65bc5718e2177c229",
40
+ "gitHead": "26e75279df438946c3fc81c12a47fae483f0ff3a",
41
41
  "engines": {
42
42
  "node": ">=20.18.3",
43
43
  "npm": ">=10.1.0"
@@ -48,11 +48,11 @@
48
48
  "wasm-feature-detect": "1.8.0",
49
49
  "ws": "8.18.1",
50
50
  "yargs": "17.7.2",
51
- "@php-wasm/util": "3.0.12",
52
- "@php-wasm/universal": "3.0.12",
53
- "@php-wasm/logger": "3.0.12",
54
- "@php-wasm/fs-journal": "3.0.12",
55
- "@php-wasm/web-service-worker": "3.0.12"
51
+ "@php-wasm/util": "3.0.13",
52
+ "@php-wasm/universal": "3.0.13",
53
+ "@php-wasm/logger": "3.0.13",
54
+ "@php-wasm/fs-journal": "3.0.13",
55
+ "@php-wasm/web-service-worker": "3.0.13"
56
56
  },
57
57
  "packageManager": "npm@10.9.2",
58
58
  "overrides": {