Start free trial

Extensions (PHP) · Replaceable services

Replaceable services

Some of the board's services can be supplied by your extension instead of the built-in one: send AI requests to your own model, scan images with another moderation service, or ask new members a different registration question. You implement a contract, and the board uses your class wherever it needs that service.

The services

ServiceKeyContractBuilt-in
AI text ai AiClient Anthropic or OpenAI, with the key set in AI settings
Image moderation image_moderation ContentModerationProvider Sightengine
Registration check captcha Captcha Cloudflare Turnstile, for registrations from flagged addresses

Only these services can be replaced. Anything else stays the board's own, so an update to ForumSpark never breaks on a class your extension changed.

Make one

php artisan fs:make service captcha

This adds src/Services/CaptchaService.php with every method of the contract and a safe placeholder in each. Fill them in and run fs:sync. Developer, Replaceable services in the admin panel lists every method and shows which service is in use on your board.

A registration check

The register page asks your class whether a new member must answer, shows the markup you return and checks the answer when the form is sent. Errors show under the field you name.

class RiddleCaptcha implements Captcha
{
    public function required(Request $request): bool
    {
        return true;
    }

    public function widget(Request $request): ?Htmlable
    {
        return new HtmlString(view('acme-riddle::question')->render());
    }

    public function passes(Request $request): bool
    {
        return Str::lower(trim((string) $request->input('riddle'))) === 'echo';
    }

    public function field(): string
    {
        return 'riddle';
    }
}

How the board chooses

  • A class in src/Services that implements one of the contracts is picked up when your extension is on. It is created through the container, so its constructor can ask for what it needs.
  • If two extensions supply the same service, the one installed first is used.
  • Admins see on your extension's row in Apps, Extensions that it replaces a service, and can go back to the built-in one from its menu without turning your extension off.
  • If your class cannot be created, the error is logged and the built-in service is used, so the board keeps working.
  • fs:check warns about a class in src/Services that implements none of the contracts, since the board ignores it.