@php-wasm/universal 0.3.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +18 -10
- package/index.js +627 -544
- package/lib/base-php.d.ts +9 -2
- package/lib/index.d.ts +1 -1
- package/lib/php-browser.d.ts +2 -0
- package/lib/supported-php-versions.d.ts +2 -2
- package/lib/universal-php.d.ts +54 -2
- package/package.json +2 -2
package/lib/base-php.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { PHPBrowser } from './php-browser';
|
|
|
2
2
|
import { PHPRequestHandlerConfiguration } from './php-request-handler';
|
|
3
3
|
import { PHPResponse } from './php-response';
|
|
4
4
|
import type { PHPRuntimeId } from './load-php-runtime';
|
|
5
|
-
import { IsomorphicLocalPHP, MessageListener, PHPRequest, PHPRunOptions, RmDirOptions, ListFilesOptions } from './universal-php';
|
|
5
|
+
import { IsomorphicLocalPHP, MessageListener, PHPRequest, PHPRequestHeaders, PHPRunOptions, RmDirOptions, ListFilesOptions, SpawnHandler, PHPEventListener, PHPEvent } from './universal-php';
|
|
6
6
|
export declare const __private__dont__use: unique symbol;
|
|
7
7
|
/**
|
|
8
8
|
* An environment-agnostic wrapper around the Emscripten PHP runtime
|
|
@@ -24,9 +24,14 @@ export declare abstract class BasePHP implements IsomorphicLocalPHP {
|
|
|
24
24
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
25
25
|
*/
|
|
26
26
|
constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
|
|
27
|
+
addEventListener(eventType: PHPEvent['type'], listener: PHPEventListener): void;
|
|
28
|
+
removeEventListener(eventType: PHPEvent['type'], listener: PHPEventListener): void;
|
|
29
|
+
dispatchEvent<Event extends PHPEvent>(event: Event): void;
|
|
27
30
|
/** @inheritDoc */
|
|
28
31
|
onMessage(listener: MessageListener): Promise<void>;
|
|
29
32
|
/** @inheritDoc */
|
|
33
|
+
setSpawnHandler(handler: SpawnHandler): Promise<void>;
|
|
34
|
+
/** @inheritDoc */
|
|
30
35
|
get absoluteUrl(): string;
|
|
31
36
|
/** @inheritDoc */
|
|
32
37
|
get documentRoot(): string;
|
|
@@ -46,6 +51,7 @@ export declare abstract class BasePHP implements IsomorphicLocalPHP {
|
|
|
46
51
|
/** @inheritDoc */
|
|
47
52
|
run(request: PHPRunOptions): Promise<PHPResponse>;
|
|
48
53
|
addServerGlobalEntry(key: string, value: string): void;
|
|
54
|
+
defineConstant(key: string, value: string | number | null): void;
|
|
49
55
|
/** @inheritDoc */
|
|
50
56
|
mkdir(path: string): void;
|
|
51
57
|
/** @inheritDoc */
|
|
@@ -68,5 +74,6 @@ export declare abstract class BasePHP implements IsomorphicLocalPHP {
|
|
|
68
74
|
isDir(path: string): boolean;
|
|
69
75
|
/** @inheritDoc */
|
|
70
76
|
fileExists(path: string): boolean;
|
|
77
|
+
exit(code?: number): any;
|
|
71
78
|
}
|
|
72
|
-
export declare function normalizeHeaders(headers:
|
|
79
|
+
export declare function normalizeHeaders(headers: PHPRequestHeaders): PHPRequestHeaders;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { FileInfo, IsomorphicLocalPHP, IsomorphicRemotePHP, MessageListener, PHPOutput, PHPRunOptions, UniversalPHP, ListFilesOptions, RmDirOptions, HTTPMethod, PHPRequest, PHPRequestHeaders, RequestHandler, } from './universal-php';
|
|
1
|
+
export type { FileInfo, IsomorphicLocalPHP, IsomorphicRemotePHP, MessageListener, PHPOutput, PHPRunOptions, UniversalPHP, ListFilesOptions, RmDirOptions, PHPEvent, PHPEventListener, HTTPMethod, PHPRequest, PHPRequestHeaders, RequestHandler, SpawnHandler, } from './universal-php';
|
|
2
2
|
export { UnhandledRejectionsTarget } from './wasm-error-reporting';
|
|
3
3
|
export { PHPResponse } from './php-response';
|
|
4
4
|
export type { PHPResponseData } from './php-response';
|
package/lib/php-browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SupportedPHPVersions: readonly ["8.2", "8.1", "8.0", "7.4", "7.3", "7.2", "7.1", "7.0"
|
|
2
|
-
export declare const LatestSupportedPHPVersion: "8.
|
|
1
|
+
export declare const SupportedPHPVersions: readonly ["8.3", "8.2", "8.1", "8.0", "7.4", "7.3", "7.2", "7.1", "7.0"];
|
|
2
|
+
export declare const LatestSupportedPHPVersion: "8.3";
|
|
3
3
|
export declare const SupportedPHPVersionsList: string[];
|
|
4
4
|
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
package/lib/universal-php.d.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { Remote } from 'comlink';
|
|
2
2
|
import { PHPResponse } from './php-response';
|
|
3
|
+
/**
|
|
4
|
+
* Represents an event related to the PHP filesystem.
|
|
5
|
+
*/
|
|
6
|
+
export interface PHPRequestEndEvent {
|
|
7
|
+
type: 'request.end';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents an event related to the PHP instance.
|
|
11
|
+
* This is intentionally not an extension of CustomEvent
|
|
12
|
+
* to make it isomorphic between different JavaScript runtimes.
|
|
13
|
+
*/
|
|
14
|
+
export type PHPEvent = PHPRequestEndEvent;
|
|
15
|
+
/**
|
|
16
|
+
* A callback function that handles PHP events.
|
|
17
|
+
*/
|
|
18
|
+
export type PHPEventListener = (event: PHPEvent) => void;
|
|
3
19
|
/**
|
|
4
20
|
* Handles HTTP requests using PHP runtime as a backend.
|
|
5
21
|
*
|
|
6
22
|
* @public
|
|
7
23
|
* @example Use PHPRequestHandler implicitly with a new PHP instance:
|
|
8
24
|
* ```js
|
|
9
|
-
* import { PHP } from '
|
|
25
|
+
* import { PHP } from '../../../web/src/index.ts';
|
|
10
26
|
*
|
|
11
27
|
* const php = await PHP.load( '7.4', {
|
|
12
28
|
* requestHandler: {
|
|
@@ -131,6 +147,24 @@ export interface RequestHandler {
|
|
|
131
147
|
documentRoot: string;
|
|
132
148
|
}
|
|
133
149
|
export interface IsomorphicLocalPHP extends RequestHandler {
|
|
150
|
+
/**
|
|
151
|
+
* Defines a constant in the PHP runtime.
|
|
152
|
+
* @param key - The name of the constant.
|
|
153
|
+
* @param value - The value of the constant.
|
|
154
|
+
*/
|
|
155
|
+
defineConstant(key: string, value: string | number | null): void;
|
|
156
|
+
/**
|
|
157
|
+
* Adds an event listener for a PHP event.
|
|
158
|
+
* @param eventType - The type of event to listen for.
|
|
159
|
+
* @param listener - The listener function to be called when the event is triggered.
|
|
160
|
+
*/
|
|
161
|
+
addEventListener(eventType: PHPEvent['type'], listener: PHPEventListener): void;
|
|
162
|
+
/**
|
|
163
|
+
* Removes an event listener for a PHP event.
|
|
164
|
+
* @param eventType - The type of event to remove the listener from.
|
|
165
|
+
* @param listener - The listener function to be removed.
|
|
166
|
+
*/
|
|
167
|
+
removeEventListener(eventType: PHPEvent['type'], listener: PHPEventListener): void;
|
|
134
168
|
/**
|
|
135
169
|
* Sets the path to the php.ini file to use for the PHP instance.
|
|
136
170
|
*
|
|
@@ -343,8 +377,25 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
343
377
|
* @param listener Callback function to handle the message.
|
|
344
378
|
*/
|
|
345
379
|
onMessage(listener: MessageListener): void;
|
|
380
|
+
/**
|
|
381
|
+
* Registers a handler to spawns a child process when
|
|
382
|
+
* `proc_open()`, `popen()`, `exec()`, `system()`, or `passthru()`
|
|
383
|
+
* is called.
|
|
384
|
+
*
|
|
385
|
+
* @param handler Callback function to spawn a process.
|
|
386
|
+
*/
|
|
387
|
+
setSpawnHandler(handler: SpawnHandler): void;
|
|
388
|
+
}
|
|
389
|
+
export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
|
|
390
|
+
interface EventEmitter {
|
|
391
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
392
|
+
emit(event: string, ...args: any[]): boolean;
|
|
346
393
|
}
|
|
347
|
-
|
|
394
|
+
type ChildProcess = EventEmitter & {
|
|
395
|
+
stdout: EventEmitter;
|
|
396
|
+
stderr: EventEmitter;
|
|
397
|
+
};
|
|
398
|
+
export type SpawnHandler = (command: string) => ChildProcess;
|
|
348
399
|
export type IsomorphicRemotePHP = Remote<IsomorphicLocalPHP>;
|
|
349
400
|
export type UniversalPHP = IsomorphicLocalPHP | IsomorphicRemotePHP;
|
|
350
401
|
export type HTTPMethod = 'GET' | 'POST' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'PUT' | 'DELETE';
|
|
@@ -441,3 +492,4 @@ export interface ListFilesOptions {
|
|
|
441
492
|
*/
|
|
442
493
|
prependPath: boolean;
|
|
443
494
|
}
|
|
495
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/universal",
|
|
3
|
-
"version": "0.3
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "PHP.wasm – emscripten bindings for PHP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"main": "./index.cjs",
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"license": "GPL-2.0-or-later",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0fd1fdb7375443821b57aad84884b5bc5dca9815",
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=16.15.1",
|
|
42
42
|
"npm": ">=8.11.0"
|