PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php

https://gitlab.com/rmoshiur81/Larave-Grading
PHP | 212 lines | 92 code | 30 blank | 90 comment | 2 complexity | c296c03ed4aa2f45bec1aef0679ff2bf MD5 | raw file
  1. <?php
  2. namespace Illuminate\Session;
  3. use Illuminate\Support\Manager;
  4. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
  5. class SessionManager extends Manager
  6. {
  7. /**
  8. * Call a custom driver creator.
  9. *
  10. * @param string $driver
  11. * @return mixed
  12. */
  13. protected function callCustomCreator($driver)
  14. {
  15. return $this->buildSession(parent::callCustomCreator($driver));
  16. }
  17. /**
  18. * Create an instance of the "array" session driver.
  19. *
  20. * @return \Illuminate\Session\Store
  21. */
  22. protected function createArrayDriver()
  23. {
  24. return $this->buildSession(new NullSessionHandler);
  25. }
  26. /**
  27. * Create an instance of the "cookie" session driver.
  28. *
  29. * @return \Illuminate\Session\Store
  30. */
  31. protected function createCookieDriver()
  32. {
  33. $lifetime = $this->app['config']['session.lifetime'];
  34. return $this->buildSession(new CookieSessionHandler($this->app['cookie'], $lifetime));
  35. }
  36. /**
  37. * Create an instance of the file session driver.
  38. *
  39. * @return \Illuminate\Session\Store
  40. */
  41. protected function createFileDriver()
  42. {
  43. return $this->createNativeDriver();
  44. }
  45. /**
  46. * Create an instance of the file session driver.
  47. *
  48. * @return \Illuminate\Session\Store
  49. */
  50. protected function createNativeDriver()
  51. {
  52. $path = $this->app['config']['session.files'];
  53. $lifetime = $this->app['config']['session.lifetime'];
  54. return $this->buildSession(new FileSessionHandler($this->app['files'], $path, $lifetime));
  55. }
  56. /**
  57. * Create an instance of the database session driver.
  58. *
  59. * @return \Illuminate\Session\Store
  60. */
  61. protected function createDatabaseDriver()
  62. {
  63. $connection = $this->getDatabaseConnection();
  64. $table = $this->app['config']['session.table'];
  65. $lifetime = $this->app['config']['session.lifetime'];
  66. return $this->buildSession(new DatabaseSessionHandler($connection, $table, $lifetime, $this->app));
  67. }
  68. /**
  69. * Get the database connection for the database driver.
  70. *
  71. * @return \Illuminate\Database\Connection
  72. */
  73. protected function getDatabaseConnection()
  74. {
  75. $connection = $this->app['config']['session.connection'];
  76. return $this->app['db']->connection($connection);
  77. }
  78. /**
  79. * Create an instance of the APC session driver.
  80. *
  81. * @return \Illuminate\Session\Store
  82. */
  83. protected function createApcDriver()
  84. {
  85. return $this->createCacheBased('apc');
  86. }
  87. /**
  88. * Create an instance of the Memcached session driver.
  89. *
  90. * @return \Illuminate\Session\Store
  91. */
  92. protected function createMemcachedDriver()
  93. {
  94. return $this->createCacheBased('memcached');
  95. }
  96. /**
  97. * Create an instance of the Wincache session driver.
  98. *
  99. * @return \Illuminate\Session\Store
  100. */
  101. protected function createWincacheDriver()
  102. {
  103. return $this->createCacheBased('wincache');
  104. }
  105. /**
  106. * Create an instance of the Redis session driver.
  107. *
  108. * @return \Illuminate\Session\Store
  109. */
  110. protected function createRedisDriver()
  111. {
  112. $handler = $this->createCacheHandler('redis');
  113. $handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
  114. return $this->buildSession($handler);
  115. }
  116. /**
  117. * Create an instance of a cache driven driver.
  118. *
  119. * @param string $driver
  120. * @return \Illuminate\Session\Store
  121. */
  122. protected function createCacheBased($driver)
  123. {
  124. return $this->buildSession($this->createCacheHandler($driver));
  125. }
  126. /**
  127. * Create the cache based session handler instance.
  128. *
  129. * @param string $driver
  130. * @return \Illuminate\Session\CacheBasedSessionHandler
  131. */
  132. protected function createCacheHandler($driver)
  133. {
  134. $store = $this->app['config']->get('session.store') ?: $driver;
  135. $minutes = $this->app['config']['session.lifetime'];
  136. return new CacheBasedSessionHandler(clone $this->app['cache']->store($store), $minutes);
  137. }
  138. /**
  139. * Build the session instance.
  140. *
  141. * @param \SessionHandlerInterface $handler
  142. * @return \Illuminate\Session\Store
  143. */
  144. protected function buildSession($handler)
  145. {
  146. if ($this->app['config']['session.encrypt']) {
  147. return new EncryptedStore(
  148. $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
  149. );
  150. } else {
  151. return new Store($this->app['config']['session.cookie'], $handler);
  152. }
  153. }
  154. /**
  155. * Get the session configuration.
  156. *
  157. * @return array
  158. */
  159. public function getSessionConfig()
  160. {
  161. return $this->app['config']['session'];
  162. }
  163. /**
  164. * Get the default session driver name.
  165. *
  166. * @return string
  167. */
  168. public function getDefaultDriver()
  169. {
  170. return $this->app['config']['session.driver'];
  171. }
  172. /**
  173. * Set the default session driver name.
  174. *
  175. * @param string $name
  176. * @return void
  177. */
  178. public function setDefaultDriver($name)
  179. {
  180. $this->app['config']['session.driver'] = $name;
  181. }
  182. }