Skip to content

Commit 95e1cb5

Browse files
committed
session class
1 parent b24cc1a commit 95e1cb5

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/HTTP/Session.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*
3131
* @package doganoo\PHPUtil\HTTP
3232
*/
33-
class Session {
33+
class Session implements \JsonSerializable {
34+
private $started = false;
35+
3436
/**
3537
* Session constructor.
3638
*/
@@ -39,7 +41,7 @@ public function __construct() {
3941
* see: https://stackoverflow.com/a/17399989
4042
*/
4143
if (session_id() == '' || !isset ($_SESSION)) {
42-
session_start();
44+
$this->started = session_start();
4345
}
4446
}
4547

@@ -117,4 +119,22 @@ public function set($index, $value) {
117119
public function regenerateSessionId() {
118120
session_regenerate_id(true);
119121
}
122+
123+
/**
124+
* @return bool
125+
*/
126+
public function isStarted(): bool {
127+
return $this->started;
128+
}
129+
130+
/**
131+
* Specify data which should be serialized to JSON
132+
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
133+
* @return mixed data which can be serialized by <b>json_encode</b>,
134+
* which is a value of any type other than a resource.
135+
* @since 5.4.0
136+
*/
137+
public function jsonSerialize() {
138+
return $_SESSION;
139+
}
120140
}

0 commit comments

Comments
 (0)