Skip to content

Commit 0b226dd

Browse files
authored
Merge pull request #7255 from kenjis/remove-config-app-session-4.4
Remove Config\App Session items
2 parents 319fea5 + 7dda3b1 commit 0b226dd

21 files changed

+127
-283
lines changed

app/Config/App.php

-107
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Config;
44

55
use CodeIgniter\Config\BaseConfig;
6-
use CodeIgniter\Session\Handlers\FileHandler;
76

87
class App extends BaseConfig
98
{
@@ -136,112 +135,6 @@ class App extends BaseConfig
136135
*/
137136
public bool $forceGlobalSecureRequests = false;
138137

139-
/**
140-
* --------------------------------------------------------------------------
141-
* Session Driver
142-
* --------------------------------------------------------------------------
143-
*
144-
* The session storage driver to use:
145-
* - `CodeIgniter\Session\Handlers\FileHandler`
146-
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
147-
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
148-
* - `CodeIgniter\Session\Handlers\RedisHandler`
149-
*
150-
* @deprecated use Config\Session::$driver instead.
151-
*/
152-
public string $sessionDriver = FileHandler::class;
153-
154-
/**
155-
* --------------------------------------------------------------------------
156-
* Session Cookie Name
157-
* --------------------------------------------------------------------------
158-
*
159-
* The session cookie name, must contain only [0-9a-z_-] characters
160-
*
161-
* @deprecated use Config\Session::$cookieName instead.
162-
*/
163-
public string $sessionCookieName = 'ci_session';
164-
165-
/**
166-
* --------------------------------------------------------------------------
167-
* Session Expiration
168-
* --------------------------------------------------------------------------
169-
*
170-
* The number of SECONDS you want the session to last.
171-
* Setting to 0 (zero) means expire when the browser is closed.
172-
*
173-
* @deprecated use Config\Session::$expiration instead.
174-
*/
175-
public int $sessionExpiration = 7200;
176-
177-
/**
178-
* --------------------------------------------------------------------------
179-
* Session Save Path
180-
* --------------------------------------------------------------------------
181-
*
182-
* The location to save sessions to and is driver dependent.
183-
*
184-
* For the 'files' driver, it's a path to a writable directory.
185-
* WARNING: Only absolute paths are supported!
186-
*
187-
* For the 'database' driver, it's a table name.
188-
* Please read up the manual for the format with other session drivers.
189-
*
190-
* IMPORTANT: You are REQUIRED to set a valid save path!
191-
*
192-
* @deprecated use Config\Session::$savePath instead.
193-
*/
194-
public string $sessionSavePath = WRITEPATH . 'session';
195-
196-
/**
197-
* --------------------------------------------------------------------------
198-
* Session Match IP
199-
* --------------------------------------------------------------------------
200-
*
201-
* Whether to match the user's IP address when reading the session data.
202-
*
203-
* WARNING: If you're using the database driver, don't forget to update
204-
* your session table's PRIMARY KEY when changing this setting.
205-
*
206-
* @deprecated use Config\Session::$matchIP instead.
207-
*/
208-
public bool $sessionMatchIP = false;
209-
210-
/**
211-
* --------------------------------------------------------------------------
212-
* Session Time to Update
213-
* --------------------------------------------------------------------------
214-
*
215-
* How many seconds between CI regenerating the session ID.
216-
*
217-
* @deprecated use Config\Session::$timeToUpdate instead.
218-
*/
219-
public int $sessionTimeToUpdate = 300;
220-
221-
/**
222-
* --------------------------------------------------------------------------
223-
* Session Regenerate Destroy
224-
* --------------------------------------------------------------------------
225-
*
226-
* Whether to destroy session data associated with the old session ID
227-
* when auto-regenerating the session ID. When set to FALSE, the data
228-
* will be later deleted by the garbage collector.
229-
*
230-
* @deprecated use Config\Session::$regenerateDestroy instead.
231-
*/
232-
public bool $sessionRegenerateDestroy = false;
233-
234-
/**
235-
* --------------------------------------------------------------------------
236-
* Session Database Group
237-
* --------------------------------------------------------------------------
238-
*
239-
* DB Group for the database session.
240-
*
241-
* @deprecated use Config\Session::$DBGroup instead.
242-
*/
243-
public ?string $sessionDBGroup = null;
244-
245138
/**
246139
* --------------------------------------------------------------------------
247140
* Reverse Proxy IPs

phpstan-baseline.neon.dist

-5
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,6 @@ parameters:
230230
count: 1
231231
path: system/Router/Router.php
232232

233-
-
234-
message: "#^Property CodeIgniter\\\\Session\\\\Session\\:\\:\\$sessionExpiration \\(int\\) in isset\\(\\) is not nullable\\.$#"
235-
count: 1
236-
path: system/Session/Session.php
237-
238233
-
239234
message: "#^Access to an undefined property object\\:\\:\\$createdField\\.$#"
240235
count: 1

system/Commands/Generators/MigrationGenerator.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use CodeIgniter\CLI\BaseCommand;
1515
use CodeIgniter\CLI\CLI;
1616
use CodeIgniter\CLI\GeneratorTrait;
17-
use Config\App as AppConfig;
1817
use Config\Session as SessionConfig;
1918

2019
/**
@@ -109,13 +108,10 @@ protected function prepare(string $class): string
109108
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
110109
$data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver'];
111110

112-
/** @var AppConfig $config */
113-
$config = config('App');
114111
/** @var SessionConfig|null $session */
115112
$session = config('Session');
116113

117-
$data['matchIP'] = ($session instanceof SessionConfig)
118-
? $session->matchIP : $config->sessionMatchIP;
114+
$data['matchIP'] = $session->matchIP;
119115
}
120116

