Composite.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Checks;
  7. use Magento\Payment\Model\MethodInterface;
  8. use Magento\Quote\Model\Quote;
  9. /**
  10. * Combines several checks with logic "AND" operation.
  11. * Use this class to register own specifications.
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Composite implements SpecificationInterface
  17. {
  18. /**
  19. * @var \Magento\Payment\Model\Checks\SpecificationInterface[]
  20. */
  21. protected $list = [];
  22. /**
  23. * @param SpecificationInterface[] $list
  24. */
  25. public function __construct(array $list)
  26. {
  27. $this->list = $list;
  28. }
  29. /**
  30. * Check whether payment method is applicable to quote
  31. *
  32. * @param MethodInterface $paymentMethod
  33. * @param \Magento\Quote\Model\Quote $quote
  34. * @return bool
  35. */
  36. public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
  37. {
  38. foreach ($this->list as $specification) {
  39. if (!$specification->isApplicable($paymentMethod, $quote)) {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45. }