Skip to content

Commit 21e4dde

Browse files
committed
Require lowercase method/function names in PHPContext accessors, add JSDoc documentation, and fix late static binding and switch fallthrough
1 parent ce48b27 commit 21e4dde

20 files changed

Lines changed: 645 additions & 151 deletions

‎src/PHPContext.d.ts‎

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ export declare class PHPResponse {
2222
value: string;
2323
}[];
2424
headersSent: boolean;
25+
/** Sets an HTTP response header. */
2526
setHeader(name: string, value: string, replace?: boolean): void;
27+
/** Removes an HTTP response header. */
2628
removeHeader(name?: string): void;
29+
/** Gets an HTTP response header value by name. */
2730
getHeader(name: string): string | undefined;
31+
/** Gets all formatted HTTP response headers. */
2832
getHeadersList(): string[];
33+
/** Sets a Set-Cookie HTTP header. */
2934
setCookie(name: string, value?: string, expires?: number, path?: string, domain?: string, secure?: boolean, httponly?: boolean, raw?: boolean): void;
3035
}
3136
export declare class PHPContext {
@@ -51,54 +56,147 @@ export declare class PHPContext {
5156
private stderr;
5257
outputText: string;
5358
constructor(engine: PHPEngine, options?: PHPContextOptions);
59+
currentClassStack: any[];
60+
get currentClass(): any;
61+
/**
62+
* Checks if an object is an instance of a class or interface.
63+
* @param className Class or interface name in lowercase.
64+
*/
5465
isInstanceOf(obj: any, className: string): boolean;
66+
/** Gets virtualized PHP stack trace frames for error handling and backtraces. */
5567
getPHPBacktrace(): any[];
68+
/** Sets a user-defined error handler function. */
5669
setErrorHandler(handler: any, levels?: number): any;
70+
/** Restores the previous error handler from the stack. */
5771
restoreErrorHandler(): boolean;
72+
/** Triggers a userland error or warning. */
5873
triggerError(message: string, level?: number, file?: string, line?: number): Promise<boolean>;
74+
/** Gets an internal variable value. */
5975
getInternalVar(name: string): any;
76+
/** Sets an internal variable value. */
6077
setInternalVar(name: string, value: any): void;
78+
/** Gets response headers as a key-value dictionary. */
6179
get responseHeaders(): Record<string, string>;
80+
/** Gets the current HTTP status code. */
6281
get statusCode(): number;
82+
/** Flushes response headers to the client. */
6383
flushHeaders(): void;
84+
/** Writes output text to stdout or active output buffer. */
6485
echo(data: any): Promise<void>;
6586
private writeStdout;
87+
/**
88+
* Gets a constant value by lowercase or exact name.
89+
* @param name Constant name in lowercase or exact key.
90+
*/
6691
getConstant(name: string): any;
92+
/**
93+
* Checks if a constant is defined.
94+
* @param name Constant name in lowercase or exact key.
95+
*/
6796
hasConstant(name: string): boolean;
97+
/**
98+
* Defines a constant.
99+
* @param name Constant name in lowercase or exact key.
100+
*/
68101
defineConstant(name: string, val: any): void;
102+
/** Gets a variable value from the current or global scope. */
69103
getVar(name: string): any;
104+
/** Sets a variable value in the current scope. */
70105
setVar(name: string, value: any): any;
106+
/** Binds a variable name to global scope. */
71107
bindGlobal(name: string): void;
108+
/** Pushes a new variable scope. */
72109
pushScope(): void;
110+
/** Pops the current variable scope. */
73111
popScope(): void;
112+
/** Sets a single array offset on a variable. */
74113
setVarOffset(name: string, key: any, value: any): any;
114+
/** Sets nested array offsets on a variable. */
75115
setVarOffsets(name: string, keys: any[], value: any): any;
76116
private assignOffsets;
77117
private assignOffset;
118+
/** Initializes a static variable in function scope. */
78119
initStaticVar(scope: string, name: string, value: any): void;
120+
/** Evaluates whether a value is truthy in PHP. */
79121
isTruthy(val: any): boolean;
122+
/**
123+
* Gets a property on an object or array.
124+
* @param prop Property name in lowercase.
125+
*/
80126
getProperty(obj: any, prop: string): Promise<any>;
127+
/**
128+
* Sets a property on an object or array.
129+
* @param prop Property name in lowercase.
130+
*/
81131
setProperty(obj: any, prop: string, value: any): Promise<any>;
132+
/** Sets a single property offset on an object. */
82133
setPropertyOffset(obj: any, prop: string, key: any, value: any): Promise<any>;
134+
/** Sets nested property offsets on an object. */
83135
setPropertyOffsets(obj: any, prop: string, keys: any[], value: any): Promise<any>;
136+
/**
137+
* Calls a method on an object.
138+
* Expects method name in lowercase.
139+
* @param method Method name in lowercase.
140+
*/
84141
callMethod(obj: any, method: string, args?: any[]): Promise<any>;
142+
/** Gets a PHPReference wrapper for a variable name. */
85143
getVarRef(name: string): PHPReference;
86-
referenceVariable(name: string): PHPReference;
144+
/**
145+
* Calls a global function.
146+
* Expects function name in lowercase.
147+
* @param name Function name in lowercase.
148+
*/
87149
callFunction(name: string, args?: any[], references?: (string | null)[]): Promise<any>;
150+
/**
151+
* Resolves a class by lowercase name.
152+
* @param className Class name in lowercase.
153+
*/
88154
resolveClass(className: string): Promise<any>;
155+
/**
156+
* Gets a static class constant.
157+
* @param className Class name in lowercase.
158+
* @param name Constant name in lowercase.
159+
*/
89160
getClassConstant(className: string, name: string): Promise<any>;
161+
/**
162+
* Gets a static class property.
163+
* @param className Class name in lowercase.
164+
* @param name Property name in lowercase.
165+
*/
90166
getStaticProperty(className: string, name: string): Promise<any>;
167+
/**
168+
* Sets a static class property.
169+
* @param className Class name in lowercase.
170+
* @param name Property name in lowercase.
171+
*/
91172
setStaticProperty(className: string, name: string, value: any): Promise<any>;
173+
/** Sets static property array offsets. */
92174
setStaticPropertyOffsets(className: string, name: string, keys: any[], value: any): Promise<any>;
93-
callStaticMethod(className: string, method: string, args?: any[]): Promise<any>;
175+
/**
176+
* Calls a static method on a class.
177+
* @param className Class name in lowercase.
178+
* @param method Method name in lowercase.
179+
*/
180+
callStaticMethod(className: string, method: string, args?: any[], targetObj?: any): Promise<any>;
181+
/**
182+
* Creates an instance of a class.
183+
* @param className Class name in lowercase.
184+
*/
94185
createObject(className: string, args?: any[]): Promise<any>;
186+
/** Evaluates PHP code in the context. */
95187
eval(code: string, filepath?: string): Promise<any>;
96188
private fileExists;
97189
private normalizeFilePath;
190+
/** Includes a PHP file. */
98191
include(filepath: string): Promise<any>;
192+
/** Includes a PHP file if not already included. */
99193
includeOnce(filepath: string): Promise<any>;
194+
/** Requires a PHP file. */
100195
require(filepath: string): Promise<any>;
196+
/** Requires a PHP file if not already required. */
101197
requireOnce(filepath: string): Promise<any>;
198+
/** Helper to create an engine, context, and execute a file. */
102199
static runFile(filepath: string, options?: PHPContextOptions): Promise<PHPContext>;
200+
/** Helper to create an engine, context, and execute inline PHP code. */
103201
static runCode(code: string, options?: PHPContextOptions): Promise<PHPContext>;
104202
}

0 commit comments

Comments
 (0)