Skip to content

Commit 741e1f3

Browse files
committed
Support arbitrary PHP extensions
Adds support for loading arbitrary PHP extensions in the web version of Playground using all three available APIs: * Query API: `?php-extension=gd&php-extension=xml-bundle` * Blueprints: `{ "phpExtensions": [ "gd", "xml-bundle" ] }` * JavaScript API: `WebPHP.loadSync(phpVersion, { extensions: ["gd", "xml-bundle"]})` For now, it only switches between a barebones ~6MB PHP build and a larger ~8MB with more extensions included. In the future, the internal implementation will change and PHP extensions will be shipped and downloaded separately – see #673 1. Click the new "Load PHP extensions" checkbox in the configuration modal 2. Go to /phpinfo.php and confirm that `gd`, `xml`, and `mbstring` extensions are now available 3. Uncheck that checkbox 4. Confirm these extensions are no longer loaded
1 parent 9815686 commit 741e1f3

File tree

39 files changed

+2291
-1285
lines changed

39 files changed

+2291
-1285
lines changed

package.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@
1414
"lint": "nx run-many --all --target=lint",
1515
"prepublishOnly": "npm run build",
1616
"preview": "nx preview playground-website",
17-
"recompile:php:web": "nx recompile-php:all php-wasm-web",
18-
"recompile:php:web:5.6": "nx recompile-php php-wasm-web --PHP_VERSION=5.6",
19-
"recompile:php:web:7.0": "nx recompile-php php-wasm-web --PHP_VERSION=7.0",
20-
"recompile:php:web:7.1": "nx recompile-php php-wasm-web --PHP_VERSION=7.1",
21-
"recompile:php:web:7.2": "nx recompile-php php-wasm-web --PHP_VERSION=7.2",
22-
"recompile:php:web:7.3": "nx recompile-php php-wasm-web --PHP_VERSION=7.3",
23-
"recompile:php:web:7.4": "nx recompile-php php-wasm-web --PHP_VERSION=7.4",
24-
"recompile:php:web:8.0": "nx recompile-php php-wasm-web --PHP_VERSION=8.0",
25-
"recompile:php:web:8.1": "nx recompile-php php-wasm-web --PHP_VERSION=8.1",
26-
"recompile:php:web:8.2": "nx recompile-php php-wasm-web --PHP_VERSION=8.2",
17+
"recompile:php:web-light": "nx recompile-php:light php-wasm-web ",
18+
"recompile:php:web-light:5.6": "nx recompile-php:light php-wasm-web --PHP_VERSION=5.6",
19+
"recompile:php:web-light:7.0": "nx recompile-php:light php-wasm-web --PHP_VERSION=7.0",
20+
"recompile:php:web-light:7.1": "nx recompile-php:light php-wasm-web --PHP_VERSION=7.1",
21+
"recompile:php:web-light:7.2": "nx recompile-php:light php-wasm-web --PHP_VERSION=7.2",
22+
"recompile:php:web-light:7.3": "nx recompile-php:light php-wasm-web --PHP_VERSION=7.3",
23+
"recompile:php:web-light:7.4": "nx recompile-php:light php-wasm-web --PHP_VERSION=7.4",
24+
"recompile:php:web-light:8.0": "nx recompile-php:light php-wasm-web --PHP_VERSION=8.0",
25+
"recompile:php:web-light:8.1": "nx recompile-php:light php-wasm-web --PHP_VERSION=8.1",
26+
"recompile:php:web-light:8.2": "nx recompile-php:light php-wasm-web --PHP_VERSION=8.2",
27+
"recompile:php:web-regular": "nx recompile-php:regular php-wasm-web",
28+
"recompile:php:web-regular:5.6": "nx recompile-php:regular php-wasm-web --PHP_VERSION=5.6",
29+
"recompile:php:web-regular:7.0": "nx recompile-php:regular php-wasm-web --PHP_VERSION=7.0",
30+
"recompile:php:web-regular:7.1": "nx recompile-php:regular php-wasm-web --PHP_VERSION=7.1",
31+
"recompile:php:web-regular:7.2": "nx recompile-php:regular php-wasm-web --PHP_VERSION=7.2",
32+
"recompile:php:web-regular:7.3": "nx recompile-php:regular php-wasm-web --PHP_VERSION=7.3",
33+
"recompile:php:web-regular:7.4": "nx recompile-php:regular php-wasm-web --PHP_VERSION=7.4",
34+
"recompile:php:web-regular:8.0": "nx recompile-php:regular php-wasm-web --PHP_VERSION=8.0",
35+
"recompile:php:web-regular:8.1": "nx recompile-php:regular php-wasm-web --PHP_VERSION=8.1",
36+
"recompile:php:web-regular:8.2": "nx recompile-php:regular php-wasm-web --PHP_VERSION=8.2",
2737
"recompile:php:node": "nx recompile-php:all php-wasm-node",
2838
"recompile:php:node:5.6": "nx recompile-php php-wasm-node --PHP_VERSION=5.6",
2939
"recompile:php:node:7.0": "nx recompile-php php-wasm-node --PHP_VERSION=7.0",

