A shorter way to define a message
还没有人认领这个 Issue。
评估
调研方向
Start with the Quick Start message in README.md and messages-and-handlers.md to understand the existing manual message contract. The issue proposes an attribute or trait that derives message type and payload from public properties while keeping manual implementations available, but leaves the API and design open. Done means the package has a considered answer on whether to support this common case and, if pursued, a defined approach that preserves manual payload contracts.
由索引模型根据 Issue 内容生成。
描述
Proposed new feature or change
The Quick Start message in README.md is 33 lines for two string properties. Message already covers getMeta()/withMeta(), so what is left per message class is getType(), getPayload() and a fromPayload() with hand-written validation:
public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static
{
if ($type !== self::TYPE) {
throw new \InvalidArgumentException("Expected type \"" . self::TYPE . "\", got \"$type\".");
}
if (!is_array($payload)
|| !is_string($payload['url'] ?? null)
|| !is_string($payload['destinationPath'] ?? null)
) {
throw new \InvalidArgumentException('Invalid data for ' . self::class . '.');
}
return new self($payload['url'], $payload['destinationPath']);
}
That is the same three checks in every message class in an application, and it is the first thing a newcomer meets in the README. Symfony Messenger and Laravel both take a plain object here.
The separation of payload from handler is well argued in messages-and-handlers.md and should stay — the request is for a short path for the common case, not a replacement. Something like an attribute or a trait that derives the type and the payload from the public properties:
#[AsMessage('download-file')]
final class DownloadFileMessage extends Message
{
public function __construct(
public readonly string $url,
public readonly string $destinationPath,
) {}
}
with the manual implementation still available for messages that are a cross-application contract and need their payload shape pinned by hand.
Is this something you would consider in the package, or is it meant to stay application-side?
- 主要语言
- PHP
- 星标
- 61
- 派生
- 31
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
yiisoft/queue 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 4/5 1-2 天 新手友好度 47/100
-
难度 3/5 1-2 天 新手友好度 54/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
难度 2/5 半天 新手友好度 68/100
components-web-app/docs#244 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
PrestaShopCorp/ps_eventbus#501 · 2 个 reaction ·
-
category::task maintenance priority::normal
难度 2/5 1-3 小时 新手友好度 62/100
e0ipso/schema-forms-php#58 ·
-
难度 2/5 1-3 小时 新手友好度 66/100
Automattic/blocks-engine#2866 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
community-scripts/ProxmoxVE#17944 · 1 条评论 ·
维护者通常 1 天内回复