123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Session\SaveHandler\Redis;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\App\DeploymentConfig;
- use Magento\Framework\App\State;
- use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
- /**
- * Redis session save handler
- */
- class Config implements \Cm\RedisSession\Handler\ConfigInterface
- {
- /**
- * Configuration path for log level
- */
- const PARAM_LOG_LEVEL = 'session/redis/log_level';
- /**
- * Configuration path for host
- */
- const PARAM_HOST = 'session/redis/host';
- /**
- * Configuration path for port
- */
- const PARAM_PORT = 'session/redis/port';
- /**
- * Configuration path for database
- */
- const PARAM_DATABASE = 'session/redis/database';
- /**
- * Configuration path for password
- */
- const PARAM_PASSWORD = 'session/redis/password';
- /**
- * Configuration path for connection timeout
- */
- const PARAM_TIMEOUT = 'session/redis/timeout';
- /**
- * Configuration path for persistent identifier
- */
- const PARAM_PERSISTENT_IDENTIFIER = 'session/redis/persistent_identifier';
- /**
- * Configuration path for compression threshold
- */
- const PARAM_COMPRESSION_THRESHOLD = 'session/redis/compression_threshold';
- /**
- * Configuration path for compression library
- */
- const PARAM_COMPRESSION_LIBRARY = 'session/redis/compression_library';
- /**
- * Configuration path for maximum number of processes that can wait for a lock on one session
- */
- const PARAM_MAX_CONCURRENCY = 'session/redis/max_concurrency';
- /**
- * Configuration path for minimum session lifetime
- */
- const PARAM_MAX_LIFETIME = 'session/redis/max_lifetime';
- /**
- * Configuration path for min
- */
- const PARAM_MIN_LIFETIME = 'session/redis/min_lifetime';
- /**
- * Configuration path for disabling session locking entirely flag
- */
- const PARAM_DISABLE_LOCKING = 'session/redis/disable_locking';
- /**
- * Configuration path for lifetime of session for bots on subsequent writes
- */
- const PARAM_BOT_LIFETIME = 'session/redis/bot_lifetime';
- /**
- * Configuration path for lifetime of session for bots on the first write
- */
- const PARAM_BOT_FIRST_LIFETIME = 'session/redis/bot_first_lifetime';
- /**
- * Configuration path for lifetime of session for non-bots on the first write
- */
- const PARAM_FIRST_LIFETIME = 'session/redis/first_lifetime';
- /**
- * Configuration path for number of seconds to wait before trying to break the lock
- */
- const PARAM_BREAK_AFTER = 'session/redis/break_after';
- /**
- * Configuration path for comma separated list of sentinel servers
- */
- const PARAM_SENTINEL_SERVERS = 'session/redis/sentinel_servers';
- /**
- * Configuration path for sentinel master
- */
- const PARAM_SENTINEL_MASTER = 'session/redis/sentinel_master';
- /**
- * Configuration path for verify sentinel master flag
- */
- const PARAM_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';
- /**
- * Configuration path for number of sentinel connection retries
- */
- const PARAM_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';
- /**
- * Cookie lifetime config path
- */
- const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime';
- /**
- * Admin session lifetime config path
- */
- const XML_PATH_ADMIN_SESSION_LIFETIME = 'admin/security/session_lifetime';
- /**
- * Session max lifetime
- */
- const SESSION_MAX_LIFETIME = 31536000;
- /**
- * Try to break lock for at most this many seconds
- */
- const DEFAULT_FAIL_AFTER = 15;
- /**
- * Deployment config
- *
- * @var DeploymentConfig
- */
- private $deploymentConfig;
- /**
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- /**
- * @var State
- */
- private $appState;
- /**
- * @param DeploymentConfig $deploymentConfig
- * @param State $appState
- * @param ScopeConfigInterface $scopeConfig
- */
- public function __construct(
- DeploymentConfig $deploymentConfig,
- State $appState,
- ScopeConfigInterface $scopeConfig
- ) {
- $this->deploymentConfig = $deploymentConfig;
- $this->appState = $appState;
- $this->scopeConfig = $scopeConfig;
- }
- /**
- * @inheritdoc
- */
- public function getLogLevel()
- {
- return $this->deploymentConfig->get(self::PARAM_LOG_LEVEL);
- }
- /**
- * @inheritdoc
- */
- public function getHost()
- {
- return $this->deploymentConfig->get(self::PARAM_HOST);
- }
- /**
- * @inheritdoc
- */
- public function getPort()
- {
- return $this->deploymentConfig->get(self::PARAM_PORT);
- }
- /**
- * @inheritdoc
- */
- public function getDatabase()
- {
- return $this->deploymentConfig->get(self::PARAM_DATABASE);
- }
- /**
- * @inheritdoc
- */
- public function getPassword()
- {
- return $this->deploymentConfig->get(self::PARAM_PASSWORD);
- }
- /**
- * @inheritdoc
- */
- public function getTimeout()
- {
- return $this->deploymentConfig->get(self::PARAM_TIMEOUT);
- }
- /**
- * @inheritdoc
- */
- public function getPersistentIdentifier()
- {
- return $this->deploymentConfig->get(self::PARAM_PERSISTENT_IDENTIFIER);
- }
- /**
- * @inheritdoc
- */
- public function getCompressionThreshold()
- {
- return $this->deploymentConfig->get(self::PARAM_COMPRESSION_THRESHOLD);
- }
- /**
- * @inheritdoc
- */
- public function getCompressionLibrary()
- {
- return $this->deploymentConfig->get(self::PARAM_COMPRESSION_LIBRARY);
- }
- /**
- * @inheritdoc
- */
- public function getMaxConcurrency()
- {
- return $this->deploymentConfig->get(self::PARAM_MAX_CONCURRENCY);
- }
- /**
- * @inheritdoc
- */
- public function getMaxLifetime()
- {
- return self::SESSION_MAX_LIFETIME;
- }
- /**
- * @inheritdoc
- */
- public function getMinLifetime()
- {
- return $this->deploymentConfig->get(self::PARAM_MIN_LIFETIME);
- }
- /**
- * @inheritdoc
- */
- public function getDisableLocking()
- {
- return $this->deploymentConfig->get(self::PARAM_DISABLE_LOCKING);
- }
- /**
- * @inheritdoc
- */
- public function getBotLifetime()
- {
- return $this->deploymentConfig->get(self::PARAM_BOT_LIFETIME);
- }
- /**
- * @inheritdoc
- */
- public function getBotFirstLifetime()
- {
- return $this->deploymentConfig->get(self::PARAM_BOT_FIRST_LIFETIME);
- }
- /**
- * @inheritdoc
- */
- public function getFirstLifetime()
- {
- return $this->deploymentConfig->get(self::PARAM_FIRST_LIFETIME);
- }
- /**
- * @inheritdoc
- */
- public function getBreakAfter()
- {
- return $this->deploymentConfig->get(self::PARAM_BREAK_AFTER . '_' . $this->appState->getAreaCode());
- }
- /**
- * @inheritdoc
- */
- public function getLifetime()
- {
- if ($this->appState->getAreaCode() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
- return (int)$this->scopeConfig->getValue(self::XML_PATH_ADMIN_SESSION_LIFETIME);
- }
- return (int)$this->scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, StoreScopeInterface::SCOPE_STORE);
- }
- /**
- * @inheritdoc
- */
- public function getSentinelServers()
- {
- return $this->deploymentConfig->get(self::PARAM_SENTINEL_SERVERS);
- }
- /**
- * @inheritdoc
- */
- public function getSentinelMaster()
- {
- return $this->deploymentConfig->get(self::PARAM_SENTINEL_MASTER);
- }
- /**
- * @inheritdoc
- */
- public function getSentinelVerifyMaster()
- {
- return $this->deploymentConfig->get(self::PARAM_SENTINEL_VERIFY_MASTER);
- }
- /**
- * @inheritdoc
- */
- public function getSentinelConnectRetries()
- {
- return $this->deploymentConfig->get(self::PARAM_SENTINEL_CONNECT_RETRIES);
- }
- /**
- * @inheritdoc
- */
- public function getFailAfter()
- {
- return self::DEFAULT_FAIL_AFTER;
- }
- }
|