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
16 changes: 14 additions & 2 deletions src/Session/HttpSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function __construct()
$this->response = getDeepContextValueByClassName(Response::class);
if($this->config->getSessionUsage() == SessionConfig::USAGE_COOKIE) {
$this->id = $this->request->getCookieParams()[$this->config->getSessionName()] ?? null;
}else{
} elseif ($this->config->getSessionUsage() == SessionConfig::USEAGE_HEADER) {
/** @var array $_sesionIdentify */
$_sesionIdentify = $this->request->getHeader(SessionConfig::HEADER_IDENTIFY);
$this->id = !empty($_sesionIdentify[0]) ? $_sesionIdentify[0] : null;
} else{
$authorization = explode(' ',$this->request->getHeaderLine('authorization'));
if(isset($authorization[1])){
$this->id = $authorization[1];
Expand Down Expand Up @@ -146,6 +150,7 @@ public function removeAttribute(string $key): void
{
unset($this->attribute[$key]);
}

public function refresh(): void
{
$id = $this->getId();
Expand All @@ -157,7 +162,14 @@ public function refresh(): void
$this->response->withCookie(new Cookie($this->config->getSessionName(), $this->id,
time() + $this->config->getTimeout(), $this->config->getPath(),
$this->config->getDomain(), $this->config->getSecure(), $this->config->getHttpOnly()));
}else{
} elseif ($this->config->getSessionUsage() == SessionConfig::USEAGE_HEADER) {
/** @var array $_sesionIdentify */
$_sesionIdentify = $this->request->getHeader(SessionConfig::HEADER_IDENTIFY);
if (!empty($_sesionIdentify[0])) {
$sesionIdentify = $_sesionIdentify[0];
$this->response->withHeader(SessionConfig::HEADER_IDENTIFY, $sesionIdentify);
}
} else{
$this->response->withHeader('Authorization', 'Bearer ' .$this->id);
}
$this->setAttribute("createTime", time());
Expand Down
28 changes: 28 additions & 0 deletions src/Session/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,29 @@

class SessionConfig extends BaseConfig
{
/**
* Session key
*/
const key = "session";

/**
* Usage cookie
*/
const USAGE_COOKIE = 'cookie';

/**
* Usage head
*/
const USEAGE_HEADER = 'header';

/**
* Header identify to identify session
*/
const HEADER_IDENTIFY = 'sessionId';

/**
* Usage token
*/
const USAGE_TOKEN = 'token';

/**
Expand All @@ -36,6 +57,13 @@ class SessionConfig extends BaseConfig

protected $sessionUsage = SessionConfig::USAGE_COOKIE;

/**
* Header identity. When $sessionUsage is set to header, should set $headerIdentity
*
* @var string
*/
protected $headerIdentity = SessionConfig::HEADER_IDENTIFY;

/**
* @var string
*/
Expand Down