Path.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Path extends \Magento\Framework\App\Config\Value
  11. {
  12. /**
  13. * @var \Magento\Framework\Session\Config\Validator\CookiePathValidator
  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\CookiePathValidator $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\CookiePathValidator $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. if (!empty($value) && !$this->configValidator->isValid($value)) {
  50. throw new \Magento\Framework\Exception\LocalizedException(__('Invalid cookie path'));
  51. }
  52. }
  53. }