yiisoft / queue

Queue extension for Yii 3.0
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
54 stars 29 forks source link

Ability to find an envelope instance from the given stack #216

Closed viktorprogger closed 1 week ago

viktorprogger commented 2 weeks ago
Q A
Is bugfix?
New feature? ✔️
Breaks BC?

This PR allows to obtain an envelope instance from envelope stack:

$idEnvelope = $message instanceof EnvelopeInterface ? $message->getEnvelopeFromStack(IdEnvelope::class) : IdEnvelope::fromMessage($message);

If the envelope you need uses EnvelopeTrait, it's more simple: code IdEnvelope::getEnvelopeFromMessage($message) will have the same effect as above.

viktorprogger commented 1 week ago

This approach will return an unwanted value in case it is overwritten somewhere in stack by an envelope with another class name. Closing.