121117
return $this->parseTemplate($class, [], [], $data);

system/Config/Services.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -638,25 +638,25 @@ public static function security(?App $config = null, bool $getShared = true)
638638
* Return the session manager.
639639
*
640640
* @return Session
641+
*
642+
* @TODO replace the first parameter type `?App` with `?SessionConfig`
641643
*/
642644
public static function session(?App $config = null, bool $getShared = true)
643645
{
644646
if ($getShared) {
645647
return static::getSharedInstance('session', $config);
646648
}
647649

648-
$config ??= config('App');
649-
assert($config instanceof App);
650-
651650
$logger = AppServices::logger();
652651

653-
/** @var SessionConfig|null $sessionConfig */
654-
$sessionConfig = config('Session');
652+
/** @var SessionConfig $config */
653+
$config = config('Session');
654+
assert($config instanceof SessionConfig, 'Missing "Config/Session.php".');
655655

656-
$driverName = $sessionConfig->driver ?? $config->sessionDriver;
656+
$driverName = $config->driver;
657657

658658
if ($driverName === DatabaseHandler::class) {
659-
$DBGroup = $sessionConfig->DBGroup ?? $config->sessionDBGroup ?? config(Database::class)->defaultGroup;
659+
$DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
660660
$db = Database::connect($DBGroup);
661661

662662
$driver = $db->getPlatform();

system/Session/Handlers/BaseHandler.php

+4-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace CodeIgniter\Session\Handlers;
1313

14-
use Config\App as AppConfig;
1514
use Config\Cookie as CookieConfig;
1615
use Config\Session as SessionConfig;
1716
use Psr\Log\LoggerAwareTrait;
@@ -105,22 +104,12 @@ abstract class BaseHandler implements SessionHandlerInterface
105104
*/
106105
protected $ipAddress;
107106

108-
public function __construct(AppConfig $config, string $ipAddress)
107+
public function __construct(SessionConfig $config, string $ipAddress)
109108
{
110-
/** @var SessionConfig|null $session */
111-
$session = config('Session');
112-
113109
// Store Session configurations
114-
if ($session instanceof SessionConfig) {
115-
$this->cookieName = $session->cookieName;
116-
$this->matchIP = $session->matchIP;
117-
$this->savePath = $session->savePath;
118-
} else {
119-
// `Config/Session.php` is absence
120-
$this->cookieName = $config->sessionCookieName;
121-
$this->matchIP = $config->sessionMatchIP;
122-
$this->savePath = $config->sessionSavePath;
123-
}
110+
$this->cookieName = $config->cookieName;
111+
$this->matchIP = $config->matchIP;
112+
$this->savePath = $config->savePath;
124113

125114
/** @var CookieConfig $cookie */
126115
$cookie = config('Cookie');

system/Session/Handlers/DatabaseHandler.php

+4-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use CodeIgniter\Database\BaseBuilder;
1515
use CodeIgniter\Database\BaseConnection;
1616
use CodeIgniter\Session\Exceptions\SessionException;
17-
use Config\App as AppConfig;
1817
use Config\Database;
1918
use Config\Session as SessionConfig;
2019
use ReturnTypeWillChange;
@@ -69,24 +68,14 @@ class DatabaseHandler extends BaseHandler
6968
/**
7069
* @throws SessionException
7170
*/
72-
public function __construct(AppConfig $config, string $ipAddress)
71+
public function __construct(SessionConfig $config, string $ipAddress)
7372
{
7473
parent::__construct($config, $ipAddress);
7574

76-
/** @var SessionConfig|null $session */
77-
$session = config('Session');
78-
7975
// Store Session configurations
80-
if ($session instanceof SessionConfig) {
81-
$this->DBGroup = $session->DBGroup ?? config(Database::class)->defaultGroup;
82-
// Add sessionCookieName for multiple session cookies.
83-
$this->idPrefix = $session->cookieName . ':';
84-
} else {
85-
// `Config/Session.php` is absence
86-
$this->DBGroup = $config->sessionDBGroup ?? config(Database::class)->defaultGroup;
87-
// Add sessionCookieName for multiple session cookies.
88-
$this->idPrefix = $config->sessionCookieName . ':';
89-
}
76+
$this->DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
77+
// Add sessionCookieName for multiple session cookies.
78+
$this->idPrefix = $config->cookieName . ':';
9079

9180
$this->table = $this->savePath;
9281
if (empty($this->table)) {

system/Session/Handlers/FileHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use CodeIgniter\I18n\Time;
1515
use CodeIgniter\Session\Exceptions\SessionException;
16-
use Config\App as AppConfig;
16+
use Config\Session as SessionConfig;
1717
use ReturnTypeWillChange;
1818

1919
/**
@@ -63,7 +63,7 @@ class FileHandler extends BaseHandler
6363
*/
6464
protected $sessionIDRegex = '';
6565

66-
public function __construct(AppConfig $config, string $ipAddress)
66+
public function __construct(SessionConfig $config, string $ipAddress)
6767
{
6868
parent::__construct($config, $ipAddress);
6969

system/Session/Handlers/MemcachedHandler.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use CodeIgniter\I18n\Time;
1515
use CodeIgniter\Session\Exceptions\SessionException;
16-
use Config\App as AppConfig;
1716
use Config\Session as SessionConfig;
1817
use Memcached;
1918
use ReturnTypeWillChange;
@@ -54,23 +53,18 @@ class MemcachedHandler extends BaseHandler
5453
/**
5554
* @throws SessionException
5655
*/
57-
public function __construct(AppConfig $config, string $ipAddress)
56+
public function __construct(SessionConfig $config, string $ipAddress)
5857
{
5958
parent::__construct($config, $ipAddress);
6059

61-
/** @var SessionConfig|null $session */
62-
$session = config('Session');
63-
64-
$this->sessionExpiration = ($session instanceof SessionConfig)
65-
? $session->expiration : $config->sessionExpiration;
60+
$this->sessionExpiration = $config->expiration;
6661

6762
if (empty($this->savePath)) {
6863
throw SessionException::forEmptySavepath();
6964
}
7065

7166
// Add sessionCookieName for multiple session cookies.
72-
$this->keyPrefix .= ($session instanceof SessionConfig)
73-
? $session->cookieName : $config->sessionCookieName . ':';
67+
$this->keyPrefix .= $config->cookieName . ':';
7468

7569
if ($this->matchIP === true) {
7670
$this->keyPrefix .= $this->ipAddress . ':';

system/Session/Handlers/RedisHandler.php

+6-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use CodeIgniter\I18n\Time;
1515
use CodeIgniter\Session\Exceptions\SessionException;
16-
use Config\App as AppConfig;
1716
use Config\Session as SessionConfig;
1817
use Redis;
1918
use RedisException;
@@ -67,28 +66,16 @@ class RedisHandler extends BaseHandler
6766
*
6867
* @throws SessionException
6968
*/
70-
public function __construct(AppConfig $config, string $ipAddress)
69+
public function __construct(SessionConfig $config, string $ipAddress)
7170
{
7271
parent::__construct($config, $ipAddress);
7372

74-
/** @var SessionConfig|null $session */
75-
$session = config('Session');
76-
7773
// Store Session configurations
78-
if ($session instanceof SessionConfig) {
79-
$this->sessionExpiration = empty($session->expiration)
80-
? (int) ini_get('session.gc_maxlifetime')
81-
: (int) $session->expiration;
82-
// Add sessionCookieName for multiple session cookies.
83-
$this->keyPrefix .= $session->cookieName . ':';
84-
} else {
85-
// `Config/Session.php` is absence
86-
$this->sessionExpiration = empty($config->sessionExpiration)
87-
? (int) ini_get('session.gc_maxlifetime')
88-
: (int) $config->sessionExpiration;
89-
// Add sessionCookieName for multiple session cookies.
90-
$this->keyPrefix .= $config->sessionCookieName . ':';
91-
}
74+
$this->sessionExpiration = empty($config->expiration)
75+
? (int) ini_get('session.gc_maxlifetime')
76+
: (int) $config->expiration;
77+
// Add sessionCookieName for multiple session cookies.
78+
$this->keyPrefix .= $config->cookieName . ':';
9279

9380
$this->setSavePath();
9481

0 commit comments

Comments
 (0)