objectManager = $objectManager; $this->sourceSelectionMethods = $sourceSelectionMethods; } /** * @inheritdoc */ public function execute( InventoryRequestInterface $inventoryRequest, string $algorithmCode ): SourceSelectionResultInterface { if (!isset($this->sourceSelectionMethods[$algorithmCode])) { throw new \LogicException( __('There is no such Source Selection Algorithm implemented: %1', $algorithmCode) ); } $sourceSelectionClassName = $this->sourceSelectionMethods[$algorithmCode]; $sourceSelectionAlgorithm = $this->objectManager->create($sourceSelectionClassName); if (false === $sourceSelectionAlgorithm instanceof SourceSelectionInterface) { throw new \LogicException( __('%1 doesn\'t implement SourceSelectionInterface', $sourceSelectionClassName) ); } return $sourceSelectionAlgorithm->execute($inventoryRequest); } }