API Index — Namespaces, Packages, Reports, Indices
HtmxResponse
in package
Fluent builder for htmx response headers (HX-*).
Obtain via Response::htmx() and chain setter calls; the headers are queued into the parent Response's headersList and emitted on the next flush().
$response->htmx()->retarget('#alerts')->reswap('afterbegin')->trigger('itemSaved');
All HX-* header values are validated for CRLF/NUL injection before queuing; invalid values trigger an E_USER_WARNING and are silently dropped (matching the behaviour of Response::header()).
Table of Contents
Properties
Methods
- __construct() : mixed
- location() : static
- HX-Location — client-side redirect that does not do a full page reload.
- oob() : string
- Wrap $html in an OOB swap element.
- pushUrl() : static
- HX-Push-Url — push a new URL onto the browser history stack.
- redirect() : static
- HX-Redirect — client-side redirect (no full page reload).
- refresh() : static
- HX-Refresh — set to "true" to trigger a full client-side page refresh.
- replaceUrl() : static
- HX-Replace-Url — replace the current URL in the location bar without
adding a history entry. Pass
false(as string "false") to prevent. - reselect() : static
- HX-Reselect — CSS selector choosing which part of the response body is swapped in (overrides an existing hx-select on the element).
- reswap() : static
- HX-Reswap — override the swap strategy declared on the triggering element.
- retarget() : static
- HX-Retarget — CSS selector that redirects the swap to a different element.
- trigger() : static
- HX-Trigger — trigger one or more client-side events after the swap.
- triggerAfterSettle() : static
- HX-Trigger-After-Settle — same as trigger() but fires after the settle step.
- triggerAfterSwap() : static
- HX-Trigger-After-Swap — same as trigger() but fires after the swap step.
- emit() : void
Properties
$response
private
Response
$response
Methods
__construct()
public
__construct(Response $response) : mixed
Parameters
- $response : Response
location()
HX-Location — client-side redirect that does not do a full page reload.
public
location(string $urlOrJson) : static
Accepts a URL string or a JSON-encoded location object
(e.g. {"path":"/page","target":"#content"}).
Parameters
- $urlOrJson : string
Return values
staticoob()
Wrap $html in an OOB swap element.
public
static oob(string $id, string $html[, string $swap = 'true' ][, string $tag = 'div' ]) : string
Generates a fragment like <div id="$id" hx-swap-oob="$swap">$html</div>.
Append the return value to any response body to perform an out-of-band
swap without an additional round-trip.
Parameters
- $id : string
-
The CSS id of the target element (without
#). - $html : string
-
Inner HTML to inject.
- $swap : string = 'true'
-
hx-swap-oob value (default: "true" → innerHTML).
- $tag : string = 'div'
-
Wrapper element tag (default: div).
Return values
stringpushUrl()
HX-Push-Url — push a new URL onto the browser history stack.
public
pushUrl(string $url) : static
Pass false (as string "false") to prevent pushing.
Parameters
- $url : string
Return values
staticredirect()
HX-Redirect — client-side redirect (no full page reload).
public
redirect(string $url) : static
Parameters
- $url : string
Return values
staticrefresh()
HX-Refresh — set to "true" to trigger a full client-side page refresh.
public
refresh([bool $refresh = true ]) : static
Parameters
- $refresh : bool = true
Return values
staticreplaceUrl()
HX-Replace-Url — replace the current URL in the location bar without
adding a history entry. Pass false (as string "false") to prevent.
public
replaceUrl(string $url) : static
Parameters
- $url : string
Return values
staticreselect()
HX-Reselect — CSS selector choosing which part of the response body is swapped in (overrides an existing hx-select on the element).
public
reselect(string $selector) : static
Parameters
- $selector : string
Return values
staticreswap()
HX-Reswap — override the swap strategy declared on the triggering element.
public
reswap(string $strategy) : static
Valid values: innerHTML, outerHTML, beforebegin, afterbegin, beforeend,
afterend, delete, none (and modifier suffixes such as innerHTML swap:1s).
Parameters
- $strategy : string
Return values
staticretarget()
HX-Retarget — CSS selector that redirects the swap to a different element.
public
retarget(string $selector) : static
Parameters
- $selector : string
Return values
statictrigger()
HX-Trigger — trigger one or more client-side events after the swap.
public
trigger(string $events) : static
Pass a single event name, a comma-separated list, or a JSON object for
events with detail data (e.g. {"showMessage":{"level":"info"}}).
Parameters
- $events : string
Return values
statictriggerAfterSettle()
HX-Trigger-After-Settle — same as trigger() but fires after the settle step.
public
triggerAfterSettle(string $events) : static
Parameters
- $events : string
Return values
statictriggerAfterSwap()
HX-Trigger-After-Swap — same as trigger() but fires after the swap step.
public
triggerAfterSwap(string $events) : static
Parameters
- $events : string
Return values
staticemit()
private
emit(string $name, string $value) : void
Parameters
- $name : string
- $value : string