@php-wasm/universal 0.7.18 → 0.7.20

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/lib/base-php.d.ts CHANGED
@@ -1,14 +1,26 @@
1
+ /// <reference types="emscripten" />
1
2
  import { PHPResponse } from './php-response';
2
3
  import type { PHPRuntimeId } from './load-php-runtime';
3
4
  import { IsomorphicLocalPHP, MessageListener, PHPRequest, PHPRequestHeaders, PHPRunOptions, RmDirOptions, ListFilesOptions, SpawnHandler, PHPEventListener, PHPEvent } from './universal-php';
4
5
  import { Semaphore } from '../../../util/src/index.ts';
5
6
  import { PHPRequestHandler } from './php-request-handler';
7
+ declare namespace Emscripten {
8
+ type NamespaceToInstance<T> = {
9
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never;
10
+ };
11
+ export type FileSystemInstance = NamespaceToInstance<typeof FS> & {
12
+ mkdirTree(path: string): void;
13
+ lookupPath(path: string, opts?: any): FS.Lookup;
14
+ };
15
+ export {};
16
+ }
6
17
  export declare const __private__dont__use: unique symbol;
7
18
  export declare class PHPExecutionFailureError extends Error {
8
19
  response: PHPResponse;
9
20
  source: 'request' | 'php-wasm';
10
21
  constructor(message: string, response: PHPResponse, source: 'request' | 'php-wasm');
11
22
  }
23
+ export declare const PHP_INI_PATH = "/internal/shared/php.ini";
12
24
  /**
13
25
  * An environment-agnostic wrapper around the Emscripten PHP runtime
14
26
  * that universals the super low-level API and provides a more convenient
@@ -53,10 +65,6 @@ export declare abstract class BasePHP implements IsomorphicLocalPHP, Disposable
53
65
  /** @inheritDoc */
54
66
  setSapiName(newName: string): Promise<void>;
55
67
  /** @inheritDoc */
56
- setPhpIniPath(path: string): void;
57
- /** @inheritDoc */
58
- setPhpIniEntry(key: string, value: string): void;
59
- /** @inheritDoc */
60
68
  chdir(path: string): void;
61
69
  /**
62
70
  * Do not use. Use new PHPRequestHandler() instead.
@@ -103,11 +111,10 @@ export declare abstract class BasePHP implements IsomorphicLocalPHP, Disposable
103
111
  [Symbol.dispose](): void;
104
112
  }
105
113
  export declare function normalizeHeaders(headers: PHPRequestHeaders): PHPRequestHeaders;
106
- type EmscriptenFS = any;
107
114
  export declare function syncFSTo(source: BasePHP, target: BasePHP, path?: string | null): void;
108
115
  /**
109
116
  * Copies the MEMFS directory structure from one FS in another FS.
110
117
  * Non-MEMFS nodes are ignored.
111
118
  */
112
- export declare function copyFS(source: EmscriptenFS, target: EmscriptenFS, path: string): void;
119
+ export declare function copyFS(source: Emscripten.FileSystemInstance, target: Emscripten.FileSystemInstance, path: string): void;
113
120
  export {};
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { IsomorphicLocalPHP, IsomorphicRemotePHP, MessageListener, PHPOutput, PHPRunOptions, UniversalPHP, ListFilesOptions, RmDirOptions, PHPEvent, PHPEventListener, HTTPMethod, PHPRequest, PHPRequestHeaders, SpawnHandler, } from './universal-php';
2
+ export { getPhpIniEntries, setPhpIniEntries, withPHPIniValues } from './ini';
2
3
  export { UnhandledRejectionsTarget } from './wasm-error-reporting';
3
4
  export { HttpCookieStore } from './http-cookie-store';
4
5
  export type { IteratePhpFilesOptions as IterateFilesOptions } from './iterate-files';
@@ -25,3 +26,4 @@ export { rotatePHPRuntime } from './rotate-php-runtime';
25
26
  export { writeFiles } from './write-files';
26
27
  export { DEFAULT_BASE_URL, ensurePathPrefix, removePathPrefix, toRelativeUrl, } from './urls';
27
28
  export { isExitCodeZero } from './is-exit-code-zero';
