@php-wasm/web 0.1.9 → 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 CHANGED
@@ -5,29 +5,27 @@ 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 {
9
- loadPHPRuntime,
10
- getPHPLoaderModule,
11
- PHP,
12
- PHPServer,
13
- } from '@php-wasm/web';
14
- const php = new PHP(
15
- // getPHPLoaderModule() calls import('php.wasm') internally
16
- // Your bundler must resolve import('php.wasm') as a static file URL.
17
- // If you use Webpack, you can use the file-loader to do so.
18
- await loadPHPRuntime(await getPHPLoaderModule('8.0'))
19
- );
8
+ import { PHP } from '@php-wasm/web';
9
+
10
+ // PHP.load() calls import('php.wasm') internally
11
+ // Your bundler must resolve import('php.wasm') as a static file URL.
12
+ // 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
+ },
17
+ });
20
18
 
21
19
  // Create and run a script directly
22
20
  php.mkdirTree('/www');
23
21
  php.writeFile('/www/index.php', `<?php echo "Hello " . $_POST['name']; ?>`);
24
- php.run({ scriptPath: '/www/index.php' });
22
+ await php.run({ scriptPath: './index.php' });
25
23
 
26
24
  // Or use the familiar HTTP concepts:
27
- const server = new PHPServer(php, { documentRoot: '/www' });
28
- const response = server.request({
25
+ const response = await php.request({
29
26
  method: 'POST',
30
- relativeUrl: '/index.php',
27
+ url: '/index.php',
31
28
  data: { name: 'John' },
32
29
  });
30
+ console.log(response.text);
33
31
  ```