<?php
 class Session {
 public static function init() {
 if(session_id() == '') session_start();
 }
 public static function set($key, $value) {
 session_regenerate_id(true);
 if($value instanceof \TCMS\Model) {
 $stdClass = new \stdClass();
 $fields = $value->getFields();
 foreach($fields as $k => $f) {
 $stdClass->$k = $f->value;
 }
 $_SESSION[$key] = $stdClass;
 }
 else {
 $_SESSION[$key] = $value;
 }
 }
 public static function get($key) {
 if (isset($_SESSION[$key])) {
 return $_SESSION[$key];
 }
 return null;
 }
 public static function removeAll() {
 session_destroy();
 unset($_SESSION);
 }
 public static function remove($key) {
 if (isset($_SESSION[$key])) {
 unset($_SESSION[$key]);
 }
 }
 public static function has(string $key) {
 return isset($_SESSION[$key]);
 }
 public static function flash(string $name, $data = null) {
 $name = 'flashtvt' . $name;
 if(empty($data)) {
 if(self::has($name)) {
 $data = self::get($name);
 self::remove($name);
 return $data;
 }
 return false;
 }
 else {
 self::set($name, $data);
 return true;
 }
 }
 }
 ?>