-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
Context stamp #3157
Context stamp #3157
Conversation
sergepavle
commented
Oct 6, 2019
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #3082 |
License | MIT |
Doc PR | api-platform/docs#1234 |
4f4de92
to
63c2c1f
Compare
63c2c1f
to
d8d2ff8
Compare
d8d2ff8
to
d997860
Compare
d997860
to
b3f1a7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you for this Pull Request! Just few more changes and it will be ready to be merged.
@@ -56,7 +57,9 @@ public function testPersist() | |||
$dummy = new Dummy(); | |||
|
|||
$messageBus = $this->prophesize(MessageBusInterface::class); | |||
$messageBus->dispatch($dummy)->willReturn(new Envelope($dummy))->shouldBeCalled(); | |||
$messageBus->dispatch(Argument::that(function (Envelope $envelope) use ($dummy) { | |||
return $dummy === $envelope->getMessage() && null !== $envelope->last(ContextStamp::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes is consistent with code from testRemove().
By this changes we make sure that have envelop with ContextStamp.
Thanks @sergepavle! Could you also open a docs PR? At least, adding an example of how to access the context using a middleware would be nice! |
This seems to make sense at first glance, but actually it doesn't work for the stated use case:
(It's most likely still useful for some cases.) You're not supposed to receive an <?php
declare(strict_types=1);
namespace App\MessageHandler\Api\Subscription;
use App\Model\Api\Subscription\PaymentDetails;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
final class PaymentDetailsHandler implements MessageHandlerInterface
{
// wtf?
// public function __invoke(Envelope $envelope): void
public function __invoke(PaymentDetails $paymentDetails): void
{
// ...
}
} |
You need to create a middleware. It’s why we must add docs! |
Creating a middleware still would not help the stated use case at all. 😄 |
* Issue api-platform#3082: Add and use ContextStamp. * Issue api-platform#3082: Add tests. * Issue api-platform#3157: Correct passing of context. * Issue api-platform#3157: Minor corrections.
* Issue api-platform#3082: Add and use ContextStamp. * Issue api-platform#3082: Add tests. * Issue api-platform#3157: Correct passing of context. * Issue api-platform#3157: Minor corrections.
@dunglas, what about this use case? This is similar to what @teohhanhui writes about. For example, how can I implement the command to update/delete a resource without using middleware? It's impossible? |