Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

ZealJsBinder extends FormBinder
in package

FinalYes

Components without htmx: a small script (/_zeal/c/zeal.js) that speaks the plain protocol (Zeal-Request: 1, Zeal-Events, Zeal-Redirect, Zeal-Reload, 422 for validation).

App::componentBinder(new ZealJsBinder()); // in the layout, once: = ZealJsBinder::script() ?>

Built on FormBinder, so the markup stays a working form without JavaScript; this binder only adds data-zc-* markers the script reads:

  • actions: data-zc-action on the element (its formaction and value already carry the URL and arguments);
  • live inputs: data-zc-live (debounce in ms) and data-zc-update; on-blur inputs: data-zc-blur and data-zc-update.

The script swaps the re-rendered component in place, keeps the value, focus and cursor of the field being typed in, lets an action replace a live update still in flight on the same component, and re-dispatches Zeal-Events as DOM events (CustomEvent, bubbling, detail set) on the component.

Table of Contents

Constants

SCRIPT  : mixed = '/_zeal/c/zeal.js'

Properties

$version  : string|null

Methods

actionAttributes()  : array<string, string|bool|null>
Attributes for an element that triggers an action.
isAsync()  : bool
Whether the request came from this binder's client script (rather than a plain form post that expects a redirect back to the page).
modelAttributes()  : array<string, string|bool|null>
Attributes for a form control bound to a #[Model] property.
refusalHeaders()  : array<string, string>
Extra headers for a refused request (400/403/404), e.g. telling the client not to swap the error text into the page.
response()  : array{status: int, headers: array}
Status and headers for an endpoint outcome.
rootAttributes()  : array<string, string|bool|null>
Extra attributes for the component's outer element.
script()  : SafeHtml
The script tag for the layout, versioned by the script's content.
source()  : string
The client script's source, served at {@see self::SCRIPT}.
triggerField()  : string|null
The name of the form control that triggered the request, if the client reports it.
version()  : string

Constants

Properties

Methods

actionAttributes()

Attributes for an element that triggers an action.

public actionAttributes(Component $component, string $url, string $argsJson) : array<string, string|bool|null>
Parameters
$component : Component
$url : string
$argsJson : string

the action arguments, JSON-encoded

Return values
array<string, string|bool|null>

isAsync()

Whether the request came from this binder's client script (rather than a plain form post that expects a redirect back to the page).

public isAsync(array<string|int, mixed> $server) : bool
Parameters
$server : array<string|int, mixed>

CGI-style request variables (HTTP_*)

Return values
bool

modelAttributes()

Attributes for a form control bound to a #[Model] property.

public modelAttributes(Component $component, string $prop, Model $model, string $updateUrl, bool $preserve) : array<string, string|bool|null>
Parameters
$component : Component
$prop : string
$model : Model
$updateUrl : string

the component's _update endpoint

$preserve : bool

true when this control triggered the current update and should be left untouched by the swap

Return values
array<string, string|bool|null>

refusalHeaders()

Extra headers for a refused request (400/403/404), e.g. telling the client not to swap the error text into the page.

public refusalHeaders() : array<string, string>
Return values
array<string, string>

response()

Status and headers for an endpoint outcome.

public response(Outcome $outcome, array<string|int, mixed> $events, string|null $redirect) : array{status: int, headers: array}
Parameters
$outcome : Outcome
$events : array<string|int, mixed>

event name → detail

$redirect : string|null
Return values
array{status: int, headers: array}

rootAttributes()

Extra attributes for the component's outer element.

public rootAttributes(Component $component, string|null $submitUrl) : array<string, string|bool|null>
Parameters
$component : Component
$submitUrl : string|null

the URL of the component's $submit action, if any

Return values
array<string, string|bool|null>

source()

The client script's source, served at {@see self::SCRIPT}.

public static source() : string
Return values
string

triggerField()

The name of the form control that triggered the request, if the client reports it.

public triggerField(array<string|int, mixed> $server) : string|null
Parameters
$server : array<string|int, mixed>
Return values
string|null

version()

private static version() : string
Return values
string
On this page