{"id":43405993,"url":"https://github.com/tomrf/htmx-message","last_synced_at":"2026-02-02T15:58:13.856Z","repository":{"id":44371684,"uuid":"512302404","full_name":"tomrf/htmx-message","owner":"tomrf","description":"PHP PSR-7 proxy classes with convenience methods for htmx (htmx.org) requests and responses","archived":false,"fork":false,"pushed_at":"2023-11-10T13:24:10.000Z","size":375,"stargazers_count":13,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-02T17:37:33.092Z","etag":null,"topics":["htmx","http-message","php","php-htmx","psr-7","responseinterface","serverrequestinterface"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomrf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-09T23:07:14.000Z","updated_at":"2024-08-08T12:10:26.000Z","dependencies_parsed_at":"2023-01-27T22:15:23.857Z","dependency_job_id":null,"html_url":"https://github.com/tomrf/htmx-message","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tomrf/htmx-message","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomrf%2Fhtmx-message","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomrf%2Fhtmx-message/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomrf%2Fhtmx-message/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomrf%2Fhtmx-message/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomrf","download_url":"https://codeload.github.com/tomrf/htmx-message/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomrf%2Fhtmx-message/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29015007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T14:58:54.169Z","status":"ssl_error","status_checked_at":"2026-02-02T14:58:51.285Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["htmx","http-message","php","php-htmx","psr-7","responseinterface","serverrequestinterface"],"created_at":"2026-02-02T15:58:13.087Z","updated_at":"2026-02-02T15:58:13.849Z","avatar_url":"https://github.com/tomrf.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# htmx-message - PHP PSR-7 proxy classes with convenience methods for htmx requests and responses\n\n[![PHP Version Require](http://poser.pugx.org/tomrf/htmx-message/require/php?style=flat-square)](https://packagist.org/packages/tomrf/htmx-message) [![Latest Stable Version](http://poser.pugx.org/tomrf/htmx-message/v?style=flat-square)](https://packagist.org/packages/tomrf/htmx-message) [![License](http://poser.pugx.org/tomrf/htmx-message/license?style=flat-square)](https://packagist.org/packages/tomrf/htmx-message)\n\nPSR-7 `ServerRequestInterface` and `ResponseInterface` proxy classes for [`htmx`](https://htmx.org)\nwith convenience methods for all special htmx headers (`HX-*`) in request and\nresponse objects.\n\n`HtmxResponse` is a proxy for PSR-7 response objects implementing `\\Psr\\Http\\Message\\ResponseInterface`.\n\n`HtmxServerRequest` is a proxy for PSR-7 server request objects implementing `\\Psr\\Http\\Message\\ServerRequestInterface`.\n\nYou can safely wrap any `ResponseInterface` or `ServerRequestInterface` object, also those not originating from [`htmx`](htmx.org), without affecting your application.\n\n`HtmxResponse` and `HtmxServerRequest` objects retains immutability in the same fashion as one would expect from a PSR-7 `MessageInterface`, returning a new object wrapping a new `ResponseInterface` instance whenever the `HtmxResponse` is changed.\n\nConforms to [`htmx`](https://htmx.org) version 1.9.x (latest) as per 2023-08-01.\n\n📔 [Go to documentation](#documentation)\n\n## Installation\nInstallation via composer:\n\n```bash\ncomposer require tomrf/htmx-message\n```\n\n## Usage\n```php\n$request = new HtmxRequest($request);     // PSR-7 `ServerRequestInterface`\n\nif ($request-\u003eisHxRequest() \u0026\u0026 $request-\u003eisHxBoosted()) {\n    $layout = 'ajax.layout';\n}\n\n[...]\n\n$response = new HtmxResponse($response);  // PSR-7 `ResponseInterface`\n\n$response = $response-\u003ewithHxTrigger('aSimpleTrigger')\n    -\u003ewithAddedHxTrigger('triggerWithParams', ['arg' =\u003e true, 'arg2' =\u003e 7])\n    -\u003ewithTriggerAfterSwap('afterSwap', time())\n    -\u003ewithHxPush($newUrl);\n\n// Emit $response as normal\n[...]\n```\n\n## Testing\n```bash\ncomposer test\n```\n\n## License\nThis project is released under the MIT License (MIT).\nSee [LICENSE](LICENSE) for more information.\n\n## Documentation\n - [Tomrf\\HtmxMessage\\HtmxResponse](#-tomrfhtmxmessagehtmxresponseclass)\n   - [getHxPush](#gethxpush)\n   - [getHxRedirect](#gethxredirect)\n   - [getHxRetarget](#gethxretarget)\n   - [getHxTrigger](#gethxtrigger)\n   - [getHxTriggerAfterSettle](#gethxtriggeraftersettle)\n   - [getHxTriggerAfterSwap](#gethxtriggerafterswap)\n   - [hasHxPush](#hashxpush)\n   - [hasHxRedirect](#hashxredirect)\n   - [hasHxRefresh](#hashxrefresh)\n   - [hasHxRetarget](#hashxretarget)\n   - [hasHxTrigger](#hashxtrigger)\n   - [hasHxTriggerAfterSettle](#hashxtriggeraftersettle)\n   - [hasHxTriggerAfterSwap](#hashxtriggerafterswap)\n   - [withAddedHxTrigger](#withaddedhxtrigger)\n   - [withAddedHxTriggerAfterSettle](#withaddedhxtriggeraftersettle)\n   - [withAddedHxTriggerAfterSwap](#withaddedhxtriggerafterswap)\n   - [withHxPush](#withhxpush)\n   - [withHxRedirect](#withhxredirect)\n   - [withHxRefresh](#withhxrefresh)\n   - [withHxRetarget](#withhxretarget)\n   - [withHxTrigger](#withhxtrigger)\n   - [withHxTriggerAfterSettle](#withhxtriggeraftersettle)\n   - [withHxTriggerAfterSwap](#withhxtriggerafterswap)\n   - [withoutHxPush](#withouthxpush)\n   - [withoutHxRedirect](#withouthxredirect)\n   - [withoutHxRefresh](#withouthxrefresh)\n   - [withoutHxRetarget](#withouthxretarget)\n   - [withoutHxTrigger](#withouthxtrigger)\n   - [withoutHxTriggerAfterSettle](#withouthxtriggeraftersettle)\n   - [withoutHxTriggerAfterSwap](#withouthxtriggerafterswap)\n - [Tomrf\\HtmxMessage\\HtmxServerRequest](#-tomrfhtmxmessagehtmxserverrequestclass)\n   - [getHxCurrentUrl](#gethxcurrenturl)\n   - [getHxPrompt](#gethxprompt)\n   - [getHxTarget](#gethxtarget)\n   - [getHxTrigger](#gethxtrigger)\n   - [getHxTriggerName](#gethxtriggername)\n   - [hasHxPrompt](#hashxprompt)\n   - [hasHxTarget](#hashxtarget)\n   - [hasHxTrigger](#hashxtrigger)\n   - [hasHxTriggerName](#hashxtriggername)\n   - [isHxBoosted](#ishxboosted)\n   - [isHxHistoryRestoreRequest](#ishxhistoryrestorerequest)\n   - [isHxRequest](#ishxrequest)\n   - [__construct](#__construct)\n\n\n***\n\n### 📂 Tomrf\\HtmxMessage\\HtmxResponse::class\n\nHtmxResponse is a proxy for PSR-7 response objects implementing\n\\Psr\\Http\\Message\\ResponseInterface.\n\nYou can safely wrap any ResponseInterface object, also those not\nresponding to a htmx request, without affecting your application.\n\nHtmxResponse objects retains immutability in the same fashion as\none would expect from a PSR-7 MessageInterface, returning a new object\nwrapping a new ResponseInterface instance whenever the HtmxResponse\nis changed.\n\nExample:\n\n    $response = new HtmxResponse($response);\n    $response = $response-\u003ewithHxTrigger('myTrigger')\n        -\u003ewithRedirect('/user/redirected')\n        -\u003ewithHxPush(false);\n\n    // ...\n\n#### getHxPush()\n\n```php\npublic function getHxPush(): string\n```\n\n#### getHxRedirect()\n\n```php\npublic function getHxRedirect(): string\n```\n\n#### getHxRetarget()\n\n```php\npublic function getHxRetarget(): string\n```\n\n#### getHxTrigger()\n\n```php\npublic function getHxTrigger(): array\n\n@return   array\n```\n\n#### getHxTriggerAfterSettle()\n\n```php\npublic function getHxTriggerAfterSettle(): array\n\n@return   array\n```\n\n#### getHxTriggerAfterSwap()\n\n```php\npublic function getHxTriggerAfterSwap(): array\n\n@return   array\n```\n\n#### hasHxPush()\n\n```php\npublic function hasHxPush(): bool\n```\n\n#### hasHxRedirect()\n\n```php\npublic function hasHxRedirect(): bool\n```\n\n#### hasHxRefresh()\n\n```php\npublic function hasHxRefresh(): bool\n```\n\n#### hasHxRetarget()\n\n```php\npublic function hasHxRetarget(): bool\n```\n\n#### hasHxTrigger()\n\n```php\npublic function hasHxTrigger(): bool\n```\n\n#### hasHxTriggerAfterSettle()\n\n```php\npublic function hasHxTriggerAfterSettle(): bool\n```\n\n#### hasHxTriggerAfterSwap()\n\n```php\npublic function hasHxTriggerAfterSwap(): bool\n```\n\n#### withAddedHxTrigger()\n\n```php\npublic function withAddedHxTrigger(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withAddedHxTriggerAfterSettle()\n\n```php\npublic function withAddedHxTriggerAfterSettle(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withAddedHxTriggerAfterSwap()\n\n```php\npublic function withAddedHxTriggerAfterSwap(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withHxPush()\n\n```php\npublic function withHxPush(\n    string|bool $url\n): static\n```\n\n#### withHxRedirect()\n\n```php\npublic function withHxRedirect(\n    string $url\n): static\n```\n\n#### withHxRefresh()\n\n```php\npublic function withHxRefresh(): static\n```\n\n#### withHxRetarget()\n\n```php\npublic function withHxRetarget(\n    string $selector\n): static\n```\n\n#### withHxTrigger()\n\n```php\npublic function withHxTrigger(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withHxTriggerAfterSettle()\n\n```php\npublic function withHxTriggerAfterSettle(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withHxTriggerAfterSwap()\n\n```php\npublic function withHxTriggerAfterSwap(\n    string $trigger,\n    mixed $argument = null\n): static\n```\n\n#### withoutHxPush()\n\n```php\npublic function withoutHxPush(): static\n```\n\n#### withoutHxRedirect()\n\n```php\npublic function withoutHxRedirect(): static\n```\n\n#### withoutHxRefresh()\n\n```php\npublic function withoutHxRefresh(): static\n```\n\n#### withoutHxRetarget()\n\n```php\npublic function withoutHxRetarget(): static\n```\n\n#### withoutHxTrigger()\n\n```php\npublic function withoutHxTrigger(): static\n```\n\n#### withoutHxTriggerAfterSettle()\n\n```php\npublic function withoutHxTriggerAfterSettle(): static\n```\n\n#### withoutHxTriggerAfterSwap()\n\n```php\npublic function withoutHxTriggerAfterSwap(): static\n```\n\n\n***\n\n### 📂 Tomrf\\HtmxMessage\\HtmxServerRequest::class\n\nHtmxServerRequest is a proxy for PSR-7 server request objects implementing\n\\Psr\\Http\\Message\\ServerRequestInterface.\n\nYou can safely wrap any ServerRequestInterface object, also those not\noriginating from htmx, without affecting your application.\n\nCheck if the request originated from htmx using the isHxRequest() method.\n\nHtmxServerRequest objects retains immutability in the same fashion as\none would expect from a PSR-7 MessageInterface, returning a new object\nwrapping a new ServerRequestInterface instance whenever the HtmxServerRequest\nis changed.\n\nExample:\n\n    $request = new HtmxServerRequest($request);\n    if ($request-\u003eisHxRequest() \u0026\u0026 $request-\u003eisHxBoosted()) {\n        // htmx request from boosted client, respond accordingly\n    }\n\n    $userPrompt = $request-\u003egetHxPrompt();\n    // ...\n\n#### getHxCurrentUrl()\n\n```php\npublic function getHxCurrentUrl(): string\n```\n\n#### getHxPrompt()\n\n```php\npublic function getHxPrompt(): string\n```\n\n#### getHxTarget()\n\n```php\npublic function getHxTarget(): string\n```\n\n#### getHxTrigger()\n\n```php\npublic function getHxTrigger(): string\n```\n\n#### getHxTriggerName()\n\n```php\npublic function getHxTriggerName(): string\n```\n\n#### hasHxPrompt()\n\n```php\npublic function hasHxPrompt(): bool\n```\n\n#### hasHxTarget()\n\n```php\npublic function hasHxTarget(): bool\n```\n\n#### hasHxTrigger()\n\n```php\npublic function hasHxTrigger(): bool\n```\n\n#### hasHxTriggerName()\n\n```php\npublic function hasHxTriggerName(): bool\n```\n\n#### isHxBoosted()\n\n```php\npublic function isHxBoosted(): bool\n```\n\n#### isHxHistoryRestoreRequest()\n\n```php\npublic function isHxHistoryRestoreRequest(): bool\n```\n\n#### isHxRequest()\n\n```php\npublic function isHxRequest(): bool\n```\n\n#### __construct()\n\n```php\npublic function __construct(\n    Psr\\Http\\Message\\ServerRequestInterface $message\n): void\n```\n\n\n\n***\n\n_Generated 2023-08-18T12:46:49+00:00 using 📚[tomrf/readme-gen](https://packagist.org/packages/tomrf/readme-gen)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomrf%2Fhtmx-message","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomrf%2Fhtmx-message","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomrf%2Fhtmx-message/lists"}