Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Config/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Session extends BaseConfig
* --------------------------------------------------------------------------
*
* The session storage driver to use:
* - `CodeIgniter\Session\Handlers\ArrayHandler` (for testing)
* - `CodeIgniter\Session\Handlers\FileHandler`
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
Expand Down
2 changes: 1 addition & 1 deletion system/Language/en/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Session language settings
return [
'missingDatabaseTable' => '"sessionSavePath" must have the table name for the Database Session Handler to work.',
'missingDatabaseTable' => 'Session: "savePath" must have the table name for the Database Session Handler to work.',
'invalidSavePath' => 'Session: Configured save path "{0}" is not a directory, does not exist or cannot be created.',
'writeProtectedSavePath' => 'Session: Configured save path "{0}" is not writable by the PHP process.',
'emptySavePath' => 'Session: No save path configured.',
Expand Down
17 changes: 10 additions & 7 deletions system/Session/Handlers/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
*/
class ArrayHandler extends BaseHandler
{
/**
* @var array<string, mixed>
*/
protected static $cache = [];

/**
* Re-initialize existing session, or creates a new one.
*
* @param string $path The path where to store/retrieve the session
* @param string $name The session name
* @param string $path The path where to store/retrieve the session.
* @param string $name The session name.
*/
public function open($path, $name): bool
{
Expand All @@ -37,7 +40,7 @@ public function open($path, $name): bool
/**
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
Expand All @@ -51,8 +54,8 @@ public function read($id)
/**
* Writes the session data to the session storage.
*
* @param string $id The session ID
* @param string $data The encoded session data
* @param string $id The session ID.
* @param string $data The encoded session data.
*/
public function write($id, $data): bool
{
Expand All @@ -68,9 +71,9 @@ public function close(): bool
}

/**
* Destroys a session
* Destroys a session.
*
* @param string $id The session ID being destroyed
* @param string $id The session ID being destroyed.
*/
public function destroy($id): bool
{
Expand Down
16 changes: 8 additions & 8 deletions system/Session/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use SessionHandlerInterface;

/**
* Base class for session handling
* Base class for session handling.
*/
abstract class BaseHandler implements SessionHandlerInterface
{
Expand All @@ -40,7 +40,7 @@ abstract class BaseHandler implements SessionHandlerInterface
protected $lock = false;

/**
* Cookie prefix
* Cookie prefix.
*
* The Config\Cookie::$prefix setting is completely ignored.
* See https://codeigniter.com/user_guide/libraries/sessions.html#session-preferences
Expand All @@ -50,14 +50,14 @@ abstract class BaseHandler implements SessionHandlerInterface
protected $cookiePrefix = '';

/**
* Cookie domain
* Cookie domain.
*
* @var string
*/
protected $cookieDomain = '';

/**
* Cookie path
* Cookie path.
*
* @var string
*/
Expand All @@ -71,7 +71,7 @@ abstract class BaseHandler implements SessionHandlerInterface
protected $cookieSecure = false;

/**
* Cookie name to use
* Cookie name to use.
*
* @var string
*/
Expand All @@ -85,17 +85,17 @@ abstract class BaseHandler implements SessionHandlerInterface
protected $matchIP = false;

/**
* Current session ID
* Current session ID.
*
* @var string|null
*/
protected $sessionID;

/**
* The 'save path' for the session
* varies between
* varies between.
*
* @var array|string
* @var array<string, mixed>|string
*/
protected $savePath;

Expand Down
36 changes: 18 additions & 18 deletions system/Session/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use ReturnTypeWillChange;

/**
* Base database session handler
* Base database session handler.
*
* Do not use this class. Use database specific handler class.
*/
Expand Down Expand Up @@ -49,21 +49,21 @@ class DatabaseHandler extends BaseHandler
protected $db;

/**
* The database type
* The database type.
*
* @var string
*/
protected $platform;

/**
* Row exists flag
* Row exists flag.
*
* @var bool
*/
protected $rowExists = false;

/**
* ID prefix for multiple session cookies
* ID prefix for multiple session cookies.
*/
protected string $idPrefix;

Expand All @@ -74,16 +74,16 @@ public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

// Store Session configurations
$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)) {

if ($this->table === '') {
throw SessionException::forMissingDatabaseTable();
}

// Store Session configurations
$this->DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
// Add session cookie name for multiple session cookies.
$this->idPrefix = $config->cookieName . ':';
$this->db = Database::connect($this->DBGroup);
$this->platform = $this->db->getPlatform();
}
Expand All @@ -96,7 +96,7 @@ public function __construct(SessionConfig $config, string $ipAddress)
*/
public function open($path, $name): bool
{
if (empty($this->db->connID)) {
if ($this->db->connID === false) {
$this->db->initialize();
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public function read($id)
}

/**
* Sets SELECT clause
* Sets SELECT clause.
*
* @return void
*/
Expand All @@ -163,7 +163,7 @@ protected function setSelect(BaseBuilder $builder)
}

/**
* Decodes column data
* Decodes column data.
*
* @param string $data
*
Expand All @@ -177,8 +177,8 @@ protected function decodeData($data)
/**
* Writes the session data to the session storage.
*
* @param string $id The session ID
* @param string $data The encoded session data
* @param string $id The session ID.
* @param string $data The encoded session data.
*/
public function write($id, $data): bool
{
Expand Down Expand Up @@ -230,7 +230,7 @@ public function write($id, $data): bool
}

/**
* Prepare data to insert/update
* Prepare data to insert/update.
*/
protected function prepareData(string $data): string
{
Expand All @@ -246,9 +246,9 @@ public function close(): bool
}

/**
* Destroys a session
* Destroys a session.
*
* @param string $id The session ID being destroyed
* @param string $id The session ID being destroyed.
*/
public function destroy($id): bool
{
Expand Down
26 changes: 13 additions & 13 deletions system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use ReturnTypeWillChange;

/**
* Session handler using file system for storage
* Session handler using file system for storage.
*/
class FileHandler extends BaseHandler
{
Expand All @@ -31,14 +31,14 @@ class FileHandler extends BaseHandler
protected $savePath;

/**
* The file handle
* The file handle.
*
* @var resource|null
*/
protected $fileHandle;

/**
* File Name
* File Name.
*
* @var string
*/
Expand All @@ -59,7 +59,7 @@ class FileHandler extends BaseHandler
protected $matchIP = false;

/**
* Regex of session ID
* Regex of session ID.
*
* @var string
*/
Expand All @@ -69,7 +69,7 @@ public function __construct(SessionConfig $config, string $ipAddress)
{
parent::__construct($config, $ipAddress);

if (! empty($this->savePath)) {
if ($this->savePath !== '') {
$this->savePath = rtrim($this->savePath, '/\\');
ini_set('session.save_path', $this->savePath);
} else {
Expand All @@ -88,8 +88,8 @@ public function __construct(SessionConfig $config, string $ipAddress)
/**
* Re-initialize existing session, or creates a new one.
*
* @param string $path The path where to store/retrieve the session
* @param string $name The session name
* @param string $path The path where to store/retrieve the session.
* @param string $name The session name.
*
* @throws SessionException
*/
Expand All @@ -114,7 +114,7 @@ public function open($path, $name): bool
/**
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
Expand Down Expand Up @@ -175,8 +175,8 @@ public function read($id)
/**
* Writes the session data to the session storage.
*
* @param string $id The session ID
* @param string $data The encoded session data
* @param string $id The session ID.
* @param string $data The encoded session data.
*/
public function write($id, $data): bool
{
Expand Down Expand Up @@ -239,9 +239,9 @@ public function close(): bool
}

/**
* Destroys a session
* Destroys a session.
*
* @param string $id The session ID being destroyed
* @param string $id The session ID being destroyed.
*/
public function destroy($id): bool
{
Expand Down Expand Up @@ -310,7 +310,7 @@ public function gc($max_lifetime)
}

/**
* Configure Session ID regular expression
* Configure Session ID regular expression.
*
* To make life easier, we force the PHP defaults. Because PHP9 forces them.
*
Expand Down
Loading
Loading