Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockSourceLinksSave.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Exception;
18 use Psr\Log\LoggerInterface;
19 
24 {
28  private $saveMultiple;
29 
33  private $logger;
34 
38  private $stockSourceLinksValidator;
39 
45  public function __construct(
46  StockSourceLinksValidator $stockSourceLinksValidator,
47  SaveMultiple $saveMultiple,
48  LoggerInterface $logger
49  ) {
50  $this->saveMultiple = $saveMultiple;
51  $this->logger = $logger;
52  $this->stockSourceLinksValidator = $stockSourceLinksValidator;
53  }
54 
61  public function execute(array $links): void
62  {
63  if (empty($links)) {
64  throw new InputException(__('Input data is empty'));
65  }
66 
67  $validationResult = $this->stockSourceLinksValidator->validate($links);
68  if (!$validationResult->isValid()) {
69  throw new ValidationException(__('Validation Failed'), null, 0, $validationResult);
70  }
71 
72  try {
73  $this->saveMultiple->execute($links);
74  } catch (Exception $e) {
75  $this->logger->error($e->getMessage());
76  throw new CouldNotSaveException(__('Could not save StockSourceLinks'), $e);
77  }
78  }
79 }
__()
Definition: __.php:13
$logger