import type { EmscriptenDownloadMonitor } from '@php-wasm/progress'; import type { ListFilesOptions, RmDirOptions } from './fs-helpers'; import type { PHP } from './php'; import type { PHPRequestHandler } from './php-request-handler'; import type { PHPResponse, StreamedPHPResponse } from './php-response'; import type { MessageListener, PHPEvent, PHPRequest, PHPRunOptions } from './universal-php'; export type LimitedPHPApi = Pick & { documentRoot: PHP['documentRoot']; absoluteUrl: PHP['absoluteUrl']; addEventListener: PHP['addEventListener'] | ((event: string, listener: (event: any) => any) => void); removeEventListener: PHP['removeEventListener'] | ((event: string, listener: (event: any) => any) => void); }; export type PHPWorkerEvent = PHPEvent | { type: string; }; export type PHPWorkerEventListener = (event: PHPWorkerEvent) => void; /** * A PHP client that can be used to run PHP code in the browser. */ export declare class PHPWorker implements LimitedPHPApi, AsyncDisposable { #private; /** @inheritDoc @php-wasm/universal!RequestHandler.absoluteUrl */ absoluteUrl: string; /** @inheritDoc @php-wasm/universal!RequestHandler.documentRoot */ documentRoot: string; private chroot; onMessageListeners: MessageListener[]; /** @inheritDoc */ constructor(requestHandler?: PHPRequestHandler, monitor?: EmscriptenDownloadMonitor); __internal_setRequestHandler(requestHandler: PHPRequestHandler): void; /** * @internal * @deprecated * Do not use this method directly in the code consuming * the web API. It will change or even be removed without * a warning. */ protected __internal_getPHP(): PHP | undefined; /** * @internal * @deprecated * Do not use this method directly in the code consuming * the web API. It will change or even be removed without * a warning. */ protected __internal_getRequestHandler(): PHPRequestHandler | undefined; setPrimaryPHP(php: PHP): Promise; /** @inheritDoc @php-wasm/universal!PHPRequestHandler.pathToInternalUrl */ pathToInternalUrl(path: string): string; /** @inheritDoc @php-wasm/universal!PHPRequestHandler.internalUrlToPath */ internalUrlToPath(internalUrl: string): string; /** * The onDownloadProgress event listener. */ onDownloadProgress(callback: (progress: CustomEvent) => void): Promise; /** @inheritDoc @php-wasm/universal!PHP.mv */ mv(fromPath: string, toPath: string): Promise; /** @inheritDoc @php-wasm/universal!PHP.rmdir */ rmdir(path: string, options?: RmDirOptions): Promise; /** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */ request(request: PHPRequest): Promise; /** * Handles a request with streaming support for large responses. * Returns a StreamedPHPResponse that allows processing the response * body incrementally without buffering the entire response in memory. * * This is useful for large file downloads (>2GB) that would otherwise * exceed JavaScript's Uint8Array size limits. * * @param request - PHP Request data. */ requestStreamed(request: PHPRequest): Promise; /** @inheritDoc @php-wasm/universal!/PHP.run */ run(request: PHPRunOptions): Promise; /** @inheritDoc @php-wasm/universal!/PHP.cli */ cli(argv: string[], options?: { env?: Record; }): Promise; /** @inheritDoc @php-wasm/universal!/PHP.chdir */ chdir(path: string): void; /** @inheritDoc @php-wasm/universal!/PHP.chdir */ cwd(): string; /** * @returns A PHP instance with a consistent chroot. */ private acquirePHPInstance; /** @inheritDoc @php-wasm/universal!/PHP.setSapiName */ setSapiName(newName: string): void; /** @inheritDoc @php-wasm/universal!/PHP.mkdir */ mkdir(path: string): void; /** @inheritDoc @php-wasm/universal!/PHP.mkdirTree */ mkdirTree(path: string): void; /** @inheritDoc @php-wasm/universal!/PHP.readFileAsText */ readFileAsText(path: string): string; /** @inheritDoc @php-wasm/universal!/PHP.readFileAsBuffer */ readFileAsBuffer(path: string): Uint8Array; /** @inheritDoc @php-wasm/universal!/PHP.writeFile */ writeFile(path: string, data: string | Uint8Array): void; /** @inheritDoc @php-wasm/universal!/PHP.unlink */ unlink(path: string): void; /** @inheritDoc @php-wasm/universal!/PHP.listFiles */ listFiles(path: string, options?: ListFilesOptions): string[]; /** @inheritDoc @php-wasm/universal!/PHP.isDir */ isDir(path: string): boolean; /** @inheritDoc @php-wasm/universal!/PHP.isFile */ isFile(path: string): boolean; /** @inheritDoc @php-wasm/universal!/PHP.fileExists */ fileExists(path: string): boolean; /** @inheritDoc @php-wasm/universal!/PHP.onMessage */ onMessage(listener: MessageListener): () => Promise; /** @inheritDoc @php-wasm/universal!/PHP.defineConstant */ defineConstant(key: string, value: string | boolean | number | null): void; /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */ addEventListener(eventType: PHPWorkerEvent['type'], listener: PHPWorkerEventListener): void; /** * Removes an event listener for a PHP event. * @param eventType - The type of event to remove the listener from. * @param listener - The listener function to be removed. */ removeEventListener(eventType: PHPWorkerEvent['type'], listener: PHPWorkerEventListener): void; protected dispatchEvent(event: Event): void; protected registerWorkerListeners(php: PHP): void; [Symbol.asyncDispose](): Promise; }