Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValidatorComposite.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
11 
19 {
23  private $validators;
24 
30  public function __construct(
31  ResultInterfaceFactory $resultFactory,
32  TMapFactory $tmapFactory,
33  array $validators = []
34  ) {
35  $this->validators = $tmapFactory->create(
36  [
37  'array' => $validators,
38  'type' => ValidatorInterface::class
39  ]
40  );
41  parent::__construct($resultFactory);
42  }
43 
50  public function validate(array $validationSubject)
51  {
52  $isValid = true;
53  $failsDescriptionAggregate = [];
54  foreach ($this->validators as $validator) {
55  $result = $validator->validate($validationSubject);
56  if (!$result->isValid()) {
57  $isValid = false;
58  $failsDescriptionAggregate = array_merge(
59  $failsDescriptionAggregate,
60  $result->getFailsDescription()
61  );
62  }
63  }
64 
65  return $this->createResult($isValid, $failsDescriptionAggregate);
66  }
67 }
createResult($isValid, array $fails=[], array $errorCodes=[])
__construct(ResultInterfaceFactory $resultFactory, TMapFactory $tmapFactory, array $validators=[])