HandlerChain.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Response;
  7. use Magento\Framework\ObjectManager\TMap;
  8. use Magento\Framework\ObjectManager\TMapFactory;
  9. /**
  10. * Class HandlerChain
  11. * @package Magento\Payment\Gateway\Response
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class HandlerChain implements HandlerInterface
  16. {
  17. /**
  18. * @var HandlerInterface[] | TMap
  19. */
  20. private $handlers;
  21. /**
  22. * @param TMapFactory $tmapFactory
  23. * @param array $handlers
  24. */
  25. public function __construct(
  26. TMapFactory $tmapFactory,
  27. array $handlers = []
  28. ) {
  29. $this->handlers = $tmapFactory->create(
  30. [
  31. 'array' => $handlers,
  32. 'type' => HandlerInterface::class
  33. ]
  34. );
  35. }
  36. /**
  37. * Handles response
  38. *
  39. * @param array $handlingSubject
  40. * @param array $response
  41. * @return void
  42. */
  43. public function handle(array $handlingSubject, array $response)
  44. {
  45. foreach ($this->handlers as $handler) {
  46. // @TODO implement exceptions catching
  47. $handler->handle($handlingSubject, $response);
  48. }
  49. }
  50. }