SessionConnectionConfigTrait.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace Aws\DynamoDb;
  3. trait SessionConnectionConfigTrait
  4. {
  5. /** @var string Name of table to store the sessions */
  6. protected $tableName = 'sessions';
  7. /** @var string Name of hash key in table. Default: "id" */
  8. protected $hashKey = 'id';
  9. /** @var string Name of the data attribute in table. Default: "data" */
  10. protected $dataAttribute = 'data';
  11. /** @var string Type of the data attribute in table. Default: "string" */
  12. protected $dataAttributeType = 'string';
  13. /** @var integer Lifetime of inactive sessions expiration */
  14. protected $sessionLifetime;
  15. /** @var string Name of the session life time attribute in table. Default: "expires" */
  16. protected $sessionLifetimeAttribute = 'expires';
  17. /** @var string Whether or not to use consistent reads */
  18. protected $consistentRead = true;
  19. /** @var string Batch options used for garbage collection */
  20. protected $batchConfig = [];
  21. /** @var boolean Whether or not to use session locking */
  22. protected $locking = false;
  23. /** @var integer Max time (s) to wait for lock acquisition */
  24. protected $maxLockWaitTime = 10;
  25. /** @var integer Min time (µs) to wait between lock attempts */
  26. protected $minLockRetryMicrotime = 10000;
  27. /** @var integer Max time (µs) to wait between lock attempts */
  28. protected $maxLockRetryMicrotime = 50000;
  29. /**
  30. * It initialize the Config class and
  31. * it sets values in case of valid configurations.
  32. *
  33. * It transforms parameters underscore separated in camelcase "this_is_a_test" => ThisIsATest
  34. * and it uses it in order to set the values.
  35. *
  36. * @param array $config
  37. */
  38. public function initConfig( array $config = [] )
  39. {
  40. if (!empty($config))
  41. {
  42. foreach ($config as $key => $value)
  43. {
  44. $method = 'set' . str_replace('_', '', ucwords($key, '_'));
  45. if(method_exists($this,$method))
  46. {
  47. call_user_func_array(array($this, $method), array($value));
  48. }
  49. }
  50. }
  51. // It applies the default PHP session lifetime, if no session lifetime config is provided
  52. if(!isset($config['session_lifetime']))
  53. {
  54. $this->setSessionLifetime((int) ini_get('session.gc_maxlifetime'));
  55. }
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getTableName()
  61. {
  62. return $this->tableName;
  63. }
  64. /**
  65. * @param string $tableName
  66. */
  67. public function setTableName($tableName)
  68. {
  69. $this->tableName = $tableName;
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function getHashKey()
  75. {
  76. return $this->hashKey;
  77. }
  78. /**
  79. * @param string $hashKey
  80. */
  81. public function setHashKey($hashKey)
  82. {
  83. $this->hashKey = $hashKey;
  84. }
  85. /**
  86. * @return string
  87. */
  88. public function getDataAttribute()
  89. {
  90. return $this->dataAttribute;
  91. }
  92. /**
  93. * @param string $dataAttribute
  94. */
  95. public function setDataAttribute($dataAttribute)
  96. {
  97. $this->dataAttribute = $dataAttribute;
  98. }
  99. /**
  100. * @return string
  101. */
  102. public function getDataAttributeType()
  103. {
  104. return $this->dataAttributeType;
  105. }
  106. /**
  107. * @param string $dataAttributeType
  108. */
  109. public function setDataAttributeType($dataAttributeType)
  110. {
  111. $this->dataAttributeType = $dataAttributeType;
  112. }
  113. /**
  114. * @return number
  115. */
  116. public function getSessionLifetime()
  117. {
  118. return $this->sessionLifetime;
  119. }
  120. /**
  121. * @param number $sessionLifetime
  122. */
  123. public function setSessionLifetime($sessionLifetime)
  124. {
  125. $this->sessionLifetime = $sessionLifetime;
  126. }
  127. /**
  128. * @return string
  129. */
  130. public function getSessionLifetimeAttribute()
  131. {
  132. return $this->sessionLifetimeAttribute;
  133. }
  134. /**
  135. * @param string $sessionLifetimeAttribute
  136. */
  137. public function setSessionLifetimeAttribute($sessionLifetimeAttribute)
  138. {
  139. $this->sessionLifetimeAttribute = $sessionLifetimeAttribute;
  140. }
  141. /**
  142. * @return boolean
  143. */
  144. public function isConsistentRead()
  145. {
  146. return $this->consistentRead;
  147. }
  148. /**
  149. * @param boolean $consistentRead
  150. */
  151. public function setConsistentRead($consistentRead)
  152. {
  153. $this->consistentRead = $consistentRead;
  154. }
  155. /**
  156. * @return mixed
  157. */
  158. public function getBatchConfig()
  159. {
  160. return $this->batchConfig;
  161. }
  162. /**
  163. * @param mixed $batchConfig
  164. */
  165. public function setBatchConfig($batchConfig)
  166. {
  167. $this->batchConfig = $batchConfig;
  168. }
  169. /**
  170. * @return boolean
  171. */
  172. public function isLocking()
  173. {
  174. return $this->locking;
  175. }
  176. /**
  177. * @param boolean $locking
  178. */
  179. public function setLocking($locking)
  180. {
  181. $this->locking = $locking;
  182. }
  183. /**
  184. * @return number
  185. */
  186. public function getMaxLockWaitTime()
  187. {
  188. return $this->maxLockWaitTime;
  189. }
  190. /**
  191. * @param number $maxLockWaitTime
  192. */
  193. public function setMaxLockWaitTime($maxLockWaitTime)
  194. {
  195. $this->maxLockWaitTime = $maxLockWaitTime;
  196. }
  197. /**
  198. * @return number
  199. */
  200. public function getMinLockRetryMicrotime()
  201. {
  202. return $this->minLockRetryMicrotime;
  203. }
  204. /**
  205. * @param number $minLockRetryMicrotime
  206. */
  207. public function setMinLockRetryMicrotime($minLockRetryMicrotime)
  208. {
  209. $this->minLockRetryMicrotime = $minLockRetryMicrotime;
  210. }
  211. /**
  212. * @return number
  213. */
  214. public function getMaxLockRetryMicrotime()
  215. {
  216. return $this->maxLockRetryMicrotime;
  217. }
  218. /**
  219. * @param number $maxLockRetryMicrotime
  220. */
  221. public function setMaxLockRetryMicrotime($maxLockRetryMicrotime)
  222. {
  223. $this->maxLockRetryMicrotime = $maxLockRetryMicrotime;
  224. }
  225. }