Current Path : /data/web/virtuals/51568/virtual/www/subdom/pomucky.1/src/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/pomucky.1/src/Session.php |
<?php namespace app; class Session { protected const FLASH_KEY = 'flash_messages'; public function __construct() { session_start(); $flashMessages = $_SESSION[self::FLASH_KEY] ?? []; foreach ($flashMessages as $key => &$flashMessage) { $flashMessage['remove'] = true; } $_SESSION[self::FLASH_KEY] = $flashMessages; } public function setFlash($key, $message) { $_SESSION[self::FLASH_KEY][$key] = [ 'remove' => false, 'value' => $message ]; } public function getFlash($key) { return $_SESSION[self::FLASH_KEY][$key]['value'] ?? false; } public function set($key, $value) { $_SESSION[$key] = $value; } public function get($key) { return $_SESSION[$key] ?? false; } public function remove($key) { unset($_SESSION[$key]); } public function __destruct() { $this->removeFlashMessages(); } private function removeFlashMessages() { $flashMessages = $_SESSION[self::FLASH_KEY] ?? []; foreach ($flashMessages as $key => $flashMessage) { if ($flashMessage['remove']) { unset($flashMessages[$key]); } } $_SESSION[self::FLASH_KEY] = $flashMessages; } }