Config.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Session\SaveHandler\Redis;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\App\DeploymentConfig;
  9. use Magento\Framework\App\State;
  10. use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
  11. /**
  12. * Redis session save handler
  13. */
  14. class Config implements \Cm\RedisSession\Handler\ConfigInterface
  15. {
  16. /**
  17. * Configuration path for log level
  18. */
  19. const PARAM_LOG_LEVEL = 'session/redis/log_level';
  20. /**
  21. * Configuration path for host
  22. */
  23. const PARAM_HOST = 'session/redis/host';
  24. /**
  25. * Configuration path for port
  26. */
  27. const PARAM_PORT = 'session/redis/port';
  28. /**
  29. * Configuration path for database
  30. */
  31. const PARAM_DATABASE = 'session/redis/database';
  32. /**
  33. * Configuration path for password
  34. */
  35. const PARAM_PASSWORD = 'session/redis/password';
  36. /**
  37. * Configuration path for connection timeout
  38. */
  39. const PARAM_TIMEOUT = 'session/redis/timeout';
  40. /**
  41. * Configuration path for persistent identifier
  42. */
  43. const PARAM_PERSISTENT_IDENTIFIER = 'session/redis/persistent_identifier';
  44. /**
  45. * Configuration path for compression threshold
  46. */
  47. const PARAM_COMPRESSION_THRESHOLD = 'session/redis/compression_threshold';
  48. /**
  49. * Configuration path for compression library
  50. */
  51. const PARAM_COMPRESSION_LIBRARY = 'session/redis/compression_library';
  52. /**
  53. * Configuration path for maximum number of processes that can wait for a lock on one session
  54. */
  55. const PARAM_MAX_CONCURRENCY = 'session/redis/max_concurrency';
  56. /**
  57. * Configuration path for minimum session lifetime
  58. */
  59. const PARAM_MAX_LIFETIME = 'session/redis/max_lifetime';
  60. /**
  61. * Configuration path for min
  62. */
  63. const PARAM_MIN_LIFETIME = 'session/redis/min_lifetime';
  64. /**
  65. * Configuration path for disabling session locking entirely flag
  66. */
  67. const PARAM_DISABLE_LOCKING = 'session/redis/disable_locking';
  68. /**
  69. * Configuration path for lifetime of session for bots on subsequent writes
  70. */
  71. const PARAM_BOT_LIFETIME = 'session/redis/bot_lifetime';
  72. /**
  73. * Configuration path for lifetime of session for bots on the first write
  74. */
  75. const PARAM_BOT_FIRST_LIFETIME = 'session/redis/bot_first_lifetime';
  76. /**
  77. * Configuration path for lifetime of session for non-bots on the first write
  78. */
  79. const PARAM_FIRST_LIFETIME = 'session/redis/first_lifetime';
  80. /**
  81. * Configuration path for number of seconds to wait before trying to break the lock
  82. */
  83. const PARAM_BREAK_AFTER = 'session/redis/break_after';
  84. /**
  85. * Configuration path for comma separated list of sentinel servers
  86. */
  87. const PARAM_SENTINEL_SERVERS = 'session/redis/sentinel_servers';
  88. /**
  89. * Configuration path for sentinel master
  90. */
  91. const PARAM_SENTINEL_MASTER = 'session/redis/sentinel_master';
  92. /**
  93. * Configuration path for verify sentinel master flag
  94. */
  95. const PARAM_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';
  96. /**
  97. * Configuration path for number of sentinel connection retries
  98. */
  99. const PARAM_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';
  100. /**
  101. * Cookie lifetime config path
  102. */
  103. const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime';
  104. /**
  105. * Admin session lifetime config path
  106. */
  107. const XML_PATH_ADMIN_SESSION_LIFETIME = 'admin/security/session_lifetime';
  108. /**
  109. * Session max lifetime
  110. */
  111. const SESSION_MAX_LIFETIME = 31536000;
  112. /**
  113. * Try to break lock for at most this many seconds
  114. */
  115. const DEFAULT_FAIL_AFTER = 15;
  116. /**
  117. * Deployment config
  118. *
  119. * @var DeploymentConfig
  120. */
  121. private $deploymentConfig;
  122. /**
  123. * @var ScopeConfigInterface
  124. */
  125. private $scopeConfig;
  126. /**
  127. * @var State
  128. */
  129. private $appState;
  130. /**
  131. * @param DeploymentConfig $deploymentConfig
  132. * @param State $appState
  133. * @param ScopeConfigInterface $scopeConfig
  134. */
  135. public function __construct(
  136. DeploymentConfig $deploymentConfig,
  137. State $appState,
  138. ScopeConfigInterface $scopeConfig
  139. ) {
  140. $this->deploymentConfig = $deploymentConfig;
  141. $this->appState = $appState;
  142. $this->scopeConfig = $scopeConfig;
  143. }
  144. /**
  145. * @inheritdoc
  146. */
  147. public function getLogLevel()
  148. {
  149. return $this->deploymentConfig->get(self::PARAM_LOG_LEVEL);
  150. }
  151. /**
  152. * @inheritdoc
  153. */
  154. public function getHost()
  155. {
  156. return $this->deploymentConfig->get(self::PARAM_HOST);
  157. }
  158. /**
  159. * @inheritdoc
  160. */
  161. public function getPort()
  162. {
  163. return $this->deploymentConfig->get(self::PARAM_PORT);
  164. }
  165. /**
  166. * @inheritdoc
  167. */
  168. public function getDatabase()
  169. {
  170. return $this->deploymentConfig->get(self::PARAM_DATABASE);
  171. }
  172. /**
  173. * @inheritdoc
  174. */
  175. public function getPassword()
  176. {
  177. return $this->deploymentConfig->get(self::PARAM_PASSWORD);
  178. }
  179. /**
  180. * @inheritdoc
  181. */
  182. public function getTimeout()
  183. {
  184. return $this->deploymentConfig->get(self::PARAM_TIMEOUT);
  185. }
  186. /**
  187. * @inheritdoc
  188. */
  189. public function getPersistentIdentifier()
  190. {
  191. return $this->deploymentConfig->get(self::PARAM_PERSISTENT_IDENTIFIER);
  192. }
  193. /**
  194. * @inheritdoc
  195. */
  196. public function getCompressionThreshold()
  197. {
  198. return $this->deploymentConfig->get(self::PARAM_COMPRESSION_THRESHOLD);
  199. }
  200. /**
  201. * @inheritdoc
  202. */
  203. public function getCompressionLibrary()
  204. {
  205. return $this->deploymentConfig->get(self::PARAM_COMPRESSION_LIBRARY);
  206. }
  207. /**
  208. * @inheritdoc
  209. */
  210. public function getMaxConcurrency()
  211. {
  212. return $this->deploymentConfig->get(self::PARAM_MAX_CONCURRENCY);
  213. }
  214. /**
  215. * @inheritdoc
  216. */
  217. public function getMaxLifetime()
  218. {
  219. return self::SESSION_MAX_LIFETIME;
  220. }
  221. /**
  222. * @inheritdoc
  223. */
  224. public function getMinLifetime()
  225. {
  226. return $this->deploymentConfig->get(self::PARAM_MIN_LIFETIME);
  227. }
  228. /**
  229. * @inheritdoc
  230. */
  231. public function getDisableLocking()
  232. {
  233. return $this->deploymentConfig->get(self::PARAM_DISABLE_LOCKING);
  234. }
  235. /**
  236. * @inheritdoc
  237. */
  238. public function getBotLifetime()
  239. {
  240. return $this->deploymentConfig->get(self::PARAM_BOT_LIFETIME);
  241. }
  242. /**
  243. * @inheritdoc
  244. */
  245. public function getBotFirstLifetime()
  246. {
  247. return $this->deploymentConfig->get(self::PARAM_BOT_FIRST_LIFETIME);
  248. }
  249. /**
  250. * @inheritdoc
  251. */
  252. public function getFirstLifetime()
  253. {
  254. return $this->deploymentConfig->get(self::PARAM_FIRST_LIFETIME);
  255. }
  256. /**
  257. * @inheritdoc
  258. */
  259. public function getBreakAfter()
  260. {
  261. return $this->deploymentConfig->get(self::PARAM_BREAK_AFTER . '_' . $this->appState->getAreaCode());
  262. }
  263. /**
  264. * @inheritdoc
  265. */
  266. public function getLifetime()
  267. {
  268. if ($this->appState->getAreaCode() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
  269. return (int)$this->scopeConfig->getValue(self::XML_PATH_ADMIN_SESSION_LIFETIME);
  270. }
  271. return (int)$this->scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, StoreScopeInterface::SCOPE_STORE);
  272. }
  273. /**
  274. * @inheritdoc
  275. */
  276. public function getSentinelServers()
  277. {
  278. return $this->deploymentConfig->get(self::PARAM_SENTINEL_SERVERS);
  279. }
  280. /**
  281. * @inheritdoc
  282. */
  283. public function getSentinelMaster()
  284. {
  285. return $this->deploymentConfig->get(self::PARAM_SENTINEL_MASTER);
  286. }
  287. /**
  288. * @inheritdoc
  289. */
  290. public function getSentinelVerifyMaster()
  291. {
  292. return $this->deploymentConfig->get(self::PARAM_SENTINEL_VERIFY_MASTER);
  293. }
  294. /**
  295. * @inheritdoc
  296. */
  297. public function getSentinelConnectRetries()
  298. {
  299. return $this->deploymentConfig->get(self::PARAM_SENTINEL_CONNECT_RETRIES);
  300. }
  301. /**
  302. * @inheritdoc
  303. */
  304. public function getFailAfter()
  305. {
  306. return self::DEFAULT_FAIL_AFTER;
  307. }
  308. }