-
-
Notifications
You must be signed in to change notification settings - Fork 28
Simplify envelopes #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Simplify envelopes #217
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
be41da6
Simplify envelopes
viktorprogger a8564c1
Apply fixes from StyleCI
StyleCIBot 02f2534
Simplify abstract envelope
viktorprogger 2bb91ad
Fix bug and test
viktorprogger 45c7c57
Apply fixes from StyleCI
StyleCIBot 9438b87
Require yiisoft/arrays package
viktorprogger 3afb619
Fix warnings
viktorprogger e297466
Merge branch 'master' into simplify-envelopes
viktorprogger 75d600a
Use new PhpBench action version
viktorprogger 9028b65
Start less checks for tests
viktorprogger 5beb769
more checks again
viktorprogger bf3d40a
Remove token from bench workflow
viktorprogger ff24d35
Merge branch 'master' into simplify-envelopes
samdark 45293ba
Update src/Message/Message.php
samdark f43c94a
Fix PhpBench action version
viktorprogger 784a826
Fix PhpBench action version
viktorprogger 0ea2fdf
Remove PHP 8.4 from PhpBench action
viktorprogger 54980d7
Merge remote-tracking branch 'origin/master' into simplify-envelopes
viktorprogger d884b8d
Fix merge error
viktorprogger 7a4fc68
Fix test
viktorprogger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Queue\Message; | ||
|
||
use Yiisoft\Arrays\ArrayHelper; | ||
|
||
abstract class AbstractEnvelope implements EnvelopeInterface | ||
{ | ||
protected array $metadata = []; | ||
private MessageInterface $message; | ||
|
||
public function __construct(MessageInterface $message) | ||
{ | ||
$this->metadata = $message->getMetadata(); | ||
$envelopes = [static::class]; | ||
while ($message instanceof EnvelopeInterface) { | ||
if ($message::class !== static::class) { | ||
$envelopes = [$message::class]; | ||
} | ||
|
||
$message = $message->getMessage(); | ||
} | ||
$this->message = $message; | ||
|
||
if (isset($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) { | ||
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge( | ||
$envelopes, | ||
array_filter( | ||
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY], | ||
static fn (string $envelope): bool => !in_array($envelope, $envelopes), | ||
), | ||
); | ||
} else { | ||
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class]; | ||
} | ||
} | ||
|
||
public function getMessage(): MessageInterface | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function getHandlerName(): string | ||
{ | ||
return $this->message->getHandlerName(); | ||
} | ||
|
||
public function getData(): mixed | ||
{ | ||
return $this->message->getData(); | ||
} | ||
|
||
public function getMetadata(): array | ||
{ | ||
return ArrayHelper::merge( | ||
$this->metadata, | ||
$this->getEnvelopeMetadata(), | ||
); | ||
} | ||
|
||
/** | ||
* Metadata of the envelope | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function getEnvelopeMetadata(): array; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.