@php-wasm/web 0.2.0 → 0.3.0

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 (42) hide show
  1. package/README.md +35 -0
  2. package/index.d.ts +11 -8
  3. package/index.js +231 -202
  4. package/kitchen-sink/php_5_6.js +85 -0
  5. package/kitchen-sink/php_5_6.wasm +0 -0
  6. package/kitchen-sink/php_7_0.js +85 -0
  7. package/kitchen-sink/php_7_0.wasm +0 -0
  8. package/kitchen-sink/php_7_1.js +85 -0
  9. package/kitchen-sink/php_7_1.wasm +0 -0
  10. package/kitchen-sink/php_7_2.js +85 -0
  11. package/kitchen-sink/php_7_2.wasm +0 -0
  12. package/kitchen-sink/php_7_3.js +85 -0
  13. package/kitchen-sink/php_7_3.wasm +0 -0
  14. package/kitchen-sink/php_7_4.js +85 -0
  15. package/kitchen-sink/php_7_4.wasm +0 -0
  16. package/kitchen-sink/php_8_0.js +85 -0
  17. package/kitchen-sink/php_8_0.wasm +0 -0
  18. package/kitchen-sink/php_8_1.js +85 -0
  19. package/kitchen-sink/php_8_1.wasm +0 -0
  20. package/kitchen-sink/php_8_2.js +85 -0
  21. package/kitchen-sink/php_8_2.wasm +0 -0
  22. package/lib/worker-thread/spawn-php-worker-thread.d.ts +1 -1
  23. package/package.json +2 -2
  24. package/lib/worker-thread/parse-startup-options.d.ts +0 -1
  25. /package/{php_5_6.js → light/php_5_6.js} +0 -0
  26. /package/{php_5_6.wasm → light/php_5_6.wasm} +0 -0
  27. /package/{php_7_0.js → light/php_7_0.js} +0 -0
  28. /package/{php_7_0.wasm → light/php_7_0.wasm} +0 -0
  29. /package/{php_7_1.js → light/php_7_1.js} +0 -0
  30. /package/{php_7_1.wasm → light/php_7_1.wasm} +0 -0
  31. /package/{php_7_2.js → light/php_7_2.js} +0 -0
  32. /package/{php_7_2.wasm → light/php_7_2.wasm} +0 -0
  33. /package/{php_7_3.js → light/php_7_3.js} +0 -0
  34. /package/{php_7_3.wasm → light/php_7_3.wasm} +0 -0
  35. /package/{php_7_4.js → light/php_7_4.js} +0 -0
  36. /package/{php_7_4.wasm → light/php_7_4.wasm} +0 -0
  37. /package/{php_8_0.js → light/php_8_0.js} +0 -0
  38. /package/{php_8_0.wasm → light/php_8_0.wasm} +0 -0
  39. /package/{php_8_1.js → light/php_8_1.js} +0 -0
  40. /package/{php_8_1.wasm → light/php_8_1.wasm} +0 -0
  41. /package/{php_8_2.js → light/php_8_2.js} +0 -0
  42. /package/{php_8_2.wasm → light/php_8_2.wasm} +0 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # WebAssembly PHP for the web
2
+
3
+ This package ships WebAssembly PHP binaries and the JavaScript API optimized for the web and a low bundle size. It comes with the Libzip extension and the SQLite extension.
4
+
5
+ Here's how to use it:
6
+
7
+ ```js
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
+ });
18
+
19
+ // Create and run a script directly
20
+ php.mkdirTree('/www');
21
+ php.writeFile('/www/index.php', `<?php echo "Hello " . $_POST['name']; ?>`);
22
+ await php.run({ scriptPath: './index.php' });
23
+
24
+ // Or use the familiar HTTP concepts:
25
+ const response = await php.request({
26
+ method: 'POST',
27
+ url: '/index.php',
28
+ data: { name: 'John' },
29
+ });
30
+ console.log(response.text);
31
+ ```
32
+
33
+ ## Attribution
34
+
35
+ `@php-wasm/web` started as a fork of the original PHP to WebAssembly build published by Oraoto in https://github.com/oraoto/pib and modified by Sean Morris in https://github.com/seanmorris/php-wasm.
package/index.d.ts CHANGED
@@ -520,11 +520,6 @@ export interface PHPRequestHandlerConfiguration {
520
520
  * Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
521
521
  */
522
522
  absoluteUrl?: string;
523
- /**
524
- * Callback used by the PHPRequestHandler to decide whether
525
- * the requested path refers to a PHP file or a static file.
526
- */
527
- isStaticFilePath?: (path: string) => boolean;
528
523
  }
529
524
  declare class PHPRequestHandler implements RequestHandler {
530
525
  #private;
@@ -697,6 +692,8 @@ export interface PHPWebLoaderOptions {
697
692
  downloadMonitor?: EmscriptenDownloadMonitor;
698
693
  requestHandler?: PHPRequestHandlerConfiguration;
699
694
  dataModules?: Array<DataModule | Promise<DataModule>>;
695
+ /** @deprecated To be replaced with `extensions` in the future */
696
+ loadAllExtensions?: boolean;
700
697
  }
701
698
  export declare class WebPHP extends BasePHP {
702
699
  /**
@@ -777,7 +774,14 @@ export declare class WebPHPEndpoint implements IsomorphicLocalPHP {
777
774
  /** @inheritDoc @php-wasm/web!WebPHP.onMessage */
778
775
  onMessage(listener: MessageListener): void;
779
776
  }
780
- export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promise<PHPLoaderModule>;
777
+ /**
778
+ * Loads the PHP loader module for the given PHP version.
779
+ *
780
+ * @param version The PHP version to load.
781
+ * @param variant Internal. Do not use.
782
+ * @returns The PHP loader module.
783
+ */
784
+ export declare function getPHPLoaderModule(version?: SupportedPHPVersion, variant?: "light" | "kitchen-sink"): Promise<PHPLoaderModule>;
781
785
  /**
782
786
  * Run this in the main application to register the service worker or
783
787
  * reload the registered worker if the app expects a different version
@@ -789,7 +793,6 @@ export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promi
789
793
  * will be re-registered.
790
794
  */
791
795
  export declare function registerServiceWorker<Client extends Remote<WebPHPEndpoint>>(phpApi: Client, scope: string, scriptUrl: string): Promise<void>;
792
- export declare function parseWorkerStartupOptions<T extends Record<string, string>>(): T;
793
796
  /**
794
797
  * Spawns a new Worker Thread.
795
798
  *
@@ -797,6 +800,6 @@ export declare function parseWorkerStartupOptions<T extends Record<string, strin
797
800
  * @param config
798
801
  * @returns The spawned Worker Thread.
799
802
  */
800
- export declare function spawnPHPWorkerThread(workerUrl: string, startupOptions?: Record<string, string>): Promise<Worker>;
803
+ export declare function spawnPHPWorkerThread(workerUrl: string, startupOptions?: Record<string, string | string[]>): Promise<Worker>;
801
804
 
802
805
  export {};