Skip to content

Commit

Permalink
Merge pull request #7255 from kenjis/remove-config-app-session-4.4
Browse files Browse the repository at this point in the history
Remove Config\App Session items
  • Loading branch information
kenjis authored Jun 23, 2023
2 parents 319fea5 + 7dda3b1 commit 0b226dd
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 283 deletions.
107 changes: 0 additions & 107 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Session\Handlers\FileHandler;

class App extends BaseConfig
{
Expand Down Expand Up @@ -136,112 +135,6 @@ class App extends BaseConfig
*/
public bool $forceGlobalSecureRequests = false;

/**
* --------------------------------------------------------------------------
* Session Driver
* --------------------------------------------------------------------------
*
* The session storage driver to use:
* - `CodeIgniter\Session\Handlers\FileHandler`
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
* - `CodeIgniter\Session\Handlers\RedisHandler`
*
* @deprecated use Config\Session::$driver instead.
*/
public string $sessionDriver = FileHandler::class;

/**
* --------------------------------------------------------------------------
* Session Cookie Name
* --------------------------------------------------------------------------
*
* The session cookie name, must contain only [0-9a-z_-] characters
*
* @deprecated use Config\Session::$cookieName instead.
*/
public string $sessionCookieName = 'ci_session';

/**
* --------------------------------------------------------------------------
* Session Expiration
* --------------------------------------------------------------------------
*
* The number of SECONDS you want the session to last.
* Setting to 0 (zero) means expire when the browser is closed.
*
* @deprecated use Config\Session::$expiration instead.
*/
public int $sessionExpiration = 7200;

/**
* --------------------------------------------------------------------------
* Session Save Path
* --------------------------------------------------------------------------
*
* The location to save sessions to and is driver dependent.
*
* For the 'files' driver, it's a path to a writable directory.
* WARNING: Only absolute paths are supported!
*
* For the 'database' driver, it's a table name.
* Please read up the manual for the format with other session drivers.
*
* IMPORTANT: You are REQUIRED to set a valid save path!
*
* @deprecated use Config\Session::$savePath instead.
*/
public string $sessionSavePath = WRITEPATH . 'session';

/**
* --------------------------------------------------------------------------
* Session Match IP
* --------------------------------------------------------------------------
*
* Whether to match the user's IP address when reading the session data.
*
* WARNING: If you're using the database driver, don't forget to update
* your session table's PRIMARY KEY when changing this setting.
*
* @deprecated use Config\Session::$matchIP instead.
*/
public bool $sessionMatchIP = false;

/**
* --------------------------------------------------------------------------
* Session Time to Update
* --------------------------------------------------------------------------
*
* How many seconds between CI regenerating the session ID.
*
* @deprecated use Config\Session::$timeToUpdate instead.
*/
public int $sessionTimeToUpdate = 300;

/**
* --------------------------------------------------------------------------
* Session Regenerate Destroy
* --------------------------------------------------------------------------
*
* Whether to destroy session data associated with the old session ID
* when auto-regenerating the session ID. When set to FALSE, the data
* will be later deleted by the garbage collector.
*
* @deprecated use Config\Session::$regenerateDestroy instead.
*/
public bool $sessionRegenerateDestroy = false;

/**
* --------------------------------------------------------------------------
* Session Database Group
* --------------------------------------------------------------------------
*
* DB Group for the database session.
*
* @deprecated use Config\Session::$DBGroup instead.
*/
public ?string $sessionDBGroup = null;

/**
* --------------------------------------------------------------------------
* Reverse Proxy IPs
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ parameters:
count: 1
path: system/Router/Router.php

-
message: "#^Property CodeIgniter\\\\Session\\\\Session\\:\\:\\$sessionExpiration \\(int\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: system/Session/Session.php

-
message: "#^Access to an undefined property object\\:\\:\\$createdField\\.$#"
count: 1
Expand Down
6 changes: 1 addition & 5 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use Config\App as AppConfig;
use Config\Session as SessionConfig;

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

/** @var AppConfig $config */
$config = config('App');
/** @var SessionConfig|null $session */
$session = config('Session');

$data['matchIP'] = ($session instanceof SessionConfig)
? $session->matchIP : $config->sessionMatchIP;
$data['matchIP'] = $session->matchIP;
}

return $this->parseTemplate($class, [], [], $data);
Expand Down
14 changes: 7 additions & 7 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,25 +638,25 @@ public static function security(?App $config = null, bool $getShared = true)
* Return the session manager.
*
* @return Session
*
* @TODO replace the first parameter type `?App` with `?SessionConfig`
*/
public static function session(?App $config = null, bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('session', $config);
}

$config ??= config('App');
assert($config instanceof App);

$logger = AppServices::logger();

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

