BackendModel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model\Config\SessionLifetime;
  7. use Magento\Framework\App\Config\Value;
  8. use Magento\Framework\Exception\LocalizedException;
  9. /**
  10. * Backend model for the admin/security/session_lifetime configuration field. Validates session lifetime.
  11. * @api
  12. * @since 100.1.0
  13. */
  14. class BackendModel extends Value
  15. {
  16. /** Maximum admin session lifetime; 1 year*/
  17. const MAX_LIFETIME = 31536000;
  18. /** Minimum admin session lifetime */
  19. const MIN_LIFETIME = 60;
  20. /**
  21. * Processing object before save data
  22. *
  23. * @since 100.1.0
  24. * @throws LocalizedException
  25. */
  26. public function beforeSave()
  27. {
  28. $value = (int)$this->getValue();
  29. if ($value > self::MAX_LIFETIME) {
  30. throw new LocalizedException(
  31. __(
  32. 'The Admin session lifetime is invalid. '
  33. . 'Set the lifetime to 31536000 seconds (one year) or shorter and try again.'
  34. )
  35. );
  36. } elseif ($value < self::MIN_LIFETIME) {
  37. throw new LocalizedException(
  38. __('The Admin session lifetime is invalid. Set the lifetime to 60 seconds or longer and try again.')
  39. );
  40. }
  41. return parent::beforeSave();
  42. }
  43. }