Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceSelectionService.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
17 {
21  private $objectManager;
22 
26  private $sourceSelectionMethods;
27 
32  public function __construct(
33  ObjectManagerInterface $objectManager,
34  array $sourceSelectionMethods = []
35  ) {
36  $this->objectManager = $objectManager;
37  $this->sourceSelectionMethods = $sourceSelectionMethods;
38  }
39 
43  public function execute(
44  InventoryRequestInterface $inventoryRequest,
45  string $algorithmCode
47  if (!isset($this->sourceSelectionMethods[$algorithmCode])) {
48  throw new \LogicException(
49  __('There is no such Source Selection Algorithm implemented: %1', $algorithmCode)
50  );
51  }
52  $sourceSelectionClassName = $this->sourceSelectionMethods[$algorithmCode];
53 
54  $sourceSelectionAlgorithm = $this->objectManager->create($sourceSelectionClassName);
55  if (false === $sourceSelectionAlgorithm instanceof SourceSelectionInterface) {
56  throw new \LogicException(
57  __('%1 doesn\'t implement SourceSelectionInterface', $sourceSelectionClassName)
58  );
59  }
60  return $sourceSelectionAlgorithm->execute($inventoryRequest);
61  }
62 }
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
__construct(ObjectManagerInterface $objectManager, array $sourceSelectionMethods=[])
execute(InventoryRequestInterface $inventoryRequest, string $algorithmCode)