Session.php 1.34 KB
Newer Older
1
<?php
2 3
namespace T3o\TerFe2\Persistence;

4 5
/*
 * This file is part of the TYPO3 CMS project.
6
 *
7 8 9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11 12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14 15
 * The TYPO3 project - inspiring people to share!
 */
16

17 18 19
/**
 * Utilities to manage session content
 */
20
class Session extends \T3o\TerFe2\Persistence\AbstractPersistence
21 22 23 24
{
    /**
     * Load content
     *
25
     * @throws \Exception
26 27 28 29
     */
    public function load()
    {
        if (empty($GLOBALS['TSFE']->fe_user)) {
30
            throw new \Exception('Could not load session without frontend user');
31 32 33
        }
        if (!$this->isLoaded) {
            $this->content = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->getName());
Markus Sommer's avatar
Markus Sommer committed
34
            $this->setIsLoaded(true);
35 36
        }
    }
37

38 39 40
    /**
     * Save content
     *
41
     * @throws \Exception
42 43 44 45
     */
    public function save()
    {
        if (empty($GLOBALS['TSFE']->fe_user)) {
46
            throw new \Exception('Could not save session without frontend user');
47 48 49 50 51
        }
        $GLOBALS['TSFE']->fe_user->setKey('ses', $this->getName(), $this->content);
        $GLOBALS['TSFE']->storeSessionData();
    }
}