Session.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace think;
  13. use think\helper\Arr;
  14. use think\session\Store;
  15. /**
  16. * Session管理类
  17. * @package think
  18. * @mixin Store
  19. */
  20. class Session extends Manager
  21. {
  22. protected $namespace = '\\think\\session\\driver\\';
  23. protected function createDriver(string $name)
  24. {
  25. $handler = parent::createDriver($name);
  26. return new Store($this->getConfig('name') ?: 'PHPSESSID', $handler, $this->getConfig('serialize'));
  27. }
  28. /**
  29. * 获取Session配置
  30. * @access public
  31. * @param null|string $name 名称
  32. * @param mixed $default 默认值
  33. * @return mixed
  34. */
  35. public function getConfig(string $name = null, $default = null)
  36. {
  37. if (!is_null($name)) {
  38. return $this->app->config->get('session.' . $name, $default);
  39. }
  40. return $this->app->config->get('session');
  41. }
  42. protected function resolveConfig(string $name)
  43. {
  44. $config = $this->app->config->get('session', []);
  45. Arr::forget($config, 'type');
  46. return $config;
  47. }
  48. /**
  49. * 默认驱动
  50. * @return string|null
  51. */
  52. public function getDefaultDriver()
  53. {
  54. return $this->app->config->get('session.type', 'file');
  55. }
  56. }