Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

A shorter way to define a message

Đang mở
#344 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
PHP
Star
61
Fork
31
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của yiisoft/queue

Tất cả issue của yiisoft/queue

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.