yiisoft / queue

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

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

Closed viktorprogger closed 2 months ago

viktorprogger commented 2 months 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 2 months ago

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