47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
||
|
||
namespace Internetfabrik\IfOberstufenplaner\Service;
|
||
|
||
|
||
class SessionHandler implements \TYPO3\CMS\Core\SingletonInterface {
|
||
|
||
private $prefixKey = 'if_oberstufenplaner_';
|
||
|
||
/**
|
||
* Returns the object stored in the user´s PHP session
|
||
* @return Object the stored object
|
||
*/
|
||
public function restoreFromSession($key) {
|
||
$sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->prefixKey . $key);
|
||
return unserialize($sessionData);
|
||
}
|
||
|
||
/**
|
||
* Writes an object into the PHP session
|
||
* @param $object
|
||
* @param string
|
||
* @return SessionHandler this
|
||
*/
|
||
public function writeToSession($object, $key) {
|
||
$sessionData = serialize($object);
|
||
$GLOBALS['TSFE']->fe_user->setKey('ses', $this->prefixKey . $key, $sessionData);
|
||
$GLOBALS['TSFE']->fe_user->storeSessionData();
|
||
return $this;
|
||
}
|
||
|
||
/**
|
||
* Cleans up the session: removes the stored object from the PHP session
|
||
* @return SessionHandler this
|
||
*/
|
||
public function cleanUpSession($key) {
|
||
$GLOBALS['TSFE']->fe_user->setKey('ses', $this->prefixKey . $key, NULL);
|
||
$GLOBALS['TSFE']->fe_user->storeSessionData();
|
||
return $this;
|
||
}
|
||
|
||
public function setPrefixKey($prefixKey) {
|
||
$this->prefixKey = $prefixKey;
|
||
}
|
||
|
||
}
|
||
?>
|