diff --git a/src/HTTP/Session.php b/src/HTTP/Session.php index 2472249..3f48892 100644 --- a/src/HTTP/Session.php +++ b/src/HTTP/Session.php @@ -30,7 +30,9 @@ * * @package doganoo\PHPUtil\HTTP */ -class Session { +class Session implements \JsonSerializable { + private $started = false; + /** * Session constructor. */ @@ -39,7 +41,7 @@ public function __construct() { * see: https://stackoverflow.com/a/17399989 */ if (session_id() == '' || !isset ($_SESSION)) { - session_start(); + $this->started = session_start(); } } @@ -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 json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() { + return $_SESSION; + } } \ No newline at end of file