tomrf/htmx-message
Composer 安装命令:
composer require tomrf/htmx-message
包简介
PHP PSR-7 proxy classes with convenience methods for htmx requests and responses
README 文档
README
PSR-7 ServerRequestInterface and ResponseInterface proxy classes for htmx
with convenience methods for all special htmx headers (HX-*) in request and
response objects.
HtmxResponse is a proxy for PSR-7 response objects implementing \Psr\Http\Message\ResponseInterface.
HtmxServerRequest is a proxy for PSR-7 server request objects implementing \Psr\Http\Message\ServerRequestInterface.
You can safely wrap any ResponseInterface or ServerRequestInterface object, also those not originating from htmx, without affecting your application.
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.
Conforms to htmx version 1.9.x (latest) as per 2023-08-01.
Installation
Installation via composer:
composer require tomrf/htmx-message
Usage
$request = new HtmxRequest($request); // PSR-7 `ServerRequestInterface` if ($request->isHxRequest() && $request->isHxBoosted()) { $layout = 'ajax.layout'; } [...] $response = new HtmxResponse($response); // PSR-7 `ResponseInterface` $response = $response->withHxTrigger('aSimpleTrigger') ->withAddedHxTrigger('triggerWithParams', ['arg' => true, 'arg2' => 7]) ->withTriggerAfterSwap('afterSwap', time()) ->withHxPush($newUrl); // Emit $response as normal [...]
Testing
composer test
License
This project is released under the MIT License (MIT). See LICENSE for more information.
Documentation
- Tomrf\HtmxMessage\HtmxResponse
- getHxPush
- getHxRedirect
- getHxRetarget
- getHxTrigger
- getHxTriggerAfterSettle
- getHxTriggerAfterSwap
- hasHxPush
- hasHxRedirect
- hasHxRefresh
- hasHxRetarget
- hasHxTrigger
- hasHxTriggerAfterSettle
- hasHxTriggerAfterSwap
- withAddedHxTrigger
- withAddedHxTriggerAfterSettle
- withAddedHxTriggerAfterSwap
- withHxPush
- withHxRedirect
- withHxRefresh
- withHxRetarget
- withHxTrigger
- withHxTriggerAfterSettle
- withHxTriggerAfterSwap
- withoutHxPush
- withoutHxRedirect
- withoutHxRefresh
- withoutHxRetarget
- withoutHxTrigger
- withoutHxTriggerAfterSettle
- withoutHxTriggerAfterSwap
- Tomrf\HtmxMessage\HtmxServerRequest
📂 Tomrf\HtmxMessage\HtmxResponse::class
HtmxResponse is a proxy for PSR-7 response objects implementing \Psr\Http\Message\ResponseInterface.
You can safely wrap any ResponseInterface object, also those not responding to a htmx request, without affecting your application.
HtmxResponse 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.
Example:
$response = new HtmxResponse($response);
$response = $response->withHxTrigger('myTrigger')
->withRedirect('/user/redirected')
->withHxPush(false);
// ...
getHxPush()
public function getHxPush(): string
getHxRedirect()
public function getHxRedirect(): string
getHxRetarget()
public function getHxRetarget(): string
getHxTrigger()
public function getHxTrigger(): array @return array
getHxTriggerAfterSettle()
public function getHxTriggerAfterSettle(): array @return array
getHxTriggerAfterSwap()
public function getHxTriggerAfterSwap(): array @return array
hasHxPush()
public function hasHxPush(): bool
hasHxRedirect()
public function hasHxRedirect(): bool
hasHxRefresh()
public function hasHxRefresh(): bool
hasHxRetarget()
public function hasHxRetarget(): bool
hasHxTrigger()
public function hasHxTrigger(): bool
hasHxTriggerAfterSettle()
public function hasHxTriggerAfterSettle(): bool
hasHxTriggerAfterSwap()
public function hasHxTriggerAfterSwap(): bool
withAddedHxTrigger()
public function withAddedHxTrigger( string $trigger, mixed $argument = null ): static
withAddedHxTriggerAfterSettle()
public function withAddedHxTriggerAfterSettle( string $trigger, mixed $argument = null ): static
withAddedHxTriggerAfterSwap()
public function withAddedHxTriggerAfterSwap( string $trigger, mixed $argument = null ): static
withHxPush()
public function withHxPush( string|bool $url ): static
withHxRedirect()
public function withHxRedirect( string $url ): static
withHxRefresh()
public function withHxRefresh(): static
withHxRetarget()
public function withHxRetarget( string $selector ): static
withHxTrigger()
public function withHxTrigger( string $trigger, mixed $argument = null ): static
withHxTriggerAfterSettle()
public function withHxTriggerAfterSettle( string $trigger, mixed $argument = null ): static
withHxTriggerAfterSwap()
public function withHxTriggerAfterSwap( string $trigger, mixed $argument = null ): static
withoutHxPush()
public function withoutHxPush(): static
withoutHxRedirect()
public function withoutHxRedirect(): static
withoutHxRefresh()
public function withoutHxRefresh(): static
withoutHxRetarget()
public function withoutHxRetarget(): static
withoutHxTrigger()
public function withoutHxTrigger(): static
withoutHxTriggerAfterSettle()
public function withoutHxTriggerAfterSettle(): static
withoutHxTriggerAfterSwap()
public function withoutHxTriggerAfterSwap(): static
📂 Tomrf\HtmxMessage\HtmxServerRequest::class
HtmxServerRequest is a proxy for PSR-7 server request objects implementing \Psr\Http\Message\ServerRequestInterface.
You can safely wrap any ServerRequestInterface object, also those not originating from htmx, without affecting your application.
Check if the request originated from htmx using the isHxRequest() method.
HtmxServerRequest objects retains immutability in the same fashion as one would expect from a PSR-7 MessageInterface, returning a new object wrapping a new ServerRequestInterface instance whenever the HtmxServerRequest is changed.
Example:
$request = new HtmxServerRequest($request);
if ($request->isHxRequest() && $request->isHxBoosted()) {
// htmx request from boosted client, respond accordingly
}
$userPrompt = $request->getHxPrompt();
// ...
getHxCurrentUrl()
public function getHxCurrentUrl(): string
getHxPrompt()
public function getHxPrompt(): string
getHxTarget()
public function getHxTarget(): string
getHxTrigger()
public function getHxTrigger(): string
getHxTriggerName()
public function getHxTriggerName(): string
hasHxPrompt()
public function hasHxPrompt(): bool
hasHxTarget()
public function hasHxTarget(): bool
hasHxTrigger()
public function hasHxTrigger(): bool
hasHxTriggerName()
public function hasHxTriggerName(): bool
isHxBoosted()
public function isHxBoosted(): bool
isHxHistoryRestoreRequest()
public function isHxHistoryRestoreRequest(): bool
isHxRequest()
public function isHxRequest(): bool
__construct()
public function __construct( Psr\Http\Message\ServerRequestInterface $message ): void
Generated 2023-08-18T12:46:49+00:00 using 📚tomrf/readme-gen
tomrf/htmx-message 适用场景与选型建议
tomrf/htmx-message 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 249 次下载、GitHub Stars 达 12, 最近一次更新时间为 2022 年 07 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「psr-7」 「http-message」 「http-response」 「http-request」 「server-request」 「htmx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomrf/htmx-message 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomrf/htmx-message 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomrf/htmx-message 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PSR-7 Response implementations
Model of a web-based resource
A High Performance API Framework By Swoole Extension
Interfaces for web resource models and services to retrieve and create them
Lightweight and strict implementation of PSR-7 HTTP Message including PSR-17 HTTP Factories.
Interface for a factory to create Psr\Http\Message\StreamInterface objects
统计信息
- 总下载量: 249
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-09