Domain.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cookie\Model\Config\Backend;
  7. /**
  8. * Backend model for domain config value
  9. */
  10. class Domain extends \Magento\Framework\App\Config\Value
  11. {
  12. /**
  13. * @var \Magento\Framework\Session\Config\Validator\CookieDomainValidator
  14. */
  15. protected $configValidator;
  16. /**
  17. * @param \Magento\Framework\Model\Context $context
  18. * @param \Magento\Framework\Registry $registry
  19. * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  20. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  21. * @param \Magento\Framework\Session\Config\Validator\CookieDomainValidator $configValidator
  22. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  23. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  24. * @param array $data
  25. * @codeCoverageIgnore
  26. */
  27. public function __construct(
  28. \Magento\Framework\Model\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. \Magento\Framework\App\Config\ScopeConfigInterface $config,
  31. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
  32. \Magento\Framework\Session\Config\Validator\CookieDomainValidator $configValidator,
  33. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  34. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  35. array $data = []
  36. ) {
  37. $this->configValidator = $configValidator;
  38. parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
  39. }
  40. /**
  41. * Validate a domain name value
  42. *
  43. * @return void
  44. * @throws \Magento\Framework\Exception\LocalizedException
  45. */
  46. public function beforeSave()
  47. {
  48. $value = $this->getValue();
  49. // Empty value is treated valid and will be handled when read the value out
  50. if (!empty($value) && !$this->configValidator->isValid($value)) {
  51. $msg = __('Invalid domain name: %1', join('; ', $this->configValidator->getMessages()));
  52. throw new \Magento\Framework\Exception\LocalizedException($msg);
  53. }
  54. }
  55. }