Skip to content

Commit 53fd4ab

Browse files
committed
config: add Config/Session.php
1 parent a68891a commit 53fd4ab

3 files changed

Lines changed: 138 additions & 9 deletions

File tree

app/Config/App.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class App extends BaseConfig
149149
* - `CodeIgniter\Session\Handlers\RedisHandler`
150150
*
151151
* @var string
152+
*
153+
* @deprecated use Config\Session::$driver instead.
152154
*/
153155
public $sessionDriver = FileHandler::class;
154156

@@ -158,6 +160,8 @@ class App extends BaseConfig
158160
* --------------------------------------------------------------------------
159161
*
160162
* The session cookie name, must contain only [0-9a-z_-] characters
163+
*
164+
* @deprecated use Config\Session::$cookieName instead.
161165
*/
162166
public string $sessionCookieName = 'ci_session';
163167

@@ -168,6 +172,8 @@ class App extends BaseConfig
168172
*
169173
* The number of SECONDS you want the session to last.
170174
* Setting to 0 (zero) means expire when the browser is closed.
175+
*
176+
* @deprecated use Config\Session::$expiration instead.
171177
*/
172178
public int $sessionExpiration = 7200;
173179

@@ -185,6 +191,8 @@ class App extends BaseConfig
185191
* Please read up the manual for the format with other session drivers.
186192
*
187193
* IMPORTANT: You are REQUIRED to set a valid save path!
194+
*
195+
* @deprecated use Config\Session::$savePath instead.
188196
*/
189197
public string $sessionSavePath = WRITEPATH . 'session';
190198

@@ -197,6 +205,8 @@ class App extends BaseConfig
197205
*
198206
* WARNING: If you're using the database driver, don't forget to update
199207
* your session table's PRIMARY KEY when changing this setting.
208+
*
209+
* @deprecated use Config\Session::$matchIP instead.
200210
*/
201211
public bool $sessionMatchIP = false;
202212

@@ -206,6 +216,8 @@ class App extends BaseConfig
206216
* --------------------------------------------------------------------------
207217
*
208218
* How many seconds between CI regenerating the session ID.
219+
*
220+
* @deprecated use Config\Session::$timeToUpdate instead.
209221
*/
210222
public int $sessionTimeToUpdate = 300;
211223

@@ -217,9 +229,22 @@ class App extends BaseConfig
217229
* Whether to destroy session data associated with the old session ID
218230
* when auto-regenerating the session ID. When set to FALSE, the data
219231
* will be later deleted by the garbage collector.
232+
*
233+
* @deprecated use Config\Session::$regenerateDestroy instead.
220234
*/
221235
public bool $sessionRegenerateDestroy = false;
222236

237+
/**
238+
* --------------------------------------------------------------------------
239+
* Session Database Group
240+
* --------------------------------------------------------------------------
241+
*
242+
* DB Group for the database session.
243+
*
244+
* @deprecated use Config\Session::$DBGroup instead.
245+
*/
246+
public ?bool $sessionDBGroup = null;
247+
223248
/**
224249
* --------------------------------------------------------------------------
225250
* Cookie Prefix

app/Config/Session.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Config;
4+
5+
use CodeIgniter\Config\BaseConfig;
6+
use CodeIgniter\Session\Handlers\FileHandler;
7+
8+
class Session extends BaseConfig
9+
{
10+
/**
11+
* --------------------------------------------------------------------------
12+
* Session Driver
13+
* --------------------------------------------------------------------------
14+
*
15+
* The session storage driver to use:
16+
* - `CodeIgniter\Session\Handlers\FileHandler`
17+
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
18+
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
19+
* - `CodeIgniter\Session\Handlers\RedisHandler`
20+
*
21+
* @phpstan-var class-string
22+
*/
23+
public string $driver = FileHandler::class;
24+
25+
/**
26+
* --------------------------------------------------------------------------
27+
* Session Cookie Name
28+
* --------------------------------------------------------------------------
29+
*
30+
* The session cookie name, must contain only [0-9a-z_-] characters
31+
*/
32+
public string $cookieName = 'ci_session';
33+
34+
/**
35+
* --------------------------------------------------------------------------
36+
* Session Expiration
37+
* --------------------------------------------------------------------------
38+
*
39+
* The number of SECONDS you want the session to last.
40+
* Setting to 0 (zero) means expire when the browser is closed.
41+
*/
42+
public int $expiration = 7200;
43+
44+
/**
45+
* --------------------------------------------------------------------------
46+
* Session Save Path
47+
* --------------------------------------------------------------------------
48+
*
49+
* The location to save sessions to and is driver dependent.
50+
*
51+
* For the 'files' driver, it's a path to a writable directory.
52+
* WARNING: Only absolute paths are supported!
53+
*
54+
* For the 'database' driver, it's a table name.
55+
* Please read up the manual for the format with other session drivers.
56+
*
57+
* IMPORTANT: You are REQUIRED to set a valid save path!
58+
*/
59+
public string $savePath = WRITEPATH . 'session';
60+
61+
/**
62+
* --------------------------------------------------------------------------
63+
* Session Match IP
64+
* --------------------------------------------------------------------------
65+
*
66+
* Whether to match the user's IP address when reading the session data.
67+
*
68+
* WARNING: If you're using the database driver, don't forget to update
69+
* your session table's PRIMARY KEY when changing this setting.
70+
*/
71+
public bool $matchIP = false;
72+
73+
/**
74+
* --------------------------------------------------------------------------
75+
* Session Time to Update
76+
* --------------------------------------------------------------------------
77+
*
78+
* How many seconds between CI regenerating the session ID.
79+
*/
80+
public int $timeToUpdate = 300;
81+
82+
/**
83+
* --------------------------------------------------------------------------
84+
* Session Regenerate Destroy
85+
* --------------------------------------------------------------------------
86+
*
87+
* Whether to destroy session data associated with the old session ID
88+
* when auto-regenerating the session ID. When set to FALSE, the data
89+
* will be later deleted by the garbage collector.
90+
*/
91+
public bool $regenerateDestroy = false;
92+
93+
/**
94+
* --------------------------------------------------------------------------
95+
* Session Database Group
96+
* --------------------------------------------------------------------------
97+
*
98+
* DB Group for the database session.
99+
*/
100+
public ?bool $DBGroup = null;
101+
}

env

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
# If you have trouble with `.`, you could also use `_`.
2525
# app_baseURL = ''
2626
# app.forceGlobalSecureRequests = false
27-
28-
# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'
29-
# app.sessionCookieName = 'ci_session'
30-
# app.sessionExpiration = 7200
31-
# app.sessionSavePath = null
32-
# app.sessionMatchIP = false
33-
# app.sessionTimeToUpdate = 300
34-
# app.sessionRegenerateDestroy = false
35-
3627
# app.CSPEnabled = false
3728

3829
#--------------------------------------------------------------------
@@ -127,6 +118,18 @@
127118
# security.redirect = false
128119
# security.samesite = 'Lax'
129120

121+
#--------------------------------------------------------------------
122+
# SESSION
123+
#--------------------------------------------------------------------
124+
125+
# session.driver = 'CodeIgniter\Session\Handlers\FileHandler'
126+
# session.cookieName = 'ci_session'
127+
# session.expiration = 7200
128+
# session.savePath = null
129+
# session.matchIP = false
130+
# session.timeToUpdate = 300
131+
# session.regenerateDestroy = false
132+
130133
#--------------------------------------------------------------------
131134
# LOGGER
132135
#--------------------------------------------------------------------

0 commit comments

Comments
 (0)