SpecificationFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /**
  8. * Creates complex specification.
  9. *
  10. * Use this class to register predefined list of specifications that should be added to any complex specification.
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class SpecificationFactory
  16. {
  17. /**
  18. * Composite Factory
  19. *
  20. * @var \Magento\Payment\Model\Checks\CompositeFactory
  21. */
  22. protected $compositeFactory;
  23. /**
  24. * @var array
  25. */
  26. protected $mapping;
  27. /**
  28. * Construct
  29. *
  30. * @param \Magento\Payment\Model\Checks\CompositeFactory $compositeFactory
  31. * @param array $mapping
  32. */
  33. public function __construct(\Magento\Payment\Model\Checks\CompositeFactory $compositeFactory, array $mapping)
  34. {
  35. $this->compositeFactory = $compositeFactory;
  36. $this->mapping = $mapping;
  37. }
  38. /**
  39. * Creates new instances of payment method models
  40. *
  41. * @param array $data
  42. * @return Composite
  43. * @throws \Magento\Framework\Exception\LocalizedException
  44. */
  45. public function create($data)
  46. {
  47. $specifications = array_intersect_key($this->mapping, array_flip((array)$data));
  48. return $this->compositeFactory->create(['list' => $specifications]);
  49. }
  50. }