Aller au contenu principal

PlaygroundClient

The Playground Client interface.

Hierarchy

  • RemoteAPI<PlaygroundWorkerEndpoint & WebClientMixin>
    • PlaygroundClient

Index

Properties

absoluteUrl

absoluteUrl: Promise<string> = ''
@inheritDoc

addEventListener

addEventListener: Remote<(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener) => void>

backfillStaticFilesRemovedFromMinifiedBuild

backfillStaticFilesRemovedFromMinifiedBuild: Remote<() => Promise<void> & () => Promise<void>>

booted

booted: Promise<false> | Promise<true> = false

documentRoot

documentRoot: Promise<string> = ''
@inheritDoc

hasCachedStaticFilesRemovedFromMinifiedBuild

hasCachedStaticFilesRemovedFromMinifiedBuild: Remote<() => Promise<boolean> & () => Promise<boolean>>

isConnected

isConnected: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Resolves to true when the remote API is ready for Comlink communication, but not necessarily fully initialized yet.


      Returns Promise<void>

isReady

isReady: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Resolves to true when the remote API is declares it’s fully loaded and ready to be used.


      Returns Promise<void>

journalFSEvents

journalFSEvents: Remote<(root: string, callback: (op: FilesystemOperation) => void) => Promise<() => any> & (root: string, callback: (op: FilesystemOperation) => void) => Promise<() => any>>

loadedWordPressVersion

loadedWordPressVersion: Promise<undefined> | Promise<string>

A string representing the version of WordPress that was loaded.

onDownloadProgress

onDownloadProgress: Remote<(callback: (progress: CustomEvent<ProgressEvent<EventTarget>>) => void) => Promise<void>>

The onDownloadProgress event listener.

onMessage

onMessage: Remote<(listener: MessageListener) => void>
@inheritDoc

removeEventListener

removeEventListener: Remote<(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener) => void>

replayFSJournal

replayFSJournal: Remote<(events: FilesystemOperation[]) => Promise<void> & (events: FilesystemOperation[]) => Promise<void>>

requestedWordPressVersion

requestedWordPressVersion: Promise<undefined> | Promise<string>

A string representing the requested version of WordPress.

scope

scope: Promise<undefined> | Promise<string>

A string representing the scope of the Playground instance.

unmounts

unmounts: Promise<Record<string, () => any>> = {}

Methods

public__internal_setRequestHandler

  • __internal_setRequestHandler(...args: [requestHandler: PHPRequestHandler]): Promise<void>
  • Parameters

    Returns Promise<void>

boot

  • boot(...args: [: WorkerBootOptions]): Promise<void>
  • Parameters

    • rest...args: [: WorkerBootOptions]

    Returns Promise<void>

