TYPO3 CMS  TYPO3_7-6
VariableFrontend.php
Go to the documentation of this file.
1 <?php
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 
19 
27 {
34  protected $useIgBinary = false;
35 
41  public function initializeObject()
42  {
43  $this->useIgBinary = extension_loaded('igbinary');
44  }
45 
58  public function set($entryIdentifier, $variable, array $tags = [], $lifetime = null)
59  {
60  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
61  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058264);
62  }
63  foreach ($tags as $tag) {
64  if (!$this->isValidTag($tag)) {
65  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058269);
66  }
67  }
68  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'])) {
69  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'] as $_funcRef) {
70  $params = [
71  'entryIdentifier' => &$entryIdentifier,
72  'variable' => &$variable,
73  'tags' => &$tags,
74  'lifetime' => &$lifetime
75  ];
76  GeneralUtility::callUserFunction($_funcRef, $params, $this);
77  }
78  }
79  if ($this->backend instanceof TransientBackendInterface) {
80  $this->backend->set($entryIdentifier, $variable, $tags, $lifetime);
81  } else {
82  if ($this->useIgBinary === true) {
83  $this->backend->set($entryIdentifier, igbinary_serialize($variable), $tags, $lifetime);
84  } else {
85  $this->backend->set($entryIdentifier, serialize($variable), $tags, $lifetime);
86  }
87  }
88  }
89 
98  public function get($entryIdentifier)
99  {
100  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
101  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058294);
102  }
103  $rawResult = $this->backend->get($entryIdentifier);
104  if ($rawResult === false) {
105  return false;
106  } else {
107  if ($this->backend instanceof TransientBackendInterface) {
108  return $rawResult;
109  } else {
110  return $this->useIgBinary === true ? igbinary_unserialize($rawResult) : unserialize($rawResult);
111  }
112  }
113  }
114 
123  public function getByTag($tag)
124  {
125  if (!$this->isValidTag($tag)) {
126  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058312);
127  }
128  $entries = [];
129  $identifiers = $this->backend->findIdentifiersByTag($tag);
130  foreach ($identifiers as $identifier) {
131  $rawResult = $this->backend->get($identifier);
132  if ($rawResult !== false) {
133  if ($this->backend instanceof TransientBackendInterface) {
134  $entries[] = $rawResult;
135  } else {
136  $entries[] = $this->useIgBinary === true ? igbinary_unserialize($rawResult) : unserialize($rawResult);
137  }
138  }
139  }
140  return $entries;
141  }
142 }
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']