packages/docs/site/docs/08-query-api/01-index.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ You can go ahead and try it out. The Playground will automatically install the t
2121

2222
## Available options
2323

24-
| Option | Default Value | Description |
25-
| -------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26-
| `php` | `8.0` | Loads the specified PHP version. Supported values: `5.6`, `7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `latest` |
27-
| `wp` | `latest` | Loads the specified WordPress version. Supported values: `5.9`, `6.0`, `6.1`, `6.2`, `6.3`, `latest`, `nightly` |
28-
| `plugin` | | Installs the specified plugin. Use the plugin name from the plugins directory URL, e.g. for a URL like `https://wordpress.org/plugins/wp-lazy-loading/`, the plugin name would be `wp-lazy-loading`. You can pre-install multiple plugins by saying `plugin=coblocks&plugin=wp-lazy-loading&…`. Installing a plugin automatically logs the user in as an admin |
29-
| `theme` | | Installs the specified theme. Use the theme name from the themes directory URL, e.g. for a URL like `https://wordpress.org/themes/disco/`, the theme name would be `disco`. Installing a theme automatically logs the user in as an admin |
30-
| `url` | `/wp-admin/` | Load the specified initial page displaying WordPress |
31-
| `mode` | `seamless` | Displays WordPress on a full-page or wraps it in a browser UI |
32-
| `lazy` | | Defer loading the Playground assets until someone clicks on the "Run" button |
33-
| `login` | `1` | Logs the user in as an admin |
34-
| `gutenberg-pr` | | Loads the specified Gutenberg Pull Request |
35-
| `storage` | | Selects the storage for Playground: `none` gets erased on page refresh, `browser` is stored in the browser, and `device` is stored in the selected directory on a device. The last two protect the user from accidentally losing their work upon page refresh. |
24+
| Option | Default Value | Description |
25+
| --------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26+
| `php` | `8.0` | Loads the specified PHP version. Supported values: `5.6`, `7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `latest` |
27+
| `php-extension` | | Loads the specified PHP extensions. Supported options: `gd`, `xml-bundle` (for libxml, xml, dom, simplexml, xmlreader, xmlwriter), and `mbstring` |
28+
| `wp` | `latest` | Loads the specified WordPress version. Supported values: `5.9`, `6.0`, `6.1`, `6.2`, `6.3`, `latest`, `nightly` |
29+
| `plugin` | | Installs the specified plugin. Use the plugin name from the plugins directory URL, e.g. for a URL like `https://wordpress.org/plugins/wp-lazy-loading/`, the plugin name would be `wp-lazy-loading`. You can pre-install multiple plugins by saying `plugin=coblocks&plugin=wp-lazy-loading&…`. Installing a plugin automatically logs the user in as an admin |
30+
| `theme` | | Installs the specified theme. Use the theme name from the themes directory URL, e.g. for a URL like `https://wordpress.org/themes/disco/`, the theme name would be `disco`. Installing a theme automatically logs the user in as an admin |
31+
| `url` | `/wp-admin/` | Load the specified initial page displaying WordPress |
32+
| `mode` | `seamless` | Displays WordPress on a full-page or wraps it in a browser UI |
33+
| `lazy` | | Defer loading the Playground assets until someone clicks on the "Run" button |
34+
| `login` | `1` | Logs the user in as an admin |
35+
| `gutenberg-pr` | | Loads the specified Gutenberg Pull Request |
36+
| `storage` | | Selects the storage for Playground: `none` gets erased on page refresh, `browser` is stored in the browser, and `device` is stored in the selected directory on a device. The last two protect the user from accidentally losing their work upon page refresh. |
3637

3738
For example, the following code embeds a Playground with a preinstalled Gutenberg plugin, and opens the post editor:
3839

