Skip to content

Commit

Permalink
session class
Browse files Browse the repository at this point in the history
  • Loading branch information
doganoo committed Dec 19, 2018
1 parent b24cc1a commit 95e1cb5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/HTTP/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
*
* @package doganoo\PHPUtil\HTTP
*/
class Session {
class Session implements \JsonSerializable {
private $started = false;

/**
* Session constructor.
*/
Expand All @@ -39,7 +41,7 @@ public function __construct() {
* see: https://stackoverflow.com/a/17399989
*/
if (session_id() == '' || !isset ($_SESSION)) {
session_start();
$this->started = session_start();
}
}

Expand Down Expand Up @@ -117,4 +119,22 @@ public function set($index, $value) {
public function regenerateSessionId() {
session_regenerate_id(true);
}

/**
* @return bool
*/
public function isStarted(): bool {
return $this->started;
}

/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize() {
return $_SESSION;
}
}

0 comments on commit 95e1cb5

Please sign in to comment.