Active.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Config\Backend;
  6. use Magento\Framework\App\Cache\TypeListInterface;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\App\Config\Value;
  9. use Magento\Framework\Data\Collection\AbstractDb;
  10. use Magento\Framework\Model\Context;
  11. use Magento\Framework\Model\ResourceModel\AbstractResource;
  12. use Magento\Framework\Registry;
  13. use Temando\Shipping\Model\Config\Backend\Active\CredentialsValidator;
  14. /**
  15. * Validate Temando API credentials before enabling the carrier.
  16. *
  17. * @package Temando\Shipping\Model
  18. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  19. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  20. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  21. * @link http://www.temando.com/
  22. */
  23. class Active extends Value
  24. {
  25. /**
  26. * @var CredentialsValidator
  27. */
  28. private $validationRules;
  29. /**
  30. * @param Context $context
  31. * @param Registry $registry
  32. * @param ScopeConfigInterface $config
  33. * @param TypeListInterface $cacheTypeList
  34. * @param CredentialsValidator $validationRules
  35. * @param AbstractResource|null $resource
  36. * @param AbstractDb|null $resourceCollection
  37. * @param array $data
  38. */
  39. public function __construct(
  40. Context $context,
  41. Registry $registry,
  42. ScopeConfigInterface $config,
  43. TypeListInterface $cacheTypeList,
  44. CredentialsValidator $validationRules,
  45. AbstractResource $resource = null,
  46. AbstractDb $resourceCollection = null,
  47. array $data = []
  48. ) {
  49. $this->validationRules = $validationRules;
  50. parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
  51. }
  52. /**
  53. * Obtain validation rules for establishing the api connection
  54. *
  55. * @return \Zend\Validator\ValidatorInterface|null
  56. */
  57. protected function _getValidationRulesBeforeSave()
  58. {
  59. $inputValidator = $this->validationRules->getInputValidator();
  60. $uriValidator = $this->validationRules->getUriEndpointValidator();
  61. $authenticationValidator = $this->validationRules->getAuthenticationValidator();
  62. $validatorChain = new \Zend\Validator\ValidatorChain();
  63. $validatorChain->attach($inputValidator, true);
  64. $validatorChain->attach($uriValidator, true);
  65. $validatorChain->attach($authenticationValidator, true);
  66. return $validatorChain;
  67. }
  68. }