TYPO3 CMS  TYPO3_6-2
FormProtectionFactory.php
Go to the documentation of this file.
1 <?php
3 
41 
47  static protected $instances = array();
48 
52  private function __construct() {
53 
54  }
55 
66  static public function get($className = NULL) {
67  if ($className === NULL) {
68  $className = self::getClassNameByState();
69  }
70  if (!isset(self::$instances[$className])) {
71  self::createAndStoreInstance($className);
72  }
73  return self::$instances[$className];
74  }
75 
82  static protected function getClassNameByState() {
83  switch (TRUE) {
84  case self::isInstallToolSession():
85  $className = 'TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection';
86  break;
87  case self::isBackendSession():
88  $className = 'TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection';
89  break;
90  case self::isFrontendSession():
91 
92  default:
93  $className = 'TYPO3\\CMS\\Core\\FormProtection\\DisabledFormProtection';
94  }
95  return $className;
96  }
97 
103  static protected function isInstallToolSession() {
104  return defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript;
105  }
106 
112  static protected function isBackendSession() {
113  return isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER'] instanceof \TYPO3\CMS\Core\Authentication\BackendUserAuthentication && isset($GLOBALS['BE_USER']->user['uid']);
114  }
115 
121  static protected function isFrontendSession() {
122  return is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->fe_user instanceof \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication && isset($GLOBALS['TSFE']->fe_user->user['uid']) && TYPO3_MODE === 'FE';
123  }
124 
132  static protected function createAndStoreInstance($className) {
133  if (!class_exists($className, TRUE)) {
134  throw new \InvalidArgumentException('$className must be the name of an existing class, but ' . 'actually was "' . $className . '".', 1285352962);
135  }
137  if (!$instance instanceof \TYPO3\CMS\Core\FormProtection\AbstractFormProtection) {
138  throw new \InvalidArgumentException('$className must be a subclass of ' . 'TYPO3\\CMS\\Core\\FormProtection\\AbstractFormProtection, but actually was "' . $className . '".', 1285353026);
139  }
140  self::$instances[$className] = $instance;
141  }
142 
154  static public function set($className, \TYPO3\CMS\Core\FormProtection\AbstractFormProtection $instance) {
155  self::$instances[$className] = $instance;
156  }
157 
165  static public function purgeInstances() {
166  foreach (self::$instances as $key => $instance) {
167  $instance->__destruct();
168  unset(self::$instances[$key]);
169  }
170  }
171 
172 }
const TYPO3_MODE
Definition: init.php:40
const TYPO3_enterInstallScript
Definition: Install.php:97
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]