$driverName = $sessionConfig->driver ?? $config->sessionDriver;
$driverName = $config->driver;

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

$driver = $db->getPlatform();
Expand Down
19 changes: 4 additions & 15 deletions system/Session/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CodeIgniter\Session\Handlers;

use Config\App as AppConfig;
use Config\Cookie as CookieConfig;
use Config\Session as SessionConfig;
use Psr\Log\LoggerAwareTrait;
Expand Down Expand Up @@ -105,22 +104,12 @@ abstract class BaseHandler implements SessionHandlerInterface
*/
protected $ipAddress;

public function __construct(AppConfig $config, string $ipAddress)
public function __construct(SessionConfig $config, string $ipAddress)
{
/** @var SessionConfig|null $session */
$session = config('Session');

// Store Session configurations
if ($session instanceof SessionConfig) {
$this->cookieName = $session->cookieName;
$this->matchIP = $session->matchIP;
$this->savePath = $session->savePath;
} else {
// `Config/Session.php` is absence
$this->cookieName = $config->sessionCookieName;
$this->matchIP = $config->sessionMatchIP;
$this->savePath = $config->sessionSavePath;
}
$this->cookieName = $config->cookieName;
$this->matchIP = $config->matchIP;
$this->savePath = $config->savePath;

/** @var CookieConfig $cookie */
$cookie = config('Cookie');
Expand Down
19 changes: 4 additions & 15 deletions system/Session/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Config\Database;
use Config\Session as SessionConfig;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -69,24 +68,14 @@ class DatabaseHandler extends BaseHandler
/**
* @throws SessionException
*/
public function __construct(AppConfig $config, string $ipAddress)
public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

/** @var SessionConfig|null $session */
$session = config('Session');

// Store Session configurations
if ($session instanceof SessionConfig) {
$this->DBGroup = $session->DBGroup ?? config(Database::class)->defaultGroup;
// Add sessionCookieName for multiple session cookies.
$this->idPrefix = $session->cookieName . ':';
} else {
// `Config/Session.php` is absence
$this->DBGroup = $config->sessionDBGroup ?? config(Database::class)->defaultGroup;
// Add sessionCookieName for multiple session cookies.
$this->idPrefix = $config->sessionCookieName . ':';
}
$this->DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
// Add sessionCookieName for multiple session cookies.
$this->idPrefix = $config->cookieName . ':';

$this->table = $this->savePath;
if (empty($this->table)) {
Expand Down
4 changes: 2 additions & 2 deletions system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Config\Session as SessionConfig;
use ReturnTypeWillChange;

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ class FileHandler extends BaseHandler
*/
protected $sessionIDRegex = '';

public function __construct(AppConfig $config, string $ipAddress)
public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

Expand Down
12 changes: 3 additions & 9 deletions system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Config\Session as SessionConfig;
use Memcached;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -54,23 +53,18 @@ class MemcachedHandler extends BaseHandler
/**
* @throws SessionException
*/
public function __construct(AppConfig $config, string $ipAddress)
public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

/** @var SessionConfig|null $session */
$session = config('Session');

$this->sessionExpiration = ($session instanceof SessionConfig)
? $session->expiration : $config->sessionExpiration;
$this->sessionExpiration = $config->expiration;

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

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

if ($this->matchIP === true) {
$this->keyPrefix .= $this->ipAddress . ':';
Expand Down
25 changes: 6 additions & 19 deletions system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\App as AppConfig;
use Config\Session as SessionConfig;
use Redis;
use RedisException;
Expand Down Expand Up @@ -67,28 +66,16 @@ class RedisHandler extends BaseHandler
*
* @throws SessionException
*/
public function __construct(AppConfig $config, string $ipAddress)
public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

/** @var SessionConfig|null $session */
$session = config('Session');

// Store Session configurations
if ($session instanceof SessionConfig) {
$this->sessionExpiration = empty($session->expiration)
? (int) ini_get('session.gc_maxlifetime')
: (int) $session->expiration;
// Add sessionCookieName for multiple session cookies.
$this->keyPrefix .= $session->cookieName . ':';
} else {
// `Config/Session.php` is absence
$this->sessionExpiration = empty($config->sessionExpiration)
? (int) ini_get('session.gc_maxlifetime')
: (int) $config->sessionExpiration;
// Add sessionCookieName for multiple session cookies.
$this->keyPrefix .= $config->sessionCookieName . ':';
}
$this->sessionExpiration = empty($config->expiration)
? (int) ini_get('session.gc_maxlifetime')
: (int) $config->expiration;
// Add sessionCookieName for multiple session cookies.
$this->keyPrefix .= $config->cookieName . ':';

$this->setSavePath();

Expand Down
Loading

0 comments on commit 0b226dd

Please sign in to comment.