HandlerComposite.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Payflow\Service\Response\Handler;
  7. use Magento\Framework\DataObject;
  8. use Magento\Payment\Model\InfoInterface;
  9. class HandlerComposite implements HandlerInterface
  10. {
  11. /**
  12. * @var HandlerInterface[]
  13. */
  14. private $handlers = [];
  15. /**
  16. * @param HandlerInterface[] $handlers
  17. */
  18. public function __construct(array $handlers = [])
  19. {
  20. array_walk(
  21. $handlers,
  22. function ($handler, $code) {
  23. if (!$handler instanceof HandlerInterface) {
  24. $message = 'Type mismatch. Expected type: %s. Actual: %s, Code: %s';
  25. throw new \LogicException(
  26. sprintf($message, 'HandlerInterface', gettype($handler), $code)
  27. );
  28. }
  29. }
  30. );
  31. $this->handlers = $handlers;
  32. }
  33. /**
  34. * {inheritdoc}
  35. */
  36. public function handle(InfoInterface $payment, DataObject $response)
  37. {
  38. foreach ($this->handlers as $handle) {
  39. $handle->handle($payment, $response);
  40. }
  41. }
  42. }