Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/WebFiori/framework into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Mar 18, 2024
2 parents 4aa9670 + c7f30e1 commit 2c40f1a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions webfiori/framework/session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ public function __construct(array $options = []) {
$this->setIsRefresh(false);
}

if (!(isset($options['duration']) && $this->setDuration($options['duration']))) {
if (!(isset($options[SessionOption::DURATION]) && $this->setDuration($options[SessionOption::DURATION]))) {
$this->setDuration(self::DEFAULT_SESSION_DURATION);
}

if ($this->getDuration() == 0) {
$this->setIsRefresh(false);
}
$tempSName = isset($options['name']) ? trim($options['name']) : '';
$tempSName = isset($options[SessionOption::NAME]) ? trim($options[SessionOption::NAME]) : '';

if (!$this->setNameHelper($tempSName)) {
throw new SessionException('Invalid session name: \''.$tempSName.'\'.');
}

$this->getCookie()->setValue(isset($options['session-id']) ? trim($options['session-id']) : self::generateSessionID($tempSName));
$this->getCookie()->setValue(isset($options[SessionOption::SESSION_ID]) ? trim($options[SessionOption::SESSION_ID]) : self::generateSessionID($tempSName));
$this->resumedAt = 0;
$this->startedAt = 0;
$this->sessionVariables = [];
Expand Down
39 changes: 39 additions & 0 deletions webfiori/framework/session/SessionOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* This file is licensed under MIT License.
*
* Copyright (c) 2024 Ibrahim BinAlshikh
*
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
*/

namespace webfiori\framework\session;

/**
* A class which is used to hold the options names that are supported during
* new session initialization or session update.
*
* @author Ibrahim
*/
class SessionOption {
/**
* An option which is used to set session duration (minutes)
*/
const DURATION = 'duration';
/**
* An option which is used to set if session timeout will be refreshed on
* each request or not (bool)
*/
const REFRESH = 'refresh';
/**
* An option which is used to set the name of the session. The name will be
* same as session cookie.
*/
const NAME = 'name';
/**
* An option which is used to set the ID of the session.
*/
const SESSION_ID = 'session-id';
}
2 changes: 1 addition & 1 deletion webfiori/framework/session/SessionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static function start(string $sessionName, array $options = []) {
self::getInstance()->pauseSessions();

if (!self::hasSession($sessionName)) {
$options['name'] = $sessionName;
$options[SessionOption::NAME] = $sessionName;
$s = new Session($options);
$s->start();
self::getInstance()->sessionsArr[] = $s;
Expand Down

0 comments on commit 2c40f1a

Please sign in to comment.