GetSourceSelectionAlgorithmList.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventorySourceSelectionApi\Model;
  8. use Magento\InventorySourceSelectionApi\Api\Data\SourceSelectionAlgorithmInterface;
  9. use Magento\InventorySourceSelectionApi\Api\Data\SourceSelectionAlgorithmInterfaceFactory;
  10. use Magento\InventorySourceSelectionApi\Api\GetSourceSelectionAlgorithmListInterface;
  11. /**
  12. * {@inheritdoc}
  13. *
  14. * @api
  15. */
  16. class GetSourceSelectionAlgorithmList implements GetSourceSelectionAlgorithmListInterface
  17. {
  18. /**
  19. * @var SourceSelectionAlgorithmInterface[]
  20. */
  21. private $availableAlgorithms;
  22. /**
  23. * @var SourceSelectionAlgorithmInterfaceFactory
  24. */
  25. private $sourceSelectionAlgorithmFactory;
  26. /**
  27. * SourceSelectionAlgorithmProvider constructor.
  28. * @param SourceSelectionAlgorithmInterfaceFactory $sourceSelectionAlgorithmFactory
  29. * @param array $availableAlgorithms
  30. */
  31. public function __construct(
  32. SourceSelectionAlgorithmInterfaceFactory $sourceSelectionAlgorithmFactory,
  33. array $availableAlgorithms = []
  34. ) {
  35. $this->availableAlgorithms = $availableAlgorithms;
  36. $this->sourceSelectionAlgorithmFactory = $sourceSelectionAlgorithmFactory;
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function execute(): array
  42. {
  43. $algorithmsList = [];
  44. foreach ($this->availableAlgorithms as $data) {
  45. $algorithmsList[] = $this->sourceSelectionAlgorithmFactory->create([
  46. 'code' => $data['code'],
  47. 'title' => $data['title'],
  48. 'description' => $data['description']
  49. ]);
  50. }
  51. return $algorithmsList;
  52. }
  53. }