TYPO3 CMS  TYPO3_6-2
Registry.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core;
3 
30 
34  protected $entries = array();
35 
39  protected $loadedNamespaces = array();
40 
50  public function get($namespace, $key, $defaultValue = NULL) {
51  $this->validateNamespace($namespace);
52  if (!$this->isNamespaceLoaded($namespace)) {
53  $this->loadEntriesByNamespace($namespace);
54  }
55  return isset($this->entries[$namespace][$key]) ? $this->entries[$namespace][$key] : $defaultValue;
56  }
57 
75  public function set($namespace, $key, $value) {
76  $this->validateNamespace($namespace);
77  if (!$this->isNamespaceLoaded($namespace)) {
78  $this->loadEntriesByNamespace($namespace);
79  }
80  $serializedValue = serialize($value);
81  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'sys_registry', 'entry_namespace = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($namespace, 'sys_registry') . ' AND entry_key = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($key, 'sys_registry'));
82  if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) < 1) {
83  $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_registry', array(
84  'entry_namespace' => $namespace,
85  'entry_key' => $key,
86  'entry_value' => $serializedValue
87  ));
88  } else {
89  $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_registry', 'entry_namespace = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($namespace, 'sys_registry') . ' AND entry_key = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($key, 'sys_registry'), array(
90  'entry_value' => $serializedValue
91  ));
92  }
93  $this->entries[$namespace][$key] = $value;
94  }
95 
104  public function remove($namespace, $key) {
105  $this->validateNamespace($namespace);
106  $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_registry', 'entry_namespace = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($namespace, 'sys_registry') . ' AND entry_key = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($key, 'sys_registry'));
107  unset($this->entries[$namespace][$key]);
108  }
109 
117  public function removeAllByNamespace($namespace) {
118  $this->validateNamespace($namespace);
119  $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_registry', 'entry_namespace = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($namespace, 'sys_registry'));
120  unset($this->entries[$namespace]);
121  }
122 
130  protected function isNamespaceLoaded($namespace) {
131  return isset($this->loadedNamespaces[$namespace]);
132  }
133 
141  protected function loadEntriesByNamespace($namespace) {
142  $this->validateNamespace($namespace);
143  $storedEntries = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_registry', 'entry_namespace = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($namespace, 'sys_registry'));
144  foreach ($storedEntries as $storedEntry) {
145  $key = $storedEntry['entry_key'];
146  $this->entries[$namespace][$key] = unserialize($storedEntry['entry_value']);
147  }
148  $this->loadedNamespaces[$namespace] = TRUE;
149  }
150 
162  protected function validateNamespace($namespace) {
163  if (strlen($namespace) < 2) {
164  throw new \InvalidArgumentException('Given namespace must be longer than two characters.', 1249755131);
165  }
166  }
167 
168 }
removeAllByNamespace($namespace)
Definition: Registry.php:117
validateNamespace($namespace)
Definition: Registry.php:162
isNamespaceLoaded($namespace)
Definition: Registry.php:130
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
loadEntriesByNamespace($namespace)
Definition: Registry.php:141