-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: PHP: Remove NodePHP and WebPHP classes in favor of a single…
… "PHP" class (#1457) > [!WARNING] > This is breaking change! Review the description below to assess the impact on your app. Consolidates the `BasePHP`, `NodePHP`, and `WebPHP` classes into a single `PHP` class. This refactor reduces redundancy and clarifies the PHP handling process across different environments. ## Examples ### NodePHP **Before** ```ts import { NodePHP } from '@php-wasm/node'; const php = await NodePHP.load('8.0'); ``` **After** ```ts import { loadNodeRuntime } from '@php-wasm/node'; import { PHP } from '@php-wasm/universal'; const php = new PHP(await loadNodeRuntime('8.0')); ``` ### WebPHP **Before** ```ts import { WebPHP } from '@php-wasm/web'; const php = await WebPHP.loadRuntime('8.0'); ``` **After** ```ts import { loadWebRuntime } from '@php-wasm/web'; import { PHP } from '@php-wasm/universal'; const php = new PHP(await loadWebRuntime('8.0')); ``` ### Mounting **Before** ```ts php.useHostFilesystem(); // or php.mount( '/home/users/adam/my-dir', '/my-dir-in-vfs'); ``` **After** ```ts import { NodeFSMount, useHostFilesystem } from '@php-wasm/node'; useHostFilesystem( php ); php.mount( new NodeFSMount( '/home/users/adam/my-dir' ), '/my-dir-in-vfs' ); ``` Closes #1399 ## Motivation First, the public API surface of all the PHP classes and interfaces is [overly complex](#514). This PR is a step towards simplifying it. Second, in the [Boot Protocol](#1398), PR the `bootWordPress()` function requires separate `createPHP` and `createPHPRuntime` callbacks just because Playground uses different classes in node.js and in the browser. With this PR, `createPHP` callback will no longer be needed anymore as `bootWordPress()` will just always create a `new PHP()` instance. ## Public API Changes - Removes `BasePHP`, `NodePHP`, and `WebPHP` classes in favor of a single PHP class exported from `@php-wasm/universal` - `php.useHostFilesystem()` was removed in favor of a decoupled function `useHostFilesystem( php )` available in `@php-wasm/node`. - `PHP.mount()` signature changed from `mount( hostPath: string, vfsPath: string )` to `mount( mountable: Mountable, vfsPath: string )` - Moves WebPHPEndpoint from `@php-wasm/web` to `@php-wasm/universal` and renames it to `PHPWorker`. That class isn't specific to the web and could be easily used by Node workers. - Removes the `IsomorphicLocalPHP` interface. The PHP class is now the source of truth for all derived worker, client, etc. implementations. - Removes the `createPhpInstance()` option from `bootWordPress( options )` in favor of always using the PHP class. - Updates to Documentation: Adjusted examples and references in the documentation to reflect the new `PHP` class. - Refactoring of Test Suites: Updated tests to work with the new class structure. ## Testing instructions Confirm all the CI checks pass – this PR includes an extensive refactor of all the tests. Heads up @wojtekn @fluiddot @sejas
- Loading branch information
Showing
70 changed files
with
1,353 additions
and
981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
packages/docs/site/docs/09-blueprints-api/06-isomorphic.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './get-php-loader-module'; | ||
export * from './networking/with-networking'; | ||
export * from './node-php'; | ||
export * from './load-runtime'; | ||
export * from './use-host-filesystem'; | ||
export * from './node-fs-mount'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
SupportedPHPVersion, | ||
loadPHPRuntime, | ||
EmscriptenOptions, | ||
} from '@php-wasm/universal'; | ||
|
||
import { getPHPLoaderModule } from '.'; | ||
import { withNetworking } from './networking/with-networking.js'; | ||
|
||
export interface PHPLoaderOptions { | ||
emscriptenOptions?: EmscriptenOptions; | ||
} | ||
|
||
/** | ||
* Does what load() does, but synchronously returns | ||
* an object with the PHP instance and a promise that | ||
* resolves when the PHP instance is ready. | ||
* | ||
* @see load | ||
*/ | ||
export async function loadNodeRuntime( | ||
phpVersion: SupportedPHPVersion, | ||
options: PHPLoaderOptions = {} | ||
) { | ||
const emscriptenOptions: EmscriptenOptions = { | ||
/** | ||
* Emscripten default behavior is to kill the process when | ||
* the WASM program calls `exit()`. We want to throw an | ||
* exception instead. | ||
*/ | ||
quit: function (code, error) { | ||
throw error; | ||
}, | ||
...(options.emscriptenOptions || {}), | ||
}; | ||
return await loadPHPRuntime( | ||
await getPHPLoaderModule(phpVersion), | ||
await withNetworking(emscriptenOptions) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Emscripten, Mountable } from '@php-wasm/universal'; | ||
|
||
export class NodeFSMount implements Mountable { | ||
constructor(private readonly localPath: string) {} | ||
|
||
mount(FS: Emscripten.RootFS, vfsMountPoint: string): void | Promise<void> { | ||
FS.mount( | ||
FS.filesystems['NODEFS'], | ||
{ root: this.localPath }, | ||
vfsMountPoint | ||
); | ||
} | ||
} |
Oops, something went wrong.