Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Get.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use Magento\InventoryApi\Api\Data\SourceInterfaceFactory;
14 
18 class Get implements GetInterface
19 {
23  private $sourceResource;
24 
28  private $sourceFactory;
29 
34  public function __construct(
35  SourceResourceModel $sourceResource,
36  SourceInterfaceFactory $sourceFactory
37  ) {
38  $this->sourceResource = $sourceResource;
39  $this->sourceFactory = $sourceFactory;
40  }
41 
45  public function execute(string $sourceCode): SourceInterface
46  {
48  $source = $this->sourceFactory->create();
49  $this->sourceResource->load($source, $sourceCode, SourceInterface::SOURCE_CODE);
50 
51  if (null === $source->getSourceCode()) {
52  throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $sourceCode]));
53  }
54  return $source;
55  }
56 }
__construct(SourceResourceModel $sourceResource, SourceInterfaceFactory $sourceFactory)
Definition: Get.php:34
$source
Definition: source.php:23
__()
Definition: __.php:13
$sourceCode
Definition: inventory.phtml:11
$sourceFactory
Definition: source.php:16