CreditmemoProcessorPool.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Api\Data\InvoiceRequestBuilder;
  7. use Magento\Sales\Api\Data\CreditmemoInterface;
  8. use Vertex\Services\Invoice\RequestInterface;
  9. /**
  10. * Contains a pool of CreditmemoProcessors for use with the InvoiceRequestBuilder
  11. *
  12. * @api
  13. * @since 2.2.1
  14. */
  15. class CreditmemoProcessorPool implements CreditmemoProcessorInterface
  16. {
  17. /** @var CreditmemoProcessorInterface[] */
  18. private $processors;
  19. /**
  20. * @param CreditmemoProcessorInterface[] $processors
  21. */
  22. public function __construct(array $processors = [])
  23. {
  24. array_walk(
  25. $processors,
  26. function ($processor) {
  27. if (!$processor instanceof CreditmemoProcessorInterface) {
  28. throw new \InvalidArgumentException(
  29. 'All processors must be an instance of ' . CreditmemoProcessorInterface::class
  30. );
  31. }
  32. }
  33. );
  34. $this->processors = $processors;
  35. }
  36. /**
  37. * Retrieve all LineItemProcessors
  38. *
  39. * @return CreditmemoProcessorInterface[]
  40. */
  41. public function getProcessors()
  42. {
  43. return $this->processors;
  44. }
  45. /**
  46. * Use a pool of CreditmemoItemProcessors
  47. *
  48. * @param RequestInterface $request
  49. * @param CreditmemoInterface $creditmemo
  50. * @return RequestInterface
  51. */
  52. public function process(RequestInterface $request, CreditmemoInterface $creditmemo)
  53. {
  54. foreach ($this->getProcessors() as $processor) {
  55. $request = $processor->process($request, $creditmemo);
  56. }
  57. return $request;
  58. }
  59. }