TYPO3 CMS  TYPO3_7-6
SessionUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Utility;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
31  protected $sessionData = [];
32 
38  protected $formPrefix = '';
39 
44 
48  public function __construct()
49  {
50  $this->frontendController = $GLOBALS['TSFE'];
51  }
52 
59  public function initSession($formPrefix = '')
60  {
61  $this->setFormPrefix($formPrefix);
62  if ($this->frontendController->loginUser) {
63  $this->sessionData = $this->frontendController->fe_user->getKey('user', $this->formPrefix);
64  } else {
65  $this->sessionData = $this->frontendController->fe_user->getKey('ses', $this->formPrefix);
66  }
67  }
68 
74  public function storeSession()
75  {
76  if ($this->frontendController->loginUser) {
77  $this->frontendController->fe_user->setKey('user', $this->formPrefix, $this->getSessionData());
78  } else {
79  $this->frontendController->fe_user->setKey('ses', $this->formPrefix, $this->getSessionData());
80  }
81  $this->frontendController->storeSessionData();
82  }
83 
89  public function destroySession()
90  {
91  $this->removeFiles();
92  if ($this->frontendController->loginUser) {
93  $this->frontendController->fe_user->setKey('user', $this->formPrefix, null);
94  } else {
95  $this->frontendController->fe_user->setKey('ses', $this->formPrefix, null);
96  }
97  $this->frontendController->storeSessionData();
98  }
99 
107  public function setSessionData($key, $value)
108  {
109  $this->sessionData[$key] = $value;
110  }
111 
121  public function getSessionData($key = null, $default = null)
122  {
123  if ($key === null) {
124  return $this->sessionData;
125  }
126  return isset($this->sessionData[$key]) ? $this->sessionData[$key] : $default;
127  }
128 
135  public function setFormPrefix($formPrefix)
136  {
137  $this->formPrefix = $formPrefix;
138  }
139 
145  protected function removeFiles()
146  {
147  $sessionData = $this->getSessionData();
148  if (is_array($sessionData)) {
149  foreach ($sessionData as $fieldName => $values) {
150  if (is_array($values)) {
151  foreach ($values as $file) {
152  if (isset($file['tempFilename'])) {
153  GeneralUtility::unlink_tempfile($file['tempFilename']);
154  }
155  }
156  }
157  }
158  }
159  }
160 }
static unlink_tempfile($uploadedTempFileName)
getSessionData($key=null, $default=null)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']