chdir

  • chdir(...args: [path: string]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<void>

defineConstant

  • defineConstant(...args: [key: string, value: null | string | number | boolean]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [key: string, value: null | string | number | boolean]

    Returns Promise<void>

fileExists

  • fileExists(...args: [path: string]): Promise<false> | Promise<true>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<false> | Promise<true>

getCurrentURL

  • getCurrentURL(...args: []): Promise<string>
  • Gets the current URL.


    Parameters

    • rest...args: []

    Returns Promise<string>

getMinifiedWordPressVersions

  • getMinifiedWordPressVersions(...args: []): Promise<{ all: { 6.3: string; 6.4: string; 6.5: string; 6.6: string; beta: string; nightly: string }; latest: string }>
  • Parameters

    • rest...args: []

    Returns Promise<{ all: { 6.3: string; 6.4: string; 6.5: string; 6.6: string; beta: string; nightly: string }; latest: string }>

getWordPressModuleDetails

  • getWordPressModuleDetails(...args: []): Promise<{ majorVersion: undefined | string; staticAssetsDirectory: undefined | string }>

  • Parameters

    • rest...args: []

    Returns Promise<{ majorVersion: undefined | string; staticAssetsDirectory: undefined | string }>

    WordPress module details, including the static assets directory and default theme.

goTo

  • goTo(...args: [requestedPath: string]): Promise<void>
  • Navigates to the requested path.


    Parameters

    • rest...args: [requestedPath: string]

    Returns Promise<void>

hasOpfsMount

  • hasOpfsMount(...args: [mountpoint: string]): Promise<false> | Promise<true>
  • Parameters

    • rest...args: [mountpoint: string]

    Returns Promise<false> | Promise<true>

internalUrlToPath

  • internalUrlToPath(...args: [internalUrl: string]): Promise<string>
  • 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

  • isDir(...args: [path: string]): Promise<false> | Promise<true>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<false> | Promise<true>

isFile

  • isFile(...args: [path: string]): Promise<false> | Promise<true>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<false> | Promise<true>

listFiles

  • listFiles(...args: [path: string, options?: ListFilesOptions]): Promise<string[]>
  • @inheritDoc

    Parameters

    • rest...args: [path: string, options?: ListFilesOptions]

    Returns Promise<string[]>

mkdir

  • mkdir(...args: [path: string]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<void>

mkdirTree

  • mkdirTree(...args: [path: string]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<void>

mountOpfs

  • mountOpfs(...args: [options: MountDescriptor, onProgress?: SyncProgressCallback]): Promise<void>
  • Parameters

    Returns Promise<void>

mv

  • mv(...args: [fromPath: string, toPath: string]): Promise<void>
  • Moves a file or directory in the PHP filesystem to a new location.


    Parameters

    • rest...args: [fromPath: string, toPath: string]

    Returns Promise<void>

onNavigation

  • onNavigation(...args: [fn: (url: string) => void]): Promise<void>
  • Sets the navigation event listener.


    Parameters

    • rest...args: [fn: (url: string) => void]

    Returns Promise<void>

pathToInternalUrl

  • pathToInternalUrl(...args: [path: string]): Promise<string>
  • 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

  • readFileAsBuffer(...args: [path: string]): Promise<Uint8Array>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<Uint8Array>

readFileAsText

  • readFileAsText(...args: [path: string]): Promise<string>
  • @inheritDoc

    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 with cli().


    Parameters

    • rest...args: [request: PHPRequest]

      PHP Request data.

    Returns Promise<PHPResponse>

rmdir

  • rmdir(...args: [path: string, options?: RmDirOptions]): Promise<void>
  • Removes a directory from the PHP filesystem.


    Parameters

    • rest...args: [path: string, options?: RmDirOptions]

      The directory path to remove.

    Returns Promise<void>

run

setIframeSandboxFlags

  • setIframeSandboxFlags(...args: [flags: string[]]): Promise<void>
  • Sets the iframe sandbox flags.


    Parameters

    • rest...args: [flags: string[]]

    Returns Promise<void>

setLoaded

  • setLoaded(...args: []): Promise<void>
  • Sets the loaded state.


    Parameters

    • rest...args: []

    Returns Promise<void>

setPrimaryPHP

  • setPrimaryPHP(...args: [php: PHP]): Promise<void>
  • Parameters

    • rest...args: [php: PHP]

    Returns Promise<void>

setProgress

  • setProgress(...args: [options: ProgressBarOptions]): Promise<void>
  • Sets the progress bar options.


    Parameters

    • rest...args: [options: ProgressBarOptions]

    Returns Promise<void>

setSapiName

  • setSapiName(...args: [newName: string]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [newName: string]

    Returns Promise<void>

unlink

  • unlink(...args: [path: string]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [path: string]

    Returns Promise<void>

unmountOpfs

  • unmountOpfs(...args: [mountpoint: string]): Promise<void>
  • Parameters

    • rest...args: [mountpoint: string]

    Returns Promise<void>

writeFile

  • writeFile(...args: [path: string, data: string | Uint8Array]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [path: string, data: string | Uint8Array]

    Returns Promise<void>