PlaygroundClient
Hierarchy
- RemoteAPI<PlaygroundWorkerEndpoint & WebClientMixin>
- PlaygroundClient
Index
Properties
Methods
- __internal_setRequestHandler
- boot
- chdir
- defineConstant
- fileExists
- getCurrentURL
- getMinifiedWordPressVersions
- getWordPressModuleDetails
- goTo
- hasOpfsMount
- internalUrlToPath
- isDir
- isFile
- listFiles
- mkdir
- mkdirTree
- mountOpfs
- mv
- onMessage
- onNavigation
- pathToInternalUrl
- readFileAsBuffer
- readFileAsText
- request
- rmdir
- run
- setIframeSandboxFlags
- setLoaded
- setPrimaryPHP
- setProgress
- setSapiName
- unlink
- unmountOpfs
- writeFile
Properties
absoluteUrl
addEventListener
backfillStaticFilesRemovedFromMinifiedBuild
booted
documentRoot
hasCachedStaticFilesRemovedFromMinifiedBuild
isConnected
Type declaration
Resolves to true when the remote API is ready for Comlink communication, but not necessarily fully initialized yet.
Returns Promise<void>
isReady
Type declaration
Resolves to true when the remote API is declares it’s fully loaded and ready to be used.
Returns Promise<void>
journalFSEvents
loadedWordPressVersion
A string representing the version of WordPress that was loaded.
onDownloadProgress
The onDownloadProgress event listener.
removeEventListener
replayFSJournal
requestedWordPressVersion
A string representing the requested version of WordPress.
scope
A string representing the scope of the Playground instance.
unmounts
Methods
public__internal_setRequestHandler
Parameters
rest...args: [requestHandler: PHPRequestHandler]
Returns Promise<void>
boot
Parameters
rest...args: [: WorkerBootOptions]
Returns Promise<void>
chdir
Parameters
rest...args: [path: string]
Returns Promise<void>
defineConstant
Parameters
rest...args: [key: string, value: null | string | number | boolean]
Returns Promise<void>
fileExists
Parameters
rest...args: [path: string]
Returns Promise<false> | Promise<true>
getCurrentURL
Gets the current URL.
Parameters
rest...args: []
Returns Promise<string>
getMinifiedWordPressVersions
Parameters
rest...args: []
Returns Promise<{ all: { 6.3: string; 6.4: string; 6.5: string; 6.6: string; 6.7: string; beta: string; nightly: string }; latest: string }>
getWordPressModuleDetails
Parameters
rest...args: []
Returns Promise<{ majorVersion: undefined | string; staticAssetsDirectory: undefined | string }>
WordPress module details, including the static assets directory and default theme.
goTo
Navigates to the requested path.
Parameters
rest...args: [requestedPath: string]
Returns Promise<void>
hasOpfsMount
Parameters
rest...args: [mountpoint: string]
Returns Promise<false> | Promise<true>
internalUrlToPath
Converts an absolute URL based at the PHPRequestHandler to a relative path without the server pathname and scope.
Parameters
rest...args: [internalUrl: string]
An absolute URL based at the PHPRequestHandler root.
Returns Promise<string>
The relative path.
isDir
Parameters
rest...args: [path: string]
Returns Promise<false> | Promise<true>
isFile
Parameters
rest...args: [path: string]
Returns Promise<false> | Promise<true>
listFiles
Parameters
rest...args: [path: string, options?: ListFilesOptions]
Returns Promise<string[]>
mkdir
Parameters
rest...args: [path: string]
Returns Promise<void>
mkdirTree
Parameters
rest...args: [path: string]
Returns Promise<void>
mountOpfs
Parameters
rest...args: [options: MountDescriptor, onProgress?: SyncProgressCallback]
Returns Promise<void>
mv
Moves a file or directory in the PHP filesystem to a new location.
Parameters
rest...args: [fromPath: string, toPath: string]
Returns Promise<void>
onMessage
Parameters
rest...args: [listener: MessageListener]
Returns Promise<() => Promise<void>>
onNavigation
Sets the navigation event listener.
Parameters
rest...args: [fn: (url: string) => void]
Returns Promise<void>
pathToInternalUrl
Converts a path to an absolute URL based at the PHPRequestHandler root.
Parameters
rest...args: [path: string]
The server path to convert to an absolute URL.
Returns Promise<string>
The absolute URL.
readFileAsBuffer
Parameters
rest...args: [path: string]
Returns Promise<Uint8Array>
readFileAsText
Parameters
rest...args: [path: string]
Returns Promise<string>
request
Serves the request – either by serving a static file, or by dispatching it to the PHP runtime.
The request() method mode behaves like a web server and only works if the PHP was initialized with a
requestHandler
option (which the online version of WordPress Playground does by default).In the request mode, you pass an object containing the request information (method, headers, body, etc.) and the path to the PHP file to run:
const php = PHP.load('7.4', {
requestHandler: {
documentRoot: "/www"
}
})
php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
const result = await php.request({
method: "GET",
headers: {
"Content-Type": "text/plain"
},
body: "Hello world!",
path: "/www/index.php"
});
// result.text === "Hello world!"The
request()
method cannot be used in conjunction withcli()
.Parameters
rest...args: [request: PHPRequest]
PHP Request data.
Returns Promise<PHPResponse>
rmdir
Removes a directory from the PHP filesystem.
Parameters
rest...args: [path: string, options?: RmDirOptions]
The directory path to remove.
Returns Promise<void>
run
Parameters
rest...args: [request: PHPRunOptions]
Returns Promise<PHPResponse>
setIframeSandboxFlags
Sets the iframe sandbox flags.
Parameters
rest...args: [flags: string[]]
Returns Promise<void>
setLoaded
Sets the loaded state.
Parameters
rest...args: []
Returns Promise<void>
setPrimaryPHP
Parameters
rest...args: [php: PHP]
Returns Promise<void>
setProgress
Sets the progress bar options.
Parameters
rest...args: [options: ProgressBarOptions]
Returns Promise<void>
setSapiName
Parameters
rest...args: [newName: string]
Returns Promise<void>
unlink
Parameters
rest...args: [path: string]
Returns Promise<void>
unmountOpfs
Parameters
rest...args: [mountpoint: string]
Returns Promise<void>
writeFile
Parameters
rest...args: [path: string, data: string | Uint8Array]
Returns Promise<void>
The Playground Client interface.