packages/docs/site/docs/09-blueprints-api/01-index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Blueprints are JSON files for setting up your very own WordPress Playground inst
1616
"php": "8.0",
1717
"wp": "latest"
1818
},
19+
"phpExtensions": [
20+
"gd",
21+
"xml-bundle",
22+
"mbstring"
23+
],
1924
"steps": [
2025
{
2126
"step": "login",

packages/docs/site/docs/09-blueprints-api/03-data-format.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import BlueprintExample from '@site/src/components/Blueprints/BlueprintExample.m
2121
"php": "7.4",
2222
"wp": "5.9"
2323
},
24+
"phpExtensions": [
25+
"gd",
26+
"xml-bundle",
27+
"mbstring"
28+
],
2429
"steps": [
2530
{
2631
"step": "login",
@@ -48,3 +53,11 @@ The `preferredVersions` property, unsurprisingly, declares the preferred of PHP
4853

4954
- `php` (string): The preferred PHP version to use. Defaults to 'latest'. Only accepts major versions like "7.4" or "8.0". Minor versions like "7.4.1" are not supported.
5055
- `wp` (string): The preferred WordPress version to use. Defaults to 'latest'. Only accepts major versions like "5.9" or "6.0". Minor versions like "5.9.1" are not supported.
56+
57+
## PHP extensions
58+
59+
The `phpExtensions` property is an array of PHP extensions to load. It can contain the following values:
60+
61+
- `gd`: Installs the GD extension.
62+
- `xml-bundle`: Installs the XML bundle extension (libxml, xml, dom, simplexml, xmlreader, xmlwriter).
63+
- `mbstring`: Installs the mbstring extension.

packages/php-wasm/compile/build.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const argParser = yargs(process.argv.slice(2))
1212
.options({
1313
PLATFORM: {
1414
type: 'string',
15-
choices: ['web', 'node'],
16-
default: 'web',
15+
choices: ['web-light', 'web-regular', 'node'],
16+
default: 'web-light',
1717
description: 'The platform to build for',
1818
},
1919
DEBUG: {
@@ -44,7 +44,6 @@ const argParser = yargs(process.argv.slice(2))
4444
WITH_CLI_SAPI: {
4545
type: 'string',
4646
choices: ['yes', 'no'],
47-
default: 'yes',
4847
description: 'Build with CLI SAPI',
4948
},
5049
WITH_OPENSSL: {
@@ -97,7 +96,13 @@ const platformDefaults = {
9796
WITH_LIBZIP: 'yes',
9897
WITH_SQLITE: 'yes',
9998
},
100-
web: {},
99+
['web-light']: {},
100+
['web-regular']: {
101+
WITH_LIBXML: 'yes',
102+
WITH_LIBPNG: 'yes',
103+
WITH_MBSTRING: 'yes',
104+
WITH_WS_NETWORKING_PROXY: 'yes',
105+
},
101106
node: {
102107
WITH_LIBXML: 'yes',
103108
WITH_LIBPNG: 'yes',
@@ -109,7 +114,8 @@ const platformDefaults = {
109114
WITH_WS_NETWORKING_PROXY: 'yes',
110115
},
111116
};
112-
const platform = args.PLATFORM === 'node' ? 'node' : 'web';
117+
const platform = args.PLATFORM;
118+
113119
/* eslint-disable prettier/prettier */
114120
const getArg = (name) => {
115121
let value =
@@ -170,7 +176,7 @@ await asyncSpawn(
170176
'--build-arg',
171177
getArg('WITH_WS_NETWORKING_PROXY'),
172178
'--build-arg',
173-
`EMSCRIPTEN_ENVIRONMENT=${platform}`,
179+
`EMSCRIPTEN_ENVIRONMENT=${platform === 'node' ? 'node' : 'web'}`,
174180
],
175181
{ cwd: sourceDir, stdio: 'inherit' }
176182
);

packages/php-wasm/universal/src/lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export {
2525
SupportedPHPVersionsList,
2626
} from './supported-php-versions';
2727
export type { SupportedPHPVersion } from './supported-php-versions';
28+
export {
29+
SupportedPHPExtensionsList,
30+
} from './supported-php-extensions';
31+
export type { SupportedPHPExtension } from './supported-php-extensions';
2832
export { BasePHP, __private__dont__use } from './base-php';
2933
export { loadPHPRuntime } from './load-php-runtime';
3034
export type {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const supportedPHPExtensions = ['mbstring', 'xml-bundle', 'gd'] as const;
2+
export type SupportedPHPExtension = (typeof supportedPHPExtensions)[number];
3+
export const SupportedPHPExtensionsList =
4+
supportedPHPExtensions as any as SupportedPHPExtension[];

0 commit comments

Comments
 (0)