AbstractValidator.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Payment\Gateway\Validator;
  8. /**
  9. * Represents a basic validator shell that can create a result
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. abstract class AbstractValidator implements ValidatorInterface
  15. {
  16. /**
  17. * @var ResultInterfaceFactory
  18. */
  19. private $resultInterfaceFactory;
  20. /**
  21. * @param ResultInterfaceFactory $resultFactory
  22. */
  23. public function __construct(
  24. ResultInterfaceFactory $resultFactory
  25. ) {
  26. $this->resultInterfaceFactory = $resultFactory;
  27. }
  28. /**
  29. * Factory method
  30. *
  31. * @param bool $isValid
  32. * @param array $fails
  33. * @param array $errorCodes
  34. * @return \Magento\Payment\Gateway\Validator\ResultInterface
  35. */
  36. protected function createResult($isValid, array $fails = [], array $errorCodes = [])
  37. {
  38. return $this->resultInterfaceFactory->create(
  39. [
  40. 'isValid' => (bool)$isValid,
  41. 'failsDescription' => $fails,
  42. 'errorCodes' => $errorCodes
  43. ]
  44. );
  45. }
  46. }