Skip to content
Merged
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
20 changes: 18 additions & 2 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Session extends DriverManager
/** @var bool */
protected static bool $hasStarted = false;

/** @var bool */
protected static bool $hasChanged = true;

/** @var array */
protected static array $options = [
'read_and_close' => true,
Expand Down Expand Up @@ -46,7 +49,7 @@ public static function start(array $options = []): void
*/
protected static function populateOptions(array $options = []): void
{
self::validateOptions($options);
static::validateOptions($options);

static::setOptions($options);
}
Expand All @@ -56,6 +59,12 @@ protected static function populateOptions(array $options = []): void
*/
protected static function setupAndStart(): void
{
if (static::$hasChanged === false) {
return;
}

static::$hasChanged = false;

static::configureDriver();
static::setupSessionParameters();
static::startSession();
Expand All @@ -67,7 +76,6 @@ protected static function setupAndStart(): void

if (static::$hasStarted === false && !empty(static::$flashData) && static::isReadOnly()) {
static::setReadWrite();
static::setupSessionParameters();
static::startSession();
}
unset($_SESSION['flash_data']);
Expand Down Expand Up @@ -203,6 +211,7 @@ public static function regenerate(): bool
*/
public static function destroy(): bool
{
static::$hasChanged = true;
\session_unset();

return \session_destroy();
Expand All @@ -212,6 +221,7 @@ public static function commit(): void
{
static::$hasStarted = false;
static::$flashData = [];
static::$hasChanged = true;

\session_write_close();
}
Expand All @@ -231,6 +241,7 @@ public static function unsaved(): bool
{
static::$hasStarted = false;
static::$flashData = [];
static::$hasChanged = true;

return \session_abort();
}
Expand Down Expand Up @@ -258,6 +269,7 @@ public static function getId(): string
*/
public static function setId(string $id): string
{
static::$hasChanged = true;
return \session_id($id);
}

Expand Down Expand Up @@ -294,11 +306,13 @@ protected static function startSessionIfNotHasStartedForceWrite(): void

public static function setReadOnly(): void
{
static::$hasChanged = true;
static::$options['read_and_close'] = true;
}

public static function setReadWrite(): void
{
static::$hasChanged = true;
static::$options['read_and_close'] = false;
}

Expand All @@ -325,6 +339,7 @@ protected static function getLifetimeForRedis(): int
*/
public static function setOption(string $key, $value): void
{
static::$hasChanged = true;
static::validateOptions([$key => $value]);
static::$options[$key] = $value;
}
Expand All @@ -336,6 +351,7 @@ public static function setOption(string $key, $value): void
*/
public static function setOptions(array $options): void
{
static::$hasChanged = true;
static::validateOptions($options);
static::$options = $options + static::$options;
}
Expand Down