Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockSourceLinkValidatorChain.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 use Magento\Framework\Validation\ValidationResultFactory;
15 
22 {
26  private $validationResultFactory;
27 
31  private $validators;
32 
38  public function __construct(
39  ValidationResultFactory $validationResultFactory,
40  array $validators = []
41  ) {
42  $this->validationResultFactory = $validationResultFactory;
43 
44  foreach ($validators as $validator) {
45  if (!$validator instanceof StockSourceLinkValidatorInterface) {
46  throw new LocalizedException(
47  __('Validator must implement StockSourceLinkValidatorInterface.')
48  );
49  }
50  }
51  $this->validators = $validators;
52  }
53 
58  {
59  $errors = [];
60  foreach ($this->validators as $validator) {
61  $validationResult = $validator->validate($link);
62 
63  if (!$validationResult->isValid()) {
64  $errors = array_merge($errors, $validationResult->getErrors());
65  }
66  }
67  return $this->validationResultFactory->create(['errors' => $errors]);
68  }
69 }
__()
Definition: __.php:13
$errors
Definition: overview.phtml:9