Composite.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Method\Specification;
  7. use Magento\Payment\Model\Method\SpecificationInterface;
  8. /**
  9. * Composite specification
  10. *
  11. * Use this class for virtual types declaration.
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Composite implements SpecificationInterface
  17. {
  18. /**
  19. * Specifications collection
  20. *
  21. * @var SpecificationInterface[]
  22. */
  23. protected $specifications = [];
  24. /**
  25. * Construct
  26. *
  27. * @param Factory $factory
  28. * @param array $specifications
  29. */
  30. public function __construct(Factory $factory, $specifications = [])
  31. {
  32. foreach ($specifications as $specification) {
  33. $this->specifications[] = $factory->create($specification);
  34. }
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function isSatisfiedBy($paymentMethod)
  40. {
  41. foreach ($this->specifications as $specification) {
  42. if (!$specification->isSatisfiedBy($paymentMethod)) {
  43. return false;
  44. }
  45. }
  46. return true;
  47. }
  48. }