0 follower

Final Class Yiisoft\Queue\Message\IdEnvelope

InheritanceYiisoft\Queue\Message\IdEnvelope » Yiisoft\Queue\Message\Envelope
ImplementsYiisoft\Queue\Message\EnvelopeInterface

ID envelope allows to identify a message.

Protected Methods

Hide inherited methods

Method Description Defined By
getEnvelopeMetadata() Yiisoft\Queue\Message\IdEnvelope

Constants

Hide inherited constants

Constant Value Description Defined By
ENVELOPE_STACK_KEY 'envelopes' Yiisoft\Queue\Message\EnvelopeInterface
MESSAGE_ID_KEY 'yii-message-id' Yiisoft\Queue\Message\IdEnvelope

Property Details

Hide inherited properties

$message protected property

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Queue\Message\MessageInterface $message, string|integer|null $id )
$message Yiisoft\Queue\Message\MessageInterface
$id string|integer|null

                public function __construct(
    protected MessageInterface $message,
    private readonly string|int|null $id,
) {
}

            
fromData() public static method
public static Yiisoft\Queue\Message\IdEnvelope fromData ( string $handlerName, mixed $data, array $metadata = [] )
$handlerName string
$data mixed
$metadata array

                public static function fromData(string $handlerName, mixed $data, array $metadata = []): static
{
    /** @psalm-suppress LessSpecificReturnStatement */
    return static::fromMessage(Message::fromData($handlerName, $data, $metadata));
}

            
fromMessage() public static method

public static Yiisoft\Queue\Message\IdEnvelope fromMessage ( Yiisoft\Queue\Message\MessageInterface $message )
$message Yiisoft\Queue\Message\MessageInterface

                public static function fromMessage(MessageInterface $message): static
{
    /** @var mixed $rawId */
    $rawId = $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null;
    /** @var int|string|null $id */
    $id = match (true) {
        $rawId === null => null, // don't remove this branch: it's important for compute speed
        is_string($rawId) => $rawId,
        is_int($rawId) => $rawId,
        is_object($rawId) && method_exists($rawId, '__toString') => (string)$rawId,
        default => null,
    };
    return new self($message, $id);
}

            
getData() public method
public mixed getData ( )

                public function getData(): mixed
{
    return $this->message->getData();
}

            
getEnvelopeMetadata() protected method

protected array getEnvelopeMetadata ( )

                protected function getEnvelopeMetadata(): array
{
    return [self::MESSAGE_ID_KEY => $this->getId()];
}

            
getHandlerName() public method
public string getHandlerName ( )

                public function getHandlerName(): string
{
    return $this->message->getHandlerName();
}

            
getId() public method

public string|integer|null getId ( )

                public function getId(): string|int|null
{
    return $this->id;
}

            
getMessage() public method
public Yiisoft\Queue\Message\MessageInterface getMessage ( )

                public function getMessage(): MessageInterface
{
    return $this->message;
}

            
getMetadata() public method
public array getMetadata ( )

                public function getMetadata(): array
{
    if ($this->metadata === null) {
        $messageMeta = $this->message->getMetadata();
        $stack = $messageMeta[EnvelopeInterface::ENVELOPE_STACK_KEY] ?? [];
        if (!is_array($stack)) {
            $stack = [];
        }
        $this->metadata = array_merge(
            $messageMeta,
            [
                EnvelopeInterface::ENVELOPE_STACK_KEY => array_merge(
                    $stack,
                    [static::class],
                ),
            ],
            $this->getEnvelopeMetadata(),
        );
    }
    return $this->metadata;
}