29
+ export { proxyFileSystem } from './proxy-file-system';
package/lib/ini.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { UniversalPHP } from './universal-php';
2
+ /**
3
+ * Reads the php.ini file and returns its entries.
4
+ *
5
+ * @param php The PHP instance.
6
+ * @param entries Optional. If provided, only the specified entries will be returned.
7
+ * @returns The php.ini entries.
8
+ */
9
+ export declare function getPhpIniEntries(php: UniversalPHP, entries?: string[]): Promise<{
10
+ [key: string]: any;
11
+ }>;
12
+ /**
13
+ * Rewrites the php.ini file with the given entries.
14
+ *
15
+ * @param php The PHP instance.
16
+ * @param entries The entries to write to the php.ini file.
17
+ */
18
+ export declare function setPhpIniEntries(php: UniversalPHP, entries: Record<string, unknown>): Promise<void>;
19
+ /**
20
+ * Sets php.ini values to the given values, executes a callback,
21
+ * and restores the original php.ini values. This is useful for
22
+ * running code with temporary php.ini values, such as when
23
+ * disabling network-related PHP functions just to run WordPress
24
+ * installer.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * await withPHPIniValues(
29
+ * php,
30
+ * {
31
+ * disable_functions: 'fsockopen',
32
+ * allow_url_fopen: '0',
33
+ * },
34
+ * async () => await runWpInstallationWizard(php, {
35
+ * options: {},
36
+ * })
37
+ * );
38
+ * ```
39
+ *
40
+ * @param php The PHP instance.
41
+ * @param phpIniValues The php.ini values to set.
42
+ * @param callback The callback to execute.
43
+ * @returns The result of the callback.
44
+ */
45
+ export declare function withPHPIniValues(php: UniversalPHP, phpIniValues: Record<string, string>, callback: () => Promise<void>): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { BasePHP } from './base-php';
2
+ /**
3
+ * Proxy specific paths to the parent's MEMFS instance.
4
+ * This is useful for sharing the WordPress installation
5
+ * between the parent and child processes.
6
+ */
7
+ export declare function proxyFileSystem(sourceOfTruth: BasePHP, replica: BasePHP, paths: string[]): void;
@@ -70,19 +70,6 @@ export interface IsomorphicLocalPHP {
70
70
  * @param listener - The listener function to be removed.
71
71
  */
72
72
  removeEventListener(eventType: PHPEvent['type'], listener: PHPEventListener): void;
73
- /**
74
- * Sets the path to the php.ini file to use for the PHP instance.
75
- *
76
- * @param path - The path to the php.ini file.
77
- */
78
- setPhpIniPath(path: string): void;
79
- /**
80
- * Sets a value for a specific key in the php.ini file for the PHP instance.
81
- *
82
- * @param key - The key to set the value for.
83
- * @param value - The value to set for the key.
84
- */
85
- setPhpIniEntry(key: string, value: string): void;
86
73
  /**
87
74
  * Recursively creates a directory with the given path in the PHP filesystem.
88
75
  * For example, if the path is `/root/php/data`, and `/root` already exists,
@@ -299,7 +286,7 @@ export type SpawnHandler = (command: string, args: string[]) => ChildProcess;
299
286
  * that can't be serialized over a remote connection. Therefeore,
300
287
  * they don't make sense in a remote PHP instance.
301
288
  */
302
- export type IsomorphicRemotePHP = Remote<Omit<IsomorphicLocalPHP, 'setSapiName' | 'setPhpIniEntry' | 'setPhpIniPath'>>;
289
+ export type IsomorphicRemotePHP = Remote<Omit<IsomorphicLocalPHP, 'setSapiName'>>;
303
290
  export type UniversalPHP = IsomorphicLocalPHP | IsomorphicRemotePHP;
304
291
  export type HTTPMethod = 'GET' | 'POST' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'PUT' | 'DELETE';
305
292
  export type PHPRequestHeaders = Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/universal",
3
- "version": "0.7.18",
3
+ "version": "0.7.20",
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": "44ba621a9ca5e78acd5d6995da44ac460f8adc50",
39
+ "gitHead": "5915ef756c88da8dcb665f9f0e49ddc0c0b10d50",
40
40
  "engines": {
41
41
  "node": ">=18.18.0",
42
42
  "npm": ">=8.11.0"