Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QuoteValidationComposite.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
16 {
20  private $validationRules = [];
21 
26  public function __construct(array $validationRules)
27  {
28  foreach ($validationRules as $validationRule) {
29  if (!($validationRule instanceof QuoteValidationRuleInterface)) {
30  throw new \InvalidArgumentException(
31  sprintf(
32  'Instance of the ValidationRuleInterface is expected, got %s instead.',
33  get_class($validationRule)
34  )
35  );
36  }
37  }
38  $this->validationRules = $validationRules;
39  }
40 
44  public function validate(Quote $quote): array
45  {
46  $aggregateResult = [];
47 
48  foreach ($this->validationRules as $validationRule) {
49  $ruleValidationResult = $validationRule->validate($quote);
50  foreach ($ruleValidationResult as $item) {
51  if (!$item->isValid()) {
52  array_push($aggregateResult, $item);
53  }
54  }
55  }
56 
57  return $aggregateResult;
58  }
59 }
$quote