Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 613 Bytes

File metadata and controls

31 lines (24 loc) · 613 Bytes

Extension System

Extensions in jsphp extend the abstract class PHPExtension:

import { PHPExtension, PHPEngine, PHPContext } from "jsphp";

export class CustomExtension extends PHPExtension {
  public readonly name = "custom";

  public onInit(engine: PHPEngine): void {
    this.constants = {
      CUSTOM_CONST: 42,
    };

    this.functions = {
      custom_hello: (ctx: PHPContext, name: string) => {
        return `Hello, ${name}!`;
      },
    };
  }
}

Registering a custom extension:

const engine = new PHPEngine({
  extensions: [new CustomExtension()],
});