HandledStamp.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Messenger\Stamp;
  11. use Symfony\Component\Messenger\Handler\HandlerDescriptor;
  12. /**
  13. * Stamp identifying a message handled by the `HandleMessageMiddleware` middleware
  14. * and storing the handler returned value.
  15. *
  16. * This is used by synchronous command buses expecting a return value and the retry logic
  17. * to only execute handlers that didn't succeed.
  18. *
  19. * @see \Symfony\Component\Messenger\Middleware\HandleMessageMiddleware
  20. * @see \Symfony\Component\Messenger\HandleTrait
  21. *
  22. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  23. */
  24. final class HandledStamp implements StampInterface
  25. {
  26. private $result;
  27. private $handlerName;
  28. /**
  29. * @param mixed $result The returned value of the message handler
  30. */
  31. public function __construct($result, string $handlerName)
  32. {
  33. $this->result = $result;
  34. $this->handlerName = $handlerName;
  35. }
  36. /**
  37. * @param mixed $result The returned value of the message handler
  38. */
  39. public static function fromDescriptor(HandlerDescriptor $handler, $result): self
  40. {
  41. return new self($result, $handler->getName());
  42. }
  43. /**
  44. * @return mixed
  45. */
  46. public function getResult()
  47. {
  48. return $this->result;
  49. }
  50. public function getHandlerName(): string
  51. {
  52. return $this->handlerName;
  53. }
  54. }